2009-02-02 15:54:00 +01:00
|
|
|
// Pairing resync
|
|
|
|
|
|
|
|
var baseName = "jstests_pair2test";
|
|
|
|
|
|
|
|
ismaster = function( n ) {
|
|
|
|
im = n.getDB( "admin" ).runCommand( { "ismaster" : 1 } );
|
|
|
|
assert( im );
|
|
|
|
return im.ismaster;
|
|
|
|
}
|
|
|
|
|
2009-03-17 18:18:54 +01:00
|
|
|
soonCount = function( count ) {
|
|
|
|
assert.soon( function() {
|
|
|
|
if ( -1 == l.getDBNames().indexOf( baseName ) )
|
|
|
|
return false;
|
|
|
|
if ( -1 == l.getDB( baseName ).getCollectionNames().indexOf( "z" ) )
|
|
|
|
return false;
|
|
|
|
return l.getDB( baseName ).z.find().count() == count;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2009-03-12 18:08:16 +01:00
|
|
|
doTest = function( signal ) {
|
|
|
|
|
|
|
|
// spec small oplog for fast startup on 64bit machines
|
|
|
|
a = startMongod( "--port", "27018", "--dbpath", "/data/db/" + baseName + "-arbiter" );
|
|
|
|
l = startMongod( "--port", "27019", "--dbpath", "/data/db/" + baseName + "-left", "--pairwith", "127.0.0.1:27020", "127.0.0.1:27018", "--oplogSize", "1" );
|
|
|
|
r = startMongod( "--port", "27020", "--dbpath", "/data/db/" + baseName + "-right", "--pairwith", "127.0.0.1:27019", "127.0.0.1:27018", "--oplogSize", "1" );
|
|
|
|
l.setSlaveOk();
|
|
|
|
|
|
|
|
assert.soon( function() { return ( ismaster( l ) == 0 && ismaster( r ) == 1 ); } );
|
|
|
|
|
|
|
|
lz = l.getDB( baseName ).z
|
|
|
|
rz = r.getDB( baseName ).z
|
|
|
|
|
|
|
|
rz.save( { _id: new ObjectId() } );
|
2009-03-17 18:18:54 +01:00
|
|
|
soonCount( 1 );
|
2009-03-12 18:08:16 +01:00
|
|
|
assert.eq( 0, l.getDB( "admin" ).runCommand( { "resync" : 1 } ).ok );
|
|
|
|
|
2009-03-17 18:18:54 +01:00
|
|
|
// Allow slave to save its db list -- eventually we can remove the sleep.
|
|
|
|
sleep( 10000 );
|
|
|
|
|
2009-03-12 18:08:16 +01:00
|
|
|
stopMongod( 27019, signal );
|
|
|
|
|
|
|
|
big = new Array( 2000 ).toString();
|
|
|
|
for( i = 0; i < 1000; ++i )
|
|
|
|
rz.save( { _id: new ObjectId(), i: i, b: big } );
|
|
|
|
|
|
|
|
l = startMongoProgram( "mongod", "--port", "27019", "--dbpath", "/data/db/" + baseName + "-left", "--pairwith", "127.0.0.1:27020", "127.0.0.1:27018", "--oplogSize", "1" );
|
|
|
|
l.setSlaveOk();
|
|
|
|
assert.soon( function() { return 1 == l.getDB( "admin" ).runCommand( { "resync" : 1 } ).ok; } );
|
|
|
|
|
2009-03-17 18:18:54 +01:00
|
|
|
sleep( 10000 );
|
|
|
|
|
|
|
|
soonCount( 1001 );
|
2009-03-12 18:08:16 +01:00
|
|
|
lz = l.getDB( baseName ).z
|
|
|
|
assert.eq( 1, lz.find( { i: 0 } ).count() );
|
|
|
|
assert.eq( 1, lz.find( { i: 999 } ).count() );
|
|
|
|
|
|
|
|
assert.eq( 0, l.getDB( "admin" ).runCommand( { "resync" : 1 } ).ok );
|
|
|
|
|
|
|
|
stopMongod( 27018 );
|
|
|
|
stopMongod( 27019 );
|
|
|
|
stopMongod( 27020 );
|
|
|
|
}
|
2009-02-02 15:54:00 +01:00
|
|
|
|
2009-03-12 18:08:16 +01:00
|
|
|
doTest( 15 ); // SIGTERM
|
|
|
|
doTest( 9 ); // SIGKILL
|