Permalink
Browse files

SERVER-4680 sendNextBatch logic isn't correct with nonzero batch size

  • Loading branch information...
1 parent 6477fd1 commit e50b2e242875405f2b52d8757139961243b21b78 Greg Studer committed Apr 20, 2012
Showing with 9 additions and 11 deletions.
  1. +7 −9 s/cursors.cpp
  2. +2 −2 s/strategy_shard.cpp
View
@@ -82,7 +82,10 @@ namespace mongo {
BufBuilder b(32768);
int num = 0;
- bool sendMore = true;
+
+ // Send more if ntoreturn is 0, or any value > 1 (one is assumed to be a single doc return, with no cursor)
+ bool sendMore = ntoreturn == 0 || ntoreturn > 1;
+ ntoreturn = abs( ntoreturn );
while ( _cursor->more() ) {
BSONObj o = _cursor->next();
@@ -99,20 +102,15 @@ namespace mongo {
break;
}
- if ( ntoreturn != 0 && ( -1 * num + _totalSent ) == ntoreturn ) {
- // hard limit - total to send
- sendMore = false;
- break;
- }
-
- if ( ntoreturn == 0 && _totalSent == 0 && num > 100 ) {
+ if ( ntoreturn == 0 && _totalSent == 0 && num >= 100 ) {
// first batch should be max 100 unless batch size specified
break;
}
}
bool hasMore = sendMore && _cursor->more();
- LOG(6) << "\t hasMore:" << hasMore << " wouldSendMoreIfHad: " << sendMore << " id:" << getId() << " totalSent: " << _totalSent << endl;
+ LOG(5) << "\t hasMore: " << hasMore << " sendMore: " << sendMore << " cursorMore: " << _cursor->more() << " ntoreturn: " << ntoreturn
+ << " num: " << num << " wouldSendMoreIfHad: " << sendMore << " id:" << getId() << " totalSent: " << _totalSent << endl;
replyToQuery( 0 , r.p() , r.m() , b.buf() , b.len() , num , _totalSent , hasMore ? getId() : 0 );
_totalSent += num;
@@ -91,10 +91,10 @@ namespace mongo {
}
ShardedClientCursorPtr cc (new ShardedClientCursor( q , cursor ));
- if ( ! cc->sendNextBatch( r ) ) {
+ if ( ! cc->sendNextBatch( r, q.ntoreturn ) ) {
return;
}
- LOG(6) << "storing cursor : " << cc->getId() << endl;
+ LOG(5) << "storing cursor : " << cc->getId() << endl;
cursorCache.store( cc );
}

0 comments on commit e50b2e2

Please sign in to comment.