summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/drop_pending_collection_reaper.cpp
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2019-03-11 15:28:01 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2019-03-12 15:02:53 -0400
commitc7e6cd6803e584a6951469e74af93ec3a7a47148 (patch)
treeaf9d995edfeea13951955305df2f7c9195920689 /src/mongo/db/repl/drop_pending_collection_reaper.cpp
parent9d81a7b6f2fbf15dc37dc1e0cc82d4062edc721b (diff)
downloadmongo-c7e6cd6803e584a6951469e74af93ec3a7a47148.tar.gz
SERVER-39957 Two-phase drop by rename should wait until dropOptime is both checkpointed and majority committed
Diffstat (limited to 'src/mongo/db/repl/drop_pending_collection_reaper.cpp')
-rw-r--r--src/mongo/db/repl/drop_pending_collection_reaper.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/mongo/db/repl/drop_pending_collection_reaper.cpp b/src/mongo/db/repl/drop_pending_collection_reaper.cpp
index 31993c6acc2..925a292143c 100644
--- a/src/mongo/db/repl/drop_pending_collection_reaper.cpp
+++ b/src/mongo/db/repl/drop_pending_collection_reaper.cpp
@@ -133,11 +133,30 @@ bool DropPendingCollectionReaper::rollBackDropPendingCollection(
void DropPendingCollectionReaper::dropCollectionsOlderThan(OperationContext* opCtx,
const OpTime& opTime) {
+
+ std::function<bool(const OpTime&)> shouldDrop = [&](const OpTime& dropOpTime) {
+ return dropOpTime <= opTime;
+ };
+
+ // With enableMajorityReadConcern=false, we can only drop collections that
+ // are older than both `opTime` and `checkpointTimestamp`.
+ auto storageEngine = opCtx->getServiceContext()->getStorageEngine();
+ if (!storageEngine->isEphemeral() && !storageEngine->supportsReadConcernMajority()) {
+ auto checkpointTimestamp = storageEngine->getLastStableRecoveryTimestamp();
+ // We don't need to compare terms because these timestamps (checkpoint, opTime and
+ // dropOpTime) all have been committed.
+ if (checkpointTimestamp && checkpointTimestamp < opTime.getTimestamp()) {
+ shouldDrop = [&](const OpTime& dropOpTime) {
+ return dropOpTime.getTimestamp() <= checkpointTimestamp;
+ };
+ }
+ }
+
DropPendingNamespaces toDrop;
{
stdx::lock_guard<stdx::mutex> lock(_mutex);
for (auto it = _dropPendingNamespaces.cbegin();
- it != _dropPendingNamespaces.cend() && it->first <= opTime;
+ it != _dropPendingNamespaces.cend() && shouldDrop(it->first);
++it) {
toDrop.insert(*it);
}