-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathcluster_parameters_initial_sync_restart.js
130 lines (115 loc) · 4.69 KB
/
cluster_parameters_initial_sync_restart.js
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* Checks that setClusterParameter behaves as expected during restart.
*
* @tags: [
* does_not_support_stepdowns,
* # Restarts all replica set member nodes mid-test.
* requires_persistence,
* requires_replication,
* requires_fcv_62,
* serverless
* ]
*/
import {
runGetClusterParameterNode,
runGetClusterParameterReplicaSet,
runSetClusterParameter,
} from "jstests/libs/cluster_server_parameter_utils.js";
import {ReplSetTest} from "jstests/libs/replsettest.js";
const tenantId = ObjectId();
let intParameter1 = {
_id: "testIntClusterParameter",
};
let strParameter1 = {
_id: "testStrClusterParameter",
};
let intParameter2 = {
_id: "testIntClusterParameter",
};
let strParameter2 = {
_id: "testStrClusterParameter",
};
function setParamsAndValidateCluster(rst) {
runSetClusterParameter(rst.getPrimary(), intParameter1);
runSetClusterParameter(rst.getPrimary(), strParameter1);
runSetClusterParameter(rst.getPrimary(), intParameter2, tenantId);
runSetClusterParameter(rst.getPrimary(), strParameter2, tenantId);
// Check that the new values are visible on the majority of the nodes.
runGetClusterParameterReplicaSet(rst,
["testIntClusterParameter", "testStrClusterParameter"],
[intParameter1, strParameter1]);
runGetClusterParameterReplicaSet(rst,
["testIntClusterParameter", "testStrClusterParameter"],
[intParameter2, strParameter2],
tenantId);
}
// Checks that up-to-date cluster parameters are transferred over to newly-added replica set nodes
// as part of initial sync.
function checkClusterParameterInitialSync(rst, newNodeOptions) {
// Update some parameter values.
intParameter1.intData = 5;
strParameter1.strData = "state 1";
intParameter2.intData = 6;
strParameter2.strData = "state 2";
setParamsAndValidateCluster(rst);
// Add a new node to the replica set, reinitiate the set, and wait for it to become a secondary
// with all data fully replicated to it.
const newNode = rst.add(newNodeOptions);
rst.reInitiate();
rst.awaitSecondaryNodes(null, [newNode]);
rst.awaitReplication();
// Check that the new node has the latest cluster parameter values.
assert(runGetClusterParameterNode(newNode,
["testIntClusterParameter", "testStrClusterParameter"],
[intParameter1, strParameter1]));
assert(runGetClusterParameterNode(newNode,
["testIntClusterParameter", "testStrClusterParameter"],
[intParameter2, strParameter2],
tenantId));
// Check that setClusterParameter properly works with the reconfigured replica set.
intParameter1.intData = 30;
strParameter1.strData = "sleep";
intParameter2.intData = 31;
strParameter2.strData = "wake";
setParamsAndValidateCluster(rst);
}
// Checks that restarted replica sets start with the most recent majority-written cluster parameter
// values.
function checkClusterParameterRestart(rst) {
// Update some parameter values.
intParameter1.intData = 7;
strParameter1.strData = "state 3";
intParameter2.intData = 8;
strParameter2.strData = "state 4";
setParamsAndValidateCluster(rst);
// Bounce restart all of the nodes.
rst.nodeList().forEach((_, index) => {
rst.restart(index);
});
// Check that restarted replica set still has the most recent setClusterParameter values.
runGetClusterParameterReplicaSet(rst,
["testIntClusterParameter", "testStrClusterParameter"],
[intParameter1, strParameter1]);
runGetClusterParameterReplicaSet(rst,
["testIntClusterParameter", "testStrClusterParameter"],
[intParameter2, strParameter2],
tenantId);
}
const baseOptions = {
setParameter: {multitenancySupport: true, featureFlagRequireTenantID: true}
};
const rst = new ReplSetTest({
nodes: 3,
serverless: true,
});
rst.startSet(baseOptions);
rst.initiate(null, null, {initiateWithDefaultElectionTimeout: true});
for (let syncMethod of ["logical", "fileCopyBased"]) {
jsTest.log("Testing initial sync w/ method = " + syncMethod);
let options = baseOptions;
options.setParameter.initialSyncMethod = syncMethod;
checkClusterParameterInitialSync(rst, options);
}
jsTest.log("Testing cluster restart");
checkClusterParameterRestart(rst);
rst.stopSet();