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
60
61
62
63
64
65
66
67
68
69
|
(function() {
load("jstests/sharding/libs/find_chunks_util.js");
var s = new ShardingTest({name: "keystring", shards: 2});
s.adminCommand({enablesharding: "test"});
s.ensurePrimaryShard('test', s.shard1.shardName);
s.adminCommand({shardcollection: "test.foo", key: {name: 1}});
let primary = s.getPrimaryShard("test").getDB("test");
let seconday = s.getOther(primary).getDB("test");
assert.eq(1, findChunksUtil.countChunksForNs(s.config, "test.foo"), "sanity check A");
var db = s.getDB("test");
db.foo.save({name: "eliot"});
db.foo.save({name: "sara"});
db.foo.save({name: "bob"});
db.foo.save({name: "joe"});
db.foo.save({name: "mark"});
db.foo.save({name: "allan"});
assert.eq(6, db.foo.find().count(), "basic count");
s.adminCommand({split: "test.foo", middle: {name: "allan"}});
s.adminCommand({split: "test.foo", middle: {name: "sara"}});
s.adminCommand({split: "test.foo", middle: {name: "eliot"}});
s.adminCommand({
movechunk: "test.foo",
find: {name: "eliot"},
to: seconday.getMongo().name,
_waitForDelete: true
});
s.printChunks();
assert.eq(3, primary.foo.find().toArray().length, "primary count");
assert.eq(3, seconday.foo.find().toArray().length, "secondary count");
assert.eq(6, db.foo.find().toArray().length, "total count");
assert.eq(6, db.foo.find().sort({name: 1}).toArray().length, "total count sorted");
assert.eq(6, db.foo.find().sort({name: 1}).count(), "total count with count()");
assert.eq("allan,bob,eliot,joe,mark,sara",
db.foo.find().sort({name: 1}).toArray().map(function(z) {
return z.name;
}),
"sort 1");
assert.eq("sara,mark,joe,eliot,bob,allan",
db.foo.find().sort({name: -1}).toArray().map(function(z) {
return z.name;
}),
"sort 2");
// make sure we can't foce a split on an extreme key
// [allan->joe)
assert.throws(function() {
s.adminCommand({split: "test.foo", middle: {name: "allan"}});
});
assert.throws(function() {
s.adminCommand({split: "test.foo", middle: {name: "eliot"}});
});
s.stop();
})();
|