summaryrefslogtreecommitdiff
path: root/jstests/core/txns/commands_banning_txnnumber_outside_transactions.js
blob: 08a8551fb099a283b6168ba06025717304d22f00 (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
// Test that commands other than retryable writes may not use txnNumber outside transactions.
// @tags: [
//   requires_document_locking,
// ]
(function() {
    "use strict";

    const isMongos = assert.commandWorked(db.runCommand("ismaster")).msg === "isdbgrid";

    const session = db.getMongo().startSession();
    const sessionDb = session.getDatabase("admin");

    const nonRetryableWriteCommands = [
        // Commands that are allowed in transactions.
        {aggregate: 1},
        {commitTransaction: 1},
        {distinct: "c"},
        {find: "c"},
        {getMore: NumberLong(1), collection: "c"},
        {killCursors: 1},
        // A selection of commands that are not allowed in transactions.
        {count: 1},
        {explain: {find: "c"}},
        {filemd5: 1},
        {isMaster: 1},
        {buildInfo: 1},
        {ping: 1},
        {listCommands: 1},
        {create: "c"},
        {drop: 1},
        {createIndexes: 1},
        {mapReduce: "c"}
    ];

    const nonRetryableWriteCommandsMongodOnly = [
        // Commands that are allowed in transactions.
        {coordinateCommitTransaction: 1, participants: []},
        {geoSearch: 1},
        {prepareTransaction: 1},
        // A selection of commands that are not allowed in transactions.
        {applyOps: 1}
    ];

    nonRetryableWriteCommands.forEach(function(command) {
        jsTest.log("Testing command: " + tojson(command));
        assert.commandFailedWithCode(
            sessionDb.runCommand(Object.assign({}, command, {txnNumber: NumberLong(0)})),
            [50768, 50889]);
    });

    if (!isMongos) {
        nonRetryableWriteCommandsMongodOnly.forEach(function(command) {
            jsTest.log("Testing command: " + tojson(command));
            assert.commandFailedWithCode(
                sessionDb.runCommand(Object.assign({}, command, {txnNumber: NumberLong(0)})),
                [50768, 50889]);
        });
    }

    session.endSession();
}());