diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2021-06-10 07:22:45 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-10 08:00:13 +0000 |
commit | 51a831577b0f0581e21724f4ade10e4880cc4f32 (patch) | |
tree | 430c2885d0ea7db637726e9e24b1b1ed4c9c2cd5 /src/mongo/db | |
parent | 0c046b785bd8d48114f627e105c7215e4734c6db (diff) | |
download | mongo-51a831577b0f0581e21724f4ade10e4880cc4f32.tar.gz |
SERVER-57587 Avoid scheduling more range deletion tasks for same range during rename
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/s/range_deletion_util.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/mongo/db/s/range_deletion_util.cpp b/src/mongo/db/s/range_deletion_util.cpp index c5f087c95bc..a42e62ffd98 100644 --- a/src/mongo/db/s/range_deletion_util.cpp +++ b/src/mongo/db/s/range_deletion_util.cpp @@ -440,7 +440,10 @@ void snapshotRangeDeletionsForRename(OperationContext* opCtx, auto rangeDeletionTasks = getPersistentRangeDeletionTasks(opCtx, fromNss); for (auto& task : rangeDeletionTasks) { - task.setNss(toNss); // Associate task to the new namespace + // Associate task to the new namespace + task.setNss(toNss); + // Assign a new id to prevent duplicate key conflicts with the source range deletion task + task.setId(UUID::gen()); store.add(opCtx, task); } } @@ -453,13 +456,12 @@ void restoreRangeDeletionTasksForRename(OperationContext* opCtx, const Namespace const auto query = QUERY(RangeDeletionTask::kNssFieldName << nss.ns()); - // Remove eventual leftovers from a previously uncompleted restore - rangeDeletionsStore.remove(opCtx, query); - rangeDeletionsForRenameStore.forEach(opCtx, query, [&](const RangeDeletionTask& deletionTask) { - auto task = deletionTask; - task.setId(UUID::gen()); // Assign a new id to prevent duplicate key errors - rangeDeletionsStore.add(opCtx, task); + try { + rangeDeletionsStore.add(opCtx, deletionTask); + } catch (const ExceptionFor<ErrorCodes::DuplicateKey>&) { + // Task already scheduled in a previous call of this method + } return true; }); } |