exclude to-be-dropped server from the random team

This commit is contained in:
He Liu 2021-09-15 09:07:50 -07:00
parent e838d63011
commit c8a3413820
2 changed files with 27 additions and 20 deletions

View File

@ -357,6 +357,10 @@ public:
void addref() override { ReferenceCounted<TCTeamInfo>::addref(); }
void delref() override { ReferenceCounted<TCTeamInfo>::delref(); }
bool hasServer(const UID& server) {
return std::find(serverIDs.begin(), serverIDs.end(), server) != serverIDs.end();
}
void addServers(const vector<UID>& servers) override {
serverIDs.reserve(servers.size());
for (int i = 0; i < servers.size(); i++) {
@ -893,11 +897,11 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
return Void();
}
std::vector<UID> getRandomHealthyTeam() {
std::vector<UID> getRandomHealthyTeam(const UID& excludeServer) {
int count = 0;
Optional<int> idx;
for (int i = 0; i < teams.size(); ++i) {
if (teams[i]->isHealthy()) {
if (teams[i]->isHealthy() && !teams[i]->hasServer(excludeServer)) {
if (std::rand() % ++count == 0) {
idx = i;
}
@ -6139,11 +6143,14 @@ ACTOR Future<Void> dataDistribution(Reference<DataDistributorData> self,
state Error err = e;
TraceEvent("DataDistributorDestroyTeamCollections").error(e);
state std::vector<UID> teamForDroppedRange;
std::vector<UID> pTeam = primaryTeamCollection->getRandomHealthyTeam();
teamForDroppedRange.insert(teamForDroppedRange.end(), pTeam.begin(), pTeam.end());
if (configuration.usableRegions > 1) {
std::vector<UID> rTeam = remoteTeamCollection->getRandomHealthyTeam();
teamForDroppedRange.insert(teamForDroppedRange.end(), rTeam.begin(), rTeam.end());
if (removeFailedServer.getFuture().isReady() && !removeFailedServer.getFuture().isError()) {
const UID serverID = removeFailedServer.getFuture().get();
std::vector<UID> pTeam = primaryTeamCollection->getRandomHealthyTeam(serverID);
teamForDroppedRange.insert(teamForDroppedRange.end(), pTeam.begin(), pTeam.end());
if (configuration.usableRegions > 1) {
std::vector<UID> rTeam = remoteTeamCollection->getRandomHealthyTeam(serverID);
teamForDroppedRange.insert(teamForDroppedRange.end(), rTeam.begin(), rTeam.end());
}
}
self->teamCollection = nullptr;
primaryTeamCollection = Reference<DDTeamCollection>();

View File

@ -1334,19 +1334,19 @@ ACTOR Future<Void> removeKeysFromFailedServer(Database cx,
SERVER_KNOBS->MOVE_KEYS_KRM_LIMIT,
SERVER_KNOBS->MOVE_KEYS_KRM_LIMIT_BYTES));
teamForDroppedRange.clear();
for (int i = 0; i < keyServers.size() && teamForDroppedRange.empty(); ++i) {
decodeKeyServersValue(UIDtoTagMap, keyServers[i].value, src, dest);
if (std::find(dest.begin(), dest.end(), serverID) == dest.end()) {
teamForDroppedRange.insert(teamForDroppedRange.end(), dest.begin(), dest.end());
}
if (!teamForDroppedRange.empty()) {
break;
}
if (std::find(src.begin(), src.end(), serverID) == src.end()) {
teamForDroppedRange.insert(teamForDroppedRange.end(), src.begin(), src.end());
}
}
// teamForDroppedRange.clear();
// for (int i = 0; i < keyServers.size() && teamForDroppedRange.empty(); ++i) {
// decodeKeyServersValue(UIDtoTagMap, keyServers[i].value, src, dest);
// if (std::find(dest.begin(), dest.end(), serverID) == dest.end()) {
// teamForDroppedRange.insert(teamForDroppedRange.end(), dest.begin(), dest.end());
// }
// if (!teamForDroppedRange.empty()) {
// break;
// }
// if (std::find(src.begin(), src.end(), serverID) == src.end()) {
// teamForDroppedRange.insert(teamForDroppedRange.end(), src.begin(), src.end());
// }
// }
state KeyRange currentKeys = KeyRangeRef(begin, keyServers.end()[-1].key);
state int i = 0;