summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/catalog_control.cpp8
-rw-r--r--src/mongo/db/catalog/collection_catalog.cpp11
-rw-r--r--src/mongo/db/catalog/collection_catalog.h4
-rw-r--r--src/mongo/db/catalog/collection_catalog_test.cpp16
-rw-r--r--src/mongo/db/storage/storage_engine_impl.cpp1
5 files changed, 20 insertions, 20 deletions
diff --git a/src/mongo/db/catalog/catalog_control.cpp b/src/mongo/db/catalog/catalog_control.cpp
index 98219a55b95..79b3126d9ff 100644
--- a/src/mongo/db/catalog/catalog_control.cpp
+++ b/src/mongo/db/catalog/catalog_control.cpp
@@ -149,8 +149,7 @@ void reopenAllDatabasesAndReloadCollectionCatalog(OperationContext* opCtx,
// Opening CollectionCatalog: The collection catalog is now in sync with the storage engine
// catalog. Clear the pre-closing state.
- CollectionCatalog::write(opCtx,
- [&](CollectionCatalog& catalog) { catalog.onOpenCatalog(opCtx); });
+ CollectionCatalog::write(opCtx, [](CollectionCatalog& catalog) { catalog.onOpenCatalog(); });
opCtx->getServiceContext()->incrementCatalogGeneration();
LOGV2(20278, "openCatalog: finished reloading collection catalog");
}
@@ -210,14 +209,13 @@ PreviousCatalogState closeCatalog(OperationContext* opCtx) {
// Need to mark the CollectionCatalog as open if we our closeAll fails, dismissed if successful.
ScopeGuard reopenOnFailure([opCtx] {
CollectionCatalog::write(opCtx,
- [&](CollectionCatalog& catalog) { catalog.onOpenCatalog(opCtx); });
+ [](CollectionCatalog& catalog) { catalog.onOpenCatalog(); });
});
// 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.
- CollectionCatalog::write(opCtx,
- [&](CollectionCatalog& catalog) { catalog.onCloseCatalog(opCtx); });
+ CollectionCatalog::write(opCtx, [](CollectionCatalog& catalog) { catalog.onCloseCatalog(); });
LOGV2_DEBUG(20270, 1, "closeCatalog: closing collection catalog");
diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp
index 9648bbbfc38..22cd4866a27 100644
--- a/src/mongo/db/catalog/collection_catalog.cpp
+++ b/src/mongo/db/catalog/collection_catalog.cpp
@@ -733,16 +733,17 @@ void CollectionCatalog::onCloseDatabase(OperationContext* opCtx, DatabaseName db
_viewsForDatabase.erase(dbName);
}
-void CollectionCatalog::onCloseCatalog(OperationContext* opCtx) {
- invariant(opCtx->lockState()->isW());
- invariant(!_shadowCatalog);
+void CollectionCatalog::onCloseCatalog() {
+ if (_shadowCatalog) {
+ return;
+ }
+
_shadowCatalog.emplace();
for (auto& entry : _catalog)
_shadowCatalog->insert({entry.first, entry.second->ns()});
}
-void CollectionCatalog::onOpenCatalog(OperationContext* opCtx) {
- invariant(opCtx->lockState()->isW());
+void CollectionCatalog::onOpenCatalog() {
invariant(_shadowCatalog);
_shadowCatalog.reset();
++_epoch;
diff --git a/src/mongo/db/catalog/collection_catalog.h b/src/mongo/db/catalog/collection_catalog.h
index f38f85c5841..9f85dd1824b 100644
--- a/src/mongo/db/catalog/collection_catalog.h
+++ b/src/mongo/db/catalog/collection_catalog.h
@@ -522,14 +522,14 @@ public:
*
* Must be called with the global lock acquired in exclusive mode.
*/
- void onCloseCatalog(OperationContext* opCtx);
+ void onCloseCatalog();
/**
* Puts the catalog back in open state, removing the pre-close state. See onCloseCatalog.
*
* Must be called with the global lock acquired in exclusive mode.
*/
- void onOpenCatalog(OperationContext* opCtx);
+ void onOpenCatalog();
/**
* The epoch is incremented whenever the catalog is closed and re-opened.
diff --git a/src/mongo/db/catalog/collection_catalog_test.cpp b/src/mongo/db/catalog/collection_catalog_test.cpp
index 1d7632709ec..779b4a836cd 100644
--- a/src/mongo/db/catalog/collection_catalog_test.cpp
+++ b/src/mongo/db/catalog/collection_catalog_test.cpp
@@ -523,7 +523,7 @@ TEST_F(CollectionCatalogTest, RenameCollection) {
TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsOldNSSIfDropped) {
{
Lock::GlobalLock globalLk(opCtx.get(), MODE_X);
- catalog.onCloseCatalog(opCtx.get());
+ catalog.onCloseCatalog();
}
catalog.deregisterCollection(opCtx.get(), colUUID, /*isDropPending=*/false);
@@ -532,7 +532,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsOldNSSIfDrop
{
Lock::GlobalLock globalLk(opCtx.get(), MODE_X);
- catalog.onOpenCatalog(opCtx.get());
+ catalog.onOpenCatalog();
}
ASSERT_EQUALS(catalog.lookupNSSByUUID(opCtx.get(), colUUID), boost::none);
@@ -547,7 +547,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreated
// Ensure that looking up non-existing UUIDs doesn't affect later registration of those UUIDs.
{
Lock::GlobalLock globalLk(opCtx.get(), MODE_X);
- catalog.onCloseCatalog(opCtx.get());
+ catalog.onCloseCatalog();
}
ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), newUUID) == nullptr);
@@ -559,7 +559,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreated
// Ensure that collection still exists after opening the catalog again.
{
Lock::GlobalLock globalLk(opCtx.get(), MODE_X);
- catalog.onOpenCatalog(opCtx.get());
+ catalog.onOpenCatalog();
}
ASSERT_EQUALS(catalog.lookupCollectionByUUID(opCtx.get(), newUUID), newCol);
@@ -573,7 +573,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS)
{
Lock::GlobalLock globalLk(opCtx.get(), MODE_X);
- catalog.onCloseCatalog(opCtx.get());
+ catalog.onCloseCatalog();
}
catalog.deregisterCollection(opCtx.get(), colUUID, /*isDropPending=*/false);
@@ -586,7 +586,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS)
// Ensure that collection still exists after opening the catalog again.
{
Lock::GlobalLock globalLk(opCtx.get(), MODE_X);
- catalog.onOpenCatalog(opCtx.get());
+ catalog.onOpenCatalog();
}
ASSERT_EQUALS(catalog.lookupCollectionByUUID(opCtx.get(), colUUID), newCol);
@@ -599,8 +599,8 @@ TEST_F(CollectionCatalogTest, CollectionCatalogEpoch) {
{
Lock::GlobalLock globalLk(opCtx.get(), MODE_X);
- catalog.onCloseCatalog(opCtx.get());
- catalog.onOpenCatalog(opCtx.get());
+ catalog.onCloseCatalog();
+ catalog.onOpenCatalog();
}
auto incrementedEpoch = catalog.getEpoch();
diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp
index a79d22a96b4..047aa0502c7 100644
--- a/src/mongo/db/storage/storage_engine_impl.cpp
+++ b/src/mongo/db/storage/storage_engine_impl.cpp
@@ -789,6 +789,7 @@ void StorageEngineImpl::cleanShutdown() {
}
CollectionCatalog::write(getGlobalServiceContext(), [](CollectionCatalog& catalog) {
+ catalog.onCloseCatalog();
catalog.deregisterAllCollectionsAndViews();
});