diff options
author | jannaerin <golden.janna@gmail.com> | 2022-07-11 17:40:58 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-11 18:57:30 +0000 |
commit | 3f5e02a10ad19d4694c82d93e4a4e3a0b36c0fb1 (patch) | |
tree | 02e3b8029d4e89c24a6f3ba94840da992e55e290 /src/mongo/db | |
parent | 735e3f711ae28979811d4dcb2d35aeba6ffa460c (diff) | |
download | mongo-3f5e02a10ad19d4694c82d93e4a4e3a0b36c0fb1.tar.gz |
SERVER-63650 Change Locker::isDbLockedForMode to take in DatabaseName
Diffstat (limited to 'src/mongo/db')
32 files changed, 166 insertions, 173 deletions
diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp index 669eb59be35..b660edcb108 100644 --- a/src/mongo/db/catalog/collection_catalog.cpp +++ b/src/mongo/db/catalog/collection_catalog.cpp @@ -682,7 +682,7 @@ void CollectionCatalog::dropCollection(OperationContext* opCtx, Collection* coll void CollectionCatalog::onOpenDatabase(OperationContext* opCtx, const DatabaseName& dbName, ViewsForDatabase&& viewsForDb) { - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_IS)); uassert(ErrorCodes::AlreadyInitialized, str::stream() << "Database " << dbName << " is already initialized", _viewsForDatabase.find(dbName) == _viewsForDatabase.end()); @@ -691,7 +691,7 @@ void CollectionCatalog::onOpenDatabase(OperationContext* opCtx, } void CollectionCatalog::onCloseDatabase(OperationContext* opCtx, DatabaseName dbName) { - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_X)); auto rid = ResourceId(RESOURCE_DATABASE, dbName.toString()); removeResource(rid, dbName.toString()); _viewsForDatabase.erase(dbName); @@ -1057,7 +1057,7 @@ std::vector<UUID> CollectionCatalog::getAllCollectionUUIDsFromDb(const DatabaseN std::vector<NamespaceString> CollectionCatalog::getAllCollectionNamesFromDb( OperationContext* opCtx, const DatabaseName& dbName) const { - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_S)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_S)); auto minUuid = UUID::parse("00000000-0000-0000-0000-000000000000").getValue(); diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index 7cc18a97b12..df085ac3a54 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -681,14 +681,14 @@ void createChangeStreamPreImagesCollection(OperationContext* opCtx) { status.isOK() || status.code() == ErrorCodes::NamespaceExists); } -// TODO SERVER-62880 pass DatabaseName instead of dbName. +// TODO SERVER-62395 Pass DatabaseName instead of dbName, and pass to isDbLockedForMode. Status createCollectionForApplyOps(OperationContext* opCtx, const std::string& dbName, const boost::optional<UUID>& ui, const BSONObj& cmdObj, const bool allowRenameOutOfTheWay, const boost::optional<BSONObj>& idIndex) { - invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, dbName), MODE_IX)); const NamespaceString newCollName(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj)); auto newCmd = cmdObj; diff --git a/src/mongo/db/catalog/database_holder_impl.cpp b/src/mongo/db/catalog/database_holder_impl.cpp index 752a6288f91..f267c109b32 100644 --- a/src/mongo/db/catalog/database_holder_impl.cpp +++ b/src/mongo/db/catalog/database_holder_impl.cpp @@ -56,7 +56,7 @@ Database* DatabaseHolderImpl::getDb(OperationContext* opCtx, const DatabaseName& "invalid db name: " + dbName.db(), NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(dbName.toString(), MODE_IS) || + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_IS) || (dbName.db().compare("local") == 0 && opCtx->lockState()->isLocked())); stdx::lock_guard<SimpleMutex> lk(_m); @@ -112,7 +112,7 @@ Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, 6198701, "invalid db name: " + dbName.db(), NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_IX)); if (justCreated) *justCreated = false; // Until proven otherwise. @@ -216,7 +216,7 @@ void DatabaseHolderImpl::dropDb(OperationContext* opCtx, Database* db) { LOGV2_DEBUG(20310, 1, "dropDatabase {name}", "name"_attr = name); - invariant(opCtx->lockState()->isDbLockedForMode(name.db(), MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(name, MODE_X)); auto catalog = CollectionCatalog::get(opCtx); for (auto collIt = catalog->begin(opCtx, name); collIt != catalog->end(opCtx); ++collIt) { @@ -274,7 +274,7 @@ void DatabaseHolderImpl::close(OperationContext* opCtx, const DatabaseName& dbNa 6198700, "invalid db name: " + dbName.db(), NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_X)); stdx::lock_guard<SimpleMutex> lk(_m); @@ -330,7 +330,7 @@ void DatabaseHolderImpl::setDbInfo(OperationContext* opCtx, 6420900, "Invalid database name: " + dbName.db(), NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_X)); stdx::lock_guard<SimpleMutex> lk(_m); @@ -353,7 +353,7 @@ void DatabaseHolderImpl::clearDbInfo(OperationContext* opCtx, const DatabaseName 6420902, "Invalid database name: " + dbName.db(), NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_IX)); stdx::lock_guard<SimpleMutex> lk(_m); @@ -394,7 +394,7 @@ boost::optional<ShardId> DatabaseHolderImpl::getDbPrimary(OperationContext* opCt 6420905, "Invalid database name: " + dbName.db(), NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_IS)); stdx::lock_guard<SimpleMutex> lk(_m); diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index 1c71aa4e933..b0a0254b5da 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -118,7 +118,7 @@ Status validateDBNameForWindows(StringData dbname) { } void assertMovePrimaryInProgress(OperationContext* opCtx, NamespaceString const& nss) { - invariant(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_IS)); auto dss = DatabaseShardingState::get(opCtx, nss.db().toString()); if (!dss) { return; @@ -305,7 +305,7 @@ Status DatabaseImpl::init(OperationContext* const opCtx) { } void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) const { - invariant(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_IX)); CollectionCatalog::CollectionInfoFn callback = [&](const CollectionPtr& collection) { try { @@ -339,12 +339,12 @@ void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) const { void DatabaseImpl::setDropPending(OperationContext* opCtx, bool dropPending) { auto mode = dropPending ? MODE_X : MODE_IX; - invariant(opCtx->lockState()->isDbLockedForMode(name().db(), mode)); + invariant(opCtx->lockState()->isDbLockedForMode(name(), mode)); _dropPending.store(dropPending); } bool DatabaseImpl::isDropPending(OperationContext* opCtx) const { - invariant(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_IS)); return _dropPending.load(); } @@ -363,7 +363,7 @@ void DatabaseImpl::getStats(OperationContext* opCtx, long long indexSize = 0; long long indexFreeStorageSize = 0; - invariant(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_IS)); catalog::forEachCollectionFromDb( opCtx, name(), MODE_IS, [&](const CollectionPtr& collection) -> bool { @@ -435,7 +435,7 @@ void DatabaseImpl::getStats(OperationContext* opCtx, } Status DatabaseImpl::dropView(OperationContext* opCtx, NamespaceString viewName) const { - dassert(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(name(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(viewName, MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(NamespaceString(_viewsName), MODE_X)); @@ -783,7 +783,7 @@ void DatabaseImpl::_checkCanCreateCollection(OperationContext* opCtx, Status DatabaseImpl::createView(OperationContext* opCtx, const NamespaceString& viewName, const CollectionOptions& options) const { - dassert(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(name(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(viewName, MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(NamespaceString(_viewsName), MODE_X)); diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp index a42652457b1..d946a349cf5 100644 --- a/src/mongo/db/catalog/database_test.cpp +++ b/src/mongo/db/catalog/database_test.cpp @@ -414,10 +414,10 @@ TEST_F( TEST_F(DatabaseTest, AutoGetDBSucceedsWithDeadlineNow) { NamespaceString nss("test", "coll"); Lock::DBLock lock(_opCtx.get(), nss.dbName(), MODE_X); - ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); try { AutoGetDb db(_opCtx.get(), nss.db(), MODE_X, Date_t::now()); - ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); } catch (const ExceptionFor<ErrorCodes::LockTimeout>&) { FAIL("Should get the db within the timeout"); } @@ -426,10 +426,10 @@ TEST_F(DatabaseTest, AutoGetDBSucceedsWithDeadlineNow) { TEST_F(DatabaseTest, AutoGetDBSucceedsWithDeadlineMin) { NamespaceString nss("test", "coll"); Lock::DBLock lock(_opCtx.get(), nss.dbName(), MODE_X); - ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); try { AutoGetDb db(_opCtx.get(), nss.db(), MODE_X, Date_t()); - ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); } catch (const ExceptionFor<ErrorCodes::LockTimeout>&) { FAIL("Should get the db within the timeout"); } @@ -438,7 +438,7 @@ TEST_F(DatabaseTest, AutoGetDBSucceedsWithDeadlineMin) { TEST_F(DatabaseTest, AutoGetCollectionForReadCommandSucceedsWithDeadlineNow) { NamespaceString nss("test", "coll"); Lock::DBLock dbLock(_opCtx.get(), nss.dbName(), MODE_X); - ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); Lock::CollectionLock collLock(_opCtx.get(), nss, MODE_X); ASSERT(_opCtx.get()->lockState()->isCollectionLockedForMode(nss, MODE_X)); try { @@ -452,7 +452,7 @@ TEST_F(DatabaseTest, AutoGetCollectionForReadCommandSucceedsWithDeadlineNow) { TEST_F(DatabaseTest, AutoGetCollectionForReadCommandSucceedsWithDeadlineMin) { NamespaceString nss("test", "coll"); Lock::DBLock dbLock(_opCtx.get(), nss.dbName(), MODE_X); - ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(_opCtx.get()->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); Lock::CollectionLock collLock(_opCtx.get(), nss, MODE_X); ASSERT(_opCtx.get()->lockState()->isCollectionLockedForMode(nss, MODE_X)); try { diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp index a0d59ea05ca..634ecdec80b 100644 --- a/src/mongo/db/catalog/drop_database.cpp +++ b/src/mongo/db/catalog/drop_database.cpp @@ -92,7 +92,8 @@ void _finishDropDatabase(OperationContext* opCtx, Database* db, std::size_t numCollections, bool abortIndexBuilds) { - invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_X)); + // TODO SERVER-67549 Use dbName directly. + invariant(opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, dbName), MODE_X)); // If DatabaseHolder::dropDb() fails, we should reset the drop-pending state on Database. ScopeGuard dropPendingGuard([db, opCtx] { db->setDropPending(opCtx, false); }); diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index ccba8559e3a..e038707d438 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -155,7 +155,7 @@ Status renameTargetCollectionToTmp(OperationContext* opCtx, // The generated unique collection name is only guaranteed to exist if the database is // exclusively locked. - invariant(opCtx->lockState()->isDbLockedForMode(targetDB->name().db(), LockMode::MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(targetDB->name(), LockMode::MODE_X)); auto tmpNameResult = makeUniqueCollectionName(opCtx, targetDB->name(), "tmp%%%%%.rename"); if (!tmpNameResult.isOK()) { return tmpNameResult.getStatus().withContext( @@ -480,7 +480,7 @@ Status renameBetweenDBs(OperationContext* opCtx, } boost::optional<Lock::DBLock> targetDBLock; - if (!opCtx->lockState()->isDbLockedForMode(target.db(), MODE_X)) { + if (!opCtx->lockState()->isDbLockedForMode(target.dbName(), MODE_X)) { targetDBLock.emplace(opCtx, target.dbName(), MODE_X); } @@ -545,7 +545,7 @@ Status renameBetweenDBs(OperationContext* opCtx, // The generated unique collection name is only guaranteed to exist if the database is // exclusively locked. - invariant(opCtx->lockState()->isDbLockedForMode(targetDB->name().db(), LockMode::MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(targetDB->name(), LockMode::MODE_X)); // Note that this temporary collection name is used by MongoMirror and thus must not be changed // without consultation. diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp index 9b194843fc6..07efc4750f8 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -220,7 +220,7 @@ void OpObserverMock::onInserts(OperationContext* opCtx, } onInsertsIsTargetDatabaseExclusivelyLocked = - opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_X); + opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_X); _logOp(opCtx, nss, "inserts"); OpObserverNoop::onInserts(opCtx, nss, uuid, begin, end, fromMigrate); diff --git a/src/mongo/db/catalog/unique_collection_name.cpp b/src/mongo/db/catalog/unique_collection_name.cpp index f7b4865e589..2096bed3820 100644 --- a/src/mongo/db/catalog/unique_collection_name.cpp +++ b/src/mongo/db/catalog/unique_collection_name.cpp @@ -45,7 +45,7 @@ PseudoRandom uniqueCollectionNamespacePseudoRandom(Date_t::now().asInt64()); StatusWith<NamespaceString> makeUniqueCollectionName(OperationContext* opCtx, const DatabaseName& dbName, StringData collectionNameModel) { - invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_IX)); // There must be at least one percent sign in the collection name model. auto numPercentSign = std::count(collectionNameModel.begin(), collectionNameModel.end(), '%'); diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp index e3ae1132263..cc0566d7926 100644 --- a/src/mongo/db/catalog_raii.cpp +++ b/src/mongo/db/catalog_raii.cpp @@ -206,7 +206,20 @@ AutoGetCollection::AutoGetCollection( // Acquire the global/RSTL and all the database locks (may or may not be multiple // databases). - _autoDb.emplace(opCtx, nsOrUUID.db(), isSharedLockMode(modeColl) ? MODE_IS : MODE_IX, deadline); + + // TODO SERVER-62923 Use DatabaseName obj directly. + auto dbName = [nsOrUUID]() { + // TODO SERVER-67817 Use NamespaceStringOrUUID::db() instead. + if (nsOrUUID.dbName()) + return nsOrUUID.dbName()->toStringWithTenantId(); + + if (nsOrUUID.nss()) + return nsOrUUID.nss()->dbName().toStringWithTenantId(); + + return DatabaseName(boost::none, "").toStringWithTenantId(); + }(); + + _autoDb.emplace(opCtx, dbName, isSharedLockMode(modeColl) ? MODE_IS : MODE_IX, deadline); // Out of an abundance of caution, force operations to acquire new snapshots after // acquiring exclusive collection locks. Operations that hold MODE_X locks make an diff --git a/src/mongo/db/catalog_raii_test.cpp b/src/mongo/db/catalog_raii_test.cpp index b0423a7a4db..e7d600cb81d 100644 --- a/src/mongo/db/catalog_raii_test.cpp +++ b/src/mongo/db/catalog_raii_test.cpp @@ -90,7 +90,7 @@ void failsWithLockTimeout(std::function<void()> func, Milliseconds timeoutMillis TEST_F(CatalogRAIITestFixture, AutoGetDBDeadline) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_X); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); failsWithLockTimeout( [&] { AutoGetDb db(client2.second.get(), nss.db(), MODE_X, Date_t::now() + timeoutMs); }, timeoutMs); @@ -106,7 +106,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetDBGlobalLockDeadline) { TEST_F(CatalogRAIITestFixture, AutoGetDBDeadlineNow) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); AutoGetDb db(client2.second.get(), nss.db(), MODE_IX); failsWithLockTimeout( [&] { AutoGetDb db(client2.second.get(), nss.db(), MODE_X, Date_t::now()); }, @@ -115,7 +115,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetDBDeadlineNow) { TEST_F(CatalogRAIITestFixture, AutoGetDBDeadlineMin) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); AutoGetDb db(client2.second.get(), nss.db(), MODE_IX); failsWithLockTimeout([&] { AutoGetDb db(client2.second.get(), nss.db(), MODE_X, Date_t{}); }, Milliseconds(0)); @@ -123,7 +123,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetDBDeadlineMin) { TEST_F(CatalogRAIITestFixture, AutoGetCollectionCollLockDeadline) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); Lock::CollectionLock collLock1(client1.second.get(), nss, MODE_X); ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X)); failsWithLockTimeout( @@ -139,7 +139,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionCollLockDeadline) { TEST_F(CatalogRAIITestFixture, AutoGetCollectionDBLockDeadline) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_X); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); failsWithLockTimeout( [&] { AutoGetCollection coll(client2.second.get(), @@ -167,7 +167,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionGlobalLockDeadline) { TEST_F(CatalogRAIITestFixture, AutoGetCollectionDeadlineNow) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); Lock::CollectionLock collLock1(client1.second.get(), nss, MODE_X); ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X)); @@ -184,7 +184,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionDeadlineNow) { TEST_F(CatalogRAIITestFixture, AutoGetCollectionDeadlineMin) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); Lock::CollectionLock collLock1(client1.second.get(), nss, MODE_X); ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X)); @@ -216,7 +216,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionNotCompatibleWithRSTLExclusiveLo TEST_F(CatalogRAIITestFixture, AutoGetCollectionDBLockCompatibleX) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); AutoGetCollection coll(client2.second.get(), nss, MODE_X); } @@ -238,7 +238,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionSecondaryNamespacesSingleDb) { ASSERT(opCtx1->lockState()->isRSTLLocked()); ASSERT(opCtx1->lockState()->isReadLocked()); // Global lock check - ASSERT(opCtx1->lockState()->isDbLockedForMode(nss.db(), MODE_IS)); + ASSERT(opCtx1->lockState()->isDbLockedForMode(nss.dbName(), MODE_IS)); ASSERT(opCtx1->lockState()->isDbLockedForMode(kSecondaryNss1.db(), MODE_IS)); ASSERT(opCtx1->lockState()->isDbLockedForMode(kSecondaryNss2.db(), MODE_IS)); ASSERT(opCtx1->lockState()->isCollectionLockedForMode(nss, MODE_IS)); @@ -276,7 +276,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionMultiNamespacesMODEIX) { ASSERT(opCtx1->lockState()->isRSTLLocked()); ASSERT(opCtx1->lockState()->isWriteLocked()); // Global lock check - ASSERT(opCtx1->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(opCtx1->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); ASSERT(opCtx1->lockState()->isDbLockedForMode(kSecondaryNss1.db(), MODE_IX)); ASSERT(opCtx1->lockState()->isDbLockedForMode(kSecondaryNss2.db(), MODE_IX)); ASSERT(opCtx1->lockState()->isCollectionLockedForMode(nss, MODE_IX)); @@ -303,7 +303,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetDbSecondaryNamespacesSingleDb) { ASSERT(opCtx1->lockState()->isRSTLLocked()); ASSERT(opCtx1->lockState()->isReadLocked()); // Global lock check - ASSERT(opCtx1->lockState()->isDbLockedForMode(nss.db(), MODE_IS)); + ASSERT(opCtx1->lockState()->isDbLockedForMode(nss.dbName(), MODE_IS)); ASSERT(opCtx1->lockState()->isDbLockedForMode(kSecondaryNss1.db(), MODE_IS)); ASSERT(opCtx1->lockState()->isDbLockedForMode(kSecondaryNss2.db(), MODE_IS)); @@ -380,7 +380,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionLockFreeGlobalLockDeadline) { TEST_F(CatalogRAIITestFixture, AutoGetCollectionLockFreeCompatibleWithCollectionExclusiveLock) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); Lock::CollectionLock collLock1(client1.second.get(), nss, MODE_X); ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X)); @@ -392,7 +392,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetCollectionLockFreeCompatibleWithCollection TEST_F(CatalogRAIITestFixture, AutoGetCollectionLockFreeCompatibleWithDatabaseExclusiveLock) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_X); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); AutoGetCollectionLockFree coll( client2.second.get(), nss, [](std::shared_ptr<const Collection>&, OperationContext*, UUID) { diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index f7663c5bee9..2d15c54be58 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -348,7 +348,7 @@ Status Cloner::_createCollectionsForDb( auto databaseHolder = DatabaseHolder::get(opCtx); const DatabaseName tenantDbName(boost::none, dbName); auto db = databaseHolder->openDb(opCtx, tenantDbName); - invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(tenantDbName, MODE_X)); auto catalog = CollectionCatalog::get(opCtx); auto collCount = 0; diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp index 5a0df7236f3..b2a6fa441c9 100644 --- a/src/mongo/db/commands/dbhash.cpp +++ b/src/mongo/db/commands/dbhash.cpp @@ -344,7 +344,7 @@ private: << minSnapshot->toString(), !minSnapshot || *mySnapshot >= *minSnapshot); } else { - invariant(opCtx->lockState()->isDbLockedForMode(db->name().db(), MODE_S)); + invariant(opCtx->lockState()->isDbLockedForMode(db->name(), MODE_S)); } auto desc = collection->getIndexCatalog()->findIdIndex(opCtx); diff --git a/src/mongo/db/concurrency/d_concurrency.cpp b/src/mongo/db/concurrency/d_concurrency.cpp index 4a76d9bf6d3..fc44e14512d 100644 --- a/src/mongo/db/concurrency/d_concurrency.cpp +++ b/src/mongo/db/concurrency/d_concurrency.cpp @@ -276,7 +276,7 @@ Lock::CollectionLock::CollectionLock(OperationContext* opCtx, _id = {RESOURCE_COLLECTION, nss.ns()}; invariant(nss.coll().size(), str::stream() << "expected non-empty collection name:" << nss); - dassert(_opCtx->lockState()->isDbLockedForMode(nss.db(), + dassert(_opCtx->lockState()->isDbLockedForMode(nss.dbName(), isSharedLockMode(mode) ? MODE_IS : MODE_IX)); _opCtx->lockState()->lock(_opCtx, _id, mode, deadline); @@ -288,7 +288,7 @@ Lock::CollectionLock::CollectionLock(OperationContext* opCtx, auto nss = CollectionCatalog::get(opCtx)->resolveNamespaceStringOrUUID(opCtx, nssOrUUID); // The UUID cannot move between databases so this one dassert is sufficient. - dassert(_opCtx->lockState()->isDbLockedForMode(nss.db(), + dassert(_opCtx->lockState()->isDbLockedForMode(nss.dbName(), isSharedLockMode(mode) ? MODE_IS : MODE_IX)); // We cannot be sure that the namespace we lock matches the UUID given because we resolve the diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp index 40e7114ea05..14d072e0270 100644 --- a/src/mongo/db/concurrency/d_concurrency_test.cpp +++ b/src/mongo/db/concurrency/d_concurrency_test.cpp @@ -1130,7 +1130,7 @@ TEST_F(DConcurrencyTestFixture, MultipleWriteDBLocksOnSameThread) { Lock::DBLock r1(opCtx.get(), dbName, MODE_X); Lock::DBLock r2(opCtx.get(), dbName, MODE_X); - ASSERT(opCtx->lockState()->isDbLockedForMode("db1", MODE_X)); + ASSERT(opCtx->lockState()->isDbLockedForMode(dbName, MODE_X)); } TEST_F(DConcurrencyTestFixture, MultipleConflictingDBLocksOnSameThread) { @@ -1141,17 +1141,17 @@ TEST_F(DConcurrencyTestFixture, MultipleConflictingDBLocksOnSameThread) { Lock::DBLock r1(opCtx.get(), dbName, MODE_X); Lock::DBLock r2(opCtx.get(), dbName, MODE_S); - ASSERT(lockState->isDbLockedForMode("db1", MODE_X)); - ASSERT(lockState->isDbLockedForMode("db1", MODE_S)); + ASSERT(lockState->isDbLockedForMode(dbName, MODE_X)); + ASSERT(lockState->isDbLockedForMode(dbName, MODE_S)); } TEST_F(DConcurrencyTestFixture, IsDbLockedForSMode) { - const std::string dbName("db"); + DatabaseName dbName(boost::none, "db"); auto opCtx = makeOperationContext(); getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext())); auto lockState = opCtx->lockState(); - Lock::DBLock dbLock(opCtx.get(), DatabaseName(boost::none, "db"), MODE_S); + Lock::DBLock dbLock(opCtx.get(), dbName, MODE_S); ASSERT(lockState->isDbLockedForMode(dbName, MODE_IS)); ASSERT(!lockState->isDbLockedForMode(dbName, MODE_IX)); @@ -1160,12 +1160,12 @@ TEST_F(DConcurrencyTestFixture, IsDbLockedForSMode) { } TEST_F(DConcurrencyTestFixture, IsDbLockedForXMode) { - const std::string dbName("db"); + DatabaseName dbName(boost::none, "db"); auto opCtx = makeOperationContext(); getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext())); auto lockState = opCtx->lockState(); - Lock::DBLock dbLock(opCtx.get(), DatabaseName(boost::none, "db"), MODE_X); + Lock::DBLock dbLock(opCtx.get(), dbName, MODE_X); ASSERT(lockState->isDbLockedForMode(dbName, MODE_IS)); ASSERT(lockState->isDbLockedForMode(dbName, MODE_IX)); @@ -1239,6 +1239,8 @@ TEST_F(DConcurrencyTestFixture, Stress) { AtomicWord<int> ready{0}; std::vector<stdx::thread> threads; + DatabaseName fooDb(boost::none, "foo"); + DatabaseName localDb(boost::none, "local"); for (int threadId = 0; threadId < kMaxStressThreads; threadId++) { threads.emplace_back([&, threadId]() { @@ -1270,11 +1272,7 @@ TEST_F(DConcurrencyTestFixture, Stress) { Lock::GlobalRead r2(clients[threadId].second.get()); ASSERT(clients[threadId].second->lockState()->isReadLocked()); } else if (i % 7 == 5) { - { - Lock::DBLock r(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_S); - } + { Lock::DBLock r(clients[threadId].second.get(), fooDb, MODE_S); } { Lock::DBLock r(clients[threadId].second.get(), DatabaseName(boost::none, "bar"), @@ -1285,36 +1283,24 @@ TEST_F(DConcurrencyTestFixture, Stress) { int q = i % 11; if (q == 0) { - Lock::DBLock r(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_S); + Lock::DBLock r(clients[threadId].second.get(), fooDb, MODE_S); ASSERT(clients[threadId].second->lockState()->isDbLockedForMode( - "foo", MODE_S)); + fooDb, MODE_S)); - Lock::DBLock r2(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_S); + Lock::DBLock r2(clients[threadId].second.get(), fooDb, MODE_S); ASSERT(clients[threadId].second->lockState()->isDbLockedForMode( - "foo", MODE_S)); + fooDb, MODE_S)); - Lock::DBLock r3(clients[threadId].second.get(), - DatabaseName(boost::none, "local"), - MODE_S); + Lock::DBLock r3(clients[threadId].second.get(), localDb, MODE_S); ASSERT(clients[threadId].second->lockState()->isDbLockedForMode( - "foo", MODE_S)); + fooDb, MODE_S)); ASSERT(clients[threadId].second->lockState()->isDbLockedForMode( - "local", MODE_S)); + localDb, MODE_S)); } else if (q == 1) { // test locking local only -- with no preceding lock - { - Lock::DBLock x(clients[threadId].second.get(), - DatabaseName(boost::none, "local"), - MODE_S); - } + { Lock::DBLock x(clients[threadId].second.get(), localDb, MODE_S); } - Lock::DBLock x(clients[threadId].second.get(), - DatabaseName(boost::none, "local"), - MODE_X); + Lock::DBLock x(clients[threadId].second.get(), localDb, MODE_X); } else if (q == 2) { { @@ -1328,9 +1314,7 @@ TEST_F(DConcurrencyTestFixture, Stress) { MODE_X); } } else if (q == 3) { - Lock::DBLock x(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_X); + Lock::DBLock x(clients[threadId].second.get(), fooDb, MODE_X); Lock::DBLock y(clients[threadId].second.get(), DatabaseName(boost::none, "admin"), MODE_S); @@ -1342,38 +1326,20 @@ TEST_F(DConcurrencyTestFixture, Stress) { DatabaseName(boost::none, "admin"), MODE_S); } else if (q == 5) { - Lock::DBLock x(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_IS); + Lock::DBLock x(clients[threadId].second.get(), fooDb, MODE_IS); } else if (q == 6) { - Lock::DBLock x(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_IX); - Lock::DBLock y(clients[threadId].second.get(), - DatabaseName(boost::none, "local"), - MODE_IX); + Lock::DBLock x(clients[threadId].second.get(), fooDb, MODE_IX); + Lock::DBLock y(clients[threadId].second.get(), localDb, MODE_IX); } else { - Lock::DBLock w(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_X); - - Lock::DBLock r2(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_S); - Lock::DBLock r3(clients[threadId].second.get(), - DatabaseName(boost::none, "local"), - MODE_S); + Lock::DBLock w(clients[threadId].second.get(), fooDb, MODE_X); + + Lock::DBLock r2(clients[threadId].second.get(), fooDb, MODE_S); + Lock::DBLock r3(clients[threadId].second.get(), localDb, MODE_S); } } else { - Lock::DBLock r(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_S); - Lock::DBLock r2(clients[threadId].second.get(), - DatabaseName(boost::none, "foo"), - MODE_S); - Lock::DBLock r3(clients[threadId].second.get(), - DatabaseName(boost::none, "local"), - MODE_S); + Lock::DBLock r(clients[threadId].second.get(), fooDb, MODE_S); + Lock::DBLock r2(clients[threadId].second.get(), fooDb, MODE_S); + Lock::DBLock r3(clients[threadId].second.get(), localDb, MODE_S); } } @@ -1758,16 +1724,16 @@ TEST_F(DConcurrencyTestFixture, DBLockTimeout) { const Milliseconds timeoutMillis = Milliseconds(1500); - Lock::DBLock L1(opctx1, DatabaseName(boost::none, "testdb"), MODE_X, Date_t::max()); - ASSERT(opctx1->lockState()->isDbLockedForMode("testdb"_sd, MODE_X)); + DatabaseName testDb(boost::none, "testdb"); + + Lock::DBLock L1(opctx1, testDb, MODE_X, Date_t::max()); + ASSERT(opctx1->lockState()->isDbLockedForMode(testDb, MODE_X)); ASSERT(L1.isLocked()); Date_t t1 = Date_t::now(); - ASSERT_THROWS_CODE( - Lock::DBLock( - opctx2, DatabaseName(boost::none, "testdb"), MODE_X, Date_t::now() + timeoutMillis), - AssertionException, - ErrorCodes::LockTimeout); + ASSERT_THROWS_CODE(Lock::DBLock(opctx2, testDb, MODE_X, Date_t::now() + timeoutMillis), + AssertionException, + ErrorCodes::LockTimeout); Date_t t2 = Date_t::now(); ASSERT_GTE(t2 - t1 + kMaxClockJitterMillis, Milliseconds(timeoutMillis)); } @@ -1844,14 +1810,16 @@ TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) { const Milliseconds timeoutMillis = Milliseconds(1500); - Lock::DBLock DBL1(opctx1, DatabaseName(boost::none, "testdb"), MODE_IX, Date_t::max()); - ASSERT(opctx1->lockState()->isDbLockedForMode("testdb"_sd, MODE_IX)); + DatabaseName testDb(boost::none, "testdb"); + + Lock::DBLock DBL1(opctx1, testDb, MODE_IX, Date_t::max()); + ASSERT(opctx1->lockState()->isDbLockedForMode(testDb, MODE_IX)); 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, DatabaseName(boost::none, "testdb"), MODE_IX, Date_t::max()); - ASSERT(opctx2->lockState()->isDbLockedForMode("testdb"_sd, MODE_IX)); + Lock::DBLock DBL2(opctx2, testDb, MODE_IX, Date_t::max()); + ASSERT(opctx2->lockState()->isDbLockedForMode(testDb, MODE_IX)); ASSERT_THROWS_CODE( Lock::CollectionLock( opctx2, NamespaceString("testdb.test"), MODE_X, Date_t::now() + timeoutMillis), @@ -2389,8 +2357,8 @@ TEST_F(DConcurrencyTestFixture, DifferentTenantsTakeDBLockOnConflictingNamespace Lock::DBLock r1(opCtx1, dbName1, MODE_X); Lock::DBLock r2(opCtx2, dbName2, MODE_X); - ASSERT(opCtx1->lockState()->isDbLockedForMode(dbName1.toStringWithTenantId(), MODE_X)); - ASSERT(opCtx2->lockState()->isDbLockedForMode(dbName2.toStringWithTenantId(), MODE_X)); + ASSERT(opCtx1->lockState()->isDbLockedForMode(dbName1, MODE_X)); + ASSERT(opCtx2->lockState()->isDbLockedForMode(dbName2, MODE_X)); } TEST_F(DConcurrencyTestFixture, ConflictingTenantDBLockThrows) { @@ -2402,10 +2370,12 @@ TEST_F(DConcurrencyTestFixture, ConflictingTenantDBLockThrows) { DatabaseName dbName1(TenantId(OID::gen()), db); Lock::DBLock r1(opCtx1, dbName1, MODE_X); + ASSERT(opCtx1->lockState()->isDbLockedForMode(dbName1, MODE_X)); auto result = runTaskAndKill(opCtx2, [&]() { Lock::DBLock r2(opCtx2, dbName1, MODE_S); }); ASSERT_THROWS_CODE(result.get(), AssertionException, ErrorCodes::Interrupted); + ASSERT(opCtx1->lockState()->isDbLockedForMode(dbName1, MODE_X)); } } // namespace diff --git a/src/mongo/db/concurrency/lock_state.cpp b/src/mongo/db/concurrency/lock_state.cpp index b9d26e6403f..8d78ae48581 100644 --- a/src/mongo/db/concurrency/lock_state.cpp +++ b/src/mongo/db/concurrency/lock_state.cpp @@ -627,15 +627,13 @@ bool LockerImpl::isLockHeldForMode(ResourceId resId, LockMode mode) const { return isModeCovered(mode, getLockMode(resId)); } -bool LockerImpl::isDbLockedForMode(StringData dbName, LockMode mode) const { - invariant(nsIsDbOnly(dbName)); - +bool LockerImpl::isDbLockedForMode(const DatabaseName& dbName, LockMode mode) const { if (isW()) return true; if (isR() && isSharedLockMode(mode)) return true; - const ResourceId resIdDb(RESOURCE_DATABASE, dbName); + const ResourceId resIdDb(RESOURCE_DATABASE, dbName.toStringWithTenantId()); return isLockHeldForMode(resIdDb, mode); } @@ -647,7 +645,7 @@ bool LockerImpl::isCollectionLockedForMode(const NamespaceString& nss, LockMode if (isR() && isSharedLockMode(mode)) return true; - const ResourceId resIdDb(RESOURCE_DATABASE, nss.db()); + const ResourceId resIdDb(RESOURCE_DATABASE, nss.dbName().toStringWithTenantId()); LockMode dbMode = getLockMode(resIdDb); if (!shouldConflictWithSecondaryBatchApplication()) diff --git a/src/mongo/db/concurrency/lock_state.h b/src/mongo/db/concurrency/lock_state.h index 7148929eecf..4664bb2c72f 100644 --- a/src/mongo/db/concurrency/lock_state.h +++ b/src/mongo/db/concurrency/lock_state.h @@ -181,7 +181,7 @@ public: virtual LockMode getLockMode(ResourceId resId) const; virtual bool isLockHeldForMode(ResourceId resId, LockMode mode) const; - virtual bool isDbLockedForMode(StringData dbName, LockMode mode) const; + virtual bool isDbLockedForMode(const DatabaseName& dbName, LockMode mode) const; virtual bool isCollectionLockedForMode(const NamespaceString& nss, LockMode mode) const; virtual ResourceId getWaitingResource() const; diff --git a/src/mongo/db/concurrency/locker.h b/src/mongo/db/concurrency/locker.h index 4441b8a9881..b9faf273eac 100644 --- a/src/mongo/db/concurrency/locker.h +++ b/src/mongo/db/concurrency/locker.h @@ -289,7 +289,7 @@ public: // These are shortcut methods for the above calls. They however check that the entire // hierarchy is properly locked and because of this they are very expensive to call. // Do not use them in performance critical code paths. - virtual bool isDbLockedForMode(StringData dbName, LockMode mode) const = 0; + virtual bool isDbLockedForMode(const DatabaseName& dbName, LockMode mode) const = 0; virtual bool isCollectionLockedForMode(const NamespaceString& nss, LockMode mode) const = 0; /** diff --git a/src/mongo/db/concurrency/locker_noop.h b/src/mongo/db/concurrency/locker_noop.h index 7ce27af01fa..f679642b0f1 100644 --- a/src/mongo/db/concurrency/locker_noop.h +++ b/src/mongo/db/concurrency/locker_noop.h @@ -148,7 +148,7 @@ public: return true; } - virtual bool isDbLockedForMode(StringData dbName, LockMode mode) const { + virtual bool isDbLockedForMode(const DatabaseName& dbName, LockMode mode) const { return true; } diff --git a/src/mongo/db/database_name.h b/src/mongo/db/database_name.h index a44979a2096..6fa31488187 100644 --- a/src/mongo/db/database_name.h +++ b/src/mongo/db/database_name.h @@ -57,7 +57,15 @@ public: * the dbName is a valid db name. */ DatabaseName(boost::optional<TenantId> tenantId, StringData dbString) - : _tenantId(std::move(tenantId)), _dbString(dbString.toString()) {} + : _tenantId(std::move(tenantId)), _dbString(dbString.toString()) { + uassert(ErrorCodes::InvalidNamespace, + "'.' is an invalid character in a db name: " + _dbString, + dbString.find('.') == std::string::npos); + + uassert(ErrorCodes::InvalidNamespace, + "database names cannot have embedded null characters", + dbString.find('\0') == std::string::npos); + } /** * Prefer to use the constructor above. diff --git a/src/mongo/db/db_raii_multi_collection_test.cpp b/src/mongo/db/db_raii_multi_collection_test.cpp index cc2ce8c100f..9fa5b4e9a30 100644 --- a/src/mongo/db/db_raii_multi_collection_test.cpp +++ b/src/mongo/db/db_raii_multi_collection_test.cpp @@ -156,7 +156,7 @@ TEST_F(AutoGetCollectionMultiTest, LockFreeMultiCollectionSingleDB) { auto locker = opCtx1->lockState(); locker->dump(); invariant(locker->isLockHeldForMode(resourceIdGlobal, MODE_IS)); - invariant(!locker->isDbLockedForMode(_primaryNss.db(), MODE_IS)); + invariant(!locker->isDbLockedForMode(_primaryNss.dbName(), MODE_IS)); // Set 'shouldConflictWithSecondaryBatchApplication' to true so isCollectionLockedForMode() // doesn't return true regardless of what locks are held. opCtx1->lockState()->setShouldConflictWithSecondaryBatchApplication(true); @@ -190,8 +190,8 @@ TEST_F(AutoGetCollectionMultiTest, LockedDuplicateNamespaces) { auto locker = opCtx1->lockState(); locker->dump(); invariant(locker->isLockHeldForMode(resourceIdGlobal, MODE_IS)); - invariant(locker->isDbLockedForMode(_primaryNss.db(), MODE_IS)); - invariant(locker->isDbLockedForMode(_secondaryNss1.db(), MODE_IS)); + invariant(locker->isDbLockedForMode(_primaryNss.dbName(), MODE_IS)); + invariant(locker->isDbLockedForMode(_secondaryNss1.dbName(), MODE_IS)); // Set 'shouldConflictWithSecondaryBatchApplication' to true so isCollectionLockedForMode() // doesn't return true regardless of what locks are held. opCtx1->lockState()->setShouldConflictWithSecondaryBatchApplication(true); @@ -217,8 +217,8 @@ TEST_F(AutoGetCollectionMultiTest, LockFreeMultiDBs) { auto locker = opCtx1->lockState(); locker->dump(); invariant(locker->isLockHeldForMode(resourceIdGlobal, MODE_IS)); - invariant(!locker->isDbLockedForMode(_primaryNss.db(), MODE_IS)); - invariant(!locker->isDbLockedForMode(_secondaryNssOtherDbNss.db(), MODE_IS)); + invariant(!locker->isDbLockedForMode(_primaryNss.dbName(), MODE_IS)); + invariant(!locker->isDbLockedForMode(_secondaryNssOtherDbNss.dbName(), MODE_IS)); // Set 'shouldConflictWithSecondaryBatchApplication' to true so isCollectionLockedForMode() // doesn't return true regardless of what locks are held. opCtx1->lockState()->setShouldConflictWithSecondaryBatchApplication(true); @@ -265,11 +265,11 @@ TEST_F(AutoGetCollectionMultiTest, LockedSecondaryNamespaceNotFound) { invariant(locker->isLocked()); invariant(locker->isLockHeldForMode(resourceIdGlobal, MODE_IS)); - invariant(locker->isDbLockedForMode(_primaryNss.db(), MODE_IS)); + invariant(locker->isDbLockedForMode(_primaryNss.dbName(), MODE_IS)); invariant(locker->isCollectionLockedForMode(_primaryNss, MODE_IS)); for (const auto& secondaryNss : _secondaryNssOrUUIDVec) { - invariant(locker->isDbLockedForMode(secondaryNss.db(), MODE_IS)); + invariant(locker->isDbLockedForMode(secondaryNss.nss()->dbName(), MODE_IS)); invariant(locker->isCollectionLockedForMode(*secondaryNss.nss(), MODE_IS)); } diff --git a/src/mongo/db/db_raii_test.cpp b/src/mongo/db/db_raii_test.cpp index 4a8e8f8f361..f49bca93985 100644 --- a/src/mongo/db/db_raii_test.cpp +++ b/src/mongo/db/db_raii_test.cpp @@ -115,7 +115,7 @@ void failsWithLockTimeout(std::function<void()> func, Milliseconds timeoutMillis TEST_F(DBRAIITestFixture, AutoGetCollectionForReadCollLockDeadline) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); Lock::CollectionLock collLock1(client1.second.get(), nss, MODE_X); ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X)); failsWithLockTimeout( @@ -130,7 +130,7 @@ TEST_F(DBRAIITestFixture, AutoGetCollectionForReadCollLockDeadline) { TEST_F(DBRAIITestFixture, AutoGetCollectionForReadDBLockDeadline) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_X); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_X)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_X)); failsWithLockTimeout( [&] { AutoGetCollectionForRead coll(client2.second.get(), @@ -156,7 +156,7 @@ TEST_F(DBRAIITestFixture, AutoGetCollectionForReadGlobalLockDeadline) { TEST_F(DBRAIITestFixture, AutoGetCollectionForReadDeadlineNow) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); Lock::CollectionLock collLock1(client1.second.get(), nss, MODE_X); ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X)); @@ -172,7 +172,7 @@ TEST_F(DBRAIITestFixture, AutoGetCollectionForReadDeadlineNow) { TEST_F(DBRAIITestFixture, AutoGetCollectionForReadDeadlineMin) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); Lock::CollectionLock collLock1(client1.second.get(), nss, MODE_X); ASSERT(client1.second->lockState()->isCollectionLockedForMode(nss, MODE_X)); @@ -186,7 +186,7 @@ TEST_F(DBRAIITestFixture, AutoGetCollectionForReadDeadlineMin) { TEST_F(DBRAIITestFixture, AutoGetCollectionForReadDBLockCompatibleXNoCollection) { Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); AutoGetCollectionForRead coll(client2.second.get(), nss); } @@ -197,7 +197,7 @@ TEST_F(DBRAIITestFixture, AutoGetCollectionForReadDBLockCompatibleXCollectionExi storageInterface()->createCollection(client1.second.get(), nss, defaultCollectionOptions)); Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); AutoGetCollectionForRead coll(client2.second.get(), nss); } @@ -208,7 +208,7 @@ TEST_F(DBRAIITestFixture, AutoGetCollectionForReadDBLockCompatibleXCollectionExi storageInterface()->createCollection(client1.second.get(), nss, defaultCollectionOptions)); Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); auto opCtx = client2.second.get(); opCtx->recoveryUnit()->setTimestampReadSource(RecoveryUnit::ReadSource::kProvided, Timestamp(1, 2)); @@ -225,7 +225,7 @@ TEST_F(DBRAIITestFixture, ASSERT_OK(repl::ReplicationCoordinator::get(client1.second.get()) ->setFollowerMode(repl::MemberState::RS_SECONDARY)); Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); // Simulate using a DBDirectClient to test this behavior for user reads. client2.first->setInDirectClient(true); @@ -246,7 +246,7 @@ TEST_F(DBRAIITestFixture, client1.second.get()->getServiceContext()->getStorageEngine()->getSnapshotManager(); snapshotManager->setLastApplied(replCoord->getMyLastAppliedOpTime().getTimestamp()); Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); // Simulate using a DBDirectClient to test this behavior for user reads. client2.first->setInDirectClient(true); @@ -275,7 +275,7 @@ TEST_F(DBRAIITestFixture, snapshotManager->setLastApplied(opTime.getTimestamp()); Lock::DBLock dbLock1(client1.second.get(), nss.dbName(), MODE_IX); - ASSERT(client1.second->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT(client1.second->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); // Simulate using a DBDirectClient to test this behavior for user reads. client2.first->setInDirectClient(true); diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp index ac00155ad77..6d4e92bd4da 100644 --- a/src/mongo/db/introspect.cpp +++ b/src/mongo/db/introspect.cpp @@ -162,7 +162,7 @@ void profile(OperationContext* opCtx, NetworkOp op) { Status createProfileCollection(OperationContext* opCtx, Database* db) { - invariant(opCtx->lockState()->isDbLockedForMode(db->name().db(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(db->name(), MODE_IX)); invariant(!opCtx->shouldParticipateInFlowControl()); const auto dbProfilingNS = NamespaceString(db->name().db(), "system.profile"); diff --git a/src/mongo/db/op_observer/op_observer_impl_test.cpp b/src/mongo/db/op_observer/op_observer_impl_test.cpp index f9bf11fd5a5..f769118faed 100644 --- a/src/mongo/db/op_observer/op_observer_impl_test.cpp +++ b/src/mongo/db/op_observer/op_observer_impl_test.cpp @@ -2914,7 +2914,7 @@ TEST_F(BatchedWriteOutputsTest, TestApplyOpsInsertDeleteUpdateIncludesTenantId) WriteUnitOfWork wuow(opCtx, true /* groupOplogEntries */); ASSERT(bwc.writesAreBatched()); - AutoGetCollection locks(opCtx, _nssWithTid, LockMode::MODE_IX); + AutoGetCollection locks(opCtx, NamespaceStringOrUUID(_nssWithTid), LockMode::MODE_IX); // (0) Insert { diff --git a/src/mongo/db/repl/oplog_applier_impl_test.cpp b/src/mongo/db/repl/oplog_applier_impl_test.cpp index 34e5996f887..24a0c66659b 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test.cpp @@ -515,7 +515,7 @@ TEST_F(OplogApplierImplTest, applyOplogEntryOrGroupedInsertsCommand) { const BSONObj&) { applyCmdCalled = true; ASSERT_TRUE(opCtx); - ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); ASSERT_EQUALS(nss, collNss); return Status::OK(); }; diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp index d0162b855a7..72c93034d8b 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp @@ -218,8 +218,10 @@ void OplogApplierImplTest::_testApplyOplogEntryOrGroupedInsertsCrudOperation( auto checkOpCtx = [](OperationContext* opCtx) { ASSERT_TRUE(opCtx); - ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode("test", MODE_IX)); - ASSERT_FALSE(opCtx->lockState()->isDbLockedForMode("test", MODE_X)); + ASSERT_TRUE( + opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, "test"), MODE_IX)); + ASSERT_FALSE( + opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, "test"), MODE_X)); ASSERT_TRUE( opCtx->lockState()->isCollectionLockedForMode(NamespaceString("test.t"), MODE_IX)); ASSERT_FALSE(opCtx->writesAreReplicated()); diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index c159fc43c07..c90093fcbe8 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -1087,7 +1087,7 @@ void renameOutOfTheWay(OperationContext* opCtx, RenameCollectionInfo info, Datab // The generated unique collection name is only guaranteed to exist if the database is // exclusively locked. - invariant(opCtx->lockState()->isDbLockedForMode(db->name().db(), LockMode::MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(db->name(), LockMode::MODE_X)); // Creates the oplog entry to temporarily rename the collection that is // preventing the renameCollection command from rolling back to a unique // namespace. diff --git a/src/mongo/db/repl/tenant_oplog_applier_test.cpp b/src/mongo/db/repl/tenant_oplog_applier_test.cpp index 3af7f8fa545..137cd265dd6 100644 --- a/src/mongo/db/repl/tenant_oplog_applier_test.cpp +++ b/src/mongo/db/repl/tenant_oplog_applier_test.cpp @@ -838,7 +838,7 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_Success) { const OplogDeleteEntryArgs& args) { onDeleteCalled = true; ASSERT_TRUE(opCtx); - ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); ASSERT_TRUE(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IX)); ASSERT_TRUE(opCtx->writesAreReplicated()); ASSERT_FALSE(args.fromMigrate); @@ -958,7 +958,7 @@ TEST_F(TenantOplogApplierTest, ApplyCreateCollCommand_Success) { const BSONObj&) { applyCmdCalled = true; ASSERT_TRUE(opCtx); - ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); ASSERT_TRUE(opCtx->writesAreReplicated()); ASSERT_EQUALS(nss, collNss); }; @@ -1001,7 +1001,7 @@ TEST_F(TenantOplogApplierTest, ApplyCreateIndexesCommand_Success) { bool fromMigrate) { ASSERT_FALSE(applyCmdCalled); applyCmdCalled = true; - ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + ASSERT_TRUE(opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); ASSERT_TRUE(opCtx->writesAreReplicated()); ASSERT_BSONOBJ_EQ(indexDoc, BSON("v" << 2 << "key" << BSON("a" << 1) << "name" diff --git a/src/mongo/db/s/database_sharding_state.cpp b/src/mongo/db/s/database_sharding_state.cpp index fe77d844162..dc340b7f2cf 100644 --- a/src/mongo/db/s/database_sharding_state.cpp +++ b/src/mongo/db/s/database_sharding_state.cpp @@ -87,7 +87,8 @@ DatabaseShardingState::DatabaseShardingState(const StringData dbName) DatabaseShardingState* DatabaseShardingState::get(OperationContext* opCtx, const StringData dbName) { // db lock must be held to have a reference to the database sharding state - dassert(opCtx->lockState()->isDbLockedForMode(dbName, MODE_IS)); + // TODO SERVER-63706 Use dbName directly + dassert(opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, dbName), MODE_IS)); auto& databasesMap = DatabaseShardingStateMap::get(opCtx->getServiceContext()); return databasesMap.getOrCreate(dbName).get(); @@ -102,14 +103,14 @@ std::shared_ptr<DatabaseShardingState> DatabaseShardingState::getSharedForLockFr void DatabaseShardingState::enterCriticalSectionCatchUpPhase(OperationContext* opCtx, DSSLock&, const BSONObj& reason) { - invariant(opCtx->lockState()->isDbLockedForMode(_dbName, MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, _dbName), MODE_X)); _critSec.enterCriticalSectionCatchUpPhase(reason); } void DatabaseShardingState::enterCriticalSectionCommitPhase(OperationContext* opCtx, DSSLock&, const BSONObj& reason) { - invariant(opCtx->lockState()->isDbLockedForMode(_dbName, MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, _dbName), MODE_X)); _critSec.enterCriticalSectionCommitPhase(reason); } @@ -125,7 +126,7 @@ MovePrimarySourceManager* DatabaseShardingState::getMovePrimarySourceManager(DSS void DatabaseShardingState::setMovePrimarySourceManager(OperationContext* opCtx, MovePrimarySourceManager* sourceMgr, DSSLock&) { - invariant(opCtx->lockState()->isDbLockedForMode(_dbName, MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, _dbName), MODE_X)); invariant(sourceMgr); invariant(!_sourceMgr); @@ -133,7 +134,7 @@ void DatabaseShardingState::setMovePrimarySourceManager(OperationContext* opCtx, } void DatabaseShardingState::clearMovePrimarySourceManager(OperationContext* opCtx) { - invariant(opCtx->lockState()->isDbLockedForMode(_dbName, MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(DatabaseName(boost::none, _dbName), MODE_IX)); const auto dssLock = DSSLock::lockExclusive(opCtx, this); _sourceMgr = nullptr; } diff --git a/src/mongo/db/startup_recovery.cpp b/src/mongo/db/startup_recovery.cpp index bc23d3a94d5..f84ef0c6547 100644 --- a/src/mongo/db/startup_recovery.cpp +++ b/src/mongo/db/startup_recovery.cpp @@ -292,7 +292,7 @@ bool hasReplSetConfigDoc(OperationContext* opCtx) { */ void assertCappedOplog(OperationContext* opCtx, Database* db) { const NamespaceString oplogNss(NamespaceString::kRsOplogNamespace); - invariant(opCtx->lockState()->isDbLockedForMode(oplogNss.db(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(oplogNss.dbName(), MODE_IS)); const CollectionPtr& oplogCollection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, oplogNss); if (oplogCollection && !oplogCollection->isCapped()) { diff --git a/src/mongo/db/storage/durable_catalog_impl.cpp b/src/mongo/db/storage/durable_catalog_impl.cpp index 7dcaae35593..b7773e96bd9 100644 --- a/src/mongo/db/storage/durable_catalog_impl.cpp +++ b/src/mongo/db/storage/durable_catalog_impl.cpp @@ -277,7 +277,7 @@ DurableCatalog::Entry DurableCatalogImpl::getEntry(RecordId catalogId) const { StatusWith<DurableCatalog::Entry> DurableCatalogImpl::_addEntry(OperationContext* opCtx, NamespaceString nss, const CollectionOptions& options) { - invariant(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); auto ident = _newUniqueIdent(nss, "collection"); @@ -319,7 +319,7 @@ StatusWith<DurableCatalog::Entry> DurableCatalogImpl::_addEntry(OperationContext StatusWith<DurableCatalog::Entry> DurableCatalogImpl::_importEntry(OperationContext* opCtx, NamespaceString nss, const BSONObj& metadata) { - invariant(opCtx->lockState()->isDbLockedForMode(nss.db(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_IX)); auto ident = metadata["ident"].String(); StatusWith<RecordId> res = diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp index 632dc4c8767..c889fd8c056 100644 --- a/src/mongo/db/views/durable_view_catalog.cpp +++ b/src/mongo/db/views/durable_view_catalog.cpp @@ -110,7 +110,7 @@ void validateViewDefinitionBSON(OperationContext* opCtx, // DurableViewCatalog void DurableViewCatalog::onExternalChange(OperationContext* opCtx, const NamespaceString& name) { - dassert(opCtx->lockState()->isDbLockedForMode(name.db(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(name.dbName(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode( NamespaceString(name.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); @@ -147,7 +147,7 @@ Status DurableViewCatalog::onExternalInsert(OperationContext* opCtx, void DurableViewCatalog::onSystemViewsCollectionDrop(OperationContext* opCtx, const NamespaceString& name) { - dassert(opCtx->lockState()->isDbLockedForMode(name.db(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(name.dbName(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode( NamespaceString(name.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); dassert(name.coll() == NamespaceString::kSystemDotViewsCollectionName); @@ -228,7 +228,7 @@ BSONObj DurableViewCatalogImpl::_validateViewDefinition(OperationContext* opCtx, void DurableViewCatalogImpl::upsert(OperationContext* opCtx, const NamespaceString& name, const BSONObj& view) { - dassert(opCtx->lockState()->isDbLockedForMode(_db->name().db(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(_db->name(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(name, MODE_IX)); NamespaceString systemViewsNs(_db->getSystemViewsName()); @@ -261,7 +261,7 @@ void DurableViewCatalogImpl::upsert(OperationContext* opCtx, } void DurableViewCatalogImpl::remove(OperationContext* opCtx, const NamespaceString& name) { - dassert(opCtx->lockState()->isDbLockedForMode(_db->name().db(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(_db->name(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(name, MODE_IX)); CollectionPtr systemViews = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace( |