summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorFaustoleyva54 <fausto.leyva@mongodb.com>2022-06-29 20:48:35 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-29 22:29:48 +0000
commita41b6c1bbe7e45fc16ae1438210ec238973ea5f7 (patch)
tree1509793a80dbe52512093e65c80ffbf1d9ab5ab1 /jstests
parent78bbb640d870fae6080f0ade272fd3d60d206e64 (diff)
downloadmongo-a41b6c1bbe7e45fc16ae1438210ec238973ea5f7.tar.gz
SERVER-67144 Prevent downgrade with TTL index on time-series collection
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthrough/timeseries_ttl_index_downgrade.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/jstests/noPassthrough/timeseries_ttl_index_downgrade.js b/jstests/noPassthrough/timeseries_ttl_index_downgrade.js
new file mode 100644
index 00000000000..3f900741727
--- /dev/null
+++ b/jstests/noPassthrough/timeseries_ttl_index_downgrade.js
@@ -0,0 +1,69 @@
+/**
+ * Tests that the cluster cannot be downgraded when there are secondary TTL indexes with partial
+ * filters on time-series present.
+ */
+(function() {
+"use strict";
+
+load("jstests/core/timeseries/libs/timeseries.js");
+load("jstests/libs/feature_flag_util.js"); // For isEnabled.
+
+const conn = MongoRunner.runMongod();
+const db = conn.getDB("test");
+
+if (!FeatureFlagUtil.isEnabled(db, "TimeseriesScalabilityImprovements")) {
+ jsTestLog(
+ "Skipped test as the featureFlagTimeseriesScalabilityImprovements feature flag is not enabled.");
+ MongoRunner.stopMongod(conn);
+ return;
+}
+
+const collName = "timeseries_ttl_index_downgrade";
+const coll = db.getCollection(collName);
+const bucketsColl = db.getCollection("system.buckets." + collName);
+
+const timeFieldName = "tm";
+const metaFieldName = "mm";
+const timeSpec = {
+ [timeFieldName]: 1
+};
+
+assert.commandWorked(db.createCollection(
+ coll.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
+
+function checkIndexForDowngrade(isCompatible) {
+ if (!isCompatible) {
+ assert.commandFailedWithCode(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}),
+ ErrorCodes.CannotDowngrade);
+ assert.commandWorked(coll.dropIndexes("*"));
+ }
+
+ assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}));
+ assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
+}
+
+// Verify that downgrading succeeds on a time-series collection without any indexes.
+checkIndexForDowngrade(true);
+
+// Verify that downgrading succeeds on a time-series collection with a partial index.
+const options = {
+ name: "partialIndexOnMeta",
+ partialFilterExpression: {[metaFieldName]: {$gt: 5}}
+};
+assert.commandWorked(coll.createIndex(timeSpec, options));
+checkIndexForDowngrade(true);
+
+// Verify that downgrading succeeds on a time-series collection created with expireAfterSeconds
+// value.
+coll.drop();
+assert.commandWorked(db.createCollection(
+ coll.getName(),
+ {timeseries: {timeField: timeFieldName, metaField: metaFieldName}, expireAfterSeconds: 3600}));
+checkIndexForDowngrade(true);
+
+// Verify that downgrading fails on a time-series collection with a partial, TTL index.
+assert.commandWorked(coll.createIndex(timeSpec, Object.merge(options, {expireAfterSeconds: 400})));
+checkIndexForDowngrade(false);
+
+MongoRunner.stopMongod(conn);
+}());