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
|
/**
* Test that setShardVersion should not reject a configdb string with the same
* replica set name, but with a member list that is not strictly the same.
*/
(function() {
"use strict";
var st = new ShardingTest({shards: 1});
var testDB = st.s.getDB('test');
testDB.adminCommand({enableSharding: 'test'});
testDB.adminCommand({shardCollection: 'test.user', key: {x: 1}});
// Initialize version on shard.
testDB.user.insert({x: 1});
var directConn = new Mongo(st.d0.host);
var adminDB = directConn.getDB('admin');
var configStr = adminDB.runCommand({getShardVersion: 'test.user'}).configServer;
var alternateConfigStr = configStr.substring(0, configStr.lastIndexOf(','));
var shardDoc = st.s.getDB('config').shards.findOne();
assert.commandWorked(adminDB.runCommand({
setShardVersion: '',
init: true,
authoritative: true,
configdb: alternateConfigStr,
shard: shardDoc._id,
shardHost: shardDoc.host
}));
assert.commandFailed(adminDB.runCommand({
setShardVersion: '',
init: true,
authoritative: true,
configdb: 'bad-rs/local:12,local:34',
shard: shardDoc._id,
shardHost: shardDoc.host
}));
var configAdmin = st.c0.getDB('admin');
// Initialize internal config string.
assert.commandWorked(configAdmin.runCommand({
setShardVersion: '',
init: true,
authoritative: true,
configdb: configStr,
shard: 'config'
}));
// Passing configdb that does not match initialized value is not ok.
assert.commandFailed(configAdmin.runCommand({
setShardVersion: '',
init: true,
authoritative: true,
configdb: 'bad-rs/local:12,local:34',
shard: 'config'
}));
// Passing configdb that matches initialized value is ok.
assert.commandWorked(configAdmin.runCommand({
setShardVersion: '',
init: true,
authoritative: true,
configdb: alternateConfigStr,
shard: 'config'
}));
st.stop();
})();
|