From 340048ba58d661f386bd80fa0685651a31e70b13 Mon Sep 17 00:00:00 2001 From: Spencer T Brody Date: Fri, 4 Nov 2011 13:32:17 -0400 Subject: Make count command on mongos error after 5 failed attempts, instead of retrying indefinitely. SERVER-4196 --- s/commands_public.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/s/commands_public.cpp b/s/commands_public.cpp index ef7110c7646..b7feedcf058 100644 --- a/s/commands_public.cpp +++ b/s/commands_public.cpp @@ -432,9 +432,13 @@ 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++; + if ( ! cm ) { // probably unsharded now return run( dbName , cmdObj , options , errmsg , result, false ); @@ -444,7 +448,7 @@ 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); @@ -472,7 +476,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 +489,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.1