Skip to content

Commit c3f3344

Browse files
committed
HBASE-28467: Addressed review comments.
Change-Id: Ife4f3a50395877027df717191befc2962deb692d
1 parent c6ed4c3 commit c3f3344

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,18 @@ public boolean shouldCacheBlockOnRead(BlockCategory category) {
275275
|| (prefetchOnOpen && (category != BlockCategory.META && category != BlockCategory.UNKNOWN));
276276
}
277277

278+
public boolean shouldCacheFileBlock(HFileInfo hFileInfo, Configuration conf) {
279+
Optional<Boolean> cacheFileBlock = Optional.of(true);
280+
// Additionally perform the time-based priority checks to see
281+
// whether, or not to cache the block.
282+
if (getBlockCache().isPresent()) {
283+
284+
cacheFileBlock = getBlockCache().get().shouldCacheFile(hFileInfo, conf);
285+
LOG.info("BlockCache Present, cacheFileBlock: {}", cacheFileBlock.get());
286+
}
287+
return cacheFileBlock.get();
288+
}
289+
278290
/** Returns true if blocks in this file should be flagged as in-memory */
279291
public boolean isInMemory() {
280292
return this.inMemory;

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,13 +1357,7 @@ public HFileBlock readBlock(long dataBlockOffset, long onDiskBlockSize, final bo
13571357
BlockType.BlockCategory category = hfileBlock.getBlockType().getCategory();
13581358
final boolean cacheCompressed = cacheConf.shouldCacheCompressed(category);
13591359
final boolean cacheOnRead = cacheConf.shouldCacheBlockOnRead(category);
1360-
Optional<Boolean> cacheFileBlock = Optional.of(true);
1361-
// Additionally perform the time-based priority checks to see
1362-
// whether, or not to cache the block.
1363-
if (cacheConf.getBlockCache().isPresent()) {
1364-
cacheFileBlock = cacheConf.getBlockCache().get().shouldCacheFile(getHFileInfo(), conf);
1365-
}
1366-
final boolean shouldCacheFileBlock = cacheFileBlock.get();
1360+
final boolean shouldCacheFileBlock = cacheConf.shouldCacheFileBlock(getHFileInfo(), conf);
13671361

13681362
// Don't need the unpacked block back and we're storing the block in the cache compressed
13691363
if (cacheOnly && cacheCompressed && cacheOnRead && shouldCacheFileBlock) {

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataTieringManager.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,31 @@ public void testFeatureKeyDisabled() throws Exception {
474474
}
475475
}
476476

477+
@Test
478+
public void testCacheConfigShouldCacheFile() throws Exception {
479+
// Evict the files from cache.
480+
for (HStoreFile file : hStoreFiles) {
481+
file.closeStoreFile(true);
482+
}
483+
// Verify that the API shouldCacheFileBlock returns the result correctly.
484+
// hStoreFiles[0], hStoreFiles[1], hStoreFiles[2] are hot files.
485+
// hStoreFiles[3] is a cold file.
486+
try {
487+
assertTrue(cacheConf.shouldCacheFileBlock(hStoreFiles.get(0).getFileInfo().getHFileInfo(),
488+
hStoreFiles.get(0).getFileInfo().getConf()));
489+
assertTrue(cacheConf.shouldCacheFileBlock(hStoreFiles.get(1).getFileInfo().getHFileInfo(),
490+
hStoreFiles.get(1).getFileInfo().getConf()));
491+
assertTrue(cacheConf.shouldCacheFileBlock(hStoreFiles.get(2).getFileInfo().getHFileInfo(),
492+
hStoreFiles.get(2).getFileInfo().getConf()));
493+
assertFalse(cacheConf.shouldCacheFileBlock(hStoreFiles.get(3).getFileInfo().getHFileInfo(),
494+
hStoreFiles.get(3).getFileInfo().getConf()));
495+
} finally {
496+
for (HStoreFile file : hStoreFiles) {
497+
file.initReader();
498+
}
499+
}
500+
}
501+
477502
@Test
478503
public void testCacheOnReadColdFile() throws Exception {
479504
// hStoreFiles[3] is a cold file. the blocks should not get loaded after a readBlock call.
@@ -488,7 +513,7 @@ public void testCacheOnReadHotFile() throws Exception {
488513
HStoreFile hStoreFile = hStoreFiles.get(0);
489514
BlockCacheKey cacheKey =
490515
new BlockCacheKey(hStoreFiles.get(0).getPath(), 0, true, BlockType.DATA);
491-
testCacheOnRead(hStoreFile, cacheKey, hStoreFile.getFileInfo().getSize(), true);
516+
testCacheOnRead(hStoreFile, cacheKey, 23025, true);
492517
}
493518

494519
private void testCacheOnRead(HStoreFile hStoreFile, BlockCacheKey key, long onDiskBlockSize,

0 commit comments

Comments
 (0)