diff options
author | Arun Banala <arun.banala@mongodb.com> | 2021-06-08 10:40:21 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-14 23:42:16 +0000 |
commit | 74a022074f4cd1cffa2a2140162d0e238a6ddbc3 (patch) | |
tree | c0743662d4053d0bcca859aa9fa646b1c5629e48 /src/mongo/db/timeseries | |
parent | ed83e49f6388e1c1260b610aff0c54fdd66389c9 (diff) | |
download | mongo-74a022074f4cd1cffa2a2140162d0e238a6ddbc3.tar.gz |
SERVER-57315 Enable shardCollection command for a time series collection
(cherry picked from commit 01fc797a67eeb398f90af39f22e55fb1a243298b)
Diffstat (limited to 'src/mongo/db/timeseries')
4 files changed, 35 insertions, 4 deletions
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 5909670ff08..dccdbbf3893 100644 --- a/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.cpp +++ b/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.cpp @@ -42,8 +42,10 @@ namespace mongo { namespace timeseries { -StatusWith<BSONObj> createBucketsIndexSpecFromTimeseriesIndexSpec( - const TimeseriesOptions& timeseriesOptions, const BSONObj& timeseriesIndexSpecBSON) { +namespace { +StatusWith<BSONObj> createBucketsSpecFromTimeseriesSpec(const TimeseriesOptions& timeseriesOptions, + const BSONObj& timeseriesIndexSpecBSON, + bool isShardKeySpec) { auto timeField = timeseriesOptions.getTimeField(); auto metaField = timeseriesOptions.getMetaField(); @@ -68,8 +70,10 @@ StatusWith<BSONObj> createBucketsIndexSpecFromTimeseriesIndexSpec( if (elem.number() >= 0) { builder.appendAs( elem, str::stream() << timeseries::kControlMinFieldNamePrefix << timeField); - builder.appendAs( - elem, str::stream() << timeseries::kControlMaxFieldNamePrefix << timeField); + if (!isShardKeySpec) { + builder.appendAs( + elem, str::stream() << timeseries::kControlMaxFieldNamePrefix << timeField); + } } else { builder.appendAs( elem, str::stream() << timeseries::kControlMaxFieldNamePrefix << timeField); @@ -112,6 +116,17 @@ StatusWith<BSONObj> createBucketsIndexSpecFromTimeseriesIndexSpec( return builder.obj(); } +} // namespace + +StatusWith<BSONObj> createBucketsIndexSpecFromTimeseriesIndexSpec( + const TimeseriesOptions& timeseriesOptions, const BSONObj& timeseriesIndexSpecBSON) { + return createBucketsSpecFromTimeseriesSpec(timeseriesOptions, timeseriesIndexSpecBSON, false); +} + +StatusWith<BSONObj> createBucketsShardKeySpecFromTimeseriesShardKeySpec( + const TimeseriesOptions& timeseriesOptions, const BSONObj& timeseriesShardKeySpecBSON) { + return createBucketsSpecFromTimeseriesSpec(timeseriesOptions, timeseriesShardKeySpecBSON, true); +} boost::optional<BSONObj> createTimeseriesIndexSpecFromBucketsIndexSpec( const TimeseriesOptions& timeseriesOptions, const BSONObj& bucketsIndexSpecBSON) { 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 4fbb9c6139e..3fa88e09a58 100644 --- a/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.h +++ b/src/mongo/db/timeseries/timeseries_index_schema_conversion_functions.h @@ -52,6 +52,9 @@ namespace timeseries { StatusWith<BSONObj> createBucketsIndexSpecFromTimeseriesIndexSpec( const TimeseriesOptions& timeseriesOptions, const BSONObj& timeseriesIndexSpecBSON); +StatusWith<BSONObj> createBucketsShardKeySpecFromTimeseriesShardKeySpec( + const TimeseriesOptions& timeseriesOptions, const BSONObj& timeseriesIndexSpecBSON); + /** * Maps the buckets collection index spec 'bucketsIndexSpecBSON' to the index schema of the * time-series collection using the information provided in 'timeseriesOptions'. diff --git a/src/mongo/db/timeseries/timeseries_options.cpp b/src/mongo/db/timeseries/timeseries_options.cpp index 00921c7d34d..81a3fc15cb4 100644 --- a/src/mongo/db/timeseries/timeseries_options.cpp +++ b/src/mongo/db/timeseries/timeseries_options.cpp @@ -117,6 +117,18 @@ int getBucketRoundingSecondsFromGranularity(BucketGranularityEnum granularity) { } MONGO_UNREACHABLE; } +bool optionsAreEqual(const TimeseriesOptions& option1, const TimeseriesOptions& option2) { + const auto option1BucketSpan = option1.getBucketMaxSpanSeconds() + ? *option1.getBucketMaxSpanSeconds() + : getMaxSpanSecondsFromGranularity(option1.getGranularity()); + const auto option2BucketSpan = option2.getBucketMaxSpanSeconds() + ? *option2.getBucketMaxSpanSeconds() + : getMaxSpanSecondsFromGranularity(option2.getGranularity()); + return option1.getTimeField() == option1.getTimeField() && + option1.getMetaField() == option2.getMetaField() && + option1.getGranularity() == option2.getGranularity() && + option1BucketSpan == option2BucketSpan; +} StatusWith<std::pair<TimeseriesOptions, bool>> applyTimeseriesOptionsModifications( const TimeseriesOptions& currentOptions, const BSONObj& mod) { diff --git a/src/mongo/db/timeseries/timeseries_options.h b/src/mongo/db/timeseries/timeseries_options.h index 56361cfbb93..feaf7e3cd33 100644 --- a/src/mongo/db/timeseries/timeseries_options.h +++ b/src/mongo/db/timeseries/timeseries_options.h @@ -63,5 +63,6 @@ StatusWith<std::pair<TimeseriesOptions, bool>> applyTimeseriesOptionsModificatio BSONObj generateViewPipeline(const TimeseriesOptions& options, bool asArray); +bool optionsAreEqual(const TimeseriesOptions& option1, const TimeseriesOptions& option2); } // namespace timeseries } // namespace mongo |