diff options
author | Faustoleyva54 <fausto.leyva@mongodb.com> | 2023-03-02 21:42:02 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-03-13 15:44:40 +0000 |
commit | 28aaaddf78d62a02ee39fe29aa4f50c94bc38ec5 (patch) | |
tree | 73898033c0507f1fbbf32af881c4bfe764197fe2 | |
parent | e1e07f94dba858ec629172b060d321ef113c21fb (diff) | |
download | mongo-r6.3.0-rc1.tar.gz |
SERVER-74507 Gracefully handle empty time-series options in collModr6.3.0-rc1
(cherry picked from commit 5035fde474f8aadfd50dc39d8a6e8619d97cb33f)
3 files changed, 33 insertions, 0 deletions
diff --git a/jstests/core/timeseries/timeseries_collmod.js b/jstests/core/timeseries/timeseries_collmod.js index 2d4888690e3..18ae48a421f 100644 --- a/jstests/core/timeseries/timeseries_collmod.js +++ b/jstests/core/timeseries/timeseries_collmod.js @@ -211,5 +211,8 @@ if (TimeseriesTest.timeseriesScalabilityImprovementsEnabled(db.getMongo())) { "timeseries": {"bucketMaxSpanSeconds": bucketingValueMax, "bucketRoundingSeconds": bucketingValueMax} })); + + // No-op command should succeed with empty time-series options. + assert.commandWorked(db.runCommand({"collMod": collName, "timeseries": {}})); } })(); diff --git a/jstests/noPassthrough/sharded_timeseries_bucketing_parameters_downgrade.js b/jstests/noPassthrough/sharded_timeseries_bucketing_parameters_downgrade.js index 4f58f1717c9..0926e372be9 100644 --- a/jstests/noPassthrough/sharded_timeseries_bucketing_parameters_downgrade.js +++ b/jstests/noPassthrough/sharded_timeseries_bucketing_parameters_downgrade.js @@ -36,6 +36,11 @@ function useBucketingParametersOnLowerFCV() { } })); + // On the latestFCV, we should not be able to use collMod with incomplete bucketing parameters. + assert.commandFailedWithCode( + db.runCommand({collMod: collName, timeseries: {bucketMaxSpanSeconds: 3600}}), + ErrorCodes.InvalidOptions); + // We should fail to downgrade if we have a collection with custom bucketing parameters set. assert.commandFailedWithCode(db.adminCommand({setFeatureCompatibilityVersion: lastLTSFCV}), ErrorCodes.CannotDowngrade); @@ -66,6 +71,23 @@ function useBucketingParametersOnLowerFCV() { timeseries: {bucketMaxSpanSeconds: 3600, bucketRoundingSeconds: 3600} }), ErrorCodes.InvalidOptions); + assert.commandFailedWithCode( + db.runCommand({collMod: collName, timeseries: {bucketMaxSpanSeconds: 3600}}), + ErrorCodes.InvalidOptions); + assert.commandFailedWithCode( + db.runCommand({collMod: collName, timeseries: {bucketRoundingSeconds: 3600}}), + ErrorCodes.InvalidOptions); + + // Verify the time-series options are valid. + let collections = assert.commandWorked(db.runCommand({listCollections: 1})).cursor.firstBatch; + let collectionEntry = collections.find(entry => entry.name === 'system.buckets.' + collName); + assert(collectionEntry); + + assert.eq(collectionEntry.options.timeseries.granularity, "seconds"); + // Downgrading does not remove the 'bucketMaxSpanSeconds' parameter. It should correspond with + // the "seconds" granularity. + assert.eq(collectionEntry.options.timeseries.bucketMaxSpanSeconds, 3600); + assert.isnull(collectionEntry.options.timeseries.bucketRoundingSeconds); } useBucketingParametersOnLowerFCV(); diff --git a/src/mongo/db/timeseries/timeseries_options.cpp b/src/mongo/db/timeseries/timeseries_options.cpp index d3d9b3693d0..d384f662a99 100644 --- a/src/mongo/db/timeseries/timeseries_options.cpp +++ b/src/mongo/db/timeseries/timeseries_options.cpp @@ -59,6 +59,14 @@ Status isTimeseriesGranularityValidAndUnchanged(const TimeseriesOptions& current bool allowSecondsParameters = feature_flags::gTimeseriesScalabilityImprovements.isEnabled( serverGlobalParams.featureCompatibility); + // If the timeseries options are completely empty, we can skip updating them. + if (!targetGranularity.has_value() && !targetOptions.getBucketMaxSpanSeconds().has_value() && + !targetOptions.getBucketRoundingSeconds().has_value()) { + if (shouldUpdateOptions) + *shouldUpdateOptions = false; + return Status::OK(); + } + if (shouldUpdateOptions) { *shouldUpdateOptions = true; } |