summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/wt_skip_prepare_conflicts_retries_failpoint.js
blob: 8943906c07e32b1a6623210e68cdc0951d17922f (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
/**
 * Tests the WT prepare conflict behavior of running operations outside of a multi-statement
 * transaction when another operation is being performed concurrently inside of the multi-statement
 * transaction with the "WTSkipPrepareConflictRetries" failpoint is enabled.
 *
 * @tags: [
 *   uses_prepare_transaction,
 *   uses_transactions,
 * ]
 */
(function() {
"use strict";

load("jstests/core/txns/libs/prepare_helpers.js");

const rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();

const primary = rst.getPrimary();
const testDB = primary.getDB("test");
const testColl = testDB.getCollection("wt_skip_prepare_conflict_retries_failpoint");

const session = primary.startSession({causalConsistency: false});
const sessionDB = session.getDatabase(testDB.getName());
const sessionColl = sessionDB.getCollection(testColl.getName());

assert.commandWorked(testDB.runCommand({profile: 2}));

assert.commandWorked(testColl.insert({_id: 1, note: "from before transaction"}, {w: "majority"}));

assert.commandWorked(
    testDB.adminCommand({configureFailPoint: "WTSkipPrepareConflictRetries", mode: "alwaysOn"}));

assert.commandWorked(
    testDB.adminCommand({configureFailPoint: "skipWriteConflictRetries", mode: "alwaysOn"}));

// A non-transactional operation conflicting with a write operation performed inside a
// multistatement transaction can encounter a WT_PREPARE_CONFLICT in the wiredtiger
// layer under several circumstances, such as performing an insert, update, or find
// on a document that is in a prepare statement. The non-transactional operation
// would then be retried after the prepared transaction commits or aborts. However, with the
// "WTSkipPrepareConflictRetries"failpoint enabled, the non-transactional operation would
// instead return with a WT_ROLLBACK error. This would then get bubbled up as a
// WriteConflictException. Enabling the "skipWriteConflictRetries" failpoint then prevents
// the higher layers from retrying the entire operation.
session.startTransaction();

assert.commandWorked(sessionColl.update({_id: 1}, {$set: {note: "from prepared transaction"}}));

const prepareTimestamp = PrepareHelpers.prepareTransaction(session);

assert.commandFailedWithCode(
    testColl.update({_id: 1}, {$set: {note: "outside prepared transaction"}}),
    ErrorCodes.WriteConflict);

assert.commandWorked(PrepareHelpers.commitTransaction(session, prepareTimestamp));

const profileEntry =
    testDB.system.profile.findOne({"command.u.$set.note": "outside prepared transaction"});
assert.gte(profileEntry.prepareReadConflicts, 1);

assert.commandWorked(
    testDB.adminCommand({configureFailPoint: "WTSkipPrepareConflictRetries", mode: "off"}));

assert.commandWorked(
    testDB.adminCommand({configureFailPoint: "skipWriteConflictRetries", mode: "off"}));

session.endSession();
rst.stopSet();
})();