Merge pull request #5897 from sfc-gh-ahusain/ahusain-fixCommitProxyCount
Use DEFAULT_COMMIT_GRV_PROXIES_RATIO to override proxies_count if mutation supplied value is -1
This commit is contained in:
commit
f8538d0bc3
|
@ -20,6 +20,9 @@
|
|||
|
||||
#include "fdbclient/DatabaseConfiguration.h"
|
||||
#include "fdbclient/SystemData.h"
|
||||
#include "flow/ITrace.h"
|
||||
#include "flow/Trace.h"
|
||||
#include "flow/genericactors.actor.h"
|
||||
|
||||
DatabaseConfiguration::DatabaseConfiguration() {
|
||||
resetInternal();
|
||||
|
@ -49,6 +52,10 @@ void DatabaseConfiguration::resetInternal() {
|
|||
storageMigrationType = StorageMigrationType::DEFAULT;
|
||||
}
|
||||
|
||||
int toInt(ValueRef const& v) {
|
||||
return atoi(v.toString().c_str());
|
||||
}
|
||||
|
||||
void parse(int* i, ValueRef const& v) {
|
||||
// FIXME: Sanity checking
|
||||
*i = atoi(v.toString().c_str());
|
||||
|
@ -466,6 +473,64 @@ std::string DatabaseConfiguration::toString() const {
|
|||
return json_spirit::write_string(json_spirit::mValue(toJSON()), json_spirit::Output_options::none);
|
||||
}
|
||||
|
||||
Key getKeyWithPrefix(std::string const& k) {
|
||||
return StringRef(k).withPrefix(configKeysPrefix);
|
||||
}
|
||||
|
||||
void DatabaseConfiguration::overwriteProxiesCount() {
|
||||
Key commitProxiesKey = getKeyWithPrefix("commit_proxies");
|
||||
Key grvProxiesKey = getKeyWithPrefix("grv_proxies");
|
||||
Key proxiesKey = getKeyWithPrefix("proxies");
|
||||
Optional<ValueRef> optCommitProxies = DatabaseConfiguration::get(commitProxiesKey);
|
||||
Optional<ValueRef> optGrvProxies = DatabaseConfiguration::get(grvProxiesKey);
|
||||
Optional<ValueRef> optProxies = DatabaseConfiguration::get(proxiesKey);
|
||||
|
||||
const int mutableGrvProxyCount = optGrvProxies.present() ? toInt(optGrvProxies.get()) : 0;
|
||||
const int mutableCommitProxyCount = optCommitProxies.present() ? toInt(optCommitProxies.get()) : 0;
|
||||
const int mutableProxiesCount = optProxies.present() ? toInt(optProxies.get()) : 0;
|
||||
|
||||
if (mutableProxiesCount > 1) {
|
||||
TraceEvent(SevDebug, "OverwriteProxiesCount")
|
||||
.detail("CPCount", commitProxyCount)
|
||||
.detail("MutableCPCount", mutableCommitProxyCount)
|
||||
.detail("GrvCount", grvProxyCount)
|
||||
.detail("MutableGrvCPCount", mutableGrvProxyCount)
|
||||
.detail("MutableProxiesCount", mutableProxiesCount);
|
||||
|
||||
if (grvProxyCount == -1 && commitProxyCount > 0) {
|
||||
if (mutableProxiesCount > commitProxyCount) {
|
||||
grvProxyCount = mutableProxiesCount - commitProxyCount;
|
||||
} else {
|
||||
// invalid configuration; provision min GrvProxies
|
||||
grvProxyCount = 1;
|
||||
commitProxyCount = mutableProxiesCount - 1;
|
||||
}
|
||||
} else if (grvProxyCount > 0 && commitProxyCount == -1) {
|
||||
if (mutableProxiesCount > grvProxyCount) {
|
||||
commitProxyCount = mutableProxiesCount - grvProxyCount;
|
||||
} else {
|
||||
// invalid configuration; provision min CommitProxies
|
||||
commitProxyCount = 1;
|
||||
grvProxyCount = mutableProxiesCount - 1;
|
||||
}
|
||||
} else if (grvProxyCount == -1 && commitProxyCount == -1) {
|
||||
// Use DEFAULT_COMMIT_GRV_PROXIES_RATIO to split proxies between Grv & Commit proxies
|
||||
const int derivedGrvProxyCount =
|
||||
std::max(1,
|
||||
std::min(CLIENT_KNOBS->DEFAULT_MAX_GRV_PROXIES,
|
||||
mutableProxiesCount / (CLIENT_KNOBS->DEFAULT_COMMIT_GRV_PROXIES_RATIO + 1)));
|
||||
|
||||
grvProxyCount = derivedGrvProxyCount;
|
||||
commitProxyCount = mutableProxiesCount - grvProxyCount;
|
||||
}
|
||||
|
||||
TraceEvent(SevDebug, "OverwriteProxiesCountResult")
|
||||
.detail("CommitProxyCount", commitProxyCount)
|
||||
.detail("GrvProxyCount", grvProxyCount)
|
||||
.detail("ProxyCount", mutableProxiesCount);
|
||||
}
|
||||
}
|
||||
|
||||
bool DatabaseConfiguration::setInternal(KeyRef key, ValueRef value) {
|
||||
KeyRef ck = key.removePrefix(configKeysPrefix);
|
||||
int type;
|
||||
|
@ -473,9 +538,13 @@ bool DatabaseConfiguration::setInternal(KeyRef key, ValueRef value) {
|
|||
if (ck == LiteralStringRef("initialized")) {
|
||||
initialized = true;
|
||||
} else if (ck == LiteralStringRef("commit_proxies")) {
|
||||
parse(&commitProxyCount, value);
|
||||
commitProxyCount = toInt(value);
|
||||
if (commitProxyCount == -1)
|
||||
overwriteProxiesCount();
|
||||
} else if (ck == LiteralStringRef("grv_proxies")) {
|
||||
parse(&grvProxyCount, value);
|
||||
grvProxyCount = toInt(value);
|
||||
if (grvProxyCount == -1)
|
||||
overwriteProxiesCount();
|
||||
} else if (ck == LiteralStringRef("resolvers")) {
|
||||
parse(&resolverCount, value);
|
||||
} else if (ck == LiteralStringRef("logs")) {
|
||||
|
@ -557,21 +626,7 @@ bool DatabaseConfiguration::setInternal(KeyRef key, ValueRef value) {
|
|||
parse((&type), value);
|
||||
storageMigrationType = (StorageMigrationType::MigrationType)type;
|
||||
} else if (ck == LiteralStringRef("proxies")) {
|
||||
int proxiesCount;
|
||||
parse(&proxiesCount, value);
|
||||
if (proxiesCount > 1) {
|
||||
int derivedGrvProxyCount =
|
||||
std::max(1,
|
||||
std::min(CLIENT_KNOBS->DEFAULT_MAX_GRV_PROXIES,
|
||||
proxiesCount / (CLIENT_KNOBS->DEFAULT_COMMIT_GRV_PROXIES_RATIO + 1)));
|
||||
int derivedCommitProxyCount = proxiesCount - derivedGrvProxyCount;
|
||||
if (grvProxyCount == -1) {
|
||||
grvProxyCount = derivedGrvProxyCount;
|
||||
}
|
||||
if (commitProxyCount == -1) {
|
||||
commitProxyCount = derivedCommitProxyCount;
|
||||
}
|
||||
}
|
||||
overwriteProxiesCount();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -333,6 +333,8 @@ private:
|
|||
|
||||
/// Check if the key is overridden by either mutableConfiguration or rawConfiguration
|
||||
bool isOverridden(std::string key) const;
|
||||
// Overwrite commitProxyCount and/or grvProxyCount if set to -1
|
||||
void overwriteProxiesCount();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -447,6 +447,7 @@ public:
|
|||
const uint8_t* begin() const { return data; }
|
||||
const uint8_t* end() const { return data + length; }
|
||||
int size() const { return length; }
|
||||
bool empty() const { return length == 0; }
|
||||
|
||||
uint8_t operator[](int i) const { return data[i]; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue