summaryrefslogtreecommitdiff
path: root/jstests/replsets/rollback_clustered_indexes.js
blob: 4f1cc3c2ed8fb836aa19071e8e90e2bc9ebafb96 (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 that writes on collections clustered by _id can be rolled back.
 * @tags: [
 *   requires_replication,
 *   requires_wiredtiger,
 * ]
 */
(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.system.buckets.t';
const collNameShort = 'system.buckets.t';
let commonOps = (node) => {
    const db = node.getDB(dbName);
    assert.commandWorked(db.createCollection(collNameShort, {clusteredIndex: true}));
    const coll = node.getCollection(collName);
    assert.commandWorked(coll.createIndex({a: 1, b: -1}));
    assert.commandWorked(coll.insert({a: 0, b: 0}));
};

// Operations that will be performed on the rollback node past the common point.
let rollbackDocs = [];
let rollbackOps = (node) => {
    const coll = node.getCollection(collName);
    let doc;
    doc = {_id: new ObjectId(), a: 1, b: 3};
    assert.commandWorked(coll.insert(doc));
    rollbackDocs.push(doc);

    doc = {_id: new ObjectId(), a: 2, b: 2};
    assert.commandWorked(coll.insert(doc));
    rollbackDocs.push(doc);

    doc = {_id: new ObjectId(), a: 3, b: 1};
    assert.commandWorked(coll.insert(doc));
    rollbackDocs.push(doc);
};

// 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 uuid = getUUIDFromListCollections(rollbackTest.getPrimary().getDB(dbName), collNameShort);
checkRollbackFiles(replTest.getDbPath(rollbackNode), collName, uuid, rollbackDocs);

rollbackTest.stop();
})();