diff options
author | XueruiFa <xuerui.fa@mongodb.com> | 2020-10-06 17:28:45 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-14 18:57:31 +0000 |
commit | eb949a18023881d941e5367ff0ac6ccf4ae46b79 (patch) | |
tree | ca4c5ddec960ebe9b4a447e482f5893d06ab0fc5 | |
parent | 2516e9546b1b5df6e15d2f93e526e7218fa953f0 (diff) | |
download | mongo-eb949a18023881d941e5367ff0ac6ccf4ae46b79.tar.gz |
SERVER-43904: Filter unelectable nodes during election handoff
(cherry picked from commit bf614cb57059c74830633855e28b3f4677cd4f8d)
-rw-r--r-- | jstests/replsets/election_handoff_skips_unelectable_nodes.js | 25 | ||||
-rw-r--r-- | jstests/sharding/move_chunk_with_session_helper.js | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/topology_coordinator.cpp | 3 |
3 files changed, 31 insertions, 6 deletions
diff --git a/jstests/replsets/election_handoff_skips_unelectable_nodes.js b/jstests/replsets/election_handoff_skips_unelectable_nodes.js new file mode 100644 index 00000000000..2e773d4c471 --- /dev/null +++ b/jstests/replsets/election_handoff_skips_unelectable_nodes.js @@ -0,0 +1,25 @@ +/* + * Tests that election handoff will not attempt to step up a node that is unelectable. + */ + +(function() { + "use strict"; + + load("jstests/replsets/libs/election_handoff.js"); + + const rst = new ReplSetTest({name: jsTestName(), nodes: 3}); + rst.startSet(); + + // Make sure there are no election timeouts firing for the duration of the test. This helps + // ensure that the test will only pass if the election handoff succeeds. + rst.initiateWithHighElectionTimeout(); + + // Freeze one of the secondaries so that it cannot be elected. As a result, the other secondary + // should always be chosen to run for primary via election handoff. + const frozenSecondary = rst.getSecondaries()[0]; + assert.commandWorked(frozenSecondary.adminCommand({replSetFreeze: ReplSetTest.kForeverSecs})); + + ElectionHandoffTest.testElectionHandoff(rst, 0, 2); + + rst.stopSet(); +})(); diff --git a/jstests/sharding/move_chunk_with_session_helper.js b/jstests/sharding/move_chunk_with_session_helper.js index 6728a245bbe..63d94a81c01 100644 --- a/jstests/sharding/move_chunk_with_session_helper.js +++ b/jstests/sharding/move_chunk_with_session_helper.js @@ -6,7 +6,7 @@ load("jstests/replsets/rslib.js"); * 2. Perform writes. * 3. Migrate only chunk to other shard. * 4. Retry writes. - * 5. Step down primary and wait for new primary. + * 5. Step up secondary and wait for new primary. * 6. Retry writes. * 7. Migrate only chunk back to original shard. * 8. Retry writes. @@ -27,11 +27,8 @@ var testMoveChunkWithSession = function( checkRetryResultFunc(result, assert.commandWorked(testDB.runCommand(cmdObj))); checkDocumentsFunc(coll); - try { - st.rs1.getPrimary().adminCommand({replSetStepDown: 60, secondaryCatchUpPeriodSecs: 30}); - } catch (excep) { - print('Expected exception due to step down: ' + tojson(excep)); - } + const secondary = st.rs1.getSecondary(); + st.rs1.stepUp(secondary); st.rs1.awaitNodesAgreeOnPrimary(); st.configRS.nodes.concat([st.s]).forEach(function awaitNode(conn) { diff --git a/src/mongo/db/repl/topology_coordinator.cpp b/src/mongo/db/repl/topology_coordinator.cpp index 506b0928416..7742c42cdb5 100644 --- a/src/mongo/db/repl/topology_coordinator.cpp +++ b/src/mongo/db/repl/topology_coordinator.cpp @@ -928,6 +928,9 @@ Status TopologyCoordinator::prepareHeartbeatResponseV1(Date_t now, return Status::OK(); } + response->setElectable( + !_getMyUnelectableReason(now, StartElectionReasonEnum::kElectionTimeout)); + const long long v = _rsConfig.getConfigVersion(); response->setConfigVersion(v); // Deliver new config if caller's version is older than ours |