From 1ba0144d4f92ed2a4f97d89ad343668c36373bde Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Fri, 15 Jan 2010 01:27:01 -0500 Subject: [PATCH] when scanning serially, if a chunk had no results, stopped prematurely SHARDING-71 --- client/parallel.cpp | 10 ++++++++-- client/parallel.h | 8 ++++++++ jstests/sharding/shard2.js | 11 ++++++++++- s/cursors.cpp | 3 ++- s/strategy_shard.cpp | 4 +++- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/client/parallel.cpp b/client/parallel.cpp index 418f99a7820..449f436550e 100644 --- a/client/parallel.cpp +++ b/client/parallel.cpp @@ -98,12 +98,18 @@ namespace mongo { if ( _current.get() && _current->more() ) return true; - if ( _serverIndex >= _servers.size() ) + if ( _serverIndex >= _servers.size() ){ return false; + } ServerAndQuery& sq = _servers[_serverIndex++]; + _current = query( sq._server , 0 , sq._extra ); - return _current->more(); + if ( _current->more() ) + return true; + + // this sq has nothing, so keep looking + return more(); } BSONObj SerialServerClusteredCursor::next(){ diff --git a/client/parallel.h b/client/parallel.h index 46660d4264c..5a22624e640 100644 --- a/client/parallel.h +++ b/client/parallel.h @@ -40,6 +40,8 @@ namespace mongo { static BSONObj concatQuery( const BSONObj& query , const BSONObj& extraFilter ); + virtual string type() const = 0; + protected: auto_ptr query( const string& server , int num = 0 , BSONObj extraFilter = BSONObj() ); @@ -80,6 +82,10 @@ namespace mongo { return ss.str(); } + operator string() const { + return toString(); + } + string _server; BSONObj _extra; BSONObj _orderObject; @@ -95,6 +101,7 @@ namespace mongo { SerialServerClusteredCursor( set servers , QueryMessage& q , int sortOrder=0); virtual bool more(); virtual BSONObj next(); + virtual string type() const { return "SerialServer"; } private: vector _servers; unsigned _serverIndex; @@ -115,6 +122,7 @@ namespace mongo { virtual ~ParallelSortClusteredCursor(); virtual bool more(); virtual BSONObj next(); + virtual string type() const { return "ParallelSort"; } private: void _init(); diff --git a/jstests/sharding/shard2.js b/jstests/sharding/shard2.js index 3a32d226ffd..566a0dbcc74 100644 --- a/jstests/sharding/shard2.js +++ b/jstests/sharding/shard2.js @@ -8,7 +8,7 @@ placeCheck = function( num ){ print("shard2 step: " + num ); } -s = new ShardingTest( "shard2" , 2 , 5 ); +s = new ShardingTest( "shard2" , 2 , 6 ); db = s.getDB( "test" ); @@ -142,6 +142,15 @@ function countCursor( c ){ assert.eq( 6 , countCursor( db.foo.find()._exec() ) , "getMore 2" ); assert.eq( 6 , countCursor( db.foo.find().limit(1)._exec() ) , "getMore 3" ); +// find by non-shard-key +db.foo.find().forEach( + function(z){ + var y = db.foo.findOne( { _id : z._id } ); + assert( y , "_id check 1 : " + tojson( z ) ); + assert.eq( z.num , y.num , "_id check 2 : " + tojson( z ) ); + } +); + // update person = db.foo.findOne( { num : 3 } ); assert.eq( "bob" , person.name , "update setup 1" ); diff --git a/s/cursors.cpp b/s/cursors.cpp index 3354b96b8e4..23b8eaf695a 100644 --- a/s/cursors.cpp +++ b/s/cursors.cpp @@ -50,8 +50,9 @@ namespace mongo { b.append( (void*)o.objdata() , o.objsize() ); num++; - if ( b.len() > maxSize ) + if ( b.len() > maxSize ){ break; + } if ( num == ntoreturn ){ // soft limit aka batch size diff --git a/s/strategy_shard.cpp b/s/strategy_shard.cpp index dd52d6f8304..e38eeb84f9e 100644 --- a/s/strategy_shard.cpp +++ b/s/strategy_shard.cpp @@ -37,7 +37,7 @@ namespace mongo { num++; } - if ( logLevel > 3 ){ + if ( logLevel > 4 ){ StringBuilder ss; ss << " shard query servers: " << servers.size() << "\n"; for ( set::iterator i = servers.begin(); i!=servers.end(); i++ ){ @@ -74,6 +74,8 @@ namespace mongo { assert( cursor ); + log(5) << " cursor type: " << cursor->type() << endl; + ShardedClientCursor * cc = new ShardedClientCursor( q , cursor ); if ( ! cc->sendNextBatch( r ) ){ delete( cursor );