summaryrefslogtreecommitdiff
path: root/jstests/sharding/resharding_prohibited_commands.js
blob: 9167db7befb74e6f9ad7ca086f61953dbac1e644 (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
/**
 * Tests that chunk migrations, collMod, createIndexes, and dropIndexes are prohibited on a
 * collection that is undergoing a resharding operation. Also tests that concurrent resharding
 * operations are prohibited.
 *
 * @tags: [
 *   requires_fcv_49,
 *   uses_atclustertime,
 * ]
 */
(function() {
"use strict";

load("jstests/libs/discover_topology.js");
load("jstests/sharding/libs/resharding_test_fixture.js");

const reshardingTest = new ReshardingTest({numDonors: 2});
reshardingTest.setup();

const donorShardNames = reshardingTest.donorShardNames;
const sourceCollection = reshardingTest.createShardedCollection({
    ns: "reshardingDb.coll",
    shardKeyPattern: {oldKey: 1},
    chunks: [{min: {oldKey: MinKey}, max: {oldKey: MaxKey}, shard: donorShardNames[0]}],
});

const recipientShardNames = reshardingTest.recipientShardNames;
reshardingTest.withReshardingInBackground(
    {
        newShardKeyPattern: {newKey: 1},
        newChunks: [{min: {newKey: MinKey}, max: {newKey: MaxKey}, shard: recipientShardNames[0]}],
    },
    (tempNs) => {
        const mongos = sourceCollection.getMongo();
        const ns = sourceCollection.getFullName();
        const db = sourceCollection.getDB();

        let res;
        assert.soon(() => {
            res = mongos.getCollection("config.collections")
                      .find({_id: {$in: [ns, tempNs]}})
                      .toArray();

            return res.length === 2 && res.every(collEntry => collEntry.allowMigrations === false);
        }, () => `timed out waiting for collections to have allowMigrations=false: ${tojson(res)}`);
        assert.soon(
            () => {
                res = mongos.getCollection("config.collections").findOne({_id: ns});
                return res.hasOwnProperty("reshardingFields");
            },
            () => `timed out waiting for resharding fields to be added to original nss: ${
                tojson(res)}`);

        const topology = DiscoverTopology.findConnectedNodes(mongos);
        const donor = new Mongo(topology.shards[donorShardNames[0]].primary);
        assert.soon(() => {
            res = donor.getCollection("config.localReshardingOperations.donor").find().toArray();
            return res.length == 1;
        }, "timed out waiting for resharding initialization on donor shard");

        assert.commandFailedWithCode(
            mongos.adminCommand({moveChunk: ns, find: {oldKey: -10}, to: donorShardNames[1]}),
            ErrorCodes.LockBusy);
        assert.commandFailedWithCode(db.runCommand({collMod: 'coll'}),
                                     ErrorCodes.ReshardCollectionInProgress);
        assert.commandFailedWithCode(sourceCollection.createIndexes([{newKey: 1}]),
                                     ErrorCodes.ReshardCollectionInProgress);
        assert.commandFailedWithCode(db.runCommand({dropIndexes: 'coll', index: '*'}),
                                     ErrorCodes.ReshardCollectionInProgress);

        let newNs = "reshardingDb2.coll2";
        assert.commandWorked(mongos.adminCommand({enableSharding: "reshardingDb2"}));
        assert.commandWorked(mongos.adminCommand({shardCollection: newNs, key: {oldKey: 1}}));

        assert.commandFailedWithCode(
            mongos.adminCommand({reshardCollection: newNs, key: {newKey: 1}}),
            ErrorCodes.ReshardCollectionInProgress);

        mongos.getCollection(newNs).drop();
    });

reshardingTest.teardown();
})();