summaryrefslogtreecommitdiff
path: root/jstests/sharding/resharding_disallow_drop.js
blob: 144abd55b1689745f78e6da647bfa2f141e2ec4a (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
/**
 * Tests that a drop can't happen while resharding is in progress.
 * @tags: [
 *  requires_fcv_53,
 *  featureFlagRecoverableShardsvrReshardCollectionCoordinator,
 * ]
 */
(function() {
"use strict";

load("jstests/libs/fail_point_util.js");

var st = new ShardingTest({
    shards: {rs0: {nodes: 2}},
    config: 1,
    mongos: 1,
    other: {
        configOptions: {setParameter: {reshardingCriticalSectionTimeoutMillis: 24 * 60 * 60 * 1000}}
    }
});

const dbName = "test";
const collName = "foo";
const ns = dbName + "." + collName;
const db = st.s.getDB(dbName);

assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: 1}}));

const reshardingPauseBeforeInsertCoordinatorDocFailpoint =
    configureFailPoint(st.configRS.getPrimary(), "pauseBeforeInsertCoordinatorDoc");

assert.commandFailedWithCode(
    db.adminCommand({reshardCollection: ns, key: {newKey: 1}, maxTimeMS: 1000}),
    ErrorCodes.MaxTimeMSExpired);

// Wait for resharding to start running on the configsvr
reshardingPauseBeforeInsertCoordinatorDocFailpoint.wait();

// Drop cannot progress while resharding is in progress
assert.commandFailedWithCode(db.runCommand({drop: collName, maxTimeMS: 5000}),
                             ErrorCodes.MaxTimeMSExpired);

// Stepdown the DB primary shard
const shard0Primary = st.rs0.getPrimary();
assert.commandWorked(
    shard0Primary.adminCommand({replSetStepDown: ReplSetTest.kForeverSecs, force: true}));
st.rs0.awaitNodesAgreeOnPrimary();

// Even after stepdown, drop cannot progress due to the in-progress resharding
assert.commandFailedWithCode(db.runCommand({drop: collName, maxTimeMS: 5000}),
                             ErrorCodes.MaxTimeMSExpired);

// Finish resharding
reshardingPauseBeforeInsertCoordinatorDocFailpoint.off();
assert.commandWorked(db.adminCommand({reshardCollection: ns, key: {newKey: 1}}));

// Now the drop can complete
assert.commandWorked(db.runCommand({drop: collName}));

st.stop();
})();