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 8c9d473b53be..bfa807d4a6f9 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 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 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 bc7bc955864c..4cd50ced57f1 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 @@ -651,6 +651,7 @@ public BucketEntry getBlockForReference(BlockCacheKey key) { 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);