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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/**
* Tests that the ports assigned to the mongobridge and mongod/mongos processes make it easy to
* reason about which mongobridge process corresponds to a particular mongod/mongos process in the
* logs.
*
* @tags: [
* requires_replication,
* requires_sharding,
* ]
*/
(function() {
"use strict";
function checkBridgeOffset(node, processType) {
const bridgePort = node.port;
const serverPort = assert.commandWorked(node.adminCommand({getCmdLineOpts: 1})).parsed.net.port;
assert.neq(bridgePort,
serverPort,
node + " is a connection to " + processType + " rather than to mongobridge");
assert.eq(bridgePort + MongoBridge.kBridgeOffset,
serverPort,
"corresponding mongobridge and " + processType +
" ports should be staggered by a multiple of 10");
}
// We use >5 nodes to ensure that allocating twice as many ports doesn't interfere with having
// the corresponding mongobridge and mongod ports staggered by a multiple of 10.
const rst = new ReplSetTest({nodes: 7, useBridge: true});
rst.startSet();
// Rig the election so that the primary remains stable throughout this test despite the replica
// set having a larger number of members.
const replSetConfig = rst.getReplSetConfig();
for (let i = 1; i < rst.nodes.length; ++i) {
replSetConfig.members[i].priority = 0;
replSetConfig.members[i].votes = 0;
}
rst.initiate(replSetConfig);
for (let node of rst.nodes) {
checkBridgeOffset(node, "mongod");
}
rst.stopSet();
// We run ShardingTest under mongobridge with 1-node replica set shards
resetAllocatedPorts();
const numMongos = 5;
const numShards = 5;
const st = new ShardingTest({
mongos: numMongos,
shards: numShards,
config: {nodes: 1},
rs: {nodes: 1},
useBridge: true,
});
for (let i = 0; i < numMongos; ++i) {
checkBridgeOffset(st["s" + i], "mongos");
}
for (let configServer of st.configRS.nodes) {
checkBridgeOffset(configServer, "config server");
}
for (let i = 0; i < numShards; ++i) {
for (let node of st["rs" + i].nodes) {
checkBridgeOffset(node, "shard");
}
}
st.stop();
})();
|