Improve DataDistribution const-correctness

This commit is contained in:
sfc-gh-tclinkenbeard 2020-12-26 19:37:54 -04:00
parent 26a4884eef
commit 19816ccdbf
3 changed files with 19 additions and 18 deletions

View File

@ -108,15 +108,15 @@ struct TCMachineInfo : public ReferenceCounted<TCMachineInfo> {
machineID = locality.zoneId().get();
}
std::string getServersIDStr() {
std::string getServersIDStr() const {
std::stringstream ss;
if (serversOnMachine.empty()) return "[unset]";
for (auto& server : serversOnMachine) {
for (const auto& server : serversOnMachine) {
ss << server->id.toString() << " ";
}
return ss.str();
return std::move(ss).str();
}
};
@ -144,16 +144,16 @@ public:
return machineIDs.size();
}
std::string getMachineIDsStr() {
std::string getMachineIDsStr() const {
std::stringstream ss;
if (machineIDs.empty()) return "[unset]";
for (auto& id : machineIDs) {
for (const auto& id : machineIDs) {
ss << id.contents().toString() << " ";
}
return ss.str();
return std::move(ss).str();
}
bool operator==(TCMachineTeamInfo& rhs) const { return this->machineIDs == rhs.machineIDs; }
@ -199,18 +199,18 @@ public:
return servers.size();
}
vector<UID> const& getServerIDs() const override { return serverIDs; }
const vector<Reference<TCServerInfo>>& getServers() { return servers; }
const vector<Reference<TCServerInfo>>& getServers() const { return servers; }
std::string getServerIDsStr() const {
std::stringstream ss;
if (serverIDs.empty()) return "[unset]";
for (auto& id : serverIDs) {
for (const auto& id : serverIDs) {
ss << id.toString() << " ";
}
return ss.str();
return std::move(ss).str();
}
void addDataInFlightToTeam(int64_t delta) override {

View File

@ -85,8 +85,8 @@ struct GetTeamRequest {
GetTeamRequest() {}
GetTeamRequest( bool wantsNewServers, bool wantsTrueBest, bool preferLowerUtilization, bool teamMustHaveShards, double inflightPenalty = 1.0 )
: wantsNewServers( wantsNewServers ), wantsTrueBest( wantsTrueBest ), preferLowerUtilization( preferLowerUtilization ), teamMustHaveShards( teamMustHaveShards ), inflightPenalty( inflightPenalty ) {}
std::string getDesc() {
std::string getDesc() const {
std::stringstream ss;
ss << "WantsNewServers:" << wantsNewServers << " WantsTrueBest:" << wantsTrueBest
@ -94,11 +94,11 @@ struct GetTeamRequest {
<< " teamMustHaveShards:" << teamMustHaveShards
<< " inflightPenalty:" << inflightPenalty << ";";
ss << "CompleteSources:";
for (auto& cs : completeSources) {
for (const auto& cs : completeSources) {
ss << cs.toString() << ",";
}
return ss.str();
return std::move(ss).str();
}
};
@ -162,9 +162,9 @@ public:
// no longer in the map), the servers will be set for all contained shards and added to all
// intersecting shards.
int getNumberOfShards( UID ssID );
int getNumberOfShards(UID ssID) const;
vector<KeyRange> getShardsFor( Team team );
bool hasShards(Team team);
bool hasShards(Team team) const;
//The first element of the pair is either the source for non-moving shards or the destination team for in-flight shards
//The second element of the pair is all previous sources for in-flight shards

View File

@ -944,13 +944,14 @@ vector<KeyRange> ShardsAffectedByTeamFailure::getShardsFor( Team team ) {
return r;
}
bool ShardsAffectedByTeamFailure::hasShards(Team team) {
bool ShardsAffectedByTeamFailure::hasShards(Team team) const {
auto it = team_shards.lower_bound(std::pair<Team, KeyRange>(team, KeyRangeRef()));
return it != team_shards.end() && it->first == team;
}
int ShardsAffectedByTeamFailure::getNumberOfShards( UID ssID ) {
return storageServerShards[ssID];
int ShardsAffectedByTeamFailure::getNumberOfShards(UID ssID) const {
auto it = storageServerShards.find(ssID);
return it == storageServerShards.end() ? 0 : it->second;
}
std::pair<vector<ShardsAffectedByTeamFailure::Team>,vector<ShardsAffectedByTeamFailure::Team>> ShardsAffectedByTeamFailure::getTeamsFor( KeyRangeRef keys ) {