summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/find_flip_sbe_enabled.js
blob: 4afccfa7d547aa88f767d899f306beac53058c0f (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
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';

/**
 * Sets the internalQueryEnableSlotBasedExecutionEngine flag to true and false, and
 * asserts that find queries using the plan cache produce the correct results.
 *
 * @tags: [
 * ]
 */

load("jstests/libs/sbe_util.js");

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

    function setup(db, coll, cluster) {
        if (!checkSBEEnabled(db)) {
            jsTestLog("Skipping this test because sbe is disabled");
        }

        cluster.executeOnMongodNodes(function(db) {
            db.adminCommand({setParameter: 1, internalQueryEnableSlotBasedExecutionEngine: false});
        });

        for (let i = 0; i < 10; ++i) {
            assertAlways.commandWorked(
                db.coll.insert({_id: i, x: i.toString(), y: i.toString(), z: i.toString()}));
        }

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

    let states = (function() {
        function init(db, coll) {
            const originalParamValue = db.adminCommand(
                {getParameter: 1, "internalQueryEnableSlotBasedExecutionEngine": 1});
            assertAlways.commandWorked(originalParamValue);
            this.originalParamValue =
                originalParamValue.internalQueryEnableSlotBasedExecutionEngine;

            if (!checkSBEEnabled(db)) {
                return;
            }
            this.isSBEEnabled = true;
        }

        function toggleSBESwitchOn(db, coll) {
            if (!this.isSBEEnabled) {
                return;
            }

            assertAlways.commandWorked(db.adminCommand(
                {setParameter: 1, internalQueryEnableSlotBasedExecutionEngine: true}));
        }

        function toggleSBESwitchOff(db, coll) {
            if (!this.isSBEEnabled) {
                return;
            }

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

        function runQueriesAndCheckResults(db, coll) {
            if (!this.isSBEEnabled) {
                return;
            }

            for (let i = 0; i < 10; i++) {
                const res =
                    db.coll.find({x: i.toString(), y: i.toString(), z: i.toString()}).toArray();
                assertAlways.eq(res.length, 1);
                assertAlways.eq(res[0]._id, i);
            }
        }

        function createIndex(db, coll) {
            if (!this.isSBEEnabled) {
                return;
            }

            assertAlways.commandWorked(db.coll.createIndex({z: 1}));
        }

        function dropIndex(db, coll) {
            if (!this.isSBEEnabled) {
                return;
            }

            assertAlways.commandWorked(db.coll.dropIndex({z: 1}));
        }

        return {
            init: init,
            toggleSBESwitchOn: toggleSBESwitchOn,
            toggleSBESwitchOff: toggleSBESwitchOff,
            runQueriesAndCheckResults: runQueriesAndCheckResults,
            createIndex: createIndex,
            dropIndex: dropIndex
        };
    })();

    let transitions = {
        init: {toggleSBESwitchOn: 1},

        toggleSBESwitchOn:
            {toggleSBESwitchOn: 0.1, toggleSBESwitchOff: 0.1, runQueriesAndCheckResults: 0.8},

        toggleSBESwitchOff:
            {toggleSBESwitchOn: 0.1, toggleSBESwitchOff: 0.1, runQueriesAndCheckResults: 0.8},

        runQueriesAndCheckResults: {
            toggleSBESwitchOn: 0.1,
            toggleSBESwitchOff: 0.1,
            runQueriesAndCheckResults: 0.78,
            createIndex: 0.02,
        },

        createIndex: {
            toggleSBESwitchOn: 0.1,
            toggleSBESwitchOff: 0.1,
            runQueriesAndCheckResults: 0.78,
            createIndex: 0.01,
            dropIndex: 0.01
        },

        dropIndex: {
            toggleSBESwitchOn: 0.1,
            toggleSBESwitchOff: 0.1,
            runQueriesAndCheckResults: 0.78,
            createIndex: 0.02,
        }
    };

    function teardown(db, coll, cluster) {
        const setParam = this.originalParamValue;
        cluster.executeOnMongodNodes(function(db) {
            assertAlways.commandWorked(db.adminCommand(
                {setParameter: 1, internalQueryEnableSlotBasedExecutionEngine: setParam}));
        });
    }

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