diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-02-25 01:23:58 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-02-25 01:23:58 -0500 |
commit | 4c98640678f0e92ef60a621ec843aa7d296d1060 (patch) | |
tree | eac174e50f81b5d350149d7557cd17b71454c468 /s/cursors.cpp | |
parent | 7b815a4a9801dfd7a6ff6ecbb4163160f8bee8fd (diff) | |
download | mongo-4c98640678f0e92ef60a621ec843aa7d296d1060.tar.gz |
getMore checkpoint
Diffstat (limited to 's/cursors.cpp')
-rw-r--r-- | s/cursors.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/s/cursors.cpp b/s/cursors.cpp index 0bd2487bf28..745501cc444 100644 --- a/s/cursors.cpp +++ b/s/cursors.cpp @@ -16,6 +16,7 @@ namespace mongo { _ntoreturn = q.ntoreturn; _totalSent = 0; + _done = false; if ( q.fields.get() ){ BSONObjBuilder b; @@ -77,7 +78,9 @@ namespace mongo { return s.simplifiedQuery(); } - bool ShardedCursor::sendNextBatch( Request& r ){ + bool ShardedCursor::sendNextBatch( Request& r , int ntoreturn ){ + uassert( "cursor already done" , ! _done ); + int maxSize = 1024 * 1024; if ( _totalSent > 0 ) maxSize *= 3; @@ -87,7 +90,7 @@ namespace mongo { int num = 0; bool sendMore = true; - cout << "TEMP: ShardedCursor " << _ns << "\t" << _query << " ntoreturn: " << _ntoreturn << endl; + cout << "TEMP: ShardedCursor " << _ns << "\t" << _query << " ntoreturn: " << ntoreturn << endl; while ( more() ){ BSONObj o = next(); cout << "\t" << o << endl; @@ -98,12 +101,12 @@ namespace mongo { if ( b.len() > maxSize ) break; - if ( num == _ntoreturn ){ + if ( num == ntoreturn ){ // soft limit aka batch size break; } - if ( ( -1 * num + _totalSent ) == _ntoreturn ){ + if ( ( -1 * num + _totalSent ) == ntoreturn ){ // hard limit - total to send sendMore = false; break; @@ -114,6 +117,7 @@ namespace mongo { log() << " hasMore:" << hasMore << " id:" << _id << endl; replyToQuery( 0 , r.p() , r.m() , b.buf() , b.len() , num , 0 , hasMore ? _id : 0 ); _totalSent += num; + _done = ! hasMore; return hasMore; } @@ -229,4 +233,28 @@ namespace mongo { } + CursorCache::CursorCache(){ + } + + CursorCache::~CursorCache(){ + // TODO: delete old cursors? + } + + ShardedCursor* CursorCache::get( long long id ){ + map<long long,ShardedCursor*>::iterator i = _cursors.find( id ); + if ( i == _cursors.end() ){ + OCCASIONALLY log() << "Sharded CursorCache missing cursor id: " << id << endl; + return 0; + } + return i->second; + } + + void CursorCache::store( ShardedCursor * cursor ){ + _cursors[cursor->getId()] = cursor; + } + void CursorCache::remove( long long id ){ + _cursors.erase( id ); + } + + CursorCache cursorCache; } |