summaryrefslogtreecommitdiff
path: root/jstests/replsets/initial_sync_write_conflict.js
blob: 20fc4fea93ff5406ffba006edbefe81b044727fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 *  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.
 */

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();

var 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.waitForState(secondary, ReplSetTest.State.SECONDARY);

// 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();