summaryrefslogtreecommitdiff
path: root/jstests/replsets/prepare_prepared_transaction_wc_timeout.js
blob: 536adff487a351c1cbb9ab7a0166552704ac000d (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
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 * Tests that when preparing a prepared transaction, we wait for writeConcern if the client optime
 * is behind the prepareTimestamp.
 *
 * @tags: [uses_transactions, uses_prepare_transaction]
 */
(function() {
"use strict";
load("jstests/libs/retryable_writes_util.js");
load("jstests/libs/write_concern_util.js");

if (!RetryableWritesUtil.storageEngineSupportsRetryableWrites(jsTest.options().storageEngine)) {
    jsTestLog("Retryable writes are not supported, skipping test");
    return;
}

const kNodes = 2;

const replTest = new ReplSetTest({nodes: kNodes});
replTest.startSet({verbose: 1});
replTest.initiate();

const priConn = replTest.getPrimary();
const secConn = replTest.getSecondary();

const lsid = UUID();

// Insert something into the user collection.
runWriteConcernRetryabilityTest(priConn,
                                secConn,
                                {
                                    insert: 'user',
                                    documents: [{_id: 10}, {_id: 30}],
                                    ordered: false,
                                    lsid: {id: lsid},
                                    txnNumber: NumberLong(34),
                                    writeConcern: {w: 'majority', wtimeout: 200},
                                },
                                kNodes);

// Since we must wait for writeConcern : majority in order for the prepareTimestamp to be
// committed, this test case will timeout when we stop replication on the secondary.
runWriteConcernRetryabilityTest(priConn,
                                secConn,
                                {
                                    prepareTransaction: 1,
                                    lsid: {id: lsid},
                                    txnNumber: NumberLong(39),
                                    autocommit: false,
                                    writeConcern: {w: 'majority', wtimeout: 200},
                                },
                                kNodes,
                                'admin',
                                function(conn) {
                                    assert.commandWorked(conn.getDB('test').runCommand({
                                        insert: 'user',
                                        documents: [{_id: 50}, {_id: 70}],
                                        ordered: false,
                                        lsid: {id: lsid},
                                        txnNumber: NumberLong(39),
                                        readConcern: {level: 'snapshot'},
                                        autocommit: false,
                                        startTransaction: true
                                    }));
                                });

// Explicitly abort transaction 39 because we cannot shut down the replica set when there
// is a prepared transaction in progress.
// TODO: SERVER-35817 Allow shutdowns when a prepared transaction is in progress.
assert.commandWorked(priConn.getDB('admin').runCommand({
    abortTransaction: 1,
    lsid: {id: lsid},
    txnNumber: NumberLong(39),
    autocommit: false,
    writeConcern: {w: 'majority'},
}));

replTest.stopSet();
})();