diff options
Diffstat (limited to 'jstests/replsets/catchup_takeover_two_nodes_ahead.js')
-rw-r--r-- | jstests/replsets/catchup_takeover_two_nodes_ahead.js | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/jstests/replsets/catchup_takeover_two_nodes_ahead.js b/jstests/replsets/catchup_takeover_two_nodes_ahead.js index 69dddd079a1..34cf44ec8f7 100644 --- a/jstests/replsets/catchup_takeover_two_nodes_ahead.js +++ b/jstests/replsets/catchup_takeover_two_nodes_ahead.js @@ -11,50 +11,54 @@ // Confirm that the most up-to-date node becomes primary. (function() { - 'use strict'; - - load('jstests/replsets/rslib.js'); - - var name = 'catchup_takeover_two_nodes_ahead'; - var replSet = new ReplSetTest({name: name, nodes: 5}); - var nodes = replSet.startSet(); - var config = replSet.getReplSetConfig(); - // Prevent nodes from syncing from other secondaries. - config.settings = {chainingAllowed: false}; - replSet.initiate(config); - replSet.awaitReplication(); - - // Write something so that nodes 0 and 1 are ahead. - stopServerReplication(nodes.slice(2, 5)); - var primary = replSet.getPrimary(); - var writeConcern = {writeConcern: {w: 2, wtimeout: replSet.kDefaultTimeoutMS}}; - assert.writeOK(primary.getDB(name).bar.insert({x: 100}, writeConcern)); - - // Write something so that node 0 is ahead of node 1. - stopServerReplication(nodes[1]); - writeConcern = {writeConcern: {w: 1, wtimeout: replSet.kDefaultTimeoutMS}}; - assert.writeOK(primary.getDB(name).bar.insert({y: 100}, writeConcern)); - - // Step up one of the lagged nodes. - assert.commandWorked(nodes[2].adminCommand({replSetStepUp: 1})); - replSet.awaitNodesAgreeOnPrimary(); - assert.eq(ReplSetTest.State.PRIMARY, - assert.commandWorked(nodes[2].adminCommand('replSetGetStatus')).myState, - nodes[2].host + " was not primary after step-up"); - jsTestLog('node 2 is now primary, but cannot accept writes'); - - // Make sure that node 2 cannot write anything. Because it is lagged and replication - // has been stopped, it shouldn't be able to become master. - assert.commandFailedWithCode(nodes[2].getDB(name).bar.insert({z: 100}, writeConcern), - ErrorCodes.NotMaster); - - // Confirm that the most up-to-date node becomes primary - // after the default catchup delay. - replSet.waitForState(0, ReplSetTest.State.PRIMARY, 60 * 1000); - - // Wait until the old primary steps down so the connections won't be closed. - replSet.waitForState(2, ReplSetTest.State.SECONDARY, replSet.kDefaultTimeoutMS); - // Let the nodes catchup. - restartServerReplication(nodes.slice(1, 5)); - replSet.stopSet(); +'use strict'; + +load('jstests/replsets/rslib.js'); + +var name = 'catchup_takeover_two_nodes_ahead'; +var replSet = new ReplSetTest({name: name, nodes: 5}); +var nodes = replSet.startSet(); +var config = replSet.getReplSetConfig(); +// Prevent nodes from syncing from other secondaries. +config.settings = { + chainingAllowed: false +}; +replSet.initiate(config); +replSet.awaitReplication(); + +// Write something so that nodes 0 and 1 are ahead. +stopServerReplication(nodes.slice(2, 5)); +var primary = replSet.getPrimary(); +var writeConcern = {writeConcern: {w: 2, wtimeout: replSet.kDefaultTimeoutMS}}; +assert.writeOK(primary.getDB(name).bar.insert({x: 100}, writeConcern)); + +// Write something so that node 0 is ahead of node 1. +stopServerReplication(nodes[1]); +writeConcern = { + writeConcern: {w: 1, wtimeout: replSet.kDefaultTimeoutMS} +}; +assert.writeOK(primary.getDB(name).bar.insert({y: 100}, writeConcern)); + +// Step up one of the lagged nodes. +assert.commandWorked(nodes[2].adminCommand({replSetStepUp: 1})); +replSet.awaitNodesAgreeOnPrimary(); +assert.eq(ReplSetTest.State.PRIMARY, + assert.commandWorked(nodes[2].adminCommand('replSetGetStatus')).myState, + nodes[2].host + " was not primary after step-up"); +jsTestLog('node 2 is now primary, but cannot accept writes'); + +// Make sure that node 2 cannot write anything. Because it is lagged and replication +// has been stopped, it shouldn't be able to become master. +assert.commandFailedWithCode(nodes[2].getDB(name).bar.insert({z: 100}, writeConcern), + ErrorCodes.NotMaster); + +// Confirm that the most up-to-date node becomes primary +// after the default catchup delay. +replSet.waitForState(0, ReplSetTest.State.PRIMARY, 60 * 1000); + +// Wait until the old primary steps down so the connections won't be closed. +replSet.waitForState(2, ReplSetTest.State.SECONDARY, replSet.kDefaultTimeoutMS); +// Let the nodes catchup. +restartServerReplication(nodes.slice(1, 5)); +replSet.stopSet(); })(); |