0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-48733 Update expectedPrimaryNodeId parameter in awaitNodesAgreeOnPrimary

This commit is contained in:
Ali Mir 2020-07-08 19:48:17 -04:00 committed by Evergreen Agent
parent ef0696ac57
commit ee7c632b25
5 changed files with 17 additions and 12 deletions

View File

@ -21,7 +21,7 @@ replTest.initiate({
{_id: 4, host: nodes[4].host, priority: 0},
],
});
replTest.awaitNodesAgreeOnPrimary(replTest.kDefaultTimeoutMS, nodes, 0);
replTest.awaitNodesAgreeOnPrimary(replTest.kDefaultTimeoutMS, nodes, nodes[0]);
var primary = replTest.getPrimary();
replTest.awaitReplication();

View File

@ -58,7 +58,7 @@ const parallelShell = startParallelShell(
}, C1), node0.port);
assert.commandWorked(node1.adminCommand({replSetStepUp: 1}));
rst.awaitNodesAgreeOnPrimary(rst.kDefaultTimeoutMS, [node1, node2, node3], 1);
rst.awaitNodesAgreeOnPrimary(rst.kDefaultTimeoutMS, [node1, node2, node3], node1);
jsTestLog("Current replica set topology: [node0 (Primary)] [node1 (Primary), node2, node3]");
assert.soon(() => node1.getDB('admin').runCommand({ismaster: 1}).ismaster);
assert.soon(() => isConfigCommitted(node1));

View File

@ -21,7 +21,7 @@ stopServerReplication(rst.nodes);
const newPrimary = rst.getSecondary();
assert.soonNoExcept(function() {
assert.commandWorked(newPrimary.adminCommand({replSetStepUp: 1}));
rst.awaitNodesAgreeOnPrimary(rst.kDefaultTimeoutMS, rst.nodes, rst.getNodeId(newPrimary));
rst.awaitNodesAgreeOnPrimary(rst.kDefaultTimeoutMS, rst.nodes, newPrimary);
return newPrimary.adminCommand('replSetGetStatus').myState === ReplSetTest.State.PRIMARY;
}, 'failed to step up node ' + newPrimary.host, rst.kDefaultTimeoutMS);

View File

@ -16,7 +16,7 @@ replTest.initiateWithAnyNodeAsPrimary({
});
// 2 should be master (give this a while to happen, as other nodes might first be elected)
replTest.awaitNodesAgreeOnPrimary(replTest.kDefaultTimeoutMS, nodes, 2);
replTest.awaitNodesAgreeOnPrimary(replTest.kDefaultTimeoutMS, nodes, nodes[2]);
// wait for 1 to not appear to be master (we are about to make it master and need a clean slate
// here)
@ -43,7 +43,7 @@ for (i = 0; i < 1000; i++) {
// bring 2 back up, 2 should wait until caught up and then become master
replTest.restart(2);
replTest.awaitNodesAgreeOnPrimary(replTest.kDefaultTimeoutMS, nodes, 2);
replTest.awaitNodesAgreeOnPrimary(replTest.kDefaultTimeoutMS, nodes, nodes[2]);
// make sure nothing was rolled back
master = replTest.getPrimary();

View File

@ -931,23 +931,25 @@ var ReplSetTest = function(opts) {
/**
* Blocks until all nodes agree on who the primary is.
* If 'expectedPrimaryNodeId' is provided, ensure that every node is seeing this node as the
* If 'expectedPrimaryNode' is provided, ensure that every node is seeing this node as the
* primary. Otherwise, ensure that all the nodes in the set agree with the first node on the
* identity of the primary.
*/
this.awaitNodesAgreeOnPrimary = function(timeout, nodes, expectedPrimaryNodeId) {
this.awaitNodesAgreeOnPrimary = function(timeout, nodes, expectedPrimaryNode) {
timeout = timeout || self.kDefaultTimeoutMS;
nodes = nodes || self.nodes;
expectedPrimaryNodeId = expectedPrimaryNodeId || -1;
if (expectedPrimaryNodeId === -1) {
// indexOf will return the index of the expected node. If expectedPrimaryNode is undefined,
// indexOf will return -1.
const expectedPrimaryNodeIdx = self.nodes.indexOf(expectedPrimaryNode);
if (expectedPrimaryNodeIdx === -1) {
print("AwaitNodesAgreeOnPrimary: Waiting for nodes to agree on any primary.");
} else {
print("AwaitNodesAgreeOnPrimary: Waiting for nodes to agree on " +
nodes[expectedPrimaryNodeId].name + " as primary.");
expectedPrimaryNode.name + " as primary.");
}
assert.soonNoExcept(function() {
var primary = expectedPrimaryNodeId;
var primary = expectedPrimaryNodeIdx;
for (var i = 0; i < nodes.length; i++) {
var replSetGetStatus =
@ -974,7 +976,10 @@ var ReplSetTest = function(opts) {
}
if (primary < 0) {
// If we haven't seen a primary yet, set it to this.
print("AwaitNodesAgreeOnPrimary: " + nodes[i].name + " thinks the " +
" primary is " + self.nodes[nodesPrimary].name +
". Other nodes are expected to agree on the same primary.");
// If the nodes haven't seen a primary yet, set primary to nodes[i]'s primary.
primary = nodesPrimary;
} else if (primary !== nodesPrimary) {
print("AwaitNodesAgreeOnPrimary: Retrying because " + nodes[i].name +