diff --git a/fdbclient/ManagementAPI.actor.cpp b/fdbclient/ManagementAPI.actor.cpp index e1b71bc89f..26961b4d20 100644 --- a/fdbclient/ManagementAPI.actor.cpp +++ b/fdbclient/ManagementAPI.actor.cpp @@ -1282,9 +1282,7 @@ ACTOR Future excludeServers(Database cx, vector servers, loop { try{ ryw.setOption( FDBTransactionOptions::SPECIAL_KEY_SPACE_CHANGE_CONFIGURATION); - Key optionKey = failed ? LiteralStringRef("\xff\xff/conf/options/failed/force") - : LiteralStringRef("\xff\xff/conf/options/exclude/force"); - ryw.set(optionKey, ValueRef()); + ryw.set(SpecialKeySpace::getManagementApiCommandOptionSpecialKey(failed ? "failed" : "exclude", "force"), ValueRef()); for(auto& s : servers) { Key addr = failed ? SpecialKeySpace::getManagementApiCommandPrefix("failed").withSuffix(s.toString()) : SpecialKeySpace::getManagementApiCommandPrefix("exclude").withSuffix(s.toString()); diff --git a/fdbclient/SpecialKeySpace.actor.cpp b/fdbclient/SpecialKeySpace.actor.cpp index c5accf9de8..7cd0376406 100644 --- a/fdbclient/SpecialKeySpace.actor.cpp +++ b/fdbclient/SpecialKeySpace.actor.cpp @@ -39,10 +39,14 @@ std::unordered_map SpecialKeySpace::moduleToB }; std::unordered_map SpecialKeySpace::managementApiCommandToRange = { - { "exclude", KeyRangeRef(LiteralStringRef("excluded/"), LiteralStringRef("excluded0")).withPrefix(managementApiRange.begin) }, - { "failed", KeyRangeRef(LiteralStringRef("failed/"), LiteralStringRef("failed0")).withPrefix(managementApiRange.begin) } + { "exclude", + KeyRangeRef(LiteralStringRef("excluded/"), LiteralStringRef("excluded0")).withPrefix(managementApiRange.begin) }, + { "failed", + KeyRangeRef(LiteralStringRef("failed/"), LiteralStringRef("failed0")).withPrefix(managementApiRange.begin) } }; +std::unordered_set SpecialKeySpace::options = { "exclude/force", "failed/force" }; + // This function will move the given KeySelector as far as possible to the standard form: // orEqual == false && offset == 1 (Standard form) // If the corresponding key is not in the underlying key range, it will move over the range @@ -348,7 +352,6 @@ void SpecialKeySpace::set(ReadYourWritesTransaction* ryw, const KeyRef& key, con if (!ryw->specialKeySpaceChangeConfiguration()) throw special_keys_write_disabled(); // TODO : check value valid auto impl = writeImpls[key]; - // TODO : do we need the separate error here to differentiate from read? if (impl == nullptr) throw special_keys_no_write_module_found(); TraceEvent(SevDebug, "SpecialKeySpaceSet") .detail("Key", key.toString()) @@ -408,7 +411,6 @@ ACTOR Future commitActor(SpecialKeySpace* sks, ReadYourWritesTransaction* state RangeMap>, KeyRangeRef>::Ranges ranges = ryw->getSpecialKeySpaceWriteMap().containedRanges(specialKeys); state RangeMap>, KeyRangeRef>::iterator iter = ranges.begin(); - // TODO : update this set container state std::set writeModulePtrs; while (iter != ranges.end()) { std::pair> entry = iter->value(); @@ -508,12 +510,12 @@ Future> DDStatsRangeImpl::getRange(ReadYourWritesTran return ddMetricsGetRangeActor(ryw, kr); } -std::unordered_set ManagementCommandsOptionsImpl::options = { "exclude/force", "failed/force" }; - -// Optional ManagementCommandsOptionsImpl::getOptionSpecialKey(const std::string& command, const std::string& -// option) { auto pair = command + "/" + option; if (options.find(pair) != options.end()) { return -// Optional(getKeyRange().begin.withSuffix(pair)); } else return Optional(); -// } +Key SpecialKeySpace::getManagementApiCommandOptionSpecialKey(const std::string& command, const std::string& option) { + Key prefix = LiteralStringRef("options/").withPrefix(managementApiRange.begin); + auto pair = command + "/" + option; + ASSERT(options.find(pair) != options.end()); + return prefix.withSuffix(pair); +} ManagementCommandsOptionsImpl::ManagementCommandsOptionsImpl(KeyRangeRef kr) : SpecialKeyRangeRWImpl(kr) {} @@ -521,7 +523,7 @@ Future> ManagementCommandsOptionsImpl::getRange(ReadY KeyRangeRef kr) const { Standalone result; // Since we only have limit number of options, a brute force loop here is enough - for (const auto& option : options) { + for (const auto& option : SpecialKeySpace::getManamentApiOptionsSet()) { auto key = getKeyRange().begin.withSuffix(option); // ignore all invalid keys auto r = ryw->getSpecialKeySpaceWriteMap()[key]; @@ -534,15 +536,15 @@ Future> ManagementCommandsOptionsImpl::getRange(ReadY void ManagementCommandsOptionsImpl::set(ReadYourWritesTransaction* ryw, const KeyRef& key, const ValueRef& value) { std::string option = key.removePrefix(getKeyRange().begin).toString(); // ignore all invalid keys - if (options.find(option) != options.end()) { - TraceEvent(SevDebug, "ManagementAPIOption").detail("Option", option).detail("Key", key); + if (SpecialKeySpace::getManamentApiOptionsSet().find(option) != SpecialKeySpace::getManamentApiOptionsSet().end()) { + TraceEvent(SevDebug, "ManagementApiOption").detail("Option", option).detail("Key", key); ryw->getSpecialKeySpaceWriteMap().insert(key, std::make_pair(true, Optional(value))); } } void ManagementCommandsOptionsImpl::clear(ReadYourWritesTransaction* ryw, const KeyRangeRef& range) { // Since we only have limit number of options, a brute force loop here is enough - for (const auto& option : options) { + for (const auto& option : SpecialKeySpace::getManamentApiOptionsSet()) { auto key = getKeyRange().begin.withSuffix(option); // ignore all invalid keys if (range.contains(key)) @@ -554,7 +556,7 @@ void ManagementCommandsOptionsImpl::clear(ReadYourWritesTransaction* ryw, const void ManagementCommandsOptionsImpl::clear(ReadYourWritesTransaction* ryw, const KeyRef& key) { std::string option = key.removePrefix(getKeyRange().begin).toString(); // ignore all invalid keys - if (options.find(option) != options.end()) { + if (SpecialKeySpace::getManamentApiOptionsSet().find(option) != SpecialKeySpace::getManamentApiOptionsSet().end()) { // ryw->getSpecialKeySpaceWriteMap().insert(key, std::make_pair(true, Optional())); ryw->getSpecialKeySpaceWriteMap().rawErase(singleKeyRange(key)); } @@ -568,7 +570,7 @@ Future> ManagementCommandsOptionsImpl::commit(ReadYourWrit // read from rwModule ACTOR Future> rwModuleGetRangeActor(ReadYourWritesTransaction* ryw, KeyRangeRef range, KeyRangeRef kr) { - KeyRangeRef krWithoutPrefix = kr.removePrefix(normalKeys.end); // TODO : need to update + KeyRangeRef krWithoutPrefix = kr.removePrefix(normalKeys.end); // TODO : need to replace with a general encode/decode funciton Standalone resultWithoutPrefix = wait(ryw->getRange(krWithoutPrefix, CLIENT_KNOBS->TOO_MANY)); ASSERT(!resultWithoutPrefix.more && resultWithoutPrefix.size() < CLIENT_KNOBS->TOO_MANY); Standalone result; @@ -695,7 +697,7 @@ ACTOR Future checkExclusion(Database db, std::vector* ad StatusObject status = wait(StatusClient::statusFetcher(db)); state std::string errorString = "ERROR: Could not calculate the impact of this exclude on the total free space in the cluster.\n" - "Please try the exclude again in 30 seconds.\n"; // TODO : update msg here + "Please try the exclude again in 30 seconds.\n"; StatusObjectReader statusObj(status); @@ -773,8 +775,6 @@ ACTOR Future checkExclusion(Database db, std::vector* ad if (ssExcludedCount == ssTotalCount || (1 - worstFreeSpaceRatio) * ssTotalCount / (ssTotalCount - ssExcludedCount) > 0.9) { std::string temp = "ERROR: This exclude may cause the total free space in the cluster to drop below 10%."; - // "\nType `exclude FORCE ' to exclude without checking free space.\n"; // TODO : update message - // here *msg = ManagementAPIError::toJsonString(false, markFailed ? "exclude failed" : "exclude", temp); return false; } @@ -829,8 +829,8 @@ ACTOR Future> excludeCommitActor(ReadYourWritesTransaction addresses, exclusions, result)) return result; // If force option is not set, we need to do safety check - auto force = ryw->getSpecialKeySpaceWriteMap()[failed ? LiteralStringRef("\xff\xff/conf/options/failed/force") - : LiteralStringRef("\xff\xff/conf/options/exclude/force")]; + auto force = ryw->getSpecialKeySpaceWriteMap()[SpecialKeySpace::getManagementApiCommandOptionSpecialKey( + failed ? "failed" : "exclude", "force")]; TraceEvent(SevDebug, "ExclusionCommit") .detail("Failed", failed) .detail("Force", force.first) @@ -878,7 +878,6 @@ Future> FailedServersRangeImpl::commit(ReadYourWritesTrans ACTOR Future> ExclusionInProgressActor(ReadYourWritesTransaction* ryw, KeyRef prefix, KeyRangeRef kr) { state Standalone result; - // TODO : get all inprogress excluded servers state Transaction& tr = ryw->getTransaction(); tr.setOption(FDBTransactionOptions::READ_SYSTEM_KEYS); tr.setOption(FDBTransactionOptions::PRIORITY_SYSTEM_IMMEDIATE); // necessary? diff --git a/fdbclient/SpecialKeySpace.actor.h b/fdbclient/SpecialKeySpace.actor.h index 213874cbf5..b964e54fdf 100644 --- a/fdbclient/SpecialKeySpace.actor.h +++ b/fdbclient/SpecialKeySpace.actor.h @@ -156,6 +156,8 @@ public: KeyRangeRef getKeyRange() const { return range; } static KeyRange getManamentApiCommandRange(std::string command) { return managementApiCommandToRange.at(command); } static Key getManagementApiCommandPrefix(std::string command) { return managementApiCommandToRange.at(command).begin; } + static Key getManagementApiCommandOptionSpecialKey(const std::string& command, const std::string& option); + static const std::unordered_set& getManamentApiOptionsSet() { return options; } private: ACTOR static Future> getActor(SpecialKeySpace* sks, ReadYourWritesTransaction* ryw, KeyRef key); @@ -175,6 +177,7 @@ private: static std::unordered_map moduleToBoundary; static std::unordered_map managementApiCommandToRange; // management command to its special keys' range + static std::unordered_set options; // "/