summaryrefslogtreecommitdiff
path: root/jstests/sharding/movechunk_include.js
blob: 285ec587682674a4a9ce8c5b7f08417c81917b60 (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
function setupMoveChunkTest(st) {
    // 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.writeOK(bulk.execute());

    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));
}