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

/**
 * Tests running sharding operations with 'collectionUUID' parameter while the sharded collection is
 * being renamed concurrenlty.
 * @tags: [
 *   # This test just performs rename operations that can't be executed in transactions.
 *   does_not_support_transactions,
 *   requires_non_retryable_writes,
 *   requires_fcv_60,
 *   requires_sharding,
 * ]
 */
load('jstests/concurrency/fsm_libs/extend_workload.js');       // for extendWorkload
load('jstests/concurrency/fsm_workloads/collection_uuid.js');  // for $config

var $config = extendWorkload($config, function($config, $super) {
    const origStates = Object.keys($config.states);
    $config.states = Object.extend({
        shardingCommands: function shardingCommands(db, collName) {
            const namespace = db.getName() + "." + collName;

            // ShardCollection should fail as the collection is already sharded.
            let shardCollectionCmd = {
                shardCollection: namespace,
                key: {a: 1},
                collectionUUID: this.collUUID
            };
            testCommand(db, namespace, "shardCollection", shardCollectionCmd, this, [
                ErrorCodes.AlreadyInitialized
            ]);

            // Reshard with new shard-key.
            let reshardCollectionCmd = {
                reshardCollection: namespace,
                key: {a: 1},
                collectionUUID: this.collUUID
            };
            testCommand(db, namespace, "reshardCollection", reshardCollectionCmd, this);

            // Refine the shard-key.
            const refineCollectionCmd = {
                refineCollectionShardKey: namespace,
                key: {a: 1, b: 1},
                collectionUUID: this.collUUID
            };
            testCommand(db,
                        namespace,
                        "refineCollectionShardKey",
                        refineCollectionCmd,
                        this,
                        // The shard key might be changed to '_id' already by another thread.
                        [ErrorCodes.InvalidOptions]);

            // Reshard back with '_id' shard-key.
            reshardCollectionCmd = {
                reshardCollection: namespace,
                key: {_id: 1},
                collectionUUID: this.collUUID
            };
            testCommand(db, namespace, "reshardCollection", reshardCollectionCmd, this);
        }
    },
                                   $super.states);

    let newTransitions = Object.extend({}, $super.transitions);
    let indexCommandsState = {};
    origStates.forEach(function(state) {
        if (state === "indexCommands") {
            indexCommandsState = newTransitions[state];
        }

        if (state !== "init") {
            newTransitions[state]["shardingCommands"] = 0.2;
        }
    });
    newTransitions["shardingCommands"] = indexCommandsState;
    $config.transitions = newTransitions;

    $config.states.init = function init(db, collName) {
        $super.states.init.apply(this, [db, collName]);

        // reshardCollcetion changes the collectionUUID.
        this.collUUIDFixed = false;
    };

    $config.threadCount = 5;
    $config.iterations = 50;

    return $config;
});