From cf3d7c143cb4861b5de0bab879b888642459f65a Mon Sep 17 00:00:00 2001 From: Peng Lu Date: Fri, 30 Jan 2026 22:11:44 +0800 Subject: [PATCH] HBASE-29862 Test case TestClearRegionBlockCache#testClearBlockCache failed --- .../hbase/io/hfile/bucket/BucketCache.java | 27 +++++++++++++++++-- 1 file changed, 25 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 ba302d7c42ce..4cbb08ed760e 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 @@ -1945,9 +1945,22 @@ public int evictBlocksRangeByHfileName(String hfileName, long initOffset, long e } private Set getAllCacheKeysForFile(String hfileName, long init, long end) { + Set 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 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 - return blocksByHFile.subSet(new BlockCacheKey(hfileName, init), true, - new BlockCacheKey(hfileName, end), true); + cacheKeys.addAll(blocksByHFile.subSet(new BlockCacheKey(hfileName, init), true, + new BlockCacheKey(hfileName, end), true)); + return cacheKeys; } /** @@ -2342,6 +2355,16 @@ public boolean hasBlocksForFile(String fileName) { return delegate.keySet().stream().filter(key -> key.getHfileName().equals(fileName)) .findFirst().isPresent(); } + + public Set getRamBlockCacheKeysForHFile(String fileName) { + Set ramCacheKeySet = new HashSet<>(); + for (BlockCacheKey blockCacheKey : delegate.keySet()) { + if (blockCacheKey.getHfileName().equals(fileName)) { + ramCacheKeySet.add(blockCacheKey); + } + } + return ramCacheKeySet; + } } public Map getBackingMap() {