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

Function randomAcrossPolicy

fdbrpc/ReplicationUtils.cpp:836–929  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

834}
835
836Reference<IReplicationPolicy> const randomAcrossPolicy(LocalitySet const& serverSet) {
837 int usedKeyTotal, keysUsed, keyIndex, valueTotal, maxValueTotal, maxKeyTotal, skips, lastKeyIndex;
838 std::vector<std::string> keyArray(serverSet.getGroupKeyMap()->_lookuparray);
839 std::set<std::string> valueSet;
840 AttribKey indexKey;
841 Optional<AttribValue> keyValue;
842 std::string keyText;
843 Reference<IReplicationPolicy> policy(new PolicyOne());
844
845 // Determine the number of keys to used within the policy
846 usedKeyTotal = deterministicRandom()->randomInt(1, keyArray.size() + 1);
847 maxKeyTotal = deterministicRandom()->randomInt(1, 4);
848 if ((usedKeyTotal > maxKeyTotal) && (deterministicRandom()->random01() > .1)) {
849 usedKeyTotal = maxKeyTotal;
850 }
851 maxValueTotal = deterministicRandom()->randomInt(1, 10);
852 keysUsed = skips = 0;
853
854 if (g_replicationdebug > 6) {
855 keyIndex = 0;
856 for (auto& key : keyArray) {
857 keyIndex++;
858 printf("%s key: (%2d) %-10s\n", ((keyIndex > 1) ? "" : "\n"), keyIndex, key.c_str());
859 }
860 }
861
862 if (g_replicationdebug > 2)
863 printf("Policy using%3d of%3lu keys Max values:%3d\n", usedKeyTotal, keyArray.size(), maxValueTotal);
864 while (keysUsed < usedKeyTotal) {
865 keyIndex = deterministicRandom()->randomInt(0, keyArray.size() - keysUsed);
866 keyText = keyArray[keyIndex];
867 lastKeyIndex = keyArray.size() - 1 - keysUsed;
868
869 // Do not allow az and sz within a policy, 90% of the time
870 if ((!keyText.compare("az")) && (deterministicRandom()->random01() > .1) &&
871 (std::find(keyArray.begin() + lastKeyIndex + 1, keyArray.end(), "sz") != keyArray.end())) {
872 skips++;
873 } else if ((!keyText.compare("sz")) && (deterministicRandom()->random01() > .1) &&
874 (std::find(keyArray.begin() + lastKeyIndex + 1, keyArray.end(), "az") != keyArray.end())) {
875 skips++;
876 } else {
877 if (g_replicationdebug > 3) {
878 printf(" keys index:%3d value: %-10s used:%3d total:%3d size:%3lu\n",
879 keyIndex,
880 keyText.c_str(),
881 keysUsed,
882 usedKeyTotal,
883 keyArray.size());
884 }
885 indexKey = serverSet.keyIndex(keyText);
886 valueSet.clear();
887 // Determine all of the values for the key
888 for (auto& entry : serverSet.getEntries()) {
889 keyValue = serverSet.getValueViaEntry(entry, indexKey);
890 if (keyValue.present()) {
891 valueSet.insert(serverSet.valueText(keyValue.get()));
892 }
893 }

Callers 1

testReplicationFunction · 0.85

Calls 15

deterministicRandomFunction · 0.85
printfFunction · 0.85
findFunction · 0.85
random01Method · 0.80
keyIndexMethod · 0.80
getValueViaEntryMethod · 0.80
valueTextMethod · 0.80
clearMethod · 0.65
getMethod · 0.65
randomIntMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected