diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2022-04-07 12:59:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-09 13:46:01 +0000 |
commit | 7ab46d9a84f4d0ea22ff412b690fc03497a21df3 (patch) | |
tree | 0ff4c462e280fb36c0491294ed8f6d7242092734 | |
parent | e24292c75094add4c13d64a5bff548206fa81a54 (diff) | |
download | mongo-7ab46d9a84f4d0ea22ff412b690fc03497a21df3.tar.gz |
SERVER-65313 Use BatchedCollectionCatalogWriter during startup recovery
Avoids quadratic behavior when initializing Databases/Collections.
(cherry picked from commit 3567535c340e69feeadbb0866f8019a6d84e355c)
-rw-r--r-- | src/mongo/db/catalog/collection_catalog_helper.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/startup_recovery.cpp | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/collection_catalog_helper.cpp b/src/mongo/db/catalog/collection_catalog_helper.cpp index 60e0d125973..63319ea6d0a 100644 --- a/src/mongo/db/catalog/collection_catalog_helper.cpp +++ b/src/mongo/db/catalog/collection_catalog_helper.cpp @@ -46,10 +46,10 @@ void forEachCollectionFromDb(OperationContext* opCtx, auto catalogForIteration = CollectionCatalog::get(opCtx); for (auto collectionIt = catalogForIteration->begin(opCtx, dbName); - collectionIt != catalogForIteration->end(opCtx); - ++collectionIt) { + collectionIt != catalogForIteration->end(opCtx);) { auto uuid = collectionIt.uuid().get(); if (predicate && !catalogForIteration->checkIfCollectionSatisfiable(uuid, predicate)) { + ++collectionIt; continue; } @@ -73,6 +73,10 @@ void forEachCollectionFromDb(OperationContext* opCtx, clk.reset(); } + // Increment iterator before calling callback. This allows for collection deletion inside + // this callback even if we are in batched inplace mode. + ++collectionIt; + // The NamespaceString couldn't be resolved from the uuid, so the collection was dropped. if (!collection) continue; diff --git a/src/mongo/db/startup_recovery.cpp b/src/mongo/db/startup_recovery.cpp index d91d484d319..76af488f216 100644 --- a/src/mongo/db/startup_recovery.cpp +++ b/src/mongo/db/startup_recovery.cpp @@ -630,6 +630,12 @@ void repairAndRecoverDatabases(OperationContext* opCtx, auto const storageEngine = opCtx->getServiceContext()->getStorageEngine(); Lock::GlobalWrite lk(opCtx); + // Use the BatchedCollectionCatalogWriter so all Collection writes to the in-memory catalog are + // done in a single copy-on-write of the catalog. This avoids quadratic behavior where we + // iterate over every collection and perform writes where the catalog would be copied every + // time. + BatchedCollectionCatalogWriter catalog(opCtx); + // Create the FCV document for the first time, if necessary. Replica set nodes only initialize // the FCV when the replica set is first initiated or by data replication. const auto& replSettings = repl::ReplicationCoordinator::get(opCtx)->getSettings(); |