summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristina <kristina@10gen.com>2012-02-09 16:19:15 -0500
committerAndy Schwerin <schwerin@10gen.com>2012-04-20 10:53:33 -0400
commit49144209b1c537692945594d909713a2fc669db0 (patch)
tree039989ec3f6608b51466a360c1fd0e5c86cd13ec
parentbea6d4be2005d0d9bd34a10353e06c472790a949 (diff)
downloadmongo-49144209b1c537692945594d909713a2fc669db0.tar.gz
Check optimes before stepping down due to priority SERVER-4810
-rw-r--r--db/repl/manager.cpp5
-rw-r--r--jstests/replsets/replsetprio1.js75
2 files changed, 45 insertions, 35 deletions
diff --git a/db/repl/manager.cpp b/db/repl/manager.cpp
index c91adc322a1..1a090710084 100644
--- a/db/repl/manager.cpp
+++ b/db/repl/manager.cpp
@@ -98,7 +98,10 @@ namespace mongo {
const Member *primary = rs->box.getPrimary();
if (primary && highestPriority &&
- highestPriority->config().priority > primary->config().priority) {
+ highestPriority->config().priority > primary->config().priority &&
+ // if we're stepping down to allow another member to become primary, we
+ // better have another member (otherOp), and it should be up-to-date
+ otherOp != 0 && highestPriority->hbinfo().opTime.getSecs() >= otherOp - 10) {
log() << "stepping down " << primary->fullName() << endl;
if (primary->h().isSelf()) {
diff --git a/jstests/replsets/replsetprio1.js b/jstests/replsets/replsetprio1.js
index a0024769f59..aeeb7494a0b 100644
--- a/jstests/replsets/replsetprio1.js
+++ b/jstests/replsets/replsetprio1.js
@@ -1,4 +1,3 @@
-// FAILING TEST
// should check that election happens in priority order
doTest = function( signal ) {
@@ -7,47 +6,55 @@ doTest = function( signal ) {
var nodes = replTest.nodeList();
replTest.startSet();
- replTest.node[0].initiate({"_id" : "unicomplex",
+ replTest.initiate({"_id" : "testSet",
"members" : [
- {"_id" : 0, "host" : nodes[0], "priority" : 1},
- {"_id" : 1, "host" : nodes[1], "priority" : 2},
+ {"_id" : 0, "host" : nodes[0], "priority" : 1},
+ {"_id" : 1, "host" : nodes[1], "priority" : 2},
{"_id" : 2, "host" : nodes[2], "priority" : 3}]});
- sleep(10000);
-
- // 2 should be master
- var m3 = replTest.nodes[2].runCommand({ismaster:1})
-
- // FAILS: node[0] is elected master, regardless of priority
- assert(m3.ismaster, 'highest priority is master');
+ // 2 should be master (give this a while to happen, as 0 will be elected, then demoted)
+ assert.soon(function() {
+ var m2 = replTest.nodes[2].getDB("admin").runCommand({ismaster:1});
+ return m2.ismaster;
+ }, 'highest priority is master', 120000);
// kill 2, 1 should take over
- var m3Id = replTest.getNodeId(nodes[2]);
- replTest.stop(m3Id);
-
- sleep(10000);
-
- var m2 = replTest.nodes[1].runCommand({ismaster:1})
- assert(m2.ismaster, 'node 2 is master');
+ replTest.stop(2);
- // bring 2 back up, nothing should happen
- replTest.start(m3Id);
+ // do some writes on 1
+ master = replTest.getMaster();
+ for (i=0; i<1000; i++) {
+ master.getDB("foo").bar.insert({i:i});
+ }
sleep(10000);
- m2 = replTest.nodes[1].runCommand({ismaster:1})
- assert(m2.ismaster, 'node 2 is still master');
-
- // kill 1, 2 should become master
- var m2Id = replTest.getNodeId(nodes[1]);
- replTest.stop(m2Id);
-
- sleep(10000);
-
- m3 = replTest.nodes[2].runCommand({ismaster:1})
- assert(m3.ismaster, 'node 3 is master');
-
- replTest.stopSet( signal );
+ for (i=0; i<1000; i++) {
+ master.getDB("bar").baz.insert({i:i});
+ }
+
+ var m1 = replTest.nodes[1].getDB("admin").runCommand({ismaster:1})
+ assert(m1.ismaster, 'node 2 is master');
+
+ // bring 2 back up, 2 should wait until caught up and then become master
+ replTest.restart(2);
+ assert.soon(function() {
+ try {
+ m2 = replTest.nodes[2].getDB("admin").runCommand({ismaster:1})
+ return m2.ismaster;
+ }
+ catch (e) {
+ print(e);
+ }
+ return false;
+ }, 'node 2 is master again');
+
+ // make sure nothing was rolled back
+ master = replTest.getMaster();
+ for (i=0; i<1000; i++) {
+ assert(master.getDB("foo").bar.findOne({i:i}) != null, 'checking '+i);
+ assert(master.getDB("bar").baz.findOne({i:i}) != null, 'checking '+i);
+ }
}
-//doTest( 15 );
+doTest( 15 );