From 2048a8099765766aa772592ecb0e5a6d54530287 Mon Sep 17 00:00:00 2001 From: Ben Becker Date: Tue, 12 Feb 2013 12:32:24 -0800 Subject: SERVER-8456: use CursorHolder to avoid auto_ptr::release --- src/mongo/db/clientcursor.h | 1 + src/mongo/db/commands/mr.cpp | 21 +++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h index aebd23d4607..0283dde5e96 100644 --- a/src/mongo/db/clientcursor.h +++ b/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; } diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index b283bca37ef..13e378dedd9 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/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 temp = - NamespaceDetailsTransient::bestGuessCursor( _config.incLong.c_str() , BSONObj() , - sortKey ); - auto_ptr 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 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 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; } -- cgit v1.2.1