summaryrefslogtreecommitdiff
path: root/s/commands_public.cpp
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2011-12-15 10:02:19 +0100
committerAntonin Kral <a.kral@bobek.cz>2011-12-15 10:02:46 +0100
commit0b48f8ada2acb0de830b23f8cefc8e3fea28d915 (patch)
treef7c2811269b6b53199412be2dd5ec02eea15d55d /s/commands_public.cpp
parent85f1cd56145b90a32b7ccdc750000deeed54fe22 (diff)
parentf0d9a01bccdaeb466c12c92057914bbfef59526c (diff)
downloadmongodb-0b48f8ada2acb0de830b23f8cefc8e3fea28d915.tar.gz
Merge branch 'upstream/2.0.2'
Diffstat (limited to 's/commands_public.cpp')
-rw-r--r--s/commands_public.cpp35
1 files changed, 25 insertions, 10 deletions
diff --git a/s/commands_public.cpp b/s/commands_public.cpp
index ef7110c..23dd7fe 100644
--- a/s/commands_public.cpp
+++ b/s/commands_public.cpp
@@ -432,9 +432,17 @@ 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++;
+
+ // This all should eventually be replaced by new pcursor framework, but for now match query
+ // retry behavior manually
+ if( numTries >= 2 ) sleepsecs( numTries - 1 );
+
if ( ! cm ) {
// probably unsharded now
return run( dbName , cmdObj , options , errmsg , result, false );
@@ -444,17 +452,20 @@ 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);
- if ( conn.setVersion() ) {
- total = 0;
- shardCounts.clear();
- cm = conf->getChunkManagerIfExists( fullns );
- conn.done();
- hadToBreak = true;
- break;
+ if ( conn.setVersion() ){
+ ChunkManagerPtr newCM = conf->getChunkManagerIfExists( fullns );
+ if( newCM->getVersion() != cm->getVersion() ){
+ cm = newCM;
+ total = 0;
+ shardCounts.clear();
+ conn.done();
+ hadToBreak = true;
+ break;
+ }
}
BSONObj temp;
@@ -472,7 +483,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 +496,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 );