summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/multi_delete_in_transaction_large.js
blob: 053becf75fc98d65127eed9b653221b704feae74 (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
// Tests large multi-deletes in a transaction to trigger multi-applyOps transaction commit path.
// @tags: [requires_replication, requires_wiredtiger]
(function() {
"use strict";

load('jstests/libs/auto_retry_transaction_in_sharding.js');

const rst = new ReplSetTest({
    nodes: 1,
    nodeOptions: {
        // Ensure the storage engine cache can accommodate large transactions.
        wiredTigerCacheSizeGB: 3,
    },
});
rst.startSet();
rst.initiate();

// Use an intentionally short collection name to minimize the footprint of operations in the oplog.
const collName = "c";
const dbName = "test";
const testDB = rst.getPrimary().getDB(dbName);
const testColl = testDB[collName];

assert.commandWorked(testDB.createCollection(testColl.getName(), {writeConcern: {w: "majority"}}));

const sessionOptions = {
    causalConsistency: false
};
const session = testDB.getMongo().startSession(sessionOptions);
const sessionDb = session.getDatabase(dbName);
const sessionColl = sessionDb[collName];
const txnOpts = {
    writeConcern: {w: "majority"}
};

// Verify that a large number of small documents can be deleted when the transaction spans multiple
// "applyOps" entries.
jsTest.log("Prepopulate the collection.");
const numberOfDocuments = 256000;
const documents = [...new Array(numberOfDocuments).keys()].map(x => ({_id: x}));
assert.commandWorked(testColl.insert(documents, {writeConcern: {w: "majority"}}));

jsTest.log("Do a large multiple-result multi-delete.");
withTxnAndAutoRetryOnMongos(session, () => {
    // Verify that all documents are removed.
    let res = assert.commandWorked(sessionColl.remove({}, {justOne: false}));
    assert.eq(numberOfDocuments, res.nRemoved);
    res = sessionColl.find({});
    assert.sameMembers(res.toArray(), []);
}, txnOpts);

// Collection should be empty.
assert.eq(0, testColl.countDocuments({}));

rst.stopSet();
}());