summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@10gen.com>2011-11-04 13:32:17 -0400
committerSpencer T Brody <spencer@10gen.com>2011-11-11 12:14:25 -0500
commit1519ef321f72b59dc8b586f049e7238728727e91 (patch)
tree490ded5816189f8727089c9db47f6bcee1a68e0d
parent1e894dad0db4d954e636350c5547f6e44c973725 (diff)
downloadmongo-1519ef321f72b59dc8b586f049e7238728727e91.tar.gz
Make count command on mongos error after 5 failed attempts, instead of retrying indefinitely. SERVER-4196
-rw-r--r--s/commands_public.cpp12
1 files 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<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 );