summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaley Connelly <haley.connelly@mongodb.com>2021-06-11 19:19:21 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-15 16:16:44 +0000
commitbd99c0e253f6b24a75eb481a7258220932a971cf (patch)
treedaa7e27dbb8976b1ec0181931d7046f0b818f146
parent9a804b395df987000d8bdab9ef14ef1ba19e03df (diff)
downloadmongo-bd99c0e253f6b24a75eb481a7258220932a971cf.tar.gz
SERVER-57656 Use ReshardingTestFixture for reshard_collection_joins_existing_operation.js
(cherry picked from commit 3660b0ceb0ad60601d0f56268be9de847e6d85ee)
-rw-r--r--jstests/sharding/reshard_collection_joins_existing_operation.js118
1 files changed, 49 insertions, 69 deletions
diff --git a/jstests/sharding/reshard_collection_joins_existing_operation.js b/jstests/sharding/reshard_collection_joins_existing_operation.js
index 0ee7dce2b64..e6654a232aa 100644
--- a/jstests/sharding/reshard_collection_joins_existing_operation.js
+++ b/jstests/sharding/reshard_collection_joins_existing_operation.js
@@ -1,7 +1,7 @@
/**
- * Tests that if a _configsvrReshardCollection command is issued and then the same command gets
- * issued again, the second command issued joins with the instance of resharding already in
- * progress.
+ * Tests that if a _configsvrReshardCollection command is issued while there is an ongoing
+ * resharding operation for the same collection with the same resharding key, the command joins with
+ * the ongoing resharding instance.
*
* Use _configsvrReshardCollection instead of reshardCollection to exercise the behavior of the
* config server in the absence of the distributed lock taken by _shardsvrReshardCollection on the
@@ -20,96 +20,76 @@ load("jstests/libs/parallelTester.js");
load("jstests/sharding/libs/resharding_test_fixture.js");
// Generates a new thread to run _configsvrReshardCollection.
-const makeConfigsvrReshardCollectionThread = (mongosConnString, configsvrReshardCollectionCmd) => {
- return new Thread((mongosConnString, configsvrReshardCollectionCmd) => {
- load("jstests/libs/discover_topology.js");
- const mongos = new Mongo(mongosConnString);
- const topology = DiscoverTopology.findConnectedNodes(mongos);
- const configsvr = new Mongo(topology.configsvr.nodes[0]);
- assert.commandWorked(configsvr.adminCommand(configsvrReshardCollectionCmd));
- }, mongosConnString, configsvrReshardCollectionCmd);
+const makeConfigsvrReshardCollectionThread = (configsvrConnString, ns) => {
+ return new Thread((configsvrConnString, ns) => {
+ const configsvr = new Mongo(configsvrConnString);
+ assert.commandWorked(configsvr.adminCommand(
+ {_configsvrReshardCollection: ns, key: {newKey: 1}, writeConcern: {w: "majority"}}));
+ }, configsvrConnString, ns);
};
-const constructTempReshardingNs = (dbName, collName) => {
- const sourceCollectionUUID = getUUIDFromListCollections(dbName, collName);
- const sourceCollectionUUIDString = extractUUIDFromObject(sourceCollectionUUID);
- return `${dbName}.system.resharding.${sourceCollectionUUIDString}`;
-};
-
-// Callers must ensure the temporary collection has actually been created by the time this is
-// called.
const getTempUUID = (tempNs) => {
const tempCollection = mongos.getCollection(tempNs);
return getUUIDFromConfigCollections(mongos, tempCollection.getFullName());
};
-const st = new ShardingTest({
- mongos: 1,
- config: 1,
- shards: 2,
- rs: {nodes: 2},
+const reshardingTest = new ReshardingTest({numDonors: 1});
+reshardingTest.setup();
+const donorShardNames = reshardingTest.donorShardNames;
+const recipientShardNames = reshardingTest.recipientShardNames;
+const sourceCollection = reshardingTest.createShardedCollection({
+ ns: "reshardingDb.coll",
+ shardKeyPattern: {oldKey: 1},
+ chunks: [{min: {oldKey: MinKey}, max: {oldKey: MaxKey}, shard: donorShardNames[0]}],
});
-const sourceCollection = st.s.getCollection("reshardingDb.coll");
-
-CreateShardedCollectionUtil.shardCollectionWithChunks(sourceCollection, {oldKey: 1}, [
- {min: {oldKey: MinKey}, max: {oldKey: MaxKey}, shard: st.shard0.shardName},
-]);
-
-const reshardKey = {
- newKey: 1
-};
-const configsvrReshardCollectionCmd = {
- _configsvrReshardCollection: sourceCollection.getFullName(),
- key: reshardKey,
- writeConcern: {w: "majority"}
-};
-
-// Before starting the actual resharding, get the source collection's UUID to construct the
-// namespace for the temporary collection that will be created.
-const sourceDBName = sourceCollection.getDB();
-const sourceCollName = sourceCollection.getName();
-const tempNs = constructTempReshardingNs(sourceDBName, sourceCollName);
-
const mongos = sourceCollection.getMongo();
const topology = DiscoverTopology.findConnectedNodes(mongos);
const configsvr = new Mongo(topology.configsvr.nodes[0]);
-const reshardCollectionThread1 =
- makeConfigsvrReshardCollectionThread(topology.mongos.nodes[0], configsvrReshardCollectionCmd);
const pauseBeforeCloningFP =
configureFailPoint(configsvr, "reshardingPauseCoordinatorBeforeCloning");
-// Issue the first _configsvrReshardCollection command and pause after the temporary collection is
-// created but before its config.collections entry is replaced.
-reshardCollectionThread1.start();
-pauseBeforeCloningFP.wait();
+const configsvrReshardCollectionThread = makeConfigsvrReshardCollectionThread(
+ topology.configsvr.nodes[0], sourceCollection.getFullName());
+
+// Fulfilled once the first reshardCollection command creates the temporary collection.
+let expectedUUIDAfterReshardingCompletes = undefined;
+
+reshardingTest.withReshardingInBackground(
+ {
+ newShardKeyPattern: {newKey: 1},
+ newChunks: [{min: {newKey: MinKey}, max: {newKey: MaxKey}, shard: recipientShardNames[0]}],
+ },
+ (tempNs) => {
+ pauseBeforeCloningFP.wait();
+
+ // The UUID of the temporary resharding collection should become the UUID of the original
+ // collection once resharding has completed.
+ expectedUUIDAfterReshardingCompletes = getTempUUID(tempNs);
-// The UUID of the temporary resharding collection should become the UUID of the original collection
-// once resharding has completed.
-const expectedUUIDAfterReshardingCompletes = getTempUUID(tempNs);
+ const reshardCollectionJoinedFP =
+ configureFailPoint(configsvr, "reshardCollectionJoinedExistingOperation");
-const reshardCollectionJoinedFP =
- configureFailPoint(configsvr, "reshardCollectionJoinedExistingOperation");
-const reshardCollectionThread2 =
- makeConfigsvrReshardCollectionThread(topology.mongos.nodes[0], configsvrReshardCollectionCmd);
+ configsvrReshardCollectionThread.start();
-// Hitting the reshardCollectionJoinedFP is additional confirmation that the second
-// _configsvrReshardCollection command (identical to the first) gets joined with the instance
-// created/running for the first command issued.
-reshardCollectionThread2.start();
-reshardCollectionJoinedFP.wait();
+ // Hitting the reshardCollectionJoinedFP is additional confirmation that
+ // _configsvrReshardCollection command (identical resharding key and collection as the
+ // ongoing operation) gets joined with the ongoing resharding operation.
+ reshardCollectionJoinedFP.wait();
-reshardCollectionJoinedFP.off();
-pauseBeforeCloningFP.off();
+ reshardCollectionJoinedFP.off();
+ pauseBeforeCloningFP.off();
+ });
-reshardCollectionThread2.join();
-reshardCollectionThread1.join();
+configsvrReshardCollectionThread.join();
// Confirm the UUID for the namespace that was resharded is the same as the temporary collection's
// UUID before the second reshardCollection command was issued.
-const finalSourceCollectionUUID = getUUIDFromListCollections(sourceDBName, sourceCollName);
+assert.neq(expectedUUIDAfterReshardingCompletes, undefined);
+const finalSourceCollectionUUID =
+ getUUIDFromListCollections(sourceCollection.getDB(), sourceCollection.getName());
assert.eq(expectedUUIDAfterReshardingCompletes, finalSourceCollectionUUID);
-st.stop();
+reshardingTest.teardown();
})();