summaryrefslogtreecommitdiff
path: root/jstests/replsets/tenant_migration_index_oplog_entries.js
blob: ec41defa7627a9a32dcbc737965f156cd5033a2e (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
 * Tests that we don't throw an error when the client performs two-phase index build operations,
 * or inserts docs that contain "commitIndexBuild" or "abortIndexBuild" fields.
 * @tags: [requires_fcv_47, incompatible_with_windows_tls, incompatible_with_eft,
 * incompatible_with_macos, requires_persistence]
 */

(function() {
"use strict";

load("jstests/libs/fail_point_util.js");
load("jstests/replsets/libs/tenant_migration_util.js");

const kDbName = "testDb";
const kCollName = "testColl";
const kNs = kDbName + "." + kCollName;

const rst = new ReplSetTest({nodes: 1});
rst.startSet();
rst.initiate();
if (!TenantMigrationUtil.isFeatureFlagEnabled(rst.getPrimary())) {
    jsTestLog("Skipping test because the tenant migrations feature flag is disabled");
    rst.stopSet();
    return;
}

const primary = rst.getPrimary();
const testDB = primary.getDB(kDbName);
const testColl = primary.getCollection(kNs);

assert.commandWorked(testDB.createCollection(kCollName));
assert.commandWorked(testDB.runCommand({insert: kCollName, documents: [{x: 0}]}));

jsTest.log("Test committing index build");
assert.commandWorked(testColl.createIndex({x: 1}));

jsTest.log("Test aborting index build");
let fp = configureFailPoint(primary, "failIndexBuildOnCommit");
assert.commandFailedWithCode(testColl.createIndex({y: 1}), 4698903);
fp.off();

jsTest.log("Test inserting docs that contain 'commitIndexBuild' and 'abortIndexBuild' fields");
assert.commandWorked(
    testDB.runCommand({insert: kCollName, documents: [{x: 1}, {commitIndexBuild: 1}]}));
assert.commandWorked(
    testDB.runCommand({insert: kCollName, documents: [{x: 1}, {abortIndexBuild: 1}]}));

jsTest.log("Test inserting docs that correspond to the 'o' field of valid 'commitIndexBuild' " +
           "and 'abortIndexBuild' oplog entries");
assert.commandWorked(testDB.runCommand({
    insert: kCollName,
    documents: [
        {x: 1},
        {
            commitIndexBuild: kCollName,
            indexBuildUUID: {$uuid: UUID()},
            indexes: [{v: 2, key: {z: 1.0}, name: "z_1"}],
            ts: {$timestamp: new Timestamp()},
            t: 1,
            wall: {$date: new Date()}
        }
    ]
}));
assert.commandWorked(testDB.runCommand({
    insert: kCollName,
    documents: [
        {x: 1},
        {
            abortIndexBuild: kCollName,
            indexBuildUUID: UUID(),
            indexes: [{v: 2, key: {z: 1.0}, name: "z_1"}],
            cause: {
                ok: false,
                code: 4698903,
                codeName: "Location4698903",
                errmsg: "index build aborted due to failpoint"
            },
            ts: {$timestamp: new Timestamp()},
            t: 1,
            wall: {$date: new Date()}
        }
    ]
}));

rst.stopSet();
})();