summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2016-04-20 17:19:30 -0400
committerRandolph Tan <randolph@10gen.com>2016-04-26 11:55:19 -0400
commit2423026ef06c43d7de4fa54095702698b359a4f9 (patch)
treec7c3e1ea66c5021864d855c7f95b0b0f55db068c /jstests
parent5c3e0d4855415cbab4bd75732208f832c11f4889 (diff)
downloadmongo-2423026ef06c43d7de4fa54095702698b359a4f9.tar.gz
SERVER-23814 Add sharding state initialization to secondaries
Outside of the OpObserver, there are currently 2 places where shard initialization occurs: during startup and during transition to primary. This patch takes out the if !replSet condition in startup so secondaries will now also perform shard initialization. This also means that if the node will eventually become a primary, it will perform the initialization twice. However, since it is already initialized, most of it will be no-op the second time around. In summary: - secondaries initializes sharding state. - nodes that will become primary will do what secondaries do. And on top of that, will read the minOpTime document and update it if minOpTimeUpdaters > 0.
Diffstat (limited to 'jstests')
-rw-r--r--jstests/sharding/shard_aware_init_secondaries.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/jstests/sharding/shard_aware_init_secondaries.js b/jstests/sharding/shard_aware_init_secondaries.js
new file mode 100644
index 00000000000..8d58c199637
--- /dev/null
+++ b/jstests/sharding/shard_aware_init_secondaries.js
@@ -0,0 +1,62 @@
+/**
+ * Tests for shard aware initialization on secondaries during startup and shard
+ * identity document creation.
+ * @tags: [requires_persistence]
+ */
+
+(function() {
+ "use strict";
+
+ var st = new ShardingTest({shards: 1});
+
+ var replTest = new ReplSetTest({nodes: 2});
+ replTest.startSet({shardsvr: ''});
+ var nodeList = replTest.nodeList();
+ replTest.initiate({
+ _id: replTest.name,
+ members:
+ [{_id: 0, host: nodeList[0], priority: 1}, {_id: 1, host: nodeList[1], priority: 0}]
+ });
+
+ var priConn = replTest.getPrimary();
+ var configConnStr = st.configRS.getURL();
+
+ var shardIdentityDoc = {
+ _id: 'shardIdentity',
+ configsvrConnectionString: configConnStr,
+ shardName: 'newShard',
+ clusterId: ObjectId()
+ };
+
+ assert.writeOK(priConn.getDB('admin').system.version.update(
+ {_id: 'shardIdentity'}, shardIdentityDoc, {upsert: true, writeConcern: {w: 2}}));
+
+ var secConn = replTest.getSecondary();
+ secConn.setSlaveOk(true);
+
+ var res = secConn.getDB('admin').runCommand({shardingState: 1});
+
+ assert(res.enabled, tojson(res));
+ assert.eq(shardIdentityDoc.configsvrConnectionString, res.configServer);
+ assert.eq(shardIdentityDoc.shardName, res.shardName);
+ assert.eq(shardIdentityDoc.clusterId, res.clusterId);
+
+ var newMongodOptions = Object.extend(secConn.savedOptions, {restart: true});
+ replTest.restart(replTest.getNodeId(secConn), newMongodOptions);
+ replTest.waitForMaster();
+ replTest.awaitSecondaryNodes();
+
+ secConn = replTest.getSecondary();
+ secConn.setSlaveOk(true);
+
+ res = secConn.getDB('admin').runCommand({shardingState: 1});
+
+ assert(res.enabled, tojson(res));
+ assert.eq(shardIdentityDoc.configsvrConnectionString, res.configServer);
+ assert.eq(shardIdentityDoc.shardName, res.shardName);
+ assert.eq(shardIdentityDoc.clusterId, res.clusterId);
+
+ replTest.stopSet();
+
+ st.stop();
+})();