summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2023-03-08 18:40:05 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-03-13 16:30:21 +0000
commit97b0299462d39456f57bde04b96b65e385971b4e (patch)
tree574fa8c531380aabf7d2b38504192812ba067296 /src/mongo/db/storage
parentb2ddd90fc82f082ea117d7b2c891dfd07463ce38 (diff)
downloadmongo-97b0299462d39456f57bde04b96b65e385971b4e.tar.gz
SERVER-74703 Replicating the dropDatabase oplog entry and clearing the collection catalog during dropDatabase is done atomically
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/storage_engine_impl.cpp36
-rw-r--r--src/mongo/db/storage/storage_engine_impl.h2
2 files changed, 6 insertions, 32 deletions
diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp
index e10d4e3865c..46798890198 100644
--- a/src/mongo/db/storage/storage_engine_impl.cpp
+++ b/src/mongo/db/storage/storage_engine_impl.cpp
@@ -919,43 +919,17 @@ Status StorageEngineImpl::dropDatabase(OperationContext* opCtx, const DatabaseNa
}
std::vector<UUID> toDrop = catalog->getAllCollectionUUIDsFromDb(dbName);
-
- // Do not timestamp any of the following writes. This will remove entries from the catalog as
- // well as drop any underlying tables. It's not expected for dropping tables to be reversible
- // on crash/recoverToStableTimestamp.
- return _dropCollectionsNoTimestamp(opCtx, toDrop);
+ return _dropCollections(opCtx, toDrop);
}
/**
* Returns the first `dropCollection` error that this method encounters. This method will attempt
* to drop all collections, regardless of the error status.
*/
-Status StorageEngineImpl::_dropCollectionsNoTimestamp(OperationContext* opCtx,
- const std::vector<UUID>& toDrop) {
- // On primaries, this method will be called outside of any `TimestampBlock` state meaning the
- // "commit timestamp" will not be set. For this case, this method needs no special logic to
- // avoid timestamping the upcoming writes.
- //
- // On secondaries, there will be a wrapping `TimestampBlock` and the "commit timestamp" will
- // be set. Carefully save that to the side so the following writes can go through without that
- // context.
- const Timestamp commitTs = opCtx->recoveryUnit()->getCommitTimestamp();
- if (!commitTs.isNull()) {
- opCtx->recoveryUnit()->clearCommitTimestamp();
- }
-
- // Ensure the method exits with the same "commit timestamp" state that it was called with.
- ScopeGuard addCommitTimestamp([&opCtx, commitTs] {
- if (!commitTs.isNull()) {
- opCtx->recoveryUnit()->setCommitTimestamp(commitTs);
- }
- });
-
- // This code makes untimestamped writes to the _mdb_catalog.
- opCtx->recoveryUnit()->allowUntimestampedWrite();
-
+Status StorageEngineImpl::_dropCollections(OperationContext* opCtx,
+ const std::vector<UUID>& toDrop) {
Status firstError = Status::OK();
- WriteUnitOfWork untimestampedDropWuow(opCtx);
+ WriteUnitOfWork wuow(opCtx);
auto collectionCatalog = CollectionCatalog::get(opCtx);
for (auto& uuid : toDrop) {
auto coll = collectionCatalog->lookupCollectionByUUIDForMetadataWrite(opCtx, uuid);
@@ -991,7 +965,7 @@ Status StorageEngineImpl::_dropCollectionsNoTimestamp(OperationContext* opCtx,
opCtx, coll, opCtx->getServiceContext()->getStorageEngine()->supportsPendingDrops());
}
- untimestampedDropWuow.commit();
+ wuow.commit();
return firstError;
}
diff --git a/src/mongo/db/storage/storage_engine_impl.h b/src/mongo/db/storage/storage_engine_impl.h
index cf465100114..a47f78c0b8a 100644
--- a/src/mongo/db/storage/storage_engine_impl.h
+++ b/src/mongo/db/storage/storage_engine_impl.h
@@ -385,7 +385,7 @@ private:
Timestamp minVisibleTs,
Timestamp minValidTs);
- Status _dropCollectionsNoTimestamp(OperationContext* opCtx, const std::vector<UUID>& toDrop);
+ Status _dropCollections(OperationContext* opCtx, const std::vector<UUID>& toDrop);
/**
* When called in a repair context (_options.forRepair=true), attempts to recover a collection