diff --git a/db/repl.cpp b/db/repl.cpp index d18efc1ec08..36fd6161f61 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -325,7 +325,7 @@ namespace mongo { int was = cmdObj.getIntField("i_was"); string myname = cmdObj.getStringField("your_name"); - if ( myname.empty() || was < -1 ) { + if ( myname.empty() || was < -3 ) { errmsg = "your_name/i_was not specified"; return false; } diff --git a/jstests/repl/pair3.js b/jstests/repl/pair3.js new file mode 100644 index 00000000000..7903cc79d27 --- /dev/null +++ b/jstests/repl/pair3.js @@ -0,0 +1,90 @@ +// test arbitration + +var baseName = "jstests_pair3test"; + +ismaster = function( n ) { + var im = n.getDB( "admin" ).runCommand( { "ismaster" : 1 } ); + print( "ismaster: " + tojson( im ) ); + assert( im, "command ismaster failed" ); + return im.ismaster; +} + +connect = function() { + startMongoProgram( "mongobridge", "--port", alPort, "--dest", "localhost:" + aPort ); + startMongoProgram( "mongobridge", "--port", arPort, "--dest", "localhost:" + aPort ); + startMongoProgram( "mongobridge", "--port", lpPort, "--dest", "localhost:" + lPort ); + startMongoProgram( "mongobridge", "--port", rpPort, "--dest", "localhost:" + rPort ); +} + +doTest = function() { + ports = allocatePorts( 7 ); + aPort = ports[ 0 ]; + alPort = ports[ 1 ]; + arPort = ports[ 2 ]; + lPort = ports[ 3 ]; + lpPort = ports[ 4 ]; + rPort = ports[ 5 ]; + rpPort = ports[ 6 ]; + + connect(); + + a = startMongod( "--port", aPort, "--dbpath", "/data/db/" + baseName + "-arbiter", "--nohttpinterface" ); + l = startMongod( "--port", lPort, "--dbpath", "/data/db/" + baseName + "-left", "--pairwith", "127.0.0.1:" + rpPort, "127.0.0.1:" + alPort, "--oplogSize", "1", "--nohttpinterface" ); + r = startMongod( "--port", rPort, "--dbpath", "/data/db/" + baseName + "-right", "--pairwith", "127.0.0.1:" + lpPort, "127.0.0.1:" + arPort, "--oplogSize", "1", "--nohttpinterface" ); + + // normal startup + + assert.soon( function() { + am = ismaster( a ); + lm = ismaster( l ); + rm = ismaster( r ); + + assert( am == 1, "am value invalid" ); + assert( lm == -1 || lm == 0, "lm value invalid" ); + assert( rm == -1 || rm == 0 || rm == 1, "rm value invalid" ); + + return ( lm == 0 && rm == 1 ); + } ); + + // disconnect l (slave) + + stopMongoProgram( alPort ); + stopMongoProgram( lpPort ); + stopMongoProgram( rpPort ); + + assert.soon( function() { + lm = ismaster( l ); + rm = ismaster( r ); + + assert( lm == 0 || lm == -3, "lm value invalid" ); + assert( rm == 1, "rm value invalid" ); + + return ( lm == -3 ); + } ); + + // disconnect r ( master ) + + stopMongoProgram( arPort ); + + assert.soon( function() { + rm = ismaster( r ); + assert( rm == 1 || rm == -3, "rm value invalid" ); + return ( rm == -3 ); + } ); + + // reconnect + + connect(); + assert.soon( function() { + lm = ismaster( l ); + rm = ismaster( r ); + + assert( lm == -3 || lm == 0, "lm value invalid" ); + assert( rm == -3 || rm == 1, "rm value invalid" ); + + return ( lm == 0 && rm == 1 ); + } ); + +} + +doTest();