Interface BlockCache

All Superinterfaces:
Iterable<CachedBlock>
All Known Subinterfaces:
FirstLevelBlockCache, ResizableBlockCache
All Known Implementing Classes:
BucketCache, CombinedBlockCache, InclusiveCombinedBlockCache, IndexOnlyLruBlockCache, LruAdaptiveBlockCache, LruBlockCache, MemcachedBlockCache, TinyLfuBlockCache

@Private public interface BlockCache extends Iterable<CachedBlock>
Block cache interface. Anything that implements the Cacheable interface can be put in the cache.
  • Method Details

    • cacheBlock

      void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory)
      Add block to cache.
      Parameters:
      cacheKey - The block's cache key.
      buf - The block contents wrapped in a ByteBuffer.
      inMemory - Whether block should be treated as in-memory
    • cacheBlock

      default void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory, boolean waitWhenCache)
      Add block to cache.
      Parameters:
      cacheKey - The block's cache key.
      buf - The block contents wrapped in a ByteBuffer.
      inMemory - Whether block should be treated as in-memory
      waitWhenCache - Whether to wait for the cache to be flushed mainly when BucketCache is configured.
    • cacheBlock

      void cacheBlock(BlockCacheKey cacheKey, Cacheable buf)
      Add block to cache (defaults to not in-memory).
      Parameters:
      cacheKey - The block's cache key.
      buf - The object to cache.
    • getBlock

      Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics)
      Fetch block from cache.
      Parameters:
      cacheKey - Block to fetch.
      caching - Whether this request has caching enabled (used for stats)
      repeat - Whether this is a repeat lookup for the same block (used to avoid double counting cache misses when doing double-check locking)
      updateCacheMetrics - Whether to update cache metrics or not
      Returns:
      Block or null if block is not in 2 cache.
    • getBlock

      default Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics, BlockType blockType)
      Fetch block from cache.
      Parameters:
      cacheKey - Block to fetch.
      caching - Whether this request has caching enabled (used for stats)
      repeat - Whether this is a repeat lookup for the same block (used to avoid double counting cache misses when doing double-check locking)
      updateCacheMetrics - Whether to update cache metrics or not
      blockType - BlockType
      Returns:
      Block or null if block is not in 2 cache.
    • evictBlock

      boolean evictBlock(BlockCacheKey cacheKey)
      Evict block from cache.
      Parameters:
      cacheKey - Block to evict
      Returns:
      true if block existed and was evicted, false if not
    • evictBlocksByHfileName

      Evicts all blocks for the given HFile.
      Returns:
      the number of blocks evicted
    • getStats

      Get the statistics for this block cache.
    • shutdown

      void shutdown()
      Shutdown the cache.
    • size

      long size()
      Returns the total size of the block cache, in bytes.
      Returns:
      size of cache, in bytes
    • getMaxSize

      long getMaxSize()
      Returns the Max size of the block cache, in bytes.
      Returns:
      size of cache, in bytes
    • getFreeSize

      long getFreeSize()
      Returns the free size of the block cache, in bytes.
      Returns:
      free space in cache, in bytes
    • getCurrentSize

      Returns the occupied size of the block cache, in bytes.
      Returns:
      occupied space in cache, in bytes
    • getCurrentDataSize

      Returns the occupied size of data blocks, in bytes.
      Returns:
      occupied space in cache, in bytes
    • getBlockCount

      Returns the number of blocks currently cached in the block cache.
      Returns:
      number of blocks in the cache
    • getDataBlockCount

      Returns the number of data blocks currently cached in the block cache.
      Returns:
      number of blocks in the cache
    • iterator

      Returns Iterator over the blocks in the cache.
      Specified by:
      iterator in interface Iterable<CachedBlock>
    • getBlockCaches

      Returns The list of sub blockcaches that make up this one; returns null if no sub caches.
    • isMetaBlock

      default boolean isMetaBlock(BlockType blockType)
      Check if block type is meta or index block
      Parameters:
      blockType - block type of a given HFile block
      Returns:
      true if block type is non-data block
    • notifyFileCachingCompleted

      default void notifyFileCachingCompleted(org.apache.hadoop.fs.Path fileName, int totalBlockCount, int dataBlockCount, long size)
      Notifies the cache implementation that the given file has been fully cached (all its blocks made into the cache).
      Parameters:
      fileName - the file that has been completely cached.
      totalBlockCount - the total of blocks cached for this file.
      dataBlockCount - number of DATA block type cached.
      size - the size, in bytes, cached.
    • blockFitsIntoTheCache

      Checks whether there's enough space left in the cache to accommodate the passed block. This method may not be overridden by all implementing classes. In such cases, the returned Optional will be empty. For subclasses implementing this logic, the returned Optional would contain the boolean value reflecting if the passed block fits into the remaining cache space available.
      Parameters:
      block - the block we want to check if fits into the cache.
      Returns:
      empty optional if this method is not supported, otherwise the returned optional contains the boolean value informing if the block fits into the cache available space.
    • shouldCacheFile

      default Optional<Boolean> shouldCacheFile(String fileName)
      Checks whether blocks for the passed file should be cached or not. This method may not be overridden by all implementing classes. In such cases, the returned Optional will be empty. For subclasses implementing this logic, the returned Optional would contain the boolean value reflecting if the passed file should indeed be cached.
      Parameters:
      fileName - to check if it should be cached.
      Returns:
      empty optional if this method is not supported, otherwise the returned optional contains the boolean value informing if the file should be cached.
    • isAlreadyCached

      Checks whether the block for the passed key is already cached. This method may not be overridden by all implementing classes. In such cases, the returned Optional will be empty. For subclasses implementing this logic, the returned Optional would contain the boolean value reflecting if the block for the passed key is already cached or not.
      Parameters:
      key - for the block we want to check if it's already in the cache.
      Returns:
      empty optional if this method is not supported, otherwise the returned optional contains the boolean value informing if the block is already cached.
    • getBlockSize

      Returns an Optional containing the size of the block related to the passed key. If the block is not in the cache, returned optional will be empty. Also, this method may not be overridden by all implementing classes. In such cases, the returned Optional will be empty.
      Parameters:
      key - for the block we want to check if it's already in the cache.
      Returns:
      empty optional if this method is not supported, otherwise the returned optional contains the boolean value informing if the block is already cached.
    • getFullyCachedFiles

      Returns an Optional containing the map of files that have been fully cached (all its blocks are present in the cache. This method may not be overridden by all implementing classes. In such cases, the returned Optional will be empty.
      Returns:
      empty optional if this method is not supported, otherwise the returned optional contains a map of all files that have been fully cached.
    • getRegionCachedInfo

      Returns an Optional containing a map of regions and the percentage of how much of it has been cached so far.
      Returns:
      empty optional if this method is not supported, otherwise the returned optional contains a map of current regions caching percentage.
    • evictBlocksRangeByHfileName

      default int evictBlocksRangeByHfileName(String hfileName, long initOffset, long endOffset)
      Evict all blocks for the given file name between the passed offset values.
      Parameters:
      hfileName - The file for which blocks should be evicted.
      initOffset - the initial offset for the range of blocks to be evicted.
      endOffset - the end offset for the range of blocks to be evicted.
      Returns:
      number of blocks evicted.
    • isCacheEnabled

      default boolean isCacheEnabled()
      API to check whether or not, the cache is enabled.
      Returns:
      returns true if the cache is enabled, false otherwise.
    • waitForCacheInitialization

      default boolean waitForCacheInitialization(long timeout)
      Wait for the bucket cache to be enabled while server restart
      Parameters:
      timeout - time to wait for the bucket cache to be enable
      Returns:
      boolean true if the bucket cache is enabled, false otherwise