summaryrefslogtreecommitdiff
path: root/jstests/replsets/rollback_drop_index_after_rename.js
blob: 143701e8e95bf88a6abde382a78984ddc29e2ce7 (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
/**
 * Test that a dropIndex on a collection that was renamed is rolled back successfully.
 *
 * This test works by creating a collection and an index in that collection,
 * then renaming that collection and rolling back a drop on that index.
 */

(function() {
"use strict";

load("jstests/replsets/libs/rollback_test.js");

const testName = "rollback_drop_index_after_rename";
const dbName = testName;

var fromColl = "fromColl";
var toColl = "toColl";
var idxName = "a_1";

// Operations that will be present on both nodes, before the common point.
let CommonOps = (node) => {
    let testDb = node.getDB(dbName);
    // This creates the collection implicitly and then creates the index.
    assert.commandWorked(testDb.runCommand({
        createIndexes: fromColl,
        indexes: [{
            key: {
                "a": 1,
            },
            name: idxName
        }]
    }));
};

// Operations that will be performed on the rollback node past the common point.
let RollbackOps = (node) => {
    let testDb = node.getDB(dbName);
    assert.commandWorked(testDb.adminCommand({
        renameCollection: dbName + "." + fromColl,
        to: dbName + "." + toColl,
    }));
    assert.commandWorked(testDb.runCommand({dropIndexes: toColl, index: idxName}));
};

// Set up Rollback Test.
let rollbackTest = new RollbackTest(testName);
CommonOps(rollbackTest.getPrimary());

let rollbackNode = rollbackTest.transitionToRollbackOperations();
RollbackOps(rollbackNode);

// Wait for rollback to finish.
rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
rollbackTest.transitionToSyncSourceOperationsDuringRollback();
rollbackTest.transitionToSteadyStateOperations();

rollbackTest.stop();
})();