summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorNikita Lapkov <nikita.lapkov@mongodb.com>2021-10-01 12:46:37 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-05 08:12:39 +0000
commita73cbaa31af52f1f8de9c35f579c69bb384a9501 (patch)
treecb2106208289cd42accaa3b57d3795c5bf462fb0 /jstests
parent9833bf4830fbfba67cbea4a6ae42d58bd6866a6f (diff)
downloadmongo-a73cbaa31af52f1f8de9c35f579c69bb384a9501.tar.gz
SERVER-60285 Add FSM test for deletes on a sharded time-series collection
Diffstat (limited to 'jstests')
-rw-r--r--jstests/concurrency/fsm_workloads/random_moveChunk_timeseries_deletes.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/jstests/concurrency/fsm_workloads/random_moveChunk_timeseries_deletes.js b/jstests/concurrency/fsm_workloads/random_moveChunk_timeseries_deletes.js
new file mode 100644
index 00000000000..d1c95834941
--- /dev/null
+++ b/jstests/concurrency/fsm_workloads/random_moveChunk_timeseries_deletes.js
@@ -0,0 +1,72 @@
+/**
+ * Extends random_moveChunk_timeseries_inserts.js workload with delete stage. Tests deletes in the
+ * presence of concurrent insert and moveChunk commands.
+ * @tags: [
+ * requires_sharding,
+ * assumes_balancer_off,
+ * requires_non_retryable_writes,
+ * ]
+ */
+'use strict';
+
+load('jstests/core/timeseries/libs/timeseries.js'); // For 'TimeseriesTest' helpers.
+// Load parent workload for extending below.
+load('jstests/concurrency/fsm_workloads/random_moveChunk_timeseries_inserts.js');
+
+var $config = extendWorkload($config, function($config, $super) {
+ $config.data.generateMetaFieldValueForInitialInserts = () => {
+ let meta = {};
+ // Insert a document with a field for every thread to test concurrent deletes of the
+ // same document.
+ for (let i = 0; i < $config.threadCount; i++) {
+ meta["tid" + i] = Random.randInt($config.data.numMetaCount);
+ }
+ return meta;
+ };
+
+ $config.data.generateMetaFieldValueForInsertStage = (tid) => {
+ // After the initial stage, each thread will insert documents containing only fields with
+ // this thread's id. This ensures we do not run into concurrency issues with concurrent
+ // inserts and deletes.
+ // NOTE: This problem does not exist for the initial set of documents, since they are
+ // inserted before any delete operation is issued.
+ return {["tid" + tid]: Random.randInt($config.data.numMetaCount)};
+ };
+
+ $config.states.init = function init(db, collName, connCache) {
+ $super.states.init.call(this, db, collName, connCache);
+
+ this.featureFlagDisabled = this.featureFlagDisabled ||
+ !TimeseriesTest.timeseriesUpdatesAndDeletesEnabled(db) ||
+ !TimeseriesTest.shardedTimeseriesUpdatesAndDeletesEnabled(db);
+ if (this.featureFlagDisabled) {
+ jsTestLog(
+ "Skipping executing this test as the requisite feature flags are not enabled.");
+ }
+ };
+
+ $config.states.doDelete = function doDelete(db, collName, connCache) {
+ if (this.featureFlagDisabled) {
+ return;
+ }
+
+ const filter = {
+ m: {
+ ["tid" + this.tid]: {
+ $gte: Random.randInt($config.data.numMetaCount),
+ },
+ },
+ };
+ assertAlways.commandWorked(db[collName].deleteMany(filter));
+ assertAlways.commandWorked(db[this.nonShardCollName].deleteMany(filter));
+ };
+
+ $config.transitions = {
+ init: {insert: 1},
+ insert: {insert: 3, doDelete: 3, moveChunk: 1},
+ doDelete: {insert: 3, doDelete: 3, moveChunk: 1},
+ moveChunk: {insert: 1, doDelete: 1, moveChunk: 0},
+ };
+
+ return $config;
+});