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

/**
 * kill_rooted_or.js
 *
 * Queries using a rooted $or predicate to cause plan selection to use the subplanner. Tests that
 * the subplanner correctly halts plan execution when the collection is dropped or a candidate index
 * is dropped.
 *
 * This workload was designed to reproduce SERVER-24761.
 */
var $config = (function() {

    // Use the workload name as the collection name, since the workload name is assumed to be
    // unique.
    var uniqueCollectionName = 'kill_rooted_or';

    var data = {
        collName: uniqueCollectionName,
        indexSpecs: [
            {a: 1},
            {a: 1, c: 1},
            {b: 1},
            {b: 1, c: 1},
        ]
    };

    var states = {
        query: function query(db, collName) {
            var cursor = db[this.collName].find({$or: [{a: 0}, {b: 0}]});
            try {
                // No documents are ever inserted into the collection.
                assertAlways.eq(0, cursor.itcount());
            } catch (e) {
                // Ignore errors due to the plan executor being killed.
            }
        },

        dropCollection: function dropCollection(db, collName) {
            db[this.collName].drop();

            // Recreate all of the indexes on the collection.
            this.indexSpecs.forEach(indexSpec => {
                assertAlways.commandWorked(db[this.collName].createIndex(indexSpec));
            });
        },

        dropIndex: function dropIndex(db, collName) {
            var indexSpec = this.indexSpecs[Random.randInt(this.indexSpecs.length)];

            // We don't assert that the command succeeded when dropping an index because it's
            // possible another thread has already dropped this index.
            db[this.collName].dropIndex(indexSpec);

            // Recreate the index that was dropped.
            assertAlways.commandWorked(db[this.collName].createIndex(indexSpec));
        }
    };

    var transitions = {
        query: {query: 0.8, dropCollection: 0.1, dropIndex: 0.1},
        dropCollection: {query: 1},
        dropIndex: {query: 1}
    };

    function setup(db, collName, cluster) {
        this.indexSpecs.forEach(indexSpec => {
            assertAlways.commandWorked(db[this.collName].createIndex(indexSpec));
        });
    }

    return {
        threadCount: 10,
        iterations: 50,
        data: data,
        states: states,
        startState: 'query',
        transitions: transitions,
        setup: setup
    };

})();