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-04-28 23:54:25 +02:00
|
|
|
soonCount = function( m, count ) {
|
2009-03-17 18:18:54 +01:00
|
|
|
assert.soon( function() {
|
2009-03-17 22:20:08 +01:00
|
|
|
// print( "counting" );
|
2009-04-23 19:55:07 +02:00
|
|
|
//// print( "counted: " + l.getDB( baseName ).z.find().count() );
|
2009-04-28 23:54:25 +02:00
|
|
|
return m.getDB( baseName ).z.find().count() == count;
|
2009-03-17 18:18:54 +01:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2009-03-12 18:08:16 +01:00
|
|
|
doTest = function( signal ) {
|
2009-04-02 00:21:07 +02:00
|
|
|
|
|
|
|
ports = allocatePorts( 3 );
|
2009-03-12 18:08:16 +01:00
|
|
|
|
2009-04-28 23:54:25 +02:00
|
|
|
a = new MongodRunner( ports[ 0 ], "/data/db/" + baseName + "-arbiter" );
|
|
|
|
l = new MongodRunner( ports[ 1 ], "/data/db/" + baseName + "-left", "127.0.0.1:" + ports[ 2 ], "127.0.0.1:" + ports[ 0 ] );
|
|
|
|
r = new MongodRunner( ports[ 2 ], "/data/db/" + baseName + "-right", "127.0.0.1:" + ports[ 1 ], "127.0.0.1:" + ports[ 0 ] );
|
2009-03-12 18:08:16 +01:00
|
|
|
|
2009-04-28 23:54:25 +02:00
|
|
|
rp = new ReplPair( l, r, a );
|
|
|
|
rp.start();
|
|
|
|
rp.waitForSteadyState();
|
|
|
|
|
|
|
|
rp.slave().setSlaveOk();
|
|
|
|
mz = rp.master().getDB( baseName ).z;
|
2009-03-12 18:08:16 +01:00
|
|
|
|
2009-04-28 23:54:25 +02:00
|
|
|
mz.save( { _id: new ObjectId() } );
|
|
|
|
soonCount( rp.slave(), 1 );
|
|
|
|
assert.eq( 0, rp.slave().getDB( "admin" ).runCommand( { "resync" : 1 } ).ok );
|
2009-03-17 22:20:08 +01:00
|
|
|
|
2009-04-15 22:52:39 +02:00
|
|
|
sleep( 3000 ); // allow time to finish clone and save ReplSource
|
2009-04-28 23:54:25 +02:00
|
|
|
rp.killNode( rp.slave(), signal );
|
|
|
|
rp.waitForSteadyState( [ 1, null ], rp.master().host );
|
2009-03-12 18:08:16 +01:00
|
|
|
|
|
|
|
big = new Array( 2000 ).toString();
|
|
|
|
for( i = 0; i < 1000; ++i )
|
2009-04-28 23:54:25 +02:00
|
|
|
mz.save( { _id: new ObjectId(), i: i, b: big } );
|
2009-04-23 19:05:03 +02:00
|
|
|
|
2009-04-28 23:54:25 +02:00
|
|
|
rp.start( true );
|
|
|
|
rp.waitForSteadyState( [ 1, 0 ], rp.master().host );
|
|
|
|
|
2009-04-23 19:05:03 +02:00
|
|
|
sleep( 15000 );
|
|
|
|
|
2009-04-28 23:54:25 +02:00
|
|
|
rp.slave().setSlaveOk();
|
2009-04-15 22:52:39 +02:00
|
|
|
assert.soon( function() {
|
2009-04-28 23:54:25 +02:00
|
|
|
ret = rp.slave().getDB( "admin" ).runCommand( { "resync" : 1 } );
|
2009-04-15 22:52:39 +02:00
|
|
|
// printjson( ret );
|
|
|
|
return 1 == ret.ok;
|
|
|
|
} );
|
2009-03-12 18:08:16 +01:00
|
|
|
|
2009-03-24 16:42:21 +01:00
|
|
|
sleep( 8000 );
|
2009-04-28 23:54:25 +02:00
|
|
|
soonCount( rp.slave(), 1001 );
|
|
|
|
sz = rp.slave().getDB( baseName ).z
|
|
|
|
assert.eq( 1, sz.find( { i: 0 } ).count() );
|
|
|
|
assert.eq( 1, sz.find( { i: 999 } ).count() );
|
2009-03-12 18:08:16 +01:00
|
|
|
|
2009-04-28 23:54:25 +02:00
|
|
|
assert.eq( 0, rp.slave().getDB( "admin" ).runCommand( { "resync" : 1 } ).ok );
|
2009-03-12 18:08:16 +01:00
|
|
|
|
2009-04-02 01:51:41 +02:00
|
|
|
ports.forEach( function( x ) { stopMongod( x ); } );
|
|
|
|
|
2009-03-12 18:08:16 +01:00
|
|
|
}
|
2009-02-02 15:54:00 +01:00
|
|
|
|
2009-03-12 18:08:16 +01:00
|
|
|
doTest( 15 ); // SIGTERM
|
|
|
|
doTest( 9 ); // SIGKILL
|