Skip to content

Commit 98fa812

Browse files
wchevreuilmokai87
authored andcommitted
HBASE-28953 Prefetch thread shouldn't run for master store (apache#6438) (apache#6445)
Signed-off-by: Peter Somogyi <[email protected]> Signed-off-by: Ankit Singhal <[email protected]> Signed-off-by: Pankaj Kumar<[email protected]>
1 parent 586b796 commit 98fa812

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
@@ -381,6 +381,28 @@ public void testPrefetchWithDelay() throws Exception {
381381
prefetchExecutorNotifier.onConfigurationChange(conf);
382382
}
383383

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

0 commit comments

Comments
 (0)