Skip to content

Commit a1ce468

Browse files
committed
HBASE-28953 Prefetch thread shouldn't run for master store
1 parent 344bf78 commit a1ce468

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFilePreadReader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ public class HFilePreadReader extends HFileReaderImpl {
3939
public HFilePreadReader(ReaderContext context, HFileInfo fileInfo, CacheConfig cacheConf,
4040
Configuration conf) throws IOException {
4141
super(context, fileInfo, cacheConf, conf);
42-
42+
// master hosted regions, like the master procedures store wouldn't have a block cache
43+
final MutableBoolean shouldCache = new MutableBoolean(cacheConf.getBlockCache().isPresent());
4344
// Prefetch file blocks upon open if requested
44-
if (cacheConf.shouldPrefetchOnOpen()) {
45+
if (shouldCache.booleanValue() && cacheConf.shouldPrefetchOnOpen()) {
4546
PrefetchExecutor.request(path, new Runnable() {
4647
@Override
4748
public void run() {
4849
long offset = 0;
4950
long end = 0;
5051
HFile.Reader prefetchStreamReader = null;
51-
final MutableBoolean shouldCache = new MutableBoolean(true);
5252
try {
5353
cacheConf.getBlockCache().ifPresent(cache -> {
5454
cache.waitForCacheInitialization(WAIT_TIME_FOR_CACHE_INITIALIZATION);
5555
Optional<Boolean> result = cache.shouldCacheFile(path.getName());
5656
shouldCache.setValue(result.isPresent() ? result.get().booleanValue() : true);
5757
});
5858
if (!shouldCache.booleanValue()) {
59-
LOG.info("Prefetch skipped for the file: " + path.getName());
59+
LOG.info("Prefetch skipped for file: {}", path);
6060
return;
6161
}
6262

hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestPrefetch.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,28 @@ public void testPrefetchWithDelay() throws Exception {
378378
prefetchExecutorNotifier.onConfigurationChange(conf);
379379
}
380380

381+
@Test
382+
public void testPrefetchWhenNoBlockCache() throws Exception {
383+
PrefetchExecutorNotifier prefetchExecutorNotifier = new PrefetchExecutorNotifier(conf);
384+
try {
385+
// Set a delay to max, as we don't need to have the thread running, but rather
386+
// assert that it never gets scheduled
387+
conf.setInt(PREFETCH_DELAY, Integer.MAX_VALUE);
388+
conf.setFloat(PREFETCH_DELAY_VARIATION, 0.0f);
389+
prefetchExecutorNotifier.onConfigurationChange(conf);
390+
391+
HFileContext context = new HFileContextBuilder().withCompression(Compression.Algorithm.GZ)
392+
.withBlockSize(DATA_BLOCK_SIZE).build();
393+
Path storeFile = writeStoreFile("testPrefetchWhenNoBlockCache", context);
394+
HFile.createReader(fs, storeFile, new CacheConfig(conf), true, conf);
395+
assertEquals(0, PrefetchExecutor.getPrefetchFutures().size());
396+
} finally {
397+
conf.setInt(PREFETCH_DELAY, 1000);
398+
conf.setFloat(PREFETCH_DELAY_VARIATION, PREFETCH_DELAY_VARIATION_DEFAULT_VALUE);
399+
prefetchExecutorNotifier.onConfigurationChange(conf);
400+
}
401+
}
402+
381403
@Test
382404
public void testPrefetchDoesntSkipHFileLink() throws Exception {
383405
testPrefetchWhenHFileLink(c -> {

0 commit comments

Comments
 (0)