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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
(function() {
'use strict';
load("jstests/libs/discover_topology.js");
load("jstests/sharding/libs/resharding_test_fixture.js");
const kNamespace = 'test.resharding';
function getCurrentOpSection(mongo, role) {
let curOpSection = {};
assert.soon(() => {
const report = mongo.getDB("admin").currentOp(
{ns: kNamespace, desc: {$regex: 'ReshardingMetrics' + role + 'Service'}});
if (report.inprog.length === 1) {
curOpSection = report.inprog[0];
return true;
}
jsTest.log(tojson(report));
return false;
}, `: was unable to find resharding ${role} service in currentOp output from ${mongo.host}`);
return curOpSection;
}
function getServerStatusSection(mongo) {
const stats = mongo.getDB('admin').serverStatus({});
assert(stats.hasOwnProperty('shardingStatistics'), stats);
const shardingStats = stats.shardingStatistics;
assert(shardingStats.hasOwnProperty('resharding'),
`Missing resharding section in ${tojson(shardingStats)}`);
return shardingStats.resharding;
}
const reshardingTest = new ReshardingTest({numDonors: 2, numRecipients: 2, reshardInPlace: true});
reshardingTest.setup();
const donorShardNames = reshardingTest.donorShardNames;
const inputCollection = reshardingTest.createShardedCollection({
ns: kNamespace,
shardKeyPattern: {oldKey: 1},
chunks: [
{min: {oldKey: MinKey}, max: {oldKey: 0}, shard: donorShardNames[0]},
{min: {oldKey: 0}, max: {oldKey: MaxKey}, shard: donorShardNames[1]},
],
});
const recipientShardNames = reshardingTest.recipientShardNames;
const topology = DiscoverTopology.findConnectedNodes(inputCollection.getMongo());
reshardingTest.withReshardingInBackground(
{
newShardKeyPattern: {newKey: 1},
newChunks: [
{min: {newKey: MinKey}, max: {newKey: 0}, shard: recipientShardNames[0]},
{min: {newKey: 0}, max: {newKey: MaxKey}, shard: recipientShardNames[1]},
],
},
(tempNs) => {
// Wait for the resharding operation and the donor services to start.
const mongos = inputCollection.getMongo();
assert.soon(() => {
const coordinatorDoc = mongos.getCollection("config.reshardingOperations").findOne({
ns: inputCollection.getFullName()
});
return coordinatorDoc !== null && coordinatorDoc.cloneTimestamp !== undefined;
});
donorShardNames.forEach(function(shardName) {
const curOpSection =
getCurrentOpSection(new Mongo(topology.shards[shardName].primary), "Donor");
assert(curOpSection.hasOwnProperty('donorState'), tojson(curOpSection));
assert(curOpSection.hasOwnProperty('totalCriticalSectionTimeElapsedSecs'),
tojson(curOpSection));
});
recipientShardNames.forEach(function(shardName) {
const curOpSection =
getCurrentOpSection(new Mongo(topology.shards[shardName].primary), "Recipient");
assert(curOpSection.hasOwnProperty('recipientState'), tojson(curOpSection));
assert(curOpSection.hasOwnProperty('documentsCopied'), tojson(curOpSection));
assert(curOpSection.hasOwnProperty('oplogEntriesApplied'), tojson(curOpSection));
assert(curOpSection.hasOwnProperty('remainingOperationTimeEstimatedSecs'),
tojson(curOpSection));
});
const curOpSection =
getCurrentOpSection(new Mongo(topology.configsvr.nodes[0]), "Coordinator");
assert(curOpSection.hasOwnProperty('coordinatorState'), tojson(curOpSection));
assert(curOpSection.hasOwnProperty('totalCriticalSectionTimeElapsedSecs'),
tojson(curOpSection));
});
let allNodes = [];
for (let [_, shardReplSet] of Object.entries(topology.shards)) {
allNodes.push(shardReplSet.primary);
}
allNodes.push(topology.configsvr.primary);
allNodes.forEach((hostName) => {
const serverStatus = getServerStatusSection(new Mongo(hostName));
let debugStr = () => {
return 'server: ' + tojson(hostName) + ', serverStatusSection: ' + tojson(serverStatus);
};
assert(serverStatus.hasOwnProperty('countSucceeded'), debugStr());
assert(serverStatus.hasOwnProperty('countFailed'), debugStr());
assert(serverStatus.hasOwnProperty('active'), debugStr());
assert(serverStatus.active.hasOwnProperty('documentsCopied'), debugStr());
assert(serverStatus.hasOwnProperty('oldestActive'), debugStr());
assert(
serverStatus.oldestActive.hasOwnProperty('recipientRemainingOperationTimeEstimatedMillis'),
debugStr());
assert(serverStatus.hasOwnProperty('latencies'), debugStr());
assert(serverStatus.latencies.hasOwnProperty('collectionCloningTotalLocalInsertTimeMillis'),
debugStr());
assert(serverStatus.hasOwnProperty('currentInSteps'), debugStr());
assert(serverStatus.currentInSteps.hasOwnProperty(
'countInstancesInRecipientState2CreatingCollection'),
debugStr());
});
reshardingTest.teardown();
})();
|