Class BlockCacheUtil

java.lang.Object
org.apache.hadoop.hbase.io.hfile.BlockCacheUtil

@Private public class BlockCacheUtil extends Object
Utilty for aggregating counts in CachedBlocks and toString/toJSON CachedBlocks and BlockCaches. No attempt has been made at making this thread safe.
  • Field Details

  • Constructor Details

  • Method Details

    • toString

      public static String toString(CachedBlock cb, long now)
      Returns The block content as String.
    • toJSON

      public static String toJSON(String filename, NavigableSet<CachedBlock> blocks) throws IOException
      Returns A JSON String of filename and counts of blocks
      Throws:
      IOException
    • toJSON

      Returns JSON string of cbsf aggregated
      Throws:
      IOException
    • toJSON

      public static String toJSON(BlockCache bc) throws IOException
      Returns JSON string of bc content.
      Throws:
      IOException
    • toStringMinusFileName

      public static String toStringMinusFileName(CachedBlock cb, long now)
      Returns The block content of bc as a String minus the filename.
    • getLoadedCachedBlocksByFile

      public static BlockCacheUtil.CachedBlocksByFile getLoadedCachedBlocksByFile(org.apache.hadoop.conf.Configuration conf, BlockCache bc)
      Get a BlockCacheUtil.CachedBlocksByFile instance and load it up by iterating content in BlockCache.
      Parameters:
      conf - Used to read configurations
      bc - 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 check
      cacheKey - the block cache key
      newBlock - 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

      public static Set<String> listAllFilesNames(Map<String,HRegion> onlineRegions)
    • getMaxCachedBlocksByFile

      public static int getMaxCachedBlocksByFile(org.apache.hadoop.conf.Configuration conf)
    • getBlockForCaching

      public static HFileBlock getBlockForCaching(CacheConfig cacheConf, HFileBlock block)
      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

      public static HFileContext cloneContext(HFileContext context)