From 1519ef321f72b59dc8b586f049e7238728727e91 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/s/commands_public.cpp b/s/commands_public.cpp index f29205b2326..44c910b136c 100644 --- a/s/commands_public.cpp +++ b/s/commands_public.cpp @@ -375,9 +375,13 @@ namespace mongo { long long total = 0; map shardCounts; + int numTries = 0; + bool hadToBreak = false; ChunkManagerPtr cm = conf->getChunkManager( fullns ); - while ( true ) { + while ( numTries < 5 ) { + numTries++; + if ( ! cm ) { // probably unsharded now return run( dbName , cmdObj , errmsg , result , l ); @@ -387,7 +391,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); @@ -428,6 +432,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