summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/drop_collection_sharded.js
blob: 53349e73bc6e6fb8b4451337efb3532b4986a564 (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
/**
 * drop_collection_sharded.js
 *
 * Repeatedly creates and drops a collection.
 *
 * @tags: [
 *   requires_sharding,
 * ]
 */
'use strict';

const dbPrefix = 'fsmDB_';
const dbCount = 2;
const collPrefix = 'sharded_coll_';
const collCount = 2;

function getRandomDb(db) {
    return db.getSiblingDB(dbPrefix + Random.randInt(dbCount));
}

function getRandomCollection(db) {
    return getRandomDb(db)[collPrefix + Random.randInt(collCount)];
}

var $config = (function() {
    var setup = function(db, collName, cluster) {
        // Initialize databases
        for (var i = 0; i < dbCount; i++) {
            const dbName = dbPrefix + i;
            db.adminCommand({enablesharding: dbName});
        }
    };

    var states = (function() {
        function init(db, collName) {
        }

        function create(db, collName) {
            const coll = getRandomCollection(db);
            jsTestLog("Executing create state on: " + coll.getFullName());
            assertAlways.commandWorked(
                db.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}}));
        }

        function drop(db, collName) {
            const coll = getRandomCollection(db);
            jsTestLog("Executing drop state on: " + coll.getFullName());
            assertAlways.commandWorked(coll.getDB().runCommand({drop: coll.getName()}));
        }

        return {init: init, create: create, drop: drop};
    })();

    var transitions = {
        init: {create: 0.5, drop: 0.5},
        create: {create: 0.5, drop: 0.5},
        drop: {create: 0.5, drop: 0.5}
    };

    return {
        threadCount: 12,
        iterations: 64,
        startState: 'init',
        data: {},
        states: states,
        setup: setup,
        transitions: transitions
    };
})();