2013-04-22 14:48:02 -04:00
|
|
|
// test that a rollback directory is created during a replica set rollback
|
|
|
|
|
// this also tests that updates are recorded in the rollback file
|
|
|
|
|
// (this test does no delete rollbacks)
|
2015-11-19 14:01:59 -05:00
|
|
|
//
|
|
|
|
|
// If all data-bearing nodes in a replica set are using an ephemeral storage engine, the set will
|
|
|
|
|
// not be able to survive a scenario where all data-bearing nodes are down simultaneously. In such a
|
|
|
|
|
// scenario, none of the members will have any data, and upon restart will each look for a member to
|
|
|
|
|
// inital sync from, so no primary will be elected. This test induces such a scenario, so cannot be
|
|
|
|
|
// run on ephemeral storage engines.
|
|
|
|
|
// @tags: [requires_persistence]
|
2013-04-22 14:48:02 -04:00
|
|
|
|
|
|
|
|
var replTest = new ReplSetTest({ name: 'rollback5', nodes: 3 });
|
|
|
|
|
var nodes = replTest.nodeList();
|
|
|
|
|
|
|
|
|
|
var conns = replTest.startSet();
|
|
|
|
|
var r = replTest.initiate({ "_id": "rollback5",
|
|
|
|
|
"members": [
|
2014-04-03 05:36:58 -04:00
|
|
|
{ "_id": 0, "host": nodes[0], priority: 3 },
|
2013-04-22 14:48:02 -04:00
|
|
|
{ "_id": 1, "host": nodes[1] },
|
|
|
|
|
{ "_id": 2, "host": nodes[2], arbiterOnly: true}]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Make sure we have a master
|
2015-12-10 10:21:51 -05:00
|
|
|
replTest.waitForState(replTest.nodes[0], ReplSetTest.State.PRIMARY, 60 * 1000);
|
2015-11-25 11:20:43 -05:00
|
|
|
var master = replTest.getPrimary();
|
2013-04-22 14:48:02 -04:00
|
|
|
var a_conn = conns[0];
|
|
|
|
|
var b_conn = conns[1];
|
|
|
|
|
a_conn.setSlaveOk();
|
|
|
|
|
b_conn.setSlaveOk();
|
|
|
|
|
var A = a_conn.getDB("test");
|
|
|
|
|
var B = b_conn.getDB("test");
|
|
|
|
|
var AID = replTest.getNodeId(a_conn);
|
|
|
|
|
var BID = replTest.getNodeId(b_conn);
|
2013-09-25 21:59:42 -04:00
|
|
|
var Apath = MongoRunner.dataDir + "/rollback5-0/";
|
|
|
|
|
var Bpath = MongoRunner.dataDir + "/rollback5-1/";
|
2013-04-22 14:48:02 -04:00
|
|
|
assert(master == conns[0], "conns[0] assumed to be master");
|
|
|
|
|
assert(a_conn.host == master.host);
|
|
|
|
|
|
|
|
|
|
// Make sure we have an arbiter
|
|
|
|
|
assert.soon(function () {
|
|
|
|
|
res = conns[2].getDB("admin").runCommand({ replSetGetStatus: 1 });
|
|
|
|
|
return res.myState == 7;
|
|
|
|
|
}, "Arbiter failed to initialize.");
|
|
|
|
|
|
2014-03-03 11:27:18 -05:00
|
|
|
var options = { writeConcern: { w: 2, wtimeout: 60000 }, upsert: true };
|
|
|
|
|
assert.writeOK(A.foo.update({ key: 'value1' }, { $set: { req: 'req' }}, options));
|
2013-04-22 14:48:02 -04:00
|
|
|
replTest.stop(AID);
|
|
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
master = replTest.getPrimary();
|
2013-04-22 14:48:02 -04:00
|
|
|
assert(b_conn.host == master.host);
|
2014-03-03 11:27:18 -05:00
|
|
|
options = { writeConcern: { w: 1, wtimeout: 60000 }, upsert: true };
|
|
|
|
|
assert.writeOK(B.foo.update({key:'value1'}, {$set: {res: 'res'}}, options));
|
2013-04-22 14:48:02 -04:00
|
|
|
replTest.stop(BID);
|
|
|
|
|
replTest.restart(AID);
|
2015-11-25 11:20:43 -05:00
|
|
|
master = replTest.getPrimary();
|
2013-04-22 14:48:02 -04:00
|
|
|
assert(a_conn.host == master.host);
|
2014-03-03 11:27:18 -05:00
|
|
|
options = { writeConcern: { w: 1, wtimeout: 60000 }, upsert: true };
|
|
|
|
|
assert.writeOK(A.foo.update({ key: 'value2' }, { $set: { req: 'req' }}, options));
|
2013-04-22 14:48:02 -04:00
|
|
|
replTest.restart(BID); // should rollback
|
|
|
|
|
reconnect(B);
|
|
|
|
|
|
|
|
|
|
print("BEFORE------------------");
|
|
|
|
|
printjson(A.foo.find().toArray());
|
|
|
|
|
|
|
|
|
|
replTest.awaitReplication();
|
|
|
|
|
replTest.awaitSecondaryNodes();
|
|
|
|
|
|
|
|
|
|
print("AFTER------------------");
|
|
|
|
|
printjson(A.foo.find().toArray());
|
2013-04-30 11:58:46 -04:00
|
|
|
|
2013-04-22 14:48:02 -04:00
|
|
|
assert.eq(2, A.foo.count());
|
|
|
|
|
assert.eq('req', A.foo.findOne({key:'value1'}).req);
|
|
|
|
|
assert.eq(null, A.foo.findOne({key:'value1'}).res);
|
2015-06-07 21:08:37 -04:00
|
|
|
reconnect(B);
|
2013-04-22 14:48:02 -04:00
|
|
|
assert.eq(2, B.foo.count());
|
|
|
|
|
assert.eq('req', B.foo.findOne({key:'value1'}).req);
|
|
|
|
|
assert.eq(null, B.foo.findOne({key:'value1'}).res);
|
|
|
|
|
|
|
|
|
|
// check here for rollback files
|
|
|
|
|
var rollbackDir = Bpath + "rollback/";
|
|
|
|
|
assert(pathExists(rollbackDir), "rollback directory was not created!");
|
|
|
|
|
|
|
|
|
|
print("rollback5.js SUCCESS");
|
|
|
|
|
replTest.stopSet(15);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function wait(f) {
|
|
|
|
|
var n = 0;
|
|
|
|
|
while (!f()) {
|
|
|
|
|
if (n % 4 == 0)
|
|
|
|
|
print("rollback5.js waiting");
|
|
|
|
|
if (++n == 4) {
|
|
|
|
|
print("" + f);
|
|
|
|
|
}
|
|
|
|
|
assert(n < 200, 'tried 200 times, giving up');
|
|
|
|
|
sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reconnect(a) {
|
|
|
|
|
wait(function() {
|
|
|
|
|
try {
|
|
|
|
|
a.bar.stats();
|
|
|
|
|
return true;
|
|
|
|
|
} catch(e) {
|
|
|
|
|
print(e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|