summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/find_flip_sbe_enabled.js
blob: b284b75b9e89b497edc81c91c93902320ca94eb5 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'use strict';

/**
 * Sets the internalQueryEnableSlotBasedExecutionEngine flag to true and false, and
 * asserts that find queries using the plan cache produce the correct results.
 *
 * @tags: [
 *     # Our test infrastructure prevents tests which use the 'setParameter' command from running in
 *     # stepdown suites, since parameters are local to each mongod in the replica set.
 *     does_not_support_stepdowns,
 * ]
 */

var $config = (function() {
    let data = {originalParamValue: false};

    function getCollectionName(collName) {
        return "find_flip_sbe_enabled_" + collName;
    }

    function setup(db, collName, cluster) {
        const originalParamValue =
            db.adminCommand({getParameter: 1, internalQueryEnableSlotBasedExecutionEngine: 1});
        assertAlways.commandWorked(originalParamValue);
        assert(originalParamValue.hasOwnProperty("internalQueryEnableSlotBasedExecutionEngine"));
        this.originalParamValue = originalParamValue.internalQueryEnableSlotBasedExecutionEngine;
        const coll = db.getCollection(getCollectionName(collName));
        for (let i = 0; i < 10; ++i) {
            assertAlways.commandWorked(
                coll.insert({_id: i, x: i.toString(), y: i.toString(), z: i.toString()}));
        }

        assertAlways.commandWorked(coll.createIndex({x: 1}));
        assertAlways.commandWorked(coll.createIndex({y: 1}));
    }

    let states = (function() {
        function setEnableSlotBasedExecutionEngineOn(db, collName) {
            assertAlways.commandWorked(db.adminCommand(
                {setParameter: 1, internalQueryEnableSlotBasedExecutionEngine: true}));
        }

        function setEnableSlotBasedExecutionEngineOff(db, collName) {
            assertAlways.commandWorked(db.adminCommand(
                {setParameter: 1, internalQueryEnableSlotBasedExecutionEngine: false}));
        }

        function runQueriesAndCheckResults(db, collName) {
            const coll = db.getCollection(getCollectionName(collName));
            for (let i = 0; i < 10; i++) {
                let res;
                try {
                    res = coll.find({x: i.toString(), y: i.toString(), z: i.toString()}).toArray();
                    assertAlways.eq(res.length, 1);
                    assertAlways.eq(res[0]._id, i);
                } catch (e) {
                    if (e.code !== ErrorCodes.QueryPlanKilled) {
                        throw e;  // This is an unexpected error, so we throw it again.
                    }
                }
            }
        }

        function createIndex(db, collName) {
            const coll = db.getCollection(getCollectionName(collName));
            const res = coll.createIndex({z: 1});
            assertAlways(res.ok === 1 || res.code === ErrorCodes.IndexBuildAlreadyInProgress ||
                             res.code == ErrorCodes.IndexBuildAborted,
                         "Create index failed: " + tojson(res));
        }

        function dropIndex(db, collName) {
            const coll = db.getCollection(getCollectionName(collName));
            const res = coll.dropIndex({z: 1});
            assertAlways(res.ok === 1 || res.code === ErrorCodes.IndexNotFound,
                         "Drop index failed: " + tojson(res));
        }

        return {
            setEnableSlotBasedExecutionEngineOn: setEnableSlotBasedExecutionEngineOn,
            setEnableSlotBasedExecutionEngineOff: setEnableSlotBasedExecutionEngineOff,
            runQueriesAndCheckResults: runQueriesAndCheckResults,
            createIndex: createIndex,
            dropIndex: dropIndex
        };
    })();

    let transitions = {
        setEnableSlotBasedExecutionEngineOn: {
            setEnableSlotBasedExecutionEngineOn: 0.1,
            setEnableSlotBasedExecutionEngineOff: 0.1,
            runQueriesAndCheckResults: 0.8
        },

        setEnableSlotBasedExecutionEngineOff: {
            setEnableSlotBasedExecutionEngineOn: 0.1,
            setEnableSlotBasedExecutionEngineOff: 0.1,
            runQueriesAndCheckResults: 0.8
        },

        runQueriesAndCheckResults: {
            setEnableSlotBasedExecutionEngineOn: 0.1,
            setEnableSlotBasedExecutionEngineOff: 0.1,
            runQueriesAndCheckResults: 0.78,
            createIndex: 0.02,
        },

        createIndex: {
            setEnableSlotBasedExecutionEngineOn: 0.1,
            setEnableSlotBasedExecutionEngineOff: 0.1,
            runQueriesAndCheckResults: 0.78,
            createIndex: 0.01,
            dropIndex: 0.01
        },

        dropIndex: {
            setEnableSlotBasedExecutionEngineOn: 0.1,
            setEnableSlotBasedExecutionEngineOff: 0.1,
            runQueriesAndCheckResults: 0.78,
            createIndex: 0.02,
        }
    };

    function teardown(db, collName, cluster) {
        // Restore the original state of the ForceClassicEngine parameter.
        const setParam = this.originalParamValue;
        cluster.executeOnMongodNodes(function(db) {
            assertAlways.commandWorked(db.adminCommand(
                {setParameter: 1, internalQueryEnableSlotBasedExecutionEngine: setParam}));
        });
    }

    return {
        threadCount: 10,
        iterations: 100,
        startState: 'setEnableSlotBasedExecutionEngineOn',
        states: states,
        transitions: transitions,
        setup: setup,
        teardown: teardown,
        data: data
    };
})();