HappenLee commented on code in PR #36235: URL: https://github.com/apache/doris/pull/36235#discussion_r1644643785
########## be/src/runtime/memory/lru_cache_policy.h: ########## @@ -208,6 +195,116 @@ class LRUCachePolicy : public CachePolicy { } } +protected: + // if check_capacity failed, will return dummy lru cache, + // compatible with ShardedLRUCache usage, but will not actually cache. + std::shared_ptr<Cache> _cache; + LRUCacheType _lru_cache_type; +}; + +class LRUCachePolicyTrackingAllocator : public LRUCachePolicy { +public: + LRUCachePolicyTrackingAllocator( + CacheType type, size_t capacity, LRUCacheType lru_cache_type, + uint32_t stale_sweep_time_s, uint32_t num_shards = DEFAULT_LRU_CACHE_NUM_SHARDS, + uint32_t element_count_capacity = DEFAULT_LRU_CACHE_ELEMENT_COUNT_CAPACITY, + bool enable_prune = true) + : LRUCachePolicy(type, capacity, lru_cache_type, stale_sweep_time_s, num_shards, + element_count_capacity, enable_prune) { + init_mem_tracker(lru_cache_type_string(lru_cache_type)); + } + + LRUCachePolicyTrackingAllocator(CacheType type, size_t capacity, LRUCacheType lru_cache_type, + uint32_t stale_sweep_time_s, uint32_t num_shards, + uint32_t element_count_capacity, + CacheValueTimeExtractor cache_value_time_extractor, + bool cache_value_check_timestamp, bool enable_prune = true) + : LRUCachePolicy(type, capacity, lru_cache_type, stale_sweep_time_s, num_shards, + element_count_capacity, cache_value_time_extractor, + cache_value_check_timestamp, enable_prune) { + init_mem_tracker(lru_cache_type_string(lru_cache_type)); + } + + ~LRUCachePolicyTrackingAllocator() override { reset_cache(); } + + void init_mem_tracker(const std::string& type_name) { Review Comment: should be private `_init_mem_tracker` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org