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

/**
 * sharded_moveChunk_drop_shard_key_index.js
 *
 * Tests that dropping the shard key index while migrating a chunk doesn't cause the shard to abort.
 *
 * This workload was designed to reproduce SERVER-24994.
 *
 * @tags: [requires_sharding, assumes_balancer_off]
 */

var $config = (function() {

    var data = {numSplitPoints: 100, shardKey: {key: 1}};

    var states = {

        init: function init(db, collName) {
            // No-op
        },

        moveChunk: function moveChunk(db, collName) {
            var configDB = db.getSiblingDB('config');
            var shards = configDB.shards.aggregate([{$sample: {size: 1}}]).toArray();
            assertAlways.eq(1, shards.length, tojson(shards));

            var shardName = shards[0]._id;
            var chunkBoundary = Random.randInt(this.numSplitPoints);

            // We don't assert that the command succeeded when migrating a chunk because it's
            // possible another thread has already started migrating a chunk.
            db.adminCommand({
                moveChunk: db[collName].getFullName(),
                find: {key: chunkBoundary},
                to: shardName,
                _waitForDelete: true,
            });
        },

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

            // Re-create the index that was dropped.
            assertAlways.commandWorked(db[collName].createIndex(this.shardKey));
        }

    };

    var transitions = {
        init: {moveChunk: 0.5, dropIndex: 0.5},
        moveChunk: {moveChunk: 0.5, dropIndex: 0.5},
        dropIndex: {moveChunk: 0.5, dropIndex: 0.5}
    };

    function setup(db, collName, cluster) {
        var bulk = db[collName].initializeUnorderedBulkOp();
        for (var i = 0; i < this.numSplitPoints; ++i) {
            bulk.insert({key: i});
        }

        var res = bulk.execute();
        assertAlways.writeOK(res);
        assertAlways.eq(this.numSplitPoints, res.nInserted, tojson(res));

        for (i = 0; i < this.numSplitPoints; ++i) {
            assertWhenOwnColl.commandWorked(
                db.adminCommand({split: db[collName].getFullName(), middle: {key: i}}));
        }
    }

    return {
        threadCount: 10,
        iterations: 100,
        data: data,
        states: states,
        transitions: transitions,
        setup: setup,
    };

})();