From c2608f0af9ab26190c1357da0dbc3ade7a18968e Mon Sep 17 00:00:00 2001 From: Evan Tschannen Date: Fri, 10 Jan 2020 14:46:40 -0800 Subject: [PATCH] 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 --- fdbserver/DataDistribution.actor.cpp | 67 +++++++++++++--------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/fdbserver/DataDistribution.actor.cpp b/fdbserver/DataDistribution.actor.cpp index 0734ee2ecc..e37c417e33 100644 --- a/fdbserver/DataDistribution.actor.cpp +++ b/fdbserver/DataDistribution.actor.cpp @@ -761,32 +761,26 @@ struct DDTeamCollection : ReferenceCounted { 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 { // 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(); + } } } }