summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/currentop_secondary_slow_op.js
blob: 945f2c88cf70a1b301d3366d0c2c800caca429d8 (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
/**
 * Confirms slow currentOp logging does not conflict with applying an oplog batch.
 * @tags: [
 *   requires_replication,
 *   sbe_incompatible,
 * ]
 */
(function() {
"use strict";

const rst = new ReplSetTest({
    nodes: [
        {},
        {
            // Disallow elections on secondary.
            rsConfig: {
                priority: 0,
                votes: 0,
            },
            slowms: 30000,  // Don't log slow operations on secondary.
        },
    ]
});
const nodes = rst.startSet();
rst.initiate();

const primary = rst.getPrimary();
const testDB = primary.getDB('test');
const coll = testDB.getCollection('test');

assert.commandWorked(coll.insert({_id: 'a'}));

const secondary = rst.getSecondary();
const secondaryDB = secondary.getDB(testDB.getName());
assert.commandWorked(secondaryDB.adminCommand({
    configureFailPoint: 'hangAfterCollectionInserts',
    mode: 'alwaysOn',
    data: {
        collectionNS: coll.getFullName(),
        first_id: 'b',
    },
}));

try {
    assert.commandWorked(coll.insert({_id: 'b'}));
    checkLog.containsJson(secondary, 20289);

    jsTestLog('Running currentOp() with slow operation logging.');
    // Lower slowms to make currentOp() log slow operation while the secondary is procesing the
    // commitIndexBuild oplog entry during oplog application.
    // Use admin db on secondary to avoid lock conflict with inserts in test db.
    const secondaryAdminDB = secondaryDB.getSiblingDB('admin');
    const profileResult = assert.commandWorked(secondaryAdminDB.setProfilingLevel(0, {slowms: -1}));
    jsTestLog('Configured profiling to always log slow ops: ' + tojson(profileResult));
    const currentOpResult = assert.commandWorked(secondaryAdminDB.currentOp());
    jsTestLog('currentOp() with slow operation logging: ' + tojson(currentOpResult));
    assert.commandWorked(
        secondaryAdminDB.setProfilingLevel(profileResult.was, {slowms: profileResult.slowms}));
    jsTestLog('Completed currentOp() with slow operation logging.');
} finally {
    assert.commandWorked(
        secondaryDB.adminCommand({configureFailPoint: 'hangAfterCollectionInserts', mode: 'off'}));
}

rst.stopSet();
})();