diff options
author | Marcos José Grillo Ramírez <marcos.grillo@10gen.com> | 2019-11-21 10:55:40 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-21 10:55:40 +0000 |
commit | f48da7a0f83762d214128799923e4bcede800dbe (patch) | |
tree | 4235e34ce3bd254e3513fef90996da252e4fc645 /jstests | |
parent | 57f2fc733c2db98f3cab55250f4d31458234836d (diff) | |
download | mongo-f48da7a0f83762d214128799923e4bcede800dbe.tar.gz |
SERVER-43990 A command to confirm that all chunks have been moved to the right zone after the initial split
Diffstat (limited to 'jstests')
8 files changed, 137 insertions, 0 deletions
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js index 408b1fdbea2..4f1f1d88899 100644 --- a/jstests/auth/lib/commands_lib.js +++ b/jstests/auth/lib/commands_lib.js @@ -5664,6 +5664,22 @@ var authCommandsLib = { }, ] }, + { + testname: "balancerCollectionStatus", + command: {shardCollection: "test.x"}, + skipUnlessSharded: true, + testcases: [ + { + runOnDb: adminDbName, + roles: Object.extend({enableSharding: 1}, roles_clusterManager), + privileges: + [{resource: {db: "test", collection: "x"}, actions: ["enableSharding"]}], + expectFail: true + }, + {runOnDb: firstDbName, roles: {}}, + {runOnDb: secondDbName, roles: {}} + ] + }, ], /************* SHARED TEST LOGIC ****************/ diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index 20fc61b2fdd..9a7e4f778a8 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -75,6 +75,7 @@ let viewsCommandTests = { _cloneCollectionOptionsFromPrimaryShard: {skip: isAnInternalCommand}, _configsvrAddShard: {skip: isAnInternalCommand}, _configsvrAddShardToZone: {skip: isAnInternalCommand}, + _configsvrBalancerCollectionStatus: {skip: isAnInternalCommand}, _configsvrBalancerStart: {skip: isAnInternalCommand}, _configsvrBalancerStatus: {skip: isAnInternalCommand}, _configsvrBalancerStop: {skip: isAnInternalCommand}, @@ -128,6 +129,16 @@ let viewsCommandTests = { }, authenticate: {skip: isUnrelated}, availableQueryOptions: {skip: isAnInternalCommand}, + balancerCollectionStatus: { + command: {balancerCollectionStatus: "test.view"}, + setup: function(conn) { + assert.commandWorked(conn.adminCommand({enableSharding: "test"})); + }, + skipStandalone: true, + expectFailure: true, + isAdminCommand: true, + expectedErrorCode: ErrorCodes.NamespaceNotSharded, + }, balancerStart: {skip: isUnrelated}, balancerStatus: {skip: isUnrelated}, balancerStop: {skip: isUnrelated}, diff --git a/jstests/sharding/balancer_collection_status.js b/jstests/sharding/balancer_collection_status.js new file mode 100644 index 00000000000..e1cbb8f48c0 --- /dev/null +++ b/jstests/sharding/balancer_collection_status.js @@ -0,0 +1,102 @@ +/** + * Test the balancerCollectionStatus command and its possible outputs + * + * Remove requires_fcv_44 tag if SERVER-43990 is backported or 4.4 becomes last-stable. + * @tags: [requires_fcv_44] + */ + +(function() { +'use strict'; + +var st = new ShardingTest({mongos: 1, shards: 3}); + +function runBalancer(rounds) { + st.startBalancer(); + let numRounds = 0; + + // Let the balancer run for caller specified number of rounds. + assert.soon(() => { + st.awaitBalancerRound(); + st.printShardingStatus(true); + numRounds++; + return (numRounds === rounds); + }, 'Balancer failed to run for ' + rounds + ' rounds', 1000 * 60 * (3 * rounds)); + + st.stopBalancer(); +} + +// only fully quilified namespaces are allowed on the command +assert.commandFailedWithCode(st.s0.adminCommand({balancerCollectionStatus: 'db'}), + ErrorCodes.InvalidNamespace); + +// only sharded databases are allowed +assert.commandFailedWithCode(st.s0.adminCommand({balancerCollectionStatus: 'db.col'}), + ErrorCodes.NamespaceNotFound); + +// setup the collection for the test +assert.commandWorked(st.s0.adminCommand({enableSharding: 'db'})); +assert.commandWorked(st.s0.adminCommand({shardCollection: 'db.col', key: {key: 1}})); + +// only sharded collections are allowed +assert.commandFailedWithCode(st.s0.adminCommand({balancerCollectionStatus: 'db.col2'}), + ErrorCodes.NamespaceNotSharded); + +var result = assert.commandWorked(st.s0.adminCommand({balancerCollectionStatus: 'db.col'})); + +// new collections must be balanced +assert.eq(result.status, 'balanced'); + +// get shardIds +var shards = st.s0.getDB('config').shards.find().toArray(); + +// manually split and place the 3 chunks on the same shard +assert.commandWorked(st.s0.adminCommand({split: 'db.col', middle: {key: 10}})); +assert.commandWorked(st.s0.adminCommand({split: 'db.col', middle: {key: 20}})); +assert.commandWorked(st.s0.adminCommand({moveChunk: 'db.col', find: {key: 0}, to: shards[0]._id})); +assert.commandWorked(st.s0.adminCommand({moveChunk: 'db.col', find: {key: 10}, to: shards[0]._id})); +assert.commandWorked(st.s0.adminCommand({moveChunk: 'db.col', find: {key: 20}, to: shards[0]._id})); + +// check the current status +result = assert.commandWorked(st.s0.adminCommand({balancerCollectionStatus: 'db.col'})); + +// chunksImbalanced expected +assert.eq(result.status, 'chunksImbalance'); + +// run balancer with 3 rounds +runBalancer(3); + +// the chunks must be balanced now +result = assert.commandWorked(st.s0.adminCommand({balancerCollectionStatus: 'db.col'})); + +assert.eq(result.status, 'balanced'); + +// manually move a chunk to a shard before creating zones (this will help +// testing the zone violation) +assert.commandWorked(st.s0.adminCommand({moveChunk: 'db.col', find: {key: 10}, to: shards[2]._id})); + +// create zones on first two shards only +assert.commandWorked(st.s0.adminCommand({addShardToZone: shards[0]._id, zone: 'zone0'})); +assert.commandWorked(st.s0.adminCommand( + {updateZoneKeyRange: 'db.col', min: {key: MinKey}, max: {key: 10}, zone: 'zone0'})); + +assert.commandWorked(st.s0.adminCommand({addShardToZone: shards[1]._id, zone: 'zone1'})); +assert.commandWorked(st.s0.adminCommand( + {updateZoneKeyRange: 'db.col', min: {key: 10}, max: {key: 20}, zone: 'zone1'})); + +result = assert.commandWorked(st.s0.adminCommand({balancerCollectionStatus: 'db.col'})); + +// having a chunk on a different zone will cause a zone violation +assert.eq(result.status, 'zoneViolation'); + +// run balancer, we don't know exactly where the first run moved the chunks +// so lets run 3 rounds just in case +runBalancer(3); + +// the chunks must be balanced now +result = assert.commandWorked(st.s0.adminCommand({balancerCollectionStatus: 'db.col'})); + +// final check: all chunks are balanced and in the correct zone +assert.eq(result.status, 'balanced'); + +st.stop(); +})();
\ No newline at end of file diff --git a/jstests/sharding/database_versioning_all_commands.js b/jstests/sharding/database_versioning_all_commands.js index 10754c7f8ef..5ce6d28e2a2 100644 --- a/jstests/sharding/database_versioning_all_commands.js +++ b/jstests/sharding/database_versioning_all_commands.js @@ -252,6 +252,7 @@ let testCases = { }, authenticate: {skip: "does not forward command to primary shard"}, availableQueryOptions: {skip: "executes locally on mongos (not sent to any remote node)"}, + balancerCollectionStatus: {skip: "does not forward command to primary shard"}, balancerStart: {skip: "not on a user database"}, balancerStatus: {skip: "not on a user database"}, balancerStop: {skip: "not on a user database"}, diff --git a/jstests/sharding/safe_secondary_reads_drop_recreate.js b/jstests/sharding/safe_secondary_reads_drop_recreate.js index aa08f7a6732..b7455ba3de1 100644 --- a/jstests/sharding/safe_secondary_reads_drop_recreate.js +++ b/jstests/sharding/safe_secondary_reads_drop_recreate.js @@ -41,6 +41,7 @@ let testCases = { _shardsvrCloneCatalogData: {skip: "primary only"}, _configsvrAddShard: {skip: "primary only"}, _configsvrAddShardToZone: {skip: "primary only"}, + _configsvrBalancerCollectionStatus: {skip: "primary only"}, _configsvrBalancerStart: {skip: "primary only"}, _configsvrBalancerStatus: {skip: "primary only"}, _configsvrBalancerStop: {skip: "primary only"}, @@ -87,6 +88,7 @@ let testCases = { authSchemaUpgrade: {skip: "primary only"}, authenticate: {skip: "does not return user data"}, availableQueryOptions: {skip: "does not return user data"}, + balancerCollectionStatus: {skip: "primary only"}, balancerStart: {skip: "primary only"}, balancerStatus: {skip: "primary only"}, balancerStop: {skip: "primary only"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js index aa47096339a..96f2efd2978 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js @@ -48,6 +48,7 @@ let testCases = { _shardsvrCloneCatalogData: {skip: "primary only"}, _configsvrAddShard: {skip: "primary only"}, _configsvrAddShardToZone: {skip: "primary only"}, + _configsvrBalancerCollectionStatus: {skip: "primary only"}, _configsvrBalancerStart: {skip: "primary only"}, _configsvrBalancerStatus: {skip: "primary only"}, _configsvrBalancerStop: {skip: "primary only"}, @@ -100,6 +101,7 @@ let testCases = { authSchemaUpgrade: {skip: "primary only"}, authenticate: {skip: "does not return user data"}, availableQueryOptions: {skip: "does not return user data"}, + balancerCollectionStatus: {skip: "primary only"}, balancerStart: {skip: "primary only"}, balancerStatus: {skip: "primary only"}, balancerStop: {skip: "primary only"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js index efa99b0c6ad..d310da83d9e 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js @@ -41,6 +41,7 @@ let testCases = { _shardsvrCloneCatalogData: {skip: "primary only"}, _configsvrAddShard: {skip: "primary only"}, _configsvrAddShardToZone: {skip: "primary only"}, + _configsvrBalancerCollectionStatus: {skip: "primary only"}, _configsvrBalancerStart: {skip: "primary only"}, _configsvrBalancerStatus: {skip: "primary only"}, _configsvrBalancerStop: {skip: "primary only"}, @@ -88,6 +89,7 @@ let testCases = { authenticate: {skip: "does not return user data"}, authSchemaUpgrade: {skip: "primary only"}, availableQueryOptions: {skip: "does not return user data"}, + balancerCollectionStatus: {skip: "primary only"}, balancerStart: {skip: "primary only"}, balancerStatus: {skip: "primary only"}, balancerStop: {skip: "primary only"}, diff --git a/jstests/sharding/track_unsharded_collections_check_shard_version.js b/jstests/sharding/track_unsharded_collections_check_shard_version.js index 3020d78a397..9ff6e225d6b 100644 --- a/jstests/sharding/track_unsharded_collections_check_shard_version.js +++ b/jstests/sharding/track_unsharded_collections_check_shard_version.js @@ -72,6 +72,7 @@ let testCases = { }, authenticate: {skip: "does not forward command to primary shard"}, availableQueryOptions: {skip: "executes locally on mongos (not sent to any remote node)"}, + balancerCollectionStatus: {skip: "does not forward command to primary shard"}, balancerStart: {skip: "not on a user database"}, balancerStatus: {skip: "not on a user database"}, balancerStop: {skip: "not on a user database"}, |