summaryrefslogtreecommitdiff
path: root/jstests/sharding/move_chunk_critical_section_non_internal_client_abort.js
blob: 8860d5bd3c874e5d6da1f1f1c7a9d5d5520c9576 (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
/**
 * Tests that a moveChunk operation is properly aborted when an index command is received from a
 * non-internal client while in the critical section.
 *
 * @tags: [
 *   does_not_support_stepdowns
 * ]
 */
(function() {
"use strict";

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

const dbName = "test";
const collName = "move_chunk_critical_section_non_internal_client_abort";
const ns = dbName + "." + collName;

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

assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
assert.commandWorked(st.s.adminCommand({movePrimary: dbName, to: st.shard0.shardName}));

assert.commandWorked(st.s.getDB(dbName).getCollection(collName).insert({_id: 0}));
assert.commandWorked(st.s.getDB(dbName).getCollection(collName).insert({_id: 1}));
assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: 1}}));

// Pause the moveChunk while it is in the critical section.
const fp = configureFailPoint(st.shard0, "moveChunkHangAtStep5");
const awaitResult =
    startParallelShell(funWithArgs(function(ns, toShardName) {
                           assert.commandFailedWithCode(
                               db.adminCommand({moveChunk: ns, find: {_id: 0}, to: toShardName}),
                               ErrorCodes.Interrupted);
                       }, ns, st.shard1.shardName), st.s.port);
fp.wait();

// Perform a collMod directly on the shard's primary to cause the moveChunk to abort.
assert.commandWorked(
    st.rs0.getPrimary().getDB(dbName).runCommand({collMod: collName, writeConcern: {w: 1}}));

fp.off();
awaitResult();

st.stop();
})();