HBASE-24915 Improve BlockCache read performance by specifying BlockType (#2288)
Signed-off-by: Viraj Jasani <vjasani@apache.org> Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
5af9852397
commit
5b515de792
|
@ -55,6 +55,21 @@ public interface BlockCache extends Iterable<CachedBlock> {
|
|||
Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat,
|
||||
boolean updateCacheMetrics);
|
||||
|
||||
/**
|
||||
* Fetch block from cache.
|
||||
* @param cacheKey Block to fetch.
|
||||
* @param caching Whether this request has caching enabled (used for stats)
|
||||
* @param repeat Whether this is a repeat lookup for the same block
|
||||
* (used to avoid double counting cache misses when doing double-check locking)
|
||||
* @param updateCacheMetrics Whether to update cache metrics or not
|
||||
* @param blockType BlockType
|
||||
* @return Block or null if block is not in 2 cache.
|
||||
*/
|
||||
default Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat,
|
||||
boolean updateCacheMetrics, BlockType blockType) {
|
||||
return getBlock(cacheKey, caching, repeat, updateCacheMetrics);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evict block from cache.
|
||||
* @param cacheKey Block to evict
|
||||
|
|
|
@ -61,7 +61,7 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
|
|||
|
||||
@Override
|
||||
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory) {
|
||||
boolean metaBlock = buf.getBlockType().getCategory() != BlockCategory.DATA;
|
||||
boolean metaBlock = isMetaBlock(buf.getBlockType());
|
||||
if (metaBlock) {
|
||||
l1Cache.cacheBlock(cacheKey, buf, inMemory);
|
||||
} else {
|
||||
|
@ -74,6 +74,10 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
|
|||
cacheBlock(cacheKey, buf, false);
|
||||
}
|
||||
|
||||
private boolean isMetaBlock(BlockType blockType) {
|
||||
return blockType.getCategory() != BlockCategory.DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching,
|
||||
boolean repeat, boolean updateCacheMetrics) {
|
||||
|
@ -86,6 +90,20 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
|
|||
l2Cache.getBlock(cacheKey, caching, repeat, updateCacheMetrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat,
|
||||
boolean updateCacheMetrics, BlockType blockType) {
|
||||
if (blockType == null) {
|
||||
return getBlock(cacheKey, caching, repeat, updateCacheMetrics);
|
||||
}
|
||||
boolean metaBlock = isMetaBlock(blockType);
|
||||
if (metaBlock) {
|
||||
return l1Cache.getBlock(cacheKey, caching, repeat, updateCacheMetrics);
|
||||
} else {
|
||||
return l2Cache.getBlock(cacheKey, caching, repeat, updateCacheMetrics);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean evictBlock(BlockCacheKey cacheKey) {
|
||||
return l1Cache.evictBlock(cacheKey) || l2Cache.evictBlock(cacheKey);
|
||||
|
|
|
@ -1115,7 +1115,8 @@ public abstract class HFileReaderImpl implements HFile.Reader, Configurable {
|
|||
BlockCache cache = cacheConf.getBlockCache().orElse(null);
|
||||
if (cache != null) {
|
||||
HFileBlock cachedBlock =
|
||||
(HFileBlock) cache.getBlock(cacheKey, cacheBlock, useLock, updateCacheMetrics);
|
||||
(HFileBlock) cache.getBlock(cacheKey, cacheBlock, useLock,
|
||||
updateCacheMetrics, expectedBlockType);
|
||||
if (cachedBlock != null) {
|
||||
if (cacheConf.shouldCacheCompressed(cachedBlock.getBlockType().getCategory())) {
|
||||
HFileBlock compressedBlock = cachedBlock;
|
||||
|
|
Loading…
Reference in New Issue