diff options
author | Matthew Saltz <matthew.saltz@mongodb.com> | 2019-10-21 17:44:33 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-10-21 17:44:33 +0000 |
commit | d7c96ec405d6fc319f32dabd9b4136d0c29bc99b (patch) | |
tree | 79eda2a0607913bdb56a7521798ed121bbf73b4b /jstests | |
parent | 23ce0082bdb2cac0df95cacf013a5272a5d95942 (diff) | |
download | mongo-d7c96ec405d6fc319f32dabd9b4136d0c29bc99b.tar.gz |
SERVER-41480 Increment major version on splits where the shard version equals the collection version
(cherry picked from commit 790609ffb6bc1dac0a3c13d1898d5884e21a1b7a)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/sharding/major_version_check.js | 18 | ||||
-rw-r--r-- | jstests/sharding/migration_failure.js | 6 | ||||
-rw-r--r-- | jstests/sharding/zero_shard_version.js | 30 |
3 files changed, 36 insertions, 18 deletions
diff --git a/jstests/sharding/major_version_check.js b/jstests/sharding/major_version_check.js index eb6eccc1f1e..baa01aa7966 100644 --- a/jstests/sharding/major_version_check.js +++ b/jstests/sharding/major_version_check.js @@ -27,7 +27,7 @@ printjson(admin.runCommand({getShardVersion: coll + ""})); printjson(staleMongos.getDB("admin").runCommand({getShardVersion: coll + ""})); // Compare strings b/c timestamp comparison is a bit weird -assert.eq(Timestamp(1, 2), admin.runCommand({getShardVersion: coll + ""}).version); +assert.eq(Timestamp(2, 2), admin.runCommand({getShardVersion: coll + ""}).version); assert.eq(Timestamp(1, 0), staleMongos.getDB("admin").runCommand({getShardVersion: coll + ""}).version); @@ -48,5 +48,21 @@ printjson(staleMongos.getDB("admin").runCommand({getShardVersion: coll + ""})); assert.eq(Timestamp(1, 0), staleMongos.getDB("admin").runCommand({getShardVersion: coll + ""}).version); +// Run another split on the original chunk, which does not exist anymore (but the stale mongos +// thinks it exists). This should fail and cause a refresh on the shard, updating its shard +// version. +assert.commandFailed(staleMongos.getDB("admin").runCommand( + {split: coll + "", bounds: [{_id: MinKey}, {_id: MaxKey}]})); + +// This findOne will cause a refresh on the router since the shard version has now been +// increased. +staleMongos.getCollection(coll + "").findOne(); + +printjson(staleMongos.getDB("admin").runCommand({getShardVersion: coll + ""})); + +// The previously stale mongos should now be up-to-date. +assert.eq(Timestamp(2, 2), + staleMongos.getDB("admin").runCommand({getShardVersion: coll + ""}).version); + st.stop(); })(); diff --git a/jstests/sharding/migration_failure.js b/jstests/sharding/migration_failure.js index f731c0d3614..7f05dd1f9bb 100644 --- a/jstests/sharding/migration_failure.js +++ b/jstests/sharding/migration_failure.js @@ -30,6 +30,12 @@ var newVersion = null; assert.commandWorked(st.shard0.getDB("admin").runCommand( {configureFailPoint: 'failMigrationCommit', mode: 'alwaysOn'})); +// The split command above bumps the shard version, and this is obtained by the router via a +// refresh at the end of the command, but the shard does not know about it yet. This find will +// cause the shard to refresh so that this next check for 'oldVersion' sees the most recent +// version prior to the migration. +coll.findOne(); + oldVersion = st.shard0.getDB("admin").runCommand({getShardVersion: coll.toString()}).global; assert.commandFailed( diff --git a/jstests/sharding/zero_shard_version.js b/jstests/sharding/zero_shard_version.js index 7d08bf34d36..209eff8e49c 100644 --- a/jstests/sharding/zero_shard_version.js +++ b/jstests/sharding/zero_shard_version.js @@ -87,7 +87,7 @@ testDB_s1.adminCommand({shardCollection: 'test.user', key: {x: 1}}); testDB_s1.adminCommand({split: 'test.user', middle: {x: 0}}); // shard0: 0|0|b, -// shard1: 1|1|b, [-inf, 0), [0, inf) +// shard1: 2|1|b, [-inf, 0), [0, inf) testDB_s1.user.insert({x: 1}); testDB_s1.user.insert({x: -11}); @@ -97,45 +97,41 @@ assert.commandWorked( st.configRS.awaitLastOpCommitted(); // Official config: -// shard0: 2|0|b, [-inf, 0) -// shard1: 2|1|b, [0, inf) +// shard0: 3|0|b, [-inf, 0) +// shard1: 3|1|b, [0, inf) // // Shard metadata: // shard0: 0|0|b -// shard1: 2|1|b +// shard1: 3|1|b // // mongos2: 2|0|a checkShardMajorVersion(st.rs0.getPrimary(), 0); -checkShardMajorVersion(st.rs1.getPrimary(), 2); +checkShardMajorVersion(st.rs1.getPrimary(), 3); // mongos2 still thinks that { x: 1 } belong to st.shard0.shardName, but should be able to // refresh it's metadata correctly. assert.neq(null, testDB_s2.user.findOne({x: 1})); -checkShardMajorVersion(st.rs0.getPrimary(), 2); -checkShardMajorVersion(st.rs1.getPrimary(), 2); +checkShardMajorVersion(st.rs0.getPrimary(), 3); +checkShardMajorVersion(st.rs1.getPrimary(), 3); // Set shard metadata to 2|0|b assert.neq(null, testDB_s2.user.findOne({x: -11})); -checkShardMajorVersion(st.rs0.getPrimary(), 2); -checkShardMajorVersion(st.rs1.getPrimary(), 2); +checkShardMajorVersion(st.rs0.getPrimary(), 3); +checkShardMajorVersion(st.rs1.getPrimary(), 3); // Official config: -// shard0: 2|0|b, [-inf, 0) -// shard1: 2|1|b, [0, inf) +// shard0: 3|0|b, [-inf, 0) +// shard1: 3|1|b, [0, inf) // // Shard metadata: -// shard0: 2|0|b -// shard1: 2|1|b +// shard0: 3|0|b +// shard1: 3|1|b // // mongos3: 2|0|a -// 4th mongos still thinks that { x: 1 } belong to st.shard0.shardName, but should be able to -// refresh it's metadata correctly. -assert.neq(null, testDB_s3.user.findOne({x: 1})); - /////////////////////////////////////////////////////// // Test mongos thinks unsharded when it's actually sharded // mongos current versions: s0: 0|0|0, s2, s3: 2|0|b |