Improve DDTeamCollection const-correctness

This commit is contained in:
sfc-gh-tclinkenbeard 2021-08-12 18:52:57 -07:00
parent cfe677c100
commit 904deb9516
2 changed files with 66 additions and 67 deletions

View File

@ -684,7 +684,6 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
Future<Void> wrongStoreTypeRemover; Future<Void> wrongStoreTypeRemover;
Reference<LocalitySet> storageServerSet; Reference<LocalitySet> storageServerSet;
std::vector<LocalityEntry> forcedEntries, resultEntries;
std::vector<DDTeamCollection*> teamCollections; std::vector<DDTeamCollection*> teamCollections;
AsyncVar<Optional<Key>> healthyZone; AsyncVar<Optional<Key>> healthyZone;
@ -710,13 +709,13 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
} }
bool satisfiesPolicy(const std::vector<Reference<TCServerInfo>>& team, int amount = -1) { bool satisfiesPolicy(const std::vector<Reference<TCServerInfo>>& team, int amount = -1) const {
forcedEntries.clear(); std::vector<LocalityEntry> forcedEntries, resultEntries;
resultEntries.clear();
if (amount == -1) { if (amount == -1) {
amount = team.size(); amount = team.size();
} }
forcedEntries.reserve(amount);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
forcedEntries.push_back(team[i]->localityEntry); forcedEntries.push_back(team[i]->localityEntry);
} }
@ -1074,7 +1073,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
} }
int64_t getDebugTotalDataInFlight() { int64_t getDebugTotalDataInFlight() const {
int64_t total = 0; int64_t total = 0;
for (auto itr = server_info.begin(); itr != server_info.end(); ++itr) for (auto itr = server_info.begin(); itr != server_info.end(); ++itr)
total += itr->second->dataInFlightToServer; total += itr->second->dataInFlightToServer;
@ -1139,14 +1138,13 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
tempMap->add(it->lastKnownInterface.locality, &it->id); tempMap->add(it->lastKnownInterface.locality, &it->id);
} }
self->resultEntries.clear(); std::vector<LocalityEntry> resultEntries, forcedEntries;
self->forcedEntries.clear();
bool result = tempSet->selectReplicas( bool result = tempSet->selectReplicas(
self->configuration.storagePolicy, self->forcedEntries, self->resultEntries); self->configuration.storagePolicy, forcedEntries, resultEntries);
ASSERT(result && self->resultEntries.size() == self->configuration.storageTeamSize); ASSERT(result && resultEntries.size() == self->configuration.storageTeamSize);
serverIds.clear(); serverIds.clear();
for (auto& it : self->resultEntries) { for (auto& it : resultEntries) {
serverIds.push_back(*tempMap->getObject(it)); serverIds.push_back(*tempMap->getObject(it));
} }
std::sort(serverIds.begin(), serverIds.end()); std::sort(serverIds.begin(), serverIds.end());
@ -1208,7 +1206,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
// Check if server or machine has a valid locality based on configured replication policy // Check if server or machine has a valid locality based on configured replication policy
bool isValidLocality(Reference<IReplicationPolicy> storagePolicy, const LocalityData& locality) { bool isValidLocality(Reference<IReplicationPolicy> storagePolicy, const LocalityData& locality) const {
// Future: Once we add simulation test that misconfigure a cluster, such as not setting some locality entries, // Future: Once we add simulation test that misconfigure a cluster, such as not setting some locality entries,
// DD_VALIDATE_LOCALITY should always be true. Otherwise, simulation test may fail. // DD_VALIDATE_LOCALITY should always be true. Otherwise, simulation test may fail.
if (!SERVER_KNOBS->DD_VALIDATE_LOCALITY) { if (!SERVER_KNOBS->DD_VALIDATE_LOCALITY) {
@ -1226,7 +1224,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return true; return true;
} }
void evaluateTeamQuality() { void evaluateTeamQuality() const {
int teamCount = teams.size(), serverCount = allServers.size(); int teamCount = teams.size(), serverCount = allServers.size();
double teamsPerServer = (double)teamCount * configuration.storageTeamSize / serverCount; double teamsPerServer = (double)teamCount * configuration.storageTeamSize / serverCount;
@ -1303,14 +1301,14 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return maxMatchingServers; return maxMatchingServers;
} }
int overlappingMachineMembers(vector<Standalone<StringRef>>& team) { int overlappingMachineMembers(vector<Standalone<StringRef>> const& team) const {
if (team.empty()) { if (team.empty()) {
return 0; return 0;
} }
int maxMatchingServers = 0; int maxMatchingServers = 0;
Standalone<StringRef>& serverID = team[0]; auto const& serverID = team[0];
for (auto& usedTeam : machine_info[serverID]->machineTeams) { for (auto const& usedTeam : machine_info.at(serverID)->machineTeams) {
auto used = usedTeam->machineIDs; auto used = usedTeam->machineIDs;
int teamIdx = 0; int teamIdx = 0;
int usedIdx = 0; int usedIdx = 0;
@ -1336,13 +1334,13 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return maxMatchingServers; return maxMatchingServers;
} }
Reference<TCMachineTeamInfo> findMachineTeam(vector<Standalone<StringRef>>& machineIDs) { Reference<TCMachineTeamInfo> findMachineTeam(vector<Standalone<StringRef>> const& machineIDs) const {
if (machineIDs.empty()) { if (machineIDs.empty()) {
return Reference<TCMachineTeamInfo>(); return Reference<TCMachineTeamInfo>();
} }
Standalone<StringRef> machineID = machineIDs[0]; Standalone<StringRef> machineID = machineIDs[0];
for (auto& machineTeam : machine_info[machineID]->machineTeams) { for (auto& machineTeam : machine_info.at(machineID)->machineTeams) {
if (machineTeam->machineIDs == machineIDs) { if (machineTeam->machineIDs == machineIDs) {
return machineTeam; return machineTeam;
} }
@ -1476,7 +1474,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return totalServerIndex; return totalServerIndex;
} }
void traceConfigInfo() { void traceConfigInfo() const {
TraceEvent("DDConfig", distributorId) TraceEvent("DDConfig", distributorId)
.detail("StorageTeamSize", configuration.storageTeamSize) .detail("StorageTeamSize", configuration.storageTeamSize)
.detail("DesiredTeamsPerServer", SERVER_KNOBS->DESIRED_TEAMS_PER_SERVER) .detail("DesiredTeamsPerServer", SERVER_KNOBS->DESIRED_TEAMS_PER_SERVER)
@ -1484,7 +1482,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
.detail("StoreType", configuration.storageServerStoreType); .detail("StoreType", configuration.storageServerStoreType);
} }
void traceServerInfo() { void traceServerInfo() const {
int i = 0; int i = 0;
TraceEvent("ServerInfo", distributorId).detail("Size", server_info.size()); TraceEvent("ServerInfo", distributorId).detail("Size", server_info.size());
@ -1502,13 +1500,14 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
TraceEvent("ServerStatus", distributorId) TraceEvent("ServerStatus", distributorId)
.detail("ServerID", uid) .detail("ServerID", uid)
.detail("Healthy", !server_status.get(uid).isUnhealthy()) .detail("Healthy", !server_status.get(uid).isUnhealthy())
.detail("MachineIsValid", server_info[uid]->machine.isValid()) .detail("MachineIsValid", server_info.at(uid)->machine.isValid())
.detail("MachineTeamSize", .detail("MachineTeamSize",
server_info[uid]->machine.isValid() ? server_info[uid]->machine->machineTeams.size() : -1); server_info.at(uid)->machine.isValid() ? server_info.at(uid)->machine->machineTeams.size()
: -1);
} }
} }
void traceServerTeamInfo() { void traceServerTeamInfo() const {
int i = 0; int i = 0;
TraceEvent("ServerTeamInfo", distributorId).detail("Size", teams.size()); TraceEvent("ServerTeamInfo", distributorId).detail("Size", teams.size());
@ -1522,7 +1521,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
} }
void traceMachineInfo() { void traceMachineInfo() const {
int i = 0; int i = 0;
TraceEvent("MachineInfo").detail("Size", machine_info.size()); TraceEvent("MachineInfo").detail("Size", machine_info.size());
@ -1537,7 +1536,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
} }
void traceMachineTeamInfo() { void traceMachineTeamInfo() const {
int i = 0; int i = 0;
TraceEvent("MachineTeamInfo", distributorId).detail("Size", machineTeams.size()); TraceEvent("MachineTeamInfo", distributorId).detail("Size", machineTeams.size());
@ -1551,7 +1550,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
// Locality string is hashed into integer, used as KeyIndex // Locality string is hashed into integer, used as KeyIndex
// For better understand which KeyIndex is used for locality, we print this info in trace. // For better understand which KeyIndex is used for locality, we print this info in trace.
void traceLocalityArrayIndexName() { void traceLocalityArrayIndexName() const {
TraceEvent("LocalityRecordKeyName").detail("Size", machineLocalityMap._keymap->_lookuparray.size()); TraceEvent("LocalityRecordKeyName").detail("Size", machineLocalityMap._keymap->_lookuparray.size());
for (int i = 0; i < machineLocalityMap._keymap->_lookuparray.size(); ++i) { for (int i = 0; i < machineLocalityMap._keymap->_lookuparray.size(); ++i) {
TraceEvent("LocalityRecordKeyIndexName") TraceEvent("LocalityRecordKeyIndexName")
@ -1560,7 +1559,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
} }
void traceMachineLocalityMap() { void traceMachineLocalityMap() const {
int i = 0; int i = 0;
TraceEvent("MachineLocalityMap", distributorId).detail("Size", machineLocalityMap.size()); TraceEvent("MachineLocalityMap", distributorId).detail("Size", machineLocalityMap.size());
@ -1581,7 +1580,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
// To enable verbose debug info, set shouldPrint to true // To enable verbose debug info, set shouldPrint to true
void traceAllInfo(bool shouldPrint = false) { void traceAllInfo(bool shouldPrint = false) const {
if (!shouldPrint) if (!shouldPrint)
return; return;
@ -1786,7 +1785,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return addedMachineTeams; return addedMachineTeams;
} }
bool isMachineTeamHealthy(vector<Standalone<StringRef>> const& machineIDs) { bool isMachineTeamHealthy(vector<Standalone<StringRef>> const& machineIDs) const {
int healthyNum = 0; int healthyNum = 0;
// A healthy machine team should have the desired number of machines // A healthy machine team should have the desired number of machines
@ -1794,7 +1793,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return false; return false;
for (auto& id : machineIDs) { for (auto& id : machineIDs) {
auto& machine = machine_info[id]; auto& machine = machine_info.at(id);
if (isMachineHealthy(machine)) { if (isMachineHealthy(machine)) {
healthyNum++; healthyNum++;
} }
@ -1802,22 +1801,22 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return (healthyNum == machineIDs.size()); return (healthyNum == machineIDs.size());
} }
bool isMachineTeamHealthy(Reference<TCMachineTeamInfo> const& machineTeam) { bool isMachineTeamHealthy(TCMachineTeamInfo const& machineTeam) const {
int healthyNum = 0; int healthyNum = 0;
// A healthy machine team should have the desired number of machines // A healthy machine team should have the desired number of machines
if (machineTeam->size() != configuration.storageTeamSize) if (machineTeam.size() != configuration.storageTeamSize)
return false; return false;
for (auto& machine : machineTeam->machines) { for (auto& machine : machineTeam.machines) {
if (isMachineHealthy(machine)) { if (isMachineHealthy(machine)) {
healthyNum++; healthyNum++;
} }
} }
return (healthyNum == machineTeam->machines.size()); return (healthyNum == machineTeam.machines.size());
} }
bool isMachineHealthy(Reference<TCMachineInfo> const& machine) { bool isMachineHealthy(Reference<TCMachineInfo> const& machine) const {
if (!machine.isValid() || machine_info.find(machine->machineID) == machine_info.end() || if (!machine.isValid() || machine_info.find(machine->machineID) == machine_info.end() ||
machine->serversOnMachine.empty()) { machine->serversOnMachine.empty()) {
return false; return false;
@ -1834,7 +1833,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
// Return the healthy server with the least number of correct-size server teams // Return the healthy server with the least number of correct-size server teams
Reference<TCServerInfo> findOneLeastUsedServer() { Reference<TCServerInfo> findOneLeastUsedServer() const {
vector<Reference<TCServerInfo>> leastUsedServers; vector<Reference<TCServerInfo>> leastUsedServers;
int minTeams = std::numeric_limits<int>::max(); int minTeams = std::numeric_limits<int>::max();
for (auto& server : server_info) { for (auto& server : server_info) {
@ -1867,11 +1866,11 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
// Randomly choose one machine team that has chosenServer and has the correct size // Randomly choose one machine team that has chosenServer and has the correct size
// When configuration is changed, we may have machine teams with old storageTeamSize // When configuration is changed, we may have machine teams with old storageTeamSize
Reference<TCMachineTeamInfo> findOneRandomMachineTeam(Reference<TCServerInfo> chosenServer) { Reference<TCMachineTeamInfo> findOneRandomMachineTeam(TCServerInfo const& chosenServer) const {
if (!chosenServer->machine->machineTeams.empty()) { if (!chosenServer.machine->machineTeams.empty()) {
std::vector<Reference<TCMachineTeamInfo>> healthyMachineTeamsForChosenServer; std::vector<Reference<TCMachineTeamInfo>> healthyMachineTeamsForChosenServer;
for (auto& mt : chosenServer->machine->machineTeams) { for (auto& mt : chosenServer.machine->machineTeams) {
if (isMachineTeamHealthy(mt)) { if (isMachineTeamHealthy(*mt)) {
healthyMachineTeamsForChosenServer.push_back(mt); healthyMachineTeamsForChosenServer.push_back(mt);
} }
} }
@ -1882,16 +1881,16 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
// If we cannot find a healthy machine team // If we cannot find a healthy machine team
TraceEvent("NoHealthyMachineTeamForServer") TraceEvent("NoHealthyMachineTeamForServer")
.detail("ServerID", chosenServer->id) .detail("ServerID", chosenServer.id)
.detail("MachineTeams", chosenServer->machine->machineTeams.size()); .detail("MachineTeams", chosenServer.machine->machineTeams.size());
return Reference<TCMachineTeamInfo>(); return Reference<TCMachineTeamInfo>();
} }
// A server team should always come from servers on a machine team // A server team should always come from servers on a machine team
// Check if it is true // Check if it is true
bool isOnSameMachineTeam(Reference<TCTeamInfo>& team) { bool isOnSameMachineTeam(TCTeamInfo const& team) const {
std::vector<Standalone<StringRef>> machineIDs; std::vector<Standalone<StringRef>> machineIDs;
for (const auto& server : team->getServers()) { for (const auto& server : team.getServers()) {
if (!server->machine.isValid()) if (!server->machine.isValid())
return false; return false;
machineIDs.push_back(server->machine->machineID); machineIDs.push_back(server->machine->machineID);
@ -1899,7 +1898,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
std::sort(machineIDs.begin(), machineIDs.end()); std::sort(machineIDs.begin(), machineIDs.end());
int numExistance = 0; int numExistance = 0;
for (const auto& server : team->getServers()) { for (const auto& server : team.getServers()) {
for (const auto& candidateMachineTeam : server->machine->machineTeams) { for (const auto& candidateMachineTeam : server->machine->machineTeams) {
std::sort(candidateMachineTeam->machineIDs.begin(), candidateMachineTeam->machineIDs.end()); std::sort(candidateMachineTeam->machineIDs.begin(), candidateMachineTeam->machineIDs.end());
if (machineIDs == candidateMachineTeam->machineIDs) { if (machineIDs == candidateMachineTeam->machineIDs) {
@ -1908,14 +1907,14 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
} }
} }
return (numExistance == team->size()); return (numExistance == team.size());
} }
// Sanity check the property of teams in unit test // Sanity check the property of teams in unit test
// Return true if all server teams belong to machine teams // Return true if all server teams belong to machine teams
bool sanityCheckTeams() { bool sanityCheckTeams() const {
for (auto& team : teams) { for (auto& team : teams) {
if (isOnSameMachineTeam(team) == false) { if (isOnSameMachineTeam(*team) == false) {
return false; return false;
} }
} }
@ -1923,7 +1922,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return true; return true;
} }
int calculateHealthyServerCount() { int calculateHealthyServerCount() const {
int serverCount = 0; int serverCount = 0;
for (auto i = server_info.begin(); i != server_info.end(); ++i) { for (auto i = server_info.begin(); i != server_info.end(); ++i) {
if (!server_status.get(i->first).isUnhealthy()) { if (!server_status.get(i->first).isUnhealthy()) {
@ -1933,7 +1932,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return serverCount; return serverCount;
} }
int calculateHealthyMachineCount() { int calculateHealthyMachineCount() const {
int totalHealthyMachineCount = 0; int totalHealthyMachineCount = 0;
for (auto& m : machine_info) { for (auto& m : machine_info) {
if (isMachineHealthy(m.second)) { if (isMachineHealthy(m.second)) {
@ -1944,7 +1943,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return totalHealthyMachineCount; return totalHealthyMachineCount;
} }
std::pair<int64_t, int64_t> calculateMinMaxServerTeamsOnServer() { std::pair<int64_t, int64_t> calculateMinMaxServerTeamsOnServer() const {
int64_t minTeams = std::numeric_limits<int64_t>::max(); int64_t minTeams = std::numeric_limits<int64_t>::max();
int64_t maxTeams = 0; int64_t maxTeams = 0;
for (auto& server : server_info) { for (auto& server : server_info) {
@ -1957,7 +1956,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return std::make_pair(minTeams, maxTeams); return std::make_pair(minTeams, maxTeams);
} }
std::pair<int64_t, int64_t> calculateMinMaxMachineTeamsOnMachine() { std::pair<int64_t, int64_t> calculateMinMaxMachineTeamsOnMachine() const {
int64_t minTeams = std::numeric_limits<int64_t>::max(); int64_t minTeams = std::numeric_limits<int64_t>::max();
int64_t maxTeams = 0; int64_t maxTeams = 0;
for (auto& machine : machine_info) { for (auto& machine : machine_info) {
@ -1971,7 +1970,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
// Sanity check // Sanity check
bool isServerTeamCountCorrect(Reference<TCMachineTeamInfo>& mt) { bool isServerTeamCountCorrect(Reference<TCMachineTeamInfo> const& mt) const {
int num = 0; int num = 0;
bool ret = true; bool ret = true;
for (auto& team : teams) { for (auto& team : teams) {
@ -1990,7 +1989,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
// Find the machine team with the least number of server teams // Find the machine team with the least number of server teams
std::pair<Reference<TCMachineTeamInfo>, int> getMachineTeamWithLeastProcessTeams() { std::pair<Reference<TCMachineTeamInfo>, int> getMachineTeamWithLeastProcessTeams() const {
Reference<TCMachineTeamInfo> retMT; Reference<TCMachineTeamInfo> retMT;
int minNumProcessTeams = std::numeric_limits<int>::max(); int minNumProcessTeams = std::numeric_limits<int>::max();
@ -2009,7 +2008,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
// Find the machine team whose members are on the most number of machine teams, same logic as serverTeamRemover // Find the machine team whose members are on the most number of machine teams, same logic as serverTeamRemover
std::pair<Reference<TCMachineTeamInfo>, int> getMachineTeamWithMostMachineTeams() { std::pair<Reference<TCMachineTeamInfo>, int> getMachineTeamWithMostMachineTeams() const {
Reference<TCMachineTeamInfo> retMT; Reference<TCMachineTeamInfo> retMT;
int maxNumMachineTeams = 0; int maxNumMachineTeams = 0;
int targetMachineTeamNumPerMachine = int targetMachineTeamNumPerMachine =
@ -2033,7 +2032,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
// Find the server team whose members are on the most number of server teams // Find the server team whose members are on the most number of server teams
std::pair<Reference<TCTeamInfo>, int> getServerTeamWithMostProcessTeams() { std::pair<Reference<TCTeamInfo>, int> getServerTeamWithMostProcessTeams() const {
Reference<TCTeamInfo> retST; Reference<TCTeamInfo> retST;
int maxNumProcessTeams = 0; int maxNumProcessTeams = 0;
int targetTeamNumPerServer = (SERVER_KNOBS->DESIRED_TEAMS_PER_SERVER * (configuration.storageTeamSize + 1)) / 2; int targetTeamNumPerServer = (SERVER_KNOBS->DESIRED_TEAMS_PER_SERVER * (configuration.storageTeamSize + 1)) / 2;
@ -2055,10 +2054,10 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return std::pair<Reference<TCTeamInfo>, int>(retST, maxNumProcessTeams); return std::pair<Reference<TCTeamInfo>, int>(retST, maxNumProcessTeams);
} }
int getHealthyMachineTeamCount() { int getHealthyMachineTeamCount() const {
int healthyTeamCount = 0; int healthyTeamCount = 0;
for (auto mt = machineTeams.begin(); mt != machineTeams.end(); ++mt) { for (const auto& mt : machineTeams) {
ASSERT((*mt)->machines.size() == configuration.storageTeamSize); ASSERT(mt->machines.size() == configuration.storageTeamSize);
if (isMachineTeamHealthy(*mt)) { if (isMachineTeamHealthy(*mt)) {
++healthyTeamCount; ++healthyTeamCount;
@ -2070,7 +2069,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
// Each machine is expected to have targetMachineTeamNumPerMachine // Each machine is expected to have targetMachineTeamNumPerMachine
// Return true if there exists a machine that does not have enough teams. // Return true if there exists a machine that does not have enough teams.
bool notEnoughMachineTeamsForAMachine() { bool notEnoughMachineTeamsForAMachine() const {
// If we want to remove the machine team with most machine teams, we use the same logic as // If we want to remove the machine team with most machine teams, we use the same logic as
// notEnoughTeamsForAServer // notEnoughTeamsForAServer
int targetMachineTeamNumPerMachine = int targetMachineTeamNumPerMachine =
@ -2092,7 +2091,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
// Each server is expected to have targetTeamNumPerServer teams. // Each server is expected to have targetTeamNumPerServer teams.
// Return true if there exists a server that does not have enough teams. // Return true if there exists a server that does not have enough teams.
bool notEnoughTeamsForAServer() { bool notEnoughTeamsForAServer() const {
// We build more teams than we finally want so that we can use serverTeamRemover() actor to remove the teams // We build more teams than we finally want so that we can use serverTeamRemover() actor to remove the teams
// whose member belong to too many teams. This allows us to get a more balanced number of teams per server. // whose member belong to too many teams. This allows us to get a more balanced number of teams per server.
// We want to ensure every server has targetTeamNumPerServer teams. // We want to ensure every server has targetTeamNumPerServer teams.
@ -2164,7 +2163,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
// instead of choosing the least used machine team. // instead of choosing the least used machine team.
// The correlation happens, for example, when we add two new machines, we may always choose the machine // The correlation happens, for example, when we add two new machines, we may always choose the machine
// team with these two new machines because they are typically less used. // team with these two new machines because they are typically less used.
Reference<TCMachineTeamInfo> chosenMachineTeam = findOneRandomMachineTeam(chosenServer); Reference<TCMachineTeamInfo> chosenMachineTeam = findOneRandomMachineTeam(*chosenServer);
if (!chosenMachineTeam.isValid()) { if (!chosenMachineTeam.isValid()) {
// We may face the situation that temporarily we have no healthy machine. // We may face the situation that temporarily we have no healthy machine.
@ -2266,7 +2265,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
} }
// Check if the number of server (and machine teams) is larger than the maximum allowed number // Check if the number of server (and machine teams) is larger than the maximum allowed number
void traceTeamCollectionInfo() { void traceTeamCollectionInfo() const {
int totalHealthyServerCount = calculateHealthyServerCount(); int totalHealthyServerCount = calculateHealthyServerCount();
int desiredServerTeams = SERVER_KNOBS->DESIRED_TEAMS_PER_SERVER * totalHealthyServerCount; int desiredServerTeams = SERVER_KNOBS->DESIRED_TEAMS_PER_SERVER * totalHealthyServerCount;
int maxServerTeams = SERVER_KNOBS->MAX_TEAMS_PER_SERVER * totalHealthyServerCount; int maxServerTeams = SERVER_KNOBS->MAX_TEAMS_PER_SERVER * totalHealthyServerCount;
@ -2436,7 +2435,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return Void(); return Void();
} }
void noHealthyTeams() { void noHealthyTeams() const {
std::set<UID> desiredServerSet; std::set<UID> desiredServerSet;
std::string desc; std::string desc;
for (auto i = server_info.begin(); i != server_info.end(); ++i) { for (auto i = server_info.begin(); i != server_info.end(); ++i) {
@ -2453,7 +2452,7 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
.detail("NonFailedServerCount", desiredServerSet.size()); .detail("NonFailedServerCount", desiredServerSet.size());
} }
bool shouldHandleServer(const StorageServerInterface& newServer) { bool shouldHandleServer(const StorageServerInterface& newServer) const {
return (includedDCs.empty() || return (includedDCs.empty() ||
std::find(includedDCs.begin(), includedDCs.end(), newServer.locality.dcId()) != includedDCs.end() || std::find(includedDCs.begin(), includedDCs.end(), newServer.locality.dcId()) != includedDCs.end() ||
(otherTrackedDCs.present() && (otherTrackedDCs.present() &&

View File

@ -547,14 +547,14 @@ public:
} }
} }
void clear(K const& k) { set(k, V()); } void clear(K const& k) { set(k, V()); }
V const& get(K const& k) { V const& get(K const& k) const {
auto it = items.find(k); auto it = items.find(k);
if (it != items.end()) if (it != items.end())
return it->second.value; return it->second.value;
else else
return defaultValue; return defaultValue;
} }
int count(K const& k) { int count(K const& k) const {
auto it = items.find(k); auto it = items.find(k);
if (it != items.end()) if (it != items.end())
return 1; return 1;
@ -566,7 +566,7 @@ public:
return destroyOnCancel(this, k, item.change.getFuture()); return destroyOnCancel(this, k, item.change.getFuture());
return item.change.getFuture(); return item.change.getFuture();
} }
std::vector<K> getKeys() { std::vector<K> getKeys() const {
std::vector<K> keys; std::vector<K> keys;
keys.reserve(items.size()); keys.reserve(items.size());
for (auto i = items.begin(); i != items.end(); ++i) for (auto i = items.begin(); i != items.end(); ++i)