diff options
author | Hugh Tong <hugh.tong@mongodb.com> | 2022-05-09 16:00:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-09 21:31:49 +0000 |
commit | 6989f87e400acff7e668ba4472d4f91adf938683 (patch) | |
tree | 276ba283e6ef6f0506b940f2dab2b6f1f71371a6 /src/mongo/db | |
parent | 32e2e0d1385f6e47f829ff70b9fce95b3873a54f (diff) | |
download | mongo-6989f87e400acff7e668ba4472d4f91adf938683.tar.gz |
SERVER-64609 Rename instances of TenantDatabaseName to DatabaseName
Diffstat (limited to 'src/mongo/db')
79 files changed, 674 insertions, 751 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 59d3e2cdf93..d6a212b8cc8 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -245,7 +245,7 @@ env.Library( target='namespace_string', source=[ 'namespace_string.cpp', - 'tenant_database_name.cpp', + 'database_name.cpp', ], LIBDEPS=[ '$BUILD_DIR/mongo/base', diff --git a/src/mongo/db/catalog/catalog_control.cpp b/src/mongo/db/catalog/catalog_control.cpp index 7266c3fa63b..5d22ba66029 100644 --- a/src/mongo/db/catalog/catalog_control.cpp +++ b/src/mongo/db/catalog/catalog_control.cpp @@ -38,11 +38,11 @@ #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" +#include "mongo/db/database_name.h" #include "mongo/db/ftdc/ftdc_mongod.h" #include "mongo/db/index_builds_coordinator.h" #include "mongo/db/namespace_string.h" #include "mongo/db/rebuild_indexes.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/logv2/log.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kStorage @@ -68,14 +68,13 @@ void reopenAllDatabasesAndReloadCollectionCatalog( boost::optional<BatchedCollectionCatalogWriter> catalogWriter(opCtx); auto databaseHolder = DatabaseHolder::get(opCtx); - std::vector<TenantDatabaseName> databasesToOpen = storageEngine->listDatabases(); - for (auto&& tenantDbName : databasesToOpen) { + std::vector<DatabaseName> databasesToOpen = storageEngine->listDatabases(); + for (auto&& dbName : databasesToOpen) { LOGV2_FOR_RECOVERY( - 23992, 1, "openCatalog: dbholder reopening database", "db"_attr = tenantDbName); - auto db = databaseHolder->openDb(opCtx, tenantDbName); - invariant(db, str::stream() << "failed to reopen database " << tenantDbName.toString()); - for (auto&& collNss : - catalogWriter.get()->getAllCollectionNamesFromDb(opCtx, tenantDbName)) { + 23992, 1, "openCatalog: dbholder reopening database", "db"_attr = dbName); + auto db = databaseHolder->openDb(opCtx, dbName); + invariant(db, str::stream() << "failed to reopen database " << dbName.toString()); + for (auto&& collNss : catalogWriter.get()->getAllCollectionNamesFromDb(opCtx, dbName)) { // Note that the collection name already includes the database component. auto collection = catalogWriter.get()->lookupCollectionByNamespace(opCtx, collNss); invariant(collection, @@ -129,14 +128,13 @@ MinVisibleTimestampMap closeCatalog(OperationContext* opCtx) { IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgress(); MinVisibleTimestampMap minVisibleTimestampMap; - std::vector<TenantDatabaseName> allDbs = + std::vector<DatabaseName> allDbs = opCtx->getServiceContext()->getStorageEngine()->listDatabases(); auto databaseHolder = DatabaseHolder::get(opCtx); auto catalog = CollectionCatalog::get(opCtx); - for (auto&& tenantDbName : allDbs) { - for (auto collIt = catalog->begin(opCtx, tenantDbName); collIt != catalog->end(opCtx); - ++collIt) { + for (auto&& dbName : allDbs) { + for (auto collIt = catalog->begin(opCtx, dbName); collIt != catalog->end(opCtx); ++collIt) { auto coll = *collIt; if (!coll) { break; diff --git a/src/mongo/db/catalog/catalog_stats.cpp b/src/mongo/db/catalog/catalog_stats.cpp index f45ffbcc6ce..36446c6096a 100644 --- a/src/mongo/db/catalog/catalog_stats.cpp +++ b/src/mongo/db/catalog/catalog_stats.cpp @@ -84,19 +84,17 @@ public: stats.internalCollections = catalogStats.internal; const auto viewCatalogDbNames = catalog->getViewCatalogDbNames(opCtx); - for (const auto& tenantDbName : viewCatalogDbNames) { + for (const auto& dbName : viewCatalogDbNames) { try { - const auto viewStats = catalog->getViewStatsForDatabase(opCtx, tenantDbName); + const auto viewStats = catalog->getViewStatsForDatabase(opCtx, dbName); invariant(viewStats); stats.timeseries += viewStats->userTimeseries; stats.views += viewStats->userViews; stats.internalViews += viewStats->internal; } catch (ExceptionForCat<ErrorCategory::Interruption>&) { - LOGV2_DEBUG(5578400, - 2, - "Failed to collect view catalog statistics", - "db"_attr = tenantDbName); + LOGV2_DEBUG( + 5578400, 2, "Failed to collect view catalog statistics", "db"_attr = dbName); } } diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp index 45b8667da8c..2c6daea298d 100644 --- a/src/mongo/db/catalog/collection_catalog.cpp +++ b/src/mongo/db/catalog/collection_catalog.cpp @@ -96,8 +96,8 @@ public: catalog._collections[collection->ns()] = collection; catalog._catalog[collection->uuid()] = collection; // TODO SERVER-64608 Use tenantID from ns - auto dbIdPair = std::make_pair(TenantDatabaseName(boost::none, collection->ns().db()), - collection->uuid()); + auto dbIdPair = + std::make_pair(DatabaseName(boost::none, collection->ns().db()), collection->uuid()); catalog._orderedCollections[dbIdPair] = collection; } @@ -181,7 +181,7 @@ public: } case UncommittedCatalogUpdates::Entry::Action::kReplacedViewsForDatabase: { writeJobs.push_back( - [dbName = TenantDatabaseName(boost::none, entry.nss.db()), + [dbName = DatabaseName(boost::none, entry.nss.db()), &viewsForDb = entry.viewsForDb.get()](CollectionCatalog& catalog) { catalog._replaceViewsForDatabase(dbName, std::move(viewsForDb)); }); @@ -225,12 +225,12 @@ private: }; CollectionCatalog::iterator::iterator(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName, + const DatabaseName& dbName, const CollectionCatalog& catalog) - : _opCtx(opCtx), _tenantDbName(tenantDbName), _catalog(&catalog) { + : _opCtx(opCtx), _dbName(dbName), _catalog(&catalog) { auto minUuid = UUID::parse("00000000-0000-0000-0000-000000000000").getValue(); - _mapIter = _catalog->_orderedCollections.lower_bound(std::make_pair(_tenantDbName, minUuid)); + _mapIter = _catalog->_orderedCollections.lower_bound(std::make_pair(_dbName, minUuid)); // Start with the first collection that is visible outside of its transaction. while (!_exhausted() && !_mapIter->second->isCommitted()) { @@ -242,10 +242,10 @@ CollectionCatalog::iterator::iterator(OperationContext* opCtx, } } -CollectionCatalog::iterator::iterator(OperationContext* opCtx, - std::map<std::pair<TenantDatabaseName, UUID>, - std::shared_ptr<Collection>>::const_iterator mapIter, - const CollectionCatalog& catalog) +CollectionCatalog::iterator::iterator( + OperationContext* opCtx, + std::map<std::pair<DatabaseName, UUID>, std::shared_ptr<Collection>>::const_iterator mapIter, + const CollectionCatalog& catalog) : _opCtx(opCtx), _mapIter(mapIter), _catalog(&catalog) {} CollectionCatalog::iterator::value_type CollectionCatalog::iterator::operator*() { @@ -306,8 +306,7 @@ bool CollectionCatalog::iterator::operator!=(const iterator& other) const { } bool CollectionCatalog::iterator::_exhausted() { - return _mapIter == _catalog->_orderedCollections.end() || - _mapIter->first.first != _tenantDbName; + return _mapIter == _catalog->_orderedCollections.end() || _mapIter->first.first != _dbName; } std::shared_ptr<const CollectionCatalog> CollectionCatalog::get(ServiceContext* svcCtx) { @@ -483,9 +482,9 @@ Status CollectionCatalog::createView(OperationContext* opCtx, invariant(opCtx->lockState()->isCollectionLockedForMode( NamespaceString(viewName.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); - TenantDatabaseName tenantDbName(boost::none, viewName.db()); - invariant(_viewsForDatabase.contains(tenantDbName)); - const ViewsForDatabase& viewsForDb = *_getViewsForDatabase(opCtx, tenantDbName); + DatabaseName dbName(boost::none, viewName.db()); + invariant(_viewsForDatabase.contains(dbName)); + const ViewsForDatabase& viewsForDb = *_getViewsForDatabase(opCtx, dbName); auto& uncommittedCatalogUpdates = UncommittedCatalogUpdates::get(opCtx); if (uncommittedCatalogUpdates.shouldIgnoreExternalViewChanges(viewName.db())) { @@ -534,9 +533,9 @@ Status CollectionCatalog::modifyView( invariant(opCtx->lockState()->isCollectionLockedForMode( NamespaceString(viewName.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); - TenantDatabaseName tenantDbName(boost::none, viewName.db()); - invariant(_viewsForDatabase.contains(tenantDbName)); - const ViewsForDatabase& viewsForDb = *_getViewsForDatabase(opCtx, tenantDbName); + DatabaseName dbName(boost::none, viewName.db()); + invariant(_viewsForDatabase.contains(dbName)); + const ViewsForDatabase& viewsForDb = *_getViewsForDatabase(opCtx, dbName); if (viewName.db() != viewOn.db()) return Status(ErrorCodes::BadValue, @@ -573,9 +572,9 @@ Status CollectionCatalog::dropView(OperationContext* opCtx, const NamespaceStrin invariant(opCtx->lockState()->isCollectionLockedForMode( NamespaceString(viewName.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); - TenantDatabaseName tenantDbName(boost::none, viewName.db()); - invariant(_viewsForDatabase.contains(tenantDbName)); - const ViewsForDatabase& viewsForDb = *_getViewsForDatabase(opCtx, tenantDbName); + DatabaseName dbName(boost::none, viewName.db()); + invariant(_viewsForDatabase.contains(dbName)); + const ViewsForDatabase& viewsForDb = *_getViewsForDatabase(opCtx, dbName); viewsForDb.requireValidCatalog(); // Make sure the view exists before proceeding. @@ -610,13 +609,12 @@ Status CollectionCatalog::dropView(OperationContext* opCtx, const NamespaceStrin return result; } -Status CollectionCatalog::reloadViews(OperationContext* opCtx, - const TenantDatabaseName& dbName) const { +Status CollectionCatalog::reloadViews(OperationContext* opCtx, const DatabaseName& dbName) const { invariant(opCtx->lockState()->isCollectionLockedForMode( - NamespaceString(dbName.dbName(), NamespaceString::kSystemDotViewsCollectionName), MODE_IS)); + NamespaceString(dbName, NamespaceString::kSystemDotViewsCollectionName), MODE_IS)); auto& uncommittedCatalogUpdates = UncommittedCatalogUpdates::get(opCtx); - if (uncommittedCatalogUpdates.shouldIgnoreExternalViewChanges(dbName.dbName())) { + if (uncommittedCatalogUpdates.shouldIgnoreExternalViewChanges(dbName.db())) { return Status::OK(); } @@ -686,9 +684,9 @@ void CollectionCatalog::dropCollection(OperationContext* opCtx, Collection* coll } void CollectionCatalog::onOpenDatabase(OperationContext* opCtx, - const TenantDatabaseName& dbName, + const DatabaseName& dbName, ViewsForDatabase&& viewsForDb) { - invariant(opCtx->lockState()->isDbLockedForMode(dbName.dbName(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_IS)); uassert(ErrorCodes::AlreadyInitialized, str::stream() << "Database " << dbName << " is already initialized", _viewsForDatabase.find(dbName) == _viewsForDatabase.end()); @@ -696,11 +694,11 @@ void CollectionCatalog::onOpenDatabase(OperationContext* opCtx, _viewsForDatabase[dbName] = std::move(viewsForDb); } -void CollectionCatalog::onCloseDatabase(OperationContext* opCtx, TenantDatabaseName tenantDbName) { - invariant(opCtx->lockState()->isDbLockedForMode(tenantDbName.dbName(), MODE_X)); - auto rid = ResourceId(RESOURCE_DATABASE, tenantDbName.dbName()); - removeResource(rid, tenantDbName.dbName()); - _viewsForDatabase.erase(tenantDbName); +void CollectionCatalog::onCloseDatabase(OperationContext* opCtx, DatabaseName dbName) { + invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_X)); + auto rid = ResourceId(RESOURCE_DATABASE, dbName.toString()); + removeResource(rid, dbName.toString()); + _viewsForDatabase.erase(dbName); } void CollectionCatalog::onCloseCatalog(OperationContext* opCtx) { @@ -961,7 +959,7 @@ boost::optional<UUID> CollectionCatalog::lookupUUIDByNSS(OperationContext* opCtx } void CollectionCatalog::iterateViews(OperationContext* opCtx, - const TenantDatabaseName& dbName, + const DatabaseName& dbName, ViewIteratorCallback callback, ViewCatalogLookupBehavior lookupBehavior) const { auto viewsForDb = _getViewsForDatabase(opCtx, dbName); @@ -982,7 +980,7 @@ void CollectionCatalog::iterateViews(OperationContext* opCtx, std::shared_ptr<const ViewDefinition> CollectionCatalog::lookupView( OperationContext* opCtx, const NamespaceString& ns) const { - auto viewsForDb = _getViewsForDatabase(opCtx, TenantDatabaseName(boost::none, ns.db())); + auto viewsForDb = _getViewsForDatabase(opCtx, DatabaseName(boost::none, ns.db())); if (!viewsForDb) { return nullptr; } @@ -1004,7 +1002,7 @@ std::shared_ptr<const ViewDefinition> CollectionCatalog::lookupView( std::shared_ptr<const ViewDefinition> CollectionCatalog::lookupViewWithoutValidatingDurable( OperationContext* opCtx, const NamespaceString& ns) const { - auto viewsForDb = _getViewsForDatabase(opCtx, TenantDatabaseName(boost::none, ns.db())); + auto viewsForDb = _getViewsForDatabase(opCtx, DatabaseName(boost::none, ns.db())); if (!viewsForDb) { return nullptr; } @@ -1047,13 +1045,12 @@ bool CollectionCatalog::checkIfCollectionSatisfiable(UUID uuid, CollectionInfoFn return predicate(collection.get()); } -std::vector<UUID> CollectionCatalog::getAllCollectionUUIDsFromDb( - const TenantDatabaseName& tenantDbName) const { +std::vector<UUID> CollectionCatalog::getAllCollectionUUIDsFromDb(const DatabaseName& dbName) const { auto minUuid = UUID::parse("00000000-0000-0000-0000-000000000000").getValue(); - auto it = _orderedCollections.lower_bound(std::make_pair(tenantDbName, minUuid)); + auto it = _orderedCollections.lower_bound(std::make_pair(dbName, minUuid)); std::vector<UUID> ret; - while (it != _orderedCollections.end() && it->first.first == tenantDbName) { + while (it != _orderedCollections.end() && it->first.first == dbName) { if (it->second->isCommitted()) { ret.push_back(it->first.second); } @@ -1063,14 +1060,14 @@ std::vector<UUID> CollectionCatalog::getAllCollectionUUIDsFromDb( } std::vector<NamespaceString> CollectionCatalog::getAllCollectionNamesFromDb( - OperationContext* opCtx, const TenantDatabaseName& tenantDbName) const { - invariant(opCtx->lockState()->isDbLockedForMode(tenantDbName.dbName(), MODE_S)); + OperationContext* opCtx, const DatabaseName& dbName) const { + invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_S)); auto minUuid = UUID::parse("00000000-0000-0000-0000-000000000000").getValue(); std::vector<NamespaceString> ret; - for (auto it = _orderedCollections.lower_bound(std::make_pair(tenantDbName, minUuid)); - it != _orderedCollections.end() && it->first.first == tenantDbName; + for (auto it = _orderedCollections.lower_bound(std::make_pair(dbName, minUuid)); + it != _orderedCollections.end() && it->first.first == dbName; ++it) { if (it->second->isCommitted()) { ret.push_back(it->second->ns()); @@ -1079,23 +1076,23 @@ std::vector<NamespaceString> CollectionCatalog::getAllCollectionNamesFromDb( return ret; } -std::vector<TenantDatabaseName> CollectionCatalog::getAllDbNames() const { - std::vector<TenantDatabaseName> ret; +std::vector<DatabaseName> CollectionCatalog::getAllDbNames() const { + std::vector<DatabaseName> ret; auto maxUuid = UUID::parse("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF").getValue(); - auto iter = _orderedCollections.upper_bound(std::make_pair(TenantDatabaseName(), maxUuid)); + auto iter = _orderedCollections.upper_bound(std::make_pair(DatabaseName(), maxUuid)); while (iter != _orderedCollections.end()) { - auto tenantDbName = iter->first.first; + auto dbName = iter->first.first; if (iter->second->isCommitted()) { - ret.push_back(tenantDbName); + ret.push_back(dbName); } else { - // If the first collection found for `tenantDbName` is not yet committed, increment the + // If the first collection found for `dbName` is not yet committed, increment the // iterator to find the next visible collection (possibly under a different - // `tenantDbName`). + // `dbName`). iter++; continue; } - // Move on to the next database after `tenantDbName`. - iter = _orderedCollections.upper_bound(std::make_pair(tenantDbName, maxUuid)); + // Move on to the next database after `dbName`. + iter = _orderedCollections.upper_bound(std::make_pair(dbName, maxUuid)); } return ret; } @@ -1124,7 +1121,7 @@ CollectionCatalog::Stats CollectionCatalog::getStats() const { } boost::optional<ViewsForDatabase::Stats> CollectionCatalog::getViewStatsForDatabase( - OperationContext* opCtx, const TenantDatabaseName& dbName) const { + OperationContext* opCtx, const DatabaseName& dbName) const { auto viewsForDb = _getViewsForDatabase(opCtx, dbName); if (!viewsForDb) { return boost::none; @@ -1147,7 +1144,7 @@ void CollectionCatalog::registerCollection(OperationContext* opCtx, std::shared_ptr<Collection> coll) { auto nss = coll->ns(); // TODO SERVER-64608 Use tenantId from nss - auto tenantDbName = TenantDatabaseName(boost::none, nss.db()); + auto dbName = DatabaseName(boost::none, nss.db()); _ensureNamespaceDoesNotExist(opCtx, nss, NamespaceType::kAll); LOGV2_DEBUG(20280, @@ -1157,7 +1154,7 @@ void CollectionCatalog::registerCollection(OperationContext* opCtx, logAttrs(nss), "uuid"_attr = uuid); - auto dbIdPair = std::make_pair(tenantDbName, uuid); + auto dbIdPair = std::make_pair(dbName, uuid); // Make sure no entry related to this uuid. invariant(_catalog.find(uuid) == _catalog.end()); @@ -1181,9 +1178,9 @@ void CollectionCatalog::registerCollection(OperationContext* opCtx, invariant(static_cast<size_t>(_stats.internal + _stats.userCollections) == _collections.size()); - // TODO SERVER-62918 create ResourceId for db with TenantDatabaseName. - auto dbRid = ResourceId(RESOURCE_DATABASE, tenantDbName.dbName()); - addResource(dbRid, tenantDbName.dbName()); + // TODO SERVER-62918 create ResourceId for db with DatabaseName. + auto dbRid = ResourceId(RESOURCE_DATABASE, dbName.toString()); + addResource(dbRid, dbName.toString()); auto collRid = ResourceId(RESOURCE_COLLECTION, nss.ns()); addResource(collRid, nss.ns()); @@ -1196,8 +1193,8 @@ std::shared_ptr<Collection> CollectionCatalog::deregisterCollection(OperationCon auto coll = std::move(_catalog[uuid]); auto ns = coll->ns(); // TODO SERVER-64608 Use tenantID from ns - auto tenantDbName = TenantDatabaseName(boost::none, coll->ns().db()); - auto dbIdPair = std::make_pair(tenantDbName, uuid); + auto dbName = DatabaseName(boost::none, coll->ns().db()); + auto dbIdPair = std::make_pair(dbName, uuid); LOGV2_DEBUG(20281, 1, "Deregistering collection", logAttrs(ns), "uuid"_attr = uuid); @@ -1266,8 +1263,7 @@ void CollectionCatalog::_ensureNamespaceDoesNotExist(OperationContext* opCtx, throw WriteConflictException(); } - if (auto viewsForDb = - _getViewsForDatabase(opCtx, TenantDatabaseName(boost::none, nss.db()))) { + if (auto viewsForDb = _getViewsForDatabase(opCtx, DatabaseName(boost::none, nss.db()))) { if (viewsForDb->lookup(nss) != nullptr) { LOGV2( 5725003, @@ -1301,10 +1297,9 @@ void CollectionCatalog::deregisterAllCollectionsAndViews() { _resourceInformation.clear(); } -void CollectionCatalog::clearViews(OperationContext* opCtx, - const TenantDatabaseName& dbName) const { +void CollectionCatalog::clearViews(OperationContext* opCtx, const DatabaseName& dbName) const { invariant(opCtx->lockState()->isCollectionLockedForMode( - NamespaceString(dbName.dbName(), NamespaceString::kSystemDotViewsCollectionName), MODE_X)); + NamespaceString(dbName, NamespaceString::kSystemDotViewsCollectionName), MODE_X)); auto it = _viewsForDatabase.find(dbName); invariant(it != _viewsForDatabase.end()); @@ -1321,8 +1316,8 @@ void CollectionCatalog::clearViews(OperationContext* opCtx, } CollectionCatalog::iterator CollectionCatalog::begin(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) const { - return iterator(opCtx, tenantDbName, *this); + const DatabaseName& dbName) const { + return iterator(opCtx, dbName, *this); } CollectionCatalog::iterator CollectionCatalog::end(OperationContext* opCtx) const { @@ -1393,9 +1388,9 @@ void CollectionCatalog::invariantHasExclusiveAccessToCollection(OperationContext } boost::optional<const ViewsForDatabase&> CollectionCatalog::_getViewsForDatabase( - OperationContext* opCtx, const TenantDatabaseName& dbName) const { + OperationContext* opCtx, const DatabaseName& dbName) const { auto& uncommittedCatalogUpdates = UncommittedCatalogUpdates::get(opCtx); - auto uncommittedViews = uncommittedCatalogUpdates.getViewsForDatabase(dbName.dbName()); + auto uncommittedViews = uncommittedCatalogUpdates.getViewsForDatabase(dbName.db()); if (uncommittedViews) { return uncommittedViews; } @@ -1407,7 +1402,7 @@ boost::optional<const ViewsForDatabase&> CollectionCatalog::_getViewsForDatabase return it->second; } -void CollectionCatalog::_replaceViewsForDatabase(const TenantDatabaseName& dbName, +void CollectionCatalog::_replaceViewsForDatabase(const DatabaseName& dbName, ViewsForDatabase&& views) { _viewsForDatabase[dbName] = std::move(views); } diff --git a/src/mongo/db/catalog/collection_catalog.h b/src/mongo/db/catalog/collection_catalog.h index f660cc9deee..2ed0ca69e6b 100644 --- a/src/mongo/db/catalog/collection_catalog.h +++ b/src/mongo/db/catalog/collection_catalog.h @@ -35,9 +35,9 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/views_for_database.h" +#include "mongo/db/database_name.h" #include "mongo/db/profile_filter.h" #include "mongo/db/service_context.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/db/views/view.h" #include "mongo/stdx/unordered_map.h" #include "mongo/util/uuid.h" @@ -64,10 +64,10 @@ public: using value_type = CollectionPtr; iterator(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName, + const DatabaseName& dbName, const CollectionCatalog& catalog); iterator(OperationContext* opCtx, - std::map<std::pair<TenantDatabaseName, UUID>, + std::map<std::pair<DatabaseName, UUID>, std::shared_ptr<Collection>>::const_iterator mapIter, const CollectionCatalog& catalog); value_type operator*(); @@ -88,9 +88,9 @@ public: bool _exhausted(); OperationContext* _opCtx; - TenantDatabaseName _tenantDbName; + DatabaseName _dbName; boost::optional<UUID> _uuid; - std::map<std::pair<TenantDatabaseName, UUID>, std::shared_ptr<Collection>>::const_iterator + std::map<std::pair<DatabaseName, UUID>, std::shared_ptr<Collection>>::const_iterator _mapIter; const CollectionCatalog* _catalog; }; @@ -192,7 +192,7 @@ public: * * Requires an IS lock on the 'system.views' collection'. */ - Status reloadViews(OperationContext* opCtx, const TenantDatabaseName& dbName) const; + Status reloadViews(OperationContext* opCtx, const DatabaseName& dbName) const; /** * Handles committing a collection to the catalog within a WriteUnitOfWork. @@ -225,15 +225,15 @@ public: * database has already been initialized. */ void onOpenDatabase(OperationContext* opCtx, - const TenantDatabaseName& dbName, + const DatabaseName& dbName, ViewsForDatabase&& viewsForDb); /** - * Removes the view records associated with 'tenantDbName', if any, from the in-memory + * Removes the view records associated with 'dbName', if any, from the in-memory * representation of the catalog. Should be called when Database instance is closed. Requires X * lock on database namespace. */ - void onCloseDatabase(OperationContext* opCtx, TenantDatabaseName tenantDbName); + void onCloseDatabase(OperationContext* opCtx, DatabaseName dbName); /** * Register the collection with `uuid`. @@ -268,7 +268,7 @@ public: * * Callers must re-fetch the catalog to observe changes. */ - void clearViews(OperationContext* opCtx, const TenantDatabaseName& dbName) const; + void clearViews(OperationContext* opCtx, const DatabaseName& dbName) const; /** * This function gets the Collection pointer that corresponds to the UUID. @@ -343,7 +343,7 @@ public: */ void iterateViews( OperationContext* opCtx, - const TenantDatabaseName& dbName, + const DatabaseName& dbName, ViewIteratorCallback callback, ViewCatalogLookupBehavior lookupBehavior = ViewCatalogLookupBehavior::kValidateViews) const; @@ -380,25 +380,25 @@ public: bool checkIfCollectionSatisfiable(UUID uuid, CollectionInfoFn predicate) const; /** - * This function gets the UUIDs of all collections from `tenantDbName`. + * This function gets the UUIDs of all collections from `dbName`. * * If the caller does not take a strong database lock, some of UUIDs might no longer exist (due * to collection drop) after this function returns. * - * Returns empty vector if the 'tenantDbName' is not known. + * Returns empty vector if the 'dbName' is not known. */ - std::vector<UUID> getAllCollectionUUIDsFromDb(const TenantDatabaseName& tenantDbName) const; + std::vector<UUID> getAllCollectionUUIDsFromDb(const DatabaseName& dbName) const; /** - * This function gets the ns of all collections from `tenantDbName`. The result is not sorted. + * This function gets the ns of all collections from `dbName`. The result is not sorted. * * Caller must take a strong database lock; otherwise, collections returned could be dropped or * renamed. * - * Returns empty vector if the 'tenantDbName' is not known. + * Returns empty vector if the 'dbName' is not known. */ - std::vector<NamespaceString> getAllCollectionNamesFromDb( - OperationContext* opCtx, const TenantDatabaseName& tenantDbName) const; + std::vector<NamespaceString> getAllCollectionNamesFromDb(OperationContext* opCtx, + const DatabaseName& dbName) const; /** * This functions gets all the database names. The result is sorted in alphabetical ascending @@ -406,7 +406,7 @@ public: * * Unlike DatabaseHolder::getNames(), this does not return databases that are empty. */ - std::vector<TenantDatabaseName> getAllDbNames() const; + std::vector<DatabaseName> getAllDbNames() const; /** * Sets 'newProfileSettings' as the profiling settings for the database 'dbName'. @@ -461,12 +461,12 @@ public: * Returns view statistics for the specified database. */ boost::optional<ViewsForDatabase::Stats> getViewStatsForDatabase( - OperationContext* opCtx, const TenantDatabaseName& dbName) const; + OperationContext* opCtx, const DatabaseName& dbName) const; /** * Returns a set of databases, by name, that have view catalogs. */ - using ViewCatalogSet = absl::flat_hash_set<TenantDatabaseName>; + using ViewCatalogSet = absl::flat_hash_set<DatabaseName>; ViewCatalogSet getViewCatalogDbNames(OperationContext* opCtx) const; /** @@ -497,7 +497,7 @@ public: */ uint64_t getEpoch() const; - iterator begin(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) const; + iterator begin(OperationContext* opCtx, const DatabaseName& dbName) const; iterator end(OperationContext* opCtx) const; /** @@ -533,14 +533,14 @@ private: * Retrieves the views for a given database, including any uncommitted changes for this * operation. */ - boost::optional<const ViewsForDatabase&> _getViewsForDatabase( - OperationContext* opCtx, const TenantDatabaseName& dbName) const; + boost::optional<const ViewsForDatabase&> _getViewsForDatabase(OperationContext* opCtx, + const DatabaseName& dbName) const; /** * Sets all namespaces used by views for a database. Will uassert if there is a conflicting * collection name in the catalog. */ - void _replaceViewsForDatabase(const TenantDatabaseName& dbName, ViewsForDatabase&& views); + void _replaceViewsForDatabase(const DatabaseName& dbName, ViewsForDatabase&& views); enum class ViewUpsertMode { // Insert all data for that view into the view map, view graph, and durable view catalog. @@ -601,15 +601,15 @@ private: using CollectionCatalogMap = stdx::unordered_map<UUID, std::shared_ptr<Collection>, UUID::Hash>; using OrderedCollectionMap = - std::map<std::pair<TenantDatabaseName, UUID>, std::shared_ptr<Collection>>; + std::map<std::pair<DatabaseName, UUID>, std::shared_ptr<Collection>>; using NamespaceCollectionMap = stdx::unordered_map<NamespaceString, std::shared_ptr<Collection>>; using UncommittedViewsSet = stdx::unordered_set<NamespaceString>; using DatabaseProfileSettingsMap = StringMap<ProfileSettings>; - using ViewsForDatabaseMap = stdx::unordered_map<TenantDatabaseName, ViewsForDatabase>; + using ViewsForDatabaseMap = stdx::unordered_map<DatabaseName, ViewsForDatabase>; CollectionCatalogMap _catalog; - OrderedCollectionMap _orderedCollections; // Ordered by <tenantDbName, collUUID> pair + OrderedCollectionMap _orderedCollections; // Ordered by <dbName, collUUID> pair NamespaceCollectionMap _collections; UncommittedViewsSet _uncommittedViews; diff --git a/src/mongo/db/catalog/collection_catalog_helper.cpp b/src/mongo/db/catalog/collection_catalog_helper.cpp index f6db8f69764..a06a6f6566e 100644 --- a/src/mongo/db/catalog/collection_catalog_helper.cpp +++ b/src/mongo/db/catalog/collection_catalog_helper.cpp @@ -60,13 +60,13 @@ Status checkIfNamespaceExists(OperationContext* opCtx, const NamespaceString& ns void forEachCollectionFromDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName, + const DatabaseName& dbName, LockMode collLockMode, CollectionCatalog::CollectionInfoFn callback, CollectionCatalog::CollectionInfoFn predicate) { auto catalogForIteration = CollectionCatalog::get(opCtx); - for (auto collectionIt = catalogForIteration->begin(opCtx, tenantDbName); + for (auto collectionIt = catalogForIteration->begin(opCtx, dbName); collectionIt != catalogForIteration->end(opCtx);) { auto uuid = collectionIt.uuid().get(); if (predicate && !catalogForIteration->checkIfCollectionSatisfiable(uuid, predicate)) { diff --git a/src/mongo/db/catalog/collection_catalog_helper.h b/src/mongo/db/catalog/collection_catalog_helper.h index 60751e6b537..7b47eca2f8b 100644 --- a/src/mongo/db/catalog/collection_catalog_helper.h +++ b/src/mongo/db/catalog/collection_catalog_helper.h @@ -62,7 +62,7 @@ Status checkIfNamespaceExists(OperationContext* opCtx, const NamespaceString& ns * Iterating through the remaining collections stops when the callback returns false. */ void forEachCollectionFromDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName, + const DatabaseName& dbName, LockMode collLockMode, CollectionCatalog::CollectionInfoFn callback, CollectionCatalog::CollectionInfoFn predicate = nullptr); diff --git a/src/mongo/db/catalog/collection_catalog_test.cpp b/src/mongo/db/catalog/collection_catalog_test.cpp index e28bcd4ad28..521c3938663 100644 --- a/src/mongo/db/catalog/collection_catalog_test.cpp +++ b/src/mongo/db/catalog/collection_catalog_test.cpp @@ -132,13 +132,12 @@ public: return it->second.end(); } - void checkCollections(const TenantDatabaseName& tenantDbName) { + void checkCollections(const DatabaseName& dbName) { unsigned long counter = 0; - for (auto [orderedIt, catalogIt] = std::tuple{collsIterator(tenantDbName.dbName()), - catalog.begin(&opCtx, tenantDbName)}; - catalogIt != catalog.end(&opCtx) && - orderedIt != collsIteratorEnd(tenantDbName.dbName()); + for (auto [orderedIt, catalogIt] = + std::tuple{collsIterator(dbName.toString()), catalog.begin(&opCtx, dbName)}; + catalogIt != catalog.end(&opCtx) && orderedIt != collsIteratorEnd(dbName.toString()); ++catalogIt, ++orderedIt) { auto catalogColl = *catalogIt; @@ -148,7 +147,7 @@ public: ++counter; } - ASSERT_EQUALS(counter, dbMap[tenantDbName.dbName()].size()); + ASSERT_EQUALS(counter, dbMap[dbName.toString()].size()); } void dropColl(const std::string dbName, UUID uuid) { @@ -291,7 +290,7 @@ public: } int numEntries = 0; - for (auto it = catalog.begin(&opCtx, TenantDatabaseName(boost::none, "resourceDb")); + for (auto it = catalog.begin(&opCtx, DatabaseName(boost::none, "resourceDb")); it != catalog.end(&opCtx); it++) { auto coll = *it; @@ -306,7 +305,7 @@ public: void tearDown() { std::vector<UUID> collectionsToDeregister; - for (auto it = catalog.begin(&opCtx, TenantDatabaseName(boost::none, "resourceDb")); + for (auto it = catalog.begin(&opCtx, DatabaseName(boost::none, "resourceDb")); it != catalog.end(&opCtx); ++it) { auto coll = *it; @@ -323,7 +322,7 @@ public: } int numEntries = 0; - for (auto it = catalog.begin(&opCtx, TenantDatabaseName(boost::none, "resourceDb")); + for (auto it = catalog.begin(&opCtx, DatabaseName(boost::none, "resourceDb")); it != catalog.end(&opCtx); it++) { numEntries++; @@ -391,18 +390,18 @@ TEST_F(CollectionCatalogResourceTest, RemoveCollection) { // Create an iterator over the CollectionCatalog and assert that all collections are present. // Iteration ends when the end of the catalog is reached. TEST_F(CollectionCatalogIterationTest, EndAtEndOfCatalog) { - checkCollections(TenantDatabaseName(boost::none, "foo")); + checkCollections(DatabaseName(boost::none, "foo")); } // Create an iterator over the CollectionCatalog and test that all collections are present. // Iteration ends // when the end of a database-specific section of the catalog is reached. TEST_F(CollectionCatalogIterationTest, EndAtEndOfSection) { - checkCollections(TenantDatabaseName(boost::none, "bar")); + checkCollections(DatabaseName(boost::none, "bar")); } TEST_F(CollectionCatalogIterationTest, GetUUIDWontRepositionEvenIfEntryIsDropped) { - auto it = catalog.begin(&opCtx, TenantDatabaseName(boost::none, "bar")); + auto it = catalog.begin(&opCtx, DatabaseName(boost::none, "bar")); auto collsIt = collsIterator("bar"); auto uuid = collsIt->first; catalog.deregisterCollection(&opCtx, uuid); @@ -627,17 +626,16 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNames) { std::vector<NamespaceString> dCollList = {d1Coll, d2Coll, d3Coll}; Lock::DBLock dbLock(opCtx.get(), "dbD", MODE_S); - auto res = - catalog.getAllCollectionNamesFromDb(opCtx.get(), TenantDatabaseName(boost::none, "dbD")); + auto res = catalog.getAllCollectionNamesFromDb(opCtx.get(), DatabaseName(boost::none, "dbD")); std::sort(res.begin(), res.end()); ASSERT(res == dCollList); - std::vector<TenantDatabaseName> tenantDbNames = {TenantDatabaseName(boost::none, "dbA"), - TenantDatabaseName(boost::none, "dbB"), - TenantDatabaseName(boost::none, "dbC"), - TenantDatabaseName(boost::none, "dbD"), - TenantDatabaseName(boost::none, "testdb")}; - ASSERT(catalog.getAllDbNames() == tenantDbNames); + std::vector<DatabaseName> dbNames = {DatabaseName(boost::none, "dbA"), + DatabaseName(boost::none, "dbB"), + DatabaseName(boost::none, "dbC"), + DatabaseName(boost::none, "dbD"), + DatabaseName(boost::none, "testdb")}; + ASSERT(catalog.getAllDbNames() == dbNames); catalog.deregisterAllCollectionsAndViews(); } @@ -687,15 +685,14 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt invisibleCollA->setCommitted(false); Lock::DBLock dbLock(opCtx.get(), "dbA", MODE_S); - auto res = - catalog.getAllCollectionNamesFromDb(opCtx.get(), TenantDatabaseName(boost::none, "dbA")); + auto res = catalog.getAllCollectionNamesFromDb(opCtx.get(), DatabaseName(boost::none, "dbA")); ASSERT(res.empty()); - std::vector<TenantDatabaseName> tenantDbNames = {TenantDatabaseName(boost::none, "dbB"), - TenantDatabaseName(boost::none, "dbC"), - TenantDatabaseName(boost::none, "dbD"), - TenantDatabaseName(boost::none, "testdb")}; - ASSERT(catalog.getAllDbNames() == tenantDbNames); + std::vector<DatabaseName> dbNames = {DatabaseName(boost::none, "dbB"), + DatabaseName(boost::none, "dbC"), + DatabaseName(boost::none, "dbD"), + DatabaseName(boost::none, "testdb")}; + ASSERT(catalog.getAllDbNames() == dbNames); // One dbName with both visible and invisible collections is still visible. std::vector<NamespaceString> dbDNss = {d1Coll, d2Coll, d3Coll}; @@ -712,12 +709,11 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt invisibleCollD->setCommitted(false); Lock::DBLock dbLock(opCtx.get(), "dbD", MODE_S); - res = catalog.getAllCollectionNamesFromDb(opCtx.get(), - TenantDatabaseName(boost::none, "dbD")); + res = catalog.getAllCollectionNamesFromDb(opCtx.get(), DatabaseName(boost::none, "dbD")); std::sort(res.begin(), res.end()); ASSERT(res == dCollList); - ASSERT(catalog.getAllDbNames() == tenantDbNames); + ASSERT(catalog.getAllDbNames() == dbNames); invisibleCollD->setCommitted(true); } @@ -732,7 +728,7 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt invisibleColl->setCommitted(false); } - std::vector<TenantDatabaseName> dbList = {TenantDatabaseName(boost::none, "testdb")}; + std::vector<DatabaseName> dbList = {DatabaseName(boost::none, "testdb")}; ASSERT(catalog.getAllDbNames() == dbList); catalog.deregisterAllCollectionsAndViews(); @@ -764,9 +760,9 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) { { auto dbLock = std::make_unique<Lock::DBLock>(opCtx, "db", MODE_IX); int numCollectionsTraversed = 0; - const TenantDatabaseName tenantDbName(boost::none, "db"); + const DatabaseName dbName(boost::none, "db"); catalog::forEachCollectionFromDb( - opCtx, tenantDbName, MODE_X, [&](const CollectionPtr& collection) { + opCtx, dbName, MODE_X, [&](const CollectionPtr& collection) { ASSERT_TRUE( opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_X)); numCollectionsTraversed++; @@ -779,9 +775,9 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) { { auto dbLock = std::make_unique<Lock::DBLock>(opCtx, "db2", MODE_IX); int numCollectionsTraversed = 0; - const TenantDatabaseName tenantDbName(boost::none, "db2"); + const DatabaseName dbName(boost::none, "db2"); catalog::forEachCollectionFromDb( - opCtx, tenantDbName, MODE_IS, [&](const CollectionPtr& collection) { + opCtx, dbName, MODE_IS, [&](const CollectionPtr& collection) { ASSERT_TRUE( opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_IS)); numCollectionsTraversed++; @@ -794,9 +790,9 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) { { auto dbLock = std::make_unique<Lock::DBLock>(opCtx, "db3", MODE_IX); int numCollectionsTraversed = 0; - const TenantDatabaseName tenantDbName(boost::none, "db3"); + const DatabaseName dbName(boost::none, "db3"); catalog::forEachCollectionFromDb( - opCtx, tenantDbName, MODE_S, [&](const CollectionPtr& collection) { + opCtx, dbName, MODE_S, [&](const CollectionPtr& collection) { numCollectionsTraversed++; return true; }); @@ -812,10 +808,10 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDbWithPredicate) { { auto dbLock = std::make_unique<Lock::DBLock>(opCtx, "db", MODE_IX); int numCollectionsTraversed = 0; - const TenantDatabaseName tenantDbName(boost::none, "db"); + const DatabaseName dbName(boost::none, "db"); catalog::forEachCollectionFromDb( opCtx, - tenantDbName, + dbName, MODE_X, [&](const CollectionPtr& collection) { ASSERT_TRUE( @@ -835,10 +831,10 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDbWithPredicate) { { auto dbLock = std::make_unique<Lock::DBLock>(opCtx, "db", MODE_IX); int numCollectionsTraversed = 0; - const TenantDatabaseName tenantDbName(boost::none, "db"); + const DatabaseName dbName(boost::none, "db"); catalog::forEachCollectionFromDb( opCtx, - tenantDbName, + dbName, MODE_IX, [&](const CollectionPtr& collection) { ASSERT_TRUE( diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp index 0fefc706426..d98d0eb19fb 100644 --- a/src/mongo/db/catalog/collection_impl.cpp +++ b/src/mongo/db/catalog/collection_impl.cpp @@ -231,7 +231,7 @@ Status checkValidationOptionsCanBeUsed(const CollectionOptions& opts, Status validateIsNotInDbs(const NamespaceString& ns, const std::vector<StringData>& disallowedDbs, StringData optionName) { - // TODO SERVER-62491 Check for TenantDatabaseName instead + // TODO SERVER-62491 Check for DatabaseName instead if (std::find(disallowedDbs.begin(), disallowedDbs.end(), ns.db()) != disallowedDbs.end()) { return {ErrorCodes::InvalidOptions, str::stream() << optionName << " collection option is not supported on the " diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index c66c6eab926..81ef7a641e3 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -45,6 +45,7 @@ #include "mongo/db/commands/create_gen.h" #include "mongo/db/concurrency/exception_util.h" #include "mongo/db/curop.h" +#include "mongo/db/database_name.h" #include "mongo/db/db_raii.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/index_builds_coordinator.h" @@ -55,7 +56,6 @@ #include "mongo/db/query/collation/collator_factory_interface.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/storage/storage_parameters_gen.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/db/timeseries/timeseries_options.h" #include "mongo/idl/command_generic_argument.h" #include "mongo/logv2/log.h" @@ -692,7 +692,7 @@ void createChangeStreamPreImagesCollection(OperationContext* opCtx) { status.isOK() || status.code() == ErrorCodes::NamespaceExists); } -// TODO SERVER-62880 pass TenantDatabaseName instead of dbName. +// TODO SERVER-62880 pass DatabaseName instead of dbName. Status createCollectionForApplyOps(OperationContext* opCtx, const std::string& dbName, const boost::optional<UUID>& ui, @@ -705,7 +705,7 @@ Status createCollectionForApplyOps(OperationContext* opCtx, auto newCmd = cmdObj; auto databaseHolder = DatabaseHolder::get(opCtx); - const TenantDatabaseName tenantDbName(boost::none, dbName); + const DatabaseName tenantDbName(boost::none, dbName); auto* const db = databaseHolder->getDb(opCtx, tenantDbName); // If a UUID is given, see if we need to rename a collection out of the way, and whether the diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h index 2640abefbcb..96582b34fd4 100644 --- a/src/mongo/db/catalog/database.h +++ b/src/mongo/db/catalog/database.h @@ -38,9 +38,9 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_options.h" +#include "mongo/db/database_name.h" #include "mongo/db/namespace_string.h" #include "mongo/db/repl/optime.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/util/string_map.h" namespace mongo { @@ -81,7 +81,7 @@ public: */ virtual Status init(OperationContext* opCtx) = 0; - virtual const TenantDatabaseName& name() const = 0; + virtual const DatabaseName& name() const = 0; virtual void clearTmpCollections(OperationContext* opCtx) const = 0; diff --git a/src/mongo/db/catalog/database_holder.h b/src/mongo/db/catalog/database_holder.h index 5b06a1765a7..3a7918acda8 100644 --- a/src/mongo/db/catalog/database_holder.h +++ b/src/mongo/db/catalog/database_holder.h @@ -35,7 +35,7 @@ #include "mongo/base/string_data.h" #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_options.h" -#include "mongo/db/tenant_database_name.h" +#include "mongo/db/database_name.h" namespace mongo { @@ -64,15 +64,13 @@ public: * Retrieves an already opened database or returns nullptr. Must be called with the database * locked in at least IS-mode. */ - virtual Database* getDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) const = 0; + virtual Database* getDb(OperationContext* opCtx, const DatabaseName& dbName) const = 0; /** * Checks if a database exists without holding a database-level lock. This class' internal mutex - * provides concurrency protection around looking up the db name of 'tenantDbName'. + * provides concurrency protection around looking up the db name of 'dbName'. */ - virtual bool dbExists(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) const = 0; + virtual bool dbExists(OperationContext* opCtx, const DatabaseName& dbName) const = 0; /** * Retrieves a database reference if it is already opened, or opens it if it hasn't been @@ -82,7 +80,7 @@ public: * existed (false). Can be NULL if this information is not necessary. */ virtual Database* openDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName, + const DatabaseName& dbName, bool* justCreated = nullptr) = 0; /** @@ -99,7 +97,7 @@ public: * Closes the specified database. Must be called with the database locked in X-mode. * No background jobs must be in progress on the database when this function is called. */ - virtual void close(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) = 0; + virtual void close(OperationContext* opCtx, const DatabaseName& dbName) = 0; /** * Closes all opened databases. Must be called with the global lock acquired in X-mode. @@ -112,15 +110,14 @@ public: /** * Returns the set of existing database names that differ only in casing. */ - virtual std::set<TenantDatabaseName> getNamesWithConflictingCasing( - const TenantDatabaseName& tenantDbName) = 0; + virtual std::set<DatabaseName> getNamesWithConflictingCasing(const DatabaseName& dbName) = 0; /** * Returns all the database names (including those which are empty). * * Unlike CollectionCatalog::getAllDbNames(), this returns databases that are empty. */ - virtual std::vector<TenantDatabaseName> getNames() = 0; + virtual std::vector<DatabaseName> getNames() = 0; }; } // namespace mongo diff --git a/src/mongo/db/catalog/database_holder_impl.cpp b/src/mongo/db/catalog/database_holder_impl.cpp index 95e6d551413..1630f7df0a4 100644 --- a/src/mongo/db/catalog/database_holder_impl.cpp +++ b/src/mongo/db/catalog/database_holder_impl.cpp @@ -50,18 +50,17 @@ namespace mongo { -Database* DatabaseHolderImpl::getDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) const { - uassert(13280, - "invalid db name: " + tenantDbName.dbName(), - NamespaceString::validDBName(tenantDbName.dbName(), - NamespaceString::DollarInDbNameBehavior::Allow)); +Database* DatabaseHolderImpl::getDb(OperationContext* opCtx, const DatabaseName& dbName) const { + uassert( + 13280, + "invalid db name: " + dbName.db(), + NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(tenantDbName.dbName(), MODE_IS) || - (tenantDbName.dbName().compare("local") == 0 && opCtx->lockState()->isLocked())); + invariant(opCtx->lockState()->isDbLockedForMode(dbName.toString(), MODE_IS) || + (dbName.db().compare("local") == 0 && opCtx->lockState()->isLocked())); stdx::lock_guard<SimpleMutex> lk(_m); - DBs::const_iterator it = _dbs.find(tenantDbName); + DBs::const_iterator it = _dbs.find(dbName); if (it != _dbs.end()) { return it->second; } @@ -69,53 +68,51 @@ Database* DatabaseHolderImpl::getDb(OperationContext* opCtx, return nullptr; } -bool DatabaseHolderImpl::dbExists(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) const { - uassert(6198702, - "invalid db name: " + tenantDbName.dbName(), - NamespaceString::validDBName(tenantDbName.dbName(), - NamespaceString::DollarInDbNameBehavior::Allow)); +bool DatabaseHolderImpl::dbExists(OperationContext* opCtx, const DatabaseName& dbName) const { + uassert( + 6198702, + "invalid db name: " + dbName.db(), + NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); stdx::lock_guard<SimpleMutex> lk(_m); - auto it = _dbs.find(tenantDbName); + auto it = _dbs.find(dbName); return it != _dbs.end() && it->second != nullptr; } -std::set<TenantDatabaseName> DatabaseHolderImpl::_getNamesWithConflictingCasing_inlock( - const TenantDatabaseName& tenantDbName) { - std::set<TenantDatabaseName> duplicates; +std::set<DatabaseName> DatabaseHolderImpl::_getNamesWithConflictingCasing_inlock( + const DatabaseName& dbName) { + std::set<DatabaseName> duplicates; for (const auto& nameAndPointer : _dbs) { // A name that's equal with case-insensitive match must be identical, or it's a duplicate. - if (tenantDbName.equalCaseInsensitive(nameAndPointer.first) && - tenantDbName != nameAndPointer.first) + if (dbName.equalCaseInsensitive(nameAndPointer.first) && dbName != nameAndPointer.first) duplicates.insert(nameAndPointer.first); } return duplicates; } -std::set<TenantDatabaseName> DatabaseHolderImpl::getNamesWithConflictingCasing( - const TenantDatabaseName& tenantDbName) { +std::set<DatabaseName> DatabaseHolderImpl::getNamesWithConflictingCasing( + const DatabaseName& dbName) { stdx::lock_guard<SimpleMutex> lk(_m); - return _getNamesWithConflictingCasing_inlock(tenantDbName); + return _getNamesWithConflictingCasing_inlock(dbName); } -std::vector<TenantDatabaseName> DatabaseHolderImpl::getNames() { +std::vector<DatabaseName> DatabaseHolderImpl::getNames() { stdx::lock_guard<SimpleMutex> lk(_m); - std::vector<TenantDatabaseName> tenantDbNames; + std::vector<DatabaseName> dbNames; for (const auto& nameAndPointer : _dbs) { - tenantDbNames.push_back(nameAndPointer.first); + dbNames.push_back(nameAndPointer.first); } - return tenantDbNames; + return dbNames; } Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName, + const DatabaseName& dbName, bool* justCreated) { - uassert(6198701, - "invalid db name: " + tenantDbName.dbName(), - NamespaceString::validDBName(tenantDbName.dbName(), - NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(tenantDbName.dbName(), MODE_IX)); + uassert( + 6198701, + "invalid db name: " + dbName.db(), + NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_IX)); if (justCreated) *justCreated = false; // Until proven otherwise. @@ -124,14 +121,14 @@ Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, // The following will insert a nullptr for dbname, which will treated the same as a non- // existant database by the get method, yet still counts in getNamesWithConflictingCasing. - if (auto db = _dbs[tenantDbName]) + if (auto db = _dbs[dbName]) return db; // We've inserted a nullptr entry for dbname: make sure to remove it on unsuccessful exit. - ScopeGuard removeDbGuard([this, &lk, opCtx, tenantDbName] { + ScopeGuard removeDbGuard([this, &lk, opCtx, dbName] { if (!lk.owns_lock()) lk.lock(); - auto it = _dbs.find(tenantDbName); + auto it = _dbs.find(dbName); // If someone else hasn't either already removed it or already set it successfully, remove. if (it != _dbs.end() && !it->second) { _dbs.erase(it); @@ -143,24 +140,24 @@ Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, }); // Check casing in lock to avoid transient duplicates. - auto duplicates = _getNamesWithConflictingCasing_inlock(tenantDbName); + auto duplicates = _getNamesWithConflictingCasing_inlock(dbName); uassert(ErrorCodes::DatabaseDifferCase, str::stream() << "db already exists with different case already have: [" - << (*duplicates.cbegin()) << "] trying to create [" - << tenantDbName.toString() << "]", + << (*duplicates.cbegin()) << "] trying to create [" << dbName.toString() + << "]", duplicates.empty()); // Do the catalog lookup and database creation outside of the scoped lock, because these may // block. lk.unlock(); - if (CollectionCatalog::get(opCtx)->getAllCollectionUUIDsFromDb(tenantDbName).empty()) { - audit::logCreateDatabase(opCtx->getClient(), tenantDbName.dbName()); + if (CollectionCatalog::get(opCtx)->getAllCollectionUUIDsFromDb(dbName).empty()) { + audit::logCreateDatabase(opCtx->getClient(), dbName.toString()); if (justCreated) *justCreated = true; } - std::unique_ptr<DatabaseImpl> newDb = std::make_unique<DatabaseImpl>(tenantDbName); + std::unique_ptr<DatabaseImpl> newDb = std::make_unique<DatabaseImpl>(dbName); Status status = newDb->init(opCtx); while (!status.isOK()) { // If we get here, then initializing the database failed because another concurrent writer @@ -168,7 +165,7 @@ Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, // them to finish. lk.lock(); - auto it = _dbs.find(tenantDbName); + auto it = _dbs.find(dbName); if (it != _dbs.end() && it->second) { // Creating databases only requires a DB lock in MODE_IX. Thus databases can be created // concurrently. If this thread "lost the race", return the database object that was @@ -181,7 +178,7 @@ Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, // in such a way that we can easily express it as a predicate for that function. _c.wait_for(lk, stdx::chrono::milliseconds(1)); - it = _dbs.find(tenantDbName); + it = _dbs.find(dbName); if (it != _dbs.end() && it->second) { // As above, another writer finished successfully, return the persisted object. removeDbGuard.dismiss(); @@ -202,10 +199,10 @@ Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, removeDbGuard.dismiss(); lk.lock(); - invariant(!_dbs[tenantDbName]); + invariant(!_dbs[dbName]); auto* db = newDb.release(); - _dbs[tenantDbName] = db; - invariant(_getNamesWithConflictingCasing_inlock(tenantDbName).empty()); + _dbs[dbName] = db; + invariant(_getNamesWithConflictingCasing_inlock(dbName).empty()); _c.notify_all(); return db; @@ -219,7 +216,7 @@ void DatabaseHolderImpl::dropDb(OperationContext* opCtx, Database* db) { LOGV2_DEBUG(20310, 1, "dropDatabase {name}", "name"_attr = name); - invariant(opCtx->lockState()->isDbLockedForMode(name.dbName(), MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(name.db(), MODE_X)); auto catalog = CollectionCatalog::get(opCtx); for (auto collIt = catalog->begin(opCtx, name); collIt != catalog->end(opCtx); ++collIt) { @@ -234,7 +231,7 @@ void DatabaseHolderImpl::dropDb(OperationContext* opCtx, Database* db) { str::stream() << "An index is building on collection '" << coll->ns() << "'."); } - audit::logDropDatabase(opCtx->getClient(), name.dbName()); + audit::logDropDatabase(opCtx->getClient(), name.toString()); auto const serviceContext = opCtx->getServiceContext(); @@ -263,35 +260,35 @@ void DatabaseHolderImpl::dropDb(OperationContext* opCtx, Database* db) { // Clean up the in-memory database state. CollectionCatalog::write(opCtx, [&](CollectionCatalog& catalog) { - catalog.clearDatabaseProfileSettings(name.dbName()); + catalog.clearDatabaseProfileSettings(name.db()); }); close(opCtx, name); auto const storageEngine = serviceContext->getStorageEngine(); - writeConflictRetry(opCtx, "dropDatabase", name.dbName(), [&] { + writeConflictRetry(opCtx, "dropDatabase", name.toString(), [&] { storageEngine->dropDatabase(opCtx, name).transitional_ignore(); }); } -void DatabaseHolderImpl::close(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) { - uassert(6198700, - "invalid db name: " + tenantDbName.dbName(), - NamespaceString::validDBName(tenantDbName.dbName(), - NamespaceString::DollarInDbNameBehavior::Allow)); - invariant(opCtx->lockState()->isDbLockedForMode(tenantDbName.dbName(), MODE_X)); +void DatabaseHolderImpl::close(OperationContext* opCtx, const DatabaseName& dbName) { + uassert( + 6198700, + "invalid db name: " + dbName.db(), + NamespaceString::validDBName(dbName.db(), NamespaceString::DollarInDbNameBehavior::Allow)); + invariant(opCtx->lockState()->isDbLockedForMode(dbName.db(), MODE_X)); stdx::lock_guard<SimpleMutex> lk(_m); - DBs::const_iterator it = _dbs.find(tenantDbName); + DBs::const_iterator it = _dbs.find(dbName); if (it == _dbs.end()) { return; } auto db = it->second; - LOGV2_DEBUG(20311, 2, "DatabaseHolder::close", "db"_attr = tenantDbName); + LOGV2_DEBUG(20311, 2, "DatabaseHolder::close", "db"_attr = dbName); CollectionCatalog::write( - opCtx, [&](CollectionCatalog& catalog) { catalog.onCloseDatabase(opCtx, tenantDbName); }); + opCtx, [&](CollectionCatalog& catalog) { catalog.onCloseDatabase(opCtx, dbName); }); delete db; db = nullptr; @@ -299,20 +296,20 @@ void DatabaseHolderImpl::close(OperationContext* opCtx, const TenantDatabaseName _dbs.erase(it); auto* const storageEngine = opCtx->getServiceContext()->getStorageEngine(); - storageEngine->closeDatabase(opCtx, tenantDbName).transitional_ignore(); + storageEngine->closeDatabase(opCtx, dbName).transitional_ignore(); } void DatabaseHolderImpl::closeAll(OperationContext* opCtx) { invariant(opCtx->lockState()->isW()); while (true) { - std::vector<TenantDatabaseName> dbs; + std::vector<DatabaseName> dbs; { stdx::lock_guard<SimpleMutex> lk(_m); for (DBs::const_iterator i = _dbs.begin(); i != _dbs.end(); ++i) { // It is the caller's responsibility to ensure that no index builds are active in // the database. - IndexBuildsCoordinator::get(opCtx)->assertNoBgOpInProgForDb(i->first.dbName()); + IndexBuildsCoordinator::get(opCtx)->assertNoBgOpInProgForDb(i->first.toString()); dbs.push_back(i->first); } } diff --git a/src/mongo/db/catalog/database_holder_impl.h b/src/mongo/db/catalog/database_holder_impl.h index 849ba757e19..758bc0e4d9c 100644 --- a/src/mongo/db/catalog/database_holder_impl.h +++ b/src/mongo/db/catalog/database_holder_impl.h @@ -31,7 +31,7 @@ #include "mongo/db/catalog/database_holder.h" -#include "mongo/db/tenant_database_name.h" +#include "mongo/db/database_name.h" #include "mongo/stdx/condition_variable.h" #include "mongo/util/concurrency/mutex.h" #include "mongo/util/string_map.h" @@ -42,30 +42,28 @@ class DatabaseHolderImpl : public DatabaseHolder { public: DatabaseHolderImpl() = default; - Database* getDb(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) const override; + Database* getDb(OperationContext* opCtx, const DatabaseName& dbName) const override; - bool dbExists(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) const override; + bool dbExists(OperationContext* opCtx, const DatabaseName& dbName) const override; Database* openDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName, + const DatabaseName& dbName, bool* justCreated = nullptr) override; void dropDb(OperationContext* opCtx, Database* db) override; - void close(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) override; + void close(OperationContext* opCtx, const DatabaseName& dbName) override; void closeAll(OperationContext* opCtx) override; - std::set<TenantDatabaseName> getNamesWithConflictingCasing( - const TenantDatabaseName& tenantDbName) override; + std::set<DatabaseName> getNamesWithConflictingCasing(const DatabaseName& dbName) override; - std::vector<TenantDatabaseName> getNames() override; + std::vector<DatabaseName> getNames() override; private: - std::set<TenantDatabaseName> _getNamesWithConflictingCasing_inlock( - const TenantDatabaseName& tenantDbName); + std::set<DatabaseName> _getNamesWithConflictingCasing_inlock(const DatabaseName& dbName); - typedef stdx::unordered_map<TenantDatabaseName, Database*> DBs; + typedef stdx::unordered_map<DatabaseName, Database*> DBs; mutable SimpleMutex _m; mutable stdx::condition_variable _c; DBs _dbs; diff --git a/src/mongo/db/catalog/database_holder_mock.h b/src/mongo/db/catalog/database_holder_mock.h index 9ef8c2229f7..d21558b4be0 100644 --- a/src/mongo/db/catalog/database_holder_mock.h +++ b/src/mongo/db/catalog/database_holder_mock.h @@ -37,33 +37,31 @@ class DatabaseHolderMock : public DatabaseHolder { public: DatabaseHolderMock() = default; - Database* getDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) const override { + Database* getDb(OperationContext* opCtx, const DatabaseName& dbName) const override { return nullptr; } - bool dbExists(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) const override { + bool dbExists(OperationContext* opCtx, const DatabaseName& dbName) const override { return false; } Database* openDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName, + const DatabaseName& dbName, bool* justCreated = nullptr) override { return nullptr; } void dropDb(OperationContext* opCtx, Database* db) override {} - void close(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) override {} + void close(OperationContext* opCtx, const DatabaseName& dbName) override {} void closeAll(OperationContext* opCtx) override {} - std::set<TenantDatabaseName> getNamesWithConflictingCasing( - const TenantDatabaseName& tenantDbName) override { - return std::set<TenantDatabaseName>(); + std::set<DatabaseName> getNamesWithConflictingCasing(const DatabaseName& dbName) override { + return std::set<DatabaseName>(); } - std::vector<TenantDatabaseName> getNames() override { + std::vector<DatabaseName> getNames() override { return {}; } }; diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index d3c402ebd6d..f2891a24585 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -154,12 +154,12 @@ Status DatabaseImpl::validateDBName(StringData dbname) { return Status::OK(); } -DatabaseImpl::DatabaseImpl(const TenantDatabaseName& tenantDbName) - : _name(tenantDbName), - _viewsName(_name.dbName() + "." + DurableViewCatalog::viewsCollectionName().toString()) {} +DatabaseImpl::DatabaseImpl(const DatabaseName& dbName) + : _name(dbName), + _viewsName(_name.toString() + "." + DurableViewCatalog::viewsCollectionName().toString()) {} Status DatabaseImpl::init(OperationContext* const opCtx) { - Status status = validateDBName(_name.dbName()); + Status status = validateDBName(_name.db()); if (!status.isOK()) { LOGV2_WARNING(20325, @@ -195,7 +195,7 @@ Status DatabaseImpl::init(OperationContext* const opCtx) { try { Lock::CollectionLock systemViewsLock( opCtx, - NamespaceString(_name.dbName(), NamespaceString::kSystemDotViewsCollectionName), + NamespaceString(_name.db(), NamespaceString::kSystemDotViewsCollectionName), MODE_IS); ViewsForDatabase viewsForDb{std::make_unique<DurableViewCatalogImpl>(this)}; Status reloadStatus = viewsForDb.reload(opCtx); @@ -296,7 +296,7 @@ Status DatabaseImpl::init(OperationContext* const opCtx) { } void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) const { - invariant(opCtx->lockState()->isDbLockedForMode(name().dbName(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IX)); CollectionCatalog::CollectionInfoFn callback = [&](const CollectionPtr& collection) { try { @@ -330,12 +330,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().dbName(), mode)); + invariant(opCtx->lockState()->isDbLockedForMode(name().db(), mode)); _dropPending.store(dropPending); } bool DatabaseImpl::isDropPending(OperationContext* opCtx) const { - invariant(opCtx->lockState()->isDbLockedForMode(name().dbName(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IS)); return _dropPending.load(); } @@ -354,7 +354,7 @@ void DatabaseImpl::getStats(OperationContext* opCtx, long long indexSize = 0; long long indexFreeStorageSize = 0; - invariant(opCtx->lockState()->isDbLockedForMode(name().dbName(), MODE_IS)); + invariant(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IS)); catalog::forEachCollectionFromDb( opCtx, name(), MODE_IS, [&](const CollectionPtr& collection) -> bool { @@ -406,8 +406,6 @@ void DatabaseImpl::getStats(OperationContext* opCtx, output->appendNumber("scaleFactor", scale); if (!opCtx->getServiceContext()->getStorageEngine()->isEphemeral()) { - // It does not matter whether _name.dbName() or _name.fullName() is passed in here since - // directoryPerDB isn't supported in Serverless. We choose _name.dbName(). boost::filesystem::path dbpath( opCtx->getServiceContext()->getStorageEngine()->getFilesystemPathForDb(_name)); boost::system::error_code ec; @@ -428,7 +426,7 @@ void DatabaseImpl::getStats(OperationContext* opCtx, } Status DatabaseImpl::dropView(OperationContext* opCtx, NamespaceString viewName) const { - dassert(opCtx->lockState()->isDbLockedForMode(name().dbName(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(viewName, MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(NamespaceString(_viewsName), MODE_X)); @@ -450,11 +448,11 @@ Status DatabaseImpl::dropCollection(OperationContext* opCtx, return Status::OK(); } - invariant(nss.db() == _name.dbName()); + invariant(nss.db() == _name.db()); if (nss.isSystem()) { if (nss.isSystemDotProfile()) { - if (catalog->getDatabaseProfileLevel(_name.dbName()) != 0) + if (catalog->getDatabaseProfileLevel(_name.db()) != 0) return Status(ErrorCodes::IllegalOperation, "turn off profiling before dropping system.profile collection"); } else if (nss.isSystemDotViews()) { @@ -631,7 +629,7 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx, void DatabaseImpl::_dropCollectionIndexes(OperationContext* opCtx, const NamespaceString& nss, Collection* collection) const { - invariant(_name.dbName() == nss.db()); + invariant(_name.db() == nss.db()); LOGV2_DEBUG( 20316, 1, "dropCollection: {namespace} - dropAllIndexes start", "namespace"_attr = nss); collection->getIndexCatalog()->dropAllIndexes(opCtx, collection, true, {}); @@ -681,8 +679,8 @@ Status DatabaseImpl::renameCollection(OperationContext* opCtx, invariant(opCtx->lockState()->isCollectionLockedForMode(fromNss, MODE_X)); invariant(opCtx->lockState()->isCollectionLockedForMode(toNss, MODE_X)); - invariant(fromNss.db() == _name.dbName()); - invariant(toNss.db() == _name.dbName()); + invariant(fromNss.db() == _name.db()); + invariant(toNss.db() == _name.db()); if (CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, toNss)) { return Status(ErrorCodes::NamespaceExists, str::stream() << "Cannot rename '" << fromNss << "' to '" << toNss @@ -770,7 +768,7 @@ void DatabaseImpl::_checkCanCreateCollection(OperationContext* opCtx, Status DatabaseImpl::createView(OperationContext* opCtx, const NamespaceString& viewName, const CollectionOptions& options) const { - dassert(opCtx->lockState()->isDbLockedForMode(name().dbName(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(viewName, MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(NamespaceString(_viewsName), MODE_X)); @@ -925,7 +923,7 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx, StatusWith<NamespaceString> DatabaseImpl::makeUniqueCollectionNamespace( OperationContext* opCtx, StringData collectionNameModel) const { - invariant(opCtx->lockState()->isDbLockedForMode(name().dbName(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(name().db(), MODE_IX)); // There must be at least one percent sign in the collection name model. auto numPercentSign = std::count(collectionNameModel.begin(), collectionNameModel.end(), '%'); @@ -961,7 +959,7 @@ StatusWith<NamespaceString> DatabaseImpl::makeUniqueCollectionNamespace( collectionName.begin(), replacePercentSign); - NamespaceString nss(_name.dbName(), collectionName); + NamespaceString nss(_name.db(), collectionName); if (!CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss)) { return nss; } @@ -975,7 +973,7 @@ StatusWith<NamespaceString> DatabaseImpl::makeUniqueCollectionNamespace( } void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext* opCtx) const { - if (name().dbName() == "local") { + if (name().db() == "local") { // Collections in the local database are not replicated, so we do not need an _id index on // any collection. For the same reason, it is not possible for the local database to contain // any drop-pending collections (drops are effective immediately). diff --git a/src/mongo/db/catalog/database_impl.h b/src/mongo/db/catalog/database_impl.h index fa09177bc1b..6aa7ae6095a 100644 --- a/src/mongo/db/catalog/database_impl.h +++ b/src/mongo/db/catalog/database_impl.h @@ -30,17 +30,17 @@ #pragma once #include "mongo/db/catalog/database.h" -#include "mongo/db/tenant_database_name.h" +#include "mongo/db/database_name.h" namespace mongo { class DatabaseImpl final : public Database { public: - explicit DatabaseImpl(const TenantDatabaseName& tenantDbName); + explicit DatabaseImpl(const DatabaseName& dbName); Status init(OperationContext*) final; - const TenantDatabaseName& name() const final { + const DatabaseName& name() const final { return _name; } @@ -145,7 +145,7 @@ private: const NamespaceString& nss, Collection* collection) const; - const TenantDatabaseName _name; // "dbname" + const DatabaseName _name; // "dbname" const NamespaceString _viewsName; // "dbname.system.views" diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index 93d742ce030..623662bb041 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -100,9 +100,7 @@ Status checkSourceAndTargetNamespaces(OperationContext* opCtx, return {ErrorCodes::IllegalOperation, "Cannot rename collections between a replicated and an unreplicated database"}; - // TODO SERVER-64608 Use the tenantID from 'source' to construct the DatabaseName - const TenantDatabaseName tenantDbName(boost::none, source.db()); - auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, tenantDbName); + auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, source.dbName()); if (!db || db->isDropPending(opCtx)) return Status(ErrorCodes::NamespaceNotFound, str::stream() @@ -153,7 +151,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().dbName(), LockMode::MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(targetDB->name().db(), LockMode::MODE_X)); auto tmpNameResult = targetDB->makeUniqueCollectionNamespace(opCtx, "tmp%%%%%.rename"); if (!tmpNameResult.isOK()) { return tmpNameResult.getStatus().withContext( @@ -321,8 +319,7 @@ Status renameCollectionWithinDB(OperationContext* opCtx, sourceLock.emplace(opCtx, source, MODE_X); } - const TenantDatabaseName tenantDbName(boost::none, source.db()); - auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, tenantDbName); + auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, source.dbName()); auto catalog = CollectionCatalog::get(opCtx); const auto sourceColl = catalog->lookupCollectionByNamespace(opCtx, source); const auto targetColl = catalog->lookupCollectionByNamespace(opCtx, target); @@ -372,8 +369,7 @@ Status renameCollectionWithinDBForApplyOps(OperationContext* opCtx, if (!status.isOK()) return status; - const TenantDatabaseName tenantDbName(boost::none, source.db()); - auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, tenantDbName); + auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, source.dbName()); const auto sourceColl = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, source); @@ -504,8 +500,7 @@ Status renameBetweenDBs(OperationContext* opCtx, DisableDocumentValidation validationDisabler(opCtx); - const TenantDatabaseName sourceTenantDbName(boost::none, source.db()); - auto sourceDB = DatabaseHolder::get(opCtx)->getDb(opCtx, sourceTenantDbName); + auto sourceDB = DatabaseHolder::get(opCtx)->getDb(opCtx, source.dbName()); if (!sourceDB) return Status(ErrorCodes::NamespaceNotFound, "source namespace does not exist"); @@ -532,8 +527,7 @@ Status renameBetweenDBs(OperationContext* opCtx, IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(sourceColl->uuid()); - const TenantDatabaseName targetTenantDbName(boost::none, target.db()); - auto targetDB = DatabaseHolder::get(opCtx)->getDb(opCtx, targetTenantDbName); + auto targetDB = DatabaseHolder::get(opCtx)->getDb(opCtx, target.dbName()); // Check if the target namespace exists and if dropTarget is true. // Return a non-OK status if target exists and dropTarget is not true or if the collection @@ -558,13 +552,12 @@ Status renameBetweenDBs(OperationContext* opCtx, // Create a temporary collection in the target database. It will be removed if we fail to // copy the collection, or on restart, so there is no need to replicate these writes. if (!targetDB) { - const TenantDatabaseName tenantDbName(boost::none, target.db()); - targetDB = DatabaseHolder::get(opCtx)->openDb(opCtx, tenantDbName); + targetDB = DatabaseHolder::get(opCtx)->openDb(opCtx, target.dbName()); } // The generated unique collection name is only guaranteed to exist if the database is // exclusively locked. - invariant(opCtx->lockState()->isDbLockedForMode(targetDB->name().dbName(), LockMode::MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(targetDB->name().db(), 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 b092cf4fffe..576a1b699e1 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -511,7 +511,7 @@ void _insertDocument(OperationContext* opCtx, const NamespaceString& nss, const CollectionPtr _getCollection_inlock(OperationContext* opCtx, const NamespaceString& nss) { invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IS)); auto databaseHolder = DatabaseHolder::get(opCtx); - auto* db = databaseHolder->getDb(opCtx, TenantDatabaseName(boost::none, nss.db())); + auto* db = databaseHolder->getDb(opCtx, DatabaseName(boost::none, nss.db())); if (!db) { return nullptr; } diff --git a/src/mongo/db/catalog/uncommitted_catalog_updates.h b/src/mongo/db/catalog/uncommitted_catalog_updates.h index 5e8ea6483e7..c89e536e0aa 100644 --- a/src/mongo/db/catalog/uncommitted_catalog_updates.h +++ b/src/mongo/db/catalog/uncommitted_catalog_updates.h @@ -32,7 +32,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/views_for_database.h" -#include "mongo/db/tenant_database_name.h" +#include "mongo/db/database_name.h" #include "mongo/db/views/view.h" #include "mongo/util/uuid.h" diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp index cf664b6f4b1..88d66867751 100644 --- a/src/mongo/db/catalog/validate_state.cpp +++ b/src/mongo/db/catalog/validate_state.cpp @@ -284,9 +284,7 @@ void ValidateState::_relockDatabaseAndCollection(OperationContext* opCtx) { << " while validating collection: " << _nss << " (" << *_uuid << ")"; _databaseLock.emplace(opCtx, _nss.db(), MODE_IS); - // TODO SERVER-64608 Use the tenantID from '_nss' to construct the DatabaseName - const TenantDatabaseName tenantDbName(boost::none, _nss.db()); - _database = DatabaseHolder::get(opCtx)->getDb(opCtx, tenantDbName); + _database = DatabaseHolder::get(opCtx)->getDb(opCtx, _nss.dbName()); uassert(ErrorCodes::Interrupted, dbErrMsg, _database); uassert(ErrorCodes::Interrupted, dbErrMsg, !_database->isDropPending(opCtx)); diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp index a17fc0a4949..ae95a0db02a 100644 --- a/src/mongo/db/catalog_raii.cpp +++ b/src/mongo/db/catalog_raii.cpp @@ -164,14 +164,14 @@ void acquireCollectionLocksInResourceIdOrder( } // namespace -// TODO SERVER-62918 Pass TenantDatabaseName instead of string for dbName. +// TODO SERVER-62918 Pass DatabaseName instead of string for dbName. AutoGetDb::AutoGetDb(OperationContext* opCtx, StringData dbName, LockMode mode, Date_t deadline, const std::set<StringData>& secondaryDbNames) : _dbName(dbName), _dbLock(opCtx, dbName, mode, deadline), _db([&] { - const TenantDatabaseName tenantDbName(boost::none, dbName); + const DatabaseName tenantDbName(boost::none, dbName); auto databaseHolder = DatabaseHolder::get(opCtx); return databaseHolder->getDb(opCtx, tenantDbName); }()) { @@ -200,8 +200,8 @@ Database* AutoGetDb::ensureDbExists(OperationContext* opCtx) { } auto databaseHolder = DatabaseHolder::get(opCtx); - const TenantDatabaseName tenantDbName(boost::none, _dbName); - _db = databaseHolder->openDb(opCtx, tenantDbName, nullptr); + const DatabaseName dbName(boost::none, _dbName); + _db = databaseHolder->openDb(opCtx, dbName, nullptr); auto dss = DatabaseShardingState::get(opCtx, _dbName); auto dssLock = DatabaseShardingState::DSSLock::lockShared(opCtx, dss); @@ -270,13 +270,13 @@ AutoGetCollection::AutoGetCollection( catalog->resolveNamespaceStringOrUUID(opCtx, secondaryNssOrUUID); auto secondaryColl = catalog->lookupCollectionByNamespace(opCtx, secondaryResolvedNss); // TODO SERVER-64608 Use tenantID on NamespaceString to construct DatabaseName - const TenantDatabaseName secondaryTenantDbName(boost::none, secondaryNssOrUUID.db()); + const DatabaseName secondaryDbName(boost::none, secondaryNssOrUUID.db()); verifyDbAndCollection(opCtx, MODE_IS, secondaryNssOrUUID, secondaryResolvedNss, secondaryColl, - databaseHolder->getDb(opCtx, secondaryTenantDbName)); + databaseHolder->getDb(opCtx, secondaryDbName)); } if (_coll) { diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index e0aa69cc74a..bc5fc066e03 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -105,8 +105,8 @@ struct Cloner::Fun { // Make sure database still exists after we resume from the temp release auto databaseHolder = DatabaseHolder::get(opCtx); // TODO SERVER-63111 use TenantDatabase in the Cloner. - const TenantDatabaseName tenantDbName(boost::none, _dbName); - auto db = databaseHolder->openDb(opCtx, tenantDbName); + const DatabaseName dbName(boost::none, _dbName); + auto db = databaseHolder->openDb(opCtx, dbName); auto catalog = CollectionCatalog::get(opCtx); auto collection = catalog->lookupCollectionByNamespace(opCtx, nss); if (!collection) { @@ -153,7 +153,7 @@ struct Cloner::Fun { repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, nss)); } - db = databaseHolder->getDb(opCtx, tenantDbName); + db = databaseHolder->getDb(opCtx, dbName); uassert(28593, str::stream() << "Database " << _dbName << " dropped while cloning", db != nullptr); @@ -342,7 +342,7 @@ Status Cloner::_createCollectionsForDb( const std::vector<CreateCollectionParams>& createCollectionParams, const std::string& dbName) { auto databaseHolder = DatabaseHolder::get(opCtx); - const TenantDatabaseName tenantDbName(boost::none, dbName); + const DatabaseName tenantDbName(boost::none, dbName); auto db = databaseHolder->openDb(opCtx, tenantDbName); invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_X)); diff --git a/src/mongo/db/commands/current_op_common.cpp b/src/mongo/db/commands/current_op_common.cpp index 7e82a137c92..304009accdb 100644 --- a/src/mongo/db/commands/current_op_common.cpp +++ b/src/mongo/db/commands/current_op_common.cpp @@ -111,7 +111,7 @@ bool CurrentOpCommandBase::run(OperationContext* opCtx, // Pipeline is complete; create an AggregateCommandRequest for $currentOp. AggregateCommandRequest request( - NamespaceString::makeCollectionlessAggregateNSS(TenantDatabaseName(boost::none, "admin")), + NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "admin")), std::move(pipeline)); // Run the pipeline and obtain a CursorResponse. diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp index 46fb1f22983..7da38954e9c 100644 --- a/src/mongo/db/commands/dbcheck.cpp +++ b/src/mongo/db/commands/dbcheck.cpp @@ -224,9 +224,9 @@ std::unique_ptr<DbCheckRun> fullDatabaseRun(OperationContext* opCtx, result->push_back(info); return true; }; - // TODO SERVER-63353: Change dbcheck command to use TenantDatabaseName + // TODO SERVER-63353: Change dbcheck command to use DatabaseName mongo::catalog::forEachCollectionFromDb( - opCtx, TenantDatabaseName(boost::none, dbName), MODE_IS, perCollectionWork); + opCtx, DatabaseName(boost::none, dbName), MODE_IS, perCollectionWork); return result; } diff --git a/src/mongo/db/commands/dbcommands_d.cpp b/src/mongo/db/commands/dbcommands_d.cpp index 7110bce5edb..51f03ce67ba 100644 --- a/src/mongo/db/commands/dbcommands_d.cpp +++ b/src/mongo/db/commands/dbcommands_d.cpp @@ -180,8 +180,8 @@ protected: // When setting the profiling level, create the database if it didn't already exist. // When just reading the profiling level, we do not create the database. auto databaseHolder = DatabaseHolder::get(opCtx); - // TODO SERVER-63109 Make _setProfileSettings pass TenantDatabaseName. - const TenantDatabaseName tenantDbName(boost::none, dbName); + // TODO SERVER-63109 Make _setProfileSettings pass DatabaseName. + const DatabaseName tenantDbName(boost::none, dbName); db = databaseHolder->openDb(opCtx, tenantDbName); } diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp index d767fa8c112..5a0df7236f3 100644 --- a/src/mongo/db/commands/dbhash.cpp +++ b/src/mongo/db/commands/dbhash.cpp @@ -234,7 +234,7 @@ public: std::set<std::string> cappedCollectionSet; bool noError = true; - const TenantDatabaseName tenantDbName(boost::none, dbname); + const DatabaseName tenantDbName(boost::none, dbname); catalog::forEachCollectionFromDb( opCtx, tenantDbName, MODE_IS, [&](const CollectionPtr& collection) { auto collNss = collection->ns(); @@ -344,7 +344,7 @@ private: << minSnapshot->toString(), !minSnapshot || *mySnapshot >= *minSnapshot); } else { - invariant(opCtx->lockState()->isDbLockedForMode(db->name().dbName(), MODE_S)); + invariant(opCtx->lockState()->isDbLockedForMode(db->name().db(), MODE_S)); } auto desc = collection->getIndexCatalog()->findIdIndex(opCtx); diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp index 90aefe1ea2d..8e08ae43b2d 100644 --- a/src/mongo/db/commands/feature_compatibility_version.cpp +++ b/src/mongo/db/commands/feature_compatibility_version.cpp @@ -377,11 +377,11 @@ void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* opCtx, bool FeatureCompatibilityVersion::hasNoReplicatedCollections(OperationContext* opCtx) { StorageEngine* storageEngine = getGlobalServiceContext()->getStorageEngine(); - std::vector<TenantDatabaseName> tenantDbNames = storageEngine->listDatabases(); + std::vector<DatabaseName> dbNames = storageEngine->listDatabases(); auto catalog = CollectionCatalog::get(opCtx); - for (auto&& tenantDbName : tenantDbNames) { - Lock::DBLock dbLock(opCtx, tenantDbName.dbName(), MODE_S); - for (auto&& collNss : catalog->getAllCollectionNamesFromDb(opCtx, tenantDbName)) { + for (auto&& dbName : dbNames) { + Lock::DBLock dbLock(opCtx, dbName.db(), MODE_S); + for (auto&& collNss : catalog->getAllCollectionNamesFromDb(opCtx, dbName)) { if (collNss.isReplicated()) { return false; } @@ -480,11 +480,10 @@ void FeatureCompatibilityVersion::fassertInitializedAfterStartup(OperationContex auto fcvDocument = findFeatureCompatibilityVersionDocument(opCtx); auto const storageEngine = opCtx->getServiceContext()->getStorageEngine(); - auto tenantDbNames = storageEngine->listDatabases(); - bool nonLocalDatabases = - std::any_of(tenantDbNames.begin(), tenantDbNames.end(), [](auto tenantDbName) { - return tenantDbName.dbName() != NamespaceString::kLocalDb; - }); + auto dbNames = storageEngine->listDatabases(); + bool nonLocalDatabases = std::any_of(dbNames.begin(), dbNames.end(), [](auto dbName) { + return dbName.db() != NamespaceString::kLocalDb; + }); // Fail to start up if there is no featureCompatibilityVersion document and there are non-local // databases present. diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp index b7c52f38cd5..92cf819bda2 100644 --- a/src/mongo/db/commands/list_collections.cpp +++ b/src/mongo/db/commands/list_collections.cpp @@ -294,9 +294,9 @@ public: void doCheckAuthorization(OperationContext* opCtx) const final { AuthorizationSession* authzSession = AuthorizationSession::get(opCtx->getClient()); - auto dbName = request().getDbName(); + auto db = request().getDbName(); auto cmdObj = request().toBSON({}); - uassertStatusOK(authzSession->checkAuthorizedToListCollections(dbName, cmdObj)); + uassertStatusOK(authzSession->checkAuthorizedToListCollections(db, cmdObj)); } NamespaceString ns() const final { @@ -309,14 +309,14 @@ public: const auto as = AuthorizationSession::get(opCtx->getClient()); const auto listCollRequest = request(); - const auto dbName = listCollRequest.getDbName(); - const TenantDatabaseName tenantDbName(getActiveTenant(opCtx), dbName); + const auto db = listCollRequest.getDbName(); + const DatabaseName dbName(getActiveTenant(opCtx), db); const bool nameOnly = listCollRequest.getNameOnly(); const bool authorizedCollections = listCollRequest.getAuthorizedCollections(); // The collator is null because collection objects are compared using binary comparison. auto expCtx = make_intrusive<ExpressionContext>( - opCtx, std::unique_ptr<CollatorInterface>(nullptr), NamespaceString(dbName)); + opCtx, std::unique_ptr<CollatorInterface>(nullptr), NamespaceString(db)); if (listCollRequest.getFilter()) { matcher = uassertStatusOK( @@ -327,13 +327,13 @@ public: // collections. bool includePendingDrops = listCollRequest.getIncludePendingDrops().value_or(false); - const NamespaceString cursorNss = NamespaceString::makeListCollectionsNSS(dbName); + const NamespaceString cursorNss = NamespaceString::makeListCollectionsNSS(db); std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> exec; std::vector<mongo::ListCollectionsReplyItem> firstBatch; { // Acquire only the global lock and set up a consistent in-memory catalog and // storage snapshot. - AutoGetDbForReadMaybeLockFree lockFreeReadBlock(opCtx, dbName); + AutoGetDbForReadMaybeLockFree lockFreeReadBlock(opCtx, db); auto catalog = CollectionCatalog::get(opCtx); CurOpFailpointHelpers::waitWhileFailPointEnabled(&hangBeforeListCollections, @@ -345,11 +345,10 @@ public: auto ws = std::make_unique<WorkingSet>(); auto root = std::make_unique<QueuedDataStage>(expCtx.get(), ws.get()); - if (DatabaseHolder::get(opCtx)->dbExists(opCtx, - TenantDatabaseName(boost::none, dbName))) { + if (DatabaseHolder::get(opCtx)->dbExists(opCtx, DatabaseName(boost::none, db))) { if (auto collNames = _getExactNameMatches(matcher.get())) { for (auto&& collName : *collNames) { - auto nss = NamespaceString(dbName, collName); + auto nss = NamespaceString(db, collName); // Only validate on a per-collection basis if the user requested // a list of authorized collections @@ -437,14 +436,14 @@ public: // needing to yield as we don't take any locks. if (opCtx->isLockFreeReadsOp()) { auto collectionCatalog = CollectionCatalog::get(opCtx); - for (auto it = collectionCatalog->begin(opCtx, tenantDbName); + for (auto it = collectionCatalog->begin(opCtx, dbName); it != collectionCatalog->end(opCtx); ++it) { perCollectionWork(*it); } } else { mongo::catalog::forEachCollectionFromDb( - opCtx, tenantDbName, MODE_IS, perCollectionWork); + opCtx, dbName, MODE_IS, perCollectionWork); } } @@ -455,7 +454,7 @@ public: ListCollectionsFilter::makeTypeCollectionFilter()); if (!skipViews) { - catalog->iterateViews(opCtx, tenantDbName, [&](const ViewDefinition& view) { + catalog->iterateViews(opCtx, db, [&](const ViewDefinition& view) { if (authorizedCollections && !as->isAuthorizedForAnyActionOnResource( ResourcePattern::forExactNamespace(view.name()))) { @@ -551,8 +550,9 @@ public: repl::ReadConcernArgs::get(opCtx), ReadPreferenceSetting::get(opCtx), cmdObj, - uassertStatusOK(AuthorizationSession::get(opCtx->getClient()) - ->checkAuthorizedToListCollections(dbName, cmdObj))}); + uassertStatusOK( + AuthorizationSession::get(opCtx->getClient()) + ->checkAuthorizedToListCollections(dbName.toString(), cmdObj))}); pinnedCursor->incNBatches(); pinnedCursor->incNReturnedSoFar(firstBatch.size()); diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp index fd60d2b26b5..d43bf0acf7c 100644 --- a/src/mongo/db/commands/list_databases.cpp +++ b/src/mongo/db/commands/list_databases.cpp @@ -37,13 +37,13 @@ #include "mongo/db/commands/list_databases_gen.h" #include "mongo/db/concurrency/exception_util.h" #include "mongo/db/curop_failpoint_helpers.h" +#include "mongo/db/database_name.h" #include "mongo/db/db_raii.h" #include "mongo/db/matcher/expression.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/storage_engine.h" -#include "mongo/db/tenant_database_name.h" namespace mongo { @@ -123,13 +123,13 @@ public: filter = std::move(matcher); } - std::vector<TenantDatabaseName> tenantDbNames; + std::vector<DatabaseName> dbNames; StorageEngine* storageEngine = getGlobalServiceContext()->getStorageEngine(); { Lock::GlobalLock lk(opCtx, MODE_IS); CurOpFailpointHelpers::waitWhileFailPointEnabled( &hangBeforeListDatabases, opCtx, "hangBeforeListDatabases", []() {}); - tenantDbNames = storageEngine->listDatabases(); + dbNames = storageEngine->listDatabases(); } std::vector<ListDatabasesReplyItem> items; @@ -138,14 +138,14 @@ public: filter->getCategory() == MatchExpression::MatchCategory::kLeaf && filter->path() == kName; long long totalSize = 0; - for (const auto& tenantDbName : tenantDbNames) { + for (const auto& dbName : dbNames) { if (authorizedDatabases && - !as->isAuthorizedForAnyActionOnAnyResourceInDB(tenantDbName.dbName())) { + !as->isAuthorizedForAnyActionOnAnyResourceInDB(dbName.toString())) { // We don't have listDatabases on the cluster or find on this database. continue; } - ListDatabasesReplyItem item(tenantDbName.dbName()); + ListDatabasesReplyItem item(dbName.db()); long long size = 0; if (!nameOnly) { @@ -154,19 +154,18 @@ public: continue; } - AutoGetDbForReadMaybeLockFree lockFreeReadBlock(opCtx, tenantDbName.dbName()); + AutoGetDbForReadMaybeLockFree lockFreeReadBlock(opCtx, dbName.db()); // The database could have been dropped since we called 'listDatabases()' above. - if (!DatabaseHolder::get(opCtx)->dbExists(opCtx, tenantDbName)) { + if (!DatabaseHolder::get(opCtx)->dbExists(opCtx, dbName)) { continue; } - writeConflictRetry(opCtx, "sizeOnDisk", tenantDbName.dbName(), [&] { - size = storageEngine->sizeOnDiskForDb(opCtx, tenantDbName); + writeConflictRetry(opCtx, "sizeOnDisk", dbName.toString(), [&] { + size = storageEngine->sizeOnDiskForDb(opCtx, dbName); }); item.setSizeOnDisk(size); - item.setEmpty(CollectionCatalog::get(opCtx) - ->getAllCollectionUUIDsFromDb(tenantDbName) - .empty()); + item.setEmpty( + CollectionCatalog::get(opCtx)->getAllCollectionUUIDsFromDb(dbName).empty()); } if (!filter || filter->matchesBSON(item.toBSON())) { totalSize += size; diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index 9ab5c0db701..0f12d23de12 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -407,7 +407,6 @@ StatusWith<StringMap<ExpressionContext::ResolvedNamespace>> resolveInvolvedNames * 'collator'. Otherwise, returns ErrorCodes::OptionNotSupportedOnView. */ Status collatorCompatibleWithPipeline(OperationContext* opCtx, - StringData dbName, const CollatorInterface* collator, const LiteParsedPipeline& liteParsedPipeline) { auto catalog = CollectionCatalog::get(opCtx); @@ -761,7 +760,6 @@ Status runAggregate(OperationContext* opCtx, // Raise an error if 'origNss' is a view. We do not need to check this if we are opening // a stream on an entire db or across the cluster. - const TenantDatabaseName origTenantDbName(boost::none, origNss.db()); if (!origNss.isCollectionlessAggregateNS()) { auto view = catalog->lookupView(opCtx, origNss); uassert(ErrorCodes::CommandNotSupportedOnView, @@ -921,8 +919,8 @@ Status runAggregate(OperationContext* opCtx, // Check that the view's collation matches the collation of any views involved in the // pipeline. if (!pipelineInvolvedNamespaces.empty()) { - auto pipelineCollationStatus = collatorCompatibleWithPipeline( - opCtx, nss.db(), expCtx->getCollator(), liteParsedPipeline); + auto pipelineCollationStatus = + collatorCompatibleWithPipeline(opCtx, expCtx->getCollator(), liteParsedPipeline); if (!pipelineCollationStatus.isOK()) { return pipelineCollationStatus; } diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index d9bce292fc9..d1cda6b6756 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -637,12 +637,12 @@ private: if (serverGlobalParams.featureCompatibility .isFCVDowngradingOrAlreadyDowngradedFromLatest()) { - for (const auto& tenantDbName : DatabaseHolder::get(opCtx)->getNames()) { - const auto& dbName = tenantDbName.dbName(); - Lock::DBLock dbLock(opCtx, dbName, MODE_IX); + for (const auto& dbName : DatabaseHolder::get(opCtx)->getNames()) { + const auto& db = dbName.db(); + Lock::DBLock dbLock(opCtx, db, MODE_IX); catalog::forEachCollectionFromDb( opCtx, - tenantDbName, + dbName, MODE_X, [&](const CollectionPtr& collection) { // Fail to downgrade if there exists a collection with @@ -665,11 +665,11 @@ private: } // TODO SERVER-63564: Remove once FCV 6.0 becomes last-lts. - for (const auto& tenantDbName : DatabaseHolder::get(opCtx)->getNames()) { - const auto& dbName = tenantDbName.dbName(); - Lock::DBLock dbLock(opCtx, dbName, MODE_IX); + for (const auto& dbName : DatabaseHolder::get(opCtx)->getNames()) { + const auto& db = dbName.db(); + Lock::DBLock dbLock(opCtx, db, MODE_IX); catalog::forEachCollectionFromDb( - opCtx, tenantDbName, MODE_X, [&](const CollectionPtr& collection) { + opCtx, dbName, MODE_X, [&](const CollectionPtr& collection) { auto indexCatalog = collection->getIndexCatalog(); auto indexIt = indexCatalog->getIndexIterator( opCtx, true /* includeUnfinishedIndexes */); @@ -712,11 +712,11 @@ private: // Block downgrade for collections with encrypted fields // TODO SERVER-65077: Remove once FCV 6.0 becomes last-lts. - for (const auto& tenantDbName : DatabaseHolder::get(opCtx)->getNames()) { - const auto& dbName = tenantDbName.dbName(); - Lock::DBLock dbLock(opCtx, dbName, MODE_IX); + for (const auto& dbName : DatabaseHolder::get(opCtx)->getNames()) { + const auto& db = dbName.db(); + Lock::DBLock dbLock(opCtx, db, MODE_IX); catalog::forEachCollectionFromDb( - opCtx, tenantDbName, MODE_X, [&](const CollectionPtr& collection) { + opCtx, dbName, MODE_X, [&](const CollectionPtr& collection) { uassert( ErrorCodes::CannotDowngrade, str::stream() << "Cannot downgrade the cluster as collection " diff --git a/src/mongo/db/commands/validate_db_metadata_cmd.cpp b/src/mongo/db/commands/validate_db_metadata_cmd.cpp index 510dcd0ac32..0d057e498f5 100644 --- a/src/mongo/db/commands/validate_db_metadata_cmd.cpp +++ b/src/mongo/db/commands/validate_db_metadata_cmd.cpp @@ -124,21 +124,21 @@ public: // If there is no database name present in the input, run validation against all the // databases. - auto tenantDbNames = validateCmdRequest.getDb() - ? std::vector<TenantDatabaseName>{TenantDatabaseName( - getActiveTenant(opCtx), validateCmdRequest.getDb()->toString())} + auto dbNames = validateCmdRequest.getDb() + ? std::vector<DatabaseName>{DatabaseName(getActiveTenant(opCtx), + validateCmdRequest.getDb()->toString())} : collectionCatalog->getAllDbNames(); - for (const auto& tenantDbName : tenantDbNames) { - AutoGetDb autoDb(opCtx, tenantDbName.dbName(), LockMode::MODE_IS); + for (const auto& dbName : dbNames) { + AutoGetDb autoDb(opCtx, dbName.db(), LockMode::MODE_IS); if (!autoDb.getDb()) { continue; } if (validateCmdRequest.getCollection()) { - if (!_validateNamespace(opCtx, - NamespaceString(tenantDbName.dbName(), - *validateCmdRequest.getCollection()))) { + if (!_validateNamespace( + opCtx, + NamespaceString(dbName.db(), *validateCmdRequest.getCollection()))) { return; } continue; @@ -147,11 +147,11 @@ public: // If there is no collection name present in the input, run validation against all // the collections. collectionCatalog->iterateViews( - opCtx, tenantDbName, [this, opCtx](const ViewDefinition& view) { + opCtx, dbName, [this, opCtx](const ViewDefinition& view) { return _validateView(opCtx, view); }); - for (auto collIt = collectionCatalog->begin(opCtx, tenantDbName); + for (auto collIt = collectionCatalog->begin(opCtx, dbName); collIt != collectionCatalog->end(opCtx); ++collIt) { if (!_validateNamespace( diff --git a/src/mongo/db/tenant_database_name.cpp b/src/mongo/db/database_name.cpp index f1c8fb0eb9e..dd1cc4869ad 100644 --- a/src/mongo/db/tenant_database_name.cpp +++ b/src/mongo/db/database_name.cpp @@ -27,13 +27,13 @@ * it in the license file. */ -#include "mongo/db/tenant_database_name.h" +#include "mongo/db/database_name.h" namespace mongo { -TenantDatabaseName TenantDatabaseName::createSystemTenantDbName(StringData dbName) { +DatabaseName DatabaseName::createSystemTenantDbName(StringData dbString) { // TODO SERVER-62491 Use kSystemTenantId - return TenantDatabaseName(boost::none, dbName); + return DatabaseName(boost::none, dbString); } } // namespace mongo diff --git a/src/mongo/db/tenant_database_name.h b/src/mongo/db/database_name.h index 27aca9131d9..c2099fc654e 100644 --- a/src/mongo/db/tenant_database_name.h +++ b/src/mongo/db/database_name.h @@ -40,115 +40,111 @@ namespace mongo { /** - * A TenantDatabaseName is a unique name for database. + * A DatabaseName is a unique name for database. * It holds a database name and tenant id, if one exists. In a serverless environment, a tenant id * is expected to exist so that a database can be uniquely identified. */ -class TenantDatabaseName { +class DatabaseName { public: /** - * Constructs an empty TenantDatabaseName. + * Constructs an empty DatabaseName. */ - TenantDatabaseName() : _tenantId(boost::none), _dbName(""), _tenantDbName(boost::none){}; + DatabaseName() : _tenantId(boost::none), _dbString(""), _tenantDbString(boost::none){}; /** - * Constructs a TenantDatabaseName from the given tenantId and database name. + * Constructs a DatabaseName from the given tenantId and database name. * "dbName" is expected only consist of a db name. It is the caller's responsibility to ensure * the dbName is a valid db name. */ - TenantDatabaseName(boost::optional<TenantId> tenantId, StringData dbName) { + DatabaseName(boost::optional<TenantId> tenantId, StringData dbString) { _tenantId = tenantId; - _dbName = dbName.toString(); + _dbString = dbString.toString(); - _tenantDbName = - _tenantId ? boost::make_optional(_tenantId->toString() + "_" + _dbName) : boost::none; + _tenantDbString = + _tenantId ? boost::make_optional(_tenantId->toString() + "_" + _dbString) : boost::none; } /** * Prefer to use the constructor above. * TODO SERVER-65456 Remove this constructor. */ - TenantDatabaseName(StringData dbName, boost::optional<TenantId> tenantId = boost::none) - : TenantDatabaseName(tenantId, dbName) {} + DatabaseName(StringData dbName, boost::optional<TenantId> tenantId = boost::none) + : DatabaseName(tenantId, dbName) {} - static TenantDatabaseName createSystemTenantDbName(StringData dbName); + static DatabaseName createSystemTenantDbName(StringData dbString); boost::optional<TenantId> tenantId() const { return _tenantId; } - const std::string& dbName() const { - return _dbName; + const std::string& db() const { + return _dbString; } - const std::string& fullName() const { - if (_tenantDbName) - return *_tenantDbName; + const std::string& toString() const { + if (_tenantDbString) + return *_tenantDbString; invariant(!_tenantId); - return _dbName; - } - - const std::string& toString() const { - return fullName(); + return _dbString; } - bool equalCaseInsensitive(const TenantDatabaseName& other) const { - return boost::iequals(fullName(), other.fullName()); + bool equalCaseInsensitive(const DatabaseName& other) const { + return boost::iequals(toString(), other.toString()); } /** * Returns -1, 0, or 1 if 'this' is less, equal, or greater than 'other' in * lexicographical order. */ - int compare(const TenantDatabaseName& other) const { - return fullName().compare(other.fullName()); + int compare(const DatabaseName& other) const { + return toString().compare(other.toString()); } template <typename H> - friend H AbslHashValue(H h, const TenantDatabaseName& obj) { - return H::combine(std::move(h), obj.fullName()); + friend H AbslHashValue(H h, const DatabaseName& obj) { + return H::combine(std::move(h), obj.toString()); } - friend auto logAttrs(const TenantDatabaseName& obj) { - return "tenantDatabaseName"_attr = obj; + friend auto logAttrs(const DatabaseName& obj) { + return "databaseName"_attr = obj; } private: boost::optional<TenantId> _tenantId; - std::string _dbName; - boost::optional<std::string> _tenantDbName; + std::string _dbString; + boost::optional<std::string> _tenantDbString; }; -inline std::ostream& operator<<(std::ostream& stream, const TenantDatabaseName& tdb) { - return stream << tdb.fullName(); +inline std::ostream& operator<<(std::ostream& stream, const DatabaseName& tdb) { + return stream << tdb.toString(); } -inline StringBuilder& operator<<(StringBuilder& builder, const TenantDatabaseName& tdb) { - return builder << tdb.fullName(); +inline StringBuilder& operator<<(StringBuilder& builder, const DatabaseName& tdb) { + return builder << tdb.toString(); } -inline bool operator==(const TenantDatabaseName& lhs, const TenantDatabaseName& rhs) { +inline bool operator==(const DatabaseName& lhs, const DatabaseName& rhs) { return lhs.compare(rhs) == 0; } -inline bool operator!=(const TenantDatabaseName& lhs, const TenantDatabaseName& rhs) { +inline bool operator!=(const DatabaseName& lhs, const DatabaseName& rhs) { return !(lhs == rhs); } -inline bool operator<(const TenantDatabaseName& lhs, const TenantDatabaseName& rhs) { +inline bool operator<(const DatabaseName& lhs, const DatabaseName& rhs) { return lhs.compare(rhs) < 0; } -inline bool operator>(const TenantDatabaseName& lhs, const TenantDatabaseName& rhs) { +inline bool operator>(const DatabaseName& lhs, const DatabaseName& rhs) { return rhs < lhs; } -inline bool operator<=(const TenantDatabaseName& lhs, const TenantDatabaseName& rhs) { +inline bool operator<=(const DatabaseName& lhs, const DatabaseName& rhs) { return !(lhs > rhs); } -inline bool operator>=(const TenantDatabaseName& lhs, const TenantDatabaseName& rhs) { +inline bool operator>=(const DatabaseName& lhs, const DatabaseName& rhs) { return !(lhs < rhs); } diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index 7c02ea125d0..b9e6bc38f46 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -878,13 +878,13 @@ AutoGetCollectionForReadCommandLockFree::AutoGetCollectionForReadCommandLockFree OldClientContext::OldClientContext(OperationContext* opCtx, const std::string& ns, bool doVersion) : _opCtx(opCtx) { - // TODO SERVER-65488 Grab the TenantDatabaseName from the NamespaceString passed in - const auto dbName = nsToDatabaseSubstring(ns); - const TenantDatabaseName tenantDbName(boost::none, dbName); - _db = DatabaseHolder::get(opCtx)->getDb(opCtx, tenantDbName); + // TODO SERVER-65488 Grab the DatabaseName from the NamespaceString passed in + const auto db = nsToDatabaseSubstring(ns); + const DatabaseName dbName(boost::none, db); + _db = DatabaseHolder::get(opCtx)->getDb(opCtx, dbName); if (!_db) { - _db = DatabaseHolder::get(opCtx)->openDb(_opCtx, tenantDbName, &_justCreated); + _db = DatabaseHolder::get(opCtx)->openDb(_opCtx, dbName, &_justCreated); invariant(_db); } @@ -905,7 +905,7 @@ OldClientContext::OldClientContext(OperationContext* opCtx, const std::string& n stdx::lock_guard<Client> lk(*_opCtx->getClient()); currentOp->enter_inlock( - ns.c_str(), CollectionCatalog::get(opCtx)->getDatabaseProfileLevel(_db->name().dbName())); + ns.c_str(), CollectionCatalog::get(opCtx)->getDatabaseProfileLevel(_db->name().db())); } AutoGetCollectionForReadCommandMaybeLockFree::AutoGetCollectionForReadCommandMaybeLockFree( diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp index 2a8db9e64a8..7d7da8040ae 100644 --- a/src/mongo/db/introspect.cpp +++ b/src/mongo/db/introspect.cpp @@ -163,10 +163,10 @@ void profile(OperationContext* opCtx, NetworkOp op) { Status createProfileCollection(OperationContext* opCtx, Database* db) { - invariant(opCtx->lockState()->isDbLockedForMode(db->name().dbName(), MODE_IX)); + invariant(opCtx->lockState()->isDbLockedForMode(db->name().db(), MODE_IX)); invariant(!opCtx->shouldParticipateInFlowControl()); - const auto dbProfilingNS = NamespaceString(db->name().dbName(), "system.profile"); + const auto dbProfilingNS = NamespaceString(db->name().db(), "system.profile"); // Checking the collection exists must also be done in the WCE retry loop. Only retrying // collection creation would endlessly throw errors because the collection exists: must check diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp index f3099235fca..cc02a9027a3 100644 --- a/src/mongo/db/namespace_string.cpp +++ b/src/mongo/db/namespace_string.cpp @@ -260,14 +260,14 @@ bool NamespaceString::mustBeAppliedInOwnOplogBatch() const { _ns == kTenantMigrationRecipientsNamespace.ns(); } -NamespaceString NamespaceString::makeListCollectionsNSS(const TenantDatabaseName& dbName) { +NamespaceString NamespaceString::makeListCollectionsNSS(const DatabaseName& dbName) { NamespaceString nss(dbName, listCollectionsCursorCol); dassert(nss.isValid()); dassert(nss.isListCollectionsCursorNS()); return nss; } -NamespaceString NamespaceString::makeCollectionlessAggregateNSS(const TenantDatabaseName& dbName) { +NamespaceString NamespaceString::makeCollectionlessAggregateNSS(const DatabaseName& dbName) { NamespaceString nss(dbName, collectionlessAggregateCursorCol); dassert(nss.isValid()); dassert(nss.isCollectionlessAggregateNS()); diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index 5dfcac951e3..d16005bc17c 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -37,9 +37,9 @@ #include "mongo/base/status_with.h" #include "mongo/base/string_data.h" #include "mongo/bson/util/builder.h" +#include "mongo/db/database_name.h" #include "mongo/db/repl/optime.h" #include "mongo/db/server_options.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/db/tenant_id.h" #include "mongo/logv2/log_attr.h" #include "mongo/util/assert_util.h" @@ -239,7 +239,7 @@ public: _ns.find('\0') == std::string::npos); auto db = _dotIndex == std::string::npos ? ns : ns.substr(0, _dotIndex); - _dbName = TenantDatabaseName(tenantId, db); + _dbName = DatabaseName(tenantId, db); } // TODO SERVER-65920 Remove this constructor once all constructor call sites have been updated @@ -251,16 +251,16 @@ public: * Constructs a NamespaceString for the given database and collection names. * "dbName" must not contain a ".", and "collectionName" must not start with one. */ - NamespaceString(TenantDatabaseName dbName, StringData collectionName) - : _ns(dbName.fullName().size() + collectionName.size() + 1, '\0') { + NamespaceString(DatabaseName dbName, StringData collectionName) + : _ns(dbName.toString().size() + collectionName.size() + 1, '\0') { uassert(ErrorCodes::InvalidNamespace, - "'.' is an invalid character in the database name: " + dbName.dbName(), - dbName.dbName().find('.') == std::string::npos); + "'.' is an invalid character in the database name: " + dbName.db(), + dbName.db().find('.') == std::string::npos); uassert(ErrorCodes::InvalidNamespace, "Collection names cannot start with '.': " + collectionName, collectionName.empty() || collectionName[0] != '.'); - auto db = dbName.fullName(); + auto db = dbName.toString(); std::string::iterator it = std::copy(db.begin(), db.end(), _ns.begin()); *it = '.'; ++it; @@ -283,14 +283,14 @@ public: * NOT expected to contain a tenantId. */ NamespaceString(boost::optional<TenantId> tenantId, StringData db, StringData collectionName) - : NamespaceString(TenantDatabaseName(tenantId, db), collectionName) {} + : NamespaceString(DatabaseName(tenantId, db), collectionName) {} // TODO SERVER-65920 Remove this constructor once all constructor call sites have been updated // to pass tenantId explicitly NamespaceString(StringData db, StringData collectionName, boost::optional<TenantId> tenantId = boost::none) - : NamespaceString(TenantDatabaseName(tenantId, db), collectionName) {} + : NamespaceString(DatabaseName(tenantId, db), collectionName) {} /** * Constructs a NamespaceString from the string 'ns'. Should only be used when reading a @@ -302,13 +302,13 @@ public: * Constructs the namespace '<dbName>.$cmd.aggregate', which we use as the namespace for * aggregation commands with the format {aggregate: 1}. */ - static NamespaceString makeCollectionlessAggregateNSS(const TenantDatabaseName& dbName); + static NamespaceString makeCollectionlessAggregateNSS(const DatabaseName& dbName); /** * Constructs a NamespaceString representing a listCollections namespace. The format for this * namespace is "<dbName>.$cmd.listCollections". */ - static NamespaceString makeListCollectionsNSS(const TenantDatabaseName& dbName); + static NamespaceString makeListCollectionsNSS(const DatabaseName& dbName); /** * NOTE: DollarInDbNameBehavior::allow is deprecated. @@ -327,10 +327,10 @@ public: StringData db() const { // TODO SERVER-65456 Remove this function. - return StringData(_dbName.fullName()); + return StringData(_dbName.toString()); } - TenantDatabaseName dbName() const { + DatabaseName dbName() const { return _dbName; } @@ -648,7 +648,7 @@ public: private: std::string _ns; size_t _dotIndex = 0; - TenantDatabaseName _dbName; + DatabaseName _dbName; }; /** @@ -658,15 +658,15 @@ private: class NamespaceStringOrUUID { public: NamespaceStringOrUUID(NamespaceString nss) : _nss(std::move(nss)) {} - NamespaceStringOrUUID(TenantDatabaseName dbname, UUID uuid) + NamespaceStringOrUUID(DatabaseName dbname, UUID uuid) : _uuid(std::move(uuid)), _dbname(std::move(dbname)) {} NamespaceStringOrUUID(boost::optional<TenantId> tenantId, std::string db, UUID uuid) - : _uuid(std::move(uuid)), _dbname(TenantDatabaseName(std::move(tenantId), std::move(db))) {} + : _uuid(std::move(uuid)), _dbname(DatabaseName(std::move(tenantId), std::move(db))) {} // TODO SERVER-65920 Remove once all call sites have been changed to take tenantId explicitly NamespaceStringOrUUID(std::string db, UUID uuid, boost::optional<TenantId> tenantId = boost::none) - : _uuid(std::move(uuid)), _dbname(TenantDatabaseName(std::move(tenantId), std::move(db))) {} + : _uuid(std::move(uuid)), _dbname(DatabaseName(std::move(tenantId), std::move(db))) {} const boost::optional<NamespaceString>& nss() const { return _nss; @@ -684,10 +684,10 @@ public: * Returns database name if this object was initialized with a UUID. */ std::string dbname() const { - return _dbname ? _dbname->dbName() : ""; + return _dbname ? _dbname->db() : ""; } - const boost::optional<TenantDatabaseName>& dbnameWithTenant() const { + const boost::optional<DatabaseName>& dbnameWithTenant() const { return _dbname; } @@ -699,7 +699,7 @@ public: * Returns database name derived from either '_nss' or '_dbname'. */ StringData db() const { - return _nss ? _nss->db() : StringData(_dbname->dbName()); + return _nss ? _nss->db() : StringData(_dbname->db()); } /** @@ -723,7 +723,7 @@ private: // Empty when '_nss' is non-none, and contains the database name when '_uuid' is // non-none. Although the UUID specifies a collection uniquely, we must later verify that the // collection belongs to the database named here. - boost::optional<TenantDatabaseName> _dbname; + boost::optional<DatabaseName> _dbname; }; std::ostream& operator<<(std::ostream& stream, const NamespaceString& nss); diff --git a/src/mongo/db/namespace_string_test.cpp b/src/mongo/db/namespace_string_test.cpp index 6fc57751e1e..9673481b874 100644 --- a/src/mongo/db/namespace_string_test.cpp +++ b/src/mongo/db/namespace_string_test.cpp @@ -280,8 +280,7 @@ TEST(NamespaceStringTest, NamespaceStringParse5) { } TEST(NamespaceStringTest, makeListCollectionsNSIsCorrect) { - NamespaceString ns = - NamespaceString::makeListCollectionsNSS(TenantDatabaseName(boost::none, "DB")); + NamespaceString ns = NamespaceString::makeListCollectionsNSS(DatabaseName(boost::none, "DB")); ASSERT_EQUALS("DB", ns.db()); ASSERT_EQUALS("$cmd.listCollections", ns.coll()); ASSERT(ns.isValid()); @@ -310,7 +309,7 @@ TEST(NamespaceStringTest, NSSWithTenantId) { ASSERT(nss.tenantId()); ASSERT_EQ(*nss.tenantId(), tenantId); - TenantDatabaseName dbName(tenantId, "foo"); + DatabaseName dbName(tenantId, "foo"); NamespaceString nss2(dbName, "bar"); ASSERT_EQ(nss2.ns(), tenantNsStr); ASSERT_EQ(nss2.toString(), tenantNsStr); @@ -334,7 +333,7 @@ TEST(NamespaceStringTest, NSSNoCollectionWithTenantId) { ASSERT(nss.tenantId()); ASSERT_EQ(*nss.tenantId(), tenantId); - TenantDatabaseName dbName(tenantId, "foo"); + DatabaseName dbName(tenantId, "foo"); NamespaceString nss2(dbName, ""); ASSERT(nss2.tenantId()); ASSERT_EQ(*nss2.tenantId(), tenantId); diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp index 8909a01ea91..33113b8b770 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -1167,9 +1167,8 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx, // Make sure the UUID values in the Collection metadata, the Collection object, and the UUID // catalog are all present and equal. invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_X)); - const TenantDatabaseName tenantDbName(boost::none, nss.db()); auto databaseHolder = DatabaseHolder::get(opCtx); - auto db = databaseHolder->getDb(opCtx, tenantDbName); + auto db = databaseHolder->getDb(opCtx, nss.dbName()); // Some unit tests call the op observer on an unregistered Database. if (!db) { return; diff --git a/src/mongo/db/pipeline/aggregation_request_helper.cpp b/src/mongo/db/pipeline/aggregation_request_helper.cpp index 81711739eb8..6a73259bef1 100644 --- a/src/mongo/db/pipeline/aggregation_request_helper.cpp +++ b/src/mongo/db/pipeline/aggregation_request_helper.cpp @@ -127,8 +127,7 @@ NamespaceString parseNs(const std::string& dbname, const BSONObj& cmdObj) { << firstElement.fieldNameStringData() << "' field must specify a collection name or 1", firstElement.number() == 1); - return NamespaceString::makeCollectionlessAggregateNSS( - TenantDatabaseName(boost::none, dbname)); + return NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, dbname)); } else { uassert(ErrorCodes::TypeMismatch, str::stream() << "collection name has invalid type: " diff --git a/src/mongo/db/pipeline/aggregation_request_test.cpp b/src/mongo/db/pipeline/aggregation_request_test.cpp index 4038b32dfd8..be336da50fd 100644 --- a/src/mongo/db/pipeline/aggregation_request_test.cpp +++ b/src/mongo/db/pipeline/aggregation_request_test.cpp @@ -254,7 +254,7 @@ TEST(AggregationRequestTest, ShouldSerializeBatchSizeIfSetAndExplainFalse) { TEST(AggregationRequestTest, ShouldSerialiseAggregateFieldToOneIfCollectionIsAggregateOneNSS) { NamespaceString nss = - NamespaceString::makeCollectionlessAggregateNSS(TenantDatabaseName(boost::none, "a")); + NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "a")); AggregateCommandRequest request(nss, {}); auto expectedSerialization = diff --git a/src/mongo/db/pipeline/change_stream_event_transform_test.cpp b/src/mongo/db/pipeline/change_stream_event_transform_test.cpp index 89dabf3c73e..a5bdb3b0b73 100644 --- a/src/mongo/db/pipeline/change_stream_event_transform_test.cpp +++ b/src/mongo/db/pipeline/change_stream_event_transform_test.cpp @@ -125,7 +125,7 @@ TEST(ChangeStreamEventTransformTest, TestCreateViewTransform) { ASSERT_DOCUMENT_EQ(applyTransformation(oplogEntry, NamespaceString::makeCollectionlessAggregateNSS( - TenantDatabaseName(boost::none, "viewDB"))), + DatabaseName(boost::none, "viewDB"))), expectedDoc); } diff --git a/src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp index 0d4f8778b14..33cf79cc36f 100644 --- a/src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp +++ b/src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp @@ -239,8 +239,7 @@ TEST_F(DocumentSourceChangeStreamAddPostImageTest, ShouldErrorIfDatabaseMismatchOnCollectionlessNss) { auto expCtx = getExpCtx(); - expCtx->ns = - NamespaceString::makeCollectionlessAggregateNSS(TenantDatabaseName(boost::none, "test")); + expCtx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "test")); // Set up the lookup change post image stage. auto lookupChangeStage = DocumentSourceChangeStreamAddPostImage::create(expCtx, getSpec()); @@ -265,8 +264,7 @@ TEST_F(DocumentSourceChangeStreamAddPostImageTest, TEST_F(DocumentSourceChangeStreamAddPostImageTest, ShouldPassIfDatabaseMatchesOnCollectionlessNss) { auto expCtx = getExpCtx(); - expCtx->ns = - NamespaceString::makeCollectionlessAggregateNSS(TenantDatabaseName(boost::none, "test")); + expCtx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "test")); // Set up the lookup change post image stage. auto lookupChangeStage = DocumentSourceChangeStreamAddPostImage::create(expCtx, getSpec()); diff --git a/src/mongo/db/pipeline/document_source_change_stream_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_test.cpp index 1c7b690a243..cdf631dfc63 100644 --- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp +++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp @@ -2848,7 +2848,7 @@ class ChangeStreamStageDBTest : public ChangeStreamStageTest { public: ChangeStreamStageDBTest() : ChangeStreamStageTest(NamespaceString::makeCollectionlessAggregateNSS( - TenantDatabaseName(boost::none, nss.db()))) {} + DatabaseName(boost::none, nss.db()))) {} }; TEST_F(ChangeStreamStageDBTest, TransformInsert) { @@ -4538,8 +4538,8 @@ TEST_F(MultiTokenFormatVersionTest, CanResumeFromV1HighWaterMark) { ResumeTokenData resumeToken = ResumeToken::makeHighWaterMarkToken(resumeTs, 2).getData(); resumeToken.version = 1; auto expCtx = getExpCtxRaw(); - expCtx->ns = NamespaceString::makeCollectionlessAggregateNSS( - TenantDatabaseName(boost::none, "unittests")); + expCtx->ns = + NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "unittests")); // Create a change stream spec that resumes after 'resumeToken'. const auto spec = diff --git a/src/mongo/db/pipeline/document_source_current_op_test.cpp b/src/mongo/db/pipeline/document_source_current_op_test.cpp index 34daaa921ba..881f5e476b7 100644 --- a/src/mongo/db/pipeline/document_source_current_op_test.cpp +++ b/src/mongo/db/pipeline/document_source_current_op_test.cpp @@ -53,8 +53,9 @@ const std::string kMockShardName = "testshard"; class DocumentSourceCurrentOpTest : public AggregationContextFixture { public: DocumentSourceCurrentOpTest() - : AggregationContextFixture(NamespaceString::makeCollectionlessAggregateNSS( - TenantDatabaseName(boost::none, "admin"))) {} + : AggregationContextFixture( + NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "admin"))) { + } }; /** @@ -100,7 +101,7 @@ TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfSpecIsNotObject) { TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfNotRunOnAdmin) { const auto specObj = fromjson("{$currentOp:{}}"); getExpCtx()->ns = - NamespaceString::makeCollectionlessAggregateNSS(TenantDatabaseName(boost::none, "foo")); + NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "foo")); ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()), AssertionException, ErrorCodes::InvalidNamespace); diff --git a/src/mongo/db/pipeline/document_source_facet_test.cpp b/src/mongo/db/pipeline/document_source_facet_test.cpp index 01bded3cc1e..3b278cdb53d 100644 --- a/src/mongo/db/pipeline/document_source_facet_test.cpp +++ b/src/mongo/db/pipeline/document_source_facet_test.cpp @@ -116,8 +116,8 @@ TEST_F(DocumentSourceFacetTest, ShouldSucceedWhenNamespaceIsCollectionless) { auto ctx = getExpCtx(); auto spec = fromjson("{$facet: {a: [{$match: {}}]}}"); - ctx->ns = NamespaceString::makeCollectionlessAggregateNSS( - TenantDatabaseName(boost::none, "unittests")); + ctx->ns = + NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "unittests")); ASSERT_TRUE(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx).get()); } diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp index ae36e6b04cf..16833172312 100644 --- a/src/mongo/db/pipeline/pipeline_test.cpp +++ b/src/mongo/db/pipeline/pipeline_test.cpp @@ -4206,7 +4206,7 @@ TEST_F(PipelineValidateTest, AggregateOneNSNotValidForEmptyPipeline) { const std::vector<BSONObj> rawPipeline = {}; auto ctx = getExpCtx(); - ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(TenantDatabaseName(boost::none, "a")); + ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "a")); ASSERT_THROWS_CODE( Pipeline::parse(rawPipeline, ctx), AssertionException, ErrorCodes::InvalidNamespace); @@ -4216,7 +4216,7 @@ TEST_F(PipelineValidateTest, AggregateOneNSNotValidIfInitialStageRequiresCollect const std::vector<BSONObj> rawPipeline = {fromjson("{$match: {}}")}; auto ctx = getExpCtx(); - ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(TenantDatabaseName(boost::none, "a")); + ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "a")); ASSERT_THROWS_CODE( Pipeline::parse(rawPipeline, ctx), AssertionException, ErrorCodes::InvalidNamespace); @@ -4226,7 +4226,7 @@ TEST_F(PipelineValidateTest, AggregateOneNSValidIfInitialStageIsCollectionless) auto ctx = getExpCtx(); auto collectionlessSource = DocumentSourceCollectionlessMock::create(ctx); - ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(TenantDatabaseName(boost::none, "a")); + ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "a")); Pipeline::create({collectionlessSource}, ctx); } @@ -4247,8 +4247,8 @@ TEST_F(PipelineValidateTest, AggregateOneNSValidForFacetPipelineRegardlessOfInit const std::vector<BSONObj> rawPipeline = {fromjson("{$facet: {subPipe: [{$match: {}}]}}")}; auto ctx = getExpCtx(); - ctx->ns = NamespaceString::makeCollectionlessAggregateNSS( - TenantDatabaseName(boost::none, "unittests")); + ctx->ns = + NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "unittests")); ASSERT_THROWS_CODE( Pipeline::parse(rawPipeline, ctx), AssertionException, ErrorCodes::InvalidNamespace); diff --git a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp index 2639d0c1050..43c97f7e7d2 100644 --- a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp +++ b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp @@ -597,9 +597,8 @@ bool CommonMongodProcessInterface::fieldsHaveSupportingUniqueIndex( // the catalog. Lock::DBLock dbLock(opCtx, nss.db(), MODE_IS); Lock::CollectionLock collLock(opCtx, nss, MODE_IS); - const TenantDatabaseName tenantDbName(boost::none, nss.db()); auto databaseHolder = DatabaseHolder::get(opCtx); - auto db = databaseHolder->getDb(opCtx, tenantDbName); + auto db = databaseHolder->getDb(opCtx, nss.dbName()); auto collection = db ? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss) : nullptr; if (!collection) { diff --git a/src/mongo/db/repair.cpp b/src/mongo/db/repair.cpp index 85b69329662..2fb9be70d05 100644 --- a/src/mongo/db/repair.cpp +++ b/src/mongo/db/repair.cpp @@ -115,8 +115,8 @@ Status dropUnfinishedIndexes(OperationContext* opCtx, Collection* collection) { Status repairCollections(OperationContext* opCtx, StorageEngine* engine, - const TenantDatabaseName& tenantDbName) { - auto colls = CollectionCatalog::get(opCtx)->getAllCollectionNamesFromDb(opCtx, tenantDbName); + const DatabaseName& dbName) { + auto colls = CollectionCatalog::get(opCtx)->getAllCollectionNamesFromDb(opCtx, dbName); for (const auto& nss : colls) { auto status = repair::repairCollection(opCtx, engine, nss); @@ -129,33 +129,31 @@ Status repairCollections(OperationContext* opCtx, } // namespace namespace repair { -Status repairDatabase(OperationContext* opCtx, - StorageEngine* engine, - const TenantDatabaseName& tenantDbName) { +Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const DatabaseName& dbName) { DisableDocumentValidation validationDisabler(opCtx); // We must hold some form of lock here invariant(opCtx->lockState()->isW()); - invariant(tenantDbName.dbName().find('.') == std::string::npos); + invariant(dbName.db().find('.') == std::string::npos); - LOGV2(21029, "repairDatabase", "db"_attr = tenantDbName); + LOGV2(21029, "repairDatabase", "db"_attr = dbName); opCtx->checkForInterrupt(); // Close the db and invalidate all current users and caches. auto databaseHolder = DatabaseHolder::get(opCtx); - databaseHolder->close(opCtx, tenantDbName); + databaseHolder->close(opCtx, dbName); // Reopening db is necessary for repairCollections. - databaseHolder->openDb(opCtx, tenantDbName); + databaseHolder->openDb(opCtx, dbName); - auto status = repairCollections(opCtx, engine, tenantDbName); + auto status = repairCollections(opCtx, engine, dbName); if (!status.isOK()) { LOGV2_FATAL_CONTINUE(21030, "Failed to repair database {dbName}: {status_reason}", "Failed to repair database", - "db"_attr = tenantDbName, + "db"_attr = dbName, "error"_attr = status); } diff --git a/src/mongo/db/repair.h b/src/mongo/db/repair.h index 391c391f91d..d2f120f7142 100644 --- a/src/mongo/db/repair.h +++ b/src/mongo/db/repair.h @@ -33,8 +33,8 @@ #include <string> #include "mongo/bson/bsonobj.h" +#include "mongo/db/database_name.h" #include "mongo/db/record_id.h" -#include "mongo/db/tenant_database_name.h" namespace mongo { class StorageEngine; @@ -51,9 +51,7 @@ namespace repair { * * It is expected that the local database will be repaired first when running in repair mode. */ -Status repairDatabase(OperationContext* opCtx, - StorageEngine* engine, - const TenantDatabaseName& tenantDbName); +Status repairDatabase(OperationContext* opCtx, StorageEngine* engine, const DatabaseName& dbName); /** * Repairs a collection using a storage engine-specific, best-effort process. diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp index 1d341317de8..972c1fb2580 100644 --- a/src/mongo/db/repl/apply_ops.cpp +++ b/src/mongo/db/repl/apply_ops.cpp @@ -41,6 +41,7 @@ #include "mongo/db/concurrency/exception_util.h" #include "mongo/db/concurrency/lock_state.h" #include "mongo/db/curop.h" +#include "mongo/db/database_name.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/index/index_descriptor.h" @@ -52,7 +53,6 @@ #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/service_context.h" #include "mongo/db/session_catalog_mongod.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/db/transaction_participant.h" #include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" @@ -305,9 +305,8 @@ Status _checkPrecondition(OperationContext* opCtx, BSONObj realres = cursor->more() ? cursor->nextSafe() : BSONObj{}; // Get collection default collation. - const TenantDatabaseName tenantDbName(boost::none, nss.db()); auto databaseHolder = DatabaseHolder::get(opCtx); - auto database = databaseHolder->getDb(opCtx, tenantDbName); + auto database = databaseHolder->getDb(opCtx, nss.dbName()); if (!database) { return {ErrorCodes::NamespaceNotFound, "database in ns does not exist: " + nss.ns()}; } diff --git a/src/mongo/db/repl/idempotency_test_fixture.cpp b/src/mongo/db/repl/idempotency_test_fixture.cpp index d2106320e97..e844e2fb6fc 100644 --- a/src/mongo/db/repl/idempotency_test_fixture.cpp +++ b/src/mongo/db/repl/idempotency_test_fixture.cpp @@ -353,14 +353,14 @@ std::string IdempotencyTest::computeDataHash(const CollectionPtr& collection) { std::vector<CollectionState> IdempotencyTest::validateAllCollections() { std::vector<CollectionState> collStates; auto catalog = CollectionCatalog::get(_opCtx.get()); - auto tenantDbNames = catalog->getAllDbNames(); - for (auto& tenantDbName : tenantDbNames) { + auto dbNames = catalog->getAllDbNames(); + for (auto& dbName : dbNames) { // Skip local database. - if (tenantDbName.dbName() != "local") { + if (dbName.db() != "local") { std::vector<NamespaceString> collectionNames; { - Lock::DBLock lk(_opCtx.get(), tenantDbName.dbName(), MODE_S); - collectionNames = catalog->getAllCollectionNamesFromDb(_opCtx.get(), tenantDbName); + Lock::DBLock lk(_opCtx.get(), dbName.db(), MODE_S); + collectionNames = catalog->getAllCollectionNamesFromDb(_opCtx.get(), dbName); } for (const auto& nss : collectionNames) { collStates.push_back(validate(nss)); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index cc5d53003be..ff034ab3575 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -200,9 +200,8 @@ void createIndexForApplyOps(OperationContext* opCtx, invariant(opCtx->lockState()->isCollectionLockedForMode(indexNss, MODE_X)); // Check if collection exists. - const TenantDatabaseName tenantDbName(boost::none, indexNss.db()); auto databaseHolder = DatabaseHolder::get(opCtx); - auto db = databaseHolder->getDb(opCtx, tenantDbName); + auto db = databaseHolder->getDb(opCtx, indexNss.dbName()); auto indexCollection = db ? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, indexNss) : nullptr; uassert(ErrorCodes::NamespaceNotFound, diff --git a/src/mongo/db/repl/oplog_applier_impl_test.cpp b/src/mongo/db/repl/oplog_applier_impl_test.cpp index 626f94fe9e3..5784b645cc5 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test.cpp @@ -2140,8 +2140,7 @@ TEST_F(OplogApplierImplTest, ApplyGroupIgnoresUpdateOperationIfDocumentIsMissing Lock::GlobalWrite globalLock(_opCtx.get()); bool justCreated = false; auto databaseHolder = DatabaseHolder::get(_opCtx.get()); - const TenantDatabaseName tenantDbName(boost::none, nss.db()); - auto db = databaseHolder->openDb(_opCtx.get(), tenantDbName, &justCreated); + auto db = databaseHolder->openDb(_opCtx.get(), nss.dbName(), &justCreated); ASSERT_TRUE(db); ASSERT_TRUE(justCreated); } 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 351a9e37ac5..9dfb154a971 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp @@ -484,7 +484,7 @@ void createDatabase(OperationContext* opCtx, StringData dbName) { Lock::GlobalWrite globalLock(opCtx); bool justCreated; auto databaseHolder = DatabaseHolder::get(opCtx); - const TenantDatabaseName tenantDbName(boost::none, dbName); + const DatabaseName tenantDbName(boost::none, dbName); auto db = databaseHolder->openDb(opCtx, tenantDbName, &justCreated); ASSERT_TRUE(db); ASSERT_TRUE(justCreated); diff --git a/src/mongo/db/repl/repl_set_commands.cpp b/src/mongo/db/repl/repl_set_commands.cpp index c7ab0f103a8..5823d880c14 100644 --- a/src/mongo/db/repl/repl_set_commands.cpp +++ b/src/mongo/db/repl/repl_set_commands.cpp @@ -711,12 +711,12 @@ namespace { */ bool replHasDatabases(OperationContext* opCtx) { StorageEngine* storageEngine = getGlobalServiceContext()->getStorageEngine(); - std::vector<TenantDatabaseName> tenantDbNames = storageEngine->listDatabases(); + std::vector<DatabaseName> dbNames = storageEngine->listDatabases(); - if (tenantDbNames.size() >= 2) + if (dbNames.size() >= 2) return true; - if (tenantDbNames.size() == 1) { - if (tenantDbNames[0].dbName() != "local") + if (dbNames.size() == 1) { + if (dbNames[0].db() != "local") return true; // we have a local database. return true if oplog isn't empty diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 9d294074c92..a46671d6c62 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -1025,23 +1025,21 @@ void ReplicationCoordinatorExternalStateImpl::_dropAllTempCollections(OperationC Lock::GlobalLock lk(opCtx, MODE_IS); StorageEngine* storageEngine = _service->getStorageEngine(); - std::vector<TenantDatabaseName> tenantDbNames = storageEngine->listDatabases(); + std::vector<DatabaseName> dbNames = storageEngine->listDatabases(); - for (std::vector<TenantDatabaseName>::iterator it = tenantDbNames.begin(); - it != tenantDbNames.end(); - ++it) { + for (const auto& dbName : dbNames) { // The local db is special because it isn't replicated. It is cleared at startup even on // replica set members. - if (it->dbName() == "local") + if (dbName.db() == "local") continue; LOGV2_DEBUG(21309, 2, "Removing temporary collections from {db}", "Removing temporary collections", - "db"_attr = *it); - AutoGetDb autoDb(opCtx, it->dbName(), MODE_IX); + "db"_attr = dbName); + AutoGetDb autoDb(opCtx, dbName.db(), MODE_IX); invariant(autoDb.getDb(), - str::stream() << "Unable to get reference to database " << it->dbName()); + str::stream() << "Unable to get reference to database " << dbName.db()); autoDb.getDb()->clearTmpCollections(opCtx); } } diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index 2443730507d..728fb0b505d 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -43,6 +43,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/exception_util.h" #include "mongo/db/concurrency/replication_state_transition_lock_guard.h" +#include "mongo/db/database_name.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" @@ -64,7 +65,6 @@ #include "mongo/db/session_txn_record_gen.h" #include "mongo/db/storage/historical_ident_tracker.h" #include "mongo/db/storage/remove_saver.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/db/transaction_history_iterator.h" #include "mongo/logv2/log.h" #include "mongo/s/catalog/type_config_version.h" @@ -359,7 +359,7 @@ void RollbackImpl::_stopAndWaitForIndexBuilds(OperationContext* opCtx) { // Get a list of all databases. StorageEngine* storageEngine = opCtx->getServiceContext()->getStorageEngine(); - std::vector<TenantDatabaseName> dbs; + std::vector<DatabaseName> dbs; { Lock::GlobalLock lk(opCtx, MODE_IS); dbs = storageEngine->listDatabases(); @@ -368,10 +368,10 @@ void RollbackImpl::_stopAndWaitForIndexBuilds(OperationContext* opCtx) { // Wait for all background operations to complete by waiting on each database. Single-phase // index builds are not stopped before rollback, so we must wait for these index builds to // complete. - std::vector<TenantDatabaseName> tenantDbNames(dbs.begin(), dbs.end()); + std::vector<DatabaseName> dbNames(dbs.begin(), dbs.end()); LOGV2(21595, "Waiting for all background operations to complete before starting rollback"); - for (auto tenantDbName : tenantDbNames) { - auto numInProg = IndexBuildsCoordinator::get(opCtx)->numInProgForDb(tenantDbName.dbName()); + for (auto dbName : dbNames) { + auto numInProg = IndexBuildsCoordinator::get(opCtx)->numInProgForDb(dbName.toString()); if (numInProg > 0) { LOGV2_DEBUG(21596, 1, @@ -379,9 +379,8 @@ void RollbackImpl::_stopAndWaitForIndexBuilds(OperationContext* opCtx) { "background operations to complete on database '{db}'", "Waiting for background operations to complete", "numBackgroundOperationsInProgress"_attr = numInProg, - "db"_attr = tenantDbName); - IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(opCtx, - tenantDbName.dbName()); + "db"_attr = dbName); + IndexBuildsCoordinator::get(opCtx)->awaitNoBgOpInProgForDb(opCtx, dbName.toString()); } } @@ -1368,11 +1367,11 @@ void RollbackImpl::_resetDropPendingState(OperationContext* opCtx) { auto storageEngine = opCtx->getServiceContext()->getStorageEngine(); storageEngine->clearDropPendingState(); - std::vector<TenantDatabaseName> tenantDbNames = storageEngine->listDatabases(); + std::vector<DatabaseName> dbNames = storageEngine->listDatabases(); auto databaseHolder = DatabaseHolder::get(opCtx); - for (const auto& tenantDbName : tenantDbNames) { - Lock::DBLock dbLock(opCtx, tenantDbName.dbName(), MODE_X); - auto db = databaseHolder->openDb(opCtx, tenantDbName); + for (const auto& dbName : dbNames) { + Lock::DBLock dbLock(opCtx, dbName.db(), MODE_X); + auto db = databaseHolder->openDb(opCtx, dbName); db->checkForIdIndexesAndDropPendingCollections(opCtx); } } diff --git a/src/mongo/db/repl/rollback_test_fixture.cpp b/src/mongo/db/repl/rollback_test_fixture.cpp index b6e72f28bb8..f2486997bb6 100644 --- a/src/mongo/db/repl/rollback_test_fixture.cpp +++ b/src/mongo/db/repl/rollback_test_fixture.cpp @@ -213,8 +213,7 @@ Collection* RollbackTest::_createCollection(OperationContext* opCtx, Lock::DBLock dbLock(opCtx, nss.db(), MODE_X); mongo::WriteUnitOfWork wuow(opCtx); auto databaseHolder = DatabaseHolder::get(opCtx); - const TenantDatabaseName tenantDbName(boost::none, nss.db()); - auto db = databaseHolder->openDb(opCtx, tenantDbName); + auto db = databaseHolder->openDb(opCtx, nss.dbName()); ASSERT_TRUE(db); db->dropCollection(opCtx, nss).transitional_ignore(); auto coll = db->createCollection(opCtx, nss, options); diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 6579e753196..7d254bc723d 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -1090,7 +1090,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().dbName(), LockMode::MODE_X)); + invariant(opCtx->lockState()->isDbLockedForMode(db->name().db(), 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. @@ -1141,8 +1141,8 @@ void renameOutOfTheWay(OperationContext* opCtx, RenameCollectionInfo info, Datab */ void rollbackRenameCollection(OperationContext* opCtx, UUID uuid, RenameCollectionInfo info) { - auto dbName = info.renameFrom.db(); - const TenantDatabaseName tenantDbName(boost::none, dbName); + auto dbString = info.renameFrom.db(); + const DatabaseName dbName(boost::none, dbString); LOGV2(21679, "Attempting to rename collection with UUID: {uuid}, from: {renameFrom}, to: " @@ -1151,9 +1151,9 @@ void rollbackRenameCollection(OperationContext* opCtx, UUID uuid, RenameCollecti "uuid"_attr = uuid, "renameFrom"_attr = info.renameFrom, "renameTo"_attr = info.renameTo); - Lock::DBLock dbLock(opCtx, dbName, MODE_X); + Lock::DBLock dbLock(opCtx, dbString, MODE_X); auto databaseHolder = DatabaseHolder::get(opCtx); - auto db = databaseHolder->openDb(opCtx, tenantDbName); + auto db = databaseHolder->openDb(opCtx, dbName); invariant(db); auto status = renameCollectionForRollback(opCtx, info.renameTo, uuid); @@ -1580,11 +1580,10 @@ void rollback_internal::syncFixUp(OperationContext* opCtx, "namespace"_attr = *nss, "uuid"_attr = uuid); - const TenantDatabaseName tenantDbName(boost::none, nss->db()); Lock::DBLock dbLock(opCtx, nss->db(), MODE_X); auto databaseHolder = DatabaseHolder::get(opCtx); - auto db = databaseHolder->openDb(opCtx, tenantDbName); + auto db = databaseHolder->openDb(opCtx, nss->dbName()); invariant(db); CollectionWriter collection(opCtx, uuid); diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp index 4a8ba7c2381..ddfe05a9266 100644 --- a/src/mongo/db/repl/storage_interface_impl.cpp +++ b/src/mongo/db/repl/storage_interface_impl.cpp @@ -55,6 +55,7 @@ #include "mongo/db/concurrency/exception_util.h" #include "mongo/db/concurrency/lock_state.h" #include "mongo/db/curop.h" +#include "mongo/db/database_name.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/exec/delete_stage.h" @@ -80,7 +81,6 @@ #include "mongo/db/storage/control/journal_flusher.h" #include "mongo/db/storage/control/storage_control.h" #include "mongo/db/storage/oplog_cap_maintainer_thread.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" #include "mongo/util/background.h" @@ -415,25 +415,25 @@ Status StorageInterfaceImpl::insertDocuments(OperationContext* opCtx, Status StorageInterfaceImpl::dropReplicatedDatabases(OperationContext* opCtx) { Lock::GlobalWrite globalWriteLock(opCtx); - std::vector<TenantDatabaseName> tenantDbNames = + std::vector<DatabaseName> dbNames = opCtx->getServiceContext()->getStorageEngine()->listDatabases(); - invariant(!tenantDbNames.empty()); + invariant(!dbNames.empty()); LOGV2(21754, "dropReplicatedDatabases - dropping {numDatabases} databases", "dropReplicatedDatabases - dropping databases", - "numDatabases"_attr = tenantDbNames.size()); + "numDatabases"_attr = dbNames.size()); ReplicationCoordinator::get(opCtx)->clearCommittedSnapshot(); auto databaseHolder = DatabaseHolder::get(opCtx); auto hasLocalDatabase = false; - for (const auto& tenantDbName : tenantDbNames) { - if (tenantDbName.dbName() == "local") { + for (const auto& dbName : dbNames) { + if (dbName.db() == "local") { hasLocalDatabase = true; continue; } - writeConflictRetry(opCtx, "dropReplicatedDatabases", tenantDbName.dbName(), [&] { - if (auto db = databaseHolder->getDb(opCtx, tenantDbName)) { + writeConflictRetry(opCtx, "dropReplicatedDatabases", dbName.toString(), [&] { + if (auto db = databaseHolder->getDb(opCtx, dbName)) { databaseHolder->dropDb(opCtx, db); } else { // This is needed since dropDatabase can't be rolled back. @@ -443,7 +443,7 @@ Status StorageInterfaceImpl::dropReplicatedDatabases(OperationContext* opCtx) { "database names but before drop: {dbName}", "dropReplicatedDatabases - database disappeared after retrieving list of " "database names but before drop", - "dbName"_attr = tenantDbName); + "dbName"_attr = dbName); } }); } @@ -451,7 +451,7 @@ Status StorageInterfaceImpl::dropReplicatedDatabases(OperationContext* opCtx) { LOGV2(21756, "dropReplicatedDatabases - dropped {numDatabases} databases", "dropReplicatedDatabases - dropped databases", - "numDatabases"_attr = tenantDbNames.size()); + "numDatabases"_attr = dbNames.size()); return Status::OK(); } diff --git a/src/mongo/db/repl/tenant_file_importer_service.cpp b/src/mongo/db/repl/tenant_file_importer_service.cpp index 09319217ac0..9d1076eb179 100644 --- a/src/mongo/db/repl/tenant_file_importer_service.cpp +++ b/src/mongo/db/repl/tenant_file_importer_service.cpp @@ -115,9 +115,9 @@ void importCopiedFiles(OperationContext* opCtx, for (auto&& m : metadatas) { Lock::CollectionLock systemViewsLock( opCtx, - NamespaceString(m.ns.db(), NamespaceString::kSystemDotViewsCollectionName), + NamespaceString(m.ns.dbName(), NamespaceString::kSystemDotViewsCollectionName), MODE_X); - uassertStatusOK(catalog->reloadViews(opCtx, TenantDatabaseName(boost::none, m.ns.db()))); + uassertStatusOK(catalog->reloadViews(opCtx, m.ns.dbName())); } } } // namespace diff --git a/src/mongo/db/repl/tenant_oplog_applier_test.cpp b/src/mongo/db/repl/tenant_oplog_applier_test.cpp index 59061054491..d442d73ec8f 100644 --- a/src/mongo/db/repl/tenant_oplog_applier_test.cpp +++ b/src/mongo/db/repl/tenant_oplog_applier_test.cpp @@ -187,7 +187,7 @@ protected: executor::NetworkInterfaceMock* _net; std::shared_ptr<executor::ThreadPoolTaskExecutor> _executor; std::string _tenantId = OID::gen().toString(); - TenantDatabaseName _dbName = TenantDatabaseName(TenantId(OID(_tenantId)), "test"); + DatabaseName _dbName = DatabaseName(TenantId(OID(_tenantId)), "test"); UUID _migrationUuid = UUID::gen(); ServiceContext::UniqueOperationContext _opCtx; TenantOplogApplierTestOpObserver* _opObserver; // Owned by service context opObserverRegistry @@ -296,7 +296,7 @@ TEST_F(TenantOplogApplierTest, NoOpsForLargeTransaction) { // Makes entries with ts from range [2, 5). std::vector<OplogEntry> srcOps = makeMultiEntryTransactionOplogEntries( - 2, _dbName.dbName(), /* prepared */ false, {innerOps1, innerOps2, innerOps3}); + 2, _dbName.db(), /* prepared */ false, {innerOps1, innerOps2, innerOps3}); pushOps(srcOps); auto writerPool = makeTenantMigrationWriterPool(); @@ -395,7 +395,7 @@ TEST_F(TenantOplogApplierTest, ApplyInsert_DatabaseMissing) { } TEST_F(TenantOplogApplierTest, ApplyInsert_CollectionMissing) { - createDatabase(_opCtx.get(), _dbName.fullName()); + createDatabase(_opCtx.get(), _dbName.toString()); auto entry = makeInsertOplogEntry(1, NamespaceString(_dbName, "bar"), UUID::gen()); bool onInsertsCalled = false; _opObserver->onInsertsFn = [&](OperationContext* opCtx, @@ -492,7 +492,7 @@ TEST_F(TenantOplogApplierTest, ApplyInsert_Success) { [&](OperationContext* opCtx, const NamespaceString& nss, const std::vector<BSONObj>& docs) { ASSERT_FALSE(onInsertsCalled); onInsertsCalled = true; - ASSERT_EQUALS(nss.db(), _dbName.fullName()); + ASSERT_EQUALS(nss.db(), _dbName.toString()); ASSERT_EQUALS(nss.coll(), "bar"); ASSERT_EQUALS(1, docs.size()); ASSERT_BSONOBJ_EQ(docs[0], entry.getObject()); @@ -646,7 +646,7 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_DatabaseMissing) { } TEST_F(TenantOplogApplierTest, ApplyDelete_CollectionMissing) { - createDatabase(_opCtx.get(), _dbName.fullName()); + createDatabase(_opCtx.get(), _dbName.toString()); auto entry = makeOplogEntry(OpTypeEnum::kDelete, NamespaceString(_dbName, "bar"), UUID::gen()); bool onDeleteCalled = false; _opObserver->onDeleteFn = [&](OperationContext* opCtx, @@ -711,7 +711,7 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_Success) { ASSERT_TRUE(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IX)); ASSERT_TRUE(opCtx->writesAreReplicated()); ASSERT_FALSE(args.fromMigrate); - ASSERT_EQUALS(nss.db(), _dbName.fullName()); + ASSERT_EQUALS(nss.db(), _dbName.toString()); ASSERT_EQUALS(nss.coll(), "bar"); ASSERT_EQUALS(uuid, observer_uuid); }; @@ -990,7 +990,7 @@ TEST_F(TenantOplogApplierTest, ApplyCollModCommand_IndexNotFound) { } TEST_F(TenantOplogApplierTest, ApplyCollModCommand_CollectionMissing) { - createDatabase(_opCtx.get(), _dbName.fullName()); + createDatabase(_opCtx.get(), _dbName.toString()); NamespaceString nss(_dbName, "bar"); UUID uuid(UUID::gen()); auto op = BSON("op" diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp index e05eb92c0c8..663ad0633f6 100644 --- a/src/mongo/db/s/migration_util.cpp +++ b/src/mongo/db/s/migration_util.cpp @@ -639,14 +639,13 @@ void submitOrphanRanges(OperationContext* opCtx, const NamespaceString& nss, con void submitOrphanRangesForCleanup(OperationContext* opCtx) { auto catalog = CollectionCatalog::get(opCtx); - const auto& tenantDbNames = catalog->getAllDbNames(); + const auto& dbNames = catalog->getAllDbNames(); - for (const auto& tenantDbName : tenantDbNames) { - if (tenantDbName.dbName() == NamespaceString::kLocalDb) + for (const auto& dbName : dbNames) { + if (dbName.db() == NamespaceString::kLocalDb) continue; - for (auto collIt = catalog->begin(opCtx, tenantDbName); collIt != catalog->end(opCtx); - ++collIt) { + for (auto collIt = catalog->begin(opCtx, dbName); collIt != catalog->end(opCtx); ++collIt) { auto uuid = collIt.uuid().get(); auto nss = catalog->lookupNSSByUUID(opCtx, uuid).get(); LOGV2_DEBUG(22034, diff --git a/src/mongo/db/startup_recovery.cpp b/src/mongo/db/startup_recovery.cpp index 21a1e46959a..1f1a3496371 100644 --- a/src/mongo/db/startup_recovery.cpp +++ b/src/mongo/db/startup_recovery.cpp @@ -86,12 +86,11 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx // If the admin database, which contains the server configuration collection with the // featureCompatibilityVersion document, does not exist, create it. auto databaseHolder = DatabaseHolder::get(opCtx); - const TenantDatabaseName fcvTenantDbName(boost::none, fcvNss.db()); - auto db = databaseHolder->getDb(opCtx, fcvTenantDbName); + auto db = databaseHolder->getDb(opCtx, fcvNss.dbName()); if (!db) { LOGV2(20998, "Re-creating admin database that was dropped."); } - db = databaseHolder->openDb(opCtx, fcvTenantDbName); + db = databaseHolder->openDb(opCtx, fcvNss.dbName()); invariant(db); // If the server configuration collection, which contains the FCV document, does not exist, then @@ -260,10 +259,10 @@ void openDatabases(OperationContext* opCtx, const StorageEngine* storageEngine, invariant(opCtx->lockState()->isW()); auto databaseHolder = DatabaseHolder::get(opCtx); - auto tenantDbNames = storageEngine->listDatabases(); - for (const auto& tenantDbName : tenantDbNames) { - LOGV2_DEBUG(21010, 1, " Opening database: {dbName}", "dbName"_attr = tenantDbName); - auto db = databaseHolder->openDb(opCtx, tenantDbName); + auto dbNames = storageEngine->listDatabases(); + for (const auto& dbName : dbNames) { + LOGV2_DEBUG(21010, 1, " Opening database: {dbName}", "dbName"_attr = dbName); + auto db = databaseHolder->openDb(opCtx, dbName); invariant(db); onDatabase(db); @@ -280,8 +279,8 @@ bool hasReplSetConfigDoc(OperationContext* opCtx) { // 'kSystemReplSetNamespace' collection have been populated if the collection exists. If the // "local" database doesn't exist at this point yet, then it will be created. const auto nss = NamespaceString::kSystemReplSetNamespace; - const TenantDatabaseName tenantDbName(boost::none, nss.db()); - databaseHolder->openDb(opCtx, tenantDbName); + + databaseHolder->openDb(opCtx, nss.dbName()); BSONObj config; return Helpers::getSingleton(opCtx, nss.ns().c_str(), config); } @@ -476,8 +475,7 @@ void startupRepair(OperationContext* opCtx, StorageEngine* storageEngine) { opCtx, NamespaceString::kServerConfigurationNamespace)) { auto databaseHolder = DatabaseHolder::get(opCtx); - const TenantDatabaseName fcvTenantDbName(boost::none, fcvColl->ns().db()); - databaseHolder->openDb(opCtx, fcvTenantDbName); + databaseHolder->openDb(opCtx, fcvColl->ns().dbName()); fassertNoTrace(4805000, repair::repairCollection( opCtx, storageEngine, NamespaceString::kServerConfigurationNamespace)); @@ -489,21 +487,20 @@ void startupRepair(OperationContext* opCtx, StorageEngine* storageEngine) { // The local database should be repaired before any other replicated collections so we know // whether not to rebuild unfinished two-phase index builds if this is a replica set node // running in standalone mode. - auto tenantDbNames = storageEngine->listDatabases(); - if (auto it = std::find(tenantDbNames.begin(), - tenantDbNames.end(), - TenantDatabaseName(boost::none, NamespaceString::kLocalDb)); - it != tenantDbNames.end()) { + auto dbNames = storageEngine->listDatabases(); + if (auto it = std::find( + dbNames.begin(), dbNames.end(), DatabaseName(boost::none, NamespaceString::kLocalDb)); + it != dbNames.end()) { fassertNoTrace(4805001, repair::repairDatabase(opCtx, storageEngine, *it)); // This must be set before rebuilding index builds on replicated collections. setReplSetMemberInStandaloneMode(opCtx, StartupRecoveryMode::kAuto); - tenantDbNames.erase(it); + dbNames.erase(it); } // Repair the remaining databases. - for (const auto& tenantDbName : tenantDbNames) { - fassertNoTrace(18506, repair::repairDatabase(opCtx, storageEngine, tenantDbName)); + for (const auto& dbName : dbNames) { + fassertNoTrace(18506, repair::repairDatabase(opCtx, storageEngine, dbName)); } openDatabases(opCtx, storageEngine, [&](auto db) { @@ -568,7 +565,7 @@ void startupRecovery(OperationContext* opCtx, !(hasReplSetConfigDoc(opCtx) || usingReplication); openDatabases(opCtx, storageEngine, [&](auto db) { - auto dbName = db->name().dbName(); + auto dbString = db->name().db(); // Ensures all collections meet requirements such as having _id indexes, and corrects them // if needed. @@ -579,12 +576,12 @@ void startupRecovery(OperationContext* opCtx, db->checkForIdIndexesAndDropPendingCollections(opCtx); // Ensure oplog is capped (mongodb does not guarantee order of inserts on noncapped // collections) - if (dbName == NamespaceString::kLocalDb) { + if (dbString == NamespaceString::kLocalDb) { assertCappedOplog(opCtx, db); } } - if (shouldClearNonLocalTmpCollections || dbName == NamespaceString::kLocalDb) { + if (shouldClearNonLocalTmpCollections || dbString == NamespaceString::kLocalDb) { db->clearTmpCollections(opCtx); } }); diff --git a/src/mongo/db/storage/storage_engine.h b/src/mongo/db/storage/storage_engine.h index 313dcb8c439..03be00aa626 100644 --- a/src/mongo/db/storage/storage_engine.h +++ b/src/mongo/db/storage/storage_engine.h @@ -37,9 +37,9 @@ #include "mongo/bson/bsonobj.h" #include "mongo/bson/timestamp.h" #include "mongo/db/catalog/index_builds.h" +#include "mongo/db/database_name.h" #include "mongo/db/resumable_index_builds_gen.h" #include "mongo/db/storage/temporary_record_store.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/util/functional.h" #include "mongo/util/str.h" @@ -199,7 +199,7 @@ public: /** * List the databases stored in this storage engine. */ - virtual std::vector<TenantDatabaseName> listDatabases() const = 0; + virtual std::vector<DatabaseName> listDatabases() const = 0; /** * Returns whether the storage engine supports capped collections. @@ -232,14 +232,12 @@ public: /** * Closes all file handles associated with a database. */ - virtual Status closeDatabase(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) = 0; + virtual Status closeDatabase(OperationContext* opCtx, const DatabaseName& dbName) = 0; /** * Deletes all data and metadata for a database. */ - virtual Status dropDatabase(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) = 0; + virtual Status dropDatabase(OperationContext* opCtx, const DatabaseName& dbName) = 0; /** * Checkpoints the data to disk. @@ -623,10 +621,9 @@ public: /** * Returns the path to the directory which has the data files of database with `dbName`. */ - virtual std::string getFilesystemPathForDb(const TenantDatabaseName& tenantDbName) const = 0; + virtual std::string getFilesystemPathForDb(const DatabaseName& dbName) const = 0; - virtual int64_t sizeOnDiskForDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) = 0; + virtual int64_t sizeOnDiskForDb(OperationContext* opCtx, const DatabaseName& dbName) = 0; virtual bool isUsingDirectoryPerDb() const = 0; diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp index c55aacfe066..f866314229b 100644 --- a/src/mongo/db/storage/storage_engine_impl.cpp +++ b/src/mongo/db/storage/storage_engine_impl.cpp @@ -773,9 +773,8 @@ StatusWith<StorageEngine::ReconcileResult> StorageEngineImpl::reconcileCatalogAn return reconcileResult; } -std::string StorageEngineImpl::getFilesystemPathForDb( - const TenantDatabaseName& tenantDbName) const { - return _catalog->getFilesystemPathForDb(tenantDbName.dbName()); +std::string StorageEngineImpl::getFilesystemPathForDb(const DatabaseName& dbName) const { + return _catalog->getFilesystemPathForDb(dbName.toString()); } void StorageEngineImpl::cleanShutdown() { @@ -821,27 +820,25 @@ RecoveryUnit* StorageEngineImpl::newRecoveryUnit() { return _engine->newRecoveryUnit(); } -std::vector<TenantDatabaseName> StorageEngineImpl::listDatabases() const { +std::vector<DatabaseName> StorageEngineImpl::listDatabases() const { return CollectionCatalog::get(getGlobalServiceContext())->getAllDbNames(); } -Status StorageEngineImpl::closeDatabase(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) { +Status StorageEngineImpl::closeDatabase(OperationContext* opCtx, const DatabaseName& dbName) { // This is ok to be a no-op as there is no database layer in kv. return Status::OK(); } -Status StorageEngineImpl::dropDatabase(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) { +Status StorageEngineImpl::dropDatabase(OperationContext* opCtx, const DatabaseName& dbName) { auto catalog = CollectionCatalog::get(opCtx); { - auto tenantDbNames = catalog->getAllDbNames(); - if (std::count(tenantDbNames.begin(), tenantDbNames.end(), tenantDbName) == 0) { + auto dbNames = catalog->getAllDbNames(); + if (std::count(dbNames.begin(), dbNames.end(), dbName) == 0) { return Status(ErrorCodes::NamespaceNotFound, "db not found to drop"); } } - std::vector<UUID> toDrop = catalog->getAllCollectionUUIDsFromDb(tenantDbName); + std::vector<UUID> toDrop = catalog->getAllCollectionUUIDsFromDb(dbName); // Do not timestamp any of the following writes. This will remove entries from the catalog as // well as drop any underlying tables. It's not expected for dropping tables to be reversible @@ -1303,8 +1300,7 @@ void StorageEngineImpl::TimestampMonitor::clearListeners() { _listeners.clear(); } -int64_t StorageEngineImpl::sizeOnDiskForDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) { +int64_t StorageEngineImpl::sizeOnDiskForDb(OperationContext* opCtx, const DatabaseName& dbName) { int64_t size = 0; auto perCollectionWork = [&](const CollectionPtr& collection) { @@ -1320,13 +1316,12 @@ int64_t StorageEngineImpl::sizeOnDiskForDb(OperationContext* opCtx, if (opCtx->isLockFreeReadsOp()) { auto collectionCatalog = CollectionCatalog::get(opCtx); - for (auto it = collectionCatalog->begin(opCtx, tenantDbName); - it != collectionCatalog->end(opCtx); + for (auto it = collectionCatalog->begin(opCtx, dbName); it != collectionCatalog->end(opCtx); ++it) { perCollectionWork(*it); } } else { - catalog::forEachCollectionFromDb(opCtx, tenantDbName, MODE_IS, perCollectionWork); + catalog::forEachCollectionFromDb(opCtx, dbName, MODE_IS, perCollectionWork); }; return size; diff --git a/src/mongo/db/storage/storage_engine_impl.h b/src/mongo/db/storage/storage_engine_impl.h index a8e36a1af88..6d9e308402a 100644 --- a/src/mongo/db/storage/storage_engine_impl.h +++ b/src/mongo/db/storage/storage_engine_impl.h @@ -73,17 +73,15 @@ public: virtual RecoveryUnit* newRecoveryUnit() override; - virtual std::vector<TenantDatabaseName> listDatabases() const override; + virtual std::vector<DatabaseName> listDatabases() const override; virtual bool supportsCappedCollections() const override { return _supportsCappedCollections; } - virtual Status closeDatabase(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) override; + virtual Status closeDatabase(OperationContext* opCtx, const DatabaseName& dbName) override; - virtual Status dropDatabase(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) override; + virtual Status dropDatabase(OperationContext* opCtx, const DatabaseName& dbName) override; virtual void flushAllFiles(OperationContext* opCtx, bool callerHoldsReadLock) override; @@ -326,7 +324,7 @@ public: StatusWith<ReconcileResult> reconcileCatalogAndIdents( OperationContext* opCtx, LastShutdownState lastShutdownState) override; - std::string getFilesystemPathForDb(const TenantDatabaseName& tenantDbName) const override; + std::string getFilesystemPathForDb(const DatabaseName& dbName) const override; DurableCatalog* getCatalog() override; @@ -347,8 +345,7 @@ public: return _dropPendingIdentReaper.getAllIdentNames(); } - int64_t sizeOnDiskForDb(OperationContext* opCtx, - const TenantDatabaseName& tenantDbName) override; + int64_t sizeOnDiskForDb(OperationContext* opCtx, const DatabaseName& dbName) override; bool isUsingDirectoryPerDb() const override { return _options.directoryPerDB; diff --git a/src/mongo/db/storage/storage_engine_mock.h b/src/mongo/db/storage/storage_engine_mock.h index d39b8b248f3..0591fbca9ad 100644 --- a/src/mongo/db/storage/storage_engine_mock.h +++ b/src/mongo/db/storage/storage_engine_mock.h @@ -41,7 +41,7 @@ public: RecoveryUnit* newRecoveryUnit() final { return nullptr; } - std::vector<TenantDatabaseName> listDatabases() const final { + std::vector<DatabaseName> listDatabases() const final { return {}; } bool supportsCappedCollections() const final { @@ -55,10 +55,10 @@ public: } void loadCatalog(OperationContext* opCtx, LastShutdownState lastShutdownState) final {} void closeCatalog(OperationContext* opCtx) final {} - Status closeDatabase(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) final { + Status closeDatabase(OperationContext* opCtx, const DatabaseName& dbName) final { return Status::OK(); } - Status dropDatabase(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) final { + Status dropDatabase(OperationContext* opCtx, const DatabaseName& dbName) final { return Status::OK(); } void flushAllFiles(OperationContext* opCtx, bool callerHoldsReadLock) final {} @@ -162,7 +162,7 @@ public: boost::optional<Timestamp> getOplogNeededForCrashRecovery() const final { return boost::none; } - std::string getFilesystemPathForDb(const TenantDatabaseName& tenantDbName) const final { + std::string getFilesystemPathForDb(const DatabaseName& dbName) const final { return ""; } std::set<std::string> getDropPendingIdents() const final { @@ -175,7 +175,7 @@ public: void checkpoint() final {} - int64_t sizeOnDiskForDb(OperationContext* opCtx, const TenantDatabaseName& tenantDbName) final { + int64_t sizeOnDiskForDb(OperationContext* opCtx, const DatabaseName& dbName) final { return 0; } bool isUsingDirectoryPerDb() const final { diff --git a/src/mongo/db/storage/storage_util.cpp b/src/mongo/db/storage/storage_util.cpp index cdc8a43e5c9..0c4f6944ea6 100644 --- a/src/mongo/db/storage/storage_util.cpp +++ b/src/mongo/db/storage/storage_util.cpp @@ -49,40 +49,39 @@ namespace mongo { namespace catalog { namespace { -auto removeEmptyDirectory = [](ServiceContext* svcCtx, - StorageEngine* storageEngine, - const NamespaceString& ns) { - // Nothing to do if not using directoryperdb or there are still collections in the database. - // If we don't support supportsPendingDrops then this is executing before the collection is - // removed from the catalog. In that case, just blindly attempt to delete the directory, it - // will only succeed if it is empty which is the behavior we want. - auto collectionCatalog = CollectionCatalog::get(svcCtx); - const TenantDatabaseName tenantDbName(boost::none, ns.db()); - if (!storageEngine->isUsingDirectoryPerDb() || - (storageEngine->supportsPendingDrops() && - collectionCatalog->begin(nullptr, tenantDbName) != collectionCatalog->end(nullptr))) { - return; - } +auto removeEmptyDirectory = + [](ServiceContext* svcCtx, StorageEngine* storageEngine, const NamespaceString& ns) { + // Nothing to do if not using directoryperdb or there are still collections in the database. + // If we don't support supportsPendingDrops then this is executing before the collection is + // removed from the catalog. In that case, just blindly attempt to delete the directory, it + // will only succeed if it is empty which is the behavior we want. + auto collectionCatalog = CollectionCatalog::get(svcCtx); + const DatabaseName& dbName = ns.dbName(); + if (!storageEngine->isUsingDirectoryPerDb() || + (storageEngine->supportsPendingDrops() && + collectionCatalog->begin(nullptr, dbName) != collectionCatalog->end(nullptr))) { + return; + } - boost::system::error_code ec; - boost::filesystem::remove(storageEngine->getFilesystemPathForDb(tenantDbName), ec); - - if (!ec) { - LOGV2(4888200, "Removed empty database directory", "db"_attr = tenantDbName.dbName()); - } else if (collectionCatalog->begin(nullptr, tenantDbName) == collectionCatalog->end(nullptr)) { - // It is possible for a new collection to be created in the database between when we - // check whether the database is empty and actually attempting to remove the directory. - // In this case, don't log that the removal failed because it is expected. However, - // since we attempt to remove the directory for both the collection and index ident - // drops, once the database is empty it will be still logged until the final of these - // ident drops occurs. - LOGV2_DEBUG(4888201, - 1, - "Failed to remove database directory", - "db"_attr = tenantDbName.dbName(), - "error"_attr = ec.message()); - } -}; + boost::system::error_code ec; + boost::filesystem::remove(storageEngine->getFilesystemPathForDb(dbName), ec); + + if (!ec) { + LOGV2(4888200, "Removed empty database directory", "db"_attr = dbName.toString()); + } else if (collectionCatalog->begin(nullptr, dbName) == collectionCatalog->end(nullptr)) { + // It is possible for a new collection to be created in the database between when we + // check whether the database is empty and actually attempting to remove the directory. + // In this case, don't log that the removal failed because it is expected. However, + // since we attempt to remove the directory for both the collection and index ident + // drops, once the database is empty it will be still logged until the final of these + // ident drops occurs. + LOGV2_DEBUG(4888201, + 1, + "Failed to remove database directory", + "db"_attr = dbName.toString(), + "error"_attr = ec.message()); + } + }; } // namespace void removeIndex(OperationContext* opCtx, diff --git a/src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp b/src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp index ebf99113d74..9457b60e1ba 100644 --- a/src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp +++ b/src/mongo/db/storage/wiredtiger/oplog_stones_server_status_section.cpp @@ -32,9 +32,9 @@ #include "mongo/db/catalog/database_holder.h" #include "mongo/db/commands/server_status.h" +#include "mongo/db/database_name.h" #include "mongo/db/db_raii.h" #include "mongo/db/namespace_string.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/logv2/log.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kFTDC diff --git a/src/mongo/db/tenant_database_name_test.cpp b/src/mongo/db/tenant_database_name_test.cpp index dcf967402e0..15ed7f9cd14 100644 --- a/src/mongo/db/tenant_database_name_test.cpp +++ b/src/mongo/db/tenant_database_name_test.cpp @@ -27,8 +27,8 @@ * it in the license file. */ +#include "mongo/db/database_name.h" #include "mongo/db/server_feature_flags_gen.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/idl/server_parameter_test_util.h" #include "mongo/unittest/death_test.h" #include "mongo/unittest/unittest.h" @@ -36,118 +36,118 @@ namespace mongo { namespace { -TEST(TenantDatabaseNameTest, MultitenancySupportDisabled) { - TenantDatabaseName tdnWithoutTenant1(boost::none, "a"); +TEST(DatabaseNameTest, MultitenancySupportDisabled) { + DatabaseName dbnWithoutTenant1(boost::none, "a"); - ASSERT(!tdnWithoutTenant1.tenantId()); - ASSERT_EQUALS(std::string("a"), tdnWithoutTenant1.dbName()); - ASSERT_EQUALS(std::string("a"), tdnWithoutTenant1.fullName()); + ASSERT(!dbnWithoutTenant1.tenantId()); + ASSERT_EQUALS(std::string("a"), dbnWithoutTenant1.db()); + ASSERT_EQUALS(std::string("a"), dbnWithoutTenant1.toString()); TenantId tenantId(OID::gen()); - TenantDatabaseName tdnWithTenant(tenantId, "a"); - ASSERT(tdnWithTenant.tenantId()); - ASSERT_EQUALS(tenantId, *tdnWithTenant.tenantId()); - ASSERT_EQUALS(std::string("a"), tdnWithTenant.dbName()); - ASSERT_EQUALS(std::string(tenantId.toString() + "_a"), tdnWithTenant.fullName()); + DatabaseName dbnWithTenant(tenantId, "a"); + ASSERT(dbnWithTenant.tenantId()); + ASSERT_EQUALS(tenantId, *dbnWithTenant.tenantId()); + ASSERT_EQUALS(std::string("a"), dbnWithTenant.db()); + ASSERT_EQUALS(std::string(tenantId.toString() + "_a"), dbnWithTenant.toString()); } -TEST(TenantDatabaseNameTest, MultitenancySupportEnabledTenantIDNotRequired) { +TEST(DatabaseNameTest, MultitenancySupportEnabledTenantIDNotRequired) { // TODO SERVER-62114 remove this test case. RAIIServerParameterControllerForTest multitenanyController("multitenancySupport", true); - TenantDatabaseName tdnWithoutTenant(boost::none, "a"); - ASSERT(!tdnWithoutTenant.tenantId()); - ASSERT_EQUALS(std::string("a"), tdnWithoutTenant.dbName()); - ASSERT_EQUALS(std::string("a"), tdnWithoutTenant.fullName()); + DatabaseName dbnWithoutTenant(boost::none, "a"); + ASSERT(!dbnWithoutTenant.tenantId()); + ASSERT_EQUALS(std::string("a"), dbnWithoutTenant.db()); + ASSERT_EQUALS(std::string("a"), dbnWithoutTenant.toString()); TenantId tenantId(OID::gen()); - TenantDatabaseName tdnWithTenant(tenantId, "a"); - ASSERT(tdnWithTenant.tenantId()); - ASSERT_EQUALS(tenantId, *tdnWithTenant.tenantId()); - ASSERT_EQUALS(std::string("a"), tdnWithTenant.dbName()); - ASSERT_EQUALS(std::string(tenantId.toString() + "_a"), tdnWithTenant.fullName()); + DatabaseName dbnWithTenant(tenantId, "a"); + ASSERT(dbnWithTenant.tenantId()); + ASSERT_EQUALS(tenantId, *dbnWithTenant.tenantId()); + ASSERT_EQUALS(std::string("a"), dbnWithTenant.db()); + ASSERT_EQUALS(std::string(tenantId.toString() + "_a"), dbnWithTenant.toString()); } /* // TODO SERVER-65457 Re-enable these tests -DEATH_TEST(TenantDatabaseNameTest, TenantIDRequiredNoTenantIdAssigned, "invariant") { +DEATH_TEST(DatabaseNameTest, TenantIDRequiredNoTenantIdAssigned, "invariant") { RAIIServerParameterControllerForTest multitenanyController("multitenancySupport", true); - TenantDatabaseName tdnWithoutTenant(boost::none, "a"); + DatabaseName dbnWithoutTenant(boost::none, "a"); } -TEST(TenantDatabaseNameTest, TenantIDRequiredBasic) { +TEST(DatabaseNameTest, TenantIDRequiredBasic) { RAIIServerParameterControllerForTest multitenanyController("multitenancySupport", true); // TODO SERVER-62114 Remove enabling this feature flag. RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); TenantId tenantId(OID::gen()); - TenantDatabaseName tdn(tenantId, "a"); - ASSERT(tdn.tenantId()); - ASSERT_EQUALS(tenantId, *tdn.tenantId()); - ASSERT_EQUALS(std::string("a"), tdn.dbName()); - ASSERT_EQUALS(std::string(tenantId.toString() + "_a"), tdn.fullName()); + DatabaseName dbn(tenantId, "a"); + ASSERT(dbn.tenantId()); + ASSERT_EQUALS(tenantId, *dbn.tenantId()); + ASSERT_EQUALS(std::string("a"), dbn.db()); + ASSERT_EQUALS(std::string(tenantId.toString() + "_a"), dbn.toString()); } */ -TEST(TenantDatabaseNameTest, VerifyEqualsOperator) { +TEST(DatabaseNameTest, VerifyEqualsOperator) { TenantId tenantId(OID::gen()); - TenantDatabaseName tdn(tenantId, "a"); - ASSERT_TRUE(TenantDatabaseName(tenantId, "a") == tdn); - ASSERT_TRUE(TenantDatabaseName(tenantId, "b") != tdn); + DatabaseName dbn(tenantId, "a"); + ASSERT_TRUE(DatabaseName(tenantId, "a") == dbn); + ASSERT_TRUE(DatabaseName(tenantId, "b") != dbn); TenantId otherTenantId = TenantId(OID::gen()); - ASSERT_TRUE(TenantDatabaseName(otherTenantId, "a") != tdn); - ASSERT_TRUE(TenantDatabaseName(boost::none, "a") != tdn); + ASSERT_TRUE(DatabaseName(otherTenantId, "a") != dbn); + ASSERT_TRUE(DatabaseName(boost::none, "a") != dbn); } -TEST(TenantDatabaseNameTest, VerifyHashFunction) { +TEST(DatabaseNameTest, VerifyHashFunction) { TenantId tenantId1(OID::gen()); TenantId tenantId2(OID::gen()); - TenantDatabaseName tdn1 = TenantDatabaseName(tenantId1, "a"); - TenantDatabaseName tdn2 = TenantDatabaseName(tenantId2, "a"); - TenantDatabaseName tdn3 = TenantDatabaseName(boost::none, "a"); + DatabaseName dbn1 = DatabaseName(tenantId1, "a"); + DatabaseName dbn2 = DatabaseName(tenantId2, "a"); + DatabaseName dbn3 = DatabaseName(boost::none, "a"); - stdx::unordered_map<TenantDatabaseName, std::string> dbMap; + stdx::unordered_map<DatabaseName, std::string> dbMap; - dbMap[tdn1] = "value T1 a1"; - ASSERT_EQUALS(dbMap[tdn1], "value T1 a1"); - dbMap[tdn1] = "value T1 a2"; - ASSERT_EQUALS(dbMap[tdn1], "value T1 a2"); - dbMap[TenantDatabaseName(tenantId1, "a")] = "value T1 a3"; - ASSERT_EQUALS(dbMap[tdn1], "value T1 a3"); + dbMap[dbn1] = "value T1 a1"; + ASSERT_EQUALS(dbMap[dbn1], "value T1 a1"); + dbMap[dbn1] = "value T1 a2"; + ASSERT_EQUALS(dbMap[dbn1], "value T1 a2"); + dbMap[DatabaseName(tenantId1, "a")] = "value T1 a3"; + ASSERT_EQUALS(dbMap[dbn1], "value T1 a3"); - dbMap[tdn2] = "value T2 a1"; - ASSERT_EQUALS(dbMap[tdn2], "value T2 a1"); - dbMap[tdn2] = "value T2 a2"; + dbMap[dbn2] = "value T2 a1"; + ASSERT_EQUALS(dbMap[dbn2], "value T2 a1"); + dbMap[dbn2] = "value T2 a2"; - dbMap[tdn3] = "value no tenant a1"; - ASSERT_EQUALS(dbMap[tdn3], "value no tenant a1"); - dbMap[tdn3] = "value no tenant a2"; + dbMap[dbn3] = "value no tenant a1"; + ASSERT_EQUALS(dbMap[dbn3], "value no tenant a1"); + dbMap[dbn3] = "value no tenant a2"; // verify all key-value in map to ensure all data is correct. - ASSERT_EQUALS(dbMap[tdn1], "value T1 a3"); - ASSERT_EQUALS(dbMap[tdn2], "value T2 a2"); - ASSERT_EQUALS(dbMap[tdn3], "value no tenant a2"); + ASSERT_EQUALS(dbMap[dbn1], "value T1 a3"); + ASSERT_EQUALS(dbMap[dbn2], "value T2 a2"); + ASSERT_EQUALS(dbMap[dbn3], "value no tenant a2"); } -TEST(TenantDatabaseNameTest, VerifyCompareFunction) { +TEST(DatabaseNameTest, VerifyCompareFunction) { TenantId tenantId1 = TenantId(OID::gen()); TenantId tenantId2 = TenantId(OID::gen()); // OID's generated by the same process are monotonically increasing. ASSERT(tenantId1 < tenantId2); - TenantDatabaseName tdn1a = TenantDatabaseName(tenantId1, "a"); - TenantDatabaseName tdn1b = TenantDatabaseName(tenantId1, "b"); - TenantDatabaseName tdn2a = TenantDatabaseName(tenantId2, "a"); - TenantDatabaseName tdn3a = TenantDatabaseName(boost::none, "a"); + DatabaseName dbn1a = DatabaseName(tenantId1, "a"); + DatabaseName dbn1b = DatabaseName(tenantId1, "b"); + DatabaseName dbn2a = DatabaseName(tenantId2, "a"); + DatabaseName dbn3a = DatabaseName(boost::none, "a"); - ASSERT(tdn1a < tdn1b); - ASSERT(tdn1b < tdn2a); - ASSERT(tdn3a != tdn1a); - ASSERT(tdn1a != tdn2a); + ASSERT(dbn1a < dbn1b); + ASSERT(dbn1b < dbn2a); + ASSERT(dbn3a != dbn1a); + ASSERT(dbn1a != dbn2a); } } // namespace } // namespace mongo diff --git a/src/mongo/db/transaction_history_iterator.cpp b/src/mongo/db/transaction_history_iterator.cpp index 5de4a6c90ae..a58db70e5f1 100644 --- a/src/mongo/db/transaction_history_iterator.cpp +++ b/src/mongo/db/transaction_history_iterator.cpp @@ -76,8 +76,8 @@ BSONObj findOneOplogEntry(OperationContext* opCtx, std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue()); AutoGetOplog oplogRead(opCtx, OplogAccessMode::kRead); - const TenantDatabaseName tenantDbName(boost::none, NamespaceString::kLocalDb); - const auto localDb = DatabaseHolder::get(opCtx)->getDb(opCtx, tenantDbName); + const DatabaseName dbName(boost::none, NamespaceString::kLocalDb); + const auto localDb = DatabaseHolder::get(opCtx)->getDb(opCtx, dbName); invariant(localDb); AutoStatsTracker statsTracker( opCtx, diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp index f84c4c6fe2d..14a8a7a3add 100644 --- a/src/mongo/db/transaction_participant.cpp +++ b/src/mongo/db/transaction_participant.cpp @@ -555,9 +555,8 @@ TransactionParticipant::getOldestActiveTimestamp(Timestamp stableTimestamp) { Lock::DBLock dbLock(opCtx.get(), nss.db(), MODE_IS, deadline); Lock::CollectionLock collLock(opCtx.get(), nss, MODE_IS, deadline); - const TenantDatabaseName tenantDbName(boost::none, nss.db()); auto databaseHolder = DatabaseHolder::get(opCtx.get()); - auto db = databaseHolder->getDb(opCtx.get(), tenantDbName); + auto db = databaseHolder->getDb(opCtx.get(), nss.dbName()); if (!db) { // There is no config database, so there cannot be any active transactions. return boost::none; diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index 9466314572f..b879181d885 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -318,13 +318,13 @@ private: nullptr != (mtab = TenantMigrationAccessBlockerRegistry::get(opCtx->getServiceContext()) .getTenantMigrationAccessBlockerForDbName( - coll.getDb()->name().fullName(), MtabType::kRecipient)) && + coll.getDb()->name().toString(), MtabType::kRecipient)) && mtab->checkIfShouldBlockTTL()) { LOGV2_DEBUG(53768, 1, "Postpone TTL of DB because of active tenant migration", "tenantMigrationAccessBlocker"_attr = mtab->getDebugInfo().jsonString(), - "database"_attr = coll.getDb()->name().dbName()); + "database"_attr = coll.getDb()->name().toString()); return; } diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp index 53d79de9893..361505220b8 100644 --- a/src/mongo/db/views/durable_view_catalog.cpp +++ b/src/mongo/db/views/durable_view_catalog.cpp @@ -41,11 +41,11 @@ #include "mongo/db/catalog/database_holder.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/curop.h" +#include "mongo/db/database_name.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" #include "mongo/db/storage/record_data.h" -#include "mongo/db/tenant_database_name.h" #include "mongo/db/views/view_catalog_helpers.h" #include "mongo/logv2/log.h" #include "mongo/stdx/unordered_set.h" @@ -78,7 +78,7 @@ void validateViewDefinitionBSON(OperationContext* opCtx, // be valid. If not valid then the NamespaceString constructor will uassert. if (viewNameIsValid) { NamespaceString viewNss(viewName); - valid &= viewNss.isValid() && viewNss.db() == dbName; + valid &= viewNss.isValid() && viewNss.dbName().db() == dbName; } valid &= NamespaceString::validCollectionName(viewDefinition["viewOn"].str()); @@ -115,7 +115,7 @@ void DurableViewCatalog::onExternalChange(OperationContext* opCtx, const Namespa // is reloaded. This will prevent any further usage of the views for this database until the // invalid view definitions are removed. auto catalog = CollectionCatalog::get(opCtx); - catalog->reloadViews(opCtx, TenantDatabaseName(boost::none, name.db())).ignore(); + catalog->reloadViews(opCtx, name.dbName()).ignore(); } Status DurableViewCatalog::onExternalInsert(OperationContext* opCtx, @@ -153,7 +153,7 @@ void DurableViewCatalog::onSystemViewsCollectionDrop(OperationContext* opCtx, dassert(name.coll() == NamespaceString::kSystemDotViewsCollectionName); auto catalog = CollectionCatalog::get(opCtx); - const TenantDatabaseName dbName(boost::none, name.db()); + const DatabaseName& dbName = name.dbName(); // First, iterate through the views on this database and audit them before they are dropped. catalog->iterateViews(opCtx, @@ -176,7 +176,7 @@ void DurableViewCatalog::onSystemViewsCollectionDrop(OperationContext* opCtx, // DurableViewCatalogImpl const std::string& DurableViewCatalogImpl::getName() const { - return _db->name().dbName(); + return _db->name().toString(); } void DurableViewCatalogImpl::iterate(OperationContext* opCtx, Callback callback) { @@ -220,16 +220,15 @@ BSONObj DurableViewCatalogImpl::_validateViewDefinition(OperationContext* opCtx, // decimal data even if decimal is disabled. fassert(40224, validateBSON(recordData.data(), recordData.size())); BSONObj viewDefinition = recordData.toBson(); - std::string dbName(_db->name().dbName()); - validateViewDefinitionBSON(opCtx, viewDefinition, dbName); + validateViewDefinitionBSON(opCtx, viewDefinition, _db->name().db()); return viewDefinition; } void DurableViewCatalogImpl::upsert(OperationContext* opCtx, const NamespaceString& name, const BSONObj& view) { - dassert(opCtx->lockState()->isDbLockedForMode(_db->name().dbName(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(_db->name().db(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(name, MODE_IX)); NamespaceString systemViewsNs(_db->getSystemViewsName()); @@ -262,7 +261,7 @@ void DurableViewCatalogImpl::upsert(OperationContext* opCtx, } void DurableViewCatalogImpl::remove(OperationContext* opCtx, const NamespaceString& name) { - dassert(opCtx->lockState()->isDbLockedForMode(_db->name().dbName(), MODE_IX)); + dassert(opCtx->lockState()->isDbLockedForMode(_db->name().db(), MODE_IX)); dassert(opCtx->lockState()->isCollectionLockedForMode(name, MODE_IX)); CollectionPtr systemViews = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace( diff --git a/src/mongo/db/views/view_catalog_test.cpp b/src/mongo/db/views/view_catalog_test.cpp index dd787101a80..1a3bfb33fb4 100644 --- a/src/mongo/db/views/view_catalog_test.cpp +++ b/src/mongo/db/views/view_catalog_test.cpp @@ -650,7 +650,7 @@ TEST_F(ViewCatalogFixture, Iterate) { Lock::DBLock dbLock(operationContext(), "db", MODE_IX); getCatalog()->iterateViews(operationContext(), - TenantDatabaseName(boost::none, "db"), + DatabaseName(boost::none, "db"), [&viewNames](const ViewDefinition& view) { std::string name = view.name().toString(); ASSERT(viewNames.end() != viewNames.find(name)); |