summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWenbin Zhu <wenbin.zhu@mongodb.com>2021-08-10 19:03:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-11 21:47:53 +0000
commit2074f5e8cd4b734573c20788dc488fb1fcf0c916 (patch)
tree02e39c120bca3093e14757ee2d9850994a5c48ca
parentd21efd2cc4ac16693589f4d7da1cf229c4d08b8d (diff)
downloadmongo-2074f5e8cd4b734573c20788dc488fb1fcf0c916.tar.gz
SERVER-59212 Make sure node stepped down before waiting for catchup takeover in catchup_takeover_with_higher_config.js
(cherry picked from commit 0698d8274f591725f3ddf0f8dcdf4c0d5f130770)
-rw-r--r--jstests/replsets/catchup_takeover_with_higher_config.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/jstests/replsets/catchup_takeover_with_higher_config.js b/jstests/replsets/catchup_takeover_with_higher_config.js
index f0977e0f812..995c38bb1ff 100644
--- a/jstests/replsets/catchup_takeover_with_higher_config.js
+++ b/jstests/replsets/catchup_takeover_with_higher_config.js
@@ -31,18 +31,17 @@ const getNodeConfigAndCompare = function(node, config, cmp) {
}
};
-// Wait for all nodes to acknowledge that the node at nodeIndex is in PRIMARY state.
-// A node may see multiple nodes claiming primary, but only checks the provided one.
-const waitForPrimaryState = function(nodes, nodeIndex, timeout) {
+// Wait for all nodes to acknowledge that the node at nodeIndex is in the specified state.
+const waitForNodeState = function(nodes, nodeIndex, state, timeout) {
assert.soon(() => {
for (const node of nodes) {
const status = assert.commandWorked(node.adminCommand({replSetGetStatus: 1}));
- if (status.members[nodeIndex].state !== ReplSetTest.State.PRIMARY) {
+ if (status.members[nodeIndex].state !== state) {
return false;
}
}
return true;
- }, `Failed to wait for primary state for node ${nodes[nodeIndex].host}`, timeout);
+ }, `Failed to agree on node ${nodes[nodeIndex].host} in state ${state}`, timeout);
};
const replSet = new ReplSetTest({name: jsTestName(), nodes: 3});
@@ -81,7 +80,7 @@ hangBeforeTermBumpFpNode2.wait();
// awaitNodesAgreeOnPrimary() or getPrimary() here which do not allow a node to
// see multiple primaries.
jsTestLog(`Waiting for all nodes to agree on ${nodes[2].host} being primary`);
-waitForPrimaryState(nodes, 2, 30 * 1000);
+waitForNodeState(nodes, 2, ReplSetTest.State.PRIMARY, 30 * 1000);
// Wait for node0 to change its sync source to node2. Later when the failpoint on node 1
// is lifted, it will do a no-op write and finish the stepup process, so its lastApplied
@@ -96,6 +95,9 @@ assert.soon(() => {
// Lift the failpoint on node1 to let it finish reconfig and bump the config term.
hangBeforeTermBumpFpNode1.off();
+jsTestLog(`Waiting for ${nodes[1].host} to step down before doing catchup takeover.`);
+waitForNodeState(nodes, 1, ReplSetTest.State.SECONDARY, 30 * 1000);
+
jsTestLog(
`Waiting for ${nodes[1].host} to finish config term bump and propagate to ${nodes[0].host}`);
assert.soon(() => getNodeConfigAndCompare(nodes[0], initialConfig, '>'));
@@ -105,7 +107,7 @@ assert(getNodeConfigAndCompare(nodes[2], initialConfig, '='));
// Wait for node1 to catchup takeover node2 after the default catchup takeover delay.
jsTestLog(`Waiting for ${nodes[1].host} to catchup takeover ${nodes[2].host}`);
-waitForPrimaryState(nodes, 1, 60 * 1000);
+waitForNodeState(nodes, 1, ReplSetTest.State.PRIMARY, 60 * 1000);
// Check again that node2 is still in catchup mode and has not installed a new config.
assert(getNodeConfigAndCompare(nodes[2], initialConfig, '='));