Permalink
Browse files

Make count command on mongos error after 5 failed attempts, instead o…

…f retrying indefinitely. SERVER-4196
  • Loading branch information...
1 parent 1e894da commit 1519ef321f72b59dc8b586f049e7238728727e91 @stbrody stbrody committed Nov 4, 2011
Showing with 10 additions and 2 deletions.
  1. +10 −2 s/commands_public.cpp
View
12 s/commands_public.cpp
@@ -375,9 +375,13 @@ namespace mongo {
long long total = 0;
map<string,long long> 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<Shard>::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 );

0 comments on commit 1519ef3

Please sign in to comment.