summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/catalog/collection_test.cpp3
-rw-r--r--src/mongo/db/catalog/create_collection.cpp4
-rw-r--r--src/mongo/db/catalog/database_impl.cpp2
-rw-r--r--src/mongo/db/catalog/database_test.cpp4
-rw-r--r--src/mongo/db/catalog/drop_collection.cpp4
-rw-r--r--src/mongo/db/catalog_raii.cpp2
-rw-r--r--src/mongo/db/catalog_raii_test.cpp6
-rw-r--r--src/mongo/db/commands/create_indexes.cpp6
-rw-r--r--src/mongo/db/commands/dbcommands_d.cpp2
-rw-r--r--src/mongo/db/commands/dbhash.cpp2
-rw-r--r--src/mongo/db/commands/list_collections.cpp2
-rw-r--r--src/mongo/db/commands/sleep_command.cpp2
-rw-r--r--src/mongo/db/commands/validate.cpp2
-rw-r--r--src/mongo/db/concurrency/d_concurrency.cpp22
-rw-r--r--src/mongo/db/concurrency/d_concurrency.h9
-rw-r--r--src/mongo/db/concurrency/d_concurrency_bm.cpp12
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp58
-rw-r--r--src/mongo/db/free_mon/free_mon_storage_test.cpp2
-rw-r--r--src/mongo/db/index_builder.cpp2
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp6
-rw-r--r--src/mongo/db/introspect.cpp2
-rw-r--r--src/mongo/db/matcher/expression_text.cpp2
-rw-r--r--src/mongo/db/pipeline/document_source_cursor.cpp2
-rw-r--r--src/mongo/db/pipeline/process_interface_shardsvr.cpp2
-rw-r--r--src/mongo/db/pipeline/process_interface_standalone.cpp4
-rw-r--r--src/mongo/db/read_concern_mongod.cpp2
-rw-r--r--src/mongo/db/repl/apply_ops.cpp2
-rw-r--r--src/mongo/db/repl/dbcheck.cpp2
-rw-r--r--src/mongo/db/repl/do_txn.cpp2
-rw-r--r--src/mongo/db/repl/idempotency_test_fixture.cpp2
-rw-r--r--src/mongo/db/repl/oplog.cpp4
-rw-r--r--src/mongo/db/repl/oplog_interface_local.cpp2
-rw-r--r--src/mongo/db/repl/replication_consistency_markers_impl_test.cpp4
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp2
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp2
-rw-r--r--src/mongo/db/repl/rs_rollback_test.cpp2
-rw-r--r--src/mongo/db/s/implicit_create_collection.cpp2
-rw-r--r--src/mongo/db/s/set_shard_version_command.cpp2
-rw-r--r--src/mongo/db/sessions_collection_rs.cpp3
-rw-r--r--src/mongo/db/transaction_participant.cpp4
-rw-r--r--src/mongo/db/transaction_participant_test.cpp2
-rw-r--r--src/mongo/db/views/durable_view_catalog.cpp2
-rw-r--r--src/mongo/dbtests/dbtests.cpp2
-rw-r--r--src/mongo/dbtests/validate_tests.cpp2
44 files changed, 119 insertions, 90 deletions
diff --git a/src/mongo/db/catalog/collection_test.cpp b/src/mongo/db/catalog/collection_test.cpp
index c847faea2db..1259e3105f6 100644
--- a/src/mongo/db/catalog/collection_test.cpp
+++ b/src/mongo/db/catalog/collection_test.cpp
@@ -67,8 +67,7 @@ void CollectionTest::makeUncapped(NamespaceString nss) {
void CollectionTest::checkValidate(
Collection* coll, bool valid, int records, int invalid, int errors) {
auto opCtx = operationContext();
- auto collLock =
- std::make_unique<Lock::CollectionLock>(opCtx->lockState(), coll->ns().ns(), MODE_X);
+ auto collLock = std::make_unique<Lock::CollectionLock>(opCtx, coll->ns().ns(), MODE_X);
for (auto level : levels) {
ValidateResults results;
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
index b2b7c8781db..63af4ff62bc 100644
--- a/src/mongo/db/catalog/create_collection.cpp
+++ b/src/mongo/db/catalog/create_collection.cpp
@@ -58,10 +58,10 @@ Status _createView(OperationContext* opCtx,
return writeConflictRetry(opCtx, "create", nss.ns(), [&] {
AutoGetOrCreateDb autoDb(opCtx, nss.db(), MODE_IX);
Lock::CollectionLock systemViewsLock(
- opCtx->lockState(),
+ opCtx,
NamespaceString(nss.db(), NamespaceString::kSystemDotViewsCollectionName).toString(),
MODE_X);
- Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, nss.ns(), MODE_IX);
Database* db = autoDb.getDb();
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 1f75c495f39..af7cf7b8d56 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -279,7 +279,7 @@ void DatabaseImpl::getStats(OperationContext* opCtx, BSONObjBuilder* output, dou
invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_IS));
for (const auto& nss : UUIDCatalog::get(opCtx).getAllCollectionNamesFromDb(_name)) {
- Lock::CollectionLock colLock(opCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock colLock(opCtx, nss.ns(), MODE_IS);
Collection* collection = getCollection(opCtx, nss.ns());
if (!collection)
diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp
index b5341afe9bf..6de17143f63 100644
--- a/src/mongo/db/catalog/database_test.cpp
+++ b/src/mongo/db/catalog/database_test.cpp
@@ -504,7 +504,7 @@ TEST_F(DatabaseTest, AutoGetCollectionForReadCommandSucceedsWithDeadlineNow) {
NamespaceString nss("test", "coll");
Lock::DBLock dbLock(_opCtx.get(), nss.db(), MODE_X);
ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.db(), MODE_X));
- Lock::CollectionLock collLock(_opCtx.get()->lockState(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock(_opCtx.get(), nss.toString(), MODE_X);
ASSERT(_opCtx.get()->lockState()->isCollectionLockedForMode(nss, MODE_X));
try {
AutoGetCollectionForReadCommand db(
@@ -518,7 +518,7 @@ TEST_F(DatabaseTest, AutoGetCollectionForReadCommandSucceedsWithDeadlineMin) {
NamespaceString nss("test", "coll");
Lock::DBLock dbLock(_opCtx.get(), nss.db(), MODE_X);
ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.db(), MODE_X));
- Lock::CollectionLock collLock(_opCtx.get()->lockState(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock(_opCtx.get(), nss.toString(), MODE_X);
ASSERT(_opCtx.get()->lockState()->isCollectionLockedForMode(nss, MODE_X));
try {
AutoGetCollectionForReadCommand db(
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp
index 2bd54a0acd4..5df9b0ba1b4 100644
--- a/src/mongo/db/catalog/drop_collection.cpp
+++ b/src/mongo/db/catalog/drop_collection.cpp
@@ -66,8 +66,8 @@ Status _dropView(OperationContext* opCtx,
if (!view) {
return Status(ErrorCodes::NamespaceNotFound, "ns not found");
}
- Lock::CollectionLock systemViewsLock(opCtx->lockState(), db->getSystemViewsName(), MODE_X);
- Lock::CollectionLock collLock(opCtx->lockState(), collectionName.ns(), MODE_IX);
+ Lock::CollectionLock systemViewsLock(opCtx, db->getSystemViewsName(), MODE_X);
+ Lock::CollectionLock collLock(opCtx, collectionName.ns(), MODE_IX);
if (MONGO_FAIL_POINT(hangDuringDropCollection)) {
log() << "hangDuringDropCollection fail point enabled. Blocking until fail point is "
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp
index d67b2cbc520..5a8eff8c8e6 100644
--- a/src/mongo/db/catalog_raii.cpp
+++ b/src/mongo/db/catalog_raii.cpp
@@ -75,7 +75,7 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
modeDB,
deadline),
_resolvedNss(resolveNamespaceStringOrUUID(opCtx, nsOrUUID)) {
- _collLock.emplace(opCtx->lockState(), _resolvedNss.ns(), modeColl, deadline);
+ _collLock.emplace(opCtx, _resolvedNss.ns(), modeColl, deadline);
// Wait for a configured amount of time after acquiring locks if the failpoint is enabled
MONGO_FAIL_POINT_BLOCK(setAutoGetCollectionWait, customWait) {
const BSONObj& data = customWait.getData();
diff --git a/src/mongo/db/catalog_raii_test.cpp b/src/mongo/db/catalog_raii_test.cpp
index a6c90d830ae..d55f887ff6e 100644
--- a/src/mongo/db/catalog_raii_test.cpp
+++ b/src/mongo/db/catalog_raii_test.cpp
@@ -133,7 +133,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetOrCreateDbDeadline) {
TEST_F(CatalogRAIITestFixture, AutoGetCollectionCollLockDeadline) {
Lock::DBLock dbLock1(client1.second.get(), nss.db(), MODE_IX);
ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX));
- Lock::CollectionLock collLock1(client1.second.get()->lockState(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock1(client1.second.get(), nss.toString(), MODE_X);
ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X));
failsWithLockTimeout(
[&] {
@@ -181,7 +181,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionGlobalLockDeadline) {
TEST_F(CatalogRAIITestFixture, AutoGetCollectionDeadlineNow) {
Lock::DBLock dbLock1(client1.second.get(), nss.db(), MODE_IX);
ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX));
- Lock::CollectionLock collLock1(client1.second.get()->lockState(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock1(client1.second.get(), nss.toString(), MODE_X);
ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X));
failsWithLockTimeout(
@@ -199,7 +199,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionDeadlineNow) {
TEST_F(CatalogRAIITestFixture, AutoGetCollectionDeadlineMin) {
Lock::DBLock dbLock1(client1.second.get(), nss.db(), MODE_IX);
ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX));
- Lock::CollectionLock collLock1(client1.second.get()->lockState(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock1(client1.second.get(), nss.toString(), MODE_X);
ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X));
failsWithLockTimeout(
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index 89c47545edc..5156edad90b 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -401,7 +401,7 @@ bool runCreateIndexes(OperationContext* opCtx,
// Collection scan and insert into index, followed by a drain of writes received in the
// background.
{
- Lock::CollectionLock colLock(opCtx->lockState(), ns.ns(), MODE_IX);
+ Lock::CollectionLock colLock(opCtx, ns.ns(), MODE_IX);
uassertStatusOK(indexer.insertAllDocumentsInCollection(opCtx, collection));
}
@@ -413,7 +413,7 @@ bool runCreateIndexes(OperationContext* opCtx,
// Perform the first drain while holding an intent lock.
{
opCtx->recoveryUnit()->abandonSnapshot();
- Lock::CollectionLock colLock(opCtx->lockState(), ns.ns(), MODE_IS);
+ Lock::CollectionLock colLock(opCtx, ns.ns(), MODE_IS);
// Read at a point in time so that the drain, which will timestamp writes at lastApplied,
// can never commit writes earlier than its read timestamp.
@@ -428,7 +428,7 @@ bool runCreateIndexes(OperationContext* opCtx,
// Perform the second drain while stopping writes on the collection.
{
opCtx->recoveryUnit()->abandonSnapshot();
- Lock::CollectionLock colLock(opCtx->lockState(), ns.ns(), MODE_S);
+ Lock::CollectionLock colLock(opCtx, ns.ns(), MODE_S);
uassertStatusOK(indexer.drainBackgroundWrites(opCtx));
}
diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp
index a21e2d76c47..1b03fb04e4d 100644
--- a/src/mongo/db/commands/dbcommands_d.cpp
+++ b/src/mongo/db/commands/dbcommands_d.cpp
@@ -259,7 +259,7 @@ public:
Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS);
invariant(dbLock.isLocked(),
"Expected lock acquisition to succeed due to UninterruptibleLockGuard");
- Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss.ns(), MODE_IS);
exec.reset();
});
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 1ae2e0880b0..5cb1d6a09e1 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -279,7 +279,7 @@ private:
// reading from the consistent snapshot doesn't overlap with any catalog operations on
// the collection.
invariant(opCtx->lockState()->isDbLockedForMode(db->name(), MODE_IS));
- collLock.emplace(opCtx->lockState(), fullCollectionName, MODE_IS);
+ collLock.emplace(opCtx, fullCollectionName, MODE_IS);
auto minSnapshot = collection->getMinimumVisibleSnapshot();
auto mySnapshot = opCtx->recoveryUnit()->getPointInTimeReadTimestamp();
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index 89a7ea9ad74..863d379b653 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -186,7 +186,7 @@ BSONObj buildCollectionBson(OperationContext* opCtx,
return b.obj();
}
- Lock::CollectionLock clk(opCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock clk(opCtx, nss.ns(), MODE_IS);
CollectionOptions options = collection->getCatalogEntry()->getCollectionOptions(opCtx);
// While the UUID is stored as a collection option, from the user's perspective it is an
diff --git a/src/mongo/db/commands/sleep_command.cpp b/src/mongo/db/commands/sleep_command.cpp
index a92d760cf81..b6d39449fe2 100644
--- a/src/mongo/db/commands/sleep_command.cpp
+++ b/src/mongo/db/commands/sleep_command.cpp
@@ -85,7 +85,7 @@ public:
uassert(50962,
"lockTarget is not a valid namespace",
NamespaceString::validCollectionComponent(ns));
- Lock::CollectionLock lk(opCtx->lockState(), ns, mode, Date_t::max());
+ Lock::CollectionLock lk(opCtx, ns, mode, Date_t::max());
opCtx->sleepFor(Milliseconds(millis));
}
}
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index 4ba5ca75025..9cfe10e4dba 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -123,7 +123,7 @@ public:
}
AutoGetDb ctx(opCtx, nss.db(), MODE_IX);
- auto collLk = stdx::make_unique<Lock::CollectionLock>(opCtx->lockState(), nss.ns(), MODE_X);
+ auto collLk = stdx::make_unique<Lock::CollectionLock>(opCtx, nss.ns(), MODE_X);
Collection* collection = ctx.getDb() ? ctx.getDb()->getCollection(opCtx, nss) : NULL;
if (!collection) {
if (ctx.getDb() && ViewCatalog::get(ctx.getDb())->lookup(opCtx, nss.ns())) {
diff --git a/src/mongo/db/concurrency/d_concurrency.cpp b/src/mongo/db/concurrency/d_concurrency.cpp
index df7064ea79c..bdd07a1d5e0 100644
--- a/src/mongo/db/concurrency/d_concurrency.cpp
+++ b/src/mongo/db/concurrency/d_concurrency.cpp
@@ -276,34 +276,30 @@ void Lock::DBLock::relockWithMode(LockMode newMode) {
}
-Lock::CollectionLock::CollectionLock(Locker* lockState,
+Lock::CollectionLock::CollectionLock(OperationContext* opCtx,
StringData ns,
LockMode mode,
Date_t deadline)
- : _id(RESOURCE_COLLECTION, ns), _result(LOCK_INVALID), _lockState(lockState) {
+ : _id(RESOURCE_COLLECTION, ns), _opCtx(opCtx) {
massert(28538, "need a non-empty collection name", nsIsFull(ns));
- dassert(_lockState->isDbLockedForMode(nsToDatabaseSubstring(ns),
- isSharedLockMode(mode) ? MODE_IS : MODE_IX));
+ dassert(opCtx->lockState()->isDbLockedForMode(nsToDatabaseSubstring(ns),
+ isSharedLockMode(mode) ? MODE_IS : MODE_IX));
LockMode actualLockMode = mode;
if (!supportsDocLocking()) {
actualLockMode = isSharedLockMode(mode) ? MODE_S : MODE_X;
}
-
- _lockState->lock(_id, actualLockMode, deadline);
- _result = LOCK_OK;
+ _opCtx->lockState()->lock(_opCtx, _id, actualLockMode, deadline);
}
Lock::CollectionLock::CollectionLock(CollectionLock&& otherLock)
- : _id(otherLock._id), _result(otherLock._result), _lockState(otherLock._lockState) {
- otherLock._lockState = nullptr;
- otherLock._result = LOCK_INVALID;
+ : _id(otherLock._id), _opCtx(otherLock._opCtx) {
+ otherLock._opCtx = nullptr;
}
Lock::CollectionLock::~CollectionLock() {
- if (isLocked()) {
- _lockState->unlock(_id);
- }
+ if (_opCtx)
+ _opCtx->lockState()->unlock(_id);
}
namespace {
diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h
index e6259e85ca4..0425d7c0cc4 100644
--- a/src/mongo/db/concurrency/d_concurrency.h
+++ b/src/mongo/db/concurrency/d_concurrency.h
@@ -358,21 +358,16 @@ public:
CollectionLock& operator=(const CollectionLock&) = delete;
public:
- CollectionLock(Locker* lockState,
+ CollectionLock(OperationContext* opCtx,
StringData ns,
LockMode mode,
Date_t deadline = Date_t::max());
CollectionLock(CollectionLock&&);
~CollectionLock();
- bool isLocked() const {
- return _result == LOCK_OK;
- }
-
private:
const ResourceId _id;
- LockResult _result;
- Locker* _lockState;
+ OperationContext* _opCtx;
};
/**
diff --git a/src/mongo/db/concurrency/d_concurrency_bm.cpp b/src/mongo/db/concurrency/d_concurrency_bm.cpp
index 88692b2a2de..de643c34374 100644
--- a/src/mongo/db/concurrency/d_concurrency_bm.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_bm.cpp
@@ -100,8 +100,7 @@ BENCHMARK_DEFINE_F(DConcurrencyTest, BM_CollectionIntentSharedLock)(benchmark::S
for (auto keepRunning : state) {
Lock::DBLock dlk(clients[state.thread_index].second.get(), "test", MODE_IS);
- Lock::CollectionLock clk(
- clients[state.thread_index].second->lockState(), "test.coll", MODE_IS);
+ Lock::CollectionLock clk(clients[state.thread_index].second.get(), "test.coll", MODE_IS);
}
if (state.thread_index == 0) {
@@ -119,8 +118,7 @@ BENCHMARK_DEFINE_F(DConcurrencyTest, BM_CollectionIntentExclusiveLock)(benchmark
for (auto keepRunning : state) {
Lock::DBLock dlk(clients[state.thread_index].second.get(), "test", MODE_IX);
- Lock::CollectionLock clk(
- clients[state.thread_index].second->lockState(), "test.coll", MODE_IX);
+ Lock::CollectionLock clk(clients[state.thread_index].second.get(), "test.coll", MODE_IX);
}
if (state.thread_index == 0) {
@@ -138,8 +136,7 @@ BENCHMARK_DEFINE_F(DConcurrencyTest, BM_MMAPv1CollectionSharedLock)(benchmark::S
for (auto keepRunning : state) {
Lock::DBLock dlk(clients[state.thread_index].second.get(), "test", MODE_IS);
- Lock::CollectionLock clk(
- clients[state.thread_index].second->lockState(), "test.coll", MODE_S);
+ Lock::CollectionLock clk(clients[state.thread_index].second.get(), "test.coll", MODE_S);
}
if (state.thread_index == 0) {
@@ -157,8 +154,7 @@ BENCHMARK_DEFINE_F(DConcurrencyTest, BM_MMAPv1CollectionExclusiveLock)(benchmark
for (auto keepRunning : state) {
Lock::DBLock dlk(clients[state.thread_index].second.get(), "test", MODE_IX);
- Lock::CollectionLock clk(
- clients[state.thread_index].second->lockState(), "test.coll", MODE_X);
+ Lock::CollectionLock clk(clients[state.thread_index].second.get(), "test.coll", MODE_X);
}
if (state.thread_index == 0) {
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index d80890a8c83..9043e00e4b7 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -1177,7 +1177,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
Lock::DBLock dbLock(opCtx.get(), "db1", MODE_IS);
{
- Lock::CollectionLock collLock(lockState, ns.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx.get(), ns.ns(), MODE_IS);
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IS));
ASSERT(!lockState->isCollectionLockedForMode(ns, MODE_IX));
@@ -1189,7 +1189,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
}
{
- Lock::CollectionLock collLock(lockState, ns.ns(), MODE_S);
+ Lock::CollectionLock collLock(opCtx.get(), ns.ns(), MODE_S);
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IS));
ASSERT(!lockState->isCollectionLockedForMode(ns, MODE_IX));
@@ -1208,7 +1208,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IX) {
Lock::DBLock dbLock(opCtx.get(), "db1", MODE_IX);
{
- Lock::CollectionLock collLock(lockState, ns.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx.get(), ns.ns(), MODE_IX);
// TODO: This is TRUE because Lock::CollectionLock converts IX lock to X
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IS));
@@ -1219,7 +1219,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IX) {
}
{
- Lock::CollectionLock collLock(lockState, ns.ns(), MODE_X);
+ Lock::CollectionLock collLock(opCtx.get(), ns.ns(), MODE_X);
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IS));
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IX));
@@ -1741,6 +1741,51 @@ TEST_F(DConcurrencyTestFixture, DBLockTimeoutDueToGlobalLock) {
ASSERT_GTE(t2 - t1, Milliseconds(timeoutMillis));
}
+TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextThrowsEvenWhenUncontested) {
+ auto clients = makeKClientsWithLockers(1);
+ auto opCtx = clients[0].second.get();
+
+ Lock::DBLock dbLock(opCtx, "db", MODE_IX);
+ opCtx->markKilled();
+
+ {
+ boost::optional<Lock::CollectionLock> collLock;
+ ASSERT_THROWS_CODE(collLock.emplace(opCtx, "db.coll", MODE_IX),
+ AssertionException,
+ ErrorCodes::Interrupted);
+ }
+}
+
+TEST_F(DConcurrencyTestFixture,
+ CollectionLockInInterruptedContextThrowsEvenWhenAcquiringRecursively) {
+ auto clients = makeKClientsWithLockers(1);
+ auto opCtx = clients[0].second.get();
+
+ Lock::DBLock dbLock(opCtx, "db", MODE_IX);
+ Lock::CollectionLock collLock(opCtx, "db.coll", MODE_IX);
+
+ opCtx->markKilled();
+
+ {
+ boost::optional<Lock::CollectionLock> recursiveCollLock;
+ ASSERT_THROWS_CODE(recursiveCollLock.emplace(opCtx, "db.coll", MODE_X),
+ AssertionException,
+ ErrorCodes::Interrupted);
+ }
+}
+
+TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextRespectsUninterruptibleGuard) {
+ auto clients = makeKClientsWithLockers(1);
+ auto opCtx = clients[0].second.get();
+
+ Lock::DBLock dbLock(opCtx, "db", MODE_IX);
+
+ opCtx->markKilled();
+
+ UninterruptibleLockGuard noInterrupt(opCtx->lockState());
+ Lock::CollectionLock collLock(opCtx, "db.coll", MODE_IX); // Does not throw.
+}
+
TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) {
auto clientOpctxPairs = makeKClientsWithLockers(2);
auto opctx1 = clientOpctxPairs[0].second.get();
@@ -1750,15 +1795,14 @@ TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) {
Lock::DBLock DBL1(opctx1, "testdb"_sd, MODE_IX, Date_t::max());
ASSERT(opctx1->lockState()->isDbLockedForMode("testdb"_sd, MODE_IX));
- Lock::CollectionLock CL1(opctx1->lockState(), "testdb.test"_sd, MODE_X, Date_t::max());
+ Lock::CollectionLock CL1(opctx1, "testdb.test"_sd, MODE_X, Date_t::max());
ASSERT(opctx1->lockState()->isCollectionLockedForMode(NamespaceString("testdb.test"), MODE_X));
Date_t t1 = Date_t::now();
Lock::DBLock DBL2(opctx2, "testdb"_sd, MODE_IX, Date_t::max());
ASSERT(opctx2->lockState()->isDbLockedForMode("testdb"_sd, MODE_IX));
ASSERT_THROWS_CODE(
- Lock::CollectionLock(
- opctx2->lockState(), "testdb.test"_sd, MODE_X, Date_t::now() + timeoutMillis),
+ Lock::CollectionLock(opctx2, "testdb.test"_sd, MODE_X, Date_t::now() + timeoutMillis),
AssertionException,
ErrorCodes::LockTimeout);
Date_t t2 = Date_t::now();
diff --git a/src/mongo/db/free_mon/free_mon_storage_test.cpp b/src/mongo/db/free_mon/free_mon_storage_test.cpp
index cee222c7dcf..396cedd5770 100644
--- a/src/mongo/db/free_mon/free_mon_storage_test.cpp
+++ b/src/mongo/db/free_mon/free_mon_storage_test.cpp
@@ -232,7 +232,7 @@ void insertDoc(OperationContext* optCtx, const NamespaceString nss, StringData i
auto storageInterface = repl::StorageInterface::get(optCtx);
Lock::DBLock dblk(optCtx, nss.db(), MODE_IS);
- Lock::CollectionLock lk(optCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock lk(optCtx, nss.ns(), MODE_IS);
BSONObj fakeDoc = BSON("_id" << id);
BSONElement elementKey = fakeDoc.firstElement();
diff --git a/src/mongo/db/index_builder.cpp b/src/mongo/db/index_builder.cpp
index 41d97c164b9..19ff41fdee9 100644
--- a/src/mongo/db/index_builder.cpp
+++ b/src/mongo/db/index_builder.cpp
@@ -163,7 +163,7 @@ Status IndexBuilder::_build(OperationContext* opCtx,
}
{
- Lock::CollectionLock collLock(opCtx->lockState(), ns.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, ns.ns(), MODE_IX);
// WriteConflict exceptions and statuses are not expected to escape this method.
status = indexer.insertAllDocumentsInCollection(opCtx, coll);
}
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index 245e48abd0e..1bf3ef9ab12 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -846,7 +846,7 @@ void IndexBuildsCoordinator::_buildIndex(OperationContext* opCtx,
// Collection scan and insert into index, followed by a drain of writes received in the
// background.
{
- Lock::CollectionLock colLock(opCtx->lockState(), nss.ns(), MODE_IX);
+ Lock::CollectionLock colLock(opCtx, nss.ns(), MODE_IX);
uassertStatusOK(
_indexBuildsManager.startBuildingIndex(opCtx, collection, replState->buildUUID));
}
@@ -859,7 +859,7 @@ void IndexBuildsCoordinator::_buildIndex(OperationContext* opCtx,
// Perform the first drain while holding an intent lock.
{
opCtx->recoveryUnit()->abandonSnapshot();
- Lock::CollectionLock colLock(opCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock colLock(opCtx, nss.ns(), MODE_IS);
// Read at a point in time so that the drain, which will timestamp writes at lastApplied,
// can never commit writes earlier than its read timestamp.
@@ -875,7 +875,7 @@ void IndexBuildsCoordinator::_buildIndex(OperationContext* opCtx,
// Perform the second drain while stopping writes on the collection.
{
opCtx->recoveryUnit()->abandonSnapshot();
- Lock::CollectionLock colLock(opCtx->lockState(), nss.ns(), MODE_S);
+ Lock::CollectionLock colLock(opCtx, nss.ns(), MODE_S);
uassertStatusOK(_indexBuildsManager.drainBackgroundWrites(
opCtx, replState->buildUUID, RecoveryUnit::ReadSource::kUnset));
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index bff47300a08..02823701286 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -153,7 +153,7 @@ void profile(OperationContext* opCtx, NetworkOp op) {
break;
}
- Lock::CollectionLock collLock(opCtx->lockState(), db->getProfilingNS(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, db->getProfilingNS(), MODE_IX);
Collection* const coll = db->getCollection(opCtx, db->getProfilingNS());
if (coll) {
diff --git a/src/mongo/db/matcher/expression_text.cpp b/src/mongo/db/matcher/expression_text.cpp
index 7ff0317c424..0522f160b6f 100644
--- a/src/mongo/db/matcher/expression_text.cpp
+++ b/src/mongo/db/matcher/expression_text.cpp
@@ -57,7 +57,7 @@ TextMatchExpression::TextMatchExpression(OperationContext* opCtx,
{
// Find text index.
AutoGetDb autoDb(opCtx, nss.db(), MODE_IS);
- Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss.ns(), MODE_IS);
Database* db = autoDb.getDb();
uassert(ErrorCodes::IndexNotFound,
diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp
index d215450b169..60225819528 100644
--- a/src/mongo/db/pipeline/document_source_cursor.cpp
+++ b/src/mongo/db/pipeline/document_source_cursor.cpp
@@ -231,7 +231,7 @@ Value DocumentSourceCursor::serialize(boost::optional<ExplainOptions::Verbosity>
auto opCtx = pExpCtx->opCtx;
auto lockMode = getLockModeForQuery(opCtx, _exec->nss());
AutoGetDb dbLock(opCtx, _exec->nss().db(), lockMode);
- Lock::CollectionLock collLock(opCtx->lockState(), _exec->nss().ns(), lockMode);
+ Lock::CollectionLock collLock(opCtx, _exec->nss().ns(), lockMode);
auto collection =
dbLock.getDb() ? dbLock.getDb()->getCollection(opCtx, _exec->nss()) : nullptr;
diff --git a/src/mongo/db/pipeline/process_interface_shardsvr.cpp b/src/mongo/db/pipeline/process_interface_shardsvr.cpp
index befc7a78231..0579bf7a00d 100644
--- a/src/mongo/db/pipeline/process_interface_shardsvr.cpp
+++ b/src/mongo/db/pipeline/process_interface_shardsvr.cpp
@@ -93,7 +93,7 @@ MongoInterfaceShardServer::collectDocumentKeyFieldsForHostedCollection(Operation
const auto metadata = [opCtx, &nss]() -> ScopedCollectionMetadata {
Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS);
- Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss.ns(), MODE_IS);
return CollectionShardingState::get(opCtx, nss)->getCurrentMetadata();
}();
diff --git a/src/mongo/db/pipeline/process_interface_standalone.cpp b/src/mongo/db/pipeline/process_interface_standalone.cpp
index ca8f42f7d16..10966e422ff 100644
--- a/src/mongo/db/pipeline/process_interface_standalone.cpp
+++ b/src/mongo/db/pipeline/process_interface_standalone.cpp
@@ -172,7 +172,7 @@ repl::OplogEntry MongoInterfaceStandalone::lookUpOplogEntryByOpTime(OperationCon
bool MongoInterfaceStandalone::isSharded(OperationContext* opCtx, const NamespaceString& nss) {
Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS);
- Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss.ns(), MODE_IS);
const auto metadata = CollectionShardingState::get(opCtx, nss)->getCurrentMetadata();
return metadata->isSharded();
}
@@ -536,7 +536,7 @@ bool MongoInterfaceStandalone::uniqueKeyIsSupportedByIndex(
// db version or do anything else. We simply want to protect against concurrent modifications to
// the catalog.
Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS);
- Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss.ns(), MODE_IS);
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, nss.db());
auto collection = db ? db->getCollection(opCtx, nss) : nullptr;
diff --git a/src/mongo/db/read_concern_mongod.cpp b/src/mongo/db/read_concern_mongod.cpp
index 7e1d0b101db..d40034db066 100644
--- a/src/mongo/db/read_concern_mongod.cpp
+++ b/src/mongo/db/read_concern_mongod.cpp
@@ -381,7 +381,7 @@ MONGO_REGISTER_SHIM(waitForLinearizableReadConcern)
{
Lock::DBLock lk(opCtx, "local", MODE_IX);
- Lock::CollectionLock lock(opCtx->lockState(), "local.oplog.rs", MODE_IX);
+ Lock::CollectionLock lock(opCtx, "local.oplog.rs", MODE_IX);
if (!replCoord->canAcceptWritesForDatabase(opCtx, "admin")) {
return {ErrorCodes::NotMaster,
diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp
index c10e5165f74..ec1cca4a84e 100644
--- a/src/mongo/db/repl/apply_ops.cpp
+++ b/src/mongo/db/repl/apply_ops.cpp
@@ -155,7 +155,7 @@ Status _applyOps(OperationContext* opCtx,
// implicitly created on upserts. We detect both cases here and fail early with
// NamespaceNotFound.
// Additionally for inserts, we fail early on non-existent collections.
- Lock::CollectionLock collectionLock(opCtx->lockState(), nss.ns(), MODE_IX);
+ Lock::CollectionLock collectionLock(opCtx, nss.ns(), MODE_IX);
auto collection = db->getCollection(opCtx, nss);
if (!collection && (*opType == 'i' || *opType == 'u')) {
uasserted(
diff --git a/src/mongo/db/repl/dbcheck.cpp b/src/mongo/db/repl/dbcheck.cpp
index c62c6020c06..a79dd182008 100644
--- a/src/mongo/db/repl/dbcheck.cpp
+++ b/src/mongo/db/repl/dbcheck.cpp
@@ -374,7 +374,7 @@ AutoGetDbForDbCheck::AutoGetDbForDbCheck(OperationContext* opCtx, const Namespac
AutoGetCollectionForDbCheck::AutoGetCollectionForDbCheck(OperationContext* opCtx,
const NamespaceString& nss,
const OplogEntriesEnum& type)
- : _agd(opCtx, nss), _collLock(opCtx->lockState(), nss.ns(), MODE_S) {
+ : _agd(opCtx, nss), _collLock(opCtx, nss.ns(), MODE_S) {
std::string msg;
_collection = _agd.getDb() ? _agd.getDb()->getCollection(opCtx, nss) : nullptr;
diff --git a/src/mongo/db/repl/do_txn.cpp b/src/mongo/db/repl/do_txn.cpp
index fe1ce92052c..a533c25bcba 100644
--- a/src/mongo/db/repl/do_txn.cpp
+++ b/src/mongo/db/repl/do_txn.cpp
@@ -140,7 +140,7 @@ Status _doTxn(OperationContext* opCtx,
str::stream() << "cannot find collection uuid " << uuidStatus.getValue(),
!nss.isEmpty());
}
- Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, nss.ns(), MODE_IX);
auto collection = db->getCollection(opCtx, nss);
// When processing an update on a non-existent collection, applyOperation_inlock()
diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp
index 692d667bafe..568fa6a1830 100644
--- a/src/mongo/db/repl/idempotency_test_fixture.cpp
+++ b/src/mongo/db/repl/idempotency_test_fixture.cpp
@@ -489,7 +489,7 @@ CollectionState IdempotencyTest::validate() {
BSONObjBuilder bob;
Lock::DBLock lk(_opCtx.get(), nss.db(), MODE_IX);
- auto lock = stdx::make_unique<Lock::CollectionLock>(_opCtx->lockState(), nss.ns(), MODE_X);
+ auto lock = stdx::make_unique<Lock::CollectionLock>(_opCtx.get(), nss.ns(), MODE_X);
ASSERT_OK(collection->validate(
_opCtx.get(), kValidateFull, false, std::move(lock), &validateResults, &bob));
ASSERT_TRUE(validateResults.valid);
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index c957994bba9..f23a0a0e9e5 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -600,7 +600,7 @@ OpTime logOp(OperationContext* opCtx,
boost::optional<Lock::CollectionLock> collWriteLock;
if (!opCtx->getServiceContext()->getStorageEngine()->supportsDocLocking()) {
dbWriteLock.emplace(opCtx, NamespaceString::kLocalDb, MODE_IX);
- collWriteLock.emplace(opCtx->lockState(), oplogInfo.oplogName, MODE_IX);
+ collWriteLock.emplace(opCtx, oplogInfo.oplogName, MODE_IX);
}
auto const oplog = oplogInfo.oplog;
@@ -661,7 +661,7 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
boost::optional<Lock::CollectionLock> collWriteLock;
if (!opCtx->getServiceContext()->getStorageEngine()->supportsDocLocking()) {
dbWriteLock.emplace(opCtx, NamespaceString::kLocalDb, MODE_IX);
- collWriteLock.emplace(opCtx->lockState(), oplogInfo.oplogName, MODE_IX);
+ collWriteLock.emplace(opCtx, oplogInfo.oplogName, MODE_IX);
}
auto oplog = oplogInfo.oplog;
diff --git a/src/mongo/db/repl/oplog_interface_local.cpp b/src/mongo/db/repl/oplog_interface_local.cpp
index 4a0ec3a9551..861ad40215f 100644
--- a/src/mongo/db/repl/oplog_interface_local.cpp
+++ b/src/mongo/db/repl/oplog_interface_local.cpp
@@ -58,7 +58,7 @@ private:
OplogIteratorLocal::OplogIteratorLocal(OperationContext* opCtx, const std::string& collectionName)
: _dbLock(opCtx, nsToDatabase(collectionName), MODE_IS),
- _collectionLock(opCtx->lockState(), collectionName, MODE_S),
+ _collectionLock(opCtx, collectionName, MODE_S),
_ctx(opCtx, collectionName),
_exec(InternalPlanner::collectionScan(opCtx,
collectionName,
diff --git a/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp b/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp
index 1a14281b863..acdbbc05a40 100644
--- a/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp
+++ b/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp
@@ -69,7 +69,7 @@ NamespaceString makeNamespace(const T& t, const std::string& suffix = "") {
BSONObj getMinValidDocument(OperationContext* opCtx, const NamespaceString& minValidNss) {
return writeConflictRetry(opCtx, "getMinValidDocument", minValidNss.ns(), [opCtx, minValidNss] {
Lock::DBLock dblk(opCtx, minValidNss.db(), MODE_IS);
- Lock::CollectionLock lk(opCtx->lockState(), minValidNss.ns(), MODE_IS);
+ Lock::CollectionLock lk(opCtx, minValidNss.ns(), MODE_IS);
BSONObj mv;
if (Helpers::getSingleton(opCtx, minValidNss.ns().c_str(), mv)) {
return mv;
@@ -89,7 +89,7 @@ BSONObj getOplogTruncateAfterPointDocument(OperationContext* opCtx,
oplogTruncateAfterPointNss.ns(),
[opCtx, oplogTruncateAfterPointNss] {
Lock::DBLock dblk(opCtx, oplogTruncateAfterPointNss.db(), MODE_IS);
- Lock::CollectionLock lk(opCtx->lockState(), oplogTruncateAfterPointNss.ns(), MODE_IS);
+ Lock::CollectionLock lk(opCtx, oplogTruncateAfterPointNss.ns(), MODE_IS);
BSONObj mv;
if (Helpers::getSingleton(opCtx, oplogTruncateAfterPointNss.ns().c_str(), mv)) {
return mv;
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index c9fbbfaac91..41f532445ce 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -494,7 +494,7 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx,
Timer timer;
const NamespaceString oplogNss(NamespaceString::kRsOplogNamespace);
AutoGetDb autoDb(opCtx, oplogNss.db(), MODE_IX);
- Lock::CollectionLock oplogCollectionLoc(opCtx->lockState(), oplogNss.ns(), MODE_X);
+ Lock::CollectionLock oplogCollectionLoc(opCtx, oplogNss.ns(), MODE_X);
Collection* oplogCollection = autoDb.getDb()->getCollection(opCtx, oplogNss);
if (!oplogCollection) {
fassertFailedWithStatusNoTrace(
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index 45a9a4a3458..7259e88210e 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -1471,7 +1471,7 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
{
const NamespaceString oplogNss(NamespaceString::kRsOplogNamespace);
Lock::DBLock oplogDbLock(opCtx, oplogNss.db(), MODE_IX);
- Lock::CollectionLock oplogCollectionLoc(opCtx->lockState(), oplogNss.ns(), MODE_X);
+ Lock::CollectionLock oplogCollectionLoc(opCtx, oplogNss.ns(), MODE_X);
OldClientContext ctx(opCtx, oplogNss.ns());
Collection* oplogCollection = ctx.db()->getCollection(opCtx, oplogNss);
if (!oplogCollection) {
diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp
index 2b646b8f3a3..30b7608e577 100644
--- a/src/mongo/db/repl/rs_rollback_test.cpp
+++ b/src/mongo/db/repl/rs_rollback_test.cpp
@@ -341,7 +341,7 @@ int _testRollbackDelete(OperationContext* opCtx,
ASSERT_TRUE(rollbackSource.called);
Lock::DBLock dbLock(opCtx, "test", MODE_S);
- Lock::CollectionLock collLock(opCtx->lockState(), "test.t", MODE_S);
+ Lock::CollectionLock collLock(opCtx, "test.t", MODE_S);
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, "test");
ASSERT_TRUE(db);
diff --git a/src/mongo/db/s/implicit_create_collection.cpp b/src/mongo/db/s/implicit_create_collection.cpp
index 81bf1e04631..2ba0c9f945b 100644
--- a/src/mongo/db/s/implicit_create_collection.cpp
+++ b/src/mongo/db/s/implicit_create_collection.cpp
@@ -97,7 +97,7 @@ public:
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, _ns.db());
if (db) {
- Lock::CollectionLock collLock(opCtx->lockState(), _ns.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, _ns.ns(), MODE_IS);
if (db->getCollection(opCtx, _ns.ns())) {
// Collection already created, no more work needs to be done.
return Status::OK();
diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp
index d77baa5ec17..e96d5a7603d 100644
--- a/src/mongo/db/s/set_shard_version_command.cpp
+++ b/src/mongo/db/s/set_shard_version_command.cpp
@@ -229,7 +229,7 @@ public:
}
boost::optional<Lock::CollectionLock> collLock;
- collLock.emplace(opCtx->lockState(), nss.ns(), MODE_IS);
+ collLock.emplace(opCtx, nss.ns(), MODE_IS);
auto* const css = CollectionShardingState::get(opCtx, nss);
const ChunkVersion collectionShardVersion = [&] {
diff --git a/src/mongo/db/sessions_collection_rs.cpp b/src/mongo/db/sessions_collection_rs.cpp
index db3e4783a66..cb986c66518 100644
--- a/src/mongo/db/sessions_collection_rs.cpp
+++ b/src/mongo/db/sessions_collection_rs.cpp
@@ -89,8 +89,7 @@ auto runIfStandaloneOrPrimary(const NamespaceString& ns, OperationContext* opCtx
bool isStandaloneOrPrimary;
{
Lock::DBLock lk(opCtx, ns.db(), MODE_IS);
- Lock::CollectionLock lock(
- opCtx->lockState(), NamespaceString::kLogicalSessionsNamespace.ns(), MODE_IS);
+ Lock::CollectionLock lock(opCtx, NamespaceString::kLogicalSessionsNamespace.ns(), MODE_IS);
auto coord = mongo::repl::ReplicationCoordinator::get(opCtx);
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index 4405ba6b10e..b4c85b12dbe 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -318,7 +318,7 @@ void TransactionParticipant::performNoopWrite(OperationContext* opCtx, StringDat
{
Lock::DBLock dbLock(opCtx, "local", MODE_IX);
- Lock::CollectionLock collectionLock(opCtx->lockState(), "local.oplog.rs", MODE_IX);
+ Lock::CollectionLock collectionLock(opCtx, "local.oplog.rs", MODE_IX);
uassert(ErrorCodes::NotMaster,
"Not primary when performing noop write for NoSuchTransaction error",
@@ -347,7 +347,7 @@ TransactionParticipant::getOldestActiveTimestamp(Timestamp stableTimestamp) {
auto nss = NamespaceString::kSessionTransactionsTableNamespace;
auto deadline = Date_t::now() + Milliseconds(100);
Lock::DBLock dbLock(opCtx.get(), nss.db(), MODE_IS, deadline);
- Lock::CollectionLock collLock(opCtx.get()->lockState(), nss.toString(), MODE_IS, deadline);
+ Lock::CollectionLock collLock(opCtx.get(), nss.toString(), MODE_IS, deadline);
auto databaseHolder = DatabaseHolder::get(opCtx.get());
auto db = databaseHolder->getDb(opCtx.get(), nss.db());
diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp
index c120bdf6837..0ce77ba0bb7 100644
--- a/src/mongo/db/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction_participant_test.cpp
@@ -1390,7 +1390,7 @@ TEST_F(TxnParticipantTest, ReacquireLocksForPreparedTransactionsOnStepUp) {
// Simulate the locking of an insert.
{
Lock::DBLock dbLock(opCtx(), "test", MODE_IX);
- Lock::CollectionLock collLock(opCtx()->lockState(), "test.foo", MODE_IX);
+ Lock::CollectionLock collLock(opCtx(), "test.foo", MODE_IX);
}
txnParticipant.prepareTransaction(opCtx(), repl::OpTime({1, 1}, 1));
txnParticipant.stashTransactionResources(opCtx());
diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp
index f32283bad27..7d263c0ae97 100644
--- a/src/mongo/db/views/durable_view_catalog.cpp
+++ b/src/mongo/db/views/durable_view_catalog.cpp
@@ -77,7 +77,7 @@ Status DurableViewCatalogImpl::iterate(OperationContext* opCtx, Callback callbac
if (!systemViews)
return Status::OK();
- Lock::CollectionLock lk(opCtx->lockState(), _db->getSystemViewsName(), MODE_IS);
+ Lock::CollectionLock lk(opCtx, _db->getSystemViewsName(), MODE_IS);
auto cursor = systemViews->getCursor(opCtx);
while (auto record = cursor->next()) {
RecordData& data = record->data;
diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp
index bb0c6211819..631bb866b5a 100644
--- a/src/mongo/dbtests/dbtests.cpp
+++ b/src/mongo/dbtests/dbtests.cpp
@@ -132,7 +132,7 @@ WriteContextForTests::WriteContextForTests(OperationContext* opCtx, StringData n
: _opCtx(opCtx), _nss(ns) {
// Lock the database and collection
_autoCreateDb.emplace(opCtx, _nss.db(), MODE_IX);
- _collLock.emplace(opCtx->lockState(), _nss.ns(), MODE_IX);
+ _collLock.emplace(opCtx, _nss.ns(), MODE_IX);
const bool doShardVersionCheck = false;
diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp
index c56bd88c2c5..290176b500f 100644
--- a/src/mongo/dbtests/validate_tests.cpp
+++ b/src/mongo/dbtests/validate_tests.cpp
@@ -86,7 +86,7 @@ protected:
lockDb(MODE_IX);
invariant(_opCtx.lockState()->isDbLockedForMode(_nss.db(), MODE_IX));
std::unique_ptr<Lock::CollectionLock> lock =
- stdx::make_unique<Lock::CollectionLock>(_opCtx.lockState(), _nss.ns(), MODE_X);
+ stdx::make_unique<Lock::CollectionLock>(&_opCtx, _nss.ns(), MODE_X);
invariant(_opCtx.lockState()->isCollectionLockedForMode(_nss, MODE_X));
Database* db = _autoDb.get()->getDb();