summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/wt_delayed_secondary_read_concern_majority.js
blob: 807a46bbeea5d2d5add7d902c67e8a0e27585ec4 (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
/**
 * SERVER-31099 WiredTiger uses lookaside (LAS) file when the cache contents are
 * pinned and can not be evicted for example in the case of a delayed secondary
 * with read concern majority. This test inserts enough data where not using the
 * lookaside file results in a stall we can't recover from.
 *
 * This test is labeled resource intensive because its total io_write is 900MB.
 * @tags: [
 *   resource_intensive,
 * ]
 */
(function() {
"use strict";

load("jstests/replsets/rslib.js");

// Skip this test if running with --nojournal and WiredTiger.
if (jsTest.options().noJournal &&
    (!jsTest.options().storageEngine || jsTest.options().storageEngine === "wiredTiger")) {
    print("Skipping test because running WiredTiger without journaling isn't a valid" +
          " replica set configuration");
    return;
}

// Skip db hash check because delayed secondary will not catch up to primary.
TestData.skipCheckDBHashes = true;

// Skip this test if not running with the "wiredTiger" storage engine.
var storageEngine = jsTest.options().storageEngine || "wiredTiger";
if (storageEngine !== "wiredTiger") {
    print('Skipping test because storageEngine is not "wiredTiger"');
    return;
} else if (jsTest.options().wiredTigerCollectionConfigString === "type=lsm") {
    // Readers of old data, such as a lagged secondary, can lead to stalls when using
    // WiredTiger's LSM tree.
    print("WT-3742: Skipping test because we're running with WiredTiger's LSM tree");
    return;
} else {
    var rst = new ReplSetTest({
        nodes: 2,
        // We are going to insert at least 100 MB of data with a long secondary
        // delay. Configure an appropriately large oplog size.
        oplogSize: 200,
    });

    var conf = rst.getReplSetConfig();
    conf.members[1].votes = 1;
    conf.members[1].priority = 0;

    rst.startSet();

    // If featureFlagUseSecondaryDelaySecs is enabled, we must use the 'secondaryDelaySecs' field
    // name in our config. Otherwise, we use 'slaveDelay'.
    const delayFieldName = selectDelayFieldName(rst);

    conf.members[1][delayFieldName] = 24 * 60 * 60;

    // We cannot wait for a stable recovery timestamp, oplog replication, or config replication due
    // to the secondary delay.
    rst.initiateWithAnyNodeAsPrimary(conf, "replSetInitiate", {
        doNotWaitForStableRecoveryTimestamp: true,
        doNotWaitForReplication: true,
        doNotWaitForNewlyAddedRemovals: true
    });
    var primary = rst.getPrimary();  // Waits for PRIMARY state.

    // The default WC is majority and we want the delayed secondary to fall behind in replication.
    assert.commandWorked(primary.adminCommand(
        {setDefaultRWConcern: 1, defaultWriteConcern: {w: 1}, writeConcern: {w: 1}}));

    // Reconfigure primary with a small cache size so less data needs to be
    // inserted to make the cache full while trying to trigger a stall.
    assert.commandWorked(primary.adminCommand(
        {setParameter: 1, "wiredTigerEngineRuntimeConfig": "cache_size=100MB"}));

    var coll = primary.getCollection("test.coll");
    var bigstr = "a".repeat(4000);

    // Do not insert with a writeConcern because we want the delayed secondary
    // to fall behind in replication. This is crucial apart from having a
    // readConcern to pin updates in memory on the primary. To prevent the
    // slave from falling off the oplog, we configure the oplog large enough
    // to accomodate all the inserts.
    for (var i = 0; i < 250; i++) {
        let batch = coll.initializeUnorderedBulkOp();
        for (var j = 0; j < 100; j++) {
            batch.insert({a: bigstr});
        }
        assert.commandWorked(batch.execute());
    }
    rst.stopSet();
}
})();