From f0d9a01bccdaeb466c12c92057914bbfef59526c Mon Sep 17 00:00:00 2001 From: Antonin Kral Date: Thu, 15 Dec 2011 09:35:47 +0100 Subject: Imported Upstream version 2.0.2 --- s/commands_public.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 's/commands_public.cpp') diff --git a/s/commands_public.cpp b/s/commands_public.cpp index ef7110c..23dd7fe 100644 --- a/s/commands_public.cpp +++ b/s/commands_public.cpp @@ -432,9 +432,17 @@ namespace mongo { long long total = 0; map shardCounts; + int numTries = 0; + bool hadToBreak = false; ChunkManagerPtr cm = conf->getChunkManagerIfExists( fullns ); - while ( true ) { + while ( numTries < 5 ) { + numTries++; + + // This all should eventually be replaced by new pcursor framework, but for now match query + // retry behavior manually + if( numTries >= 2 ) sleepsecs( numTries - 1 ); + if ( ! cm ) { // probably unsharded now return run( dbName , cmdObj , options , errmsg , result, false ); @@ -444,17 +452,20 @@ namespace mongo { cm->getShardsForQuery( shards , filter ); assert( shards.size() ); - bool hadToBreak = false; + hadToBreak = false; for (set::iterator it=shards.begin(), end=shards.end(); it != end; ++it) { ShardConnection conn(*it, fullns); - if ( conn.setVersion() ) { - total = 0; - shardCounts.clear(); - cm = conf->getChunkManagerIfExists( fullns ); - conn.done(); - hadToBreak = true; - break; + if ( conn.setVersion() ){ + ChunkManagerPtr newCM = conf->getChunkManagerIfExists( fullns ); + if( newCM->getVersion() != cm->getVersion() ){ + cm = newCM; + total = 0; + shardCounts.clear(); + conn.done(); + hadToBreak = true; + break; + } } BSONObj temp; @@ -472,7 +483,7 @@ namespace mongo { // my version is old total = 0; shardCounts.clear(); - cm = conf->getChunkManagerIfExists( fullns , true ); + cm = conf->getChunkManagerIfExists( fullns , true, numTries > 2 ); // Force reload on third attempt hadToBreak = true; break; } @@ -485,6 +496,10 @@ namespace mongo { if ( ! hadToBreak ) break; } + if (hadToBreak) { + errmsg = "Tried 5 times without success to get count for " + fullns + " from all shards"; + return false; + } total = applySkipLimit( total , cmdObj ); result.appendNumber( "n" , total ); -- cgit v1.2.3