summaryrefslogtreecommitdiff
path: root/jstests/sharding/ddl_ops_reported_on_current_op_command.js
blob: a35615e4f23a877669953a749e8cf4cedb259f19 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
 * Checks that DDL command that use step-down resilient coordinators are shown when calling the
 * currentOp command.
 *
 * @tags: [
 *   requires_fcv_50,
 *   featureFlagShardingFullDDLSupport,
 *   disabled_due_to_server_58295
 * ]
 */
(function() {
'use strict';

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

const kDbName = 'db';
const kCollectionName = 'test';
const nss = kDbName + '.' + kCollectionName;
const toNss = nss + '_renamed';

let st = new ShardingTest({shards: 1});

st.s.adminCommand({enableSharding: kDbName, primaryShard: st.shard0.shardName});

st.s.getDB(kDbName).getCollection(kCollectionName).insert({x: 1});

let getCurrentOpOfDDL = (ddlOpThread, desc) => {
    let ddlCoordinatorFailPoint =
        configureFailPoint(st.getPrimaryShard(kDbName), 'hangBeforeRunningCoordinatorInstance');

    ddlOpThread.start();
    ddlCoordinatorFailPoint.wait();
    let currOp = st.s.getDB('admin')
                     .aggregate([{$currentOp: {allUsers: true}}, {$match: {desc: desc}}])
                     .toArray();

    ddlCoordinatorFailPoint.off();
    ddlOpThread.join();

    return currOp;
};

{
    jsTestLog('Check create collection shows in current op');

    let shardKey = {_id: 1};

    let ddlOpThread = new Thread((mongosConnString, nss, shardKey) => {
        let mongos = new Mongo(mongosConnString);
        mongos.adminCommand({shardCollection: nss, key: shardKey});
    }, st.s0.host, nss, shardKey);

    let currOp = getCurrentOpOfDDL(ddlOpThread, 'CreateCollectionCoordinator');

    // There must be one operation running with the appropiate ns.
    assert.eq(1, currOp.length);
    assert.eq(nss, currOp[0].ns);
    // It must have at least the shardKey.
    assert(currOp[0].hasOwnProperty('command'));
    assert(currOp[0].command.hasOwnProperty('shardKey'));
    assert.eq(shardKey, currOp[0].command.shardKey);
}

{
    jsTestLog('Check refine collection shard key shows in current op');

    let newShardKey = {_id: 1, x: 1};
    st.s.getCollection(nss).createIndex(newShardKey);
    let ddlOpThread = new Thread((mongosConnString, nss, newShardKey) => {
        let mongos = new Mongo(mongosConnString);
        mongos.adminCommand({refineCollectionShardKey: nss, key: newShardKey});
    }, st.s0.host, nss, newShardKey);

    let currOp = getCurrentOpOfDDL(ddlOpThread, 'RefineCollectionShardKeyCoordinator');

    // There must be one operation running with the appropiate ns.
    assert.eq(1, currOp.length);
    assert.eq(nss, currOp[0].ns);
    assert(currOp[0].hasOwnProperty('command'));
    assert(currOp[0].command.hasOwnProperty('newShardKey'));
    assert.eq(newShardKey, currOp[0].command.newShardKey);
}

{
    jsTestLog('Check rename collection shows in current op');

    let ddlOpThread = new Thread((mongosConnString, fromNss, toNss) => {
        let mongos = new Mongo(mongosConnString);
        mongos.getCollection(fromNss).renameCollection(toNss.split('.')[1], true);
    }, st.s0.host, nss, toNss);

    let currOp = getCurrentOpOfDDL(ddlOpThread, 'RenameCollectionCoordinator');

    // There must be one operation running with the appropiate ns.
    assert.eq(1, currOp.length);
    assert.eq(nss, currOp[0].ns);

    // It must have the target collection.
    assert(currOp[0].hasOwnProperty('command'));
    assert.docEq({to: toNss, dropTarget: true, stayTemp: false}, currOp[0].command);
}

{
    jsTestLog('Check move primary shows in current op');

    let ddlOpThread = new Thread((mongosConnString, dbName, destShard) => {
        let mongos = new Mongo(mongosConnString);
        mongos.adminCommand({movePrimary: dbName, to: destShard});
    }, st.s0.host, kDbName, st.shard0.shardName);

    let currOp = getCurrentOpOfDDL(ddlOpThread, 'MovePrimaryCoordinator');

    // There must be one operation running with the appropiate ns.
    assert.eq(1, currOp.length);
    assert.eq(kDbName, currOp[0].ns);
    assert(currOp[0].command.hasOwnProperty('request'));
    assert(currOp[0].command.request.hasOwnProperty('toShardId'));
    assert.eq(st.shard0.shardName, currOp[0].command.request.toShardId);
}

{
    jsTestLog('Check drop collection shows in current op');

    let ddlOpThread = new Thread((mongosConnString, nss) => {
        let mongos = new Mongo(mongosConnString);
        mongos.getCollection(nss).drop();
    }, st.s0.host, toNss);

    let currOp = getCurrentOpOfDDL(ddlOpThread, 'DropCollectionCoordinator');

    // There must be one operation running with the appropiate ns.
    assert.eq(1, currOp.length);
    assert.eq(toNss, currOp[0].ns);
}

{
    jsTestLog('Check drop database shows in current op');

    let ddlOpThread = new Thread((mongosConnString, dbName) => {
        let mongos = new Mongo(mongosConnString);
        mongos.getDB(dbName).dropDatabase();
    }, st.s0.host, kDbName);

    let currOp = getCurrentOpOfDDL(ddlOpThread, 'DropDatabaseCoordinator');

    // There must be one operation running with the appropiate ns.
    assert.eq(1, currOp.length);
    assert.eq(kDbName, currOp[0].ns.split('.')[0]);
}

st.stop();
})();