Package org.apache.hadoop.hbase.io.hfile
Class CombinedBlockCache
java.lang.Object
org.apache.hadoop.hbase.io.hfile.CombinedBlockCache
- All Implemented Interfaces:
Iterable<CachedBlock>,HeapSize,BlockCache,ResizableBlockCache
- Direct Known Subclasses:
InclusiveCombinedBlockCache
CombinedBlockCache is an abstraction layer that combines
FirstLevelBlockCache and
BucketCache. The smaller lruCache is used to cache bloom blocks and index blocks. The
larger Cache is used to cache data blocks.
getBlock(BlockCacheKey, boolean, boolean, boolean) reads first from the smaller l1Cache
before looking for the block in the l2Cache. Blocks evicted from l1Cache are put into the bucket
cache. Metrics are the combined size and hits and misses of both caches.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CombinedBlockCache.CombinedCacheStatsprotected final FirstLevelBlockCacheprotected final BlockCacheprivate static final org.slf4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionblockFitsIntoTheCache(HFileBlock block) Checks whether there's enough space left in the cache to accommodate the passed block.voidcacheBlock(BlockCacheKey cacheKey, Cacheable buf) Add block to cache (defaults to not in-memory).voidcacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory) Add block to cache.voidcacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory, boolean waitWhenCache) Add block to cache.booleanevictBlock(BlockCacheKey cacheKey) Evict block from cache.intevictBlocksByHfileName(String hfileName) Evicts all blocks for the given HFile.getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) Fetch block from cache.Returns The list of sub blockcaches that make up this one; returns null if no sub caches.longReturns the number of blocks currently cached in the block cache.Returns an Optional containing the size of the block related to the passed key.private CacheablegetBlockWithType(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) longReturns the occupied size of data blocks, in bytes.longReturns the occupied size of the block cache, in bytes.longReturns the number of data blocks currently cached in the block cache.longReturns the free size of the block cache, in bytes.Returns the list of fully cached fileslongReturns the Max size of the block cache, in bytes.intgetRpcRefCount(BlockCacheKey cacheKey) getStats()Get the statistics for this block cache.longheapSize()Return the approximate 'exclusive deep size' of implementing object.Checks whether the block for the passed key is already cached.iterator()Returns Iterator over the blocks in the cache.voidnotifyFileBlockEvicted(String fileName) Notifies the cache implementation that the given file had a block evictedvoidnotifyFileCachingCompleted(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).voidsetMaxSize(long size) Sets the max heap size that can be used by the BlockCache.shouldCacheFile(String fileName) Checks whether blocks for the passed file should be cached or not.voidshutdown()Shutdown the cache.longsize()Returns the total size of the block cache, in bytes.private voidupdateBlockMetrics(Cacheable block, BlockCacheKey key, BlockCache cache, boolean caching) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.hbase.io.hfile.BlockCache
isMetaBlockMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
l1Cache
-
l2Cache
-
combinedCacheStats
-
LOG
-
-
Constructor Details
-
CombinedBlockCache
-
-
Method Details
-
heapSize
Description copied from interface:HeapSizeReturn the approximate 'exclusive deep size' of implementing object. Includes count of payload and hosting object sizings. -
cacheBlock
Description copied from interface:BlockCacheAdd block to cache.- Specified by:
cacheBlockin interfaceBlockCache- 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
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory, boolean waitWhenCache) Description copied from interface:BlockCacheAdd block to cache.- Specified by:
cacheBlockin interfaceBlockCache- Parameters:
cacheKey- The block's cache key.buf- The block contents wrapped in a ByteBuffer.inMemory- Whether block should be treated as in-memorywaitWhenCache- Whether to wait for the cache to be flushed mainly when BucketCache is configured.
-
cacheBlock
Description copied from interface:BlockCacheAdd block to cache (defaults to not in-memory).- Specified by:
cacheBlockin interfaceBlockCache- Parameters:
cacheKey- The block's cache key.buf- The object to cache.
-
getBlock
public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) Description copied from interface:BlockCacheFetch block from cache.- Specified by:
getBlockin interfaceBlockCache- 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.
-
updateBlockMetrics
private void updateBlockMetrics(Cacheable block, BlockCacheKey key, BlockCache cache, boolean caching) -
getBlockWithType
private Cacheable getBlockWithType(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) -
evictBlock
Description copied from interface:BlockCacheEvict block from cache.- Specified by:
evictBlockin interfaceBlockCache- Parameters:
cacheKey- Block to evict- Returns:
- true if block existed and was evicted, false if not
-
evictBlocksByHfileName
Description copied from interface:BlockCacheEvicts all blocks for the given HFile.- Specified by:
evictBlocksByHfileNamein interfaceBlockCache- Returns:
- the number of blocks evicted
-
getStats
Description copied from interface:BlockCacheGet the statistics for this block cache.- Specified by:
getStatsin interfaceBlockCache
-
shutdown
Description copied from interface:BlockCacheShutdown the cache.- Specified by:
shutdownin interfaceBlockCache
-
size
Description copied from interface:BlockCacheReturns the total size of the block cache, in bytes.- Specified by:
sizein interfaceBlockCache- Returns:
- size of cache, in bytes
-
getMaxSize
Description copied from interface:BlockCacheReturns the Max size of the block cache, in bytes.- Specified by:
getMaxSizein interfaceBlockCache- Returns:
- size of cache, in bytes
-
getCurrentDataSize
Description copied from interface:BlockCacheReturns the occupied size of data blocks, in bytes.- Specified by:
getCurrentDataSizein interfaceBlockCache- Returns:
- occupied space in cache, in bytes
-
getFreeSize
Description copied from interface:BlockCacheReturns the free size of the block cache, in bytes.- Specified by:
getFreeSizein interfaceBlockCache- Returns:
- free space in cache, in bytes
-
getCurrentSize
Description copied from interface:BlockCacheReturns the occupied size of the block cache, in bytes.- Specified by:
getCurrentSizein interfaceBlockCache- Returns:
- occupied space in cache, in bytes
-
getBlockCount
Description copied from interface:BlockCacheReturns the number of blocks currently cached in the block cache.- Specified by:
getBlockCountin interfaceBlockCache- Returns:
- number of blocks in the cache
-
getDataBlockCount
Description copied from interface:BlockCacheReturns the number of data blocks currently cached in the block cache.- Specified by:
getDataBlockCountin interfaceBlockCache- Returns:
- number of blocks in the cache
-
iterator
Description copied from interface:BlockCacheReturns Iterator over the blocks in the cache.- Specified by:
iteratorin interfaceBlockCache- Specified by:
iteratorin interfaceIterable<CachedBlock>
-
getBlockCaches
Description copied from interface:BlockCacheReturns The list of sub blockcaches that make up this one; returns null if no sub caches.- Specified by:
getBlockCachesin interfaceBlockCache
-
getFullyCachedFiles
Returns the list of fully cached files- Specified by:
getFullyCachedFilesin interfaceBlockCache- Returns:
- empty optional if this method is not supported, otherwise the returned optional contains a map of all files that have been fully cached.
-
setMaxSize
Description copied from interface:ResizableBlockCacheSets the max heap size that can be used by the BlockCache.- Specified by:
setMaxSizein interfaceResizableBlockCache- Parameters:
size- The max heap size.
-
getRpcRefCount
-
getFirstLevelCache
-
getSecondLevelCache
-
notifyFileCachingCompleted
public void notifyFileCachingCompleted(org.apache.hadoop.fs.Path fileName, int totalBlockCount, int dataBlockCount, long size) Description copied from interface:BlockCacheNotifies the cache implementation that the given file has been fully cached (all its blocks made into the cache).- Specified by:
notifyFileCachingCompletedin interfaceBlockCache- Parameters:
fileName- the file that has been completely cached.
-
notifyFileBlockEvicted
Description copied from interface:BlockCacheNotifies the cache implementation that the given file had a block evicted- Specified by:
notifyFileBlockEvictedin interfaceBlockCache- Parameters:
fileName- the file had a block evicted.
-
blockFitsIntoTheCache
Description copied from interface:BlockCacheChecks 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.- Specified by:
blockFitsIntoTheCachein interfaceBlockCache- 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
Description copied from interface:BlockCacheChecks 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.- Specified by:
shouldCacheFilein interfaceBlockCache- 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
Description copied from interface:BlockCacheChecks 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.- Specified by:
isAlreadyCachedin interfaceBlockCache- 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
Description copied from interface:BlockCacheReturns 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.- Specified by:
getBlockSizein interfaceBlockCache- 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.
-