summaryrefslogtreecommitdiff
path: root/jstests/sharding/jumbo1.js
blob: f26b0f36268d486eb6dab70221adeeb78496e330 (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
(function() {
'use strict';

var s = new ShardingTest({shards: 2, mongos: 1, other: {chunkSize: 1, enableAutoSplit: true}});

assert.commandWorked(s.s0.adminCommand({enablesharding: "test"}));
s.ensurePrimaryShard('test', s.shard1.shardName);
assert.commandWorked(s.s0.adminCommand({shardcollection: "test.foo", key: {x: 1}}));

var db = s.getDB("test");

const big = 'X'.repeat(10000);

// Create sufficient documents to create a jumbo chunk, and use the same shard key in all of
// them so that the chunk cannot be split.
var x = 0;
var bulk = db.foo.initializeUnorderedBulkOp();
for (var i = 0; i < 500; i++) {
    bulk.insert({x: x, big: big});
}

// Create documents with different shard keys that can be split and moved without issue.
for (; x < 1500; x++) {
    bulk.insert({x: x, big: big});
}

assert.commandWorked(bulk.execute());

s.printShardingStatus(true);

s.startBalancer();

function diff1() {
    var x = s.chunkCounts("foo");
    printjson(x);
    return Math.max(x[s.shard0.shardName], x[s.shard1.shardName]) -
        Math.min(x[s.shard0.shardName], x[s.shard1.shardName]);
}

assert.soon(function() {
    var d = diff1();
    print("diff: " + d);
    s.printShardingStatus(true);
    return d < 5;
}, "balance didn't happen", 1000 * 60 * 10, 5000);

// Check that the jumbo chunk did not move, which shouldn't be possible.
var jumboChunk =
    s.getDB('config').chunks.findOne({ns: 'test.foo', min: {$lte: {x: 0}}, max: {$gt: {x: 0}}});
assert.eq(s.shard1.shardName, jumboChunk.shard, 'jumbo chunk ' + tojson(jumboChunk) + ' was moved');

// TODO: SERVER-26531 Make sure that balancer marked the first chunk as jumbo.
// Assumption: balancer favors moving the lowest valued chunk out of a shard.
// assert(jumboChunk.jumbo, tojson(jumboChunk));

s.stop();
})();