summaryrefslogtreecommitdiff
path: root/jstests/sharding
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2016-04-22 14:10:33 -0400
committerRandolph Tan <randolph@10gen.com>2016-05-05 15:45:46 -0400
commitd5b670a01622ff5b9cd8dc1a988321022948182b (patch)
tree3eaf298e2815f11c5fefbaddec9cf0011efd0755 /jstests/sharding
parent9f91d422fc826d08b8eca8d323276c22d63ba436 (diff)
downloadmongo-d5b670a01622ff5b9cd8dc1a988321022948182b.tar.gz
SERVER-23765 Update config string of shardIdentity document
Diffstat (limited to 'jstests/sharding')
-rw-r--r--jstests/sharding/shard_identity_config_update.js116
1 files changed, 116 insertions, 0 deletions
diff --git a/jstests/sharding/shard_identity_config_update.js b/jstests/sharding/shard_identity_config_update.js
new file mode 100644
index 00000000000..b2952780d80
--- /dev/null
+++ b/jstests/sharding/shard_identity_config_update.js
@@ -0,0 +1,116 @@
+/**
+ * Tests that the config server connection string in the shard identity document of both the
+ * primary and secondary will get updated whenever the config server membership changes.
+ */
+(function() {
+ "use strict";
+
+ load('jstests/replsets/rslib.js');
+
+ var st = new ShardingTest({shards: {rs0: {nodes: 2}}});
+
+ // TODO: remove crutch once all node shard aware is complete.
+ var setupShardIdentity = function(conn, configConnStr) {
+ var shardIdentityDoc = {
+ _id: 'shardIdentity',
+ configsvrConnectionString: configConnStr,
+ shardName: 'newShard',
+ clusterId: ObjectId()
+ };
+
+ var res = conn.getDB('admin')
+ .system.version.update({_id: 'shardIdentity'}, shardIdentityDoc, true);
+ assert.eq(1, res.nUpserted);
+ };
+
+ var shardPri = st.rs0.getPrimary();
+ setupShardIdentity(st.rs0.getPrimary(), st.configRS.getURL());
+
+ // Note: Adding new replica set member by hand because of SERVER-24011.
+
+ var newNode = MongoRunner.runMongod(
+ {configsvr: '', replSet: st.configRS.name, storageEngine: 'wiredTiger'});
+
+ var replConfig = st.configRS.getReplSetConfigFromNode();
+ replConfig.version += 1;
+ replConfig.members.push({_id: 3, host: newNode.host});
+
+ reconfig(st.configRS, replConfig);
+
+ /**
+ * Returns true if the shardIdentity document has all the replica set member nodes in the
+ * expectedConfigStr.
+ */
+ var checkConfigStrUpdated = function(conn, expectedConfigStr) {
+ var shardIdentity = conn.getDB('admin').system.version.findOne({_id: 'shardIdentity'});
+
+ var shardConfigsvrStr = shardIdentity.configsvrConnectionString;
+ var shardConfigReplName = shardConfigsvrStr.split('/')[0];
+ var expectedReplName = expectedConfigStr.split('/')[0];
+
+ assert.eq(expectedReplName, shardConfigReplName);
+
+ var expectedHostList = expectedConfigStr.split('/')[1].split(',');
+ var shardConfigHostList = shardConfigsvrStr.split('/')[1].split(',');
+
+ if (expectedHostList.length != shardConfigHostList.length) {
+ return false;
+ }
+
+ for (var x = 0; x < expectedHostList.length; x++) {
+ if (shardConfigsvrStr.indexOf(expectedHostList[x]) == -1) {
+ return false;
+ }
+ }
+
+ return true;
+ };
+
+ var origConfigConnStr = st.configRS.getURL();
+ var expectedConfigStr = origConfigConnStr + ',' + newNode.host;
+ assert.soon(function() {
+ return checkConfigStrUpdated(st.rs0.getPrimary(), expectedConfigStr);
+ });
+
+ var secConn = st.rs0.getSecondary();
+ secConn.setSlaveOk(true);
+ assert.soon(function() {
+ return checkConfigStrUpdated(secConn, expectedConfigStr);
+ });
+
+ //
+ // Remove the newly added member from the config replSet while the shards are down.
+ // Check that the shard identity document will be updated with the new replSet connection
+ // string when they come back up.
+ //
+
+ st.rs0.stop(0);
+ st.rs0.stop(1);
+
+ MongoRunner.stopMongod(newNode.port);
+
+ replConfig = st.configRS.getReplSetConfigFromNode();
+ replConfig.version += 1;
+ replConfig.members.pop();
+
+ reconfig(st.configRS, replConfig);
+
+ st.rs0.restart(0, {shardsvr: ''});
+ st.rs0.restart(1, {shardsvr: ''});
+
+ st.rs0.waitForMaster();
+ st.rs0.awaitSecondaryNodes();
+
+ assert.soon(function() {
+ return checkConfigStrUpdated(st.rs0.getPrimary(), origConfigConnStr);
+ });
+
+ secConn = st.rs0.getSecondary();
+ secConn.setSlaveOk(true);
+ assert.soon(function() {
+ return checkConfigStrUpdated(secConn, origConfigConnStr);
+ });
+
+ st.stop();
+
+})();