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

/**
 * Executes the create_index_background.js workload, but with a partial filter expression on the
 * indexed field.
 *
 * @tags: [
 *   assumes_balancer_off,
 *   creates_background_indexes
 * ]
 */
load('jstests/concurrency/fsm_libs/extend_workload.js');               // For extendWorkload.
load('jstests/concurrency/fsm_workloads/create_index_background.js');  // For $config.

var $config = extendWorkload($config, function($config, $super) {
    const fieldName = "isIndexed";

    $config.data.getIndexSpec = function() {
        return {[fieldName]: 1};
    };

    $config.data.getPartialFilterExpression = function() {
        return {[fieldName]: 1};
    };

    $config.data.extendUpdateExpr = function extendUpdateExpr(updateExpr) {
        // Set the field so that it may change whether or not it still applies to the partial index.
        updateExpr['$set'] = {[fieldName]: Random.randInt(2)};
        return updateExpr;
    };

    $config.data.extendDocument = function extendDocument(originalDoc) {
        // Be sure we're not overwriting an existing field.
        assertAlways.eq(originalDoc.hasOwnProperty(fieldName), false);

        // Create documents so that about half are indexed by applying to the partial filter
        // expression.
        originalDoc[fieldName] = Random.randInt(2);
        return originalDoc;
    };

    $config.setup = function setup() {
        $super.setup.apply(this, arguments);
    };

    return $config;
});