blob: ff476aa3419671c01253c3c4e45c8611ae9c78fa (
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
|
/**
* Tests that an unprepared transaction can be rolled back.
* @tags: [requires_replication, requires_wiredtiger, requires_fcv_44]
*/
(function() {
'use strict';
load('jstests/replsets/libs/rollback_test.js');
load('jstests/replsets/libs/rollback_files.js');
load("jstests/libs/uuid_util.js");
// Operations that will be present on both nodes, before the common point.
const dbName = 'test';
const collName = 'test.t';
const collNameShort = 't';
let CommonOps = (node) => {
const coll = node.getCollection(collName);
assert.commandWorked(coll.insert({_id: 0}));
};
// Operations that will be performed on the rollback node past the common point.
let RollbackOps = (node) => {
const session = node.startSession();
const sessionDB = session.getDatabase(dbName);
const sessionColl = sessionDB.getCollection(collNameShort);
session.startTransaction();
assert.commandWorked(sessionColl.insert({_id: "a"}));
assert.commandWorked(sessionColl.insert({_id: "b"}));
assert.commandWorked(sessionColl.insert({_id: "c"}));
assert.commandWorked(session.commitTransaction_forTesting());
session.endSession();
};
// Set up Rollback Test.
const rollbackTest = new RollbackTest();
CommonOps(rollbackTest.getPrimary());
const rollbackNode = rollbackTest.transitionToRollbackOperations();
RollbackOps(rollbackNode);
// Wait for rollback to finish.
rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
rollbackTest.transitionToSyncSourceOperationsDuringRollback();
rollbackTest.transitionToSteadyStateOperations();
// Check collection count.
const primary = rollbackTest.getPrimary();
const coll = primary.getCollection(collName);
assert.eq(1, coll.find().itcount());
assert.eq(1, coll.count());
// Confirm that the rollback wrote deleted documents to a file.
const replTest = rollbackTest.getTestFixture();
const expectedDocs = [{_id: "a"}, {_id: "b"}, {_id: "c"}];
const uuid = getUUIDFromListCollections(rollbackTest.getPrimary().getDB(dbName), collNameShort);
checkRollbackFiles(replTest.getDbPath(rollbackNode), collName, uuid, expectedDocs);
rollbackTest.stop();
})();
|