summaryrefslogtreecommitdiff
path: root/jstests/replsets/oplog_sampling.js
blob: ff477521dbeb96537785f6c6de801de39d55e17e (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
/**
 * Ensure serverStatus reports the total time spent sampling the oplog for all storage engines that
 * support OplogStones.
 * @tags: [ requires_wiredtiger, requires_persistence ]
 */
(function() {
"use strict";

// Force oplog sampling to occur on start up for small numbers of oplog inserts.
const replSet = new ReplSetTest({
    nodes: 1,
    nodeOptions: {
        setParameter: {
            "maxOplogTruncationPointsDuringStartup": 10,
            logComponentVerbosity: tojson({storage: {verbosity: 2}}),
        }
    }
});
replSet.startSet();
replSet.initiate();

let coll = replSet.getPrimary().getDB("test").getCollection("testcoll");

let res = replSet.getPrimary().getDB("test").serverStatus();
assert.commandWorked(res);

// Small (or empty) oplogs should be processed by scanning.
assert.gt(res.oplogTruncation.totalTimeProcessingMicros, 0);
assert.eq(res.oplogTruncation.processingMethod, "scanning");

// Insert enough documents to force oplog sampling to occur on the following start up.
const maxOplogDocsForScanning = 2000;
for (let i = 0; i < maxOplogDocsForScanning + 1; i++) {
    assert.commandWorked(coll.insert({m: 1 + i}));
}

// Restart replica set to load entries from the oplog for sampling.
replSet.stopSet(null /* signal */, true /* forRestart */);
replSet.startSet({restart: true});

res = replSet.getPrimary().getDB("test").serverStatus();
assert.commandWorked(res);

assert.gt(res.oplogTruncation.totalTimeProcessingMicros, 0);
assert.eq(res.oplogTruncation.processingMethod, "sampling");

replSet.stopSet();
})();