diff --git a/jstests/sharding/repro-server-71626.js b/jstests/sharding/repro-server-71626.js new file mode 100644 index 00000000000..bd4df08db29 --- /dev/null +++ b/jstests/sharding/repro-server-71626.js @@ -0,0 +1,37 @@ +(function() { +'use strict'; + +load("jstests/libs/fail_point_util.js"); + +let st = new ShardingTest({mongos: 1, shards: 2}); + +const dbName = "test"; +const collName = "foo"; +const ns = dbName + "." + collName; + +assert.commandWorked(st.s.adminCommand({enableSharding: dbName})); +assert.commandWorked(st.s.adminCommand({movePrimary: dbName, to: st.shard0.shardName})); +assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {x: 1}})); + +assert.commandWorked(st.s.adminCommand({split: "test.foo", middle: {x: 0}})); + +// Set failpoint on mongos. +const failPoint = configureFailPoint(st.s, "pauseMongosSplitChunk"); + +// On parallel shell, split. +const awaitShell = startParallelShell( + () => { assert.commandWorked(db.adminCommand({split: "test.foo", middle: {x: 10}})); }, + st.s.port); + +// Wait for failpoint to be hit. +failPoint.wait(); + +// Move the chunk to the other shard +assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {x: 10}, to: st.shard1.shardName})); + +// Unset the failpoint. +failPoint.off(); + +awaitShell(); +st.stop(); +})(); diff --git a/src/mongo/s/commands/cluster_split_cmd.cpp b/src/mongo/s/commands/cluster_split_cmd.cpp index 5532fac1daf..db355153a24 100644 --- a/src/mongo/s/commands/cluster_split_cmd.cpp +++ b/src/mongo/s/commands/cluster_split_cmd.cpp @@ -45,10 +45,13 @@ #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/grid.h" #include "mongo/s/shard_util.h" +#include "mongo/util/fail_point.h" namespace mongo { namespace { +MONGO_FAIL_POINT_DEFINE(pauseMongosSplitChunk); + /** * Asks the mongod holding this chunk to find a key that approximately divides the specified chunk * in two. Throws on error or if the chunk is indivisible. @@ -134,6 +137,8 @@ public: Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx, nss)); + pauseMongosSplitChunk.pauseWhileSet(); + const BSONField findField("find", BSONObj()); const BSONField boundsField("bounds", BSONArray()); const BSONField middleField("middle", BSONObj());