summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2017-02-23 17:19:27 -0500
committerJudah Schvimer <judah@mongodb.com>2017-03-06 10:07:27 -0500
commit04eb46ca8ceb1862c82ea70745cf72b4cc6450e3 (patch)
treef143ede8ce65511731b464c3b95728ea2972c058
parent0a72f6e61c1dda519715d5bea03a1529cab6863d (diff)
downloadmongo-04eb46ca8ceb1862c82ea70745cf72b4cc6450e3.tar.gz
SERVER-27810 Guarantee that all nodes agree node 0 is primary after ReplSetTest.initiate()
(cherry picked from commit 3823a20f0186d0e6b544212fb423f9f0ef786235)
-rw-r--r--jstests/multiVersion/set_feature_compatibility_version.js2
-rw-r--r--src/mongo/shell/replsettest.js52
2 files changed, 50 insertions, 4 deletions
diff --git a/jstests/multiVersion/set_feature_compatibility_version.js b/jstests/multiVersion/set_feature_compatibility_version.js
index 821e9dc489e..e688d1421f4 100644
--- a/jstests/multiVersion/set_feature_compatibility_version.js
+++ b/jstests/multiVersion/set_feature_compatibility_version.js
@@ -208,7 +208,7 @@
replSetConfig = rst.getReplSetConfig();
replSetConfig.members[1].priority = 0;
replSetConfig.members[1].votes = 0;
- rst.initiate(replSetConfig);
+ rst.initiate(replSetConfig, 'replSetInitiate', false);
primaryAdminDB = rst.getPrimary().getDB("admin");
res = assert.commandWorked(
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index 20cc33dd4a3..29cee6aae9b 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -672,12 +672,14 @@ var ReplSetTest = function(opts) {
this._updateConfigIfNotDurable(config);
};
- this.initiate = function(cfg, initCmd, timeout) {
+ this.initiate = function(cfg, initCmd, ensureNode0Primary) {
var master = this.nodes[0].getDB("admin");
var config = cfg || this.getReplSetConfig();
var cmd = {};
var cmdKey = initCmd || 'replSetInitiate';
- timeout = timeout || self.kDefaultTimeoutMS;
+ if (ensureNode0Primary === undefined) {
+ ensureNode0Primary = true;
+ }
// Throw an exception if nodes[0] is unelectable in the given config.
if (!_isElectable(config.members[0])) {
@@ -733,7 +735,11 @@ var ReplSetTest = function(opts) {
return false;
}, "replSetReconfig during initiate failed", 3, 5 * 1000);
- this.awaitSecondaryNodes(timeout);
+ if (ensureNode0Primary) {
+ this.stepUp(this.nodes[0]);
+ } else {
+ this.awaitSecondaryNodes();
+ }
}
// Setup authentication if running test with authentication
@@ -743,6 +749,46 @@ var ReplSetTest = function(opts) {
}
};
+ this.stepUp = function(node) {
+ this.awaitSecondaryNodes();
+ this.awaitNodesAgreeOnPrimary();
+ if (this.getPrimary() === node) {
+ return;
+ }
+
+ if (this.protocolVersion === 0 || jsTestOptions().useLegacyReplicationProtocol) {
+ // Ensure the specified node is primary.
+ for (let i = 0; i < this.nodes.length; i++) {
+ let primary = this.getPrimary();
+ if (primary === node) {
+ break;
+ }
+ try {
+ // Make sure the nodes do not step back up for 10 minutes.
+ assert.commandWorked(
+ primary.adminCommand({replSetStepDown: 10 * 60, force: true}));
+ } catch (ex) {
+ print("Caught exception while stepping down node '" + tojson(node.host) +
+ "': " + tojson(ex));
+ }
+ this.awaitNodesAgreeOnPrimary();
+ }
+
+ // Reset the rest of the nodes so they can run for election during the test.
+ for (let i = 0; i < this.nodes.length; i++) {
+ // Cannot call replSetFreeze on the primary.
+ if (this.nodes[i] === node) {
+ continue;
+ }
+ assert.commandWorked(this.nodes[i].adminCommand({replSetFreeze: 0}));
+ }
+ } else {
+ assert.commandWorked(node.adminCommand({replSetStepUp: 1}));
+ this.awaitNodesAgreeOnPrimary();
+ }
+ assert.eq(this.getPrimary(), node, node.host + " was not primary after stepUp");
+ };
+
/**
* Gets the current replica set config from the specified node index. If no nodeId is specified,
* uses the primary node.