diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2015-07-07 16:29:21 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2015-07-27 17:32:17 -0400 |
commit | cd98b5f0e5673716acd9c11c73c01243ea503d69 (patch) | |
tree | 522b2a8ad87bdace4d357955880aa0c99a82b196 /jstests/replsets/protocol_version_upgrade_downgrade.js | |
parent | 5b759f3b3b704c93c59173789e393fcad6ee48f7 (diff) | |
download | mongo-cd98b5f0e5673716acd9c11c73c01243ea503d69.tar.gz |
SERVER-19606 Upgrade / downgrade of election protocol version
Diffstat (limited to 'jstests/replsets/protocol_version_upgrade_downgrade.js')
-rw-r--r-- | jstests/replsets/protocol_version_upgrade_downgrade.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/jstests/replsets/protocol_version_upgrade_downgrade.js b/jstests/replsets/protocol_version_upgrade_downgrade.js new file mode 100644 index 00000000000..214addff7e0 --- /dev/null +++ b/jstests/replsets/protocol_version_upgrade_downgrade.js @@ -0,0 +1,77 @@ +load("jstests/replsets/rslib.js"); + +(function() { + +"use strict"; +var name = "protocol_version_upgrade_downgrade"; +var rst = new ReplSetTest({name: name, nodes: 3}); + +rst.startSet(); +// Initiate the replset in protocol version 0. +var conf = rst.getReplSetConfig(); +conf.settings = conf.settings || { }; +conf.settings.protocolVersion = 0; +rst.initiate(conf); +rst.awaitSecondaryNodes(); + +var primary = rst.getMaster(); +var primaryColl = primary.getDB("test").coll; + +// Set verbosity for replication on all nodes. +var verbosity = { + "setParameter" : 1, + "logComponentVerbosity" : { + "replication" : { "verbosity" : 3 }, + } +} +primary.adminCommand(verbosity); +rst.getSecondaries().forEach(function (node) {node.adminCommand(verbosity)}); + +// Do a write, this will set up sync sources on secondaries. +print("do a write"); +assert.writeOK(primaryColl.bar.insert({x: 1}, {writeConcern: {w: 3}})); +// Check optime format in protocol version 0, which is a Timestamp. +var res = primary.adminCommand({replSetGetStatus: 1}); +assert.commandWorked(res); +assert.eq(res.members[0].optime.term, null); + +// +// Upgrade protocol version +// +res = primary.adminCommand({replSetGetConfig: 1}); +assert.commandWorked(res); +conf = res.config; +assert.eq(conf.settings.protocolVersion, 0); +// Change protocol version +conf.settings.protocolVersion = 1; +conf.version++; +reconfig(rst, conf); +// This write may block until all nodes finish upgrade, because replSetUpdatePosition may be +// rejected by the primary for mismatched config version before secondaries get reconfig. +// This will make secondaries blacklist the primary for 0.5 seconds. +assert.writeOK(primaryColl.bar.insert({x: 2}, {writeConcern: {w: 3}})); + +// Check optime format in protocol version 1, which is an object including the term. +res = primary.adminCommand({replSetGetStatus: 1}); +assert.commandWorked(res); +assert.eq(res.members[0].optime.term, NumberLong(0)); + +// +// Downgrade protocol version +// +res = primary.adminCommand({replSetGetConfig: 1}); +assert.commandWorked(res); +conf = res.config; +assert.eq(conf.settings.protocolVersion, 1); +// Change protocol version +conf.settings.protocolVersion = 0; +conf.version++; +reconfig(rst, conf); +assert.writeOK(primaryColl.bar.insert({x: 3}, {writeConcern: {w: 3}})); + +// Check optime format in protocol version 0, which is a Timestamp. +res = primary.adminCommand({replSetGetStatus: 1}); +assert.commandWorked(res); +assert.eq(res.members[0].optime.term, null); + +})(); |