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
|
/**
* Tests that the cluster parameter "shardedClusterCardinalityForDirectConns" has the correct value
* after upgrade, downgrade, and addShard.
*
* TODO SERVER-75391: Enable when config shards can downgrade FCV
* @tags: [multiversion_incompatible, featureFlagClusterCardinalityParameter,
* config_shard_incompatible]
*/
(function() {
'use strict';
load("jstests/sharding/libs/remove_shard_util.js");
const st = new ShardingTest({shards: 1, useHostname: false});
const additionalShard = new ReplSetTest({name: "additionalShard", host: 'localhost', nodes: 1});
additionalShard.startSet({shardsvr: ""});
additionalShard.initiate();
let checkClusterParameter = function(conn, expectedValue) {
let resp = assert.commandWorked(
conn.adminCommand({getClusterParameter: "shardedClusterCardinalityForDirectConns"}));
assert.eq(resp.clusterParameters[0].hasTwoOrMoreShards, expectedValue);
};
// There is only one shard in the cluster, so the cluster parameter should be false
checkClusterParameter(st.configRS.getPrimary(), false);
checkClusterParameter(st.shard0, false);
assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}));
assert.commandWorked(st.s.adminCommand({addShard: additionalShard.getURL(), name: "shard02"}));
assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
// There are two shards in the cluster while upgrading, so the cluster parameter should be true
checkClusterParameter(st.configRS.getPrimary(), true);
checkClusterParameter(st.shard0, true);
checkClusterParameter(additionalShard.getPrimary(), true);
assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}));
removeShard(st, "shard02");
assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
// There is one shard in the cluster while upgrading, so the cluster parameter should be false
checkClusterParameter(st.configRS.getPrimary(), false);
checkClusterParameter(st.shard0, false);
assert.commandWorked(st.s.adminCommand({addShard: additionalShard.getURL(), name: "shard02"}));
// Since the feature flag is enabled, addShard should update the cluster parameter
checkClusterParameter(st.configRS.getPrimary(), true);
checkClusterParameter(st.shard0, true);
checkClusterParameter(additionalShard.getPrimary(), true);
removeShard(st, "shard02");
// Removing a shard while the feature flag is enabled shouldn't change the cluster parameter
checkClusterParameter(st.configRS.getPrimary(), true);
checkClusterParameter(st.shard0, true);
additionalShard.stopSet();
st.stop();
})();
|