2017-08-16 15:38:38 -04:00
|
|
|
/**
|
|
|
|
|
* Initial sync runs in several phases - the first 3 are as follows:
|
|
|
|
|
* 1) fetches the last oplog entry (op_start1) on the source;
|
|
|
|
|
* 2) copies all non-local databases from the source; and
|
|
|
|
|
* 3) fetches and applies operations from the source after op_start1.
|
|
|
|
|
*
|
|
|
|
|
* This test updates and deletes a document on the source between phases 1 and 2. The
|
|
|
|
|
* secondary will initially fail to apply the update operation in phase 3 and subsequently have
|
|
|
|
|
* to attempt to check the source for a new copy of the document. Before the secondary checks the
|
|
|
|
|
* source, we insert a new copy of the document into this collection on the source and mark the
|
|
|
|
|
* collection on which the document to be fetched resides as drop pending, thus effectively
|
|
|
|
|
* renaming the collection but preserving the UUID. This ensures the secondary fetches the
|
|
|
|
|
* document by UUID rather than namespace.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
load("jstests/libs/check_log.js");
|
2019-06-19 14:00:25 -04:00
|
|
|
load("jstests/replsets/libs/initial_sync_update_missing_doc.js");
|
2018-12-23 12:16:32 -05:00
|
|
|
load("jstests/replsets/libs/two_phase_drops.js"); // For TwoPhaseDropCollectionTest.
|
2017-08-16 15:38:38 -04:00
|
|
|
|
|
|
|
|
var name = 'initial_sync_update_missing_doc3';
|
|
|
|
|
var replSet = new ReplSetTest({
|
|
|
|
|
name: name,
|
2019-06-19 14:00:25 -04:00
|
|
|
nodes: 1,
|
2017-08-16 15:38:38 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
replSet.startSet();
|
|
|
|
|
replSet.initiate();
|
2019-06-19 14:00:25 -04:00
|
|
|
const primary = replSet.getPrimary();
|
|
|
|
|
const dbName = 'test';
|
2017-08-16 15:38:38 -04:00
|
|
|
|
2018-12-23 12:16:32 -05:00
|
|
|
// Check for 'system.drop' two phase drop support.
|
|
|
|
|
if (!TwoPhaseDropCollectionTest.supportsDropPendingNamespaces(replSet)) {
|
|
|
|
|
jsTestLog('Drop pending namespaces not supported by storage engine. Skipping test.');
|
|
|
|
|
replSet.stopSet();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 14:00:25 -04:00
|
|
|
var coll = primary.getDB(dbName).getCollection(name);
|
|
|
|
|
assert.commandWorked(coll.insert({_id: 0, x: 1}));
|
2017-08-16 15:38:38 -04:00
|
|
|
|
2019-06-19 14:00:25 -04:00
|
|
|
// Add a secondary node with priority: 0 so that we prevent elections while it is syncing
|
|
|
|
|
// from the primary.
|
|
|
|
|
// We cannot give the secondary votes: 0 because then it will not be able to acknowledge
|
|
|
|
|
// majority writes. That means the sync source can immediately drop it's collection
|
|
|
|
|
// because it alone determines the majority commit point.
|
|
|
|
|
const secondaryConfig = {rsConfig: {priority: 0}};
|
|
|
|
|
const secondary = reInitiateSetWithSecondary(replSet, secondaryConfig);
|
2017-08-16 15:38:38 -04:00
|
|
|
|
2019-06-19 14:00:25 -04:00
|
|
|
// Update and remove document on primary.
|
|
|
|
|
assert.commandWorked(coll.update({_id: 0}, {x: 2}, {upsert: false}));
|
|
|
|
|
assert.commandWorked(coll.remove({_id: 0}, {justOne: true}));
|
2017-08-16 15:38:38 -04:00
|
|
|
|
2019-06-19 14:00:25 -04:00
|
|
|
turnOffHangBeforeCopyingDatabasesFailPoint(secondary);
|
2017-08-16 15:38:38 -04:00
|
|
|
|
|
|
|
|
// Re-insert deleted document.
|
2019-06-19 14:00:25 -04:00
|
|
|
assert.commandWorked(coll.insert({_id: 0, x: 3}));
|
2017-08-16 15:38:38 -04:00
|
|
|
// Mark the collection as drop pending so it gets renamed, but retains the UUID.
|
|
|
|
|
assert.commandWorked(primary.getDB('test').runCommand({"drop": name}));
|
|
|
|
|
|
2019-05-30 11:22:10 -04:00
|
|
|
var res = assert.commandWorked(secondary.adminCommand({replSetGetStatus: 1}));
|
2017-08-16 15:38:38 -04:00
|
|
|
assert.eq(res.initialSyncStatus.fetchedMissingDocs, 0);
|
|
|
|
|
var firstOplogEnd = res.initialSyncStatus.initialSyncOplogEnd;
|
|
|
|
|
|
|
|
|
|
secondary.getDB('test').setLogLevel(1, 'replication');
|
2019-06-19 14:00:25 -04:00
|
|
|
turnOffHangBeforeGettingMissingDocFailPoint(primary, secondary, name, 1);
|
2017-08-16 15:38:38 -04:00
|
|
|
secondary.getDB('test').setLogLevel(0, 'replication');
|
|
|
|
|
|
|
|
|
|
replSet.awaitReplication();
|
|
|
|
|
replSet.awaitSecondaryNodes();
|
|
|
|
|
|
|
|
|
|
replSet.stopSet();
|
|
|
|
|
})();
|