2015-11-19 14:58:30 -05:00
|
|
|
// Test resync command:
|
|
|
|
|
// 1. Start master/slave deployment.
|
|
|
|
|
// 2. Insert a document to seed the oplog.
|
|
|
|
|
// 3. Assert that the resync command fails when the slave is caught up to the master.
|
|
|
|
|
// 4. Stop the slave.
|
|
|
|
|
// 5. Insert enough documents to rotate the oplog.
|
|
|
|
|
// 6. Restart the slave.
|
|
|
|
|
// 7. Assert the resync command now works on the slave.
|
|
|
|
|
// 8. Assert the slave eventually has the same data.
|
|
|
|
|
// 9. Assert the slave now rejects the resync command.
|
|
|
|
|
//
|
|
|
|
|
// This test cannot be run on ephemeral storage engines, because after restarting, at step 6, the
|
|
|
|
|
// slave will not have any data and will start an initial sync, rejecting the resync command.
|
|
|
|
|
// @tags: [requires_persistence]
|
2009-01-29 11:46:45 -05:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
soonCount = function(count) {
|
|
|
|
|
assert.soon(function() {
|
|
|
|
|
// print( "check count" );
|
|
|
|
|
// print( "count: " + s.getDB( baseName ).z.find().count() );
|
|
|
|
|
return s.getDB("foo").a.find().count() == count;
|
|
|
|
|
});
|
2016-02-04 12:30:30 -05:00
|
|
|
};
|
2009-03-17 17:20:08 -04:00
|
|
|
|
2012-08-07 17:55:34 -04:00
|
|
|
doTest = function(signal, extraOpts) {
|
2016-03-09 12:17:50 -05:00
|
|
|
print("signal: " + signal);
|
2011-07-13 11:05:44 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
var rt = new ReplTest("repl2tests");
|
2009-04-01 18:21:07 -04:00
|
|
|
|
2009-12-09 17:38:48 -08:00
|
|
|
// implicit small oplog makes slave get out of sync
|
2016-03-09 12:17:50 -05:00
|
|
|
m = rt.start(true, {oplogSize: "1"});
|
2012-08-07 17:55:34 -04:00
|
|
|
s = rt.start(false, extraOpts);
|
2011-07-13 11:05:44 -04:00
|
|
|
|
2016-02-04 12:30:30 -05:00
|
|
|
am = m.getDB("foo").a;
|
2011-07-13 11:05:44 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
am.save({_id: new ObjectId()});
|
|
|
|
|
soonCount(1);
|
|
|
|
|
assert.eq(0, s.getDB("admin").runCommand({"resync": 1}).ok);
|
|
|
|
|
rt.stop(false, signal);
|
2011-07-13 11:05:44 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
big = new Array(2000).toString();
|
|
|
|
|
for (i = 0; i < 1000; ++i)
|
|
|
|
|
am.save({_id: new ObjectId(), i: i, b: big});
|
2009-10-26 14:19:52 -04:00
|
|
|
|
2012-08-07 17:55:34 -04:00
|
|
|
s = rt.start(false, extraOpts, true);
|
2011-07-13 11:05:44 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
print("earliest op in master: " +
|
|
|
|
|
tojson(m.getDB("local").oplog.$main.find().sort({$natural: 1}).limit(1).next()));
|
|
|
|
|
print("latest op on slave: " + tojson(s.getDB("local").sources.findOne()));
|
2011-07-13 11:05:44 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.soon(function() {
|
|
|
|
|
var result = s.getDB("admin").runCommand({"resync": 1});
|
|
|
|
|
print("resync says: " + tojson(result));
|
2011-07-13 11:05:44 -04:00
|
|
|
return result.ok == 1;
|
2016-03-09 12:17:50 -05:00
|
|
|
});
|
2009-03-17 17:20:08 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
soonCount(1001);
|
|
|
|
|
assert.automsg("m.getDB( 'local' ).getCollection( 'oplog.$main' ).stats().size > 0");
|
2010-08-09 13:41:36 -07:00
|
|
|
|
2016-02-04 12:30:30 -05:00
|
|
|
as = s.getDB("foo").a;
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(1, as.find({i: 0}).count());
|
|
|
|
|
assert.eq(1, as.find({i: 999}).count());
|
2011-07-13 11:05:44 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(0, s.getDB("admin").runCommand({"resync": 1}).ok);
|
2009-03-12 13:08:16 -04:00
|
|
|
|
2009-10-26 14:19:52 -04:00
|
|
|
rt.stop();
|
2009-04-01 19:51:41 -04:00
|
|
|
|
2016-02-04 12:30:30 -05:00
|
|
|
};
|
2009-03-12 13:08:16 -04:00
|
|
|
|
2016-03-17 14:41:31 -04:00
|
|
|
doTest(15, {"vv": null}); // SIGTERM
|
2016-03-09 12:17:50 -05:00
|
|
|
doTest(9, {"vv": null, journal: null}); // SIGKILL
|