summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEric Milkie <milkie@mongodb.com>2019-11-04 18:49:17 +0000
committerevergreen <evergreen@mongodb.com>2019-11-04 18:49:17 +0000
commited610057b4a87cf96e3ba12bea8ae258a569906e (patch)
tree9239a8d332048a609bbe58e1f9565cd29835e5db /src
parent927eb1ea8c8b972ec4930d669a9d0804683b10e5 (diff)
downloadmongo-ed610057b4a87cf96e3ba12bea8ae258a569906e.tar.gz
SERVER-44368 protect opCtx's Locker with Client lock
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/auth/auth_op_observer_test.cpp4
-rw-r--r--src/mongo/db/catalog_raii_test.cpp2
-rw-r--r--src/mongo/db/client.cpp7
-rw-r--r--src/mongo/db/client.h10
-rw-r--r--src/mongo/db/concurrency/d_concurrency_bm.cpp2
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp50
-rw-r--r--src/mongo/db/op_observer_impl_test.cpp4
-rw-r--r--src/mongo/db/operation_context.cpp2
-rw-r--r--src/mongo/db/operation_context.h6
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl_test.cpp4
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp2
-rw-r--r--src/mongo/db/transaction_participant.cpp4
12 files changed, 57 insertions, 40 deletions
diff --git a/src/mongo/db/auth/auth_op_observer_test.cpp b/src/mongo/db/auth/auth_op_observer_test.cpp
index cbbff8dfe93..e97db4656ef 100644
--- a/src/mongo/db/auth/auth_op_observer_test.cpp
+++ b/src/mongo/db/auth/auth_op_observer_test.cpp
@@ -145,7 +145,7 @@ TEST_F(AuthOpObserverTest, MultipleAboutToDeleteAndOnDelete) {
DEATH_TEST_F(AuthOpObserverTest, AboutToDeleteMustPreceedOnDelete, "invariant") {
AuthOpObserver opObserver;
auto opCtx = cc().makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerNoop>());
+ cc().swapLockState(std::make_unique<LockerNoop>());
NamespaceString nss = {"test", "coll"};
opObserver.onDelete(opCtx.get(), nss, {}, {}, false, {});
}
@@ -153,7 +153,7 @@ DEATH_TEST_F(AuthOpObserverTest, AboutToDeleteMustPreceedOnDelete, "invariant")
DEATH_TEST_F(AuthOpObserverTest, EachOnDeleteRequiresAboutToDelete, "invariant") {
AuthOpObserver opObserver;
auto opCtx = cc().makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerNoop>());
+ cc().swapLockState(std::make_unique<LockerNoop>());
NamespaceString nss = {"test", "coll"};
opObserver.aboutToDelete(opCtx.get(), nss, {});
opObserver.onDelete(opCtx.get(), nss, {}, {}, false, {});
diff --git a/src/mongo/db/catalog_raii_test.cpp b/src/mongo/db/catalog_raii_test.cpp
index b01e508db03..97c67cd0f25 100644
--- a/src/mongo/db/catalog_raii_test.cpp
+++ b/src/mongo/db/catalog_raii_test.cpp
@@ -56,7 +56,7 @@ public:
ClientAndCtx makeClientWithLocker(const std::string& clientName) {
auto client = getServiceContext()->makeClient(clientName);
auto opCtx = client->makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ client->swapLockState(std::make_unique<LockerImpl>());
return std::make_pair(std::move(client), std::move(opCtx));
}
diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp
index 3bac054c2b1..a24e7a06453 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -41,6 +41,7 @@
#include "mongo/base/status.h"
#include "mongo/db/lasterror.h"
+#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/concurrency/thread_name.h"
@@ -145,6 +146,12 @@ Client* Client::getCurrent() {
return currentClient.get();
}
+std::unique_ptr<Locker> Client::swapLockState(std::unique_ptr<Locker> locker) {
+ scoped_spinlock scopedLock(_lock);
+ invariant(_opCtx);
+ return _opCtx->swapLockState(std::move(locker), scopedLock);
+}
+
Client& cc() {
invariant(haveClient());
return *Client::getCurrent();
diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h
index 75e828c63c3..6aea69b5c2a 100644
--- a/src/mongo/db/client.h
+++ b/src/mongo/db/client.h
@@ -52,6 +52,7 @@
namespace mongo {
class Collection;
+class Locker;
class OperationContext;
class ThreadClient;
@@ -144,7 +145,7 @@ public:
void reportState(BSONObjBuilder& builder);
// Ensures stability of the client's OperationContext. When the client is locked,
- // the OperationContext will not disappear.
+ // the OperationContext and the Locker within it will not disappear.
void lock() {
_lock.lock();
}
@@ -229,6 +230,13 @@ public:
return _prng;
}
+ /**
+ * Safely swaps the locker in the OperationContext, releasing the old locker to the caller.
+ * Locks this Client to do this safely.
+ */
+ std::unique_ptr<Locker> swapLockState(std::unique_ptr<Locker> locker);
+
+
private:
friend class ServiceContext;
friend class ThreadClient;
diff --git a/src/mongo/db/concurrency/d_concurrency_bm.cpp b/src/mongo/db/concurrency/d_concurrency_bm.cpp
index a13df7a3ea4..a153f934de7 100644
--- a/src/mongo/db/concurrency/d_concurrency_bm.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_bm.cpp
@@ -55,7 +55,7 @@ public:
auto client = getGlobalServiceContext()->makeClient(str::stream()
<< "test client for thread " << i);
auto opCtx = client->makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ client->swapLockState(std::make_unique<LockerImpl>());
clients.emplace_back(std::move(client), std::move(opCtx));
}
}
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index 92c4a943075..c19883a2b17 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -100,7 +100,7 @@ public:
auto client =
getServiceContext()->makeClient(str::stream() << "test client for thread " << i);
auto opCtx = client->makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ client->swapLockState(std::make_unique<LockerImpl>());
clients.emplace_back(std::move(client), std::move(opCtx));
}
return clients;
@@ -136,13 +136,13 @@ public:
TEST_F(DConcurrencyTestFixture, WriteConflictRetryInstantiatesOK) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
writeConflictRetry(opCtx.get(), "", "", [] {});
}
TEST_F(DConcurrencyTestFixture, WriteConflictRetryRetriesFunctionOnWriteConflictException) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto&& opDebug = CurOp::get(opCtx.get())->debug();
ASSERT_EQUALS(0, opDebug.additiveMetrics.writeConflicts.load());
ASSERT_EQUALS(100, writeConflictRetry(opCtx.get(), "", "", [&opDebug] {
@@ -156,7 +156,7 @@ TEST_F(DConcurrencyTestFixture, WriteConflictRetryRetriesFunctionOnWriteConflict
TEST_F(DConcurrencyTestFixture, WriteConflictRetryPropagatesNonWriteConflictException) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
ASSERT_THROWS_CODE(writeConflictRetry(opCtx.get(),
"",
"",
@@ -171,7 +171,7 @@ TEST_F(DConcurrencyTestFixture, WriteConflictRetryPropagatesNonWriteConflictExce
TEST_F(DConcurrencyTestFixture,
WriteConflictRetryPropagatesWriteConflictExceptionIfAlreadyInAWriteUnitOfWork) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::GlobalWrite globalWrite(opCtx.get());
WriteUnitOfWork wuow(opCtx.get());
ASSERT_THROWS(writeConflictRetry(opCtx.get(), "", "", [] { throw WriteConflictException(); }),
@@ -262,7 +262,7 @@ TEST_F(DConcurrencyTestFixture, ResourceMutex) {
TEST_F(DConcurrencyTestFixture, GlobalRead) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::GlobalRead globalRead(opCtx.get());
ASSERT(opCtx->lockState()->isR());
ASSERT_EQ(opCtx->lockState()->getLockMode(resourceIdReplicationStateTransitionLock), MODE_IX);
@@ -270,7 +270,7 @@ TEST_F(DConcurrencyTestFixture, GlobalRead) {
TEST_F(DConcurrencyTestFixture, GlobalWrite) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::GlobalWrite globalWrite(opCtx.get());
ASSERT(opCtx->lockState()->isW());
ASSERT_EQ(opCtx->lockState()->getLockMode(resourceIdReplicationStateTransitionLock), MODE_IX);
@@ -278,7 +278,7 @@ TEST_F(DConcurrencyTestFixture, GlobalWrite) {
TEST_F(DConcurrencyTestFixture, GlobalWriteAndGlobalRead) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
Lock::GlobalWrite globalWrite(opCtx.get());
@@ -296,7 +296,7 @@ TEST_F(DConcurrencyTestFixture, GlobalWriteAndGlobalRead) {
TEST_F(DConcurrencyTestFixture,
GlobalWriteRequiresExplicitDowngradeToIntentWriteModeIfDestroyedWhileHoldingDatabaseLock) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
auto globalWrite = std::make_unique<Lock::GlobalWrite>(opCtx.get());
@@ -338,7 +338,7 @@ TEST_F(DConcurrencyTestFixture,
TEST_F(DConcurrencyTestFixture,
GlobalWriteRequiresSupportsDowngradeToIntentWriteModeWhileHoldingDatabaseLock) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
auto globalWrite = std::make_unique<Lock::GlobalWrite>(opCtx.get());
@@ -379,7 +379,7 @@ TEST_F(DConcurrencyTestFixture,
TEST_F(DConcurrencyTestFixture,
NestedGlobalWriteSupportsDowngradeToIntentWriteModeWhileHoldingDatabaseLock) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
auto outerGlobalWrite = std::make_unique<Lock::GlobalWrite>(opCtx.get());
@@ -709,7 +709,7 @@ TEST_F(DConcurrencyTestFixture, GlobalLockX_TimeoutDueToGlobalLockX) {
TEST_F(DConcurrencyTestFixture, TempReleaseGlobalWrite) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
Lock::GlobalWrite globalWrite(opCtx.get());
ASSERT_EQ(lockState->getLockMode(resourceIdReplicationStateTransitionLock), MODE_IX);
@@ -726,7 +726,7 @@ TEST_F(DConcurrencyTestFixture, TempReleaseGlobalWrite) {
TEST_F(DConcurrencyTestFixture, TempReleaseRecursive) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
Lock::GlobalWrite globalWrite(opCtx.get());
Lock::DBLock lk(opCtx.get(), "SomeDBName", MODE_X);
@@ -1075,7 +1075,7 @@ TEST_F(DConcurrencyTestFixture, LockCompleteInterruptedWhenUncontested) {
TEST_F(DConcurrencyTestFixture, DBLockTakesS) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::DBLock dbRead(opCtx.get(), "db", MODE_S);
const ResourceId resIdDb(RESOURCE_DATABASE, std::string("db"));
@@ -1084,7 +1084,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesS) {
TEST_F(DConcurrencyTestFixture, DBLockTakesX) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::DBLock dbWrite(opCtx.get(), "db", MODE_X);
const ResourceId resIdDb(RESOURCE_DATABASE, std::string("db"));
@@ -1093,7 +1093,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesX) {
TEST_F(DConcurrencyTestFixture, DBLockTakesISForAdminIS) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::DBLock dbRead(opCtx.get(), "admin", MODE_IS);
ASSERT(opCtx->lockState()->getLockMode(resourceIdAdminDB) == MODE_IS);
@@ -1101,7 +1101,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesISForAdminIS) {
TEST_F(DConcurrencyTestFixture, DBLockTakesSForAdminS) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::DBLock dbRead(opCtx.get(), "admin", MODE_S);
ASSERT(opCtx->lockState()->getLockMode(resourceIdAdminDB) == MODE_S);
@@ -1109,7 +1109,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesSForAdminS) {
TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminIX) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::DBLock dbWrite(opCtx.get(), "admin", MODE_IX);
ASSERT(opCtx->lockState()->getLockMode(resourceIdAdminDB) == MODE_X);
@@ -1117,7 +1117,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminIX) {
TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminX) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::DBLock dbWrite(opCtx.get(), "admin", MODE_X);
ASSERT(opCtx->lockState()->getLockMode(resourceIdAdminDB) == MODE_X);
@@ -1125,7 +1125,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminX) {
TEST_F(DConcurrencyTestFixture, MultipleWriteDBLocksOnSameThread) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
Lock::DBLock r1(opCtx.get(), "db1", MODE_X);
Lock::DBLock r2(opCtx.get(), "db1", MODE_X);
@@ -1134,7 +1134,7 @@ TEST_F(DConcurrencyTestFixture, MultipleWriteDBLocksOnSameThread) {
TEST_F(DConcurrencyTestFixture, MultipleConflictingDBLocksOnSameThread) {
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
Lock::DBLock r1(opCtx.get(), "db1", MODE_X);
Lock::DBLock r2(opCtx.get(), "db1", MODE_S);
@@ -1147,7 +1147,7 @@ TEST_F(DConcurrencyTestFixture, IsDbLockedForSMode) {
const std::string dbName("db");
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
Lock::DBLock dbLock(opCtx.get(), dbName, MODE_S);
@@ -1161,7 +1161,7 @@ TEST_F(DConcurrencyTestFixture, IsDbLockedForXMode) {
const std::string dbName("db");
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
Lock::DBLock dbLock(opCtx.get(), dbName, MODE_X);
@@ -1175,7 +1175,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
const NamespaceString ns("db1.coll");
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
Lock::DBLock dbLock(opCtx.get(), "db1", MODE_IS);
@@ -1206,7 +1206,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IX) {
const NamespaceString ns("db1.coll");
auto opCtx = makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ getClient()->swapLockState(std::make_unique<LockerImpl>());
auto lockState = opCtx->lockState();
Lock::DBLock dbLock(opCtx.get(), "db1", MODE_IX);
diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp
index 06dcdc944fd..a264e817411 100644
--- a/src/mongo/db/op_observer_impl_test.cpp
+++ b/src/mongo/db/op_observer_impl_test.cpp
@@ -527,7 +527,7 @@ TEST_F(OpObserverTest, MultipleAboutToDeleteAndOnDelete) {
DEATH_TEST_F(OpObserverTest, AboutToDeleteMustPreceedOnDelete, "invariant") {
OpObserverImpl opObserver;
auto opCtx = cc().makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerNoop>());
+ cc().swapLockState(std::make_unique<LockerNoop>());
NamespaceString nss = {"test", "coll"};
opObserver.onDelete(opCtx.get(), nss, {}, kUninitializedStmtId, false, {});
}
@@ -535,7 +535,7 @@ DEATH_TEST_F(OpObserverTest, AboutToDeleteMustPreceedOnDelete, "invariant") {
DEATH_TEST_F(OpObserverTest, EachOnDeleteRequiresAboutToDelete, "invariant") {
OpObserverImpl opObserver;
auto opCtx = cc().makeOperationContext();
- opCtx->swapLockState(std::make_unique<LockerNoop>());
+ cc().swapLockState(std::make_unique<LockerNoop>());
NamespaceString nss = {"test", "coll"};
opObserver.aboutToDelete(opCtx.get(), nss, {});
opObserver.onDelete(opCtx.get(), nss, {}, kUninitializedStmtId, false, {});
diff --git a/src/mongo/db/operation_context.cpp b/src/mongo/db/operation_context.cpp
index bab631ad351..0a281d3b3ba 100644
--- a/src/mongo/db/operation_context.cpp
+++ b/src/mongo/db/operation_context.cpp
@@ -382,7 +382,7 @@ void OperationContext::setLockState(std::unique_ptr<Locker> locker) {
_locker = std::move(locker);
}
-std::unique_ptr<Locker> OperationContext::swapLockState(std::unique_ptr<Locker> locker) {
+std::unique_ptr<Locker> OperationContext::swapLockState(std::unique_ptr<Locker> locker, WithLock) {
invariant(_locker);
invariant(locker);
_locker.swap(locker);
diff --git a/src/mongo/db/operation_context.h b/src/mongo/db/operation_context.h
index 9a7fb8c17ad..03a385651eb 100644
--- a/src/mongo/db/operation_context.h
+++ b/src/mongo/db/operation_context.h
@@ -44,6 +44,7 @@
#include "mongo/platform/mutex.h"
#include "mongo/stdx/condition_variable.h"
#include "mongo/transport/session.h"
+#include "mongo/util/concurrency/with_lock.h"
#include "mongo/util/decorable.h"
#include "mongo/util/interruptible.h"
#include "mongo/util/lockable_adapter.h"
@@ -133,9 +134,10 @@ public:
void setLockState(std::unique_ptr<Locker> locker);
/**
- * Swaps the locker, releasing the old locker to the caller.
+ * Swaps the locker, releasing the old locker to the caller. The Client lock is required to
+ * call this function.
*/
- std::unique_ptr<Locker> swapLockState(std::unique_ptr<Locker> locker);
+ std::unique_ptr<Locker> swapLockState(std::unique_ptr<Locker> locker, WithLock);
/**
* Returns Status::OK() unless this operation is in a killed state.
diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
index f4bb250ce1d..0091850e6ef 100644
--- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp
@@ -1924,7 +1924,7 @@ TEST_F(StepDownTest,
// locker to test this, or otherwise stepDown will be granted the lock automatically.
ReplicationStateTransitionLockGuard transitionGuard(opCtx.get(), MODE_X);
ASSERT_TRUE(opCtx->lockState()->isRSTLExclusive());
- auto locker = opCtx.get()->swapLockState(std::make_unique<LockerImpl>());
+ auto locker = getClient()->swapLockState(std::make_unique<LockerImpl>());
ASSERT_THROWS_CODE(
getReplCoord()->stepDown(opCtx.get(), false, Milliseconds(0), Milliseconds(1000)),
@@ -1935,7 +1935,7 @@ TEST_F(StepDownTest,
ASSERT_TRUE(locker->isRSTLExclusive());
ASSERT_FALSE(opCtx->lockState()->isRSTLLocked());
- opCtx.get()->swapLockState(std::move(locker));
+ getClient()->swapLockState(std::move(locker));
}
/* Step Down Test for a 5-node replica set */
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
index fdfd5bcd167..e57d25e58ee 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_oplog_manager.cpp
@@ -172,7 +172,7 @@ void WiredTigerOplogManager::_oplogJournalThreadLoop(WiredTigerSessionCache* ses
//
// TODO (SERVER-41392): the Replicate Before Journaling project will be removing the
// waitUntilDurable() call requiring an opCtx parameter.
- opCtx->swapLockState(std::make_unique<LockerImpl>());
+ cc().swapLockState(std::make_unique<LockerImpl>());
stdx::unique_lock<Latch> lk(_oplogVisibilityStateMutex);
{
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index 01d378e2d88..53f7350d77b 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -669,7 +669,7 @@ TransactionParticipant::TxnResources::TxnResources(WithLock wl,
_ruState = opCtx->getWriteUnitOfWork()->release();
opCtx->setWriteUnitOfWork(nullptr);
- _locker = opCtx->swapLockState(std::make_unique<LockerImpl>());
+ _locker = opCtx->swapLockState(std::make_unique<LockerImpl>(), wl);
// Inherit the locking setting from the original one.
opCtx->lockState()->setShouldConflictWithSecondaryBatchApplication(
_locker->shouldConflictWithSecondaryBatchApplication());
@@ -762,7 +762,7 @@ void TransactionParticipant::TxnResources::release(OperationContext* opCtx) {
// We intentionally do not capture the return value of swapLockState(), which is just an empty
// locker. At the end of the operation, if the transaction is not complete, we will stash the
// operation context's locker and replace it with a new empty locker.
- opCtx->swapLockState(std::move(_locker));
+ opCtx->swapLockState(std::move(_locker), lk);
opCtx->lockState()->updateThreadIdToCurrentThread();
auto oldState = opCtx->setRecoveryUnit(std::move(_recoveryUnit),