summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/wt_prepare_conflict.js
blob: 67fffd102105cba9ac24409e0109e551d9dd70b8 (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
/**
 * Tests that WT_PREPARE_CONFLICT errors are retried correctly on read operations, but does not test
 * any actual prepare transaction functionality.
 * @tag: [requires_wiredtiger]
 */
(function() {
    "strict";

    let conn = MongoRunner.runMongod();
    let testDB = conn.getDB("test");

    let t = testDB.prepare_conflict;
    t.drop();

    // Test different types of operations: removals, updates, and index operations.
    assert.commandWorked(t.createIndex({x: 1}));
    assert.commandWorked(
        t.createIndex({y: 1}, {partialFilterExpression: {_id: {$gte: 500}}, unique: true}));
    let rand = {"#RAND_INT": [0, 1000]};
    let ops = [
        {op: "remove", ns: t.getFullName(), query: {_id: rand}},
        {op: "findOne", ns: t.getFullName(), query: {_id: rand}},
        {
          op: "update",
          ns: t.getFullName(),
          query: {_id: rand},
          update: {$inc: {x: 1}},
          upsert: true
        },
        {op: "findOne", ns: t.getFullName(), query: {x: rand}},
        {
          op: "update",
          ns: t.getFullName(),
          query: {_id: rand},
          update: {$inc: {y: 1}},
          upsert: true
        },
        {op: "findOne", ns: t.getFullName(), query: {y: rand}},
        {op: "findOne", ns: t.getFullName(), query: {_id: rand}},
    ];

    let seconds = 5;
    let parallel = 5;
    let host = testDB.getMongo().host;

    let benchArgs = {ops, seconds, parallel, host};

    assert.commandWorked(testDB.adminCommand(
        {configureFailPoint: 'WTAlwaysNotifyPrepareConflictWaiters', mode: 'alwaysOn'}));

    assert.commandWorked(testDB.adminCommand(
        {configureFailPoint: 'WTPrepareConflictForReads', mode: {activationProbability: 0.05}}));

    res = benchRun(benchArgs);

    assert.commandWorked(
        testDB.adminCommand({configureFailPoint: 'WTPrepareConflictForReads', mode: "off"}));

    assert.commandWorked(testDB.adminCommand(
        {configureFailPoint: 'WTAlwaysNotifyPrepareConflictWaiters', mode: 'off'}));
    res = t.validate();
    assert(res.valid, tojson(res));
    MongoRunner.stopMongod(conn);
})();