diff --git a/jstests/sharding/drop_collection_if_uuid_not_matching.js b/jstests/sharding/drop_collection_if_uuid_not_matching.js index de7c450059b..cdf44226f8f 100644 --- a/jstests/sharding/drop_collection_if_uuid_not_matching.js +++ b/jstests/sharding/drop_collection_if_uuid_not_matching.js @@ -9,6 +9,7 @@ * does_not_support_stepdowns, # The command is not resilient to stepdowns * ] */ +import {configureFailPoint} from "jstests/libs/fail_point_util.js"; const dbName = "test"; @@ -40,7 +41,9 @@ function runTests(collName, commandName, writeConcern) { assert.eq(null, db.getCollection(collName).findOne({_id: 0})); // Existing collection with the expected UUID (command succeeds but no drop) + let fp = configureFailPoint(st.rs0.getPrimary(), 'delayRefreshAfterShardCollection'); assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: 1}})); + fp.off(); const collUUID = st.config.collections.findOne({_id: ns}).uuid; assert.commandWorked(db.getCollection(collName).insert({_id: 0})); assert.commandWorked(db.runCommand(appenWriteConcern( diff --git a/src/mongo/db/s/sharding_util.cpp b/src/mongo/db/s/sharding_util.cpp index 87e190529e6..e815ca2d215 100644 --- a/src/mongo/db/s/sharding_util.cpp +++ b/src/mongo/db/s/sharding_util.cpp @@ -74,7 +74,7 @@ #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding namespace mongo { - +MONGO_FAIL_POINT_DEFINE(delayRefreshAfterShardCollection); namespace sharding_util { using namespace fmt::literals; @@ -95,18 +95,34 @@ void tellShardsToRefreshCollection(OperationContext* opCtx, void triggerFireAndForgetShardRefreshes(OperationContext* opCtx, const std::vector& shardIds, const NamespaceString& nss) { - auto cmd = FlushRoutingTableCacheUpdates(nss); - cmd.setSyncFromConfig(true); - cmd.setDbName(nss.dbName()); - for (const auto& shardId : shardIds) { + auto service = opCtx->getService(); + auto refreshFn = [](OperationContext* opCtx, + const ShardId& shardId, + const NamespaceString& nss) { auto recipientShard = uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, shardId)); - + auto cmd = FlushRoutingTableCacheUpdates(nss); + cmd.setSyncFromConfig(true); + cmd.setDbName(nss.dbName()); recipientShard->runFireAndForgetCommand(opCtx, ReadPreferenceSetting{ReadPreference::PrimaryOnly}, DatabaseName::kAdmin, cmd.toBSON({})); + }; + auto executor = Grid::get(opCtx)->getExecutorPool()->getFixedExecutor(); + for (const auto& shardId : shardIds) { + if (delayRefreshAfterShardCollection.shouldFail()) { + auto future = ExecutorFuture(executor).then([shardId, nss, refreshFn, service] { + sleepFor(Seconds(30)); + + ThreadClient threadClient(service); + ServiceContext::UniqueOperationContext opCtx = threadClient->makeOperationContext(); + refreshFn(opCtx.get(), shardId, nss); + }); + } else { + refreshFn(opCtx, shardId, nss); + } } }