diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp index 81f95a67c54..76a1d3ed0da 100644 --- a/db/dbhelpers.cpp +++ b/db/dbhelpers.cpp @@ -85,6 +85,7 @@ namespace mongo { } } virtual long long nscanned() { + // We don't support yielding, so will always have c_. assert( c_.get() ); return c_->nscanned(); } diff --git a/db/query.cpp b/db/query.cpp index 57cabca588a..c0976b7bb58 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -76,8 +76,7 @@ namespace mongo { } } virtual long long nscanned() { - assert( c_.get() ); - return c_->nscanned(); + return c_.get() ? c_->nscanned() : _nscanned; } virtual void next() { if ( !c_->ok() ) { @@ -417,6 +416,7 @@ namespace mongo { _ns(ns), _capped(false), _count(), _myCount(), _skip( spec["skip"].numberLong() ), _limit( spec["limit"].numberLong() ), + _nscanned(), _bc() { } @@ -431,8 +431,7 @@ namespace mongo { } virtual long long nscanned() { - assert( _c.get() ); - return _c->nscanned(); + return _c.get() ? _c->nscanned() : _nscanned; } virtual bool prepareToYield() { @@ -466,6 +465,7 @@ namespace mongo { return; } + _nscanned = _c->nscanned(); if ( _bc ) { if ( _firstMatch.isEmpty() ) { _firstMatch = _bc->currKeyNode().key.copy(); @@ -528,6 +528,7 @@ namespace mongo { long long _myCount; long long _skip; long long _limit; + long long _nscanned; shared_ptr _c; BSONObj _query; BtreeCursor * _bc; @@ -741,8 +742,7 @@ namespace mongo { if ( _findingStartCursor.get() ) { return 0; // should only be one query plan, so value doesn't really matter. } - assert( _c.get() ); - return _c->nscanned(); + return _c.get() ? _c->nscanned() : _nscanned; } virtual void next() { diff --git a/db/update.cpp b/db/update.cpp index 7de9bb1a573..a7b0a2a7813 100644 --- a/db/update.cpp +++ b/db/update.cpp @@ -913,8 +913,7 @@ namespace mongo { } } virtual long long nscanned() { - assert( _c.get() ); - return _c->nscanned(); + return _c.get() ? _c->nscanned() : _nscanned; } virtual void next() { if ( ! _c->ok() ) { diff --git a/jstests/slowNightly/explain2.js b/jstests/slowNightly/explain2.js new file mode 100644 index 00000000000..032f0fa8de8 --- /dev/null +++ b/jstests/slowNightly/explain2.js @@ -0,0 +1,18 @@ +// Test for race condition SERVER-2807. One cursor is dropped and another is not. + +collName = 'jstests_slowNightly_explain2'; + +t = db[ collName ]; +t.drop(); + +db.createCollection( collName, {capped:true,size:100000} ); +t = db[ collName ]; +t.ensureIndex( {x:1} ); + +a = startParallelShell( 'for( i = 0; i < 50000; ++i ) { db.' + collName + '.insert( {x:i,y:1} ); }' ); + +for( i = 0; i < 800; ++i ) { + t.find( {x:{$gt:-1},y:1} ).sort({x:-1}).explain(); +} + +a(); \ No newline at end of file