blob: 1d9aafb08e7d677ea8030af981b2270be4fe5c19 (
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
|
// 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');
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();
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;
var electionTimeoutMillis = config.settings.electionTimeoutMillis;
var stepDownGuardMillis = electionTimeoutMillis * 2;
var stepDownException = assert.throws(function() {
var result = primary.adminCommand({replSetStepDown: stepDownGuardMillis / 1000});
print('replSetStepDown did not throw exception but returned: ' + tojson(result));
});
assert(isNetworkError(stepDownException),
'replSetStepDown did not disconnect client; failed with ' + tojson(stepDownException));
// Step down primary and wait for node 1 to be promoted to primary.
replSet.waitForState(replSet.nodes[1], ReplSetTest.State.PRIMARY, 60 * 1000);
// Eventually node 0 will stand for election again because it has a higher priorty.
replSet.waitForState(
replSet.nodes[0], ReplSetTest.State.PRIMARY, stepDownGuardMillis + 60 * 1000);
})();
|