Skip to content

Commit 1f88a38

Browse files
committed
HBASE-28467: Addressed further review comments.
Change-Id: Ia55e2e6ee415fa68d1c2714d127670f6df9c404d
1 parent 668dbd6 commit 1f88a38

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

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

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

278-
public boolean shouldCacheFileBlock(HFileInfo hFileInfo, Configuration conf) {
278+
public boolean shouldCacheBlockOnRead(BlockCategory category, HFileInfo hFileInfo,
279+
Configuration conf) {
279280
Optional<Boolean> cacheFileBlock = Optional.of(true);
280-
// Additionally perform the time-based priority checks to see
281-
// whether, or not to cache the block.
282281
if (getBlockCache().isPresent()) {
283-
284282
cacheFileBlock = getBlockCache().get().shouldCacheFile(hFileInfo, conf);
285-
LOG.info("BlockCache Present, cacheFileBlock: {}", cacheFileBlock.get());
286283
}
287-
return cacheFileBlock.get();
284+
return shouldCacheBlockOnRead(category) && cacheFileBlock.get();
288285
}
289286

290287
/** Returns true if blocks in this file should be flagged as in-memory */

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,8 @@ public HFileBlock getMetaBlock(String metaBlockName, boolean cacheBlock) throws
11931193
BlockCacheKey cacheKey =
11941194
new BlockCacheKey(name, metaBlockOffset, this.isPrimaryReplicaReader(), BlockType.META);
11951195

1196-
cacheBlock &= cacheConf.shouldCacheBlockOnRead(BlockType.META.getCategory());
1196+
cacheBlock &=
1197+
cacheConf.shouldCacheBlockOnRead(BlockType.META.getCategory(), getHFileInfo(), conf);
11971198
HFileBlock cachedBlock =
11981199
getCachedBlock(cacheKey, cacheBlock, false, true, BlockType.META, null);
11991200
if (cachedBlock != null) {
@@ -1346,15 +1347,15 @@ public HFileBlock readBlock(long dataBlockOffset, long onDiskBlockSize, final bo
13461347
}
13471348
BlockType.BlockCategory category = hfileBlock.getBlockType().getCategory();
13481349
final boolean cacheCompressed = cacheConf.shouldCacheCompressed(category);
1349-
final boolean cacheOnRead = cacheConf.shouldCacheBlockOnRead(category);
1350-
final boolean shouldCacheFileBlock = cacheConf.shouldCacheFileBlock(getHFileInfo(), conf);
1350+
final boolean cacheOnRead =
1351+
cacheConf.shouldCacheBlockOnRead(category, getHFileInfo(), conf);
13511352

13521353
// Don't need the unpacked block back and we're storing the block in the cache compressed
1353-
if (cacheOnly && cacheCompressed && cacheOnRead && shouldCacheFileBlock) {
1354+
if (cacheOnly && cacheCompressed && cacheOnRead) {
13541355
cacheConf.getBlockCache().ifPresent(cache -> {
13551356
LOG.debug("Skipping decompression of block {} in prefetch", cacheKey);
13561357
// Cache the block if necessary
1357-
if (cacheable && cacheConf.shouldCacheBlockOnRead(category)) {
1358+
if (cacheable && cacheOnRead) {
13581359
cache.cacheBlock(cacheKey, hfileBlock, cacheConf.isInMemory(), cacheOnly);
13591360
}
13601361
});
@@ -1367,7 +1368,7 @@ public HFileBlock readBlock(long dataBlockOffset, long onDiskBlockSize, final bo
13671368
HFileBlock unpacked = hfileBlock.unpack(hfileContext, fsBlockReader);
13681369
// Cache the block if necessary
13691370
cacheConf.getBlockCache().ifPresent(cache -> {
1370-
if (cacheable && cacheConf.shouldCacheBlockOnRead(category) && shouldCacheFileBlock) {
1371+
if (cacheable && cacheOnRead) {
13711372
// Using the wait on cache during compaction and prefetching.
13721373
cache.cacheBlock(cacheKey, cacheCompressed ? hfileBlock : unpacked,
13731374
cacheConf.isInMemory(), cacheOnly);

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.apache.hadoop.hbase.io.hfile.BlockCacheFactory;
5656
import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
5757
import org.apache.hadoop.hbase.io.hfile.BlockType;
58+
import org.apache.hadoop.hbase.io.hfile.BlockType.BlockCategory;
5859
import org.apache.hadoop.hbase.io.hfile.CacheConfig;
5960
import org.apache.hadoop.hbase.io.hfile.CacheTestUtils;
6061
import org.apache.hadoop.hbase.io.hfile.HFileBlock;
@@ -484,13 +485,17 @@ public void testCacheConfigShouldCacheFile() throws Exception {
484485
// hStoreFiles[0], hStoreFiles[1], hStoreFiles[2] are hot files.
485486
// hStoreFiles[3] is a cold file.
486487
try {
487-
assertTrue(cacheConf.shouldCacheFileBlock(hStoreFiles.get(0).getFileInfo().getHFileInfo(),
488+
assertTrue(cacheConf.shouldCacheBlockOnRead(BlockCategory.DATA,
489+
hStoreFiles.get(0).getFileInfo().getHFileInfo(),
488490
hStoreFiles.get(0).getFileInfo().getConf()));
489-
assertTrue(cacheConf.shouldCacheFileBlock(hStoreFiles.get(1).getFileInfo().getHFileInfo(),
491+
assertTrue(cacheConf.shouldCacheBlockOnRead(BlockCategory.DATA,
492+
hStoreFiles.get(1).getFileInfo().getHFileInfo(),
490493
hStoreFiles.get(1).getFileInfo().getConf()));
491-
assertTrue(cacheConf.shouldCacheFileBlock(hStoreFiles.get(2).getFileInfo().getHFileInfo(),
494+
assertTrue(cacheConf.shouldCacheBlockOnRead(BlockCategory.DATA,
495+
hStoreFiles.get(2).getFileInfo().getHFileInfo(),
492496
hStoreFiles.get(2).getFileInfo().getConf()));
493-
assertFalse(cacheConf.shouldCacheFileBlock(hStoreFiles.get(3).getFileInfo().getHFileInfo(),
497+
assertFalse(cacheConf.shouldCacheBlockOnRead(BlockCategory.DATA,
498+
hStoreFiles.get(3).getFileInfo().getHFileInfo(),
494499
hStoreFiles.get(3).getFileInfo().getConf()));
495500
} finally {
496501
for (HStoreFile file : hStoreFiles) {
@@ -509,7 +514,7 @@ public void testCacheOnReadColdFile() throws Exception {
509514

510515
@Test
511516
public void testCacheOnReadHotFile() throws Exception {
512-
// hStoreFiles[0] is a hot file. the blocks should not get loaded after a readBlock call.
517+
// hStoreFiles[0] is a hot file. the blocks should get loaded after a readBlock call.
513518
HStoreFile hStoreFile = hStoreFiles.get(0);
514519
BlockCacheKey cacheKey =
515520
new BlockCacheKey(hStoreFiles.get(0).getPath(), 0, true, BlockType.DATA);

0 commit comments

Comments
 (0)