summaryrefslogtreecommitdiff
path: root/jstests/sharding/move_chunk_respects_maxtimems.js
blob: 570a6817f85fde4940d3c9098d637c5be1274b52 (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
/**
 * Tests that if maxTimeMS is sent with a moveChunk command, the client thread that issued moveChunk
 * will be interrupted when maxTimeMS is exceeded, but moveChunk will eventually succeed in the
 * background.
 */
(function() {

"use strict";

load("jstests/libs/fail_point_util.js");
load('jstests/libs/parallel_shell_helpers.js');
load("jstests/sharding/libs/find_chunks_util.js");

var st = new ShardingTest({shards: 2});

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

// Create a sharded collection with one chunk on shard0.
assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
assert.commandWorked(st.s.adminCommand({movePrimary: dbName, to: st.shard0.shardName}));
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {x: 1}}));

// Enable failpoint which will cause moveChunk to hang indefinitely.
let step1Failpoint = configureFailPoint(st.shard0, "moveChunkHangAtStep1");

const awaitResult = startParallelShell(
    funWithArgs(function(ns, toShardName) {
        // Send moveChunk with maxTimeMS. We set it to 15 seconds to ensure that the moveChunk
        // command is run and the task to execute the moveChunk logic is launched before maxTimeMS
        // expires. That way we can check below that a maxTimeMS timeout won't fail the migration.
        assert.commandFailedWithCode(
            db.adminCommand({moveChunk: ns, find: {x: 0}, to: toShardName, maxTimeMS: 15000}),
            ErrorCodes.MaxTimeMSExpired);
    }, ns, st.shard1.shardName), st.s.port);

awaitResult();
step1Failpoint.off();

jsTestLog("Waiting for moveChunk to succeed in the background");

// The moveChunk should eventually succeed in the background even though the client thread was
// interrupted.
assert.soon(() => {
    var numChunksOnShard0 =
        findChunksUtil.findChunksByNs(st.config, ns, {shard: st.shard0.shardName}).itcount();
    var numChunksOnShard1 =
        findChunksUtil.findChunksByNs(st.config, ns, {shard: st.shard1.shardName}).itcount();
    return numChunksOnShard0 == 0 && numChunksOnShard1 == 1;
});

st.stop();
})();