diff options
author | Alexander Ignatyev <alexander.ignatyev@mongodb.com> | 2021-11-03 13:34:30 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-03 14:17:31 +0000 |
commit | aebaaf20a7dea071770976aed8533f011c722b8c (patch) | |
tree | cea93e4b21410c5e1186af1d8349afd5b6a33623 /src/mongo/db/query/sbe_plan_cache.cpp | |
parent | 14cd3f8d8d89a2bdc33374f80ed04d1e326f8fc6 (diff) | |
download | mongo-aebaaf20a7dea071770976aed8533f011c722b8c.tar.gz |
SERVER-60066 Remove plan cache entries on collection drop
Diffstat (limited to 'src/mongo/db/query/sbe_plan_cache.cpp')
-rw-r--r-- | src/mongo/db/query/sbe_plan_cache.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/db/query/sbe_plan_cache.cpp b/src/mongo/db/query/sbe_plan_cache.cpp index 6dc300e846a..07d904b1506 100644 --- a/src/mongo/db/query/sbe_plan_cache.cpp +++ b/src/mongo/db/query/sbe_plan_cache.cpp @@ -31,6 +31,7 @@ #include "mongo/db/query/sbe_plan_cache.h" +#include "mongo/db/query/plan_cache_invalidator.h" #include "mongo/db/query/plan_cache_size_parameter.h" #include "mongo/db/server_options.h" #include "mongo/logv2/log.h" @@ -42,6 +43,18 @@ namespace { const auto sbePlanCacheDecoration = ServiceContext::declareDecoration<std::unique_ptr<sbe::PlanCache>>(); +class SbePlanCacheInvalidatorCallback final : public PlanCacheInvalidatorCallback { +public: + SbePlanCacheInvalidatorCallback(ServiceContext* serviceCtx) : _serviceCtx{serviceCtx} {} + + void invalidateCacheEntriesWith(UUID collectionUuid, size_t oldVersion) override { + clearPlanCache(_serviceCtx, collectionUuid, oldVersion); + } + +private: + ServiceContext* _serviceCtx; +}; + size_t convertToSizeInBytes(const plan_cache_util::PlanCacheSizeParameter& param) { constexpr size_t kBytesInMB = 1014 * 1024; constexpr size_t kMBytesInGB = 1014; @@ -116,6 +129,8 @@ ServiceContext::ConstructorActionRegisterer planCacheRegisterer{ plan_cache_util::sbePlanCacheSizeUpdaterDecoration(serviceCtx) = std::make_unique<PlanCacheSizeUpdaterImpl>(); + PlanCacheInvalidatorCallback::set( + serviceCtx, std::make_unique<SbePlanCacheInvalidatorCallback>(serviceCtx)); if (feature_flags::gFeatureFlagSbePlanCache.isEnabledAndIgnoreFCV()) { auto status = plan_cache_util::PlanCacheSizeParameter::parse(planCacheSize.get()); uassertStatusOK(status); @@ -142,4 +157,21 @@ sbe::PlanCache& getPlanCache(OperationContext* opCtx) { tassert(5933400, "Cannot get the global SBE plan cache by a nullptr", opCtx); return getPlanCache(opCtx->getServiceContext()); } + +void clearPlanCache(ServiceContext* serviceCtx, UUID collectionUuid, size_t collectionVersion) { + if (feature_flags::gFeatureFlagSbePlanCache.isEnabledAndIgnoreFCV()) { + auto removed = sbe::getPlanCache(serviceCtx) + .removeIf([&collectionUuid, collectionVersion](const PlanCacheKey& key) { + return key.getCollectionVersion() == collectionVersion && + key.getCollectionUuid() == collectionUuid; + }); + + LOGV2_DEBUG(6006600, + 1, + "Clearing SBE Plan Cache", + "collectionUuid"_attr = collectionUuid, + "collectionVersion"_attr = collectionVersion, + "removedEntries"_attr = removed); + } +} } // namespace mongo::sbe |