File: migrateBig.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 (61 lines) | stat: -rw-r--r-- 1,891 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
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

s = new ShardingTest( "migrateBig" , 2 , 0 , 1 , { chunksize : 1 } );
s.config.settings.update( { _id: "balancer" }, { $set : { stopped : true, _waitForDelete : true } } , true );
s.adminCommand( { enablesharding : "test" } );
s.adminCommand( { shardcollection : "test.foo" , key : { x : 1 } } );

db = s.getDB( "test" )
coll = db.foo

big = ""
while ( big.length < 10000 )
    big += "eliot"

for ( x=0; x<100; x++ )
    coll.insert( { x : x , big : big } )
db.getLastError();

s.adminCommand( { split : "test.foo" , middle : { x : 33 } } )
s.adminCommand( { split : "test.foo" , middle : { x : 66 } } )
s.adminCommand( { movechunk : "test.foo" , find : { x : 90 } , to : s.getOther( s.getServer( "test" ) ).name } )

db.printShardingStatus()

print( "YO : "  + s.getServer( "test" ).host )
direct = new Mongo( s.getServer( "test" ).host )
print( "direct : " + direct )

directDB = direct.getDB( "test" )

for ( done=0; done<2*1024*1024; done+=big.length ){
    directDB.foo.insert( { x : 50 + Math.random() , big : big } )
    directDB.getLastError();
}

db.printShardingStatus()

assert.throws( function(){  s.adminCommand( { movechunk : "test.foo" , find : { x : 50 } , to : s.getOther( s.getServer( "test" ) ).name } ); } , [] , "move should fail" )

for ( i=0; i<20; i+= 2 ) {
    try {
        s.adminCommand( { split : "test.foo" , middle : { x : i } } );
    }
    catch ( e ) {
        // we may have auto split on some of these
        // which is ok
        print(e);
    }
}

db.printShardingStatus()


s.config.settings.update( { _id: "balancer" }, { $set : { stopped: false } } , true );

assert.soon( function(){ var x = s.chunkDiff( "foo" , "test" ); print( "chunk diff: " + x ); return x < 2; } , "no balance happened" , 8 * 60 * 1000 , 2000 ) 

assert.soon( function(){ return !s.isAnyBalanceInFlight(); } );

assert.eq( coll.count() , coll.find().itcount() );

s.stop()