Files
mongo/jstests/replsets/sync_source_override_secondary_read_preference.js
Kyra Ramesh Krishna 2c424186f6 SERVER-104343: Add unsupportedSyncSource check to avoid hitting read preference invariant (#37071)
GitOrigin-RevId: 4c4041829d4e510a641147f910372d7692d7eca4
2025-06-11 16:29:23 +00:00

59 lines
1.8 KiB
JavaScript

/**
* Tests that an initial syncing node being forced to sync from the primary through
* unsupportedSyncSource will be able to bypass an initialSyncSourceReadPreference
* of secondary only.
*
* @tags: [
* requires_fcv_82
* ]
*/
import {kDefaultWaitForFailPointTimeout} from "jstests/libs/fail_point_util.js";
import {ReplSetTest} from "jstests/libs/replsettest.js";
const rst = new ReplSetTest({name: jsTestName(), nodes: [{}, {rsConfig: {priority: 0}}]});
rst.startSet();
rst.initiate();
const primary = rst.getPrimary();
const primaryDb = primary.getDB("testDb");
// Add some data to be cloned.
const primaryColl = primaryDb.getCollection("testColl");
assert.commandWorked(primaryColl.insert([{a: 1}, {b: 2}, {c: 3}]));
rst.awaitReplication();
jsTestLog(
"Adding new node with unsupportedSyncSource to be the primary and readPreference to be secondary only.");
const initialSyncNode = rst.add({
rsConfig: {priority: 0, votes: 0},
setParameter: {
'unsupportedSyncSource': primary.host,
'initialSyncSourceReadPreference': 'secondary',
'failpoint.initialSyncHangBeforeCopyingDatabases': tojson({mode: 'alwaysOn'}),
}
});
rst.reInitiate();
jsTestLog("Wait until after the sync source has been chosen to confirm it is the primary.");
assert.commandWorked(initialSyncNode.adminCommand({
waitForFailPoint: "initialSyncHangBeforeCopyingDatabases",
timesEntered: 1,
maxTimeMS: kDefaultWaitForFailPointTimeout
}));
const res = assert.commandWorked(initialSyncNode.adminCommand({replSetGetStatus: 1}));
assert.eq(primary.host, res.syncSourceHost);
jsTestLog("Sync source confirmed to be primary.");
// Allow the node to continue copying databases.
assert.commandWorked(initialSyncNode.adminCommand(
{configureFailPoint: "initialSyncHangBeforeCopyingDatabases", mode: "off"}));
rst.awaitSecondaryNodes();
rst.stopSet();