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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
// Test db case checking with replication SERVER-2111
baseName = "jstests_repl_dbcase";
rt = new ReplTest( baseName );
m = rt.start( true );
s = rt.start( false );
n1 = "dbname";
n2 = "dbNAme";
/**
* The value of n should be n1 or n2. Check that n is soon present while its
* opposite is not present.
*/
function check( n ) {
assert.soon( function() {
try {
// Our db name changes may trigger an exception - SERVER-3189.
names = s.getDBNames();
} catch (e) {
return false;
}
n1Idx = names.indexOf( n1 );
n2Idx = names.indexOf( n2 );
if ( n1Idx != -1 && n2Idx != -1 ) {
// n1 and n2 may both be reported as present transiently.
return false;
}
// Return true if we matched expected n.
return -1 != names.indexOf( n );
} );
}
/** Allow some time for additional operations to be processed by the slave. */
function checkTwice( n ) {
check( n );
// zzz is expected to be cloned after n1 and n2 because of its position in the alphabet.
m.getDB( "zzz" ).c.save( {} );
assert.soon( function() { return s.getDB( "zzz" ).c.count(); } )
check( n );
m.getDB( "zzz" ).dropDatabase();
}
/**
* The slave may create in memory db names on the master matching old dbs it is
* attempting to clone. This function forces operation 'cmd' by deleting those
* in memory dbs if necessary. This function should only be called in cases where
* 'cmd' would succeed if not for the in memory dbs on master created by the slave.
*/
function force( cmd ) {
print( "cmd: " + cmd );
eval( cmd );
while( m1.getLastError() ) {
sleep( 100 );
m1.dropDatabase();
m2.dropDatabase();
eval( cmd );
}
}
m1 = m.getDB( n1 );
m2 = m.getDB( n2 );
m1.c.save( {} );
m2.c.save( {} ); // will fail due to conflict
m1.getLastError(); // Wait for write operations to complete.
check( n1 );
m1.dropDatabase();
force( "m2.c.save( {} );" ); // will now succeed
check( n2 );
m2.dropDatabase();
force( "m1.c.save( {} );" );
check( n1 );
for( i = 0; i < 5; ++i ) {
m1.dropDatabase();
force( "m2.c.save( {} );" );
m2.dropDatabase();
force( "m1.c.save( {} );" );
}
checkTwice( n1 );
m1.dropDatabase();
force( "m2.c.save( {} );" );
for( i = 0; i < 5; ++i ) {
m2.dropDatabase();
force( "m1.c.save( {} );" );
m1.dropDatabase();
force( "m2.c.save( {} );" );
}
checkTwice( n2 );
|