summaryrefslogtreecommitdiff
path: root/jstests/sharding/tag_auto_split.js
blob: 835ec3b154674c9b2f40d94d416afd967edb29e2 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Test to make sure that tag ranges get split
(function() {

var s = new ShardingTest({ name: "tag_auto_split",
                           shards: 2,
                           mongos: 1,
                           other: { enableBalancer : true } });

db = s.getDB( "test" );

s.adminCommand( { enablesharding : "test" } );
s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );

assert.eq( 1, s.config.chunks.count() );

sh.addShardTag( "shard0000" , "a" );

sh.addTagRange( "test.foo" , { _id : 5 } , { _id : 10 } , "a" );
sh.addTagRange( "test.foo" , { _id : 10 } , { _id : 15 } , "b" );

assert.soon( function() {
    return s.config.chunks.count() == 3;
}, "things didn't get split", 1000 * 60 * 10, 1000 );

s.printShardingStatus();

s.stop();

//test without full shard key on tags
s = new ShardingTest({ name: "tag_auto_split2",
                       shards: 2,
                       mongos: 1,
                       other: { enableBalancer : true } });

db = s.getDB( "test" );

s.adminCommand( { enablesharding : "test" } );
s.ensurePrimaryShard('test', 'shard0001');
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1, a : 1 } } );

assert.eq( 1, s.config.chunks.count() );

sh.addShardTag( "shard0000" , "a" );

sh.addTagRange( "test.foo" , { _id : 5 } , { _id : 10 } , "a" );
sh.addTagRange( "test.foo" , { _id : 10 } , { _id : 15 } , "b" );

assert.soon( function() {
    return s.config.chunks.count() == 3;
}, "things didn't get split", 1000 * 60 * 10, 1000 );

s.config.chunks.find().forEach(
    function(chunk){
        var numFields = 0;
        for ( var x in chunk.min ) {
            numFields++;
            assert( x == "_id" || x == "a", tojson(chunk) );
        }
        assert.eq( 2, numFields,tojson(chunk) );
    }
);

// check chunk mins correspond exactly to tag range boundaries, extended to match shard key
assert.eq( 1, s.config.chunks.find( {min : {_id : 5 , a : MinKey} } ).count(),
           "bad chunk range boundary" );
assert.eq( 1, s.config.chunks.find( {min : {_id : 10 , a : MinKey} } ).count(),
           "bad chunk range boundary" );

s.stop();

})();