summaryrefslogtreecommitdiff
path: root/jstests/replsets/arbiter_new_hostname.js
blob: dd7bc11fd360c264761c650391227932b405a062 (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
/*
 * An arbiter that is stopped and restarted on a different port and rejoins the
 * replica set should enter removed state and should not start data replication.
 *
 * @tags: [
 *     requires_fcv_49,
 * ]
 */
(function() {
"use strict";
const replTest = new ReplSetTest({name: 'test', nodes: 3});
replTest.startSet();
const nodes = replTest.nodeList();
let config = {
    "_id": "test",
    "members": [
        {"_id": 0, "host": nodes[0]},
        {"_id": 1, "host": nodes[1]},
        {"_id": 2, "host": nodes[2], arbiterOnly: true}
    ]
};
replTest.initiate(config);

let primary = replTest.getPrimary();
replTest.awaitReplication();
replTest.awaitSecondaryNodes();

const arbiterId = 2;
const newPort = replTest.getPort(arbiterId) + 1;
jsTestLog("Restarting the arbiter node on a new port: " + newPort);
replTest.stop(arbiterId);
replTest.start(arbiterId, {port: newPort}, true);

jsTestLog("Reconfiguring the set to change the arbiter's port.");
config = replTest.getReplSetConfigFromNode();
jsTestLog(`Original config: ${tojson(config)}`);

const hostname = config.members[arbiterId].host.split(":")[0];
config.version++;
config.members[arbiterId].host = hostname + ":" + newPort;
jsTestLog(`New config: ${tojson(config)}`);
assert.commandWorked(primary.getDB("admin").runCommand({replSetReconfig: config}));
replTest.awaitReplication();
replTest.awaitNodesAgreeOnConfigVersion();
replTest.stopSet();
}());