diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2021-02-05 05:21:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-05 09:40:41 +0000 |
commit | f554448cbf6cd1dc3a561bc6b358fd79c8e8a1d4 (patch) | |
tree | b91a156fe34ec4530287364f971496c768ff8c99 /jstests/sharding/test_resharding_test_fixture_detects_unowned_docs.js | |
parent | 2bdf8c73962d53a98a8e048d10d718e6858e944b (diff) | |
download | mongo-f554448cbf6cd1dc3a561bc6b358fd79c8e8a1d4.tar.gz |
SERVER-53520 Assert recipients own all their docs in ReshardingTest.
Diffstat (limited to 'jstests/sharding/test_resharding_test_fixture_detects_unowned_docs.js')
-rw-r--r-- | jstests/sharding/test_resharding_test_fixture_detects_unowned_docs.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/jstests/sharding/test_resharding_test_fixture_detects_unowned_docs.js b/jstests/sharding/test_resharding_test_fixture_detects_unowned_docs.js new file mode 100644 index 00000000000..e2eb940aebb --- /dev/null +++ b/jstests/sharding/test_resharding_test_fixture_detects_unowned_docs.js @@ -0,0 +1,76 @@ +/** + * Test for the ReshardingTest fixture itself. + * + * Verifies that an exception is thrown if a recipient shard has a document it doesn't actually own. + * + * @tags: [ + * requires_fcv_49, + * uses_atclustertime, + * ] + */ +(function() { +"use strict"; + +load('jstests/libs/discover_topology.js'); +load("jstests/sharding/libs/resharding_test_fixture.js"); + +const reshardingTest = new ReshardingTest({numDonors: 1, numRecipients: 2}); +reshardingTest.setup(); + +const ns = "reshardingDb.coll"; +const donorShardNames = reshardingTest.donorShardNames; +const sourceCollection = reshardingTest.createShardedCollection({ + ns, + shardKeyPattern: {oldKey: 1}, + chunks: [{min: {oldKey: MinKey}, max: {oldKey: MaxKey}, shard: donorShardNames[0]}], +}); + +// Perform some inserts before resharding starts so there's data to clone. +assert.commandWorked(sourceCollection.insert([ + {_id: "moves to recipient0", oldKey: -10, newKey: -10}, + {_id: "moves to recipient1", oldKey: 10, newKey: 10}, +])); + +const mongos = sourceCollection.getMongo(); +const topology = DiscoverTopology.findConnectedNodes(mongos); + +const recipientShardNames = reshardingTest.recipientShardNames; +const recipient0 = new Mongo(topology.shards[recipientShardNames[0]].primary); + +const err = assert.throws(() => { + reshardingTest.withReshardingInBackground( + { + newShardKeyPattern: {newKey: 1}, + newChunks: [ + {min: {newKey: MinKey}, max: {newKey: 0}, shard: recipientShardNames[0]}, + {min: {newKey: 0}, max: {newKey: MaxKey}, shard: recipientShardNames[1]}, + ], + }, + (tempNs) => { + // Wait for the recipients to have finished cloning so the temporary resharding + // collection is known to exist. + assert.soon(() => { + const coordinatorDoc = + mongos.getCollection("config.reshardingOperations").findOne(); + return coordinatorDoc !== null && coordinatorDoc.state === "applying"; + }); + + // Insert a document directly into recipient0 that is truly owned by recipient1. + const tempColl = recipient0.getCollection(tempNs); + assert.commandWorked( + tempColl.insert({_id: "unowned by recipient0", oldKey: 10, newKey: 10})); + }); +}); + +assert(/temporary resharding collection had unowned documents/.test(err.message), err); + +// The ReshardingTest fixture will have interrupted the reshardCollection command on mongos so the +// JavaScript thread running the command can be joined. The resharding operation is still active on +// config server so we must manually wait for it to complete. +assert.soon(() => { + const coordinatorDoc = mongos.getCollection("config.reshardingOperations").findOne(); + return coordinatorDoc === null; +}); + +reshardingTest.teardown(); +})(); |