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
|
/*
1) Add shard
2) topology time must increase
3) remove shard
4) topology time must increase
*/
function assertTopologyGt(topologyTime1, topologyTime2, msg) {
let msgError = `[${tojson(topologyTime1)} <= ${tojson(topologyTime2)}] ${msg}`;
assert.gt(timestampCmp(topologyTime1, topologyTime2), 0, msgError);
}
function cmdAsInternalClient(st, cmd) {
const command =
{[cmd]: 1, internalClient: {minWireVersion: NumberInt(0), maxWireVersion: NumberInt(7)}};
const connInternal = new Mongo(st.configRS.getPrimary().host);
const res = assert.commandWorked(connInternal.adminCommand(command));
connInternal.close();
return res;
}
function getTopologyTime(st) {
let res = cmdAsInternalClient(st, "hello");
return res.$topologyTime;
}
function printConfigShards(st, msg) {
print(msg, tojson(st.s.getDB("config").shards.find().toArray()));
}
(function() {
'use strict';
load('jstests/sharding/libs/remove_shard_util.js');
var st = new ShardingTest({shards: 1, rs: {nodes: 1}, config: 3});
let initialTopology = getTopologyTime(st);
// AddShard
let rs = new ReplSetTest({name: "rs1", nodes: 1});
rs.startSet({shardsvr: ""});
rs.initiate();
rs.awaitReplication();
assert.commandWorked(st.s.getDB("admin").runCommand({addShard: rs.getURL(), name: "rs1"}));
let topologyTimeAfterAddShard = getTopologyTime(st);
// topology time must increase
assertTopologyGt(topologyTimeAfterAddShard,
initialTopology,
"Current topologyTime should change after add shard, but it did not");
removeShard(st, "rs1");
printConfigShards(st, "config.shards after remove shard ");
let topologyTimeAfterRemoveShard = getTopologyTime(st);
// topology time should change
assertTopologyGt(topologyTimeAfterRemoveShard,
topologyTimeAfterAddShard,
"Current topologyTime should change after remove shard, but it did not");
rs.stopSet();
st.stop();
})();
|