Reads the excludedlocality and failed locality keys using management api, parses them and returns the list.
| 2628 | // Reads the excludedlocality and failed locality keys using management api, |
| 2629 | // parses them and returns the list. |
| 2630 | bool 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. |
no test coverage detected