MCPcopy Create free account
hub / github.com/apple/foundationdb / parseLocalitiesFromKeys

Function parseLocalitiesFromKeys

fdbclient/SpecialKeySpace.actor.cpp:2630–2669  ·  view source on GitHub ↗

Reads the excludedlocality and failed locality keys using management api, parses them and returns the list.

Source from the content-addressed store, hash-verified

2628// Reads the excludedlocality and failed locality keys using management api,
2629// parses them and returns the list.
2630bool parseLocalitiesFromKeys(ReadYourWritesTransaction* ryw,
2631 bool failed,
2632 std::unordered_set<std::string>& localities,
2633 std::vector<AddressExclusion>& addresses,
2634 std::set<AddressExclusion>& exclusions,
2635 std::vector<ProcessData>& workers,
2636 Optional<std::string>& msg) {
2637 KeyRangeRef range = failed ? SpecialKeySpace::getManagementApiCommandRange("failedlocality")
2638 : SpecialKeySpace::getManagementApiCommandRange("excludedlocality");
2639 auto ranges = ryw->getSpecialKeySpaceWriteMap().containedRanges(range);
2640 auto iter = ranges.begin();
2641 while (iter != ranges.end()) {
2642 auto entry = iter->value();
2643 // only check for exclude(set) operation, include(clear) are not checked
2644 TraceEvent(SevDebug, "ParseLocalities")
2645 .detail("Valid", entry.first)
2646 .detail("Set", entry.second.present())
2647 .detail("Key", iter->begin().toString());
2648 if (entry.first && entry.second.present()) {
2649 Key locality = iter->begin().removePrefix(range.begin);
2650 if (locality.startsWith(LocalityData::ExcludeLocalityPrefix) &&
2651 locality.toString().find(':') != std::string::npos) {
2652 std::set<AddressExclusion> localityAddresses = getAddressesByLocality(workers, locality.toString());
2653 if (!localityAddresses.empty()) {
2654 std::copy(localityAddresses.begin(), localityAddresses.end(), back_inserter(addresses));
2655 exclusions.insert(localityAddresses.begin(), localityAddresses.end());
2656 }
2657
2658 localities.insert(locality.toString());
2659 } else {
2660 std::string error = "ERROR: \'" + locality.toString() + "\' is not a valid locality\n";
2661 msg = ManagementAPIError::toJsonString(
2662 false, entry.second.present() ? (failed ? "exclude failed" : "exclude") : "include", error);
2663 return false;
2664 }
2665 }
2666 ++iter;
2667 }
2668 return true;
2669}
2670
2671// On commit, parses the special exclusion keys and get the localities to be excluded, check for exclusions
2672// and add them to the exclusion list. Also, clears the special management api keys with includeLocalities.

Calls 15

TraceEventClass · 0.85
getAddressesByLocalityFunction · 0.85
copyFunction · 0.85
containedRangesMethod · 0.80
detailMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
valueMethod · 0.45
presentMethod · 0.45
toStringMethod · 0.45
removePrefixMethod · 0.45
startsWithMethod · 0.45

Tested by

no test coverage detected