2010-07-12 16:38:57 +02:00
|
|
|
// count2.js
|
|
|
|
|
|
|
|
s1 = new ShardingTest( "count2" , 2 , 1 , 2 );
|
|
|
|
s2 = s1._mongos[1];
|
|
|
|
|
|
|
|
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" );
|
|
|
|
|
2010-07-16 18:30:37 +02:00
|
|
|
s1.printChunks( "test.foo" )
|
|
|
|
|
2010-07-12 16:38:57 +02:00
|
|
|
s1.adminCommand( { movechunk : "test.foo" , find : { name : "aaa" } , to : s1.getOther( s1.getServer( "test" ) ).name } );
|
|
|
|
|
|
|
|
assert.eq( 3, db1.count( { name : { $gte: "aaa" , $lt: "ddd" } } ) , "post count mongos1" );
|
2010-07-16 06:31:43 +02:00
|
|
|
|
2010-07-12 16:38:57 +02:00
|
|
|
// The second mongos still thinks its shard mapping is valid and accepts a cound
|
2010-07-16 18:30:37 +02:00
|
|
|
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" );
|
2010-07-12 16:38:57 +02:00
|
|
|
|
|
|
|
db2.findOne();
|
|
|
|
|
|
|
|
assert.eq( 3, db2.count( { name : { $gte: "aaa" , $lt: "ddd" } } ) );
|
|
|
|
|
2010-07-16 06:31:43 +02:00
|
|
|
s1.stop();
|