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

/**
 * view_catalog_direct_system_writes.js
 *
 * Extends 'view_catalog.js' in concurrently creating, modifying and dropping view namespaces, but
 * does so via direct writes to system.views instead of using the collMod or drop commands. Each
 * worker operates on their own view, built on a shared underlying collection.
 */
load('jstests/concurrency/fsm_libs/extend_workload.js');    // for extendWorkload
load('jstests/concurrency/fsm_workloads/view_catalog.js');  // for $config

var $config = extendWorkload($config, function($config, $super) {
    $config.states.create = function create(db, collName) {
        this.counter++;
        let pipeline = [{$match: {_id: this.counter}}];
        assertAlways.commandWorked(db.system.views.insert({
            _id: db.getName() + "." + this.threadViewName,
            viewOn: this.threadCollName,
            pipeline: pipeline
        }));
        this.confirmViewDefinition(db, this.threadViewName, collName, pipeline, this.counter);
    };

    $config.states.drop = function drop(db, collName) {
        assertAlways.commandWorked(
            db.system.views.deleteOne({_id: db.getName() + "." + this.threadViewName}));

        let res = db.runCommand({listCollections: 1, filter: {name: this.threadViewName}});
        assertAlways.commandWorked(res);
        assertAlways.eq(0, res.cursor.firstBatch.length, tojson(res));
    };

    // Unfortunately we cannot perform an update in the place of a collMod since the update would
    // contain a $-prefixed field (the $match from the pipeline, and so would be rejected by the
    // update system. This is okay, the drop override below is enough to reproduce the issue seen in
    // SERVER-37283. Because of this, we modify the transitions to favor going to drop more often.
    $config.transitions = {
        init: {create: 1},
        create: {modify: 0.5, drop: 0.5},
        modify: {modify: 0.3, drop: 0.7},
        drop: {create: 1}
    };

    return $config;
});