summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2012-06-27 15:36:11 -0400
committerTad Marshall <tad@10gen.com>2012-06-27 15:36:51 -0400
commit12de29a40185e24c1bfb2c5d838903c15e8b2a85 (patch)
tree890f74800bc94f99b0af74aa2f77951489e45720
parentdd36d37c09408cd0fac5c40b48c071afd7491b1e (diff)
downloadmongo-12de29a40185e24c1bfb2c5d838903c15e8b2a85.tar.gz
SERVER-4800 make unsorted parallel cursors do round-robin when pulling data, minimize timeouts
Signed-off-by: Tad Marshall <tad@10gen.com>
-rw-r--r--client/parallel.cpp11
-rw-r--r--client/parallel.h1
2 files changed, 11 insertions, 1 deletions
diff --git a/client/parallel.cpp b/client/parallel.cpp
index d7975a6849b..df2f3fcfc5b 100644
--- a/client/parallel.cpp
+++ b/client/parallel.cpp
@@ -365,6 +365,7 @@ namespace mongo {
void ParallelSortClusteredCursor::_finishCons() {
_numServers = _servers.size();
+ _lastFrom = 0;
_cursors = 0;
if ( ! _sortKey.isEmpty() && ! _fields.isEmpty() ) {
@@ -693,7 +694,13 @@ namespace mongo {
BSONObj best = BSONObj();
int bestFrom = -1;
- for ( int i=0; i<_numServers; i++) {
+ for( int j = 0; j < _numServers; j++ ){
+
+ // Iterate _numServers times, starting one past the last server we used.
+ // This means we actually start at server #1, not #0, but shouldn't matter
+
+ int i = ( j + _lastFrom + 1 ) % _numServers;
+
if ( ! _cursors[i].more() )
continue;
@@ -714,6 +721,8 @@ namespace mongo {
bestFrom = i;
}
+ _lastFrom = bestFrom;
+
uassert( 10019 , "no more elements" , ! best.isEmpty() );
_cursors[bestFrom].next();
diff --git a/client/parallel.h b/client/parallel.h
index 869bff95a4a..cbf64826596 100644
--- a/client/parallel.h
+++ b/client/parallel.h
@@ -241,6 +241,7 @@ namespace mongo {
virtual void _explain( map< string,list<BSONObj> >& out );
int _numServers;
+ int _lastFrom;
set<ServerAndQuery> _servers;
BSONObj _sortKey;