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

/**
 * reindex_background.js
 *
 * Bulk inserts 1000 documents and builds indexes in background, then alternates between reindexing
 * and querying against the collection. Operates on a separate collection for each thread. Note
 * that because indexes are initially built in the background, reindexing is also done in the 
 * background.
 */

load('jstests/concurrency/fsm_libs/extend_workload.js'); // for extendWorkload
load('jstests/concurrency/fsm_workloads/reindex.js'); // for $config

var $config = extendWorkload($config, function($config, $super) {
    $config.data.prefix = 'reindex_background';

    $config.states.createIndexes = function createIndexes(db, collName) {
        var coll = db[this.threadCollName];

        // The number of indexes created here is also stored in data.nIndexes
        var textResult = coll.ensureIndex({ text: 'text' }, { background: true });
        assertAlways.commandWorked(textResult);

        var geoResult = coll.ensureIndex({ geo: '2dsphere' }, { background: true });
        assertAlways.commandWorked(geoResult);

        var integerResult = coll.ensureIndex({ integer: 1 }, {background: true });
        assertAlways.commandWorked(integerResult);
    };

    return $config;
});