diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2022-06-08 14:50:34 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-08 16:40:23 +0000 |
commit | cfcaabb06c6e9d42ed3aae805bcfaa0726e4ca9e (patch) | |
tree | 609e6b39e310d2b781c05a5b119442ce8eb83b89 /src/mongo/db/timeseries | |
parent | 1a578ef55d316eb5fec5cc135cf056f6f17ab616 (diff) | |
download | mongo-cfcaabb06c6e9d42ed3aae805bcfaa0726e4ca9e.tar.gz |
SERVER-67086 Fix gTimeseriesMetricIndexes usage
Diffstat (limited to 'src/mongo/db/timeseries')
3 files changed, 20 insertions, 24 deletions
diff --git a/src/mongo/db/timeseries/timeseries_commands_conversion_helper.cpp b/src/mongo/db/timeseries/timeseries_commands_conversion_helper.cpp index be234d0d95f..7b8899a101a 100644 --- a/src/mongo/db/timeseries/timeseries_commands_conversion_helper.cpp +++ b/src/mongo/db/timeseries/timeseries_commands_conversion_helper.cpp @@ -83,12 +83,12 @@ CreateIndexesCommand makeTimeseriesCreateIndexesCommand(OperationContext* opCtx, std::vector<mongo::BSONObj> indexes; for (const auto& origIndex : origIndexes) { BSONObjBuilder builder; - bool isBucketsIndexSpecCompatibleForDowngrade = true; + bool includeOriginalSpec = false; for (const auto& elem : origIndex) { if (elem.fieldNameStringData() == IndexDescriptor::kPartialFilterExprFieldName) { - if (feature_flags::gTimeseriesMetricIndexes.isEnabledAndIgnoreFCV() && - serverGlobalParams.featureCompatibility.isFCVUpgradingToOrAlreadyLatest()) { - isBucketsIndexSpecCompatibleForDowngrade = false; + if (feature_flags::gTimeseriesMetricIndexes.isEnabled( + serverGlobalParams.featureCompatibility)) { + includeOriginalSpec = true; } else { uasserted(ErrorCodes::InvalidOptions, "Partial indexes are not supported on time-series collections"); @@ -195,11 +195,11 @@ CreateIndexesCommand makeTimeseriesCreateIndexesCommand(OperationContext* opCtx, << " Command request: " << redact(origCmd.toBSON({})), bucketsIndexSpecWithStatus.isOK()); - if (!timeseries::isBucketsIndexSpecCompatibleForDowngrade( + if (timeseries::shouldIncludeOriginalSpec( options, BSON(NewIndexSpec::kKeyFieldName << bucketsIndexSpecWithStatus.getValue()))) { - isBucketsIndexSpecCompatibleForDowngrade = false; + includeOriginalSpec = true; } builder.append(NewIndexSpec::kKeyFieldName, @@ -212,12 +212,11 @@ CreateIndexesCommand makeTimeseriesCreateIndexesCommand(OperationContext* opCtx, builder.append(elem); } - if (feature_flags::gTimeseriesMetricIndexes.isEnabledAndIgnoreFCV() && - !isBucketsIndexSpecCompatibleForDowngrade) { + if (feature_flags::gTimeseriesMetricIndexes.isEnabled( + serverGlobalParams.featureCompatibility) && + includeOriginalSpec) { // Store the original user index definition on the transformed index definition for the - // time-series buckets collection if this is a newly supported index type on time-series - // collections. This is to avoid any additional downgrade steps for index types already - // supported in 5.0. + // time-series buckets collection. builder.appendObject(IndexDescriptor::kOriginalSpecFieldName, origIndex.objdata()); } diff --git a/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.cpp b/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.cpp index 83b6e3f6e9d..4dcf9a73eda 100644 --- a/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.cpp +++ b/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.cpp @@ -149,7 +149,8 @@ StatusWith<BSONObj> createBucketsSpecFromTimeseriesSpec(const TimeseriesOptions& // Indexes on measurement fields are only supported when the 'gTimeseriesMetricIndexes' // feature flag is enabled. - if (!feature_flags::gTimeseriesMetricIndexes.isEnabledAndIgnoreFCV()) { + if (!feature_flags::gTimeseriesMetricIndexes.isEnabled( + serverGlobalParams.featureCompatibility)) { auto reason = str::stream(); reason << "Invalid index spec for time-series collection: " << redact(timeseriesIndexSpecBSON) << ". "; @@ -366,7 +367,7 @@ StatusWith<BSONObj> createBucketsShardKeySpecFromTimeseriesShardKeySpec( boost::optional<BSONObj> createTimeseriesIndexFromBucketsIndex( const TimeseriesOptions& timeseriesOptions, const BSONObj& bucketsIndex) { bool timeseriesMetricIndexesFeatureFlagEnabled = - feature_flags::gTimeseriesMetricIndexes.isEnabledAndIgnoreFCV(); + feature_flags::gTimeseriesMetricIndexes.isEnabled(serverGlobalParams.featureCompatibility); if (bucketsIndex.hasField(kOriginalSpecFieldName) && timeseriesMetricIndexesFeatureFlagEnabled) { @@ -406,21 +407,16 @@ std::list<BSONObj> createTimeseriesIndexesFromBucketsIndexes( return indexSpecs; } -bool isBucketsIndexSpecCompatibleForDowngrade(const TimeseriesOptions& timeseriesOptions, - const BSONObj& bucketsIndex) { +bool shouldIncludeOriginalSpec(const TimeseriesOptions& timeseriesOptions, + const BSONObj& bucketsIndex) { if (!bucketsIndex.hasField(kKeyFieldName)) { return false; } - if (bucketsIndex.hasField(kPartialFilterExpressionFieldName)) { - // Partial indexes are not supported in FCV < 5.2. - return false; - } - return createTimeseriesIndexSpecFromBucketsIndexSpec( timeseriesOptions, bucketsIndex.getField(kKeyFieldName).Obj(), - /*timeseriesMetricIndexesFeatureFlagEnabled=*/false) != boost::none; + /*timeseriesMetricIndexesFeatureFlagEnabled=*/false) == boost::none; } bool doesBucketsIndexIncludeMeasurement(OperationContext* opCtx, diff --git a/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.h b/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.h index ad1bb795fd2..144893c0d77 100644 --- a/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.h +++ b/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.h @@ -71,10 +71,11 @@ std::list<BSONObj> createTimeseriesIndexesFromBucketsIndexes( const TimeseriesOptions& timeseriesOptions, const std::list<BSONObj>& bucketsIndexes); /** - * Returns true if the 'bucketsIndex' is compatible for FCV downgrade. + * Returns true if the original index specification should be included when creating an index on the + * time-series buckets collection. */ -bool isBucketsIndexSpecCompatibleForDowngrade(const TimeseriesOptions& timeseriesOptions, - const BSONObj& bucketsIndex); +bool shouldIncludeOriginalSpec(const TimeseriesOptions& timeseriesOptions, + const BSONObj& bucketsIndex); /** * Returns true if 'bucketsIndex' uses a measurement field, excluding the time field. Checks both |