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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1d46b2fcd KUDU-613: Fix BlockCache Constructor
1d46b2fcd is described below

commit 1d46b2fcdba6b30c52ebbba8725a16d749e4f857
Author: Mahesh Reddy <[email protected]>
AuthorDate: Wed Feb 12 00:50:48 2025 -0500

    KUDU-613: Fix BlockCache Constructor
    
    The capacity constraints are not calculated properly
    when creating a block cache with the slru eviction
    policy. This patch fixes this miscalculation.
    
    Change-Id: Icfde56fd766ba7160052e88ca09a63845f3297c6
    Reviewed-on: http://gerrit.cloudera.org:8080/22478
    Reviewed-by: Alexey Serbin <[email protected]>
    Tested-by: Alexey Serbin <[email protected]>
---
 src/kudu/cfile/block_cache.cc | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/kudu/cfile/block_cache.cc b/src/kudu/cfile/block_cache.cc
index 4ece823d2..0aa5d47b2 100644
--- a/src/kudu/cfile/block_cache.cc
+++ b/src/kudu/cfile/block_cache.cc
@@ -201,8 +201,8 @@ Cache* BlockCache::CreateCache(int64_t capacity) {
 }
 
 Cache* BlockCache::CreateCache(int64_t probationary_segment_capacity,
-                   int64_t protected_segment_capacity,
-                   uint32_t lookups) {
+                               int64_t protected_segment_capacity,
+                               uint32_t lookups) {
   const auto& mem_type = BlockCache::GetConfiguredCacheMemoryTypeOrDie();
   switch (mem_type) {
     case Cache::MemoryType::DRAM:
@@ -244,16 +244,17 @@ Cache::EvictionPolicy 
BlockCache::GetCacheEvictionPolicyOrDie() {
 
 BlockCache::BlockCache() {
   const auto& eviction_policy = GetCacheEvictionPolicyOrDie();
+  int64_t capacity = FLAGS_block_cache_capacity_mb * 1024 * 1024;
   if (eviction_policy == Cache::EvictionPolicy::LRU) {
-    unique_ptr<Cache> lru_cache(CreateCache(FLAGS_block_cache_capacity_mb * 
1024 * 1024));
+    unique_ptr<Cache> lru_cache(CreateCache(capacity));
     cache_ = std::move(lru_cache);
   } else {
     DCHECK(eviction_policy == Cache::EvictionPolicy::SLRU);
-    int64_t probationary_capacity =
-        static_cast<int>(std::round((1.0 - 
FLAGS_block_cache_protected_segment_percentage)
-        * 1024 * 1024));
-    int64_t protected_capacity =
-        
static_cast<int>(std::round(FLAGS_block_cache_protected_segment_percentage * 
1024 * 1024));
+    int64_t probationary_capacity = static_cast<int64_t>(
+        std::round((1.0 - FLAGS_block_cache_protected_segment_percentage) * 
capacity));
+    int64_t protected_capacity = static_cast<int64_t>(
+        std::round(FLAGS_block_cache_protected_segment_percentage * capacity));
+    DCHECK_EQ(capacity, probationary_capacity + protected_capacity);
     unique_ptr<Cache> slru_cache(CreateCache(probationary_capacity, 
protected_capacity,
                                              
FLAGS_block_cache_lookups_before_upgrade));
     cache_ = std::move(slru_cache);

Reply via email to