summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/update_and_bulk_insert.js
blob: 5d59ff2b0eff636110615ba0bc89be6c842227be (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';

/**
 * update_and_bulk_insert.js
 *
 * Each thread alternates between inserting 100 documents and updating every document in the
 * collection.
 *
 * This workload was designed to test for an issue similar to SERVER-20512 with UpdateStage, where
 * we attempted to make a copy of a record after a WriteConflictException occurred in
 * Collection::updateDocument().
 */
var $config = (function() {

    var states = {
        insert: function insert(db, collName) {
            var bulk = db[collName].initializeUnorderedBulkOp();
            for (var i = 0; i < 100; ++i) {
                bulk.insert({});
            }
            assert.writeOK(bulk.execute());
        },

        update: function update(db, collName) {
            var res = db[collName].update({}, {$inc: {n: 1}}, {multi: true});
            assertAlways.lte(0, res.nMatched, tojson(res));
            if (db.getMongo().writeMode() === 'commands') {
                assertAlways.eq(res.nMatched, res.nModified, tojson(res));
            }
            assertAlways.eq(0, res.nUpserted, tojson(res));
        }
    };

    var transitions = {
        insert: {insert: 0.2, update: 0.8},
        update: {insert: 0.2, update: 0.8}
    };

    return {
        threadCount: 5,
        iterations: 50,
        startState: 'insert',
        states: states,
        transitions: transitions
    };

})();