summaryrefslogtreecommitdiff
path: root/s
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:01:45 -0500
commit340048ba58d661f386bd80fa0685651a31e70b13 (patch)
tree66414da7e70a19c119fc4cb7a6b1b6ae0122c1fb /s
parente5cd12cde3104326e9572880a0a4fbaded04d612 (diff)
downloadmongo-340048ba58d661f386bd80fa0685651a31e70b13.tar.gz
Make count command on mongos error after 5 failed attempts, instead of retrying indefinitely. SERVER-4196
Diffstat (limited to 's')
-rw-r--r--s/commands_public.cpp14
1 files 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<string,long long> 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<Shard>::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 );