From cb8b9029c089316a198b5f98a74ae21fc1f18299 Mon Sep 17 00:00:00 2001 From: Silvia Surroca Date: Tue, 27 Sep 2022 13:45:23 +0000 Subject: SERVER-65016 Remove range deletions as part of `dropCollection` --- src/mongo/db/s/drop_collection_coordinator.cpp | 13 ++++++++----- src/mongo/db/s/range_deleter_service.cpp | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/mongo/db/s/drop_collection_coordinator.cpp b/src/mongo/db/s/drop_collection_coordinator.cpp index 7061a240378..3510faf2e1d 100644 --- a/src/mongo/db/s/drop_collection_coordinator.cpp +++ b/src/mongo/db/s/drop_collection_coordinator.cpp @@ -68,11 +68,9 @@ DropReply DropCollectionCoordinator::dropCollectionLocally(OperationContext* opC csr->clearFilteringMetadataForDroppedCollection(opCtx); } - DropReply result; - uassertStatusOK(dropCollection( - opCtx, nss, &result, DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops)); - - // Remove all range deletion task documents present on disk for the dropped collection + // Remove all range deletion task documents present on disk for the collection to drop. This is + // a best-effort tentative considering that migrations are not blocked, hence some new document + // may be inserted before actually dropping the collection. if (collectionUUID) { // The multi-document remove command cannot be run in transactions, so run it using // an alternative client. @@ -97,6 +95,11 @@ DropReply DropCollectionCoordinator::dropCollectionLocally(OperationContext* opC } } + DropReply result; + uassertStatusOK(dropCollection( + opCtx, nss, &result, DropCollectionSystemCollectionMode::kDisallowSystemCollectionDrops)); + + // Force the refresh of the catalog cache to purge outdated information const auto catalog = Grid::get(opCtx)->catalogCache(); uassertStatusOK(catalog->getCollectionRoutingInfoWithRefresh(opCtx, nss)); diff --git a/src/mongo/db/s/range_deleter_service.cpp b/src/mongo/db/s/range_deleter_service.cpp index d27c71f3932..954fc10395c 100644 --- a/src/mongo/db/s/range_deleter_service.cpp +++ b/src/mongo/db/s/range_deleter_service.cpp @@ -487,6 +487,9 @@ SharedSemiFuture RangeDeleterService::registerTask( void RangeDeleterService::deregisterTask(const UUID& collUUID, const ChunkRange& range) { auto lock = _acquireMutexFailIfServiceNotUp(); _rangeDeletionTasks[collUUID].erase(std::make_shared(range)); + if (_rangeDeletionTasks[collUUID].size() == 0) { + _rangeDeletionTasks.erase(collUUID); + } } int RangeDeleterService::getNumRangeDeletionTasksForCollection(const UUID& collectionUUID) { -- cgit v1.2.1