summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dwight@10gen.com>2010-08-03 10:56:05 -0400
committerDwight <dwight@10gen.com>2010-08-03 10:56:05 -0400
commit7620a8d7b3eced9900c6161b9bff09255051b42b (patch)
treebd453bd6731cecafab555b55daff779c775ece9b
parent989d740a75f72e85d75b9b54b2627dacade590c9 (diff)
downloadmongo-7620a8d7b3eced9900c6161b9bff09255051b42b.tar.gz
rollback.js
-rw-r--r--jstests/replsets/rollback.js73
1 files changed, 59 insertions, 14 deletions
diff --git a/jstests/replsets/rollback.js b/jstests/replsets/rollback.js
index 61215cb6fe3..baf9956ec3e 100644
--- a/jstests/replsets/rollback.js
+++ b/jstests/replsets/rollback.js
@@ -1,4 +1,7 @@
-print("TODO FINISH THIS TEST NOT DONE");
+// try running as :
+//
+// mongo --nodb rollback.js | tee out | grep -v ^m31
+//
var debugging = 0;
@@ -20,11 +23,14 @@ w = 0;
function wait(f) {
w++;
+ var n = 0;
while (!f()) {
print("waiting " + w);
+ if( ++n == 2 )
+ print("" + f);
sleep(2000);
}
- print("done waiting " + w);
+// print("done waiting " + w);
}
doTest = function (signal) {
@@ -32,7 +38,7 @@ doTest = function (signal) {
var replTest = new ReplSetTest({ name: 'unicomplex', nodes: 3 });
var nodes = replTest.nodeList();
- print(tojson(nodes));
+ //print(tojson(nodes));
var conns = replTest.startSet();
var r = replTest.initiate({ "_id": "unicomplex",
@@ -47,40 +53,79 @@ doTest = function (signal) {
a = conns[0];
A = a.getDB("admin");
b = conns[1];
+ a.setSlaveOk();
b.setSlaveOk();
B = b.getDB("admin");
assert(master == conns[0], "conns[0] assumed to be master");
+ assert(a == master);
//deb(master);
// Make sure we have an arbiter
assert.soon(function () {
res = conns[2].getDB("admin").runCommand({ replSetGetStatus: 1 });
- printjson(res);
+ //printjson(res);
return res.myState == 7;
}, "Arbiter failed to initialize.");
// Wait for initial replication
- var t = master.getDB("foo").bar;
+ var t = a.getDB("foo").bar;
var u = b.getDB("foo").bar;
- t.insert({ a: "foo" });
- t.insert({ a: "foo", x: 1 });
- t.insert({ y: 9, a: "foo" });
+ t.insert({ q: 1, a: "foo" });
+ t.insert({ q: 2, a: "foo", x: 1 });
+ t.insert({ q: 3, bb: 9, a: "foo" });
assert(t.count() == 3, "t.count");
- //wait( function() {
-
+ // wait for secondary to get this data
wait(function () { return u.count() == 3; });
A.runCommand({ replSetTest: 1, blind: true });
+ wait(function () { return B.isMaster().ismaster; });
+ //print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+ //printjson(B.isMaster());
+ u.insert({ q: 4 });
+ u.insert({ q: 5 });
+ u.insert({ q: 6 });
+ assert(u.count() == 6, "u.count");
+
+ // a should not have the new data as it was in blind state.
+ B.runCommand({ replSetTest: 1, blind: true });
+ A.runCommand({ replSetTest: 1, blind: false });
+ wait(function () { return !B.isMaster().ismaster; });
+ wait(function () { return A.isMaster().ismaster; });
+
+ printjson(A.isMaster());
+ assert(t.count() == 3, "t is 3");
+ t.insert({ q: 7 });
+ t.insert({ q: 8 });
+ {
+ assert(t.count() == 5);
+ var x = t.find().toArray();
+ assert(x[0].q == 1, '1');
+ assert(x[1].q == 2, '2');
+ assert(x[2].q == 3, '3');
+ assert(x[3].q == 7, '7');
+ assert(x[4].q == 8, '8');
+ }
- wait(function () { return B.isMaster(); });
+ // A is 1 2 3 7 8
+ // B is 1 2 3 4 5 6
- print(u.count());
- pause("SUCCESS");
+ // bring B back online
+ B.runCommand({ replSetTest: 1, blind: false });
+
+ wait(function () { return B.isMaster().ismaster || B.isMaster().secondary; });
+ // everyone is up here...
+ assert(A.isMaster().ismaster || A.isMaster().secondary, "A up");
+ assert(B.isMaster().ismaster || B.isMaster().secondary, "B up");
+
+ printjson(t.find().toArray());
+ printjson(u.find().toArray());
+
+ pause("SUCCESS");
replTest.stopSet(signal);
}
- doTest( 15 );
+doTest( 15 );