From bbaf069f100e86664b7795d097f0c802fe3965df Mon Sep 17 00:00:00 2001 From: Randolph Tan Date: Wed, 23 Mar 2016 17:32:02 -0400 Subject: SERVER-22661 Require --shardsvr for shard aware initialization --- jstests/sharding/shard_aware_init.js | 58 ++++++++++++++++++++--- jstests/sharding/shard_aware_primary_failover.js | 2 +- jstests/sharding/sharding_state_after_stepdown.js | 4 +- 3 files changed, 55 insertions(+), 9 deletions(-) (limited to 'jstests') diff --git a/jstests/sharding/shard_aware_init.js b/jstests/sharding/shard_aware_init.js index 0679096d1c2..b97c459c007 100644 --- a/jstests/sharding/shard_aware_init.js +++ b/jstests/sharding/shard_aware_init.js @@ -27,6 +27,37 @@ clusterId: ObjectId() }; + /** + * Restarts the server without --shardsvr and replace the shardIdentity doc with a valid + * document. Then, restarts the server again with --shardsvr. This also returns a + * connection to the server after the last restart. + */ + var restartAndFixShardIdentityDoc = function(startOptions) { + var options = Object.extend({}, startOptions); + delete options.shardsvr; + mongodConn = MongoRunner.runMongod(options); + waitForMaster(mongodConn); + + var res = mongodConn.getDB('admin') + .system.version.update({_id: 'shardIdentity'}, shardIdentityDoc); + assert.eq(1, res.nModified); + + MongoRunner.stopMongod(mongodConn.port); + + newMongodOptions.shardsvr = ''; + mongodConn = MongoRunner.runMongod(newMongodOptions); + waitForMaster(mongodConn); + + res = mongodConn.getDB('admin').runCommand({shardingState: 1}); + + assert(res.enabled); + assert.eq(shardIdentityDoc.configsvrConnectionString, res.configServer); + assert.eq(shardIdentityDoc.shardName, res.shardName); + assert.eq(shardIdentityDoc.clusterId, res.clusterId); + + return mongodConn; + }; + assert.writeOK(mongodConn.getDB('admin').system.version.insert(shardIdentityDoc)); // @@ -51,7 +82,7 @@ assert.eq(shardIdentityDoc.clusterId, res.clusterId); // - // Test badly formatted shardIdentity doc + // Test shardIdentity doc without configsvrConnectionString, resulting into parse error // assert.writeOK(mongodConn.getDB('admin').system.version.update( @@ -65,25 +96,40 @@ waitForMaster(mongodConn); }); - // TODO: add more bad format tests. + // + // Test that it is possible to fix the invalid shardIdentity doc by not passing --shardsvr + // + + try { + // The server was terminated not by calling stopMongod earlier, this will cleanup + // the process from registry in shell_utils_launcher. + MongoRunner.stopMongod(newMongodOptions.port); + } catch (ex) { + if (!(ex instanceof (MongoRunner.StopError))) { + throw ex; + } + } + + mongodConn = restartAndFixShardIdentityDoc(newMongodOptions); + res = mongodConn.getDB('admin').runCommand({shardingState: 1}); + assert(res.enabled); }; var st = new ShardingTest({shards: 1}); - var mongod = MongoRunner.runMongod(); + var mongod = MongoRunner.runMongod({shardsvr: ''}); runTest(mongod, st.configRS.getURL()); MongoRunner.stopMongod(mongod.port); var replTest = new ReplSetTest({nodes: 1}); - replTest.startSet(); + replTest.startSet({shardsvr: ''}); replTest.initiate(); runTest(replTest.getPrimary(), st.configRS.getURL()); - // TODO: cleanup properly once --shardsvr checks are added - // replTest.stopSet(); + replTest.stopSet(); st.stop(); diff --git a/jstests/sharding/shard_aware_primary_failover.js b/jstests/sharding/shard_aware_primary_failover.js index 6fac918494e..0d939c6e1ea 100644 --- a/jstests/sharding/shard_aware_primary_failover.js +++ b/jstests/sharding/shard_aware_primary_failover.js @@ -8,7 +8,7 @@ var st = new ShardingTest({shards: 1}); var replTest = new ReplSetTest({nodes: 3}); - replTest.startSet(); + replTest.startSet({shardsvr: ''}); var nodes = replTest.nodeList(); replTest.initiate({ _id: replTest.name, diff --git a/jstests/sharding/sharding_state_after_stepdown.js b/jstests/sharding/sharding_state_after_stepdown.js index f5d9896a0d0..3007b4b08a2 100644 --- a/jstests/sharding/sharding_state_after_stepdown.js +++ b/jstests/sharding/sharding_state_after_stepdown.js @@ -45,8 +45,8 @@ false }); - st.rs0.start(rs0Primary, {restart: true}); - st.rs1.start(rs1Primary, {restart: true}); + st.rs0.start(rs0Primary, Object.extend(rs0Primary.savedOptions, {restart: true})); + st.rs1.start(rs1Primary, Object.extend(rs1Primary.savedOptions, {restart: true})); ReplSetTest.awaitRSClientHosts(mongos, [rs0Primary, rs1Primary], -- cgit v1.2.1