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
|
/**
* Tests adding shard to sharded cluster will fail if the implicitDefaultWriteConcern is
* w:1 and CWWC is not set.
* @tags: [requires_fcv_50, disabled_due_to_server_58295]
*/
(function() {
"use strict";
load("jstests/replsets/rslib.js"); // For reconfig and isConfigCommitted.
function addNonArbiterNode(nodeId, rst) {
const config = rst.getReplSetConfigFromNode();
config.members.push({_id: nodeId, host: rst.add().host});
config.version++;
reconfig(rst, config);
assert.soon(() => isConfigCommitted(rst.getPrimary()));
rst.waitForConfigReplication(rst.getPrimary());
rst.awaitReplication();
}
function testAddShard(CWWCSet, isPSASet, fixAddShard) {
jsTestLog("Running sharding test with CWWCSet: " + tojson(CWWCSet) +
", isPSASet: " + tojson(isPSASet));
let replSetNodes = [{}, {}];
if (isPSASet) {
replSetNodes = [{}, {}, {arbiter: true}];
}
let shardServer = new ReplSetTest(
{name: "shardServer", nodes: replSetNodes, nodeOptions: {shardsvr: ""}, useHostName: true});
const conns = shardServer.startSet();
shardServer.initiate();
const st = new ShardingTest({
shards: 0,
mongos: 1,
});
var admin = st.getDB('admin');
if (CWWCSet) {
jsTestLog("Setting the CWWC before adding shard.");
assert.commandWorked(st.s.adminCommand(
{setDefaultRWConcern: 1, defaultWriteConcern: {w: "majority", wtimeout: 0}}));
}
jsTestLog("Attempting to add shard to the cluster");
if (!CWWCSet && isPSASet) {
jsTestLog("Adding shard to the cluster should fail.");
assert.commandFailed(admin.runCommand({addshard: shardServer.getURL()}));
if (fixAddShard == "setCWWC") {
jsTestLog("Setting the CWWC to fix addShard.");
assert.commandWorked(st.s.adminCommand(
{setDefaultRWConcern: 1, defaultWriteConcern: {w: "majority", wtimeout: 0}}));
} else {
jsTestLog("Reconfig shardServer to fix addShard.");
addNonArbiterNode(3, shardServer);
addNonArbiterNode(4, shardServer);
}
}
jsTestLog("Adding shard to the cluster should succeed.");
assert.commandWorked(admin.runCommand({addshard: shardServer.getURL()}));
st.stop();
shardServer.stopSet();
}
for (const CWWCSet of [true, false]) {
for (const isPSASet of [false, true]) {
if (!CWWCSet && isPSASet) {
for (const fixAddShard of ["setCWWC", "reconfig"]) {
testAddShard(CWWCSet, isPSASet, fixAddShard);
}
} else {
testAddShard(CWWCSet, isPSASet);
}
}
}
})();
|