summaryrefslogtreecommitdiff
path: root/jstests/replsets/rollback_transactions_count.js
blob: f965211284afdcac3a49a198f61548c57576e87b (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
59
60
61
62
63
64
65
66
/**
 * Tests that rollback fixes the transactions table and gets the correct fastcounts for
 * transactions.
 *
 * @tags: [uses_transactions]
 */
(function() {
    "use strict";

    load("jstests/replsets/libs/rollback_test.js");

    const testName = "rollback_transactions_count";
    const dbName = testName;
    const collName = "txnCollName";

    const rollbackTest = new RollbackTest(testName);
    const primary = rollbackTest.getPrimary();

    const session1 = primary.startSession();
    const sessionDb1 = session1.getDatabase(dbName);
    const sessionColl1 = sessionDb1[collName];
    assert.commandWorked(sessionColl1.insert({a: 1}));
    session1.startTransaction();
    assert.commandWorked(sessionColl1.insert({b: 1}));
    assert.commandWorked(session1.commitTransaction_forTesting());

    rollbackTest.awaitLastOpCommitted();
    assert.commandWorked(
        primary.adminCommand({configureFailPoint: 'disableSnapshotting', mode: 'alwaysOn'}));

    const session2 = primary.startSession();
    const sessionDb2 = session2.getDatabase(dbName);
    const sessionColl2 = sessionDb2[collName];
    session2.startTransaction();
    assert.commandWorked(sessionColl2.insert({c: 1}));
    assert.commandWorked(session2.commitTransaction_forTesting());

    rollbackTest.transitionToRollbackOperations();

    session2.startTransaction();
    assert.commandWorked(sessionColl2.insert({d: 1}));
    assert.commandWorked(session2.commitTransaction_forTesting());

    const session3 = primary.startSession();
    const sessionDb3 = session3.getDatabase(dbName);
    const sessionColl3 = sessionDb3[collName];
    session3.startTransaction();
    assert.commandWorked(sessionColl3.insert({e: 1}));
    assert.commandWorked(session3.commitTransaction_forTesting());

    assert.eq(sessionColl1.find().itcount(), 5);

    rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
    rollbackTest.transitionToSyncSourceOperationsDuringRollback();
    try {
        rollbackTest.transitionToSteadyStateOperations();
    } finally {
        assert.commandWorked(
            primary.adminCommand({configureFailPoint: 'disableSnapshotting', mode: 'off'}));
    }

    assert.eq(sessionColl1.find().itcount(), 3);
    assert.eq(primary.getDB('config')['transactions'].find().itcount(), 2);

    rollbackTest.stop();
})();