summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2022-08-09 15:47:04 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-09 16:29:30 +0000
commit6f918f3fed2333aa3d1ac213bd8176743a733895 (patch)
tree9964e9110f7ea146ec34cbc034a2d1b71fc9d321 /jstests
parentd56d5295aed750c2d9d585d78d1d224955b40a62 (diff)
downloadmongo-6f918f3fed2333aa3d1ac213bd8176743a733895.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')
-rw-r--r--jstests/sharding/libs/resharding_test_fixture.js5
-rw-r--r--jstests/sharding/resharding_temp_ns_routing_info_unsharded.js49
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 487eb751c57..330d68892fb 100644
--- a/jstests/sharding/libs/resharding_test_fixture.js
+++ b/jstests/sharding/libs/resharding_test_fixture.js
@@ -262,6 +262,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();
+})();