summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2019-04-16 17:33:20 -0400
committerGeert Bosch <geert@mongodb.com>2019-04-17 15:40:11 -0400
commite0cafae280e508ef887bd08978dcbc5630c08a34 (patch)
tree225fea823d49fcbe836a0f64d3afdfd7573ebfc5
parentbf774fb0a5e9bed81bc475585deb70812a2c9c41 (diff)
downloadmongo-e0cafae280e508ef887bd08978dcbc5630c08a34.tar.gz
SERVER-40688 Make CollectionLock take NamespaceString
-rw-r--r--src/mongo/db/catalog/collection_test.cpp2
-rw-r--r--src/mongo/db/catalog/create_collection.cpp4
-rw-r--r--src/mongo/db/catalog/database.h4
-rw-r--r--src/mongo/db/catalog/database_impl.cpp4
-rw-r--r--src/mongo/db/catalog/database_impl.h10
-rw-r--r--src/mongo/db/catalog/database_test.cpp4
-rw-r--r--src/mongo/db/catalog/drop_collection.cpp2
-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.cpp13
-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.cpp9
-rw-r--r--src/mongo/db/concurrency/d_concurrency.h2
-rw-r--r--src/mongo/db/concurrency/d_concurrency_bm.cpp12
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp21
-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.cpp12
-rw-r--r--src/mongo/db/introspect.cpp5
-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.cpp10
-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.cpp4
-rw-r--r--src/mongo/db/s/set_shard_version_command.cpp2
-rw-r--r--src/mongo/db/sessions_collection_rs.cpp2
-rw-r--r--src/mongo/db/transaction_participant.cpp4
-rw-r--r--src/mongo/db/transaction_participant_test.cpp2
-rw-r--r--src/mongo/dbtests/dbtests.cpp2
-rw-r--r--src/mongo/dbtests/validate_tests.cpp2
45 files changed, 95 insertions, 91 deletions
diff --git a/src/mongo/db/catalog/collection_test.cpp b/src/mongo/db/catalog/collection_test.cpp
index 1259e3105f6..a6486ebc9b0 100644
--- a/src/mongo/db/catalog/collection_test.cpp
+++ b/src/mongo/db/catalog/collection_test.cpp
@@ -67,7 +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, coll->ns().ns(), MODE_X);
+ auto collLock = std::make_unique<Lock::CollectionLock>(opCtx, coll->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 63af4ff62bc..cc0dd7959ec 100644
--- a/src/mongo/db/catalog/create_collection.cpp
+++ b/src/mongo/db/catalog/create_collection.cpp
@@ -59,9 +59,9 @@ Status _createView(OperationContext* opCtx,
AutoGetOrCreateDb autoDb(opCtx, nss.db(), MODE_IX);
Lock::CollectionLock systemViewsLock(
opCtx,
- NamespaceString(nss.db(), NamespaceString::kSystemDotViewsCollectionName).toString(),
+ NamespaceString(nss.db(), NamespaceString::kSystemDotViewsCollectionName),
MODE_X);
- Lock::CollectionLock collLock(opCtx, nss.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, nss, MODE_IX);
Database* db = autoDb.getDb();
diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h
index d494ea6c153..fe6be299938 100644
--- a/src/mongo/db/catalog/database.h
+++ b/src/mongo/db/catalog/database.h
@@ -99,7 +99,7 @@ public:
virtual int getProfilingLevel() const = 0;
- virtual const char* getProfilingNS() const = 0;
+ virtual const NamespaceString& getProfilingNS() const = 0;
/**
* Sets the 'drop-pending' state of this Database.
@@ -164,7 +164,7 @@ public:
const StringData toNS,
const bool stayTemp) const = 0;
- virtual const std::string& getSystemViewsName() const = 0;
+ virtual const NamespaceString& getSystemViewsName() const = 0;
/**
* Generates a collection namespace suitable for creating a temporary collection.
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index af7cf7b8d56..47372e7f5cd 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -279,8 +279,8 @@ 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, nss.ns(), MODE_IS);
- Collection* collection = getCollection(opCtx, nss.ns());
+ Lock::CollectionLock colLock(opCtx, nss, MODE_IS);
+ Collection* collection = getCollection(opCtx, nss);
if (!collection)
continue;
diff --git a/src/mongo/db/catalog/database_impl.h b/src/mongo/db/catalog/database_impl.h
index d761cd02866..bb9fd30b2a3 100644
--- a/src/mongo/db/catalog/database_impl.h
+++ b/src/mongo/db/catalog/database_impl.h
@@ -62,8 +62,8 @@ public:
int getProfilingLevel() const final {
return _profile.load();
}
- const char* getProfilingNS() const final {
- return _profileName.c_str();
+ const NamespaceString& getProfilingNS() const final {
+ return _profileName;
}
void setDropPending(OperationContext* opCtx, bool dropPending) final;
@@ -132,7 +132,7 @@ public:
static Status validateDBName(StringData dbname);
- const std::string& getSystemViewsName() const final {
+ const NamespaceString& getSystemViewsName() const final {
return _viewsName;
}
@@ -182,8 +182,8 @@ private:
const uint64_t _epoch;
- const std::string _profileName; // "dbname.system.profile"
- const std::string _viewsName; // "dbname.system.views"
+ const NamespaceString _profileName; // "dbname.system.profile"
+ const NamespaceString _viewsName; // "dbname.system.views"
AtomicWord<int> _profile{0}; // 0=off
diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp
index 6de17143f63..a1ad7565aff 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(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock(_opCtx.get(), nss, 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(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock(_opCtx.get(), nss, 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 5df9b0ba1b4..391a5a76048 100644
--- a/src/mongo/db/catalog/drop_collection.cpp
+++ b/src/mongo/db/catalog/drop_collection.cpp
@@ -67,7 +67,7 @@ Status _dropView(OperationContext* opCtx,
return Status(ErrorCodes::NamespaceNotFound, "ns not found");
}
Lock::CollectionLock systemViewsLock(opCtx, db->getSystemViewsName(), MODE_X);
- Lock::CollectionLock collLock(opCtx, collectionName.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, collectionName, 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 5a8eff8c8e6..154ea62f970 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, _resolvedNss.ns(), modeColl, deadline);
+ _collLock.emplace(opCtx, _resolvedNss, 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 d55f887ff6e..9ca2b4cdde4 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(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock1(client1.second.get(), nss, 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(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock1(client1.second.get(), nss, 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(), nss.toString(), MODE_X);
+ Lock::CollectionLock collLock1(client1.second.get(), nss, 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 368298d286c..7e93a5d4366 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -301,7 +301,7 @@ bool runCreateIndexes(OperationContext* opCtx,
opCtx->recoveryUnit()->abandonSnapshot();
boost::optional<Lock::CollectionLock> exclusiveCollectionLock(
- boost::in_place_init, opCtx, ns.ns(), MODE_X);
+ boost::in_place_init, opCtx, ns, MODE_X);
// Allow the strong lock acquisition above to be interrupted, but from this point forward do
// not allow locks or re-locks to be interrupted.
@@ -362,7 +362,7 @@ bool runCreateIndexes(OperationContext* opCtx,
ON_BLOCK_EXIT([&] {
if (!exclusiveCollectionLock) {
opCtx->recoveryUnit()->abandonSnapshot();
- exclusiveCollectionLock.emplace(opCtx, ns.ns(), MODE_X);
+ exclusiveCollectionLock.emplace(opCtx, ns, MODE_X);
}
if (MONGO_FAIL_POINT(leaveIndexBuildUnfinishedForShutdown)) {
// Set a flag to leave the persisted index build state intact when cleanUpAfterBuild()
@@ -397,7 +397,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, ns.ns(), MODE_IS);
+ Lock::CollectionLock colLock(opCtx, ns, MODE_IS);
uassertStatusOK(indexer.insertAllDocumentsInCollection(opCtx, collection));
}
@@ -409,7 +409,7 @@ bool runCreateIndexes(OperationContext* opCtx,
// Perform the first drain while holding an intent lock.
{
opCtx->recoveryUnit()->abandonSnapshot();
- Lock::CollectionLock colLock(opCtx, ns.ns(), MODE_IS);
+ Lock::CollectionLock colLock(opCtx, 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.
@@ -424,7 +424,8 @@ bool runCreateIndexes(OperationContext* opCtx,
// Perform the second drain while stopping writes on the collection.
{
opCtx->recoveryUnit()->abandonSnapshot();
- Lock::CollectionLock colLock(opCtx, ns.ns(), MODE_S);
+ Lock::CollectionLock colLock(opCtx, ns, MODE_S);
+
uassertStatusOK(indexer.drainBackgroundWrites(opCtx));
}
@@ -436,7 +437,7 @@ bool runCreateIndexes(OperationContext* opCtx,
// Need to get exclusive collection lock back to complete the index build.
if (indexer.isBackgroundBuilding()) {
opCtx->recoveryUnit()->abandonSnapshot();
- exclusiveCollectionLock.emplace(opCtx, ns.ns(), MODE_X);
+ exclusiveCollectionLock.emplace(opCtx, ns, MODE_X);
}
db = databaseHolder->getDb(opCtx, ns.db());
diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp
index 1b03fb04e4d..5bede2d66f6 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, nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss, MODE_IS);
exec.reset();
});
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 5cb1d6a09e1..97a4904a516 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, fullCollectionName, MODE_IS);
+ collLock.emplace(opCtx, ns, 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 863d379b653..8d711c43cf2 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, nss.ns(), MODE_IS);
+ Lock::CollectionLock clk(opCtx, nss, 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 b6d39449fe2..73f10c97422 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, ns, mode, Date_t::max());
+ Lock::CollectionLock lk(opCtx, NamespaceString(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 9cfe10e4dba..dbc5ff11323 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, nss.ns(), MODE_X);
+ auto collLk = stdx::make_unique<Lock::CollectionLock>(opCtx, nss, 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 0debd7b7ce8..29076651b50 100644
--- a/src/mongo/db/concurrency/d_concurrency.cpp
+++ b/src/mongo/db/concurrency/d_concurrency.cpp
@@ -277,13 +277,12 @@ void Lock::DBLock::relockWithMode(LockMode newMode) {
Lock::CollectionLock::CollectionLock(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
LockMode mode,
Date_t deadline)
- : _id(RESOURCE_COLLECTION, ns), _opCtx(opCtx) {
- massert(28538, "need a non-empty collection name", nsIsFull(ns));
-
- dassert(opCtx->lockState()->isDbLockedForMode(nsToDatabaseSubstring(ns),
+ : _id(RESOURCE_COLLECTION, nss.ns()), _opCtx(opCtx) {
+ invariant(nss.coll().size(), str::stream() << "expected non-empty collection name:" << nss);
+ dassert(opCtx->lockState()->isDbLockedForMode(nss.db(),
isSharedLockMode(mode) ? MODE_IS : MODE_IX));
LockMode actualLockMode = mode;
if (!supportsDocLocking()) {
diff --git a/src/mongo/db/concurrency/d_concurrency.h b/src/mongo/db/concurrency/d_concurrency.h
index 7300824373c..5e9bd6a94a2 100644
--- a/src/mongo/db/concurrency/d_concurrency.h
+++ b/src/mongo/db/concurrency/d_concurrency.h
@@ -357,7 +357,7 @@ public:
public:
CollectionLock(OperationContext* opCtx,
- StringData ns,
+ const NamespaceString& nss,
LockMode mode,
Date_t deadline = Date_t::max());
CollectionLock(CollectionLock&&);
diff --git a/src/mongo/db/concurrency/d_concurrency_bm.cpp b/src/mongo/db/concurrency/d_concurrency_bm.cpp
index de643c34374..c375ffdd73f 100644
--- a/src/mongo/db/concurrency/d_concurrency_bm.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_bm.cpp
@@ -100,7 +100,8 @@ 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.get(), "test.coll", MODE_IS);
+ Lock::CollectionLock clk(
+ clients[state.thread_index].second.get(), NamespaceString("test.coll"), MODE_IS);
}
if (state.thread_index == 0) {
@@ -118,7 +119,8 @@ 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.get(), "test.coll", MODE_IX);
+ Lock::CollectionLock clk(
+ clients[state.thread_index].second.get(), NamespaceString("test.coll"), MODE_IX);
}
if (state.thread_index == 0) {
@@ -136,7 +138,8 @@ 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.get(), "test.coll", MODE_S);
+ Lock::CollectionLock clk(
+ clients[state.thread_index].second.get(), NamespaceString("test.coll"), MODE_S);
}
if (state.thread_index == 0) {
@@ -154,7 +157,8 @@ 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.get(), "test.coll", MODE_X);
+ Lock::CollectionLock clk(
+ clients[state.thread_index].second.get(), NamespaceString("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 7e2b70472bd..cbe7d62bf35 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -1176,7 +1176,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
Lock::DBLock dbLock(opCtx.get(), "db1", MODE_IS);
{
- Lock::CollectionLock collLock(opCtx.get(), ns.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx.get(), ns, MODE_IS);
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IS));
ASSERT(!lockState->isCollectionLockedForMode(ns, MODE_IX));
@@ -1188,7 +1188,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IS) {
}
{
- Lock::CollectionLock collLock(opCtx.get(), ns.ns(), MODE_S);
+ Lock::CollectionLock collLock(opCtx.get(), ns, MODE_S);
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IS));
ASSERT(!lockState->isCollectionLockedForMode(ns, MODE_IX));
@@ -1207,7 +1207,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IX) {
Lock::DBLock dbLock(opCtx.get(), "db1", MODE_IX);
{
- Lock::CollectionLock collLock(opCtx.get(), ns.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx.get(), ns, MODE_IX);
// TODO: This is TRUE because Lock::CollectionLock converts IX lock to X
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IS));
@@ -1218,7 +1218,7 @@ TEST_F(DConcurrencyTestFixture, IsCollectionLocked_DB_Locked_IX) {
}
{
- Lock::CollectionLock collLock(opCtx.get(), ns.ns(), MODE_X);
+ Lock::CollectionLock collLock(opCtx.get(), ns, MODE_X);
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IS));
ASSERT(lockState->isCollectionLockedForMode(ns, MODE_IX));
@@ -1749,7 +1749,7 @@ TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextThrowsEvenWhen
{
boost::optional<Lock::CollectionLock> collLock;
- ASSERT_THROWS_CODE(collLock.emplace(opCtx, "db.coll", MODE_IX),
+ ASSERT_THROWS_CODE(collLock.emplace(opCtx, NamespaceString("db.coll"), MODE_IX),
AssertionException,
ErrorCodes::Interrupted);
}
@@ -1761,13 +1761,13 @@ TEST_F(DConcurrencyTestFixture,
auto opCtx = clients[0].second.get();
Lock::DBLock dbLock(opCtx, "db", MODE_IX);
- Lock::CollectionLock collLock(opCtx, "db.coll", MODE_IX);
+ Lock::CollectionLock collLock(opCtx, NamespaceString("db.coll"), MODE_IX);
opCtx->markKilled();
{
boost::optional<Lock::CollectionLock> recursiveCollLock;
- ASSERT_THROWS_CODE(recursiveCollLock.emplace(opCtx, "db.coll", MODE_X),
+ ASSERT_THROWS_CODE(recursiveCollLock.emplace(opCtx, NamespaceString("db.coll"), MODE_X),
AssertionException,
ErrorCodes::Interrupted);
}
@@ -1782,7 +1782,7 @@ TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextRespectsUninte
opCtx->markKilled();
UninterruptibleLockGuard noInterrupt(opCtx->lockState());
- Lock::CollectionLock collLock(opCtx, "db.coll", MODE_IX); // Does not throw.
+ Lock::CollectionLock collLock(opCtx, NamespaceString("db.coll"), MODE_IX); // Does not throw.
}
TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) {
@@ -1794,14 +1794,15 @@ 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, "testdb.test"_sd, MODE_X, Date_t::max());
+ Lock::CollectionLock CL1(opctx1, NamespaceString("testdb.test"), 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, "testdb.test"_sd, MODE_X, Date_t::now() + timeoutMillis),
+ Lock::CollectionLock(
+ opctx2, NamespaceString("testdb.test"), 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 396cedd5770..dc813d35e4b 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, nss.ns(), MODE_IS);
+ Lock::CollectionLock lk(optCtx, nss, 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 19ff41fdee9..a2f25c3475c 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, ns.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, 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 1bf3ef9ab12..243e5755d20 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, nss.ns(), MODE_IX);
+ Lock::CollectionLock colLock(opCtx, nss, 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, nss.ns(), MODE_IS);
+ Lock::CollectionLock colLock(opCtx, nss, 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, nss.ns(), MODE_S);
+ Lock::CollectionLock colLock(opCtx, nss, MODE_S);
uassertStatusOK(_indexBuildsManager.drainBackgroundWrites(
opCtx, replState->buildUUID, RecoveryUnit::ReadSource::kUnset));
@@ -904,7 +904,7 @@ void IndexBuildsCoordinator::_buildIndex(OperationContext* opCtx,
str::stream() << "Database not found after relocking. Index build: "
<< replState->buildUUID
<< ": "
- << nss.ns()
+ << nss
<< " ("
<< replState->collectionUUID
<< ")");
@@ -912,7 +912,7 @@ void IndexBuildsCoordinator::_buildIndex(OperationContext* opCtx,
str::stream() << "Collection not found after relocking. Index build: "
<< replState->buildUUID
<< ": "
- << nss.ns()
+ << nss
<< " ("
<< replState->collectionUUID
<< ")");
@@ -1106,7 +1106,7 @@ int IndexBuildsCoordinator::_getNumIndexesTotal(OperationContext* opCtx, Collect
<< nss);
auto indexCatalog = collection->getIndexCatalog();
- invariant(indexCatalog, str::stream() << "Collection is missing index catalog: " << nss.ns());
+ invariant(indexCatalog, str::stream() << "Collection is missing index catalog: " << nss);
return indexCatalog->numIndexesTotal(opCtx);
}
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index 02823701286..606bec261d7 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -193,8 +193,7 @@ void profile(OperationContext* opCtx, NetworkOp op) {
Status createProfileCollection(OperationContext* opCtx, Database* db) {
invariant(opCtx->lockState()->isDbLockedForMode(db->name(), MODE_X));
- const std::string dbProfilingNS(db->getProfilingNS());
-
+ auto& dbProfilingNS = db->getProfilingNS();
Collection* const collection = db->getCollection(opCtx, dbProfilingNS);
if (collection) {
if (!collection->isCapped()) {
@@ -214,7 +213,7 @@ Status createProfileCollection(OperationContext* opCtx, Database* db) {
WriteUnitOfWork wunit(opCtx);
repl::UnreplicatedWritesBlock uwb(opCtx);
- invariant(db->createCollection(opCtx, dbProfilingNS, collectionOptions));
+ invariant(db->createCollection(opCtx, dbProfilingNS.ns(), collectionOptions));
wunit.commit();
return Status::OK();
diff --git a/src/mongo/db/matcher/expression_text.cpp b/src/mongo/db/matcher/expression_text.cpp
index 0522f160b6f..8fdcd65befc 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, nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss, 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 60225819528..0015d915acc 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, _exec->nss().ns(), lockMode);
+ Lock::CollectionLock collLock(opCtx, _exec->nss(), 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 0579bf7a00d..3d54341c325 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, nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss, 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 10966e422ff..0a60ce26907 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, nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss, 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, nss.ns(), MODE_IS);
+ Lock::CollectionLock collLock(opCtx, nss, 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 d40034db066..de45682e0f4 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, "local.oplog.rs", MODE_IX);
+ Lock::CollectionLock lock(opCtx, NamespaceString("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 ec1cca4a84e..8e3a8105667 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, nss.ns(), MODE_IX);
+ Lock::CollectionLock collectionLock(opCtx, nss, 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 a79dd182008..2f16cbacf6e 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, nss.ns(), MODE_S) {
+ : _agd(opCtx, nss), _collLock(opCtx, nss, 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 a533c25bcba..3fb6f97f4e4 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, nss.ns(), MODE_IX);
+ Lock::CollectionLock collLock(opCtx, nss, 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 568fa6a1830..984c9f84577 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.get(), nss.ns(), MODE_X);
+ auto lock = stdx::make_unique<Lock::CollectionLock>(_opCtx.get(), nss, 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 f23a0a0e9e5..2a3dcd239d0 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -127,7 +127,7 @@ struct LocalOplogInfo {
LocalOplogInfo() = default;
// Name of the oplog collection.
- std::string oplogName;
+ NamespaceString oplogName;
// The "oplog" pointer is always valid (or null) because an operation must take the global
// exclusive lock to set the pointer to null when the Collection instance is destroyed. See
@@ -259,7 +259,7 @@ bool shouldBuildInForeground(OperationContext* opCtx,
void setOplogCollectionName(ServiceContext* service) {
switch (ReplicationCoordinator::get(service)->getReplicationMode()) {
case ReplicationCoordinator::modeReplSet:
- localOplogInfo(service).oplogName = NamespaceString::kRsOplogNamespace.ns();
+ localOplogInfo(service).oplogName = NamespaceString::kRsOplogNamespace;
break;
case ReplicationCoordinator::modeNone:
// leave empty.
@@ -837,7 +837,7 @@ void createOplog(OperationContext* opCtx, const std::string& oplogCollectionName
void createOplog(OperationContext* opCtx) {
const auto isReplSet = ReplicationCoordinator::get(opCtx)->getReplicationMode() ==
ReplicationCoordinator::modeReplSet;
- createOplog(opCtx, localOplogInfo(opCtx->getServiceContext()).oplogName, isReplSet);
+ createOplog(opCtx, localOplogInfo(opCtx->getServiceContext()).oplogName.ns(), isReplSet);
}
OplogSlot getNextOpTimeNoPersistForTesting(OperationContext* opCtx) {
@@ -2102,8 +2102,8 @@ void clearLocalOplogPtr() {
void acquireOplogCollectionForLogging(OperationContext* opCtx) {
auto& oplogInfo = localOplogInfo(opCtx->getServiceContext());
- if (!oplogInfo.oplogName.empty()) {
- AutoGetCollection autoColl(opCtx, NamespaceString(oplogInfo.oplogName), MODE_IX);
+ if (!oplogInfo.oplogName.isEmpty()) {
+ AutoGetCollection autoColl(opCtx, oplogInfo.oplogName, MODE_IX);
oplogInfo.oplog = autoColl.getCollection();
}
}
diff --git a/src/mongo/db/repl/oplog_interface_local.cpp b/src/mongo/db/repl/oplog_interface_local.cpp
index 861ad40215f..cc6c4ac6e20 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, collectionName, MODE_S),
+ _collectionLock(opCtx, NamespaceString(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 acdbbc05a40..d6f103a4113 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, minValidNss.ns(), MODE_IS);
+ Lock::CollectionLock lk(opCtx, minValidNss, 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, oplogTruncateAfterPointNss.ns(), MODE_IS);
+ Lock::CollectionLock lk(opCtx, oplogTruncateAfterPointNss, 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 41f532445ce..41df37761a9 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, oplogNss.ns(), MODE_X);
+ Lock::CollectionLock oplogCollectionLoc(opCtx, oplogNss, 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 7259e88210e..2f9b3bc34d6 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, oplogNss.ns(), MODE_X);
+ Lock::CollectionLock oplogCollectionLoc(opCtx, oplogNss, 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 30b7608e577..abe2ba25a3a 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, "test.t", MODE_S);
+ Lock::CollectionLock collLock(opCtx, NamespaceString("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 2ba0c9f945b..7ea8c1e1345 100644
--- a/src/mongo/db/s/implicit_create_collection.cpp
+++ b/src/mongo/db/s/implicit_create_collection.cpp
@@ -97,8 +97,8 @@ public:
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, _ns.db());
if (db) {
- Lock::CollectionLock collLock(opCtx, _ns.ns(), MODE_IS);
- if (db->getCollection(opCtx, _ns.ns())) {
+ Lock::CollectionLock collLock(opCtx, _ns, MODE_IS);
+ if (db->getCollection(opCtx, _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 e96d5a7603d..0eb2fbde66c 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, nss.ns(), MODE_IS);
+ collLock.emplace(opCtx, nss, 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 cb986c66518..1cabfb99af2 100644
--- a/src/mongo/db/sessions_collection_rs.cpp
+++ b/src/mongo/db/sessions_collection_rs.cpp
@@ -89,7 +89,7 @@ auto runIfStandaloneOrPrimary(const NamespaceString& ns, OperationContext* opCtx
bool isStandaloneOrPrimary;
{
Lock::DBLock lk(opCtx, ns.db(), MODE_IS);
- Lock::CollectionLock lock(opCtx, NamespaceString::kLogicalSessionsNamespace.ns(), MODE_IS);
+ Lock::CollectionLock lock(opCtx, NamespaceString::kLogicalSessionsNamespace, 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 07bea4b2de2..8bf9d8925b2 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, "local.oplog.rs", MODE_IX);
+ Lock::CollectionLock collectionLock(opCtx, NamespaceString("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(), nss.toString(), MODE_IS, deadline);
+ Lock::CollectionLock collLock(opCtx.get(), nss, 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 0ce77ba0bb7..ed2a238683f 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(), "test.foo", MODE_IX);
+ Lock::CollectionLock collLock(opCtx(), NamespaceString("test.foo"), MODE_IX);
}
txnParticipant.prepareTransaction(opCtx(), repl::OpTime({1, 1}, 1));
txnParticipant.stashTransactionResources(opCtx());
diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp
index 631bb866b5a..3a16b947f98 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, _nss.ns(), MODE_IX);
+ _collLock.emplace(opCtx, _nss, MODE_IX);
const bool doShardVersionCheck = false;
diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp
index 9fb912f9538..2a84eef2168 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, _nss.ns(), MODE_X);
+ stdx::make_unique<Lock::CollectionLock>(&_opCtx, _nss, MODE_X);
invariant(_opCtx.lockState()->isCollectionLockedForMode(_nss, MODE_X));
Database* db = _autoDb.get()->getDb();