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

zhangduo pushed a commit to branch branch-2.5
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.5 by this push:
     new 622eb7b6cdc HBASE-29862 Test case 
TestClearRegionBlockCache#testClearBlockCache failed (branch-2.5) (#7820)
622eb7b6cdc is described below

commit 622eb7b6cdc0f72591d20d86e0b19a1a13fc284d
Author: Peng Lu <[email protected]>
AuthorDate: Sun Mar 1 10:18:27 2026 +0800

    HBASE-29862 Test case TestClearRegionBlockCache#testClearBlockCache failed 
(branch-2.5) (#7820)
    
    Signed-off-by: Duo Zhang <[email protected]>
---
 .../hadoop/hbase/io/hfile/bucket/BucketCache.java  | 33 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
index 2854ff598dd..0ca8665f354 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java
@@ -1420,8 +1420,7 @@ public class BucketCache implements BlockCache, HeapSize {
    */
   @Override
   public int evictBlocksByHfileName(String hfileName) {
-    Set<BlockCacheKey> keySet = blocksByHFile.subSet(new 
BlockCacheKey(hfileName, Long.MIN_VALUE),
-      true, new BlockCacheKey(hfileName, Long.MAX_VALUE), true);
+    Set<BlockCacheKey> keySet = getAllCacheKeysForFile(hfileName, 0L, 
Long.MAX_VALUE);
 
     int numEvicted = 0;
     for (BlockCacheKey key : keySet) {
@@ -1433,6 +1432,25 @@ public class BucketCache implements BlockCache, HeapSize 
{
     return numEvicted;
   }
 
+  private Set<BlockCacheKey> getAllCacheKeysForFile(String hfileName, long 
init, long end) {
+    Set<BlockCacheKey> cacheKeys = new HashSet<>();
+    // At this moment, Some Bucket Entries may be in the WriterThread queue, 
and not yet put into
+    // the backingMap. So, when executing this method, we should check both 
the RAMCache and
+    // backingMap to ensure all CacheKeys are obtained.
+    // For more details, please refer to HBASE-29862.
+    Set<BlockCacheKey> ramCacheKeySet = 
ramCache.getRamBlockCacheKeysForHFile(hfileName);
+    for (BlockCacheKey key : ramCacheKeySet) {
+      if (key.getOffset() >= init && key.getOffset() <= end) {
+        cacheKeys.add(key);
+      }
+    }
+
+    // These keys are just for comparison and are short lived, so we need only 
file name and offset
+    cacheKeys.addAll(blocksByHFile.subSet(new BlockCacheKey(hfileName, init), 
true,
+      new BlockCacheKey(hfileName, end), true));
+    return cacheKeys;
+  }
+
   /**
    * Used to group bucket entries into priority buckets. There will be a 
BucketEntryGroup for each
    * priority (single, multi, memory). Once bucketed, the eviction algorithm 
takes the appropriate
@@ -1770,5 +1788,16 @@ public class BucketCache implements BlockCache, HeapSize 
{
         re.getData().release();
       }
     }
+
+    public Set<BlockCacheKey> getRamBlockCacheKeysForHFile(String fileName) {
+      Set<BlockCacheKey> ramCacheKeySet = new HashSet<>();
+      for (BlockCacheKey blockCacheKey : delegate.keySet()) {
+        if (blockCacheKey.getHfileName().equals(fileName)) {
+          ramCacheKeySet.add(blockCacheKey);
+        }
+      }
+
+      return ramCacheKeySet;
+    }
   }
 }

Reply via email to