diff options
-rw-r--r-- | jstests/multiVersion/targetedTestsLastLtsFeatures/partial_indexes_downgrade.js | 58 | ||||
-rw-r--r-- | src/mongo/db/commands/set_feature_compatibility_version_command.cpp | 5 |
2 files changed, 28 insertions, 35 deletions
diff --git a/jstests/multiVersion/targetedTestsLastLtsFeatures/partial_indexes_downgrade.js b/jstests/multiVersion/targetedTestsLastLtsFeatures/partial_indexes_downgrade.js index 4aab34fb17d..700354bdfb1 100644 --- a/jstests/multiVersion/targetedTestsLastLtsFeatures/partial_indexes_downgrade.js +++ b/jstests/multiVersion/targetedTestsLastLtsFeatures/partial_indexes_downgrade.js @@ -6,45 +6,39 @@ 'use strict'; const dbpath = MongoRunner.dataPath + 'partial_indexes_downgrade'; +resetDbpath(dbpath); -function runTest(targetFCV) { - resetDbpath(dbpath); +// Start with 6.0, create a partial index with an $or, then make sure we fail to downgrade FCV +// to 5.0. Drop the index, then actually downgrade to 5.0. +{ + const conn = + MongoRunner.runMongod({dbpath: dbpath, binVersion: 'latest', noCleanData: true}); - // Start with 6.0, create a partial index with an $or, then make sure we fail to downgrade FCV - // to 5.x. Drop the index, then actually downgrade to 5.x. - { - const conn = - MongoRunner.runMongod({dbpath: dbpath, binVersion: 'latest', noCleanData: true}); + const db = conn.getDB('test'); + const coll = db['partial_indexes_downgrade']; + assert.commandWorked(coll.createIndex( + {a: 1, b: 1}, {partialFilterExpression: {$or: [{a: {$lt: 20}}, {b: {$lt: 10}}]}})); - const db = conn.getDB('test'); - const coll = db['partial_indexes_downgrade']; - assert.commandWorked(coll.createIndex( - {a: 1, b: 1}, {partialFilterExpression: {$or: [{a: {$lt: 20}}, {b: {$lt: 10}}]}})); + coll.insert({a: 1, b: 1}); + coll.insert({a: 30, b: 20}); - coll.insert({a: 1, b: 1}); - coll.insert({a: 30, b: 20}); + assert.commandFailedWithCode(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}), + ErrorCodes.CannotDowngrade); + coll.dropIndexes(); + assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV})); - assert.commandFailedWithCode(db.adminCommand({setFeatureCompatibilityVersion: targetFCV}), - ErrorCodes.CannotDowngrade); - coll.dropIndexes(); - assert.commandWorked(db.adminCommand({setFeatureCompatibilityVersion: targetFCV})); - - MongoRunner.stopMongod(conn); - } + MongoRunner.stopMongod(conn); +} - // Startup with 5.x binary, with FCV set to 5.x. - { - const conn = MongoRunner.runMongod({dbpath: dbpath, binVersion: targetFCV, noCleanData: true}); +// Startup with 5.0 binary, with FCV set to 5.0. +{ + const conn = MongoRunner.runMongod({dbpath: dbpath, binVersion: lastLTSFCV, noCleanData: true}); - const db = conn.getDB('test'); - const coll = db['partial_indexes_downgrade']; - // Make sure we are on the same db path as before. - assert.eq(coll.aggregate().toArray().length, 2); + const db = conn.getDB('test'); + const coll = db['partial_indexes_downgrade']; + // Make sure we are on the same db path as before. + assert.eq(coll.aggregate().toArray().length, 2); - MongoRunner.stopMongod(conn); - } + MongoRunner.stopMongod(conn); } - -runTest(lastLTSFCV); -runTest(lastContinuousFCV); })();
\ No newline at end of file diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index bb73916d87f..883fd3d0edf 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -746,7 +746,7 @@ private: // (Generic FCV reference): TODO SERVER-60912: When kLastLTS is 6.0, remove this FCV-gated // downgrade code. - if (!feature_flags::gTimeseriesMetricIndexes.isEnabledOnVersion(requestedVersion)) { + if (requestedVersion == multiversion::GenericFCV::kLastLTS) { for (const auto& tenantDbName : DatabaseHolder::get(opCtx)->getNames()) { const auto& dbName = tenantDbName.dbName(); Lock::DBLock dbLock(opCtx, dbName, MODE_IX); @@ -762,8 +762,7 @@ private: // in 5.2 and up. If the user tries to downgrade the cluster to an // earlier version, they must first remove all incompatible secondary // indexes on time-series measurements. - if (requestedVersion == multiversion::GenericFCV::kLastLTS && - collection->getTimeseriesOptions()) { + if (collection->getTimeseriesOptions()) { uassert( ErrorCodes::CannotDowngrade, str::stream() |