blob: 9a3dbfeda0967e8a587452b1eefe5a5362e5680a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// Priority (1 member with non-default priority).
// 3-node replica set - one arbiter and two electable nodes with different priorities.
// Wait for replica set to stabilize with higher priority node as primary.
// Step down high priority node. Wait for the lower priority electable node to become primary.
// Eventually high priority node will run a priority takeover election to become primary.
(function() {
'use strict';
load('jstests/replsets/rslib.js');
load('jstests/replsets/libs/election_metrics.js');
var name = 'priority_takeover_one_node_higher_priority';
var replSet = new ReplSetTest({
name: name,
nodes: [
{rsConfig: {priority: 3}},
{},
{rsConfig: {arbiterOnly: true}},
]
});
replSet.startSet();
replSet.initiate();
replSet.waitForState(replSet.nodes[0], ReplSetTest.State.PRIMARY);
var primary = replSet.getPrimary();
const initialPrimaryStatus = assert.commandWorked(primary.adminCommand({serverStatus: 1}));
replSet.awaitSecondaryNodes();
replSet.awaitReplication();
// Primary should step down long enough for election to occur on secondary.
var config = assert.commandWorked(primary.adminCommand({replSetGetConfig: 1})).config;
assert.commandWorked(primary.adminCommand({replSetStepDown: replSet.kDefaultTimeoutMS / 1000}));
// Step down primary and wait for node 1 to be promoted to primary.
replSet.waitForState(replSet.nodes[1], ReplSetTest.State.PRIMARY);
// Unfreeze node 0 so it can seek election.
assert.commandWorked(primary.adminCommand({replSetFreeze: 0}));
// Eventually node 0 will stand for election again because it has a higher priority.
replSet.waitForState(replSet.nodes[0], ReplSetTest.State.PRIMARY);
// Check that both the 'called' and 'successful' fields of the 'priorityTakeover' election
// reason counter have been incremented in serverStatus. We allow an increase of more than 1
// in case a slow election causes a priority takeover to fail.
const newPrimaryStatus = assert.commandWorked(primary.adminCommand({serverStatus: 1}));
verifyServerStatusElectionReasonCounterChange(initialPrimaryStatus.electionMetrics,
newPrimaryStatus.electionMetrics,
"priorityTakeover",
1,
undefined, /* expectedNumSuccessful */
true /* allowGreater */);
replSet.stopSet();
})();
|