Package org.apache.hadoop.hbase.io.hfile
Class CombinedBlockCache
java.lang.Object
org.apache.hadoop.hbase.io.hfile.CombinedBlockCache
- All Implemented Interfaces:
- Iterable<CachedBlock>,- ConfigurationObserver,- 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 SummaryNested Classes
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final CombinedBlockCache.CombinedCacheStatsprotected final FirstLevelBlockCacheprotected final BlockCacheprivate static final org.slf4j.Logger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier 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.combineCacheResults(Optional<Boolean> result1, Optional<Boolean> result2) booleanevictBlock(BlockCacheKey cacheKey) Evict block from cache.intevictBlocksByHfileName(String hfileName) Evicts all blocks for the given HFile.intevictBlocksRangeByHfileName(String hfileName, long initOffset, long endOffset) Evict all blocks for the given file name between the passed offset values.getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) Fetch block from cache.getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics, BlockType blockType) 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.Returns an Optional containing a map of regions and the percentage of how much of it has been cached so far.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.booleanAPI to check whether or not, the cache is enabled.iterator()Returns Iterator over the blocks in the cache.voidnotifyFileCachingCompleted(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).voidonConfigurationChange(org.apache.hadoop.conf.Configuration config) Allows for BlockCache implementations to provide a mean to refresh their configurations.voidsetMaxSize(long size) Sets the max heap size that can be used by the BlockCache.shouldCacheBlock(BlockCacheKey key, long maxTimeStamp, org.apache.hadoop.conf.Configuration conf) Checks whether the block represented by the given key should be cached or not.shouldCacheFile(HFileInfo hFileInfo, org.apache.hadoop.conf.Configuration conf) 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) booleanwaitForCacheInitialization(long timeout) Wait for the block cache implementation to be completely enabled.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.hadoop.hbase.io.hfile.BlockCacheisMetaBlockMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Field Details- 
l1Cache
- 
l2Cache
- 
combinedCacheStats
- 
LOG
 
- 
- 
Constructor Details- 
CombinedBlockCache
 
- 
- 
Method Details- 
heapSizeDescription copied from interface:HeapSizeReturn the approximate 'exclusive deep size' of implementing object. Includes count of payload and hosting object sizings.
- 
cacheBlockDescription copied from interface:BlockCacheAdd block to cache.- Specified by:
- cacheBlockin interface- BlockCache
- Parameters:
- cacheKey- The block's cache key.
- buf- The block contents wrapped in a ByteBuffer.
- inMemory- Whether block should be treated as in-memory
 
- 
cacheBlockpublic void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory, boolean waitWhenCache) Description copied from interface:BlockCacheAdd block to cache.- Specified by:
- cacheBlockin interface- BlockCache
- 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.
 
- 
cacheBlockDescription copied from interface:BlockCacheAdd block to cache (defaults to not in-memory).- Specified by:
- cacheBlockin interface- BlockCache
- Parameters:
- cacheKey- The block's cache key.
- buf- The object to cache.
 
- 
getBlockpublic Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) Description copied from interface:BlockCacheFetch block from cache.- Specified by:
- getBlockin interface- BlockCache
- 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.
 
- 
updateBlockMetricsprivate void updateBlockMetrics(Cacheable block, BlockCacheKey key, BlockCache cache, boolean caching) 
- 
getBlockpublic Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics, BlockType blockType) Description copied from interface:BlockCacheFetch block from cache.- Specified by:
- getBlockin interface- BlockCache
- 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.
 
- 
getBlockWithTypeprivate Cacheable getBlockWithType(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) 
- 
evictBlockDescription copied from interface:BlockCacheEvict block from cache.- Specified by:
- evictBlockin interface- BlockCache
- Parameters:
- cacheKey- Block to evict
- Returns:
- true if block existed and was evicted, false if not
 
- 
evictBlocksByHfileNameDescription copied from interface:BlockCacheEvicts all blocks for the given HFile.- Specified by:
- evictBlocksByHfileNamein interface- BlockCache
- Returns:
- the number of blocks evicted
 
- 
getStatsDescription copied from interface:BlockCacheGet the statistics for this block cache.- Specified by:
- getStatsin interface- BlockCache
 
- 
shutdownDescription copied from interface:BlockCacheShutdown the cache.- Specified by:
- shutdownin interface- BlockCache
 
- 
sizeDescription copied from interface:BlockCacheReturns the total size of the block cache, in bytes.- Specified by:
- sizein interface- BlockCache
- Returns:
- size of cache, in bytes
 
- 
getMaxSizeDescription copied from interface:BlockCacheReturns the Max size of the block cache, in bytes.- Specified by:
- getMaxSizein interface- BlockCache
- Returns:
- size of cache, in bytes
 
- 
getCurrentDataSizeDescription copied from interface:BlockCacheReturns the occupied size of data blocks, in bytes.- Specified by:
- getCurrentDataSizein interface- BlockCache
- Returns:
- occupied space in cache, in bytes
 
- 
getFreeSizeDescription copied from interface:BlockCacheReturns the free size of the block cache, in bytes.- Specified by:
- getFreeSizein interface- BlockCache
- Returns:
- free space in cache, in bytes
 
- 
getCurrentSizeDescription copied from interface:BlockCacheReturns the occupied size of the block cache, in bytes.- Specified by:
- getCurrentSizein interface- BlockCache
- Returns:
- occupied space in cache, in bytes
 
- 
getBlockCountDescription copied from interface:BlockCacheReturns the number of blocks currently cached in the block cache.- Specified by:
- getBlockCountin interface- BlockCache
- Returns:
- number of blocks in the cache
 
- 
getDataBlockCountDescription copied from interface:BlockCacheReturns the number of data blocks currently cached in the block cache.- Specified by:
- getDataBlockCountin interface- BlockCache
- Returns:
- number of blocks in the cache
 
- 
iteratorDescription copied from interface:BlockCacheReturns Iterator over the blocks in the cache.- Specified by:
- iteratorin interface- BlockCache
- Specified by:
- iteratorin interface- Iterable<CachedBlock>
 
- 
getBlockCachesDescription copied from interface:BlockCacheReturns The list of sub blockcaches that make up this one; returns null if no sub caches.- Specified by:
- getBlockCachesin interface- BlockCache
 
- 
getFullyCachedFilesReturns the list of fully cached files- Specified by:
- getFullyCachedFilesin interface- BlockCache
- Returns:
- empty optional if this method is not supported, otherwise the returned optional contains a map of all files that have been fully cached.
 
- 
getRegionCachedInfoDescription copied from interface:BlockCacheReturns an Optional containing a map of regions and the percentage of how much of it has been cached so far.- Specified by:
- getRegionCachedInfoin interface- BlockCache
- Returns:
- empty optional if this method is not supported, otherwise the returned optional contains a map of current regions caching percentage.
 
- 
setMaxSizeDescription copied from interface:ResizableBlockCacheSets the max heap size that can be used by the BlockCache.- Specified by:
- setMaxSizein interface- ResizableBlockCache
- Parameters:
- size- The max heap size.
 
- 
getRpcRefCount
- 
getFirstLevelCache
- 
getSecondLevelCache
- 
notifyFileCachingCompletedpublic 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 interface- BlockCache
- 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.
 
- 
onConfigurationChangeDescription copied from interface:BlockCacheAllows for BlockCache implementations to provide a mean to refresh their configurations. Since HBASE-29249, CacheConfig implements PropagatingConfigurationObserver and registers itself together with the used BlockCache implementation for notifications of dynamic configuration changes. The default is a noop.- Specified by:
- onConfigurationChangein interface- BlockCache
- Specified by:
- onConfigurationChangein interface- ConfigurationObserver
- Parameters:
- config- the new configuration to be updated.
 
- 
blockFitsIntoTheCacheDescription 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 interface- BlockCache
- 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.
 
- 
shouldCacheFilepublic Optional<Boolean> shouldCacheFile(HFileInfo hFileInfo, org.apache.hadoop.conf.Configuration conf) 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 interface- BlockCache
- Parameters:
- hFileInfo- Information about the file to check if it should be cached.
- conf- The configuration object to use for determining caching behavior.
- Returns:
- empty optional if this method is not supported, otherwise the returned optional contains the boolean value informing if the file should be cached.
 
- 
shouldCacheBlockpublic Optional<Boolean> shouldCacheBlock(BlockCacheKey key, long maxTimeStamp, org.apache.hadoop.conf.Configuration conf) Description copied from interface:BlockCacheChecks whether the block represented by the given key 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 block should indeed be cached.- Specified by:
- shouldCacheBlockin interface- BlockCache
- Parameters:
- key- The key representing the block to check if it should be cached.
- maxTimeStamp- The maximum timestamp for the block to check if it should be cached.
- conf- The configuration object to use for determining caching behavior.
- Returns:
- An empty Optional if this method is not supported; otherwise, the returned Optional contains the boolean value indicating if the block should be cached.
 
- 
combineCacheResults
- 
isAlreadyCachedDescription 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 interface- BlockCache
- 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.
 
- 
getBlockSizeDescription 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 interface- BlockCache
- 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.
 
- 
evictBlocksRangeByHfileNameDescription copied from interface:BlockCacheEvict all blocks for the given file name between the passed offset values.- Specified by:
- evictBlocksRangeByHfileNamein interface- BlockCache
- 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.
 
- 
waitForCacheInitializationDescription copied from interface:BlockCacheWait for the block cache implementation to be completely enabled. Some block cache implementations may take longer to initialise, and this initialisation may be asynchronous.- Specified by:
- waitForCacheInitializationin interface- BlockCache
- Parameters:
- timeout- time to wait for the cache to become enabled.
- Returns:
- boolean true if the cache is enabled, false otherwise.
 
- 
isCacheEnabledDescription copied from interface:BlockCacheAPI to check whether or not, the cache is enabled.- Specified by:
- isCacheEnabledin interface- BlockCache
- Returns:
- returns true if the cache is enabled, false otherwise.
 
 
-