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
Nested ClassesModifier and TypeClassDescription(package private) static classLittle data structure to hold counts for a file.static classUse one of these to keep a running account of cached blocks by file. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final org.apache.hbase.thirdparty.com.google.gson.GsonNeeded generating JSON.private static final org.slf4j.Loggerstatic final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic HFileContextcloneContext(HFileContext context) private static intcompareCacheBlock(Cacheable left, Cacheable right, boolean includeNextBlockMetadata) static HFileBlockgetBlockForCaching(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.CachedBlocksByFileinstance and load it up by iterating content inBlockCache.static intgetMaxCachedBlocksByFile(org.apache.hadoop.conf.Configuration conf) listAllFilesNames(Map<String, HRegion> onlineRegions) static booleanshouldReplaceExistingCacheBlock(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 StringtoJSON(String filename, NavigableSet<CachedBlock> blocks) Returns A JSON String offilenameand counts ofblocksstatic StringtoJSON(BlockCache bc) Returns JSON string ofbccontent.static StringReturns JSON string ofcbsfaggregatedstatic StringtoString(CachedBlock cb, long now) Returns The block content as String.static StringtoStringMinusFileName(CachedBlock cb, long now) Returns The block content ofbcas a String minus the filename.static intvalidateBlockAddition(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 ofcbsfaggregated- Throws:
IOException
-
toJSON
Returns JSON string ofbccontent.- Throws:
IOException
-
toStringMinusFileName
Returns The block content ofbcas a String minus the filename. -
getLoadedCachedBlocksByFile
public static BlockCacheUtil.CachedBlocksByFile getLoadedCachedBlocksByFile(org.apache.hadoop.conf.Configuration conf, BlockCache bc) Get aBlockCacheUtil.CachedBlocksByFileinstance 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
-