yiguolei commented on code in PR #28940: URL: https://github.com/apache/doris/pull/28940#discussion_r1437574743
########## be/src/runtime/memory/lru_cache_policy.h: ########## @@ -34,22 +36,62 @@ struct LRUCacheValueBase { // Base of lru cache, allow prune stale entry and prune all entry. class LRUCachePolicy : public CachePolicy { public: - LRUCachePolicy(CacheType type, uint32_t stale_sweep_time_s) - : CachePolicy(type, stale_sweep_time_s) {}; + LRUCachePolicy(CacheType type, uint32_t stale_sweep_time_s, bool enable_prune = true) + : CachePolicy(type, stale_sweep_time_s, enable_prune) {}; LRUCachePolicy(CacheType type, size_t capacity, LRUCacheType lru_cache_type, - uint32_t stale_sweep_time_s, uint32_t num_shards = -1) - : CachePolicy(type, stale_sweep_time_s) { - _cache = num_shards == -1 - ? std::unique_ptr<Cache>( - new ShardedLRUCache(type_string(type), capacity, lru_cache_type)) - : std::unique_ptr<Cache>(new ShardedLRUCache(type_string(type), capacity, - lru_cache_type, num_shards)); + uint32_t stale_sweep_time_s, uint32_t num_shards = DEFAULT_LRU_CACHE_NUM_SHARDS, + bool enable_prune = true) + : CachePolicy(type, stale_sweep_time_s, enable_prune) { + init(capacity, lru_cache_type, num_shards); + } + + bool prepare(size_t capacity, uint32_t num_shards) { + CHECK(!_is_init); + if (capacity < num_shards) { + LOG(INFO) << fmt::format( + "{} lru cache capacity({} B) less than num_shards({}), init failed, will be " + "disabled.", + type_string(type()), capacity, num_shards); + _enable_prune = false; + return false; + } + _is_init = true; Review Comment: 为啥在prepare 里更新 is_init=true? 而不是在init里? 这yang很混乱。 -- 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