fix: completeSources could be larger than the teamSize, so we need to check all completeSources

we do not need to track bestSize, since all teams in the list will be the same size
This commit is contained in:
Evan Tschannen 2020-01-10 14:46:40 -08:00
parent 02a8e8d1e9
commit c2608f0af9
1 changed files with 30 additions and 37 deletions

View File

@ -761,32 +761,26 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
completeSources.insert( req.completeSources[i] );
}
if( !req.wantsNewServers ) {
int bestSize = 0;
for( int i = 0; i < req.completeSources.size(); i++ ) {
if( self->server_info.count( req.completeSources[i] ) ) {
auto& teamList = self->server_info[ req.completeSources[i] ]->teams;
for( int j = 0; j < teamList.size(); j++ ) {
bool found = true;
auto serverIDs = teamList[j]->getServerIDs();
for( int k = 0; k < teamList[j]->size(); k++ ) {
if( !completeSources.count( serverIDs[k] ) ) {
found = false;
break;
}
}
if(found && teamList[j]->isHealthy() && teamList[j]->size() > bestSize) {
bestOption = teamList[j];
bestSize = teamList[j]->size();
if( !self->server_info.count( req.completeSources[i] ) ) {
continue;
}
auto& teamList = self->server_info[ req.completeSources[i] ]->teams;
for( int j = 0; j < teamList.size(); j++ ) {
bool found = true;
auto serverIDs = teamList[j]->getServerIDs();
for( int k = 0; k < teamList[j]->size(); k++ ) {
if( !completeSources.count( serverIDs[k] ) ) {
found = false;
break;
}
}
break;
if(found && teamList[j]->isHealthy()) {
req.reply.send( teamList[j] );
return Void();
}
}
}
if(bestOption.present()) {
req.reply.send( bestOption );
return Void();
}
}
if( req.wantsTrueBest ) {
@ -833,25 +827,24 @@ struct DDTeamCollection : ReferenceCounted<DDTeamCollection> {
// We will get stuck at this! This only happens when a DC fails. No need to consider it right now.
if(!bestOption.present() && self->zeroHealthyTeams->get()) {
//Attempt to find the unhealthy source server team and return it
int bestSize = 0;
for( int i = 0; i < req.completeSources.size(); i++ ) {
if( self->server_info.count( req.completeSources[i] ) ) {
auto& teamList = self->server_info[ req.completeSources[i] ]->teams;
for( int j = 0; j < teamList.size(); j++ ) {
bool found = true;
auto serverIDs = teamList[j]->getServerIDs();
for( int k = 0; k < teamList[j]->size(); k++ ) {
if( !completeSources.count( serverIDs[k] ) ) {
found = false;
break;
}
}
if(found && teamList[j]->size() > bestSize) {
bestOption = teamList[j];
bestSize = teamList[j]->size();
if( !self->server_info.count( req.completeSources[i] ) ) {
continue;
}
auto& teamList = self->server_info[ req.completeSources[i] ]->teams;
for( int j = 0; j < teamList.size(); j++ ) {
bool found = true;
auto serverIDs = teamList[j]->getServerIDs();
for( int k = 0; k < teamList[j]->size(); k++ ) {
if( !completeSources.count( serverIDs[k] ) ) {
found = false;
break;
}
}
break;
if(found) {
req.reply.send( teamList[j] );
return Void();
}
}
}
}