diff options
author | Geert Bosch <geert@mongodb.com> | 2019-04-29 14:11:12 -0400 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2019-05-07 13:17:24 -0400 |
commit | ab689c15777a5c2f7d35f602d125fdc7f2fb344c (patch) | |
tree | f10a2d6bfad8cc009e722ed366e635dfecbb7ee1 /src/mongo/db/catalog | |
parent | 042f4e1f2164f3a801acfd379fafc217817b392c (diff) | |
download | mongo-ab689c15777a5c2f7d35f602d125fdc7f2fb344c.tar.gz |
SERVER-40892 Rename UUIDCatalog to CollectionCatalog
Diffstat (limited to 'src/mongo/db/catalog')
22 files changed, 255 insertions, 234 deletions
diff --git a/src/mongo/db/catalog/SConscript b/src/mongo/db/catalog/SConscript index 31857fcec6b..bf49127cdab 100644 --- a/src/mongo/db/catalog/SConscript +++ b/src/mongo/db/catalog/SConscript @@ -307,13 +307,12 @@ env.CppUnitTest( ) env.Library( - target='uuid_catalog', + target='collection_catalog', source=[ - 'uuid_catalog.cpp', + 'collection_catalog.cpp', ], LIBDEPS=[ 'collection', - 'database_holder', '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/db/namespace_string', '$BUILD_DIR/mongo/db/service_context', @@ -324,23 +323,23 @@ env.Library( ) env.Library( - target='uuid_catalog_helper', + target='collection_catalog_helper', source=[ - 'uuid_catalog_helper.cpp', + 'collection_catalog_helper.cpp', ], LIBDEPS_PRIVATE=[ - 'uuid_catalog', + 'collection_catalog', '$BUILD_DIR/mongo/db/concurrency/lock_manager', ] ) env.CppUnitTest( - target='uuid_catalog_test', + target='collection_catalog_test', source=[ - 'uuid_catalog_test.cpp', + 'collection_catalog_test.cpp', ], LIBDEPS=[ - 'uuid_catalog', + 'collection_catalog', '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/storage/kv/kv_prefix', ], @@ -353,7 +352,8 @@ env.Library( ], LIBDEPS_PRIVATE=[ 'collection', - 'uuid_catalog', + 'collection_catalog', + 'database_holder', '$BUILD_DIR/mongo/db/index_builds_coordinator_interface', '$BUILD_DIR/mongo/db/repair_database', '$BUILD_DIR/mongo/db/service_context', @@ -415,7 +415,7 @@ env.Library( '$BUILD_DIR/mongo/db/views/views_mongod', ], LIBDEPS_PRIVATE=[ - '$BUILD_DIR/mongo/db/catalog/uuid_catalog_helper', + '$BUILD_DIR/mongo/db/catalog/collection_catalog_helper', '$BUILD_DIR/mongo/db/commands/server_status_core', '$BUILD_DIR/mongo/db/index/index_build_interceptor', '$BUILD_DIR/mongo/db/logical_clock', @@ -452,6 +452,9 @@ env.Library( 'index_key_validate', 'multi_index_block', ], + LIBDEPS_PRIVATE=[ + 'database_holder', + ], ) env.CppUnitTest( @@ -478,7 +481,7 @@ env.CppUnitTest( ], LIBDEPS=[ 'catalog_helpers', - 'uuid_catalog', + 'collection_catalog', '$BUILD_DIR/mongo/db/auth/authmocks', '$BUILD_DIR/mongo/db/db_raii', '$BUILD_DIR/mongo/db/namespace_string', @@ -496,6 +499,7 @@ env.CppUnitTest( ], LIBDEPS=[ 'catalog_helpers', + 'database_holder', '$BUILD_DIR/mongo/db/auth/authmocks', '$BUILD_DIR/mongo/db/db_raii', '$BUILD_DIR/mongo/db/namespace_string', @@ -516,6 +520,7 @@ env.CppUnitTest( ], LIBDEPS=[ 'catalog_helpers', + 'database_holder', '$BUILD_DIR/mongo/db/auth/authmocks', '$BUILD_DIR/mongo/db/db_raii', '$BUILD_DIR/mongo/db/namespace_string', diff --git a/src/mongo/db/catalog/catalog_control.cpp b/src/mongo/db/catalog/catalog_control.cpp index 4e91be65a5b..92e9ec691da 100644 --- a/src/mongo/db/catalog/catalog_control.cpp +++ b/src/mongo/db/catalog/catalog_control.cpp @@ -36,9 +36,9 @@ #include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/ftdc/ftdc_mongod.h" #include "mongo/db/index_builds_coordinator.h" #include "mongo/db/namespace_string.h" @@ -79,14 +79,15 @@ MinVisibleTimestampMap closeCatalog(OperationContext* opCtx) { } } - // Need to mark the UUIDCatalog as open if we our closeAll fails, dismissed if successful. - auto reopenOnFailure = makeGuard([opCtx] { UUIDCatalog::get(opCtx).onOpenCatalog(opCtx); }); - // Closing UUID Catalog: only lookupNSSByUUID will fall back to using pre-closing state to + // Need to mark the CollectionCatalog as open if we our closeAll fails, dismissed if successful. + auto reopenOnFailure = + makeGuard([opCtx] { CollectionCatalog::get(opCtx).onOpenCatalog(opCtx); }); + // Closing CollectionCatalog: only lookupNSSByUUID will fall back to using pre-closing state to // allow authorization for currently unknown UUIDs. This is needed because authorization needs // to work before acquiring locks, and might otherwise spuriously regard a UUID as unknown // while reloading the catalog. - UUIDCatalog::get(opCtx).onCloseCatalog(opCtx); - LOG(1) << "closeCatalog: closing UUID catalog"; + CollectionCatalog::get(opCtx).onCloseCatalog(opCtx); + LOG(1) << "closeCatalog: closing collection catalog"; // Close all databases. log() << "closeCatalog: closing all databases"; @@ -120,7 +121,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib auto indexName = indexNamespace.second; auto collCatalogEntry = - UUIDCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(collNss); + CollectionCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(collNss); invariant(collCatalogEntry, str::stream() << "couldn't get collection catalog entry for collection " << collNss.toString()); @@ -155,7 +156,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib NamespaceString collNss(entry.first); auto collCatalogEntry = - UUIDCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(collNss); + CollectionCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(collNss); invariant(collCatalogEntry, str::stream() << "couldn't get collection catalog entry for collection " << collNss.toString()); @@ -169,7 +170,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib fassert(40690, rebuildIndexesOnCollection(opCtx, collCatalogEntry, indexSpecs)); } - // Open all databases and repopulate the UUID catalog. + // Open all databases and repopulate the CollectionCatalog. log() << "openCatalog: reopening all databases"; auto databaseHolder = DatabaseHolder::get(opCtx); std::vector<std::string> databasesToOpen = storageEngine->listDatabases(); @@ -177,7 +178,8 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib LOG_FOR_RECOVERY(1) << "openCatalog: dbholder reopening database " << dbName; auto db = databaseHolder->openDb(opCtx, dbName); invariant(db, str::stream() << "failed to reopen database " << dbName); - for (auto&& collNss : UUIDCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, dbName)) { + for (auto&& collNss : + CollectionCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, dbName)) { // Note that the collection name already includes the database component. auto collection = db->getCollection(opCtx, collNss); invariant(collection, @@ -199,10 +201,10 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib } } } - // Opening UUID Catalog: The UUID catalog is now in sync with the storage engine catalog. Clear - // the pre-closing state. - UUIDCatalog::get(opCtx).onOpenCatalog(opCtx); - log() << "openCatalog: finished reloading UUID catalog"; + // Opening CollectionCatalog: The collection catalog is now in sync with the storage engine + // catalog. Clear the pre-closing state. + CollectionCatalog::get(opCtx).onOpenCatalog(opCtx); + log() << "openCatalog: finished reloading collection catalog"; } } // namespace catalog } // namespace mongo diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index bf0c62380c5..5f081288ea9 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -527,7 +527,7 @@ void updateUniqueIndexesOnUpgrade(OperationContext* opCtx) { std::vector<std::string> dbNames; { Lock::GlobalLock lk(opCtx, MODE_IS); - dbNames = UUIDCatalog::get(opCtx).getAllDbNames(); + dbNames = CollectionCatalog::get(opCtx).getAllDbNames(); } for (auto it = dbNames.begin(); it != dbNames.end(); ++it) { @@ -561,7 +561,7 @@ Status updateNonReplicatedUniqueIndexes(OperationContext* opCtx) { std::vector<std::string> dbNames; { Lock::GlobalLock lk(opCtx, MODE_IS); - dbNames = UUIDCatalog::get(opCtx).getAllDbNames(); + dbNames = CollectionCatalog::get(opCtx).getAllDbNames(); } for (auto it = dbNames.begin(); it != dbNames.end(); ++it) { auto dbName = *it; diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h index 39cb24a20d7..37b8c25a988 100644 --- a/src/mongo/db/catalog/collection.h +++ b/src/mongo/db/catalog/collection.h @@ -183,8 +183,8 @@ public: * Sets a new namespace on this Collection, in the case that the Collection is being renamed. * In general, reads and writes to Collection objects are synchronized using locks from the lock * manager. However, there is special synchronization for ns() and setNs() so that the - * UUIDCatalog can perform UUID to namespace lookup without holding a Collection lock. See - * UUIDCatalog::setCollectionNamespace(). + * CollectionCatalog can perform UUID to namespace lookup without holding a Collection lock. See + * CollectionCatalog::setCollectionNamespace(). */ virtual void setNs(NamespaceString nss) = 0; diff --git a/src/mongo/db/catalog/uuid_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp index f8edcc77a77..1bfb90dba4e 100644 --- a/src/mongo/db/catalog/uuid_catalog.cpp +++ b/src/mongo/db/catalog/collection_catalog.cpp @@ -30,10 +30,9 @@ #include "mongo/platform/basic.h" -#include "uuid_catalog.h" +#include "collection_catalog.h" #include "mongo/db/catalog/database.h" -#include "mongo/db/catalog/database_holder.h" #include "mongo/db/concurrency/lock_manager_defs.h" #include "mongo/db/storage/recovery_unit.h" #include "mongo/util/assert_util.h" @@ -42,13 +41,15 @@ namespace mongo { namespace { -const ServiceContext::Decoration<UUIDCatalog> getCatalog = - ServiceContext::declareDecoration<UUIDCatalog>(); +const ServiceContext::Decoration<CollectionCatalog> getCatalog = + ServiceContext::declareDecoration<CollectionCatalog>(); } // namespace -class UUIDCatalog::FinishDropChange : public RecoveryUnit::Change { +class CollectionCatalog::FinishDropChange : public RecoveryUnit::Change { public: - FinishDropChange(UUIDCatalog& catalog, std::unique_ptr<Collection> coll, CollectionUUID uuid) + FinishDropChange(CollectionCatalog& catalog, + std::unique_ptr<Collection> coll, + CollectionUUID uuid) : _catalog(catalog), _coll(std::move(coll)), _uuid(uuid) {} void commit(boost::optional<Timestamp>) override { @@ -60,35 +61,37 @@ public: } private: - UUIDCatalog& _catalog; + CollectionCatalog& _catalog; std::unique_ptr<Collection> _coll; CollectionUUID _uuid; }; -UUIDCatalog::iterator::iterator(StringData dbName, uint64_t genNum, const UUIDCatalog& uuidCatalog) - : _dbName(dbName), _genNum(genNum), _uuidCatalog(&uuidCatalog) { +CollectionCatalog::iterator::iterator(StringData dbName, + uint64_t genNum, + const CollectionCatalog& catalog) + : _dbName(dbName), _genNum(genNum), _catalog(&catalog) { auto minUuid = UUID::parse("00000000-0000-0000-0000-000000000000").getValue(); - stdx::lock_guard<stdx::mutex> lock(_uuidCatalog->_catalogLock); - _mapIter = _uuidCatalog->_orderedCollections.lower_bound(std::make_pair(_dbName, minUuid)); + stdx::lock_guard<stdx::mutex> lock(_catalog->_catalogLock); + _mapIter = _catalog->_orderedCollections.lower_bound(std::make_pair(_dbName, minUuid)); // The entry _mapIter points to is valid if it's not at the end of _orderedCollections and // the entry's database is the same as dbName. - while (_mapIter != _uuidCatalog->_orderedCollections.end() && - _mapIter->first.first == _dbName && _mapIter->second->collectionPtr == nullptr) { + while (_mapIter != _catalog->_orderedCollections.end() && _mapIter->first.first == _dbName && + _mapIter->second->collectionPtr == nullptr) { _mapIter++; } - if (_mapIter != _uuidCatalog->_orderedCollections.end() && _mapIter->first.first == _dbName) { + if (_mapIter != _catalog->_orderedCollections.end() && _mapIter->first.first == _dbName) { _uuid = _mapIter->first.second; } } -UUIDCatalog::iterator::iterator( +CollectionCatalog::iterator::iterator( std::map<std::pair<std::string, CollectionUUID>, CollectionInfo*>::const_iterator mapIter) : _mapIter(mapIter) {} -UUIDCatalog::iterator::pointer UUIDCatalog::iterator::operator->() { - stdx::lock_guard<stdx::mutex> lock(_uuidCatalog->_catalogLock); +CollectionCatalog::iterator::pointer CollectionCatalog::iterator::operator->() { + stdx::lock_guard<stdx::mutex> lock(_catalog->_catalogLock); _repositionIfNeeded(); if (_exhausted()) { return nullptr; @@ -97,8 +100,8 @@ UUIDCatalog::iterator::pointer UUIDCatalog::iterator::operator->() { return &_mapIter->second->collectionPtr; } -UUIDCatalog::iterator::reference UUIDCatalog::iterator::operator*() { - stdx::lock_guard<stdx::mutex> lock(_uuidCatalog->_catalogLock); +CollectionCatalog::iterator::reference CollectionCatalog::iterator::operator*() { + stdx::lock_guard<stdx::mutex> lock(_catalog->_catalogLock); _repositionIfNeeded(); if (_exhausted()) { return _nullCollection; @@ -107,12 +110,12 @@ UUIDCatalog::iterator::reference UUIDCatalog::iterator::operator*() { return _mapIter->second->collectionPtr; } -boost::optional<CollectionUUID> UUIDCatalog::iterator::uuid() { +boost::optional<CollectionUUID> CollectionCatalog::iterator::uuid() { return _uuid; } -UUIDCatalog::iterator UUIDCatalog::iterator::operator++() { - stdx::lock_guard<stdx::mutex> lock(_uuidCatalog->_catalogLock); +CollectionCatalog::iterator CollectionCatalog::iterator::operator++() { + stdx::lock_guard<stdx::mutex> lock(_catalog->_catalogLock); // Skip over CollectionInfo that has CatalogEntry but has no Collection object. do { @@ -123,7 +126,7 @@ UUIDCatalog::iterator UUIDCatalog::iterator::operator++() { if (_exhausted()) { // If the iterator is at the end of the map or now points to an entry that does not // correspond to the correct database. - _mapIter = _uuidCatalog->_orderedCollections.end(); + _mapIter = _catalog->_orderedCollections.end(); _uuid = boost::none; return *this; } @@ -133,34 +136,34 @@ UUIDCatalog::iterator UUIDCatalog::iterator::operator++() { return *this; } -UUIDCatalog::iterator UUIDCatalog::iterator::operator++(int) { +CollectionCatalog::iterator CollectionCatalog::iterator::operator++(int) { auto oldPosition = *this; ++(*this); return oldPosition; } -bool UUIDCatalog::iterator::operator==(const iterator& other) { - stdx::lock_guard<stdx::mutex> lock(_uuidCatalog->_catalogLock); +bool CollectionCatalog::iterator::operator==(const iterator& other) { + stdx::lock_guard<stdx::mutex> lock(_catalog->_catalogLock); - if (other._mapIter == _uuidCatalog->_orderedCollections.end()) { + if (other._mapIter == _catalog->_orderedCollections.end()) { return _uuid == boost::none; } return _uuid == other._uuid; } -bool UUIDCatalog::iterator::operator!=(const iterator& other) { +bool CollectionCatalog::iterator::operator!=(const iterator& other) { return !(*this == other); } -bool UUIDCatalog::iterator::_repositionIfNeeded() { - if (_genNum == _uuidCatalog->_generationNumber) { +bool CollectionCatalog::iterator::_repositionIfNeeded() { + if (_genNum == _catalog->_generationNumber) { return false; } - _genNum = _uuidCatalog->_generationNumber; + _genNum = _catalog->_generationNumber; // If the map has been modified, find the entry the iterator was on, or the one right after it. - _mapIter = _uuidCatalog->_orderedCollections.lower_bound(std::make_pair(_dbName, *_uuid)); + _mapIter = _catalog->_orderedCollections.lower_bound(std::make_pair(_dbName, *_uuid)); // It is possible that the collection object is gone while catalog entry is // still in the map. Skip that type of entries. @@ -182,41 +185,41 @@ bool UUIDCatalog::iterator::_repositionIfNeeded() { return repositioned; } -bool UUIDCatalog::iterator::_exhausted() { - return _mapIter == _uuidCatalog->_orderedCollections.end() || _mapIter->first.first != _dbName; +bool CollectionCatalog::iterator::_exhausted() { + return _mapIter == _catalog->_orderedCollections.end() || _mapIter->first.first != _dbName; } -UUIDCatalog& UUIDCatalog::get(ServiceContext* svcCtx) { +CollectionCatalog& CollectionCatalog::get(ServiceContext* svcCtx) { return getCatalog(svcCtx); } -UUIDCatalog& UUIDCatalog::get(OperationContext* opCtx) { +CollectionCatalog& CollectionCatalog::get(OperationContext* opCtx) { return getCatalog(opCtx->getServiceContext()); } -void UUIDCatalog::onCreateCollection(OperationContext* opCtx, - std::unique_ptr<Collection> coll, - CollectionUUID uuid) { +void CollectionCatalog::onCreateCollection(OperationContext* opCtx, + std::unique_ptr<Collection> coll, + CollectionUUID uuid) { registerCollectionObject(uuid, std::move(coll)); opCtx->recoveryUnit()->onRollback([this, uuid] { deregisterCollectionObject(uuid); }); } -void UUIDCatalog::onDropCollection(OperationContext* opCtx, CollectionUUID uuid) { +void CollectionCatalog::onDropCollection(OperationContext* opCtx, CollectionUUID uuid) { auto coll = deregisterCollectionObject(uuid); opCtx->recoveryUnit()->registerChange(new FinishDropChange(*this, std::move(coll), uuid)); } -void UUIDCatalog::setCollectionNamespace(OperationContext* opCtx, - Collection* coll, - const NamespaceString& fromCollection, - const NamespaceString& toCollection) { - // Rather than maintain, in addition to the UUID -> Collection* mapping, an auxiliary data - // structure with the UUID -> namespace mapping, the UUIDCatalog relies on Collection::ns() to - // provide UUID to namespace lookup. In addition, the UUIDCatalog does not require callers to - // hold locks. +void CollectionCatalog::setCollectionNamespace(OperationContext* opCtx, + Collection* coll, + const NamespaceString& fromCollection, + const NamespaceString& toCollection) { + // Rather than maintain, in addition to the UUID -> Collection* mapping, an auxiliary + // data structure with the UUID -> namespace mapping, the CollectionCatalog relies on + // Collection::ns() to provide UUID to namespace lookup. In addition, the CollectionCatalog + // does not require callers to hold locks. // - // This means that Collection::ns() may be called while only '_catalogLock' (and no lock manager - // locks) are held. The purpose of this function is ensure that we write to the Collection's - // namespace string under '_catalogLock'. + // This means that Collection::ns() may be called while only '_catalogLock' (and no lock + // manager locks) are held. The purpose of this function is ensure that we write to the + // Collection's namespace string under '_catalogLock'. invariant(coll); stdx::lock_guard<stdx::mutex> lock(_catalogLock); CollectionCatalogEntry* catalogEntry = @@ -250,17 +253,17 @@ void UUIDCatalog::setCollectionNamespace(OperationContext* opCtx, }); } -void UUIDCatalog::onCloseDatabase(OperationContext* opCtx, Database* db) { +void CollectionCatalog::onCloseDatabase(OperationContext* opCtx, std::string dbName) { invariant(opCtx->lockState()->isW()); - for (auto it = begin(db->name()); it != end(); ++it) { + for (auto it = begin(dbName); it != end(); ++it) { deregisterCollectionObject(it.uuid().get()); } - auto rid = ResourceId(RESOURCE_DATABASE, db->name()); - removeResource(rid, db->name()); + auto rid = ResourceId(RESOURCE_DATABASE, dbName); + removeResource(rid, dbName); } -void UUIDCatalog::onCloseCatalog(OperationContext* opCtx) { +void CollectionCatalog::onCloseCatalog(OperationContext* opCtx) { invariant(opCtx->lockState()->isW()); stdx::lock_guard<stdx::mutex> lock(_catalogLock); invariant(!_shadowCatalog); @@ -269,14 +272,14 @@ void UUIDCatalog::onCloseCatalog(OperationContext* opCtx) { _shadowCatalog->insert({entry.first, entry.second.collection->ns()}); } -void UUIDCatalog::onOpenCatalog(OperationContext* opCtx) { +void CollectionCatalog::onOpenCatalog(OperationContext* opCtx) { invariant(opCtx->lockState()->isW()); stdx::lock_guard<stdx::mutex> lock(_catalogLock); invariant(_shadowCatalog); _shadowCatalog.reset(); } -Collection* UUIDCatalog::lookupCollectionByUUID(CollectionUUID uuid) const { +Collection* CollectionCatalog::lookupCollectionByUUID(CollectionUUID uuid) const { stdx::lock_guard<stdx::mutex> lock(_catalogLock); auto foundIt = _catalog.find(uuid); return foundIt == _catalog.end() || foundIt->second.collectionPtr == nullptr @@ -284,7 +287,7 @@ Collection* UUIDCatalog::lookupCollectionByUUID(CollectionUUID uuid) const { : foundIt->second.collection.get(); } -Collection* UUIDCatalog::lookupCollectionByNamespace(const NamespaceString& nss) const { +Collection* CollectionCatalog::lookupCollectionByNamespace(const NamespaceString& nss) const { stdx::lock_guard<stdx::mutex> lock(_catalogLock); auto it = _collections.find(nss); return it == _collections.end() || it->second->collectionPtr == nullptr @@ -292,20 +295,21 @@ Collection* UUIDCatalog::lookupCollectionByNamespace(const NamespaceString& nss) : it->second->collection.get(); } -CollectionCatalogEntry* UUIDCatalog::lookupCollectionCatalogEntryByUUID(CollectionUUID uuid) const { +CollectionCatalogEntry* CollectionCatalog::lookupCollectionCatalogEntryByUUID( + CollectionUUID uuid) const { stdx::lock_guard<stdx::mutex> lock(_catalogLock); auto foundIt = _catalog.find(uuid); return foundIt == _catalog.end() ? nullptr : foundIt->second.collectionCatalogEntry.get(); } -CollectionCatalogEntry* UUIDCatalog::lookupCollectionCatalogEntryByNamespace( +CollectionCatalogEntry* CollectionCatalog::lookupCollectionCatalogEntryByNamespace( const NamespaceString& nss) const { stdx::lock_guard<stdx::mutex> lock(_catalogLock); auto it = _collections.find(nss); return it == _collections.end() ? nullptr : it->second->collectionCatalogEntry.get(); } -boost::optional<NamespaceString> UUIDCatalog::lookupNSSByUUID(CollectionUUID uuid) const { +boost::optional<NamespaceString> CollectionCatalog::lookupNSSByUUID(CollectionUUID uuid) const { stdx::lock_guard<stdx::mutex> lock(_catalogLock); auto foundIt = _catalog.find(uuid); if (foundIt != _catalog.end()) { @@ -325,7 +329,8 @@ boost::optional<NamespaceString> UUIDCatalog::lookupNSSByUUID(CollectionUUID uui return boost::none; } -boost::optional<CollectionUUID> UUIDCatalog::lookupUUIDByNSS(const NamespaceString& nss) const { +boost::optional<CollectionUUID> CollectionCatalog::lookupUUIDByNSS( + const NamespaceString& nss) const { stdx::lock_guard<stdx::mutex> lock(_catalogLock); auto minUuid = UUID::parse("00000000-0000-0000-0000-000000000000").getValue(); auto it = _orderedCollections.lower_bound(std::make_pair(nss.db().toString(), minUuid)); @@ -341,7 +346,8 @@ boost::optional<CollectionUUID> UUIDCatalog::lookupUUIDByNSS(const NamespaceStri return boost::none; } -std::vector<CollectionUUID> UUIDCatalog::getAllCollectionUUIDsFromDb(StringData dbName) const { +std::vector<CollectionUUID> CollectionCatalog::getAllCollectionUUIDsFromDb( + StringData dbName) const { stdx::lock_guard<stdx::mutex> lock(_catalogLock); auto minUuid = UUID::parse("00000000-0000-0000-0000-000000000000").getValue(); auto it = _orderedCollections.lower_bound(std::make_pair(dbName.toString(), minUuid)); @@ -354,8 +360,8 @@ std::vector<CollectionUUID> UUIDCatalog::getAllCollectionUUIDsFromDb(StringData return ret; } -std::vector<NamespaceString> UUIDCatalog::getAllCollectionNamesFromDb(OperationContext* opCtx, - StringData dbName) const { +std::vector<NamespaceString> CollectionCatalog::getAllCollectionNamesFromDb( + OperationContext* opCtx, StringData dbName) const { invariant(opCtx->lockState()->isDbLockedForMode(dbName, MODE_S)); stdx::lock_guard<stdx::mutex> lock(_catalogLock); @@ -370,7 +376,7 @@ std::vector<NamespaceString> UUIDCatalog::getAllCollectionNamesFromDb(OperationC return ret; } -std::vector<std::string> UUIDCatalog::getAllDbNames() const { +std::vector<std::string> CollectionCatalog::getAllDbNames() const { std::vector<std::string> ret; stdx::lock_guard<stdx::mutex> lock(_catalogLock); auto maxUuid = UUID::parse("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF").getValue(); @@ -383,7 +389,7 @@ std::vector<std::string> UUIDCatalog::getAllDbNames() const { return ret; } -void UUIDCatalog::registerCatalogEntry( +void CollectionCatalog::registerCatalogEntry( CollectionUUID uuid, std::unique_ptr<CollectionCatalogEntry> collectionCatalogEntry) { stdx::lock_guard<stdx::mutex> lock(_catalogLock); @@ -407,7 +413,8 @@ void UUIDCatalog::registerCatalogEntry( _orderedCollections[dbIdPair] = &_catalog[uuid]; } -void UUIDCatalog::registerCollectionObject(CollectionUUID uuid, std::unique_ptr<Collection> coll) { +void CollectionCatalog::registerCollectionObject(CollectionUUID uuid, + std::unique_ptr<Collection> coll) { stdx::lock_guard<stdx::mutex> lock(_catalogLock); LOG(0) << "Registering collection object " << coll->ns() << " with UUID " << uuid; @@ -440,7 +447,7 @@ void UUIDCatalog::registerCollectionObject(CollectionUUID uuid, std::unique_ptr< addResource(collRid, ns.ns()); } -std::unique_ptr<Collection> UUIDCatalog::deregisterCollectionObject(CollectionUUID uuid) { +std::unique_ptr<Collection> CollectionCatalog::deregisterCollectionObject(CollectionUUID uuid) { stdx::lock_guard<stdx::mutex> lock(_catalogLock); invariant(_catalog.find(uuid) != _catalog.end()); @@ -473,7 +480,8 @@ std::unique_ptr<Collection> UUIDCatalog::deregisterCollectionObject(CollectionUU return coll; } -std::unique_ptr<CollectionCatalogEntry> UUIDCatalog::deregisterCatalogEntry(CollectionUUID uuid) { +std::unique_ptr<CollectionCatalogEntry> CollectionCatalog::deregisterCatalogEntry( + CollectionUUID uuid) { stdx::lock_guard<stdx::mutex> lock(_catalogLock); invariant(_catalog.find(uuid) != _catalog.end()); @@ -505,7 +513,7 @@ std::unique_ptr<CollectionCatalogEntry> UUIDCatalog::deregisterCatalogEntry(Coll return catalogEntry; } -void UUIDCatalog::deregisterAllCatalogEntriesAndCollectionObjects() { +void CollectionCatalog::deregisterAllCatalogEntriesAndCollectionObjects() { stdx::lock_guard<stdx::mutex> lock(_catalogLock); LOG(0) << "Deregistering all the catalog entries and collection objects"; @@ -531,15 +539,15 @@ void UUIDCatalog::deregisterAllCatalogEntriesAndCollectionObjects() { _generationNumber++; } -UUIDCatalog::iterator UUIDCatalog::begin(StringData db) const { +CollectionCatalog::iterator CollectionCatalog::begin(StringData db) const { return iterator(db, _generationNumber, *this); } -UUIDCatalog::iterator UUIDCatalog::end() const { +CollectionCatalog::iterator CollectionCatalog::end() const { return iterator(_orderedCollections.end()); } -boost::optional<std::string> UUIDCatalog::lookupResourceName(const ResourceId& rid) { +boost::optional<std::string> CollectionCatalog::lookupResourceName(const ResourceId& rid) { invariant(rid.getType() == RESOURCE_DATABASE || rid.getType() == RESOURCE_COLLECTION); stdx::lock_guard<stdx::mutex> lock(_resourceLock); @@ -559,7 +567,7 @@ boost::optional<std::string> UUIDCatalog::lookupResourceName(const ResourceId& r return *namespaces.begin(); } -void UUIDCatalog::removeResource(const ResourceId& rid, const std::string& entry) { +void CollectionCatalog::removeResource(const ResourceId& rid, const std::string& entry) { invariant(rid.getType() == RESOURCE_DATABASE || rid.getType() == RESOURCE_COLLECTION); stdx::lock_guard<stdx::mutex> lock(_resourceLock); @@ -577,7 +585,7 @@ void UUIDCatalog::removeResource(const ResourceId& rid, const std::string& entry } } -void UUIDCatalog::addResource(const ResourceId& rid, const std::string& entry) { +void CollectionCatalog::addResource(const ResourceId& rid, const std::string& entry) { invariant(rid.getType() == RESOURCE_DATABASE || rid.getType() == RESOURCE_COLLECTION); stdx::lock_guard<stdx::mutex> lock(_resourceLock); diff --git a/src/mongo/db/catalog/uuid_catalog.h b/src/mongo/db/catalog/collection_catalog.h index 33d36b34780..8a7dcaae650 100644 --- a/src/mongo/db/catalog/uuid_catalog.h +++ b/src/mongo/db/catalog/collection_catalog.h @@ -29,12 +29,12 @@ #pragma once +#include <map> #include <set> #include <unordered_map> #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/collection_catalog_entry.h" -#include "mongo/db/op_observer.h" #include "mongo/db/service_context.h" #include "mongo/stdx/functional.h" #include "mongo/util/uuid.h" @@ -48,9 +48,9 @@ namespace mongo { using CollectionUUID = UUID; class Database; -class UUIDCatalog { - UUIDCatalog(const UUIDCatalog&) = delete; - UUIDCatalog& operator=(const UUIDCatalog&) = delete; +class CollectionCatalog { + CollectionCatalog(const CollectionCatalog&) = delete; + CollectionCatalog& operator=(const CollectionCatalog&) = delete; friend class iterator; struct CollectionInfo; @@ -62,9 +62,9 @@ public: using pointer = const value_type*; using reference = const value_type&; - iterator(StringData dbName, uint64_t genNum, const UUIDCatalog& uuidCatalog); + iterator(StringData dbName, uint64_t genNum, const CollectionCatalog& catalog); iterator(std::map<std::pair<std::string, CollectionUUID>, - UUIDCatalog::CollectionInfo*>::const_iterator mapIter); + CollectionCatalog::CollectionInfo*>::const_iterator mapIter); pointer operator->(); reference operator*(); iterator operator++(); @@ -94,16 +94,16 @@ public: boost::optional<CollectionUUID> _uuid; uint64_t _genNum; std::map<std::pair<std::string, CollectionUUID>, CollectionInfo*>::const_iterator _mapIter; - const UUIDCatalog* _uuidCatalog; + const CollectionCatalog* _catalog; static constexpr Collection* _nullCollection = nullptr; }; - static UUIDCatalog& get(ServiceContext* svcCtx); - static UUIDCatalog& get(OperationContext* opCtx); - UUIDCatalog() = default; + static CollectionCatalog& get(ServiceContext* svcCtx); + static CollectionCatalog& get(OperationContext* opCtx); + CollectionCatalog() = default; /** - * This function inserts the entry for uuid, coll into the UUID Collection. It is called by + * This function inserts the entry for uuid, coll into the collection catalog. It is called by * the op observer when a collection is created. */ void onCreateCollection(OperationContext* opCtx, @@ -111,7 +111,7 @@ public: CollectionUUID uuid); /** - * This function removes the entry for uuid from the UUID catalog. It is called by the op + * This function removes the entry for uuid from the collection catalog. It is called by the op * observer when a collection is dropped. */ void onDropCollection(OperationContext* opCtx, CollectionUUID uuid); @@ -131,11 +131,11 @@ public: /** * Implies onDropCollection for all collections in db, but is not transactional. */ - void onCloseDatabase(OperationContext* opCtx, Database* db); + void onCloseDatabase(OperationContext* opCtx, std::string dbName); /** * Register the collection catalog entry with `uuid`. The collection object with `uuid` must not - * exist in the UUIDCatalog yet. + * exist in the CollectionCatalog yet. */ void registerCatalogEntry(CollectionUUID uuid, std::unique_ptr<CollectionCatalogEntry> collectionCatalogEntry); @@ -148,7 +148,7 @@ public: /** * Register the collection object with `uuid`. The collection catalog entry with `uuid` already - * exists in the UUIDCatalog. + * exists in the CollectionCatalog. */ void registerCollectionObject(CollectionUUID uuid, std::unique_ptr<Collection> coll); @@ -211,7 +211,7 @@ public: boost::optional<NamespaceString> lookupNSSByUUID(CollectionUUID uuid) const; /** - * Returns the UUID if `nss` exists in UUIDCatalog. The time complexity of + * Returns the UUID if `nss` exists in CollectionCatalog. The time complexity of * this function is linear to the number of collections in `nss.db()`. */ boost::optional<CollectionUUID> lookupUUIDByNSS(const NamespaceString& nss) const; @@ -282,7 +282,7 @@ public: private: class FinishDropChange; - friend class UUIDCatalog::iterator; + friend class CollectionCatalog::iterator; const std::vector<CollectionUUID>& _getOrdering_inlock(const StringData& db, const stdx::lock_guard<stdx::mutex>&); diff --git a/src/mongo/db/catalog/uuid_catalog_helper.cpp b/src/mongo/db/catalog/collection_catalog_helper.cpp index 5bbc2bf6618..34b6ce992e1 100644 --- a/src/mongo/db/catalog/uuid_catalog_helper.cpp +++ b/src/mongo/db/catalog/collection_catalog_helper.cpp @@ -27,8 +27,9 @@ * it in the license file. */ -#include "mongo/db/catalog/uuid_catalog_helper.h" +#include "mongo/db/catalog/collection_catalog_helper.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/concurrency/d_concurrency.h" @@ -41,11 +42,10 @@ void forEachCollectionFromDb( LockMode collLockMode, std::function<bool(Collection* collection, CollectionCatalogEntry* catalogEntry)> callback) { - UUIDCatalog& uuidCatalog = UUIDCatalog::get(opCtx); - for (auto collectionIt = uuidCatalog.begin(dbName); collectionIt != uuidCatalog.end(); - ++collectionIt) { + CollectionCatalog& catalog = CollectionCatalog::get(opCtx); + for (auto collectionIt = catalog.begin(dbName); collectionIt != catalog.end(); ++collectionIt) { auto uuid = collectionIt.uuid().get(); - auto nss = uuidCatalog.lookupNSSByUUID(uuid); + auto nss = catalog.lookupNSSByUUID(uuid); // If the NamespaceString can't be resolved from the uuid, then the collection was dropped. if (!nss) { @@ -54,8 +54,8 @@ void forEachCollectionFromDb( Lock::CollectionLock clk(opCtx, *nss, collLockMode); - auto collection = uuidCatalog.lookupCollectionByUUID(uuid); - auto catalogEntry = uuidCatalog.lookupCollectionCatalogEntryByUUID(uuid); + auto collection = catalog.lookupCollectionByUUID(uuid); + auto catalogEntry = catalog.lookupCollectionCatalogEntryByUUID(uuid); if (!collection || !catalogEntry || catalogEntry->ns() != *nss) continue; diff --git a/src/mongo/db/catalog/uuid_catalog_helper.h b/src/mongo/db/catalog/collection_catalog_helper.h index 0530618b102..50df494842e 100644 --- a/src/mongo/db/catalog/uuid_catalog_helper.h +++ b/src/mongo/db/catalog/collection_catalog_helper.h @@ -29,8 +29,8 @@ #pragma once -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/concurrency/lock_manager_defs.h" +#include "mongo/db/operation_context.h" namespace mongo { diff --git a/src/mongo/db/catalog/uuid_catalog_test.cpp b/src/mongo/db/catalog/collection_catalog_test.cpp index 34542ae9e91..7a4f96fd2f5 100644 --- a/src/mongo/db/catalog/uuid_catalog_test.cpp +++ b/src/mongo/db/catalog/collection_catalog_test.cpp @@ -26,7 +26,7 @@ * exception statement from all source files in the program, then also delete * it in the license file. */ -#include "mongo/db/catalog/uuid_catalog.h" +#include "mongo/db/catalog/collection_catalog.h" #include <algorithm> #include <boost/optional/optional_io.hpp> @@ -41,11 +41,11 @@ using namespace mongo; /** - * A test fixture that creates a UUID Catalog and Collection* pointer to store in it. + * A test fixture that creates a CollectionCatalog and Collection* pointer to store in it. */ -class UUIDCatalogTest : public unittest::Test { +class CollectionCatalogTest : public unittest::Test { public: - UUIDCatalogTest() + CollectionCatalogTest() : nss("testdb", "testcol"), col(nullptr), colUUID(CollectionUUID::gen()), @@ -69,7 +69,7 @@ public: } protected: - UUIDCatalog catalog; + CollectionCatalog catalog; OperationContextNoop opCtx; NamespaceString nss; CollectionMock* col; @@ -78,7 +78,7 @@ protected: CollectionUUID prevUUID; }; -class UUIDCatalogIterationTest : public unittest::Test { +class CollectionCatalogIterationTest : public unittest::Test { public: void setUp() { for (int counter = 0; counter < 5; ++counter) { @@ -144,12 +144,12 @@ public: } protected: - UUIDCatalog catalog; + CollectionCatalog catalog; OperationContextNoop opCtx; std::map<std::string, std::map<CollectionUUID, CollectionMock*>> dbMap; }; -class UUIDCatalogResourceMapTest : public unittest::Test { +class CollectionCatalogResourceMapTest : public unittest::Test { public: void setUp() { // The first and second collection namespaces map to the same ResourceId. @@ -175,10 +175,10 @@ protected: std::string thirdCollection; ResourceId thirdResourceId; - UUIDCatalog catalog; + CollectionCatalog catalog; }; -TEST_F(UUIDCatalogResourceMapTest, EmptyTest) { +TEST_F(CollectionCatalogResourceMapTest, EmptyTest) { boost::optional<std::string> resource = catalog.lookupResourceName(firstResourceId); ASSERT_EQ(boost::none, resource); @@ -187,7 +187,7 @@ TEST_F(UUIDCatalogResourceMapTest, EmptyTest) { ASSERT_EQ(boost::none, resource); } -TEST_F(UUIDCatalogResourceMapTest, InsertTest) { +TEST_F(CollectionCatalogResourceMapTest, InsertTest) { catalog.addResource(firstResourceId, firstCollection); boost::optional<std::string> resource = catalog.lookupResourceName(thirdResourceId); ASSERT_EQ(boost::none, resource); @@ -201,7 +201,7 @@ TEST_F(UUIDCatalogResourceMapTest, InsertTest) { ASSERT_EQ(thirdCollection, resource); } -TEST_F(UUIDCatalogResourceMapTest, RemoveTest) { +TEST_F(CollectionCatalogResourceMapTest, RemoveTest) { catalog.addResource(firstResourceId, firstCollection); catalog.addResource(thirdResourceId, thirdCollection); @@ -221,7 +221,7 @@ TEST_F(UUIDCatalogResourceMapTest, RemoveTest) { ASSERT_EQ(boost::none, resource); } -TEST_F(UUIDCatalogResourceMapTest, CollisionTest) { +TEST_F(CollectionCatalogResourceMapTest, CollisionTest) { // firstCollection and secondCollection map to the same ResourceId. catalog.addResource(firstResourceId, firstCollection); catalog.addResource(secondResourceId, secondCollection); @@ -267,7 +267,7 @@ TEST_F(UUIDCatalogResourceMapTest, CollisionTest) { ASSERT_EQ(boost::none, resource); } -class UUIDCatalogResourceTest : public unittest::Test { +class CollectionCatalogResourceTest : public unittest::Test { public: void setUp() { for (int i = 0; i < 5; i++) { @@ -313,12 +313,12 @@ public: protected: OperationContextNoop opCtx; - UUIDCatalog catalog; + CollectionCatalog catalog; }; namespace { -TEST_F(UUIDCatalogResourceTest, RemoveAllResources) { +TEST_F(CollectionCatalogResourceTest, RemoveAllResources) { catalog.deregisterAllCatalogEntriesAndCollectionObjects(); const std::string dbName = "resourceDb"; @@ -332,7 +332,7 @@ TEST_F(UUIDCatalogResourceTest, RemoveAllResources) { } } -TEST_F(UUIDCatalogResourceTest, LookupDatabaseResource) { +TEST_F(CollectionCatalogResourceTest, LookupDatabaseResource) { const std::string dbName = "resourceDb"; auto rid = ResourceId(RESOURCE_DATABASE, dbName); boost::optional<std::string> ridStr = catalog.lookupResourceName(rid); @@ -341,13 +341,13 @@ TEST_F(UUIDCatalogResourceTest, LookupDatabaseResource) { ASSERT(ridStr->find(dbName) != std::string::npos); } -TEST_F(UUIDCatalogResourceTest, LookupMissingDatabaseResource) { +TEST_F(CollectionCatalogResourceTest, LookupMissingDatabaseResource) { const std::string dbName = "missingDb"; auto rid = ResourceId(RESOURCE_DATABASE, dbName); ASSERT(!catalog.lookupResourceName(rid)); } -TEST_F(UUIDCatalogResourceTest, LookupCollectionResource) { +TEST_F(CollectionCatalogResourceTest, LookupCollectionResource) { const std::string collNs = "resourceDb.coll1"; auto rid = ResourceId(RESOURCE_COLLECTION, collNs); boost::optional<std::string> ridStr = catalog.lookupResourceName(rid); @@ -356,13 +356,13 @@ TEST_F(UUIDCatalogResourceTest, LookupCollectionResource) { ASSERT(ridStr->find(collNs) != std::string::npos); } -TEST_F(UUIDCatalogResourceTest, LookupMissingCollectionResource) { +TEST_F(CollectionCatalogResourceTest, LookupMissingCollectionResource) { const std::string dbName = "resourceDb.coll5"; auto rid = ResourceId(RESOURCE_COLLECTION, dbName); ASSERT(!catalog.lookupResourceName(rid)); } -TEST_F(UUIDCatalogResourceTest, RemoveCollection) { +TEST_F(CollectionCatalogResourceTest, RemoveCollection) { const std::string collNs = "resourceDb.coll1"; auto coll = catalog.lookupCollectionByNamespace(NamespaceString(collNs)); auto uniqueColl = catalog.deregisterCollectionObject(coll->uuid().get()); @@ -371,20 +371,21 @@ TEST_F(UUIDCatalogResourceTest, RemoveCollection) { ASSERT(!catalog.lookupResourceName(rid)); } -// Create an iterator over the UUIDCatalog and assert that all collections are present. +// 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(UUIDCatalogIterationTest, EndAtEndOfCatalog) { +TEST_F(CollectionCatalogIterationTest, EndAtEndOfCatalog) { checkCollections("foo"); } -// Create an iterator over the UUIDCatalog and test that all collections are present. Iteration ends +// 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(UUIDCatalogIterationTest, EndAtEndOfSection) { +TEST_F(CollectionCatalogIterationTest, EndAtEndOfSection) { checkCollections("bar"); } // Delete an entry in the catalog while iterating. -TEST_F(UUIDCatalogIterationTest, InvalidateEntry) { +TEST_F(CollectionCatalogIterationTest, InvalidateEntry) { auto it = catalog.begin("bar"); // Invalidate bar.coll1. @@ -404,7 +405,7 @@ TEST_F(UUIDCatalogIterationTest, InvalidateEntry) { } // Delete the entry pointed to by the iterator and dereference the iterator. -TEST_F(UUIDCatalogIterationTest, InvalidateAndDereference) { +TEST_F(CollectionCatalogIterationTest, InvalidateAndDereference) { auto it = catalog.begin("bar"); auto collsIt = collsIterator("bar"); auto uuid = collsIt->first; @@ -420,7 +421,7 @@ TEST_F(UUIDCatalogIterationTest, InvalidateAndDereference) { } // Delete the last entry for a database while pointing to it and dereference the iterator. -TEST_F(UUIDCatalogIterationTest, InvalidateLastEntryAndDereference) { +TEST_F(CollectionCatalogIterationTest, InvalidateLastEntryAndDereference) { auto it = catalog.begin("bar"); NamespaceString lastNs; boost::optional<CollectionUUID> uuid; @@ -444,7 +445,7 @@ TEST_F(UUIDCatalogIterationTest, InvalidateLastEntryAndDereference) { } // Delete the last entry in the map while pointing to it and dereference the iterator. -TEST_F(UUIDCatalogIterationTest, InvalidateLastEntryInMapAndDereference) { +TEST_F(CollectionCatalogIterationTest, InvalidateLastEntryInMapAndDereference) { auto it = catalog.begin("foo"); NamespaceString lastNs; boost::optional<CollectionUUID> uuid; @@ -467,7 +468,7 @@ TEST_F(UUIDCatalogIterationTest, InvalidateLastEntryInMapAndDereference) { ASSERT(*it == nullptr); } -TEST_F(UUIDCatalogIterationTest, BeginSkipsOverEmptyCollectionObject) { +TEST_F(CollectionCatalogIterationTest, BeginSkipsOverEmptyCollectionObject) { NamespaceString a1("a", "coll1"); NamespaceString a2("a", "coll2"); @@ -491,7 +492,7 @@ TEST_F(UUIDCatalogIterationTest, BeginSkipsOverEmptyCollectionObject) { ASSERT(coll->ns().ns() == a2.ns()); } -TEST_F(UUIDCatalogIterationTest, BeginSkipsOverEmptyCollectionObjectButStopsAtDbBoundary) { +TEST_F(CollectionCatalogIterationTest, BeginSkipsOverEmptyCollectionObjectButStopsAtDbBoundary) { NamespaceString a("a", "coll1"); NamespaceString b("b", "coll1"); @@ -511,7 +512,7 @@ TEST_F(UUIDCatalogIterationTest, BeginSkipsOverEmptyCollectionObjectButStopsAtDb ASSERT(it == catalog.end()); } -TEST_F(UUIDCatalogIterationTest, GetUUIDWontRepositionEvenIfEntryIsDropped) { +TEST_F(CollectionCatalogIterationTest, GetUUIDWontRepositionEvenIfEntryIsDropped) { auto it = catalog.begin("bar"); auto collsIt = collsIterator("bar"); auto uuid = collsIt->first; @@ -521,11 +522,11 @@ TEST_F(UUIDCatalogIterationTest, GetUUIDWontRepositionEvenIfEntryIsDropped) { ASSERT_EQUALS(uuid, it.uuid()); } -TEST_F(UUIDCatalogTest, OnCreateCollection) { +TEST_F(CollectionCatalogTest, OnCreateCollection) { ASSERT(catalog.lookupCollectionByUUID(colUUID) == col); } -TEST_F(UUIDCatalogTest, LookupCollectionByUUID) { +TEST_F(CollectionCatalogTest, LookupCollectionByUUID) { // Ensure the string value of the NamespaceString of the obtained Collection is equal to // nss.ns(). ASSERT_EQUALS(catalog.lookupCollectionByUUID(colUUID)->ns().ns(), nss.ns()); @@ -533,14 +534,14 @@ TEST_F(UUIDCatalogTest, LookupCollectionByUUID) { ASSERT(catalog.lookupCollectionByUUID(CollectionUUID::gen()) == nullptr); } -TEST_F(UUIDCatalogTest, LookupNSSByUUID) { +TEST_F(CollectionCatalogTest, LookupNSSByUUID) { // Ensure the string value of the obtained NamespaceString is equal to nss.ns(). ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID)->ns(), nss.ns()); // Ensure namespace lookups of unknown UUIDs result in empty NamespaceStrings. ASSERT_EQUALS(catalog.lookupNSSByUUID(CollectionUUID::gen()), boost::none); } -TEST_F(UUIDCatalogTest, InsertAfterLookup) { +TEST_F(CollectionCatalogTest, InsertAfterLookup) { auto newUUID = CollectionUUID::gen(); NamespaceString newNss(nss.db(), "newcol"); auto newCollUnique = std::make_unique<CollectionMock>(newNss); @@ -556,13 +557,13 @@ TEST_F(UUIDCatalogTest, InsertAfterLookup) { ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), nss); } -TEST_F(UUIDCatalogTest, OnDropCollection) { +TEST_F(CollectionCatalogTest, OnDropCollection) { catalog.onDropCollection(&opCtx, colUUID); // Ensure the lookup returns a null pointer upon removing the colUUID entry. ASSERT(catalog.lookupCollectionByUUID(colUUID) == nullptr); } -TEST_F(UUIDCatalogTest, RenameCollection) { +TEST_F(CollectionCatalogTest, RenameCollection) { auto uuid = CollectionUUID::gen(); NamespaceString oldNss(nss.db(), "oldcol"); auto collUnique = std::make_unique<CollectionMock>(oldNss); @@ -578,7 +579,7 @@ TEST_F(UUIDCatalogTest, RenameCollection) { ASSERT_EQUALS(catalog.lookupCollectionByUUID(uuid), collection); } -TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsOldNSSIfDropped) { +TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsOldNSSIfDropped) { catalog.onCloseCatalog(&opCtx); catalog.onDropCollection(&opCtx, colUUID); catalog.deregisterCatalogEntry(colUUID); @@ -588,7 +589,7 @@ TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsOldNSSIfDropped) { ASSERT_EQUALS(catalog.lookupNSSByUUID(colUUID), boost::none); } -TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreatedNSS) { +TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreatedNSS) { auto newUUID = CollectionUUID::gen(); NamespaceString newNss(nss.db(), "newcol"); auto newCollUnique = std::make_unique<CollectionMock>(newNss); @@ -610,7 +611,7 @@ TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreatedNSS) { ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), nss); } -TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS) { +TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS) { NamespaceString newNss(nss.db(), "newcol"); auto newCollUnique = std::make_unique<CollectionMock>(newNss); auto newCatalogEntry = std::make_unique<CollectionCatalogEntryMock>(newNss.ns()); @@ -632,12 +633,12 @@ TEST_F(UUIDCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS) { ASSERT_EQUALS(*catalog.lookupNSSByUUID(colUUID), newNss); } -DEATH_TEST_F(UUIDCatalogResourceTest, AddInvalidResourceType, "invariant") { +DEATH_TEST_F(CollectionCatalogResourceTest, AddInvalidResourceType, "invariant") { auto rid = ResourceId(RESOURCE_GLOBAL, 0); catalog.addResource(rid, ""); } -TEST_F(UUIDCatalogTest, GetAllCollectionNamesAndGetAllDbNames) { +TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNames) { NamespaceString aColl("dbA", "collA"); NamespaceString b1Coll("dbB", "collB1"); NamespaceString b2Coll("dbB", "collB2"); diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp index 57f1f5fa173..16db8b5fb0e 100644 --- a/src/mongo/db/catalog/collection_impl.cpp +++ b/src/mongo/db/catalog/collection_impl.cpp @@ -42,6 +42,7 @@ #include "mongo/bson/simple_bsonelement_comparator.h" #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/db/background.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/collection_info_cache_impl.h" #include "mongo/db/catalog/collection_options.h" @@ -49,7 +50,6 @@ #include "mongo/db/catalog/index_catalog_impl.h" #include "mongo/db/catalog/index_consistency.h" #include "mongo/db/catalog/index_key_validate.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands/server_status_metric.h" #include "mongo/db/concurrency/d_concurrency.h" diff --git a/src/mongo/db/catalog/collection_impl.h b/src/mongo/db/catalog/collection_impl.h index cc26c48ae73..795c0947192 100644 --- a/src/mongo/db/catalog/collection_impl.h +++ b/src/mongo/db/catalog/collection_impl.h @@ -37,7 +37,7 @@ namespace mongo { class IndexConsistency; -class UUIDCatalog; +class CollectionCatalog; class CollectionImpl final : public Collection, public CappedCallback { private: static const int kMagicNumber = 1357924; diff --git a/src/mongo/db/catalog/collection_mock.h b/src/mongo/db/catalog/collection_mock.h index 14e9f8d1550..e4cd77b6809 100644 --- a/src/mongo/db/catalog/collection_mock.h +++ b/src/mongo/db/catalog/collection_mock.h @@ -35,7 +35,7 @@ namespace mongo { /** - * This class comprises a mock Collection for use by UUIDCatalog unit tests. + * This class comprises a mock Collection for use by CollectionCatalog unit tests. */ class CollectionMock : public Collection { public: diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index d2ecd5bed28..3a6a151106d 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -34,14 +34,15 @@ #include "mongo/db/catalog/create_collection.h" #include "mongo/bson/bsonobj.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/database_holder.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/command_generic_argument.h" #include "mongo/db/commands.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" #include "mongo/db/db_raii.h" #include "mongo/db/namespace_string.h" +#include "mongo/db/op_observer.h" #include "mongo/db/operation_context.h" #include "mongo/db/ops/insert.h" #include "mongo/db/repl/replication_coordinator.h" @@ -222,7 +223,7 @@ Status createCollectionForApplyOps(OperationContext* opCtx, "Invalid UUID in applyOps create command: " + uuid.toString(), uuid.isRFC4122v4()); - auto& catalog = UUIDCatalog::get(opCtx); + auto& catalog = CollectionCatalog::get(opCtx); const auto currentName = catalog.lookupNSSByUUID(uuid); auto serviceContext = opCtx->getServiceContext(); auto opObserver = serviceContext->getOpObserver(); diff --git a/src/mongo/db/catalog/create_collection_test.cpp b/src/mongo/db/catalog/create_collection_test.cpp index 2d2061c1e98..591855f4479 100644 --- a/src/mongo/db/catalog/create_collection_test.cpp +++ b/src/mongo/db/catalog/create_collection_test.cpp @@ -29,9 +29,9 @@ #include "mongo/platform/basic.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/create_collection.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" #include "mongo/db/db_raii.h" #include "mongo/db/jsobj.h" @@ -186,8 +186,8 @@ TEST_F(CreateCollectionTest, ASSERT_EQUALS(uuid, getCollectionUuid(opCtx.get(), newNss)); // Check that old collection that was renamed out of the way still exists. - auto& uuidCatalog = UUIDCatalog::get(opCtx.get()); - auto renamedCollectionNss = uuidCatalog.lookupNSSByUUID(existingCollectionUuid); + auto& catalog = CollectionCatalog::get(opCtx.get()); + auto renamedCollectionNss = catalog.lookupNSSByUUID(existingCollectionUuid); ASSERT(renamedCollectionNss); ASSERT_TRUE(collectionExists(opCtx.get(), *renamedCollectionNss)) << "old renamed collection with UUID " << existingCollectionUuid diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h index c13a0920b57..83402b8650e 100644 --- a/src/mongo/db/catalog/database.h +++ b/src/mongo/db/catalog/database.h @@ -36,8 +36,8 @@ #include "mongo/base/string_data.h" #include "mongo/bson/bsonobj.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_options.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/namespace_string.h" #include "mongo/db/repl/optime.h" #include "mongo/util/string_map.h" @@ -74,8 +74,8 @@ public: inline Database(Database&&) = delete; inline Database& operator=(Database&&) = delete; - virtual UUIDCatalog::iterator begin(OperationContext* opCtx) const = 0; - virtual UUIDCatalog::iterator end(OperationContext* opCtx) const = 0; + virtual CollectionCatalog::iterator begin(OperationContext* opCtx) const = 0; + virtual CollectionCatalog::iterator end(OperationContext* opCtx) const = 0; /** * Sets up internal memory structures. diff --git a/src/mongo/db/catalog/database_holder_impl.cpp b/src/mongo/db/catalog/database_holder_impl.cpp index 2446a074cc2..cd346130f0c 100644 --- a/src/mongo/db/catalog/database_holder_impl.cpp +++ b/src/mongo/db/catalog/database_holder_impl.cpp @@ -35,9 +35,9 @@ #include "mongo/db/audit.h" #include "mongo/db/background.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_impl.h" #include "mongo/db/catalog/database_impl.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/operation_context.h" #include "mongo/db/repl/oplog.h" @@ -136,7 +136,7 @@ Database* DatabaseHolderImpl::openDb(OperationContext* opCtx, StringData ns, boo // different databases for the same name. lk.unlock(); - if (UUIDCatalog::get(opCtx).getAllCollectionUUIDsFromDb(dbname).empty()) { + if (CollectionCatalog::get(opCtx).getAllCollectionUUIDsFromDb(dbname).empty()) { audit::logCreateDatabase(opCtx->getClient(), dbname); if (justCreated) *justCreated = true; @@ -213,7 +213,7 @@ void DatabaseHolderImpl::close(OperationContext* opCtx, StringData ns) { auto db = it->second; repl::oplogCheckCloseDatabase(opCtx, db); - UUIDCatalog::get(opCtx).onCloseDatabase(opCtx, db); + CollectionCatalog::get(opCtx).onCloseDatabase(opCtx, dbName.toString()); db->close(opCtx); delete db; @@ -254,7 +254,7 @@ void DatabaseHolderImpl::closeAll(OperationContext* opCtx) { Database* db = _dbs[name]; repl::oplogCheckCloseDatabase(opCtx, db); - UUIDCatalog::get(opCtx).onCloseDatabase(opCtx, db); + CollectionCatalog::get(opCtx).onCloseDatabase(opCtx, name); db->close(opCtx); delete db; diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index 3eb78f7b082..ff36de7092e 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -42,14 +42,14 @@ #include "mongo/base/init.h" #include "mongo/db/audit.h" #include "mongo/db/background.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_entry.h" +#include "mongo/db/catalog/collection_catalog_helper.h" #include "mongo/db/catalog/collection_impl.h" #include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/drop_indexes.h" #include "mongo/db/catalog/index_catalog.h" -#include "mongo/db/catalog/uuid_catalog.h" -#include "mongo/db/catalog/uuid_catalog_helper.h" #include "mongo/db/clientcursor.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -87,7 +87,7 @@ MONGO_FAIL_POINT_DEFINE(hangBeforeLoggingCreateCollection); std::unique_ptr<Collection> _createCollectionInstance(OperationContext* opCtx, const NamespaceString& nss) { - auto cce = UUIDCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(nss); + auto cce = CollectionCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(nss); auto rs = cce->getRecordStore(); auto uuid = cce->getCollectionOptions(opCtx).uuid; invariant(rs, @@ -168,20 +168,20 @@ void DatabaseImpl::init(OperationContext* const opCtx) const { uasserted(10028, status.toString()); } - auto& uuidCatalog = UUIDCatalog::get(opCtx); - for (const auto& nss : uuidCatalog.getAllCollectionNamesFromDb(opCtx, _name)) { + auto& catalog = CollectionCatalog::get(opCtx); + for (const auto& nss : catalog.getAllCollectionNamesFromDb(opCtx, _name)) { auto ownedCollection = _createCollectionInstance(opCtx, nss); invariant(ownedCollection); // Call registerCollectionObject directly because we're not in a WUOW. auto uuid = *(ownedCollection->uuid()); - uuidCatalog.registerCollectionObject(uuid, std::move(ownedCollection)); + catalog.registerCollectionObject(uuid, std::move(ownedCollection)); } - // At construction time of the viewCatalog, the UUIDCatalog map wasn't initialized yet, so no - // system.views collection would be found. Now we're sufficiently initialized, signal a version - // change. Also force a reload, so if there are problems with the catalog contents as might be - // caused by incorrect mongod versions or similar, they are found right away. + // At construction time of the viewCatalog, the CollectionCatalog map wasn't initialized yet, + // so no system.views collection would be found. Now we're sufficiently initialized, signal a + // version change. Also force a reload, so if there are problems with the catalog contents as + // might be caused by incorrect mongod versions or similar, they are found right away. auto views = ViewCatalog::get(this); views->invalidate(); Status reloadStatus = views->reloadIfNeeded(opCtx); @@ -196,9 +196,10 @@ void DatabaseImpl::init(OperationContext* const opCtx) const { void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) const { invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_X)); - for (const auto& nss : UUIDCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, _name)) { + for (const auto& nss : + CollectionCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, _name)) { CollectionCatalogEntry* coll = - UUIDCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(nss); + CollectionCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(nss); CollectionOptions options = coll->getCollectionOptions(opCtx); if (!options.temp) @@ -497,7 +498,7 @@ Status DatabaseImpl::_finishDropCollection(OperationContext* opCtx, UUID uuid = *collection->uuid(); log() << "Finishing collection drop for " << nss << " (" << uuid << ")."; - UUIDCatalog& catalog = UUIDCatalog::get(opCtx); + CollectionCatalog& catalog = CollectionCatalog::get(opCtx); catalog.onDropCollection(opCtx, uuid); auto storageEngine = @@ -506,7 +507,7 @@ Status DatabaseImpl::_finishDropCollection(OperationContext* opCtx, } Collection* DatabaseImpl::getCollection(OperationContext* opCtx, const NamespaceString& nss) const { - return UUIDCatalog::get(opCtx).lookupCollectionByNamespace(nss); + return CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss); } Status DatabaseImpl::renameCollection(OperationContext* opCtx, @@ -553,10 +554,11 @@ Status DatabaseImpl::renameCollection(OperationContext* opCtx, checked_cast<KVStorageEngine*>(opCtx->getServiceContext()->getStorageEngine()); Status status = storageEngine->getCatalog()->renameCollection(opCtx, fromNss, toNss, stayTemp); - // Set the namespace of 'collToRename' from within the UUIDCatalog. This is necessary because - // the UUIDCatalog mutex synchronizes concurrent access to the collection's namespace for + // Set the namespace of 'collToRename' from within the CollectionCatalog. This is necessary + // because + // the CollectionCatalog mutex synchronizes concurrent access to the collection's namespace for // callers that may not hold a collection lock. - UUIDCatalog::get(opCtx).setCollectionNamespace(opCtx, collToRename, fromNss, toNss); + CollectionCatalog::get(opCtx).setCollectionNamespace(opCtx, collToRename, fromNss, toNss); opCtx->recoveryUnit()->onCommit([collToRename](auto commitTime) { // Ban reading from this collection on committed reads on snapshots before now. @@ -684,10 +686,10 @@ Collection* DatabaseImpl::createCollection(OperationContext* opCtx, opCtx, nss, optionsWithUUID, true /*allocateDefaultSpace*/)); // Create Collection object - auto& uuidCatalog = UUIDCatalog::get(opCtx); + auto& catalog = CollectionCatalog::get(opCtx); auto ownedCollection = _createCollectionInstance(opCtx, nss); Collection* collection = ownedCollection.get(); - uuidCatalog.onCreateCollection(opCtx, std::move(ownedCollection), *(collection->uuid())); + catalog.onCreateCollection(opCtx, std::move(ownedCollection), *(collection->uuid())); opCtx->recoveryUnit()->onCommit([collection](auto commitTime) { // Ban reading from this collection on committed reads on snapshots before now. if (commitTime) @@ -803,7 +805,8 @@ void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext* return; } - for (const auto& nss : UUIDCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, _name)) { + for (const auto& nss : + CollectionCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, _name)) { if (nss.isDropPendingNamespace()) { auto dropOpTime = fassert(40459, nss.getDropPendingNamespaceOpTime()); log() << "Found drop-pending namespace " << nss << " with drop optime " << dropOpTime; diff --git a/src/mongo/db/catalog/database_impl.h b/src/mongo/db/catalog/database_impl.h index ffaee26c449..ef90e9cf08f 100644 --- a/src/mongo/db/catalog/database_impl.h +++ b/src/mongo/db/catalog/database_impl.h @@ -128,12 +128,12 @@ public: void checkForIdIndexesAndDropPendingCollections(OperationContext* opCtx) const final; - UUIDCatalog::iterator begin(OperationContext* opCtx) const final { - return UUIDCatalog::get(opCtx).begin(_name); + CollectionCatalog::iterator begin(OperationContext* opCtx) const final { + return CollectionCatalog::get(opCtx).begin(_name); } - UUIDCatalog::iterator end(OperationContext* opCtx) const final { - return UUIDCatalog::get(opCtx).end(); + CollectionCatalog::iterator end(OperationContext* opCtx) const final { + return CollectionCatalog::get(opCtx).end(); } uint64_t epoch() const { diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp index fdf80e6b1f8..4a9d08b678b 100644 --- a/src/mongo/db/catalog/database_test.cpp +++ b/src/mongo/db/catalog/database_test.cpp @@ -33,9 +33,9 @@ #include <pcrecpp.h> #include "mongo/bson/util/builder.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/index_catalog.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/concurrency/write_conflict_exception.h" @@ -352,14 +352,14 @@ TEST_F(DatabaseTest, RenameCollectionPreservesUuidOfSourceCollectionAndUpdatesUu auto fromUuid = UUID::gen(); - auto&& uuidCatalog = UUIDCatalog::get(opCtx); - ASSERT_EQUALS(boost::none, uuidCatalog.lookupNSSByUUID(fromUuid)); + auto&& catalog = CollectionCatalog::get(opCtx); + ASSERT_EQUALS(boost::none, catalog.lookupNSSByUUID(fromUuid)); WriteUnitOfWork wuow(opCtx); CollectionOptions fromCollectionOptions; fromCollectionOptions.uuid = fromUuid; ASSERT_TRUE(db->createCollection(opCtx, fromNss, fromCollectionOptions)); - ASSERT_EQUALS(fromNss, *uuidCatalog.lookupNSSByUUID(fromUuid)); + ASSERT_EQUALS(fromNss, *catalog.lookupNSSByUUID(fromUuid)); auto stayTemp = false; ASSERT_OK(db->renameCollection(opCtx, fromNss, toNss, stayTemp)); @@ -375,7 +375,7 @@ TEST_F(DatabaseTest, RenameCollectionPreservesUuidOfSourceCollectionAndUpdatesUu ASSERT_TRUE(toUuid); ASSERT_EQUALS(fromUuid, *toUuid); - ASSERT_EQUALS(toNss, *uuidCatalog.lookupNSSByUUID(*toUuid)); + ASSERT_EQUALS(toNss, *catalog.lookupNSSByUUID(*toUuid)); wuow.commit(); }); diff --git a/src/mongo/db/catalog/index_builds_manager.cpp b/src/mongo/db/catalog/index_builds_manager.cpp index c061074efa7..67bbcb94059 100644 --- a/src/mongo/db/catalog/index_builds_manager.cpp +++ b/src/mongo/db/catalog/index_builds_manager.cpp @@ -34,10 +34,10 @@ #include "mongo/db/catalog/index_builds_manager.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/index_timestamp_helper.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/operation_context.h" #include "mongo/db/storage/write_unit_of_work.h" @@ -141,7 +141,7 @@ StatusWith<std::pair<long long, long long>> IndexBuildsManager::startBuildingInd OperationContext* opCtx, NamespaceString ns, const UUID& buildUUID) { auto builder = _getBuilder(buildUUID); - auto cce = UUIDCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(ns); + auto cce = CollectionCatalog::get(opCtx).lookupCollectionCatalogEntryByNamespace(ns); auto rs = cce ? cce->getRecordStore() : nullptr; // Iterate all records in the collection. Delete them if they aren't valid BSON. Index them diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index 3f8f82c35cc..6baf2ddfbe8 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -34,12 +34,12 @@ #include "mongo/db/catalog/rename_collection.h" #include "mongo/db/background.h" +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/document_validation.h" #include "mongo/db/catalog/drop_collection.h" #include "mongo/db/catalog/index_catalog.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/curop.h" @@ -48,6 +48,7 @@ #include "mongo/db/index_builds_coordinator.h" #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" +#include "mongo/db/op_observer.h" #include "mongo/db/ops/insert.h" #include "mongo/db/query/query_knobs_gen.h" #include "mongo/db/repl/replication_coordinator.h" @@ -66,7 +67,7 @@ namespace { MONGO_FAIL_POINT_DEFINE(writeConfilctInRenameCollCopyToTmp); boost::optional<NamespaceString> getNamespaceFromUUID(OperationContext* opCtx, const UUID& uuid) { - return UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid); + return CollectionCatalog::get(opCtx).lookupNSSByUUID(uuid); } bool isCollectionSharded(OperationContext* opCtx, const NamespaceString& nss) { @@ -762,7 +763,7 @@ Status renameCollectionForApplyOps(OperationContext* opCtx, OptionalCollectionUUID uuidToRename; if (!ui.eoo()) { uuidToRename = uassertStatusOK(UUID::parse(ui)); - auto nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuidToRename.get()); + auto nss = CollectionCatalog::get(opCtx).lookupNSSByUUID(uuidToRename.get()); if (nss) sourceNss = *nss; } diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp index 96b8fc46890..9a70e6c3105 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -33,12 +33,12 @@ #include <string> #include <vector> +#include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/collection_options.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/catalog/index_catalog.h" #include "mongo/db/catalog/rename_collection.h" -#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" #include "mongo/db/concurrency/write_conflict_exception.h" #include "mongo/db/db_raii.h" @@ -387,7 +387,7 @@ CollectionUUID _getCollectionUuid(OperationContext* opCtx, const NamespaceString * Get collection namespace by UUID. */ NamespaceString _getCollectionNssFromUUID(OperationContext* opCtx, const UUID& uuid) { - Collection* source = UUIDCatalog::get(opCtx).lookupCollectionByUUID(uuid); + Collection* source = CollectionCatalog::get(opCtx).lookupCollectionByUUID(uuid); return source ? source->ns() : NamespaceString(); } @@ -626,7 +626,7 @@ TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetDo ASSERT_FALSE(_collectionExists(_opCtx.get(), collC)); // B (originally A) should exist ASSERT_TRUE(_collectionExists(_opCtx.get(), collB)); - // collAUUID should be associated with collB's NamespaceString in the UUIDCatalog. + // collAUUID should be associated with collB's NamespaceString in the CollectionCatalog. auto newCollNS = _getCollectionNssFromUUID(_opCtx.get(), collAUUID); ASSERT_TRUE(newCollNS.isValid()); ASSERT_EQUALS(newCollNS, collB); @@ -652,7 +652,7 @@ TEST_F(RenameCollectionTest, RenameCollectionForApplyOpsDropTargetByUUIDTargetEx // B (originally A) should exist ASSERT_TRUE(_collectionExists(_opCtx.get(), collB)); // The original B should exist too, but with a temporary name - const auto& tmpB = UUIDCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID); + const auto& tmpB = CollectionCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID); ASSERT(tmpB); ASSERT_TRUE(tmpB->coll().startsWith("tmp")); ASSERT_TRUE(*tmpB != collB); @@ -685,7 +685,7 @@ TEST_F(RenameCollectionTest, // B (originally A) should exist ASSERT_TRUE(_collectionExists(_opCtx.get(), collB)); // The original B should exist too, but with a temporary name - const auto& tmpB = UUIDCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID); + const auto& tmpB = CollectionCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID); ASSERT(tmpB); ASSERT_TRUE(*tmpB != collB); ASSERT_TRUE(tmpB->coll().startsWith("tmp")); @@ -711,7 +711,7 @@ TEST_F(RenameCollectionTest, // B (originally A) should exist ASSERT_TRUE(_collectionExists(_opCtx.get(), collB)); // The original B should exist too, but with a temporary name - const auto& tmpB = UUIDCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID); + const auto& tmpB = CollectionCatalog::get(_opCtx.get()).lookupNSSByUUID(collBUUID); ASSERT(tmpB); ASSERT_TRUE(*tmpB != collB); ASSERT_TRUE(tmpB->coll().startsWith("tmp")); @@ -1168,15 +1168,15 @@ TEST_F(RenameCollectionTest, RenameAcrossDatabasesDoesNotPreserveCatalogPointers ASSERT_NE(targetCatalogEntry, sourceCatalogEntry); } -TEST_F(RenameCollectionTest, UUIDCatalogMappingRemainsIntactThroughRename) { +TEST_F(RenameCollectionTest, CollectionCatalogMappingRemainsIntactThroughRename) { _createCollection(_opCtx.get(), _sourceNss); Lock::GlobalWrite globalWrite(_opCtx.get()); - auto& uuidCatalog = UUIDCatalog::get(_opCtx.get()); + auto& catalog = CollectionCatalog::get(_opCtx.get()); Collection* sourceColl = _getCollection_inlock(_opCtx.get(), _sourceNss); ASSERT(sourceColl); - ASSERT_EQ(sourceColl, uuidCatalog.lookupCollectionByUUID(*sourceColl->uuid())); + ASSERT_EQ(sourceColl, catalog.lookupCollectionByUUID(*sourceColl->uuid())); ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, _targetNss, {})); - ASSERT_EQ(sourceColl, uuidCatalog.lookupCollectionByUUID(*sourceColl->uuid())); + ASSERT_EQ(sourceColl, catalog.lookupCollectionByUUID(*sourceColl->uuid())); } TEST_F(RenameCollectionTest, FailRenameCollectionFromReplicatedToUnreplicatedDB) { |