summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/timeseries_insert_idle_bucket_expiration.js
blob: b3360afd188bc1450296b739e6e353c88575b4fc (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
'use strict';

/**
 * Tests concurrent time-series inserts, with enough batches and data to force buckets to be closed
 * due to the memory usage threshold.
 *
 * @tags: [
 *   requires_timeseries,
 *   # Timeseries do not support multi-document transactions with inserts.
 *   does_not_support_transactions,
 * ]
 */

var $config = (function() {
    const timeFieldName = 'time';
    const metaFieldName = 'tag';
    const numDocs = 100;

    function getCollectionName(collName) {
        return jsTestName() + "_" + collName;
    }

    const insert = function(db, collName, tid, ordered) {
        const docs = [];
        for (let i = 0; i < numDocs; ++i) {
            docs.push({
                [timeFieldName]: ISODate(),
                [metaFieldName]: (tid * numDocs) + i,
            });
        }
        assert.commandWorked(db.runCommand({insert: collName, documents: docs, ordered: ordered}));
    };

    const states = {
        init: function(db, collName) {},

        insertOrdered: function(db, collNameSuffix) {
            let collName = getCollectionName(collNameSuffix);
            insert(db, collName, this.tid, true);
        },

        insertUnordered: function(db, collNameSuffix) {
            let collName = getCollectionName(collNameSuffix);
            insert(db, collName, this.tid, false);
        },
    };

    const setup = function(db, collNameSuffix, cluster) {
        let collName = getCollectionName(collNameSuffix);
        cluster.executeOnMongodNodes((db) => {
            assert.commandWorked(db.adminCommand(
                {setParameter: 1, timeseriesIdleBucketExpiryMemoryUsageThreshold: 1024}));
        });

        assert.commandWorked(db.createCollection(
            collName, {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
    };

    const teardown = function(db, collNameSuffix, cluster) {
        let collName = getCollectionName(collNameSuffix);
        const bucketCatalog = db.serverStatus().bucketCatalog;
        if (bucketCatalog !== undefined) {
            jsTestLog(bucketCatalog);
        }
        jsTestLog(db.runCommand({collStats: collName}).timeseries);

        cluster.executeOnMongodNodes((db) => {
            assert.commandWorked(db.adminCommand({
                setParameter: 1,
                timeseriesIdleBucketExpiryMemoryUsageThreshold: 1024 * 1024 * 100,
            }));
        });
    };

    const standardTransition = {
        insertOrdered: 0.5,
        insertUnordered: 0.5,
    };

    const transitions = {
        init: standardTransition,
        insertOrdered: standardTransition,
        insertUnordered: standardTransition,
    };

    return {
        threadCount: 10,
        iterations: 100,
        setup: setup,
        teardown: teardown,
        states: states,
        transitions: transitions,
    };
})();