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

Function findBestPolicySet

fdbrpc/ReplicationUtils.cpp:217–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217bool findBestPolicySet(std::vector<LocalityEntry>& bestResults,
218 Reference<LocalitySet>& localitySet,
219 Reference<IReplicationPolicy> const& policy,
220 unsigned int nMinItems,
221 unsigned int nSelectTests,
222 unsigned int nPolicyTests) {
223
224 bool bestFound = false;
225
226 // Specialization for policies of shape:
227 // - PolicyOne()
228 // - PolicyAcross(,"zoneId",PolicyOne())
229 // - TODO: More specializations for common policies
230 if (policy->name() == "One") {
231 bestFound = true;
232 int count = 0;
233 auto& mutableEntries = localitySet->getMutableEntries();
234 deterministicRandom()->randomShuffle(mutableEntries);
235 for (auto const& entry : mutableEntries) {
236 bestResults.push_back(entry);
237 if (++count == nMinItems)
238 break;
239 }
240 } else if (policy->name() == "Across") {
241 PolicyAcross* pa = (PolicyAcross*)policy.getPtr();
242 std::set<std::string> attributeKeys;
243 pa->attributeKeys(&attributeKeys);
244 if (pa->embeddedPolicyName() == "One" && attributeKeys.size() == 1 &&
245 *attributeKeys.begin() == "zoneid" // This algorithm can actually apply to any field
246 ) {
247 bestFound = findBestPolicySetSimple(pa->getCount(), localitySet, bestResults, nMinItems);
248 if (bestFound && g_network->isSimulated()) {
249 std::vector<LocalityEntry> oldBest;
250 auto oldBestFound =
251 findBestPolicySetExpensive(oldBest, localitySet, policy, nMinItems, nSelectTests, nPolicyTests);
252 if (!oldBestFound) {
253 TraceEvent(SevError, "FBPSMissmatch").detail("Policy", policy->info());
254 } else {
255 ASSERT(mostUsedZoneCount(localitySet, bestResults) <= mostUsedZoneCount(localitySet, oldBest));
256 }
257 }
258 } else {
259 bestFound =
260 findBestPolicySetExpensive(bestResults, localitySet, policy, nMinItems, nSelectTests, nPolicyTests);
261 }
262 } else {
263 bestFound = findBestPolicySetExpensive(bestResults, localitySet, policy, nMinItems, nSelectTests, nPolicyTests);
264 }
265 return bestFound;
266}
267
268bool findBestUniquePolicySet(std::vector<LocalityEntry>& bestResults,
269 Reference<LocalitySet>& localitySet,

Callers 2

testReplicationFunction · 0.85

Calls 15

deterministicRandomFunction · 0.85
findBestPolicySetSimpleFunction · 0.85
TraceEventClass · 0.85
mostUsedZoneCountFunction · 0.85
randomShuffleMethod · 0.80
embeddedPolicyNameMethod · 0.80
detailMethod · 0.80
nameMethod · 0.65
getCountMethod · 0.65
push_backMethod · 0.45
getPtrMethod · 0.45

Tested by

no test coverage detected