summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2022-06-08 14:50:34 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-08 16:40:23 +0000
commitcfcaabb06c6e9d42ed3aae805bcfaa0726e4ca9e (patch)
tree609e6b39e310d2b781c05a5b119442ce8eb83b89 /src/mongo/db
parent1a578ef55d316eb5fec5cc135cf056f6f17ab616 (diff)
downloadmongo-cfcaabb06c6e9d42ed3aae805bcfaa0726e4ca9e.tar.gz
SERVER-67086 Fix gTimeseriesMetricIndexes usage
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp5
-rw-r--r--src/mongo/db/index/expression_keys_private.cpp5
-rw-r--r--src/mongo/db/server_options.h9
-rw-r--r--src/mongo/db/timeseries/timeseries_commands_conversion_helper.cpp21
-rw-r--r--src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.cpp16
-rw-r--r--src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.h7
6 files changed, 26 insertions, 37 deletions
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index aaf5e7607f2..b102b7fd3e5 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -2166,8 +2166,9 @@ Status CollectionImpl::prepareForIndexBuild(OperationContext* opCtx,
str::stream() << "index " << imd.nameStringData()
<< " is already in current metadata: " << _metadata->toBSON());
- if (getTimeseriesOptions() && feature_flags::gTimeseriesMetricIndexes.isEnabledAndIgnoreFCV() &&
- serverGlobalParams.featureCompatibility.isFCVUpgradingToOrAlreadyLatest() &&
+ if (getTimeseriesOptions() &&
+ feature_flags::gTimeseriesMetricIndexes.isEnabled(
+ serverGlobalParams.featureCompatibility) &&
timeseries::doesBucketsIndexIncludeMeasurement(
opCtx, ns(), *getTimeseriesOptions(), spec->infoObj())) {
invariant(_metadata->timeseriesBucketsMayHaveMixedSchemaData);
diff --git a/src/mongo/db/index/expression_keys_private.cpp b/src/mongo/db/index/expression_keys_private.cpp
index 845e65c4b65..0e8fb0d6208 100644
--- a/src/mongo/db/index/expression_keys_private.cpp
+++ b/src/mongo/db/index/expression_keys_private.cpp
@@ -433,8 +433,9 @@ void ExpressionKeysPrivate::validateDocumentCommon(const CollectionPtr& collecti
const BSONObj& keyPattern) {
// If we have a timeseries collection, check that indexed metric fields do not have expanded
// array values
- if (auto tsOptions = collection->getTimeseriesOptions();
- tsOptions && feature_flags::gTimeseriesMetricIndexes.isEnabledAndIgnoreFCV()) {
+ if (auto tsOptions = collection->getTimeseriesOptions(); tsOptions &&
+ feature_flags::gTimeseriesMetricIndexes.isEnabled(
+ serverGlobalParams.featureCompatibility)) {
// Each user metric field will be included twice, as both control.min.<field> and
// control.max.<field>, so we'll want to keep track that we've checked data.<field> to avoid
// scanning it twice. The time field can be excluded as it is guaranteed to be a date at
diff --git a/src/mongo/db/server_options.h b/src/mongo/db/server_options.h
index 643fe7a46a1..25a69ffa995 100644
--- a/src/mongo/db/server_options.h
+++ b/src/mongo/db/server_options.h
@@ -201,15 +201,6 @@ struct ServerGlobalParams {
version != multiversion::GenericFCV::kLastLTS;
}
- bool isFCVUpgradingToOrAlreadyLatest() const {
- auto currentVersion = getVersion();
-
- // (Generic FCV reference): This FCV reference should exist across LTS binary versions.
- return currentVersion == multiversion::GenericFCV::kUpgradingFromLastLTSToLatest ||
- isGreaterThanOrEqualTo(
- multiversion::GenericFCV::kUpgradingFromLastContinuousToLatest);
- }
-
bool isFCVDowngradingOrAlreadyDowngradedFromLatest() const {
auto currentVersion = getVersion();
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