summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/CRUD_and_commands_with_createindexes.js
blob: dc885e0b575b7b05d806153b6dbaa93de7fbf828 (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
'use strict';

/**
 * Perform CRUD operations, some of which may implicitly create collections. Also perform index
 * creations which may implicitly create collections. Performs these in parallel with collection-
 * dropping operations.
 */
load('jstests/concurrency/fsm_libs/extend_workload.js');         // for extendWorkload
load('jstests/concurrency/fsm_workloads/CRUD_and_commands.js');  // for $config

// TODO(SERVER-46971) combine with CRUD_and_commands.js and remove `local` readConcern.
TestData.defaultTransactionReadConcernLevel = "local";

var $config = extendWorkload($config, function($config, $super) {
    const origStates = Object.keys($config.states);
    $config.states = Object.extend({
        createIndex: function createIndex(db, collName) {
            db[collName].createIndex({value: 1});
        },
        createIdIndex: function createIdIndex(db, collName) {
            try {
                assertWhenOwnColl.commandWorked(db[collName].createIndex({_id: 1}));
            } catch (e) {
                if (e.code == ErrorCodes.ConflictingOperationInProgress) {
                    // createIndex concurrently with dropCollection can throw.
                    if (TestData.runInsideTransaction) {
                        e["errorLabels"] = ["TransientTransactionError"];
                        throw e;
                    }
                }
            }
        },

        dropIndex: function dropIndex(db, collName) {
            db[collName].dropIndex({value: 1});
        }
    },
                                   $super.states);

    let newTransitions = Object.extend({}, $super.transitions);
    let exampleState = {};
    origStates.forEach(function(state) {
        newTransitions[state]["createIndex"] = 0.10;
        newTransitions[state]["createIdIndex"] = 0.10;
        newTransitions[state]["dropIndex"] = 0.10;
        if (state !== "init" && state !== "dropCollection") {
            exampleState = $config.transitions[state];
        }
    });

    newTransitions["createIndex"] = exampleState;
    newTransitions["createIdIndex"] = exampleState;
    newTransitions["dropIndex"] = exampleState;

    $config.transitions = newTransitions;
    return $config;
});