summaryrefslogtreecommitdiff
path: root/jstests/replsets/rollback_files_no_prepare_conflict.js
blob: 25d0aa3f8deadc55b16878b8587d50061ed22d02 (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
/**
 * Tests that rolling back prepared transactions does not lead to prepare conflicts. These may
 * occur while writing out rollback data files for ops that were done outside of those
 * transactions but are in conflict with their contents. However, since we abort prepared
 * transactions on rollback, such prepare conflicts would be unnecessary. This test therefore
 * verifies that they do not happen.
 *
 * @tags: [uses_transactions, uses_prepare_transaction]
 */
(function() {
"use strict";
load("jstests/core/txns/libs/prepare_helpers.js");
load("jstests/replsets/libs/rollback_test.js");

const name = "rollback_files_no_prepare_conflicts";
const dbName = "test";
const collName = name;

const rollbackTest = new RollbackTest(name);

let primary = rollbackTest.getPrimary();
let testDB = primary.getDB(dbName);
let testColl = testDB.getCollection(collName);

jsTestLog("Issue an insert that will be common to both nodes.");
assert.commandWorked(testColl.insert({_id: 42, a: "one"}));

rollbackTest.transitionToRollbackOperations();

const session = primary.startSession();
const sessionDB = session.getDatabase(dbName);
const sessionColl = sessionDB.getCollection(collName);

jsTestLog("Make an update to that document outside of a transaction on the rollback node.");
assert.commandWorked(testColl.update({_id: 42, a: "one"}, {_id: 42, a: "two"}));

session.startTransaction();

jsTestLog("Update the same document on the same node, this time as part of a transaction.");
assert.commandWorked(sessionColl.update({_id: 42, a: "two"}, {_id: 42, a: "three"}));

jsTestLog("Prepare the transaction on the rollback node.");
PrepareHelpers.prepareTransaction(session, {w: 1});

rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
rollbackTest.transitionToSyncSourceOperationsDuringRollback();
rollbackTest.transitionToSteadyStateOperations();

jsTestLog("Verify that the document is in the same state as it was at the common point.");
primary = rollbackTest.getPrimary();
testDB = primary.getDB(dbName);
testColl = testDB.getCollection(collName);
assert.docEq({_id: 42, a: "one"}, testColl.findOne({_id: 42}));

rollbackTest.stop();
})();