Package org.apache.hadoop.hbase.io.hfile
Class BlockCacheUtil
java.lang.Object
org.apache.hadoop.hbase.io.hfile.BlockCacheUtil
Utilty for aggregating counts in CachedBlocks and toString/toJSON CachedBlocks and BlockCaches.
No attempt has been made at making this thread safe.
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Little data structure to hold counts for a file.static class
Use one of these to keep a running account of cached blocks by file. -
Field Summary
Modifier and TypeFieldDescriptionprivate static final int
private static final org.apache.hbase.thirdparty.com.google.gson.Gson
Needed generating JSON.private static final org.slf4j.Logger
static final long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic HFileContext
cloneContext
(HFileContext context) private static int
compareCacheBlock
(Cacheable left, Cacheable right, boolean includeNextBlockMetadata) static HFileBlock
getBlockForCaching
(CacheConfig cacheConf, HFileBlock block) Similarly to HFileBlock.Writer.getBlockForCaching(), creates a HFileBlock instance without checksum for caching.getLoadedCachedBlocksByFile
(org.apache.hadoop.conf.Configuration conf, BlockCache bc) Get aBlockCacheUtil.CachedBlocksByFile
instance and load it up by iterating content inBlockCache
.static int
getMaxCachedBlocksByFile
(org.apache.hadoop.conf.Configuration conf) listAllFilesNames
(Map<String, HRegion> onlineRegions) static boolean
shouldReplaceExistingCacheBlock
(BlockCache blockCache, BlockCacheKey cacheKey, Cacheable newBlock) Because of the region splitting, it's possible that the split key locate in the middle of a block.static String
toJSON
(String filename, NavigableSet<CachedBlock> blocks) Returns A JSON String offilename
and counts ofblocks
static String
toJSON
(BlockCache bc) Returns JSON string ofbc
content.static String
Returns JSON string ofcbsf
aggregatedstatic String
toString
(CachedBlock cb, long now) Returns The block content as String.static String
toStringMinusFileName
(CachedBlock cb, long now) Returns The block content ofbc
as a String minus the filename.static int
validateBlockAddition
(Cacheable existing, Cacheable newBlock, BlockCacheKey cacheKey) Validate that the existing and newBlock are the same without including the nextBlockMetadata, if not, throw an exception.
-
Field Details
-
LOG
-
NANOS_PER_SECOND
- See Also:
-
GSON
Needed generating JSON. -
DEFAULT_MAX
- See Also:
-
-
Constructor Details
-
BlockCacheUtil
public BlockCacheUtil()
-
-
Method Details
-
toString
Returns The block content as String. -
toJSON
Returns JSON string ofcbsf
aggregated- Throws:
IOException
-
toJSON
Returns JSON string ofbc
content.- Throws:
IOException
-
toStringMinusFileName
Returns The block content ofbc
as a String minus the filename. -
getLoadedCachedBlocksByFile
public static BlockCacheUtil.CachedBlocksByFile getLoadedCachedBlocksByFile(org.apache.hadoop.conf.Configuration conf, BlockCache bc) Get aBlockCacheUtil.CachedBlocksByFile
instance and load it up by iterating content inBlockCache
.- Parameters:
conf
- Used to read configurationsbc
- Block Cache to iterate.- Returns:
- Laoded up instance of CachedBlocksByFile
-
compareCacheBlock
private static int compareCacheBlock(Cacheable left, Cacheable right, boolean includeNextBlockMetadata) -
validateBlockAddition
public static int validateBlockAddition(Cacheable existing, Cacheable newBlock, BlockCacheKey cacheKey) Validate that the existing and newBlock are the same without including the nextBlockMetadata, if not, throw an exception. If they are the same without the nextBlockMetadata, return the comparison.- Parameters:
existing
- block that is existing in the cache.newBlock
- block that is trying to be cached.cacheKey
- the cache key of the blocks.- Returns:
- comparison of the existing block to the newBlock.
-
shouldReplaceExistingCacheBlock
public static boolean shouldReplaceExistingCacheBlock(BlockCache blockCache, BlockCacheKey cacheKey, Cacheable newBlock) Because of the region splitting, it's possible that the split key locate in the middle of a block. So it's possible that both the daughter regions load the same block from their parent HFile. When pread, we don't force the read to read all of the next block header. So when two threads try to cache the same block, it's possible that one thread read all of the next block header but the other one didn't. if the already cached block hasn't next block header but the new block to cache has, then we can replace the existing block with the new block for better performance.(HBASE-20447)- Parameters:
blockCache
- BlockCache to checkcacheKey
- the block cache keynewBlock
- the new block which try to put into the block cache.- Returns:
- true means need to replace existing block with new block for the same block cache key. false means just keep the existing block.
-
listAllFilesNames
-
getMaxCachedBlocksByFile
-
getBlockForCaching
Similarly to HFileBlock.Writer.getBlockForCaching(), creates a HFileBlock instance without checksum for caching. This is needed for when we cache blocks via readers (either prefetch or client read), otherwise we may fail equality comparison when checking against same block that may already have been cached at write time.- Parameters:
cacheConf
- the related CacheConfig object.block
- the HFileBlock instance to be converted.- Returns:
- the resulting HFileBlock instance without checksum.
-
cloneContext
-