summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/catalog/collection_catalog_helper.cpp8
-rw-r--r--src/mongo/db/startup_recovery.cpp6
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();