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

Method populateSatelliteTagLocations

fdbserver/LogSystem.cpp:67–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67void LogSet::populateSatelliteTagLocations(int logRouterTags, int oldLogRouterTags, int txsTags, int oldTxsTags) {
68 satelliteTagLocations.clear();
69 satelliteTagLocations.resize(std::max({ logRouterTags, oldLogRouterTags, txsTags, oldTxsTags }) + 1);
70
71 std::map<int, int> server_usedBest;
72 std::set<std::pair<int, int>> used_servers;
73 for (int i = 0; i < tLogLocalities.size(); i++) {
74 used_servers.insert(std::make_pair(0, i));
75 }
76
77 Reference<LocalitySet> serverSet = Reference<LocalitySet>(new LocalityMap<std::pair<int, int>>());
78 LocalityMap<std::pair<int, int>>* serverMap = (LocalityMap<std::pair<int, int>>*)serverSet.getPtr();
79 std::vector<std::pair<int, int>> resultPairs;
80 for (int loc = 0; loc < satelliteTagLocations.size(); loc++) {
81 int team = loc;
82 if (loc < logRouterTags) {
83 team = loc + 1;
84 } else if (loc == logRouterTags) {
85 team = 0;
86 }
87
88 bool teamComplete = false;
89 alsoServers.resize(1);
90 serverMap->clear();
91 resultPairs.clear();
92 for (auto& used_idx : used_servers) {
93 auto entry = serverMap->add(tLogLocalities[used_idx.second], &used_idx);
94 if (!resultPairs.size()) {
95 resultPairs.push_back(used_idx);
96 alsoServers[0] = entry;
97 }
98
99 resultEntries.clear();
100 if (serverSet->selectReplicas(tLogPolicy, alsoServers, resultEntries)) {
101 for (auto& entry : resultEntries) {
102 resultPairs.push_back(*serverMap->getObject(entry));
103 }
104 int firstBestUsed = server_usedBest[resultPairs[0].second];
105 for (int i = 1; i < resultPairs.size(); i++) {
106 int thisBestUsed = server_usedBest[resultPairs[i].second];
107 if (thisBestUsed < firstBestUsed) {
108 std::swap(resultPairs[0], resultPairs[i]);
109 firstBestUsed = thisBestUsed;
110 }
111 }
112 server_usedBest[resultPairs[0].second]++;
113
114 for (auto& res : resultPairs) {
115 satelliteTagLocations[team].push_back(res.second);
116 used_servers.erase(res);
117 res.first++;
118 used_servers.insert(res);
119 }
120 teamComplete = true;
121 break;
122 }
123 }
124 ASSERT(teamComplete);

Callers 1

newEpochMethod · 0.80

Calls 11

swapFunction · 0.85
getObjectMethod · 0.80
clearMethod · 0.65
resizeMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
getPtrMethod · 0.45
addMethod · 0.45
push_backMethod · 0.45
selectReplicasMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected