summaryrefslogtreecommitdiff
path: root/jstests/replsets/rollback_via_refetch_update_rollback_id_before_oplog_truncation.js
blob: d560cc7d419a32b66f03eea696093cd05d5e7779 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * This test demonstrates that rollback via refetch always increments the rollback id as soon as it
 * resolves the common point and before proceeding with other operations.
 *
 * This is a regression test that makes sure we avoid the scenario where we truncate our oplog (at
 * which point the rollback is effectively finished), then shut down uncleanly before we get a
 * chance to update the rollbackId.
 *
 * @tags: [requires_journaling]
 */

(function() {
    "use strict";
    load("jstests/replsets/libs/rollback_test.js");
    load("jstests/replsets/rslib.js");

    const name = jsTestName();
    TestData.allowUncleanShutdowns = true;

    jsTest.log("Set up a RollbackTest with enableMajorityReadConcern=false");
    const rst = new ReplSetTest({
        name,
        nodes: [{}, {}, {rsConfig: {arbiterOnly: true}}],
        useBridge: true,
        nodeOptions: {enableMajorityReadConcern: "false"},
        settings: {chainingAllowed: false}
    });

    rst.startSet();
    rst.initiate();

    const rollbackTest = new RollbackTest(name, rst);
    const rollbackNode = rollbackTest.transitionToRollbackOperations();

    const baseRBID = assert.commandWorked(rollbackNode.adminCommand("replSetGetRBID")).rbid;

    rollbackTest.transitionToSyncSourceOperationsBeforeRollback();

    jsTestLog("Make rollback-via-refetch exit early after truncating the oplog");
    assert.commandWorked(rollbackNode.adminCommand(
        {configureFailPoint: "rollbackExitEarlyAfterCollectionDrop", mode: "alwaysOn"}));

    rollbackTest.transitionToSyncSourceOperationsDuringRollback();

    jsTestLog("Wait until we hit the failpoint");
    checkLog.contains(rollbackNode, "rollbackExitEarlyAfterCollectionDrop fail point enabled");

    // Check that the RBID has still managed to advance.
    // Looking at the RBID directly is our first line of defense.
    assert.eq(baseRBID + 1, assert.commandWorked(rollbackNode.adminCommand("replSetGetRBID")).rbid);

    assert.commandWorked(rollbackNode.adminCommand(
        {configureFailPoint: "rollbackExitEarlyAfterCollectionDrop", mode: "off"}));

    // Verify that the node can rejoin the set as normal.
    rollbackTest.transitionToSteadyStateOperations();
    rollbackTest.stop();
}());