diff options
Diffstat (limited to 'src/mongo/db/catalog/coll_mod.cpp')
| -rw-r--r-- | src/mongo/db/catalog/coll_mod.cpp | 58 |
1 files changed, 40 insertions, 18 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 3bb76fee38b..2c9f03053d0 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -118,6 +118,7 @@ struct ParsedCollModRequest { bool dryRun = false; boost::optional<long long> cappedSize; boost::optional<long long> cappedMax; + boost::optional<bool> timeseriesBucketsMayHaveMixedSchemaData; }; Status getNotSupportedOnViewError(StringData fieldName) { @@ -400,6 +401,11 @@ StatusWith<std::pair<ParsedCollModRequest, BSONObj>> parseCollModRequest(Operati } if (cmdIndex.getPrepareUnique()) { + // Check if prepareUnique is being set on a time-series collection. + if (isTimeseries) { + return {ErrorCodes::InvalidOptions, + "cannot set 'prepareUnique' for indexes of a time-series collection."}; + } parsed.numModifications++; // Attempting to modify with the same value should be treated as a no-op. if (cmrIndex->idx->prepareUnique() == *cmdIndex.getPrepareUnique() || @@ -605,6 +611,17 @@ StatusWith<std::pair<ParsedCollModRequest, BSONObj>> parseCollModRequest(Operati timeseries->serialize(&subObjBuilder); } + if (auto mixedSchema = cmr.getTimeseriesBucketsMayHaveMixedSchemaData()) { + if (!isTimeseries) { + return getOnlySupportedOnTimeseriesError( + CollMod::kTimeseriesBucketsMayHaveMixedSchemaDataFieldName); + } + + parsed.timeseriesBucketsMayHaveMixedSchemaData = mixedSchema; + oplogEntryBuilder.append(CollMod::kTimeseriesBucketsMayHaveMixedSchemaDataFieldName, + *mixedSchema); + } + if (auto& dryRun = cmr.getDryRun()) { parsed.dryRun = *dryRun; // The dry run option should never be included in a collMod oplog entry. @@ -930,6 +947,11 @@ Status _collModInternal(OperationContext* opCtx, *cmd.getExpireAfterSeconds()); } + if (auto mixedSchema = cmrNew.timeseriesBucketsMayHaveMixedSchemaData) { + coll.getWritableCollection(opCtx)->setTimeseriesBucketsMayHaveMixedSchemaData( + opCtx, mixedSchema); + } + // Handle index modifications. processCollModIndexRequest( opCtx, &coll, cmrNew.indexRequest, &indexCollModInfo, result, mode); @@ -985,24 +1007,24 @@ Status _collModInternal(OperationContext* opCtx, // (Generic FCV reference): TODO SERVER-60912: When kLastLTS is 6.0, remove this FCV-gated // upgrade/downgrade code. const auto currentVersion = serverGlobalParams.featureCompatibility.getVersion(); - if (coll->getTimeseriesOptions() && !coll->getTimeseriesBucketsMayHaveMixedSchemaData() && - (currentVersion == multiversion::GenericFCV::kUpgradingFromLastLTSToLatest || - currentVersion == multiversion::GenericFCV::kLatest)) { - // (Generic FCV reference): While upgrading the FCV from kLastLTS to kLatest, collMod is - // called as part of the upgrade process to add the - // 'timeseriesBucketsMayHaveMixedSchemaData=true' catalog entry flag for time-series - // collections that are missing the flag. This indicates that the time-series collection - // existed in earlier server versions and may have mixed-schema data. - coll.getWritableCollection(opCtx)->setTimeseriesBucketsMayHaveMixedSchemaData(opCtx, - true); - } else if (coll->getTimeseriesBucketsMayHaveMixedSchemaData() && - (currentVersion == multiversion::GenericFCV::kDowngradingFromLatestToLastLTS || - currentVersion == multiversion::GenericFCV::kLastLTS)) { - // (Generic FCV reference): While downgrading the FCV to kLastLTS, collMod is called as - // part of the downgrade process to remove the 'timeseriesBucketsMayHaveMixedSchemaData' - // catalog entry flag for time-series collections that have the flag. - coll.getWritableCollection(opCtx)->setTimeseriesBucketsMayHaveMixedSchemaData( - opCtx, boost::none); + if (coll->getTimeseriesOptions()) { + if (currentVersion == multiversion::GenericFCV::kUpgradingFromLastLTSToLatest) { + // (Generic FCV reference): While upgrading the FCV from kLastLTS to kLatest, + // collMod is called as part of the upgrade process to add the + // 'timeseriesBucketsMayHaveMixedSchemaData=true' catalog entry flag for time-series + // collections that are missing the flag. This indicates that the time-series + // collection existed in earlier server versions and may have mixed-schema data. + coll.getWritableCollection(opCtx)->setTimeseriesBucketsMayHaveMixedSchemaData(opCtx, + true); + } else if (currentVersion == + multiversion::GenericFCV::kDowngradingFromLatestToLastLTS) { + // (Generic FCV reference): While downgrading the FCV to kLastLTS, collMod is called + // as part of the downgrade process to remove the + // 'timeseriesBucketsMayHaveMixedSchemaData' catalog entry flag for time-series + // collections that have the flag. + coll.getWritableCollection(opCtx)->setTimeseriesBucketsMayHaveMixedSchemaData( + opCtx, boost::none); + } } // Only observe non-view collMods, as view operations are observed as operations on the |
