summaryrefslogtreecommitdiff
path: root/jstests/sharding/moveshard1.js
blob: 9220983ab10f3f500878d293eb45dbc9c1e5b08c (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
// movechunk1.js

s = new ShardingTest( "movechunk1" , 2 );

l = s._connections[0];
r = s._connections[1];

ldb = l.getDB( "foo" );
rdb = r.getDB( "foo" );

ldb.things.save( { a : 1 } )
ldb.things.save( { a : 2 } )
ldb.things.save( { a : 3 } )

assert.eq( ldb.things.count() , 3 );
assert.eq( rdb.things.count() , 0 );

startResult = l.getDB( "admin" ).runCommand( { "movechunk.start" : "foo.things" , 
                                               "to" : s._connections[1].name , 
                                               "from" : s._connections[0].name , 
                                               filter : { a : { $gt : 2 } }
                                             } );
print( "movechunk.start: " + tojson( startResult ) );
assert( startResult.ok == 1 , "start failed!" );

finishResult = l.getDB( "admin" ).runCommand( { "movechunk.finish" : "foo.things" , 
                                                finishToken : startResult.finishToken ,
                                                to : s._connections[1].name , 
                                                newVersion : 1 } );
print( "movechunk.finish: " + tojson( finishResult ) );
assert( finishResult.ok == 1 , "finishResult failed!" );

assert.eq( rdb.things.count() , 1 , "right has wrong size after move" );
assert.eq( ldb.things.count() , 2 , "left has wrong size after move" );


s.stop();