diff options
author | Judah Schvimer <judah@mongodb.com> | 2017-04-14 12:02:52 -0400 |
---|---|---|
committer | Judah Schvimer <judah@mongodb.com> | 2017-04-14 15:43:08 -0400 |
commit | f98bd7d1a376ab741024d21e20e4b1b48d9a0af6 (patch) | |
tree | 4a01c7d3f87194c872043c29c1dfaaec02a9d872 | |
parent | f20d3d9ad3653ffcd2d905e8349ce2dbb64e52d6 (diff) | |
download | mongo-f98bd7d1a376ab741024d21e20e4b1b48d9a0af6.tar.gz |
SERVER-28096 fix jstest stepUp functions
-rw-r--r-- | jstests/replsets/double_rollback.js | 15 | ||||
-rw-r--r-- | jstests/replsets/double_rollback_early.js | 15 | ||||
-rw-r--r-- | jstests/replsets/read_committed_stale_history.js | 13 | ||||
-rw-r--r-- | jstests/replsets/rollback_after_sync_source_selection.js | 16 | ||||
-rw-r--r-- | jstests/replsets/rollback_with_socket_error_then_steady_state.js | 15 | ||||
-rw-r--r-- | jstests/replsets/write_concern_after_stepdown.js | 12 | ||||
-rw-r--r-- | jstests/replsets/write_concern_after_stepdown_and_stepup.js | 14 | ||||
-rw-r--r-- | src/mongo/shell/replsettest.js | 43 |
8 files changed, 51 insertions, 92 deletions
diff --git a/jstests/replsets/double_rollback.js b/jstests/replsets/double_rollback.js index 7c22e6c3921..1f37bd93349 100644 --- a/jstests/replsets/double_rollback.js +++ b/jstests/replsets/double_rollback.js @@ -45,21 +45,8 @@ }); } - function stepUp(rst, node) { - var primary = rst.getPrimary(); - if (primary != node) { - try { - assert.commandWorked(primary.adminCommand({replSetStepDown: 1, force: true})); - } catch (ex) { - print("Caught exception while stepping down from node '" + tojson(node.host) + - "': " + tojson(ex)); - } - } - waitForState(node, ReplSetTest.State.PRIMARY); - } - jsTestLog("Make sure node 0 is primary."); - stepUp(rst, nodes[0]); + rst.stepUp(nodes[0]); assert.eq(nodes[0], rst.getPrimary()); // Wait for all data bearing nodes to get up to date. assert.writeOK(nodes[0].getDB(dbName).getCollection(collName).insert( diff --git a/jstests/replsets/double_rollback_early.js b/jstests/replsets/double_rollback_early.js index 07757270593..4af501701c6 100644 --- a/jstests/replsets/double_rollback_early.js +++ b/jstests/replsets/double_rollback_early.js @@ -26,21 +26,8 @@ var nodes = rst.startSet(); rst.initiate(); - function stepUp(rst, node) { - var primary = rst.getPrimary(); - if (primary != node) { - try { - assert.commandWorked(primary.adminCommand({replSetStepDown: 1, force: true})); - } catch (ex) { - print("Caught exception while stepping down from node '" + tojson(node.host) + - "': " + tojson(ex)); - } - } - waitForState(node, ReplSetTest.State.PRIMARY); - } - jsTestLog("Make sure node 0 is primary."); - stepUp(rst, nodes[0]); + rst.stepUp(nodes[0]); assert.eq(nodes[0], rst.getPrimary()); // Wait for all data bearing nodes to get up to date. assert.writeOK(nodes[0].getCollection(collName).insert( diff --git a/jstests/replsets/read_committed_stale_history.js b/jstests/replsets/read_committed_stale_history.js index 0d2943a1a1a..a92595bf439 100644 --- a/jstests/replsets/read_committed_stale_history.js +++ b/jstests/replsets/read_committed_stale_history.js @@ -38,16 +38,6 @@ }); } - function stepUp(node) { - var primary = rst.getPrimary(); - if (primary != node) { - assert.throws(function() { - primary.adminCommand({replSetStepDown: 60 * 5}); - }); - } - waitForPrimary(node); - } - // Asserts that the given document is not visible in the committed snapshot on the given node. function checkDocNotCommitted(node, doc) { var docs = @@ -56,8 +46,7 @@ } jsTestLog("Make sure node 0 is primary."); - rst.getPrimary(); - stepUp(nodes[0]); + rst.stepUp(nodes[0]); var primary = rst.getPrimary(); var secondaries = rst.getSecondaries(); assert.eq(nodes[0], primary); diff --git a/jstests/replsets/rollback_after_sync_source_selection.js b/jstests/replsets/rollback_after_sync_source_selection.js index 1edd9612377..817da77164e 100644 --- a/jstests/replsets/rollback_after_sync_source_selection.js +++ b/jstests/replsets/rollback_after_sync_source_selection.js @@ -30,22 +30,8 @@ var nodes = rst.startSet(); rst.initiate(); - function stepUp(rst, node) { - var primary = rst.getPrimary(); - if (primary !== node) { - try { - assert.commandWorked(primary.adminCommand({replSetStepDown: 60, force: true})); - } catch (ex) { - print("Caught exception while stepping down from node '" + tojson(primary.host) + - "': " + tojson(ex)); - } - waitForState(node, ReplSetTest.State.PRIMARY); - assert.commandWorked(primary.adminCommand({replSetFreeze: 0})); - } - } - jsTestLog("Make sure node 0 is primary."); - stepUp(rst, nodes[0]); + rst.stepUp(nodes[0]); assert.eq(nodes[0], rst.getPrimary()); // Wait for all data bearing nodes to get up to date. assert.writeOK(nodes[0].getCollection(collName).insert( diff --git a/jstests/replsets/rollback_with_socket_error_then_steady_state.js b/jstests/replsets/rollback_with_socket_error_then_steady_state.js index 8dcea725885..25a5c863970 100644 --- a/jstests/replsets/rollback_with_socket_error_then_steady_state.js +++ b/jstests/replsets/rollback_with_socket_error_then_steady_state.js @@ -29,21 +29,8 @@ var nodes = rst.startSet(); rst.initiate(); - function stepUp(rst, node) { - var primary = rst.getPrimary(); - if (primary != node) { - try { - assert.commandWorked(primary.adminCommand({replSetStepDown: 1, force: true})); - } catch (ex) { - print("Caught exception while stepping down from node '" + tojson(node.host) + - "': " + tojson(ex)); - } - } - waitForState(node, ReplSetTest.State.PRIMARY); - } - jsTestLog("Make sure node 0 is primary."); - stepUp(rst, nodes[0]); + rst.stepUp(nodes[0]); assert.eq(nodes[0], rst.getPrimary()); // Wait for all data bearing nodes to get up to date. assert.writeOK(nodes[0].getCollection(collName).insert( diff --git a/jstests/replsets/write_concern_after_stepdown.js b/jstests/replsets/write_concern_after_stepdown.js index 22f6f627fda..57cc44fda79 100644 --- a/jstests/replsets/write_concern_after_stepdown.js +++ b/jstests/replsets/write_concern_after_stepdown.js @@ -23,18 +23,8 @@ }); } - function stepUp(node) { - var primary = rst.getPrimary(); - if (primary != node) { - assert.throws(function() { - primary.adminCommand({replSetStepDown: 60 * 5}); - }); - } - waitForPrimary(node); - } - jsTestLog("Make sure node 0 is primary."); - stepUp(nodes[0]); + rst.stepUp(nodes[0]); var primary = rst.getPrimary(); var secondaries = rst.getSecondaries(); assert.eq(nodes[0], primary); diff --git a/jstests/replsets/write_concern_after_stepdown_and_stepup.js b/jstests/replsets/write_concern_after_stepdown_and_stepup.js index beb2bd16e0a..22167ee356c 100644 --- a/jstests/replsets/write_concern_after_stepdown_and_stepup.js +++ b/jstests/replsets/write_concern_after_stepdown_and_stepup.js @@ -31,18 +31,8 @@ }); } - function stepUp(node) { - var primary = rst.getPrimary(); - if (primary != node) { - assert.throws(function() { - primary.adminCommand({replSetStepDown: 60 * 5}); - }); - } - waitForPrimary(node); - } - jsTestLog("Make sure node 0 is primary."); - stepUp(nodes[0]); + rst.stepUp(nodes[0]); var primary = rst.getPrimary(); var secondaries = rst.getSecondaries(); assert.eq(nodes[0], primary); @@ -113,7 +103,7 @@ }); jsTest.log("Make the original primary become primary once again"); - stepUp(nodes[0]); + rst.stepUp(nodes[0]); jsTest.log("Unblock the thread waiting for replication of the now rolled-back write, ensure " + "that the write concern failed"); diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js index 5b84c008cbf..0b1419caa07 100644 --- a/src/mongo/shell/replsettest.js +++ b/src/mongo/shell/replsettest.js @@ -593,6 +593,49 @@ var ReplSetTest = function(opts) { }; /** + * Steps up 'node' as primary. + * Waits for all nodes to reach the same optime before each election. + * Calls awaitReplication() which requires all connections in 'nodes' to be authenticated. + */ + this.stepUp = function(node) { + this.awaitReplication(); + this.awaitNodesAgreeOnPrimary(); + if (this.getPrimary() === node) { + print("Node " + node.host + " is already primary, no need to step it up."); + return; + } + print("Stepping up node " + node.host); + + // Ensure the specified node is primary. + for (var i = 0; i < this.nodes.length; i++) { + var 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.awaitReplication(); + this.awaitNodesAgreeOnPrimary(); + } + + // Reset the rest of the nodes so they can run for election during the test. + for (var 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})); + } + + 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. */ |