mwkang commented on code in PR #8469:
URL: https://github.com/apache/hbase/pull/8469#discussion_r3655135132


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java:
##########
@@ -722,22 +727,48 @@ public Cacheable getBlock(BlockCacheKey key, boolean 
caching, boolean repeat,
         // When using file io engine persistent cache,
         // the cache map state might differ from the actual cache. If we reach 
this block,
         // we should remove the cache key entry from the backing map
-        backingMap.remove(key);
-        fileNotFullyCached(key, bucketEntry);
+        failedBucketEntryRead = true;
         LOG.debug("Failed to fetch block for cache key: {}.", key, hioex);
       } catch (IOException ioex) {
         LOG.error("Failed reading block " + key + " from bucket cache", ioex);
         checkIOErrorIsTolerated();
       } finally {
         lock.readLock().unlock();
       }
+      if (failedBucketEntryRead) {
+        removeFailedBucketEntry(bucketEntry);
+      }
     }
     if (!repeat && updateCacheMetrics) {
       cacheStats.miss(caching, key.isPrimary(), key.getBlockType());
     }
     return null;
   }
 
+  private void removeFailedBucketEntry(BucketEntry bucketEntry) {
+    BlockCacheKey cacheKey = findBackingMapKey(bucketEntry);
+    if (cacheKey == null) {
+      return;
+    }
+    bucketEntry.withWriteLock(offsetLock, () -> {
+      if (backingMap.remove(cacheKey, bucketEntry)) {
+        blockEvicted(cacheKey, bucketEntry, true, false);
+      }
+      return null;
+    });
+  }
+
+  private BlockCacheKey findBackingMapKey(BucketEntry bucketEntry) {

Review Comment:
   I extracted getBlockKeyForReference and now reuse it from both 
getBlockForReference and getBlock.
   
   The inconsistent-entry path no longer scans backingMap. It uses 
blocksByHFile.ceiling(lookupKey) to find the actual stored key, including its 
region and family metadata, verifies the hfile/offset identity, and 
conditionally removes the matching BucketEntry under its offset write lock.
   
   testHBaseIOExceptionThroughReferenceEvictsStoredEntry covers the 
reference-file lookup path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to