2016-05-18 14:29:12 -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.
|
|
|
|
|
*
|
2019-08-06 23:00:28 -04:00
|
|
|
* This test updates and deletes a document on the source between phases 1 and 2. The secondary will
|
|
|
|
|
* fail to apply the update operation in phase 3 but initial sync completes nevertheless. The
|
|
|
|
|
* absence of the document on the source indicates that the source is free to ignore the failed
|
|
|
|
|
* update operation.
|
2016-05-18 14:29:12 -04:00
|
|
|
*/
|
|
|
|
|
|
2024-08-20 17:54:15 -04:00
|
|
|
import {ReplSetTest} from "jstests/libs/replsettest.js";
|
2016-05-18 14:29:12 -04:00
|
|
|
import {
|
2019-08-06 23:00:28 -04:00
|
|
|
finishAndValidate,
|
2016-05-18 14:29:12 -04:00
|
|
|
reInitiateSetWithSecondary,
|
2019-06-19 14:00:25 -04:00
|
|
|
turnOffHangBeforeCopyingDatabasesFailPoint,
|
2019-07-10 13:00:33 -04:00
|
|
|
updateRemove,
|
2019-06-19 14:00:25 -04:00
|
|
|
} from "jstests/replsets/libs/initial_sync_update_missing_doc.js";
|
2016-12-13 17:53:24 -05:00
|
|
|
|
2019-08-06 23:00:28 -04:00
|
|
|
const replSet = new ReplSetTest({nodes: 1});
|
2016-05-18 14:29:12 -04:00
|
|
|
|
|
|
|
|
replSet.startSet();
|
|
|
|
|
replSet.initiate();
|
2019-06-19 14:00:25 -04:00
|
|
|
const primary = replSet.getPrimary();
|
2025-08-21 10:17:44 -07:00
|
|
|
const dbName = "test";
|
2019-08-06 23:00:28 -04:00
|
|
|
const collectionName = jsTestName();
|
|
|
|
|
const coll = primary.getDB(dbName).getCollection(collectionName);
|
2019-06-19 14:00:25 -04:00
|
|
|
assert.commandWorked(coll.insert({_id: 0, x: 1}));
|
2016-05-18 14:29:12 -04:00
|
|
|
|
2019-06-19 14:00:25 -04:00
|
|
|
// Add a secondary node with priority: 0 and votes: 0 so that we prevent elections while
|
|
|
|
|
// it is syncing from the primary.
|
|
|
|
|
const secondaryConfig = {
|
2025-08-21 10:17:44 -07:00
|
|
|
rsConfig: {votes: 0, priority: 0},
|
2019-06-19 14:00:25 -04:00
|
|
|
};
|
|
|
|
|
const secondary = reInitiateSetWithSecondary(replSet, secondaryConfig);
|
2016-05-18 14:29:12 -04:00
|
|
|
|
2019-06-19 14:00:25 -04:00
|
|
|
// Update and remove document on primary.
|
2019-07-10 13:00:33 -04:00
|
|
|
updateRemove(coll, {_id: 0});
|
2019-06-19 14:00:25 -04:00
|
|
|
turnOffHangBeforeCopyingDatabasesFailPoint(secondary);
|
2019-08-06 23:00:28 -04:00
|
|
|
finishAndValidate(replSet, collectionName, 0 /* numDocuments */);
|
2019-06-19 14:00:25 -04:00
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
replSet.stopSet();
|