summaryrefslogtreecommitdiff
path: root/jstests/core/batched_multi_deletes.js
blob: 70287f2d6ebb52a5ff5eb9ebf68307ab80007368 (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
/**
 * Tests batch-deleting a large range of data.
 * This test does not rely on getMores on purpose, as this is a requirement for running on
 * tenant migration passthroughs.
 *
 * @tags: [
 *  does_not_support_retryable_writes,
 *  # TODO (SERVER-55909): make WUOW 'groupOplogEntries' the only mode of operation.
 *  does_not_support_transactions,
 *  multiversion_incompatible,
 *  no_selinux,
 *  requires_fcv_61,
 *  requires_non_retryable_writes,
 * ]
 */

(function() {
"use strict";

function populateAndMassDelete(queryPredicate) {
    const testDB = db.getSiblingDB('test');
    const coll = testDB['c'];

    const collCount = 94321;  // Intentionally not a multiple of batchedDeletesTargetBatchDocs.

    coll.drop();
    assert.commandWorked(
        coll.insertMany([...Array(collCount).keys()].map(x => ({_id: x, a: x})), {ordered: false}));

    assert.eq(collCount, coll.countDocuments({}));

    // Verify the delete will involve the BATCHED_DELETE stage.
    const expl = testDB.runCommand({
        explain: {delete: coll.getName(), deletes: [{q: queryPredicate, limit: 0}]},
        verbosity: "executionStats"
    });
    assert.commandWorked(expl);

    if (expl["queryPlanner"]["winningPlan"]["stage"] === "SHARD_WRITE") {
        // This is a sharded cluster. Verify all shards execute the BATCHED_DELETE stage.
        for (let shard of expl["queryPlanner"]["winningPlan"]["shards"]) {
            assert.eq(shard["winningPlan"]["stage"], "BATCHED_DELETE");
        }
    } else {
        // Non-sharded
        assert.eq(expl["queryPlanner"]["winningPlan"]["stage"], "BATCHED_DELETE");
    }

    // Execute and verify the deletion.
    assert.eq(collCount, coll.countDocuments({}));
    assert.commandWorked(coll.deleteMany(queryPredicate));
    assert.eq(null, coll.findOne());
}

populateAndMassDelete({_id: {$gte: 0}});
populateAndMassDelete({a: {$gte: 0}});
})();