summaryrefslogtreecommitdiff
path: root/jstests/sharding/fair_balancer_round.js
blob: 90fc345c8cbab6415734816eb53f0f51af366f1f (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
//
// Tests that a balancer round loads newly sharded collection data
//

var options = {
    mongosOptions: {verbose: 1}
};

var st = new ShardingTest({shards: 2, mongos: 2, other: options});

// Stop balancer initially
st.stopBalancer();

var mongos = st.s0;
var staleMongos = st.s1;
var coll = mongos.getCollection("foo.bar");

// Shard collection through first mongos
assert(mongos.adminCommand({enableSharding: coll.getDB() + ""}).ok);
st.ensurePrimaryShard(coll.getDB().getName(), 'shard0001');
assert(mongos.adminCommand({shardCollection: coll + "", key: {_id: 1}}).ok);

// Create a bunch of chunks
var numSplits = 20;
for (var i = 0; i < numSplits; i++) {
    assert(mongos.adminCommand({split: coll + "", middle: {_id: i}}).ok);
}

// Stop the first mongos who setup the cluster.
st.stopMongos(0);

// Start balancer, which lets the stale mongos balance
assert.writeOK(staleMongos.getDB("config")
                   .settings.update({_id: "balancer"}, {$set: {stopped: false}}, true));

// Make sure we eventually start moving chunks
assert.soon(function() {
    return staleMongos.getCollection("config.changelog").count({what: /moveChunk/}) > 0;
}, "no balance happened", 5 * 60 * 1000);

jsTest.log("DONE!");

st.stop();