summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/list_indexes.js
blob: 6bcdb8ba96ce495b121cbf0e87d1c6290684081a (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';

/**
 * list_indexes.js
 *
 * Checks that the listIndexes command can tolerate concurrent modifications to the
 * index catalog.
 */
var $config = (function() {

    var states = (function() {
        // Picks a random index to drop and recreate.
        function modifyIndices(db, collName) {
            var spec = {};
            spec['foo' + this.tid] = 1;

            assertWhenOwnColl.commandWorked(db[collName].dropIndex(spec));
            sleep(100);
            assertWhenOwnColl.commandWorked(db[collName].ensureIndex(spec));
        }

        // List indexes, using a batchSize of 2 to ensure getmores happen.
        function listIndices(db, collName) {
            var cursor = new DBCommandCursor(
                db.getMongo(), db.runCommand({listIndexes: collName, cursor: {batchSize: 2}}));
            assertWhenOwnColl.gte(cursor.itcount(), 0);
        }

        return {
            modifyIndices: modifyIndices,
            listIndices: listIndices
        };
    })();

    var transitions = {
        modifyIndices: {listIndices: 0.75, modifyIndices: 0.25},
        listIndices: {listIndices: 0.25, modifyIndices: 0.75}
    };

    function setup(db, collName) {
        // Create indices {fooi: 1}.
        for (var i = 0; i < this.threadCount; ++i) {
            var spec = {};
            spec['foo' + i] = 1;
            assertAlways.commandWorked(db[collName].ensureIndex(spec));
        }
    }

    return {
        threadCount: 10,
        iterations: 20,
        states: states,
        startState: 'modifyIndices',
        transitions: transitions,
        setup: setup
    };
})();