File: count2.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 (49 lines) | stat: -rw-r--r-- 1,682 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
// count2.js

s1 = new ShardingTest( "count2" , 2 , 1 , 2 );
s2 = s1._mongos[1];
s1.stopBalancer();

s1.adminCommand( { enablesharding: "test" } );
s1.adminCommand( { shardcollection: "test.foo" , key : { name : 1 } } );

db1 = s1.getDB( "test" ).foo;
db2 = s2.getDB( "test" ).foo;

assert.eq( 1, s1.config.chunks.count(), "sanity check A");

db1.save( { name : "aaa" } )
db1.save( { name : "bbb" } )
db1.save( { name : "ccc" } )
db1.save( { name : "ddd" } )
db1.save( { name : "eee" } )
db1.save( { name : "fff" } )

s1.adminCommand( { split : "test.foo" , middle : { name : "ddd" } } );

assert.eq( 3, db1.count( { name : { $gte: "aaa" , $lt: "ddd" } } ) , "initial count mongos1" );
assert.eq( 3, db2.count( { name : { $gte: "aaa" , $lt: "ddd" } } ) , "initial count mongos2" );

s1.printChunks( "test.foo" )

s1.adminCommand( { movechunk : "test.foo" , find : { name : "aaa" } , to : s1.getOther( s1.getServer( "test" ) ).name, _waitForDelete : true });

assert.eq( 3, db1.count( { name : { $gte: "aaa" , $lt: "ddd" } } ) , "post count mongos1" );

// The second mongos still thinks its shard mapping is valid and accepts a cound
print( "before sleep: " + Date() )
sleep( 2000 )
print( "after  sleep: " + Date() )
s1.printChunks( "test.foo" )
assert.eq( 3, db2.find( { name : { $gte: "aaa" , $lt: "ddd" } } ).count() , "post count mongos2" );

db2.findOne();

assert.eq( 3, db2.count( { name : { $gte: "aaa" , $lt: "ddd" } } ) );

assert.eq( 4, db2.find().limit( 4 ).count( true ));
assert.eq( 4, db2.find().limit( -4 ).count( true ));
assert.eq( 6, db2.find().limit( 0 ).count( true ));
assert.eq( 6, db2.getDB().runCommand({ count: db2.getName(), limit: 0 }).n );

s1.stop();