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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
* Test which configures various configs (hidden/priorities/no-chaining) that replExec queues
* stay at reasonable/stable levels after repeated reconfigs/stepdowns
*/
(function() {
"use strict";
var numNodes = 5;
var maxQueueSizeExpected = 11;
var replTest = new ReplSetTest({name: 'testSet', nodes: numNodes});
var nodes = replTest.startSet();
replTest.initiate();
var primary = replTest.getPrimary();
var testQueues = function() {
/* Example stats under executor
"counters" : {
"eventCreated" : 2,
"eventWait" : 2,
"cancels" : 17,
"waits" : 490,
"scheduledNetCmd" : 90,
"scheduledDBWork" : 2,
"scheduledXclWork" : 0,
"scheduledWorkAt" : 120,
"scheduledWork" : 494,
"schedulingFailures" : 0
},
"queues" : {
"networkInProgress" : 0,
"dbWorkInProgress" : 0,
"exclusiveInProgress" : 0,
"sleepers" : 3,
"ready" : 0,
"free" : 4
},
*/
assert.soon(function() {
primary = replTest.getPrimary();
try {
var stats = replTest.nodes.map(m => m.getDB("admin").serverStatus());
stats.forEach(s => {
var executorStats = s.metrics.repl.executor;
printjson(s.host);
printjson(executorStats);
var queues = executorStats.queues;
assert.lt(queues.sleepers, maxQueueSizeExpected, "sleepers");
assert.lt(queues.ready, maxQueueSizeExpected, "ready");
assert.lt(queues.networkInProgress, maxQueueSizeExpected, "networkInProgress");
});
} catch (e) {
return false;
}
return true;
}, "queues too high", 13 * 1000 /*13 secs*/); // what we are looking for has a 10s timeout.
};
var reconfig = function(newConfig) {
newConfig.version += 1;
try {
assert.commandWorked(replTest.getPrimary().adminCommand({replSetReconfig: newConfig}));
} catch (e) {
if (tojson(e).indexOf("error doing query: failed") < 0) {
throw e;
}
}
};
replTest.awaitSecondaryNodes();
// We cannot reconfig nodes[2] to have priority 0 if it is currently the primary. After the
// first reconfig, it will be unelectable so this only needs to be done once.
if (replTest.getPrimary() === replTest.nodes[2]) {
jsTestLog("Stepping down node 2 before reconfig");
assert.throws(function() {
replTest.nodes[2].adminCommand({replSetStepDown: 5, force: true});
});
replTest.waitForState(replTest.nodes[2], ReplSetTest.State.SECONDARY);
}
// ** Setup different priorities
var c = replTest.getReplSetConfigFromNode();
c.members[0].priority = 99;
c.members[1].priority = 2;
c.members[2].priority = 0;
reconfig(c);
for (var i = 0; i < 50; i++) {
reconfig(c);
testQueues();
}
// ** Setup different priorities
var c = replTest.getReplSetConfigFromNode();
c.members[2].hidden = true;
c.members[3].priority = 1000;
c.members[4].priority = 1000;
reconfig(c);
for (var i = 0; i < 50; i++) {
reconfig(c);
testQueues();
}
replTest.stopSet();
}());
|