Skip to content
Browse files

SERVER-8456: use CursorHolder to avoid auto_ptr::release

  • Loading branch information...
1 parent 33aa949 commit 2048a8099765766aa772592ecb0e5a6d54530287 @vrtx vrtx committed with monkey101
Showing with 10 additions and 12 deletions.
  1. +1 −0 src/mongo/db/clientcursor.h
  2. +9 −12 src/mongo/db/commands/mr.cpp
View
1 src/mongo/db/clientcursor.h
@@ -143,6 +143,7 @@ namespace mongo {
~Holder() {
DESTRUCTOR_GUARD ( reset(); );
}
+ ClientCursor* get() { return _c; }
operator bool() { return _c; }
ClientCursor * operator-> () { return _c; }
const ClientCursor * operator-> () const { return _c; }
View
21 src/mongo/db/commands/mr.cpp
@@ -768,10 +768,12 @@ namespace mongo {
verify( pm == op->setMessage( "m/r: (3/3) final reduce to collection" , _safeCount( _db, _config.incLong, BSONObj(), QueryOption_SlaveOk ) ) );
shared_ptr<Cursor> temp =
- NamespaceDetailsTransient::bestGuessCursor( _config.incLong.c_str() , BSONObj() ,
- sortKey );
- auto_ptr<ClientCursor> cursor( new ClientCursor( QueryOption_NoCursorTimeout , temp , _config.incLong.c_str() ) );
-
+ NamespaceDetailsTransient::bestGuessCursor(_config.incLong.c_str(),
+ BSONObj(),
+ sortKey);
+ ClientCursor::Holder cursor(new ClientCursor(QueryOption_NoCursorTimeout,
+ temp,
+ _config.incLong.c_str()));
// iterate over all sorted objects
while ( cursor->ok() ) {
BSONObj o = cursor->current().getOwned();
@@ -784,7 +786,6 @@ namespace mongo {
all.push_back( o );
if ( pm->hits() % 100 == 0 ) {
if ( ! cursor->yield() ) {
- cursor.release();
break;
}
killCurrentOp.checkForInterrupt();
@@ -800,7 +801,6 @@ namespace mongo {
}
catch (...) {
yield.relock();
- cursor.release();
throw;
}
@@ -809,15 +809,11 @@ namespace mongo {
all.push_back( o );
if ( ! yield.stillOk() ) {
- cursor.release();
break;
}
killCurrentOp.checkForInterrupt();
}
-
- // we need to release here since we temp release below
- cursor.release();
{
dbtempreleasecond tl;
@@ -1091,7 +1087,9 @@ namespace mongo {
// obtain full cursor on data to apply mr to
shared_ptr<Cursor> temp = NamespaceDetailsTransient::getCursor( config.ns.c_str(), config.filter, config.sort );
uassert( 16052, str::stream() << "could not create cursor over " << config.ns << " for query : " << config.filter << " sort : " << config.sort, temp.get() );
- auto_ptr<ClientCursor> cursor( new ClientCursor( QueryOption_NoCursorTimeout , temp , config.ns.c_str() ) );
+ ClientCursor::Holder cursor(new ClientCursor(QueryOption_NoCursorTimeout,
+ temp,
+ config.ns.c_str()));
uassert( 16053, str::stream() << "could not create client cursor over " << config.ns << " for query : " << config.filter << " sort : " << config.sort, cursor.get() );
Timer mt;
@@ -1132,7 +1130,6 @@ namespace mongo {
inReduce += t.micros();
if ( ! yield.stillOk() ) {
- cursor.release();
break;
}

0 comments on commit 2048a80

Please sign in to comment.
Something went wrong with that request. Please try again.