Populates version vector (with randomly generated tag localities, ids, and commit versions) based on the given specifications. @param vv Version vector @param tagCount total number of storage servers in the cluster @param localityCount total number of localities/regions in the cluster @param maxTagId maximum value of any tag id in the cluster @param maxCommitVersionDelta maximum difference between
| 101 | // @note assumes each locality contains the same number of tags |
| 102 | // @note picks locality values randomly from range [tagLocalityInvalid+1, INT8_MAX) |
| 103 | void populateVersionVector(VersionVector& vv, |
| 104 | int tagCount, |
| 105 | int localityCount, |
| 106 | int maxTagId, |
| 107 | const uint64_t maxCommitVersionDelta) { |
| 108 | std::vector<uint16_t> ids; |
| 109 | std::vector<int8_t> localities; |
| 110 | Version minVersion; |
| 111 | std::vector<Version> versions; |
| 112 | int tagsPerLocality = tagCount / localityCount; |
| 113 | |
| 114 | // Populate localities. |
| 115 | for (int i = 0; localities.size() < (size_t)localityCount; i++) { |
| 116 | int8_t locality = deterministicRandom()->randomInt(tagLocalityInvalid + 1, INT8_MAX); |
| 117 | if (std::find(localities.begin(), localities.end(), locality) == localities.end()) { |
| 118 | localities.push_back(locality); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Populate ids. |
| 123 | for (int i = 0; i < tagCount; i++) { |
| 124 | // Some of the ids could be duplicates, that's fine. |
| 125 | ids.push_back(deterministicRandom()->randomInt(0, maxTagId)); |
| 126 | } |
| 127 | |
| 128 | // Choose a value for minVersion. (Choose a value in such a way that |
| 129 | // "minVersion + maxCommitVersionDelta" does not exceed INT64_MAX.) |
| 130 | if (maxCommitVersionDelta <= UINT16_MAX) { |
| 131 | minVersion = deterministicRandom()->randomUInt32(); |
| 132 | } else if (maxCommitVersionDelta <= UINT32_MAX) { |
| 133 | minVersion = deterministicRandom()->randomInt(0, UINT16_MAX); |
| 134 | } else { |
| 135 | minVersion = 0; |
| 136 | } |
| 137 | |
| 138 | // Populate versions. |
| 139 | Version versionDelta; |
| 140 | for (int i = 0; i < tagCount; i++) { |
| 141 | if (maxCommitVersionDelta <= UINT8_MAX) { |
| 142 | versionDelta = deterministicRandom()->randomInt(0, UINT8_MAX); |
| 143 | } else if (maxCommitVersionDelta <= UINT16_MAX) { |
| 144 | versionDelta = deterministicRandom()->randomInt(0, UINT16_MAX); |
| 145 | } else if (maxCommitVersionDelta <= UINT32_MAX) { |
| 146 | versionDelta = deterministicRandom()->randomUInt32(); |
| 147 | } else { |
| 148 | versionDelta = deterministicRandom()->randomInt64(0, INT64_MAX); |
| 149 | } |
| 150 | // Some of the versions could be duplicates, that's fine. |
| 151 | versions.push_back(minVersion + versionDelta); |
| 152 | } |
| 153 | |
| 154 | // Sort versions. |
| 155 | std::sort(versions.begin(), versions.end()); |
| 156 | |
| 157 | // Populate the version vector. |
| 158 | std::set<Tag> tags; |
| 159 | int tagIndex = 0; |
| 160 | for (int i = 0; i < localities.size() && tagIndex < tagCount; i++) { |
no test coverage detected