This is an automated email from the ASF dual-hosted git repository.

airborne pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 2dace7af0c1 [fix](cache) always create data and index page cache to 
avoid null pointer (#59266)
2dace7af0c1 is described below

commit 2dace7af0c139e6421f0111d5728947c68bfda34
Author: zzzxl <[email protected]>
AuthorDate: Tue Dec 23 11:37:38 2025 +0800

    [fix](cache) always create data and index page cache to avoid null pointer 
(#59266)
---
 be/src/olap/page_cache.cpp               |  14 +++--
 be/src/runtime/memory/lru_cache_policy.h |   8 +--
 be/test/olap/page_cache_test.cpp         | 104 +++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+), 10 deletions(-)

diff --git a/be/src/olap/page_cache.cpp b/be/src/olap/page_cache.cpp
index 7e1129ba4de..24e3b844dbb 100644
--- a/be/src/olap/page_cache.cpp
+++ b/be/src/olap/page_cache.cpp
@@ -82,19 +82,21 @@ StoragePageCache* 
StoragePageCache::create_global_cache(size_t capacity,
 StoragePageCache::StoragePageCache(size_t capacity, int32_t 
index_cache_percentage,
                                    int64_t pk_index_cache_capacity, uint32_t 
num_shards)
         : _index_cache_percentage(index_cache_percentage) {
+    size_t data_page_capacity = 0;
+    size_t index_page_capacity = 0;
     if (index_cache_percentage == 0) {
-        _data_page_cache = std::make_unique<DataPageCache>(capacity, 
num_shards);
+        data_page_capacity = capacity;
     } else if (index_cache_percentage == 100) {
-        _index_page_cache = std::make_unique<IndexPageCache>(capacity, 
num_shards);
+        index_page_capacity = capacity;
     } else if (index_cache_percentage > 0 && index_cache_percentage < 100) {
-        _data_page_cache = std::make_unique<DataPageCache>(
-                capacity * (100 - index_cache_percentage) / 100, num_shards);
-        _index_page_cache = std::make_unique<IndexPageCache>(
-                capacity * index_cache_percentage / 100, num_shards);
+        data_page_capacity = capacity * (100 - index_cache_percentage) / 100;
+        index_page_capacity = capacity * index_cache_percentage / 100;
     } else {
         CHECK(false) << "invalid index page cache percentage";
     }
 
+    _data_page_cache = std::make_unique<DataPageCache>(data_page_capacity, 
num_shards);
+    _index_page_cache = std::make_unique<IndexPageCache>(index_page_capacity, 
num_shards);
     _pk_index_page_cache = 
std::make_unique<PKIndexPageCache>(pk_index_cache_capacity, num_shards);
 }
 
diff --git a/be/src/runtime/memory/lru_cache_policy.h 
b/be/src/runtime/memory/lru_cache_policy.h
index 7aa0b746715..c5dbec0878b 100644
--- a/be/src/runtime/memory/lru_cache_policy.h
+++ b/be/src/runtime/memory/lru_cache_policy.h
@@ -74,11 +74,11 @@ public:
     void reset_cache() { _cache.reset(); }
 
     bool check_capacity(size_t capacity, uint32_t num_shards) {
-        if (capacity < num_shards) {
+        if (capacity == 0 || 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);
+                    "{} lru cache capacity({} B) {} num_shards({}), will be 
disabled.",
+                    type_string(type()), capacity, capacity == 0 ? "is 0, 
ignore" : "less than",
+                    num_shards);
             _enable_prune = false;
             return false;
         }
diff --git a/be/test/olap/page_cache_test.cpp b/be/test/olap/page_cache_test.cpp
index a6b9300c105..17011231b53 100644
--- a/be/test/olap/page_cache_test.cpp
+++ b/be/test/olap/page_cache_test.cpp
@@ -286,4 +286,108 @@ TEST_F(StoragePageCacheTest, mixed_pages) {
     }
 }
 
+TEST_F(StoragePageCacheTest, zero_index_cache_percentage) {
+    StoragePageCache cache(kNumShards * 2048, 0, 0, kNumShards);
+
+    StoragePageCache::CacheKey data_key("data", 0, 0);
+    StoragePageCache::CacheKey index_key("index", 0, 0);
+
+    segment_v2::PageTypePB page_type_data = segment_v2::DATA_PAGE;
+    segment_v2::PageTypePB page_type_index = segment_v2::INDEX_PAGE;
+
+    {
+        PageCacheHandle handle;
+        auto* data = new DataPage(1024, true, page_type_data);
+        cache.insert(data_key, data, &handle, page_type_data, false);
+        auto found = cache.lookup(data_key, &handle, page_type_data);
+        EXPECT_TRUE(found);
+    }
+
+    {
+        PageCacheHandle handle;
+        auto* index = new DataPage(1024, true, page_type_index);
+        cache.insert(index_key, index, &handle, page_type_index, false);
+        auto found = cache.lookup(index_key, &handle, page_type_index);
+        EXPECT_FALSE(found);
+    }
+}
+
+TEST_F(StoragePageCacheTest, full_index_cache_percentage) {
+    StoragePageCache cache(kNumShards * 2048, 100, 0, kNumShards);
+
+    StoragePageCache::CacheKey data_key("data", 0, 0);
+    StoragePageCache::CacheKey index_key("index", 0, 0);
+
+    segment_v2::PageTypePB page_type_data = segment_v2::DATA_PAGE;
+    segment_v2::PageTypePB page_type_index = segment_v2::INDEX_PAGE;
+
+    {
+        PageCacheHandle handle;
+        auto* data = new DataPage(1024, true, page_type_data);
+        cache.insert(data_key, data, &handle, page_type_data, false);
+        auto found = cache.lookup(data_key, &handle, page_type_data);
+        EXPECT_FALSE(found);
+    }
+
+    {
+        PageCacheHandle handle;
+        auto* index = new DataPage(1024, true, page_type_index);
+        cache.insert(index_key, index, &handle, page_type_index, false);
+        auto found = cache.lookup(index_key, &handle, page_type_index);
+        EXPECT_TRUE(found);
+    }
+}
+
+TEST_F(StoragePageCacheTest, zero_total_capacity) {
+    StoragePageCache cache(0, 50, 0, kNumShards);
+
+    StoragePageCache::CacheKey data_key("data", 0, 0);
+    StoragePageCache::CacheKey index_key("index", 0, 0);
+
+    segment_v2::PageTypePB page_type_data = segment_v2::DATA_PAGE;
+    segment_v2::PageTypePB page_type_index = segment_v2::INDEX_PAGE;
+
+    {
+        PageCacheHandle handle;
+        auto* data = new DataPage(1024, true, page_type_data);
+        cache.insert(data_key, data, &handle, page_type_data, false);
+        auto found = cache.lookup(data_key, &handle, page_type_data);
+        EXPECT_FALSE(found);
+    }
+
+    {
+        PageCacheHandle handle;
+        auto* index = new DataPage(1024, true, page_type_index);
+        cache.insert(index_key, index, &handle, page_type_index, false);
+        auto found = cache.lookup(index_key, &handle, page_type_index);
+        EXPECT_FALSE(found);
+    }
+}
+
+TEST_F(StoragePageCacheTest, capacity_less_than_num_shards) {
+    StoragePageCache cache(10, 50, 0, kNumShards);
+
+    StoragePageCache::CacheKey data_key("data", 0, 0);
+    StoragePageCache::CacheKey index_key("index", 0, 0);
+
+    segment_v2::PageTypePB page_type_data = segment_v2::DATA_PAGE;
+    segment_v2::PageTypePB page_type_index = segment_v2::INDEX_PAGE;
+
+    {
+        PageCacheHandle handle;
+        auto* data = new DataPage(1024, true, page_type_data);
+        cache.insert(data_key, data, &handle, page_type_data, false);
+        auto found = cache.lookup(data_key, &handle, page_type_data);
+        EXPECT_FALSE(found);
+    }
+
+    {
+        PageCacheHandle handle;
+        auto* index = new DataPage(1024, true, page_type_index);
+        cache.insert(index_key, index, &handle, page_type_index, false);
+        auto found = cache.lookup(index_key, &handle, page_type_index);
+        EXPECT_FALSE(found);
+    }
+}
+
 } // namespace doris


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to