@@ -311,7 +311,7 @@ namespace mongo {
311311 // This is a read lock. TODO: There is a cursor flag for not needing this. Do we care?
312312 Client::ReadContext ctx (ns);
313313
314- // cout << "running getMore in new system, cursorid " << cursorid << endl;
314+ QLOG () << " running getMore in new system, cursorid " << cursorid << endl;
315315
316316 // This checks to make sure the operation is allowed on a replicated node. Since we are not
317317 // passing in a query object (necessary to check SlaveOK query option), the only state where
@@ -413,6 +413,15 @@ namespace mongo {
413413 if (Runner::RUNNER_DEAD == state || Runner::RUNNER_ERROR == state) {
414414 // If we're dead there's no way to get more results.
415415 saveClientCursor = false ;
416+ // In the old system tailable capped cursors would be killed off at the
417+ // cursorid level. If a tailable capped cursor is nuked the cursorid
418+ // would vanish.
419+ //
420+ // In the new system they die and are cleaned up later (or time out).
421+ // So this is where we get to remove the cursorid.
422+ if (0 == numResults) {
423+ resultFlags = ResultFlag_CursorNotFound;
424+ }
416425 }
417426 else if (Runner::RUNNER_EOF == state) {
418427 // EOF is also end of the line unless it's tailable.
@@ -428,11 +437,17 @@ namespace mongo {
428437 // cc is now invalid, as is the runner
429438 cursorid = 0 ;
430439 cc = NULL ;
440+ QLOG () << " getMore NOT saving client cursor, ended w/state "
441+ << Runner::statestr (state)
442+ << endl;
431443 }
432444 else {
433445 // Continue caching the ClientCursor.
434446 cc->incPos (numResults);
435447 runner->saveState ();
448+ QLOG () << " getMore saving client cursor ended w/state "
449+ << Runner::statestr (state)
450+ << endl;
436451
437452 // Possibly note slave's position in the oplog.
438453 if ((queryOptions & QueryOption_OplogReplay) && !slaveReadTill.isNull ()) {
@@ -455,7 +470,7 @@ namespace mongo {
455470 qr->startingFrom = startingResult;
456471 qr->nReturned = numResults;
457472 bb.decouple ();
458- // cout << "getMore returned " << numResults << " results\n";
473+ QLOG () << " getMore returned " << numResults << " results\n " ;
459474 return qr;
460475 }
461476
@@ -749,8 +764,8 @@ namespace mongo {
749764 cq->getParsed ().getFilter ());
750765 ccId = cc->cursorid ();
751766
752- // cout << "caching runner with cursorid " << ccId
753- // << " after returning " << numResults << " results" << endl;
767+ QLOG () << " caching runner with cursorid " << ccId
768+ << " after returning " << numResults << " results" << endl;
754769
755770 // ClientCursor takes ownership of runner. Release to make sure it's not deleted.
756771 runner.release ();
@@ -774,7 +789,7 @@ namespace mongo {
774789 cc->setLeftoverMaxTimeMicros (curop.getRemainingMaxTimeMicros ());
775790 }
776791 else {
777- // cout << "not caching runner but returning " << numResults << " results\n";
792+ QLOG () << " not caching runner but returning " << numResults << " results\n " ;
778793 }
779794
780795 // Add the results from the query into the output buffer.
0 commit comments