From ad0c764b6f5020033092a91164e0187add0deb94 Mon Sep 17 00:00:00 2001 From: Pierlauro Sciarelli Date: Mon, 9 Jan 2023 07:03:32 +0000 Subject: SERVER-72290 `deleteRangeDeletionTasksForRename` must not deregister tasks for the target collection --- src/mongo/db/s/range_deletion_util.cpp | 5 --- src/mongo/db/s/range_deletion_util_test.cpp | 54 ++++++++++++++++------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/mongo/db/s/range_deletion_util.cpp b/src/mongo/db/s/range_deletion_util.cpp index c34400e7590..15c06d17d9d 100644 --- a/src/mongo/db/s/range_deletion_util.cpp +++ b/src/mongo/db/s/range_deletion_util.cpp @@ -456,11 +456,6 @@ void restoreRangeDeletionTasksForRename(OperationContext* opCtx, const Namespace void deleteRangeDeletionTasksForRename(OperationContext* opCtx, const NamespaceString& fromNss, const NamespaceString& toNss) { - // Delete range deletion tasks associated to the source collection - PersistentTaskStore rangeDeletionsStore( - NamespaceString::kRangeDeletionNamespace); - rangeDeletionsStore.remove(opCtx, BSON(RangeDeletionTask::kNssFieldName << fromNss.ns())); - // Delete already restored snapshots associated to the target collection PersistentTaskStore rangeDeletionsForRenameStore( NamespaceString::kRangeDeletionForRenameNamespace); diff --git a/src/mongo/db/s/range_deletion_util_test.cpp b/src/mongo/db/s/range_deletion_util_test.cpp index c7854ad1d6b..3845c11af77 100644 --- a/src/mongo/db/s/range_deletion_util_test.cpp +++ b/src/mongo/db/s/range_deletion_util_test.cpp @@ -876,19 +876,22 @@ TEST_F(RenameRangeDeletionsTest, BasicRenameRangeDeletionsTest) { restoreRangeDeletionTasksForRename(_opCtx, kToNss); deleteRangeDeletionTasksForRename(_opCtx, kNss, kToNss); - // Make sure just range deletions for the TO collection are found - ASSERT_EQ(10, rangeDeletionsStore.count(_opCtx)); + const auto targetRangeDeletionsQuery = BSON(RangeDeletionTask::kNssFieldName << kToNss.ns()); + + // Make sure range deletions for the TO collection are found + ASSERT_EQ(10, rangeDeletionsStore.count(_opCtx, targetRangeDeletionsQuery)); int foundTasks = 0; - rangeDeletionsStore.forEach(_opCtx, BSONObj(), [&](const RangeDeletionTask& newTask) { - auto task = tasks.at(foundTasks++); - ASSERT_EQ(newTask.getNss(), kToNss); - ASSERT_EQ(newTask.getCollectionUuid(), task.getCollectionUuid()); - ASSERT_EQ(newTask.getDonorShardId(), task.getDonorShardId()); - ASSERT(SimpleBSONObjComparator::kInstance.evaluate(newTask.getRange().toBSON() == - task.getRange().toBSON())); - ASSERT(newTask.getWhenToClean() == task.getWhenToClean()); - return true; - }); + rangeDeletionsStore.forEach( + _opCtx, targetRangeDeletionsQuery, [&](const RangeDeletionTask& newTask) { + auto task = tasks.at(foundTasks++); + ASSERT_EQ(newTask.getNss(), kToNss); + ASSERT_EQ(newTask.getCollectionUuid(), task.getCollectionUuid()); + ASSERT_EQ(newTask.getDonorShardId(), task.getDonorShardId()); + ASSERT(SimpleBSONObjComparator::kInstance.evaluate(newTask.getRange().toBSON() == + task.getRange().toBSON())); + ASSERT(newTask.getWhenToClean() == task.getWhenToClean()); + return true; + }); ASSERT_EQ(foundTasks, numTasks); // Make sure no garbage is left in intermediate collection @@ -933,19 +936,22 @@ TEST_F(RenameRangeDeletionsTest, IdempotentRenameRangeDeletionsTest) { deleteRangeDeletionTasksForRename(_opCtx, kNss, kToNss); } - // Make sure just range deletions for the TO collection are found - ASSERT_EQ(10, rangeDeletionsStore.count(_opCtx)); + const auto targetRangeDeletionsQuery = BSON(RangeDeletionTask::kNssFieldName << kToNss.ns()); + + // Make sure range deletions for the TO collection are found + ASSERT_EQ(10, rangeDeletionsStore.count(_opCtx, targetRangeDeletionsQuery)); int foundTasks = 0; - rangeDeletionsStore.forEach(_opCtx, BSONObj(), [&](const RangeDeletionTask& newTask) { - auto task = tasks.at(foundTasks++); - ASSERT_EQ(newTask.getNss(), kToNss); - ASSERT_EQ(newTask.getCollectionUuid(), task.getCollectionUuid()); - ASSERT_EQ(newTask.getDonorShardId(), task.getDonorShardId()); - ASSERT(SimpleBSONObjComparator::kInstance.evaluate(newTask.getRange().toBSON() == - task.getRange().toBSON())); - ASSERT(newTask.getWhenToClean() == task.getWhenToClean()); - return true; - }); + rangeDeletionsStore.forEach( + _opCtx, targetRangeDeletionsQuery, [&](const RangeDeletionTask& newTask) { + auto task = tasks.at(foundTasks++); + ASSERT_EQ(newTask.getNss(), kToNss); + ASSERT_EQ(newTask.getCollectionUuid(), task.getCollectionUuid()); + ASSERT_EQ(newTask.getDonorShardId(), task.getDonorShardId()); + ASSERT(SimpleBSONObjComparator::kInstance.evaluate(newTask.getRange().toBSON() == + task.getRange().toBSON())); + ASSERT(newTask.getWhenToClean() == task.getWhenToClean()); + return true; + }); ASSERT_EQ(foundTasks, numTasks); // Make sure no garbage is left in intermediate collection -- cgit v1.2.1