summaryrefslogtreecommitdiff
path: root/jstests/sharding/resharding_critical_section_timeout.js
blob: 5370f24a7d5e813dd14976cb3aa4ed7bf84fbbf5 (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
/**
 * Verifies that resharding honors the critical section timeout.
 *
 * @tags: [
 *   requires_fcv_49,
 *   uses_atclustertime,
 *   disabled_due_to_server_58295
 * ]
 */

(function() {
'use strict';

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

function setupTest(reshardingTest, namespace, timeout) {
    reshardingTest.setup();

    jsTest.log(`Running test for criticalSectionTimeoutMillis = ${timeout}`);

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

    const mongos = inputCollection.getMongo();
    const topology = DiscoverTopology.findConnectedNodes(mongos);
    const coordinator = new Mongo(topology.configsvr.nodes[0]);
    assert.commandWorked(coordinator.getDB("admin").adminCommand(
        {setParameter: 1, reshardingCriticalSectionTimeoutMillis: timeout}));

    assert.commandWorked(inputCollection.insert([
        {_id: "stays on shard0", oldKey: -10, newKey: -10},
        {_id: "moves to shard0", oldKey: 10, newKey: -10},
        {_id: "moves to shard1", oldKey: -10, newKey: 10},
        {_id: "stays on shard1", oldKey: 10, newKey: 10},
    ]));
}

// This test will not timeout.
const successReshardingTest =
    new ReshardingTest({numDonors: 2, numRecipients: 2, reshardInPlace: true});
const noTimeoutMillis = 8000;
var namespace = `reshardingDb.coll${noTimeoutMillis}`;

setupTest(successReshardingTest, namespace, noTimeoutMillis);

var recipientShardNames = successReshardingTest.recipientShardNames;
successReshardingTest.withReshardingInBackground({
    newShardKeyPattern: {newKey: 1},
    newChunks: [
        {min: {newKey: MinKey}, max: {newKey: 0}, shard: recipientShardNames[0]},
        {min: {newKey: 0}, max: {newKey: MaxKey}, shard: recipientShardNames[1]},
    ],
});

successReshardingTest.teardown();

// This test will timeout.
const failureReshardingTest =
    new ReshardingTest({numDonors: 2, numRecipients: 2, reshardInPlace: true});
const shouldTimeoutMillis = 0;
namespace = `reshardingDb.coll${shouldTimeoutMillis}`;

setupTest(failureReshardingTest, namespace, shouldTimeoutMillis);

recipientShardNames = failureReshardingTest.recipientShardNames;
failureReshardingTest.withReshardingInBackground(
    {
        newShardKeyPattern: {newKey: 1},
        newChunks: [
            {min: {newKey: MinKey}, max: {newKey: 0}, shard: recipientShardNames[0]},
            {min: {newKey: 0}, max: {newKey: MaxKey}, shard: recipientShardNames[1]},
        ],
    },
    (tempNs) => {},
    {expectedErrorCode: ErrorCodes.ReshardingCriticalSectionTimeout});

failureReshardingTest.teardown();
})();