summaryrefslogtreecommitdiff
path: root/s/strategy.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-02-25 00:40:38 -0500
committerEliot Horowitz <eliot@10gen.com>2009-02-25 00:40:38 -0500
commitdbbbdf47877886a65c5428f1a9f7578129687076 (patch)
tree5499b353252f8e473cd85e38b9dfcd46cc8efdfc /s/strategy.cpp
parent585c669cbf21caae51496f83fe4c6aa858e500b4 (diff)
downloadmongo-dbbbdf47877886a65c5428f1a9f7578129687076.tar.gz
some limit fixes, getMore checkpoint
Diffstat (limited to 's/strategy.cpp')
-rw-r--r--s/strategy.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/s/strategy.cpp b/s/strategy.cpp
index 068d4933820..c17c86866d2 100644
--- a/s/strategy.cpp
+++ b/s/strategy.cpp
@@ -54,7 +54,11 @@ namespace mongo {
_ns = q.ns;
_query = q.query.copy();
_options = q.queryOptions;
+ _skip = q.ntoskip;
+ _ntoreturn = q.ntoreturn;
+ _totalSent = 0;
+
if ( q.fields.get() ){
BSONObjBuilder b;
for ( set<string>::iterator i=q.fields->begin(); i!=q.fields->end(); i++)
@@ -115,12 +119,17 @@ namespace mongo {
return s.simplifiedQuery();
}
- void ShardedCursor::sendNextBatch( Request& r ){
+ bool ShardedCursor::sendNextBatch( Request& r ){
+ int maxSize = 1024 * 1024;
+ if ( _totalSent > 0 )
+ maxSize *= 3;
+
BufBuilder b(32768);
int num = 0;
+ bool sendMore = true;
- cout << "TEMP: ShardedCursor " << _ns << "\t" << _query << endl;
+ cout << "TEMP: ShardedCursor " << _ns << "\t" << _query << " ntoreturn: " << _ntoreturn << endl;
while ( more() ){
BSONObj o = next();
cout << "\t" << o << endl;
@@ -128,14 +137,25 @@ namespace mongo {
b.append( (void*)o.objdata() , o.objsize() );
num++;
- if ( b.len() > 2097152 ){
- // TEMP
+ if ( b.len() > maxSize )
+ break;
+
+ if ( num == _ntoreturn ){
+ // soft limit aka batch size
break;
}
+ if ( ( -1 * num + _totalSent ) == _ntoreturn ){
+ // hard limit - total to send
+ sendMore = false;
+ break;
+ }
}
- uassert( "can't handle getMore with sharding yet" , ! more() );
- replyToQuery( 0 , r.p() , r.m() , b.buf() , b.len() , num );
+ bool hasMore = sendMore && more();
+ log() << " hasMore:" << hasMore << " id:" << _id << endl;
+ replyToQuery( 0 , r.p() , r.m() , b.buf() , b.len() , num , 0 , hasMore ? _id : 0 );
+ _totalSent += num;
+ return hasMore;
}
}