mongo/jstests/replsets/initial_sync_write_conflict.js
Steve McClure 1ffbc6c2e9 SERVER-109432: Autofix JS var usage to favor let (#40637)
GitOrigin-RevId: 9674b7db36a0f3f650d39c1e3fb2ad6ff2141cfb
2025-08-28 19:21:01 +00:00

37 lines
1.2 KiB
JavaScript

/*
* Tests that initial sync is successfully able to clone the collection and build
* index without any orphan index entries even if a WriteConflictException is
* thrown while inserting documents into collections.
*/
import {ReplSetTest} from "jstests/libs/replsettest.js";
const testName = "write_conflict_exception";
// Start a 2 node replica set.
const replSet = new ReplSetTest({name: testName, nodes: [{}, {rsConfig: {priority: 0}}]});
jsTest.log("Starting test");
replSet.startSet();
replSet.initiate();
let secondary = replSet.getSecondary();
// Start and restart secondary with fail point that throws exception enabled.
jsTest.log("Stopping secondary");
replSet.stop(secondary);
jsTest.log("Re-starting secondary ");
secondary = replSet.start(secondary, {
startClean: true,
setParameter: {"failpoint.failAfterBulkLoadDocInsert": "{'mode': {'times': 1}}"},
});
// Wait for everything to be synced.
jsTest.log("Waiting for initial sync to succeed");
replSet.awaitSecondaryNodes();
// If the index table contains any entries pointing to invalid document(RecordID), then
// validateCollections called during replica stopSet will capture the index corruption and throw
// error.
replSet.stopSet();