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
|
// A replica set's passive nodes should be okay to add as part of a shard config
(function() {
var s = new ShardingTest({name: "addshard4", shards: 2, mongos: 1, other: {useHostname: true}});
var r = new ReplSetTest({name: "addshard4", nodes: 3, nodeOptions: {shardsvr: ""}});
r.startSet();
var config = r.getReplSetConfig();
config.members[2].priority = 0;
r.initiate(config);
// Wait for replica set to be fully initialized - could take some time
// to pre-allocate files on slow systems
r.awaitReplication();
var primary = r.getPrimary();
var members = config.members.map(function(elem) {
return elem.host;
});
var shardName = "addshard4/" + members.join(",");
var invalidShardName = "addshard4/foobar";
print("adding shard " + shardName);
// First try adding shard with the correct replica set name but incorrect hostname
// This will make sure that the metadata for this replica set name is cleaned up
// so that the set can be added correctly when it has the proper hostnames.
assert.throws(function() {
s.adminCommand({"addshard": invalidShardName});
});
var result = s.adminCommand({"addshard": shardName});
printjson(result);
assert.eq(result, true);
r.stopSet();
r = new ReplSetTest({name: "addshard42", nodes: 3, nodeOptions: {shardsvr: ""}});
r.startSet();
config = r.getReplSetConfig();
config.members[2].arbiterOnly = true;
r.initiate(config);
// Wait for replica set to be fully initialized - could take some time
// to pre-allocate files on slow systems
r.awaitReplication();
primary = r.getPrimary();
print("adding shard addshard42");
// Setting CWWC for addShard to work, as implicitDefaultWC is set to w:1.
assert.commandWorked(s.s.adminCommand(
{setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: "majority"}}));
result = s.adminCommand({"addshard": "addshard42/" + config.members[2].host});
printjson(result);
assert.eq(result, true);
s.stop();
r.stopSet();
})();
|