You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by wc...@apache.org on 2024/10/28 09:38:32 UTC

(hbase) branch branch-2 updated: HBASE-28934: Avoid waits within HFilePreadReader constructors for cache initialisation. (#6389) (#6398)

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

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


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 0a5bec47fa5 HBASE-28934: Avoid waits within HFilePreadReader constructors for cache initialisation. (#6389) (#6398)
0a5bec47fa5 is described below

commit 0a5bec47fa599fa3a63b9777a41ecfaaec10bd5b
Author: Wellington Ramos Chevreuil <wc...@apache.org>
AuthorDate: Mon Oct 28 09:38:26 2024 +0000

    HBASE-28934: Avoid waits within HFilePreadReader constructors for cache initialisation. (#6389) (#6398)
    
    Signed-off-by: Wellington Chevreuil <wc...@apache.org>
    Co-authored-by: jhungund <10...@users.noreply.github.com>
---
 .../hadoop/hbase/io/hfile/HFilePreadReader.java      | 20 ++++++++++++--------
 .../hadoop/hbase/io/hfile/bucket/BucketCache.java    |  1 +
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePreadReader.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePreadReader.java
index 8c9d473b53b..bfa807d4a6f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePreadReader.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePreadReader.java
@@ -39,23 +39,27 @@ public class HFilePreadReader extends HFileReaderImpl {
   public HFilePreadReader(ReaderContext context, HFileInfo fileInfo, CacheConfig cacheConf,
     Configuration conf) throws IOException {
     super(context, fileInfo, cacheConf, conf);
-    final MutableBoolean shouldCache = new MutableBoolean(true);
-
-    cacheConf.getBlockCache().ifPresent(cache -> {
-      cache.waitForCacheInitialization(WAIT_TIME_FOR_CACHE_INITIALIZATION);
-      Optional<Boolean> result = cache.shouldCacheFile(path.getName());
-      shouldCache.setValue(result.isPresent() ? result.get().booleanValue() : true);
-    });
 
     // Prefetch file blocks upon open if requested
-    if (cacheConf.shouldPrefetchOnOpen() && shouldCache.booleanValue()) {
+    if (cacheConf.shouldPrefetchOnOpen()) {
       PrefetchExecutor.request(path, new Runnable() {
         @Override
         public void run() {
           long offset = 0;
           long end = 0;
           HFile.Reader prefetchStreamReader = null;
+          final MutableBoolean shouldCache = new MutableBoolean(true);
           try {
+            cacheConf.getBlockCache().ifPresent(cache -> {
+              cache.waitForCacheInitialization(WAIT_TIME_FOR_CACHE_INITIALIZATION);
+              Optional<Boolean> result = cache.shouldCacheFile(path.getName());
+              shouldCache.setValue(result.isPresent() ? result.get().booleanValue() : true);
+            });
+            if (!shouldCache.booleanValue()) {
+              LOG.info("Prefetch skipped for the file: " + path.getName());
+              return;
+            }
+
             ReaderContext streamReaderContext = ReaderContextBuilder.newBuilder(context)
               .withReaderType(ReaderContext.ReaderType.STREAM)
               .withInputStreamWrapper(new FSDataInputStreamWrapper(context.getFileSystem(),
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 9258118017b..3ea6602b4fd 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
@@ -639,6 +639,7 @@ public class BucketCache implements BlockCache, HeapSize {
   public Cacheable getBlock(BlockCacheKey key, boolean caching, boolean repeat,
     boolean updateCacheMetrics) {
     if (!isCacheEnabled()) {
+      cacheStats.miss(caching, key.isPrimary(), key.getBlockType());
       return null;
     }
     RAMQueueEntry re = ramCache.get(key);