blob: 653326e2ab604a001fa8b9d5accb1b19e259b9e0 (
plain)
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
|
function setupMoveChunkTest(shardOptions) {
var st = new ShardingTest({
shards: 2,
mongos: 1,
other: {
chunkSize: 1,
shardOptions: shardOptions,
}
});
// Stop Balancer
st.stopBalancer();
var testdb = st.getDB("test");
var testcoll = testdb.foo;
st.adminCommand({enablesharding: "test"});
st.ensurePrimaryShard('test', st.shard1.shardName);
st.adminCommand({shardcollection: "test.foo", key: {_id: 1}});
var str = "";
while (str.length < 10000) {
str += "asdasdsdasdasdasdas";
}
var data = 0;
var num = 0;
// Insert till you get to 10MB of data
var bulk = testcoll.initializeUnorderedBulkOp();
while (data < (1024 * 1024 * 10)) {
bulk.insert({_id: num++, s: str});
data += str.length;
}
assert.commandWorked(bulk.execute());
// Make sure there are chunks to move
for (var i = 0; i < 10; ++i) {
assert.commandWorked(st.splitFind("test.foo", {_id: i}));
}
var stats = st.chunkCounts("foo");
var to = "";
for (shard in stats) {
if (stats[shard] == 0) {
to = shard;
break;
}
}
var result = st.adminCommand({
movechunk: "test.foo",
find: {_id: 1},
to: to,
_waitForDelete: true
}); // some tests need this...
assert(result, "movechunk failed: " + tojson(result));
return st;
}
|