summaryrefslogtreecommitdiff
path: root/jstests/sharding/transactions_prohibited_in_sharded_cluster.js
blob: 6ad97243043fc79e785e7f16b11c2bd0d7fc0c6e (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
/**
 * Verify that multi-statement transactions are disallowed on mongos.
 */
(function() {
    'use strict';

    const st = new ShardingTest({shards: 1, mongos: 1, config: 1, rsOptions: {nodes: 1}});
    const mongos = st.s0;
    const dbName = "test";
    const collName = "coll";

    // Start a session on the mongos.
    const session = mongos.getDB(dbName).getMongo().startSession();
    const sessionDb = session.getDatabase(dbName);
    let txnNumber = 0;

    // Unable to start a transaction via mongos with a read.
    assert.commandFailedWithCode(sessionDb.runCommand({
        find: collName,
        readConcern: {level: "snapshot"},
        txnNumber: NumberLong(txnNumber++),
        startTransaction: true,
        autocommit: false
    }),
                                 50841);

    // Unable to start a transaction via mongos with a write.
    assert.commandFailedWithCode(sessionDb.runCommand({
        insert: collName,
        documents: [{_id: 1}],
        readConcern: {level: "snapshot"},
        txnNumber: NumberLong(txnNumber++),
        startTransaction: true,
        autocommit: false
    }),
                                 50841);

    // 'startTransaction' and 'autocommit' arguments are always rejected by mongos.
    assert.commandFailedWithCode(sessionDb.runCommand({
        find: collName,
        readConcern: {level: "snapshot"},
        txnNumber: NumberLong(txnNumber++),
        autocommit: false
    }),
                                 50841);

    assert.commandFailedWithCode(sessionDb.runCommand({
        find: collName,
        readConcern: {level: "snapshot"},
        txnNumber: NumberLong(txnNumber++),
        startTransaction: true
    }),
                                 50841);

    st.stop();

})();