summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2021-10-06 01:01:06 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-06 01:33:27 +0000
commited1a1de3bbf155f9e14ad536f47771b9c8ba2561 (patch)
tree08ffc0ddecb08964ea10f829363371fbbf35d5ff
parentc7739cfe47ea9099188580022a334e335e4b42ef (diff)
downloadmongo-ed1a1de3bbf155f9e14ad536f47771b9c8ba2561.tar.gz
Revert "SERVER-58736 Avoid quadratic behavior in rollback with many collections"
This reverts commit 2bc550f5f4d47b6ae2ca176acc2865f1f4a8035a.
-rw-r--r--src/mongo/db/catalog/collection_catalog.cpp8
-rw-r--r--src/mongo/db/catalog/collection_catalog.h16
-rw-r--r--src/mongo/db/catalog/database_impl.cpp41
3 files changed, 19 insertions, 46 deletions
diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp
index aca202437d7..e45b1ed2954 100644
--- a/src/mongo/db/catalog/collection_catalog.cpp
+++ b/src/mongo/db/catalog/collection_catalog.cpp
@@ -532,14 +532,6 @@ void CollectionCatalog::write(ServiceContext* svcCtx, CatalogWriteFn job) {
void CollectionCatalog::write(OperationContext* opCtx,
std::function<void(CollectionCatalog&)> job) {
- if (opCtx->lockState()->isW()) {
- // Modifications can be done in-place when the global exclusive lock is held as all active
- // transactions and cursors are closed.
- auto& storage = getCatalog(opCtx->getServiceContext());
- auto base = atomic_load(&storage.catalog);
- job(*base);
- return;
- }
write(opCtx->getServiceContext(), std::move(job));
}
diff --git a/src/mongo/db/catalog/collection_catalog.h b/src/mongo/db/catalog/collection_catalog.h
index 5c8f4c03107..21fa2122928 100644
--- a/src/mongo/db/catalog/collection_catalog.h
+++ b/src/mongo/db/catalog/collection_catalog.h
@@ -123,12 +123,6 @@ public:
}
};
- /**
- * During the duration that the CollectionCatalog pointer is held by the caller, the global lock
- * must be held in some mode by the caller to prevent write operations from making in-place
- * modifications on the CollectionCatalog. This pointer is unsafe to use once the global lock
- * is relinquished.
- */
static std::shared_ptr<const CollectionCatalog> get(ServiceContext* svcCtx);
static std::shared_ptr<const CollectionCatalog> get(OperationContext* opCtx);
@@ -139,12 +133,8 @@ public:
static void stash(OperationContext* opCtx, std::shared_ptr<const CollectionCatalog> catalog);
/**
- * Perform a write to the catalog using:
- * (1) in-place if a global exclusive lock is held in the overload for OperationContext, or,
- * (2) using copy-on-write if the global exclusive lock is not held, or if the overload for
- * ServiceContext is used.
- *
- * For (2), a catalog previously returned by get() will not be modified.
+ * Perform a write to the catalog using copy-on-write. A catalog previously returned by get()
+ * will not be modified.
*
* This call will block until the modified catalog has been committed. Concurrant writes are
* batched together and will thus block each other. It is important to not perform blocking
@@ -390,7 +380,7 @@ public:
void onCloseCatalog(OperationContext* opCtx);
/**
- * Puts the catalog back in open state, removing the pre-close state. See onCloseCatalog.
+ * Puts the catatlog back in open state, removing the pre-close state. See onCloseCatalog.
*
* Must be called with the global lock acquired in exclusive mode.
*/
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 66c5db11027..30fd7a113e8 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -213,43 +213,34 @@ void DatabaseImpl::init(OperationContext* const opCtx) const {
void DatabaseImpl::clearTmpCollections(OperationContext* opCtx) const {
invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_IX));
- std::vector<UUID> collectionUUIDsToDrop;
CollectionCatalog::CollectionInfoFn callback = [&](const CollectionPtr& collection) {
- collectionUUIDsToDrop.push_back(collection->uuid());
- return true;
- };
-
- CollectionCatalog::CollectionInfoFn predicate = [&](const CollectionPtr& collection) {
- return collection->getCollectionOptions().temp;
- };
-
- catalog::forEachCollectionFromDb(opCtx, name(), MODE_IX, callback, predicate);
-
- for (const auto& collectionUUIDToDrop : collectionUUIDsToDrop) {
- AutoGetCollection autoColl(
- opCtx, NamespaceStringOrUUID(_name, collectionUUIDToDrop), MODE_X);
- if (!autoColl.getCollection()) {
- // The collection has already been dropped.
- continue;
- }
-
try {
WriteUnitOfWork wuow(opCtx);
- Status status = dropCollection(opCtx, autoColl->ns(), {});
+ Status status = dropCollection(opCtx, collection->ns(), {});
if (!status.isOK()) {
LOGV2_WARNING(20327,
+ "could not drop temp collection '{namespace}': {error}",
"could not drop temp collection",
- "namespace"_attr = autoColl->ns(),
+ "namespace"_attr = collection->ns(),
"error"_attr = redact(status));
}
wuow.commit();
} catch (const WriteConflictException&) {
- LOGV2_WARNING(20328,
- "could not drop temp collection due to WriteConflictException",
- "namespace"_attr = autoColl->ns());
+ LOGV2_WARNING(
+ 20328,
+ "could not drop temp collection '{namespace}' due to WriteConflictException",
+ "could not drop temp collection due to WriteConflictException",
+ "namespace"_attr = collection->ns());
opCtx->recoveryUnit()->abandonSnapshot();
}
- }
+ return true;
+ };
+
+ CollectionCatalog::CollectionInfoFn predicate = [&](const CollectionPtr& collection) {
+ return collection->getCollectionOptions().temp;
+ };
+
+ catalog::forEachCollectionFromDb(opCtx, name(), MODE_X, callback, predicate);
}
void DatabaseImpl::setDropPending(OperationContext* opCtx, bool dropPending) {