summaryrefslogtreecommitdiff
path: root/jstests/core/batched_multi_deletes.js
diff options
context:
space:
mode:
authorJosef Ahmad <josef.ahmad@mongodb.com>2022-03-24 16:07:41 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-24 18:58:47 +0000
commit16227df086c840630ded6e4304fd25c04b7fac6b (patch)
treed5220bc4c091773de111ed8bf97178fa857640d9 /jstests/core/batched_multi_deletes.js
parent7671b3cca3c5fb1024b8affcafe92c9dfed37280 (diff)
downloadmongo-16227df086c840630ded6e4304fd25c04b7fac6b.tar.gz
SERVER-63047 Make delete batches fully transactional
Diffstat (limited to 'jstests/core/batched_multi_deletes.js')
-rw-r--r--jstests/core/batched_multi_deletes.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/jstests/core/batched_multi_deletes.js b/jstests/core/batched_multi_deletes.js
new file mode 100644
index 00000000000..894c68e8a59
--- /dev/null
+++ b/jstests/core/batched_multi_deletes.js
@@ -0,0 +1,60 @@
+/**
+ * Tests batch-deleting a large range of data.
+ *
+ * @tags: [
+ * does_not_support_retryable_writes,
+ * # TODO (SERVER-55909): make WUOW 'groupOplogEntries' the only mode of operation.
+ * does_not_support_transactions,
+ * multiversion_incompatible,
+ * requires_fcv_60,
+ * requires_getmore,
+ * requires_non_retryable_writes,
+ * # TODO (SERVER-63044): namespace for this test is hardcoded, tenant migrations rename it.
+ * tenant_migration_incompatible,
+ * ]
+ */
+
+(function() {
+"use strict";
+
+function populateAndMassDelete(queryPredicate) {
+ // '__internalBatchedDeletesTesting.Collection0' is a special, hardcoded namespace that batches
+ // multi-doc deletes if the 'internalBatchUserMultiDeletesForTest' server parameter is set.
+ // TODO (SERVER-63044): remove this special handling.
+ const testDB = db.getSiblingDB('__internalBatchedDeletesTesting');
+ const coll = testDB['Collection0'];
+
+ const collCount =
+ 54321; // Intentionally not a multiple of BatchedDeleteStageBatchParams::targetBatchDocs.
+
+ coll.drop();
+ assert.commandWorked(coll.insertMany([...Array(collCount).keys()].map(x => ({_id: x, a: x}))));
+
+ assert.eq(collCount, coll.find().itcount());
+
+ // Verify the delete will involve the BATCHED_DELETE stage.
+ const expl = testDB.runCommand({
+ explain: {delete: coll.getName(), deletes: [{q: {_id: {$gte: 0}}, 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.find().itcount());
+ assert.commandWorked(coll.deleteMany(queryPredicate));
+ assert.eq(0, coll.find().itcount());
+}
+
+populateAndMassDelete({_id: {$gte: 0}});
+populateAndMassDelete({a: {$gte: 0}});
+})();