summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorYuhong Zhang <danielzhangyh@gmail.com>2022-02-02 19:33:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-02 20:55:17 +0000
commit806bb2afb2415a2ecc9cc8306e1bfb606a1f74ec (patch)
treea058eca2f3b4609a4dbce839ca2057013cd2ff5b /jstests
parent20254ccae1ac2878d62cb3a3d14afd23021b6c7d (diff)
downloadmongo-806bb2afb2415a2ecc9cc8306e1bfb606a1f74ec.tar.gz
SERVER-63089 Disallow downgrade when the index comment field exists
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthrough/index_comment_downgrade.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/jstests/noPassthrough/index_comment_downgrade.js b/jstests/noPassthrough/index_comment_downgrade.js
new file mode 100644
index 00000000000..2f70d31089a
--- /dev/null
+++ b/jstests/noPassthrough/index_comment_downgrade.js
@@ -0,0 +1,67 @@
+/**
+ * Tests that the cluster cannot be downgraded when there are indexes with the 'comment' field
+ * present.
+ *
+ * TODO SERVER-63171: Update this test once kLastContinuous is 5.3.
+ * TODO SERVER-63172: Remove this test once kLastLTS is 6.0.
+ *
+ * @tags: [requires_fcv_53]
+ */
+(function() {
+"use strict";
+
+const conn = MongoRunner.runMongod();
+const db = conn.getDB("test");
+
+const collModIndexUniqueEnabled = assert
+ .commandWorked(db.getMongo().adminCommand(
+ {getParameter: 1, featureFlagCollModIndexUnique: 1}))
+ .featureFlagCollModIndexUnique.value;
+
+if (!collModIndexUniqueEnabled) {
+ jsTestLog('Skipping test because the collMod unique index feature flag is disabled.');
+ MongoRunner.stopMongod(conn);
+ return;
+}
+
+const collName = "index_comment_downgrade";
+const coll = db.getCollection(collName);
+assert.commandWorked(db.createCollection(coll.getName()));
+
+function checkIndexForDowngrade(withFCV, fixIndex, isCompatible) {
+ assert.commandWorked(coll.createIndex({a: 1}, {comment: {"index_to_be_dropped": 1}}));
+ // TODO SERVER-62971: Add the case to use collMod to remove the 'comment' field.
+ // assert.commandWorked(coll.createIndex({b: 1}, {comment: {"index_to_be_collMod": 1}}));
+
+ if (fixIndex) {
+ // Resolves the incompatibility before the downgrade.
+ assert.commandWorked(coll.dropIndex({a: 1}));
+ // assert.commandWorked(db.runCommand({collMod: collName, index: {keyPattern: {b: 1},
+ // comment: new Object()}}));
+ } else if (!isCompatible) {
+ assert.commandFailedWithCode(db.adminCommand({setFeatureCompatibilityVersion: withFCV}),
+ ErrorCodes.CannotDowngrade);
+ assert.commandWorked(coll.dropIndexes("*"));
+ }
+
+ // Downgrades to the version 'withFCV' and reset to 'latestFCV'.
+ assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: withFCV}));
+ assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: latestFCV}));
+
+ assert.commandWorked(coll.dropIndexes("*"));
+}
+
+// Fails to downgrade to 5.2.
+checkIndexForDowngrade(lastContinuousFCV, false, false);
+
+// Fails to downgrade to 5.0.
+checkIndexForDowngrade(lastLTSFCV, false, false);
+
+// Successfully downgrades to 5.2 after removing the 'comment' field.
+checkIndexForDowngrade(lastContinuousFCV, true, true);
+
+// Successfully downgrades to 5.0 after removing the 'comment' field.
+checkIndexForDowngrade(lastLTSFCV, true, true);
+
+MongoRunner.stopMongod(conn);
+}());