Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ public class HFilePreadReader extends HFileReaderImpl {
public HFilePreadReader(ReaderContext context, HFileInfo fileInfo, CacheConfig cacheConf,
Configuration conf) throws IOException {
super(context, fileInfo, cacheConf, conf);

// master hosted regions, like the master procedures store wouldn't have a block cache
final MutableBoolean shouldCache = new MutableBoolean(cacheConf.getBlockCache().isPresent());
// Prefetch file blocks upon open if requested
if (cacheConf.shouldPrefetchOnOpen()) {
if (shouldCache.booleanValue() && 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());
LOG.info("Prefetch skipped for file: {}", path);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,28 @@ public void testPrefetchWithDelay() throws Exception {
prefetchExecutorNotifier.onConfigurationChange(conf);
}

@Test
public void testPrefetchWhenNoBlockCache() throws Exception {
PrefetchExecutorNotifier prefetchExecutorNotifier = new PrefetchExecutorNotifier(conf);
try {
// Set a delay to max, as we don't need to have the thread running, but rather
// assert that it never gets scheduled
conf.setInt(PREFETCH_DELAY, Integer.MAX_VALUE);
conf.setFloat(PREFETCH_DELAY_VARIATION, 0.0f);
prefetchExecutorNotifier.onConfigurationChange(conf);

HFileContext context = new HFileContextBuilder().withCompression(Compression.Algorithm.GZ)
.withBlockSize(DATA_BLOCK_SIZE).build();
Path storeFile = writeStoreFile("testPrefetchWhenNoBlockCache", context);
HFile.createReader(fs, storeFile, new CacheConfig(conf), true, conf);
assertEquals(0, PrefetchExecutor.getPrefetchFutures().size());
} finally {
conf.setInt(PREFETCH_DELAY, 1000);
conf.setFloat(PREFETCH_DELAY_VARIATION, PREFETCH_DELAY_VARIATION_DEFAULT_VALUE);
prefetchExecutorNotifier.onConfigurationChange(conf);
}
}

@Test
public void testPrefetchDoesntSkipHFileLink() throws Exception {
testPrefetchWhenHFileLink(c -> {
Expand Down