File: hash_shard_num_chunks.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (35 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download | duplicates (3)
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
// Hash sharding with initial chunk count set.

var s = new ShardingTest({ shards : 3, mongos : 1, verbose : 1 });
var dbname = "test";
var coll = "foo";
var db = s.getDB(dbname);
db.adminCommand({ enablesharding : dbname });

//for simplicity turn off balancer
s.stopBalancer();

var res = db.adminCommand({ shardcollection : dbname + "." + coll,
                             key : { a : "hashed" },
                             numInitialChunks : 500 });
assert.eq(res.ok, 1, "shardcollection didn't work");
db.printShardingStatus();
var numChunks = s.config.chunks.count();
assert.eq(numChunks, 500 , "should be exactly 500 chunks");

var shards = s.config.shards.find();
shards.forEach(
    // check that each shard has one third the numInitialChunks
    function (shard){
        var numChunksOnShard = s.config.chunks.find({"shard" : shard._id}).count();
        assert.gte(numChunksOnShard, Math.floor(500/3));
    }
);

// Check that the collection gets dropped correctly (which doesn't happen if pre-splitting
// fails to create the collection on all shards).
res = db.runCommand({ "drop" : coll });
assert.eq(res.ok, 1, "couldn't drop empty, pre-split collection");

s.stop();