diff --git a/be/src/cloud/cloud_tablet_mgr.cpp b/be/src/cloud/cloud_tablet_mgr.cpp index 94383ac3d0dec9..854bb29315fe42 100644 --- a/be/src/cloud/cloud_tablet_mgr.cpp +++ b/be/src/cloud/cloud_tablet_mgr.cpp @@ -148,7 +148,9 @@ CloudTabletMgr::CloudTabletMgr(CloudStorageEngine& engine) _tablet_map(std::make_unique()), _cache(std::make_unique( CachePolicy::CacheType::CLOUD_TABLET_CACHE, config::tablet_cache_capacity, - LRUCacheType::NUMBER, 0, config::tablet_cache_shards, false /*enable_prune*/)) {} + LRUCacheType::NUMBER, /*sweep time*/ 0, config::tablet_cache_shards, + /*element_count_capacity*/ 0, /*enable_prune*/ false, + /*is_lru_k*/ false)) {} CloudTabletMgr::~CloudTabletMgr() = default; diff --git a/be/src/cloud/cloud_txn_delete_bitmap_cache.cpp b/be/src/cloud/cloud_txn_delete_bitmap_cache.cpp index a0f3b20142911a..e1d512004159df 100644 --- a/be/src/cloud/cloud_txn_delete_bitmap_cache.cpp +++ b/be/src/cloud/cloud_txn_delete_bitmap_cache.cpp @@ -34,7 +34,9 @@ namespace doris { CloudTxnDeleteBitmapCache::CloudTxnDeleteBitmapCache(size_t size_in_bytes) : LRUCachePolicy(CachePolicy::CacheType::CLOUD_TXN_DELETE_BITMAP_CACHE, size_in_bytes, - LRUCacheType::SIZE, 86400, 4), + LRUCacheType::SIZE, /*stale_sweep_time_s*/ 86400, /*num_shards*/ 4, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is_lru_k*/ false), _stop_latch(1) {} CloudTxnDeleteBitmapCache::~CloudTxnDeleteBitmapCache() { diff --git a/be/src/olap/page_cache.h b/be/src/olap/page_cache.h index f19dff67c32378..308eef8b524702 100644 --- a/be/src/olap/page_cache.h +++ b/be/src/olap/page_cache.h @@ -118,8 +118,8 @@ class StoragePageCache { DataPageCache(size_t capacity, uint32_t num_shards) : LRUCachePolicy(CachePolicy::CacheType::DATA_PAGE_CACHE, capacity, LRUCacheType::SIZE, config::data_page_cache_stale_sweep_time_sec, - num_shards, DEFAULT_LRU_CACHE_ELEMENT_COUNT_CAPACITY, true, true) { - } + num_shards, /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is lru-k*/ true) {} }; class IndexPageCache : public LRUCachePolicy { @@ -127,7 +127,8 @@ class StoragePageCache { IndexPageCache(size_t capacity, uint32_t num_shards) : LRUCachePolicy(CachePolicy::CacheType::INDEXPAGE_CACHE, capacity, LRUCacheType::SIZE, config::index_page_cache_stale_sweep_time_sec, - num_shards) {} + num_shards, /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is lru-k*/ false) {} }; class PKIndexPageCache : public LRUCachePolicy { @@ -135,7 +136,9 @@ class StoragePageCache { PKIndexPageCache(size_t capacity, uint32_t num_shards) : LRUCachePolicy(CachePolicy::CacheType::PK_INDEX_PAGE_CACHE, capacity, LRUCacheType::SIZE, - config::pk_index_page_cache_stale_sweep_time_sec, num_shards) {} + config::pk_index_page_cache_stale_sweep_time_sec, num_shards, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is lru-k*/ false) {} }; static constexpr uint32_t kDefaultNumShards = 16; diff --git a/be/src/olap/rowset/segment_v2/condition_cache.h b/be/src/olap/rowset/segment_v2/condition_cache.h index 68a7dc10a08c93..cc66b20417c4ee 100644 --- a/be/src/olap/rowset/segment_v2/condition_cache.h +++ b/be/src/olap/rowset/segment_v2/condition_cache.h @@ -83,7 +83,9 @@ class ConditionCache : public LRUCachePolicy { ConditionCache(size_t capacity, uint32_t num_shards) : LRUCachePolicy(CachePolicy::CacheType::CONDITION_CACHE, capacity, LRUCacheType::SIZE, - config::inverted_index_cache_stale_sweep_time_sec, num_shards) {} + config::inverted_index_cache_stale_sweep_time_sec, num_shards, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is_lru_k*/ true) {} bool lookup(const CacheKey& key, ConditionCacheHandle* handle); diff --git a/be/src/olap/rowset/segment_v2/inverted_index_cache.h b/be/src/olap/rowset/segment_v2/inverted_index_cache.h index b80f2c01027b6e..64392f6bb51c14 100644 --- a/be/src/olap/rowset/segment_v2/inverted_index_cache.h +++ b/be/src/olap/rowset/segment_v2/inverted_index_cache.h @@ -106,16 +106,17 @@ class InvertedIndexSearcherCache { : LRUCachePolicy(CachePolicy::CacheType::INVERTEDINDEX_SEARCHER_CACHE, capacity, LRUCacheType::SIZE, config::inverted_index_cache_stale_sweep_time_sec, num_shards, - element_count_capacity, true) {} + element_count_capacity, /*enable_prune*/ true, + /*is lru k*/ false) {} InvertedIndexSearcherCachePolicy(size_t capacity, uint32_t num_shards, uint32_t element_count_capacity, CacheValueTimeExtractor cache_value_time_extractor, bool cache_value_check_timestamp) - : LRUCachePolicy(CachePolicy::CacheType::INVERTEDINDEX_SEARCHER_CACHE, capacity, - LRUCacheType::SIZE, - config::inverted_index_cache_stale_sweep_time_sec, num_shards, - element_count_capacity, cache_value_time_extractor, - cache_value_check_timestamp, true) {} + : LRUCachePolicy( + CachePolicy::CacheType::INVERTEDINDEX_SEARCHER_CACHE, capacity, + LRUCacheType::SIZE, config::inverted_index_cache_stale_sweep_time_sec, + num_shards, element_count_capacity, cache_value_time_extractor, + cache_value_check_timestamp, /*enable_prune*/ true, /*is lru k*/ false) {} }; // Insert a cache entry by key. // And the cache entry will be returned in handle. @@ -229,7 +230,9 @@ class InvertedIndexQueryCache : public LRUCachePolicy { InvertedIndexQueryCache(size_t capacity, uint32_t num_shards) : LRUCachePolicy(CachePolicy::CacheType::INVERTEDINDEX_QUERY_CACHE, capacity, LRUCacheType::SIZE, config::inverted_index_cache_stale_sweep_time_sec, - num_shards) {} + num_shards, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is_lru_k*/ true) {} bool lookup(const CacheKey& key, InvertedIndexQueryCacheHandle* handle); diff --git a/be/src/olap/schema_cache.h b/be/src/olap/schema_cache.h index 68cd809ed226f4..3def66a90f5d51 100644 --- a/be/src/olap/schema_cache.h +++ b/be/src/olap/schema_cache.h @@ -87,7 +87,9 @@ class SchemaCache : public LRUCachePolicy { SchemaCache(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::SCHEMA_CACHE, capacity, LRUCacheType::NUMBER, - config::schema_cache_sweep_time_sec) {} + config::schema_cache_sweep_time_sec, /*num shards*/ 32, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is lru-k*/ false) {} private: static constexpr char SCHEMA_DELIMITER = '-'; diff --git a/be/src/olap/segment_loader.h b/be/src/olap/segment_loader.h index 48b3cb17355707..42b0201a1ff89a 100644 --- a/be/src/olap/segment_loader.h +++ b/be/src/olap/segment_loader.h @@ -83,10 +83,11 @@ class SegmentCache : public LRUCachePolicy { }; SegmentCache(size_t memory_bytes_limit, size_t segment_num_limit) - : LRUCachePolicy( - CachePolicy::CacheType::SEGMENT_CACHE, memory_bytes_limit, LRUCacheType::SIZE, - config::tablet_rowset_stale_sweep_time_sec, DEFAULT_LRU_CACHE_NUM_SHARDS * 2, - cast_set(segment_num_limit), config::enable_segment_cache_prune) {} + : LRUCachePolicy(CachePolicy::CacheType::SEGMENT_CACHE, memory_bytes_limit, + LRUCacheType::SIZE, config::tablet_rowset_stale_sweep_time_sec, + /*num shards*/ 64, + /*element count capacity */ cast_set(segment_num_limit), + config::enable_segment_cache_prune, /*is lru-k*/ true) {} // Lookup the given segment in the cache. // If the segment is found, the cache entry will be written into handle. diff --git a/be/src/olap/storage_engine.h b/be/src/olap/storage_engine.h index 0977d66a802939..ecc6504308ba59 100644 --- a/be/src/olap/storage_engine.h +++ b/be/src/olap/storage_engine.h @@ -624,7 +624,9 @@ class CreateTabletRRIdxCache : public LRUCachePolicy { CreateTabletRRIdxCache(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::CREATE_TABLET_RR_IDX_CACHE, capacity, LRUCacheType::NUMBER, - /*stale_sweep_time_s*/ 30 * 60, 1) {} + /*stale_sweep_time_s*/ 30 * 60, /*num shards*/ 1, + /*element count capacity */ 0, + /*enable prune*/ true, /*is lru-k*/ false) {} }; struct DirInfo { diff --git a/be/src/olap/tablet_column_object_pool.h b/be/src/olap/tablet_column_object_pool.h index 998ba7a9aa4b5a..8383b805c1f31d 100644 --- a/be/src/olap/tablet_column_object_pool.h +++ b/be/src/olap/tablet_column_object_pool.h @@ -34,7 +34,10 @@ class TabletColumnObjectPool : public LRUCachePolicy { public: TabletColumnObjectPool(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::TABLET_COLUMN_OBJECT_POOL, capacity, - LRUCacheType::NUMBER, config::tablet_schema_cache_recycle_interval) {} + LRUCacheType::NUMBER, config::tablet_schema_cache_recycle_interval, + /*num_shards*/ 32, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is_lru_k*/ false) {} static TabletColumnObjectPool* create_global_column_cache(size_t capacity) { auto* res = new TabletColumnObjectPool(capacity); diff --git a/be/src/olap/tablet_meta.cpp b/be/src/olap/tablet_meta.cpp index d60d71b891e6bb..61c6c7508d319d 100644 --- a/be/src/olap/tablet_meta.cpp +++ b/be/src/olap/tablet_meta.cpp @@ -1223,7 +1223,9 @@ static void decode_agg_cache_key(const std::string& key_str, int64_t& tablet_id, DeleteBitmapAggCache::DeleteBitmapAggCache(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::DELETE_BITMAP_AGG_CACHE, capacity, LRUCacheType::SIZE, config::delete_bitmap_agg_cache_stale_sweep_time_sec, - 256) {} + /*num_shards*/ 256, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is_lru_k*/ false) {} DeleteBitmapAggCache* DeleteBitmapAggCache::instance() { return ExecEnv::GetInstance()->delete_bitmap_agg_cache(); diff --git a/be/src/olap/tablet_schema_cache.h b/be/src/olap/tablet_schema_cache.h index e18892a3ca5f06..808b7b4a9cfbbd 100644 --- a/be/src/olap/tablet_schema_cache.h +++ b/be/src/olap/tablet_schema_cache.h @@ -29,7 +29,10 @@ class TabletSchemaCache : public LRUCachePolicy { TabletSchemaCache(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::TABLET_SCHEMA_CACHE, capacity, - LRUCacheType::NUMBER, config::tablet_schema_cache_recycle_interval) {} + LRUCacheType::NUMBER, config::tablet_schema_cache_recycle_interval, + /*num_shards*/ 32, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is_lru_k*/ false) {} static TabletSchemaCache* create_global_schema_cache(size_t capacity) { auto* res = new TabletSchemaCache(capacity); diff --git a/be/src/olap/txn_manager.h b/be/src/olap/txn_manager.h index 7de2d39db1a086..52663fed4d53ab 100644 --- a/be/src/olap/txn_manager.h +++ b/be/src/olap/txn_manager.h @@ -302,8 +302,10 @@ class TxnManager { public: TabletVersionCache(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::TABLET_VERSION_CACHE, capacity, - LRUCacheType::NUMBER, -1, DEFAULT_LRU_CACHE_NUM_SHARDS, - DEFAULT_LRU_CACHE_ELEMENT_COUNT_CAPACITY, false) {} + LRUCacheType::NUMBER, /*sweeptime*/ -1, + /*num_shards*/ 32, + /*element_count_capacity*/ 0, /*enable_prune*/ false, + /*is_lru_k*/ false) {} }; private: diff --git a/be/src/pipeline/query_cache/query_cache.h b/be/src/pipeline/query_cache/query_cache.h index 827c516ad75f07..4ac06bd511670b 100644 --- a/be/src/pipeline/query_cache/query_cache.h +++ b/be/src/pipeline/query_cache/query_cache.h @@ -142,7 +142,9 @@ class QueryCache : public LRUCachePolicy { QueryCache(size_t capacity, uint32_t num_shards) : LRUCachePolicy(CachePolicy::CacheType::QUERY_CACHE, capacity, LRUCacheType::SIZE, - 3600 * 24, num_shards) {} + 3600 * 24, /*num_shards*/ num_shards, + /*element_count_capacity*/ 0, /*enable_prune*/ true, + /*is_lru_k*/ true) {} bool lookup(const CacheKey& key, int64_t version, QueryCacheHandle* handle); diff --git a/be/src/runtime/load_channel_mgr.h b/be/src/runtime/load_channel_mgr.h index 989f2ac0530bcd..3c2b7d015719dc 100644 --- a/be/src/runtime/load_channel_mgr.h +++ b/be/src/runtime/load_channel_mgr.h @@ -91,8 +91,9 @@ class LoadChannelMgr { LoadStateChannelCache(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::LOAD_STATE_CHANNEL_CACHE, capacity, - LRUCacheType::NUMBER, -1, DEFAULT_LRU_CACHE_NUM_SHARDS, - DEFAULT_LRU_CACHE_ELEMENT_COUNT_CAPACITY, false) {} + LRUCacheType::NUMBER, /*sweep time*/ -1, /*num shards*/ 32, + /*element capacity*/ 0, /*enable prune */ false, + /*is lru k*/ false) {} }; using CacheValue = LoadStateChannelCache::CacheValue; diff --git a/be/src/runtime/memory/lru_cache_policy.h b/be/src/runtime/memory/lru_cache_policy.h index ddc3f186e7c933..dd2ebcabbb0b94 100644 --- a/be/src/runtime/memory/lru_cache_policy.h +++ b/be/src/runtime/memory/lru_cache_policy.h @@ -35,9 +35,8 @@ namespace doris { class LRUCachePolicy : public CachePolicy { public: LRUCachePolicy(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, bool is_lru_k = DEFAULT_LRU_CACHE_IS_LRU_K) + uint32_t stale_sweep_time_s, uint32_t num_shards, + uint32_t element_count_capacity, bool enable_prune, bool is_lru_k) : CachePolicy(type, capacity, stale_sweep_time_s, enable_prune), _lru_cache_type(lru_cache_type) { if (check_capacity(capacity, num_shards)) { @@ -55,8 +54,7 @@ class LRUCachePolicy : public CachePolicy { 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, - bool is_lru_k = DEFAULT_LRU_CACHE_IS_LRU_K) + bool cache_value_check_timestamp, bool enable_prune, bool is_lru_k) : CachePolicy(type, capacity, stale_sweep_time_s, enable_prune), _lru_cache_type(lru_cache_type) { if (check_capacity(capacity, num_shards)) { diff --git a/be/src/service/point_query_executor.cpp b/be/src/service/point_query_executor.cpp index 5c5ca44c3e697c..a8f8eadd1f240e 100644 --- a/be/src/service/point_query_executor.cpp +++ b/be/src/service/point_query_executor.cpp @@ -216,7 +216,8 @@ LookupConnectionCache* LookupConnectionCache::create_global_instance(size_t capa RowCache::RowCache(int64_t capacity, int num_shards) : LRUCachePolicy(CachePolicy::CacheType::POINT_QUERY_ROW_CACHE, capacity, LRUCacheType::SIZE, config::point_query_row_cache_stale_sweep_time_sec, - num_shards) {} + num_shards, /*element count capacity */ 0, + /*enable prune*/ true, /*is lru-k*/ true) {} // Create global instance of this class RowCache* RowCache::create_global_cache(int64_t capacity, uint32_t num_shards) { diff --git a/be/src/service/point_query_executor.h b/be/src/service/point_query_executor.h index ffddfe86db51c4..1b76c3da6e4796 100644 --- a/be/src/service/point_query_executor.h +++ b/be/src/service/point_query_executor.h @@ -232,8 +232,9 @@ class LookupConnectionCache : public LRUCachePolicy { friend class PointQueryExecutor; LookupConnectionCache(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::LOOKUP_CONNECTION_CACHE, capacity, - LRUCacheType::NUMBER, - config::tablet_lookup_cache_stale_sweep_time_sec) {} + LRUCacheType::NUMBER, config::tablet_lookup_cache_stale_sweep_time_sec, + /*num shards*/ 32, /*element count capacity */ 0, + /*enable prune*/ true, /*is lru-k*/ true) {} static std::string encode_key(__int128_t cache_id) { fmt::memory_buffer buffer; diff --git a/be/src/util/obj_lru_cache.cpp b/be/src/util/obj_lru_cache.cpp index fb03f1907d3ac0..be7e654b8b2a7c 100644 --- a/be/src/util/obj_lru_cache.cpp +++ b/be/src/util/obj_lru_cache.cpp @@ -22,7 +22,8 @@ namespace doris { ObjLRUCache::ObjLRUCache(int64_t capacity, uint32_t num_shards) : LRUCachePolicy(CachePolicy::CacheType::COMMON_OBJ_LRU_CACHE, capacity, LRUCacheType::NUMBER, config::common_obj_lru_cache_stale_sweep_time_sec, - num_shards), + /*num shards*/ 32, /*element count capacity */ 0, + /*enable prune*/ true, /*is lru-k*/ true), _enabled(capacity > 0) {} bool ObjLRUCache::lookup(const ObjKey& key, CacheHandle* handle) { diff --git a/be/test/olap/lru_cache_test.cpp b/be/test/olap/lru_cache_test.cpp index 64fe925f15f688..ee8a64fc92747b 100644 --- a/be/test/olap/lru_cache_test.cpp +++ b/be/test/olap/lru_cache_test.cpp @@ -93,14 +93,14 @@ class CacheTest : public testing::Test { public: CacheTestSizePolicy(size_t capacity) : LRUCachePolicy(CachePolicy::CacheType::FOR_UT_CACHE_SIZE, capacity, - LRUCacheType::SIZE, -1) {} + LRUCacheType::SIZE, -1, 32, 0, true, false) {} }; class CacheTestNumberPolicy : public LRUCachePolicy { public: CacheTestNumberPolicy(size_t capacity, uint32_t num_shards) : LRUCachePolicy(CachePolicy::CacheType::FOR_UT_CACHE_NUMBER, capacity, - LRUCacheType::NUMBER, -1, num_shards) {} + LRUCacheType::NUMBER, -1, num_shards, 0, true, false) {} }; // there is 16 shards in ShardedLRUCache