From f05b9437fbdc53deecf55ed3c20e36af3d733953 Mon Sep 17 00:00:00 2001 From: Charlie Swanson Date: Thu, 2 Mar 2017 13:54:24 -0500 Subject: SERVER-22541 Refactor RAII locking helpers. Removes the class 'ScopedTransaction' and moves the responsibility of abandoning the snapshot onto the GlobalLock class. Also renames the AutoGetCollectionForRead class to AutoGetCollectionForReadCommand, and adds a new AutoGetCollectionForRead class. Unlike AutoGetCollectionForReadCommand, this new class will not update the namespace on the CurrentOp object, nor will it add an entry to Top. --- src/mongo/db/cloner.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/mongo/db/cloner.cpp') diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 20455ad7c22..9c3252b83d6 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -144,8 +144,7 @@ struct Cloner::Fun { invariant(from_collection.coll() != "system.indexes"); // XXX: can probably take dblock instead - unique_ptr scopedXact(new ScopedTransaction(opCtx, MODE_X)); - unique_ptr globalWriteLock(new Lock::GlobalWrite(opCtx->lockState())); + unique_ptr globalWriteLock(new Lock::GlobalWrite(opCtx)); uassert( ErrorCodes::NotMaster, str::stream() << "Not primary while cloning collection " << from_collection.ns() @@ -198,13 +197,11 @@ struct Cloner::Fun { } opCtx->checkForInterrupt(); - scopedXact.reset(); globalWriteLock.reset(); CurOp::get(opCtx)->yielded(); - scopedXact.reset(new ScopedTransaction(opCtx, MODE_X)); - globalWriteLock.reset(new Lock::GlobalWrite(opCtx->lockState())); + globalWriteLock.reset(new Lock::GlobalWrite(opCtx)); // Check if everything is still all right. if (opCtx->writesAreReplicated()) { @@ -479,8 +476,7 @@ bool Cloner::copyCollection(OperationContext* opCtx, auto sourceIndexes = _conn->getIndexSpecs(nss.ns(), QueryOption_SlaveOk); auto idIndexSpec = getIdIndexSpec(sourceIndexes); - ScopedTransaction transaction(opCtx, MODE_IX); - Lock::DBLock dbWrite(opCtx->lockState(), dbname, MODE_X); + Lock::DBLock dbWrite(opCtx, dbname, MODE_X); uassert(ErrorCodes::PrimarySteppedDown, str::stream() << "Not primary while copying collection " << ns << " (Cloner)", -- cgit v1.2.1