summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/apply_ops_DDL_operation_does_not_take_global_X.js
blob: d8cd49f7995a52b5a05dbbfe00d51eec6ed5b9df (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
/**
 * Test that applying DDL operation on secondary does not take a global X lock.
 *
 * @tags: [requires_replication, requires_snapshot_read]
 */

(function() {
    'use strict';

    const testDBName = 'test';
    const readDBName = 'read';
    const readCollName = 'readColl';
    const testCollName = 'testColl';
    const renameCollName = 'renameColl';

    const rst = new ReplSetTest({name: jsTestName(), nodes: 2});
    rst.startSet();
    rst.initiate();

    const primary = rst.getPrimary();
    const secondary = rst.getSecondary();

    assert.commandWorked(
        primary.getDB(readDBName)
            .runCommand({insert: readCollName, documents: [{x: 1}], writeConcern: {w: 2}}));

    // The find will hang and holds a global IS lock.
    assert.commandWorked(secondary.getDB("admin").runCommand(
        {configureFailPoint: "waitInFindBeforeMakingBatch", mode: "alwaysOn"}));

    const findWait = startParallelShell(function() {
        db.getMongo().setSlaveOk();
        assert.eq(db.getSiblingDB('read')
                      .getCollection('readColl')
                      .find()
                      .comment('read hangs')
                      .itcount(),
                  1);
    }, secondary.port);

    assert.soon(function() {
        let findOp = secondary.getDB('admin')
                         .aggregate([{$currentOp: {}}, {$match: {'command.comment': 'read hangs'}}])
                         .toArray();
        return findOp.length == 1;
    });

    {
        // Run a series of DDL commands, none of which should take the global X lock.
        const testDB = primary.getDB(testDBName);
        assert.commandWorked(testDB.runCommand({create: testCollName, writeConcern: {w: 2}}));

        assert.commandWorked(
            testDB.runCommand({collMod: testCollName, validator: {v: 1}, writeConcern: {w: 2}}));

        assert.commandWorked(testDB.runCommand({
            createIndexes: testCollName,
            indexes: [{key: {x: 1}, name: 'x_1'}],
            writeConcern: {w: 2}
        }));

        assert.commandWorked(
            testDB.runCommand({dropIndexes: testCollName, index: 'x_1', writeConcern: {w: 2}}));

        assert.commandWorked(primary.getDB('admin').runCommand({
            renameCollection: testDBName + '.' + testCollName,
            to: testDBName + '.' + renameCollName,
            writeConcern: {w: 2}
        }));

        assert.commandWorked(testDB.runCommand({drop: renameCollName, writeConcern: {w: 2}}));
    }

    assert.commandWorked(secondary.getDB("admin").runCommand(
        {configureFailPoint: "waitInFindBeforeMakingBatch", mode: "off"}));
    findWait();

    rst.stopSet();
})();