Apache9 commented on code in PR #5525:
URL: https://github.com/apache/hbase/pull/5525#discussion_r1404716373


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCache.java:
##########
@@ -161,4 +164,14 @@ default Cacheable getBlock(BlockCacheKey cacheKey, boolean 
caching, boolean repe
   default boolean isMetaBlock(BlockType blockType) {
     return blockType != null && blockType.getCategory() != 
BlockType.BlockCategory.DATA;
   }
+
+  /**
+   * Clean Cache by evicting the blocks of files belonging to regions that are 
no longer served by
+   * the RegionServer.
+   * @param server HRegionServer
+   * @return A map of filename and number of blocks evicted.
+   */
+  default Optional<Map<String, Integer>> uncacheStaleBlocks(HRegionServer 
server) {

Review Comment:
   I prefer here we pass an interface, for testing whether a region is 
available, instead of pass a HRegionServer directly.  It will be easier for 
testing.
   And just returning a Map is enough? If we do not clean any blocks, just 
return an empty map?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java:
##########
@@ -2002,4 +2005,27 @@ public void fileCacheCompleted(Path filePath, long size) 
{
     regionCachedSizeMap.merge(regionName, size, (oldpf, fileSize) -> oldpf + 
fileSize);
   }
 
+  @Override
+  public Optional<Map<String, Integer>> uncacheStaleBlocks(HRegionServer 
server) {
+    Map<String, Integer> evictedFilesWithStaleBlocks = new HashMap<>();
+
+    fullyCachedFiles.forEach((fileName, value) -> {
+      int blocksEvicted;
+      try {
+        if (!server.getRegionByEncodedName(value.getFirst()).isAvailable()) {
+          blocksEvicted = evictBlocksByHfileName(fileName);
+        } else {
+          blocksEvicted = 0;
+        }
+      } catch (NotServingRegionException nsre) {

Review Comment:
   Is this the normal path? In the above if condition, we test isAvailable, so 
why here we could still get a NotServingRegionException?



-- 
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