diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2022-08-09 15:51:17 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-09 16:29:50 +0000 |
commit | 8e55aa4ae2719be344a689a678f96531d4f82629 (patch) | |
tree | 8ad300136714280bd3bc486bbc649b4352738d5a /jstests/sharding | |
parent | 315375bbda07e56c7ccbb703b0c5dd3e544ed48a (diff) | |
download | mongo-8e55aa4ae2719be344a689a678f96531d4f82629.tar.gz |
SERVER-68628 Refresh routing info on primary during resharding.
The primary of a replica set shard may otherwise have arbitrarily stale
routing information for the source collection and temporary resharding
collection based on the time of its last refresh.
(cherry picked from commit eda2f5d5d94ef0e7ec8016e5b9cad00d746f1787)
Diffstat (limited to 'jstests/sharding')
-rw-r--r-- | jstests/sharding/libs/resharding_test_fixture.js | 5 | ||||
-rw-r--r-- | jstests/sharding/resharding_temp_ns_routing_info_unsharded.js | 49 |
2 files changed, 54 insertions, 0 deletions
diff --git a/jstests/sharding/libs/resharding_test_fixture.js b/jstests/sharding/libs/resharding_test_fixture.js index 5785ada3200..ac6efd7b0d1 100644 --- a/jstests/sharding/libs/resharding_test_fixture.js +++ b/jstests/sharding/libs/resharding_test_fixture.js @@ -283,6 +283,11 @@ var ReshardingTest = class { return sourceCollection; } + get tempNs() { + assert.neq(undefined, this._tempNs, "createShardedCollection must be called first"); + return this._tempNs; + } + /** * Reshards an existing collection using the specified new shard key and new chunk ranges. * diff --git a/jstests/sharding/resharding_temp_ns_routing_info_unsharded.js b/jstests/sharding/resharding_temp_ns_routing_info_unsharded.js new file mode 100644 index 00000000000..d7616222920 --- /dev/null +++ b/jstests/sharding/resharding_temp_ns_routing_info_unsharded.js @@ -0,0 +1,49 @@ +/** + * Tests that write operations on the collection being resharded succeed even when the routing + * information for the associated temporary resharding collection is stale. + */ +(function() { +"use strict"; + +load("jstests/libs/discover_topology.js"); +load("jstests/libs/fail_point_util.js"); +load("jstests/sharding/libs/resharding_test_fixture.js"); + +const reshardingTest = new ReshardingTest({reshardInPlace: false}); +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]}], + primaryShardName: recipientShardNames[0], +}); + +const mongos = sourceCollection.getMongo(); +const topology = DiscoverTopology.findConnectedNodes(mongos); +const donor = new Mongo(topology.shards[donorShardNames[0]].primary); + +const reshardingPauseDonorBeforeCatalogCacheRefreshFailpoint = + configureFailPoint(donor, "reshardingPauseDonorBeforeCatalogCacheRefresh"); + +// We trigger a refresh to make the catalog cache track the routing info for the temporary +// resharding namespace as unsharded because the collection won't exist yet. +assert.commandWorked(donor.adminCommand({_flushRoutingTableCacheUpdates: reshardingTest.tempNs})); + +reshardingTest.withReshardingInBackground( // + { + newShardKeyPattern: {newKey: 1}, + newChunks: [{min: {newKey: MinKey}, max: {newKey: MaxKey}, shard: recipientShardNames[0]}], + }, + () => { + reshardingPauseDonorBeforeCatalogCacheRefreshFailpoint.wait(); + + assert.commandWorked(sourceCollection.insert({_id: 0, oldKey: 5, newKey: 15})); + reshardingPauseDonorBeforeCatalogCacheRefreshFailpoint.off(); + }); + +reshardingTest.teardown(); +})(); |