From 08408f78930ace30f5a8cc0823b41b7d7798a24c Mon Sep 17 00:00:00 2001 From: Martin Neupauer Date: Thu, 10 Jan 2019 13:57:28 -0500 Subject: [PATCH] SERVER-38933 currentOp is not resilient to drop shard --- .../sharding_continuous_config_stepdown.yml | 1 + .../sharding/current_op_with_drop_shard.js | 25 +++++++++++++++++++ .../db/pipeline/mongos_process_interface.cpp | 3 +++ 3 files changed, 29 insertions(+) create mode 100644 jstests/sharding/current_op_with_drop_shard.js diff --git a/buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml b/buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml index 383400c4f5b..3ba7977663c 100644 --- a/buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml +++ b/buildscripts/resmokeconfig/suites/sharding_continuous_config_stepdown.yml @@ -25,6 +25,7 @@ selector: - jstests/sharding/basic_merge.js - jstests/sharding/count1.js - jstests/sharding/count2.js + - jstests/sharding/current_op_with_drop_shard.js - jstests/sharding/cursor1.js - jstests/sharding/diffservers1.js - jstests/sharding/disable_autosplit.js diff --git a/jstests/sharding/current_op_with_drop_shard.js b/jstests/sharding/current_op_with_drop_shard.js new file mode 100644 index 00000000000..aaadca2dc3f --- /dev/null +++ b/jstests/sharding/current_op_with_drop_shard.js @@ -0,0 +1,25 @@ +// Tests that currentOp is resilient to drop shard. +(function() { + 'use strict'; + + const st = new ShardingTest({shards: 2, rs: {nodes: 1}}); + + // We need the balancer to remove a shard. + st.startBalancer(); + + const mongosDB = st.s.getDB(jsTestName()); + const shardName = st.shard0.shardName; + + var res = st.s.adminCommand({removeShard: shardName}); + assert.commandWorked(res); + assert.eq('started', res.state); + assert.soon(function() { + res = st.s.adminCommand({removeShard: shardName}); + assert.commandWorked(res); + return ('completed' === res.state); + }, "removeShard never completed for shard " + shardName); + + assert.commandWorked(mongosDB.currentOp()); + + st.stop(); +})(); diff --git a/src/mongo/db/pipeline/mongos_process_interface.cpp b/src/mongo/db/pipeline/mongos_process_interface.cpp index 53cf418e36a..effb02d4e6f 100644 --- a/src/mongo/db/pipeline/mongos_process_interface.cpp +++ b/src/mongo/db/pipeline/mongos_process_interface.cpp @@ -441,6 +441,9 @@ MongoSInterface::DispatchShardPipelineResults MongoSInterface::dispatchShardPipe if (!shardRegistry->reload(opCtx)) { shardRegistry->reload(opCtx); } + // Rebuild the set of shards as the shard registry might have changed. + shardIds = getTargetedShards( + opCtx, mustRunOnAll, executionNsRoutingInfo, shardQuery, aggRequest.getCollation()); } // Explain does not produce a cursor, so instead we scatter-gather commands to the shards.