submitRangeDeletionTask does not correctly handle the case where forceShardFilteringMetadataRefresh throws NamespaceNotFound. In this case, the range deletion task should be deleted, but the code to do that will not execute. I can confirm this by applying the following diff, which contains a unit test that demonstrates the incorrect behavior:
diff --git a/src/mongo/db/s/migration_util_test.cpp b/src/mongo/db/s/migration_util_test.cpp index e6e4deaebb..001c307bbb 100644 --- a/src/mongo/db/s/migration_util_test.cpp +++ b/src/mongo/db/s/migration_util_test.cpp @@ -378,6 +378,31 @@ TEST_F(MigrationUtilsTest, TestInvalidUUID) { using SubmitRangeDeletionTaskTest = MigrationUtilsTest; +TEST_F(SubmitRangeDeletionTaskTest, + FailsAndDeletesTaskIfFilteringMetadataIsUnknownEvenAfterRefresh) { + auto opCtx = operationContext(); + + const auto uuid = UUID::gen(); + auto deletionTask = createDeletionTask(kNss, uuid, 0, 10); + + PersistentTaskStore<RangeDeletionTask> store(opCtx, NamespaceString::kRangeDeletionNamespace); + store.add(opCtx, deletionTask); + ASSERT_EQ(store.count(opCtx), 1); + + // Make the refresh triggered by submitting the task return an empty result so that . + auto result = + stdx::async(stdx::launch::async, [this, uuid] { + respondToMetadataRefreshRequestsWithError(); + }); + + auto submitTaskFuture = migrationutil::submitRangeDeletionTask(opCtx, deletionTask); + + // The task should not have been submitted, and the task's entry should have been removed from + // the persistent store. + ASSERT_FALSE(submitTaskFuture.get(opCtx)); + ASSERT_EQ(store.count(opCtx), 0); +} + TEST_F(SubmitRangeDeletionTaskTest, SucceedsIfFilteringMetadataUUIDMatchesTaskUUID) { auto opCtx = operationContext();