2016-09-20 15:13:07 -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 fetches operations from sync source; and
|
|
|
|
|
* 3) applies operations from the source after op_start1.
|
|
|
|
|
*
|
2016-11-07 14:57:51 -05:00
|
|
|
* This test renames a collection on the source between phases 1 and 2, but renameCollection is not
|
|
|
|
|
* supported in initial sync. The secondary will initially fail to apply the command in phase 3
|
2016-09-20 15:13:07 -04:00
|
|
|
* and subsequently have to retry the initial sync.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-25 18:52:44 +00:00
|
|
|
import {configureFailPoint} from "jstests/libs/fail_point_util.js";
|
2024-08-20 17:54:15 -04:00
|
|
|
import {ReplSetTest} from "jstests/libs/replsettest.js";
|
2016-12-13 17:53:24 -05:00
|
|
|
|
2025-08-28 15:11:44 -04:00
|
|
|
let name = "initial_sync_applier_error";
|
|
|
|
|
let replSet = new ReplSetTest({
|
2016-09-20 15:13:07 -04:00
|
|
|
name: name,
|
|
|
|
|
nodes: [{}, {rsConfig: {arbiterOnly: true}}],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
replSet.startSet();
|
|
|
|
|
replSet.initiate();
|
2025-08-28 15:11:44 -04:00
|
|
|
let primary = replSet.getPrimary();
|
2016-09-20 15:13:07 -04:00
|
|
|
|
2025-08-28 15:11:44 -04:00
|
|
|
let coll = primary.getDB("test").getCollection(name);
|
2019-08-14 13:52:59 +00:00
|
|
|
assert.commandWorked(coll.insert({_id: 0, content: "hi"}));
|
2016-09-20 15:13:07 -04:00
|
|
|
|
|
|
|
|
// Add a secondary node but make it hang after retrieving the last op on the source
|
|
|
|
|
// but before copying databases.
|
2025-08-28 15:11:44 -04:00
|
|
|
let secondary = replSet.add({setParameter: "numInitialSyncAttempts=2", rsConfig: {votes: 0, priority: 0}});
|
2020-08-27 14:07:45 -04:00
|
|
|
secondary.setSecondaryOk();
|
2016-09-20 15:13:07 -04:00
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
let failPoint = configureFailPoint(secondary, "initialSyncHangBeforeCopyingDatabases");
|
2016-09-20 15:13:07 -04:00
|
|
|
replSet.reInitiate();
|
|
|
|
|
|
|
|
|
|
// Wait for fail point message to be logged.
|
2019-10-25 18:52:44 +00:00
|
|
|
failPoint.wait();
|
2016-09-20 15:13:07 -04:00
|
|
|
|
2025-08-28 15:11:44 -04:00
|
|
|
let newCollName = name + "_2";
|
2016-11-07 14:57:51 -05:00
|
|
|
assert.commandWorked(coll.renameCollection(newCollName, true));
|
2019-10-25 18:52:44 +00:00
|
|
|
failPoint.off();
|
2016-09-20 15:13:07 -04:00
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
checkLog.contains(secondary, "Initial sync done");
|
2016-09-20 15:13:07 -04:00
|
|
|
|
|
|
|
|
replSet.awaitReplication();
|
|
|
|
|
replSet.awaitSecondaryNodes();
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
assert.eq(0, secondary.getDB("test").getCollection(name).count());
|
|
|
|
|
assert.eq(1, secondary.getDB("test").getCollection(newCollName).count());
|
|
|
|
|
assert.eq("hi", secondary.getDB("test").getCollection(newCollName).findOne({_id: 0}).content);
|
|
|
|
|
replSet.stopSet();
|