diff options
author | Benety Goh <benety@mongodb.com> | 2021-12-01 05:28:23 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-12-01 10:52:08 +0000 |
commit | be633665c662db20301838fd905ca4d5b50cdc12 (patch) | |
tree | f64c151cfbaf336fc5de804c834e2d262be8c651 /src/mongo/db/catalog | |
parent | 5712c40efd2c6908fb562d7e6b1007298047afb5 (diff) | |
download | mongo-be633665c662db20301838fd905ca4d5b50cdc12.tar.gz |
SERVER-61800 remove ParsedCollModRequest::clusteredIndexExpireAfterSeconds in favor of CollMod::getExpireAfterSeconds()
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r-- | src/mongo/db/catalog/coll_mod.cpp | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 658a438f392..a62bf76ba6a 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -63,6 +63,7 @@ #include "mongo/logv2/log.h" #include "mongo/util/fail_point.h" #include "mongo/util/version/releases.h" +#include "mongo/util/visit_helper.h" namespace mongo { @@ -105,7 +106,6 @@ struct ParsedCollModRequest { // and ParsedCollModIndexRequest. BSONObj cmdObj; // owned ParsedCollModIndexRequest indexRequest; - BSONElement clusteredIndexExpireAfterSeconds = {}; BSONElement viewPipeLine = {}; std::string viewOn = {}; boost::optional<Collection::Validator> collValidator; @@ -416,7 +416,8 @@ StatusWith<ParsedCollModRequest> parseCollModRequest(OperationContext* opCtx, uassertStatusOK(index_key_validate::validateExpireAfterSeconds(elemNum)); } - cmr.clusteredIndexExpireAfterSeconds = e; + // Access this value through the generated CollMod IDL type. + // See CollModRequest::getExpireAfterSeconds(). } else if (fieldName == CollMod::kTimeseriesFieldName) { cmr.numModifications++; if (!isTimeseries) { @@ -452,43 +453,44 @@ StatusWith<ParsedCollModRequest> parseCollModRequest(OperationContext* opCtx, return {std::move(cmr)}; } -void _setClusteredExpireAfterSeconds(OperationContext* opCtx, - const CollectionOptions& oldCollOptions, - Collection* coll, - const BSONElement& clusteredIndexExpireAfterSeconds) { +void _setClusteredExpireAfterSeconds( + OperationContext* opCtx, + const CollectionOptions& oldCollOptions, + Collection* coll, + const stdx::variant<std::string, std::int64_t>& clusteredIndexExpireAfterSeconds) { invariant(oldCollOptions.clusteredIndex); boost::optional<int64_t> oldExpireAfterSeconds = oldCollOptions.expireAfterSeconds; - if (clusteredIndexExpireAfterSeconds.type() == mongo::String) { - const std::string newExpireAfterSeconds = clusteredIndexExpireAfterSeconds.String(); - invariant(newExpireAfterSeconds == "off"); - if (!oldExpireAfterSeconds) { - // expireAfterSeconds is already disabled on the clustered index. - return; - } - - coll->updateClusteredIndexTTLSetting(opCtx, boost::none); - return; - } + stdx::visit( + visit_helper::Overloaded{ + [&](const std::string& newExpireAfterSeconds) { + invariant(newExpireAfterSeconds == "off"); + if (!oldExpireAfterSeconds) { + // expireAfterSeconds is already disabled on the clustered index. + return; + } - invariant(clusteredIndexExpireAfterSeconds.type() == mongo::NumberLong); - int64_t newExpireAfterSeconds = clusteredIndexExpireAfterSeconds.safeNumberLong(); - if (oldExpireAfterSeconds && *oldExpireAfterSeconds == newExpireAfterSeconds) { - // expireAfterSeconds is already the requested value on the clustered index. - return; - } + coll->updateClusteredIndexTTLSetting(opCtx, boost::none); + }, + [&](std::int64_t newExpireAfterSeconds) { + if (oldExpireAfterSeconds && *oldExpireAfterSeconds == newExpireAfterSeconds) { + // expireAfterSeconds is already the requested value on the clustered index. + return; + } - // If this collection was not previously TTL, inform the TTL monitor when we commit. - if (!oldExpireAfterSeconds) { - auto ttlCache = &TTLCollectionCache::get(opCtx->getServiceContext()); - opCtx->recoveryUnit()->onCommit([ttlCache, uuid = coll->uuid()](auto _) { - ttlCache->registerTTLInfo(uuid, TTLCollectionCache::ClusteredId()); - }); - } + // If this collection was not previously TTL, inform the TTL monitor when we commit. + if (!oldExpireAfterSeconds) { + auto ttlCache = &TTLCollectionCache::get(opCtx->getServiceContext()); + opCtx->recoveryUnit()->onCommit([ttlCache, uuid = coll->uuid()](auto _) { + ttlCache->registerTTLInfo(uuid, TTLCollectionCache::ClusteredId()); + }); + } - invariant(newExpireAfterSeconds >= 0); - coll->updateClusteredIndexTTLSetting(opCtx, newExpireAfterSeconds); + invariant(newExpireAfterSeconds >= 0); + coll->updateClusteredIndexTTLSetting(opCtx, newExpireAfterSeconds); + }}, + clusteredIndexExpireAfterSeconds); } Status _processCollModDryRunMode(OperationContext* opCtx, @@ -613,7 +615,6 @@ Status _collModInternal(OperationContext* opCtx, ParsedCollModRequest cmrNew = std::move(statusW.getValue()); auto viewPipeline = cmrNew.viewPipeLine; auto viewOn = cmrNew.viewOn; - auto clusteredIndexExpireAfterSeconds = cmrNew.clusteredIndexExpireAfterSeconds; auto ts = cmd.getTimeseries(); if (!serverGlobalParams.quiet.load()) { @@ -678,11 +679,9 @@ Status _collModInternal(OperationContext* opCtx, boost::optional<IndexCollModInfo> indexCollModInfo; // Handle collMod operation type appropriately. - if (clusteredIndexExpireAfterSeconds) { - _setClusteredExpireAfterSeconds(opCtx, - oldCollOptions, - coll.getWritableCollection(), - clusteredIndexExpireAfterSeconds); + if (cmd.getExpireAfterSeconds()) { + _setClusteredExpireAfterSeconds( + opCtx, oldCollOptions, coll.getWritableCollection(), *cmd.getExpireAfterSeconds()); } // Handle index modifications. |