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 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.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.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) -
getBlock
public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics, BlockType blockType) 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 notblockType- BlockType- Returns:
- Block or null if block is not in 2 cache.
-
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.
-
getRegionCachedInfo
Description 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 interfaceBlockCache- Returns:
- empty optional if this method is not supported, otherwise the returned optional contains a map of current regions caching percentage.
-
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.totalBlockCount- the total of blocks cached for this file.dataBlockCount- number of DATA block type cached.size- the size, in bytes, cached.
-
onConfigurationChange
Description 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 interfaceBlockCache- Specified by:
onConfigurationChangein interfaceConfigurationObserver- Parameters:
config- the new configuration to be updated.
-
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
public 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 interfaceBlockCache- 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.
-
shouldCacheBlock
public 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 interfaceBlockCache- 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
-
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.
-
evictBlocksRangeByHfileName
Description copied from interface:BlockCacheEvict all blocks for the given file name between the passed offset values.- Specified by:
evictBlocksRangeByHfileNamein interfaceBlockCache- 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.
-
waitForCacheInitialization
Description 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 interfaceBlockCache- Parameters:
timeout- time to wait for the cache to become enabled.- Returns:
- boolean true if the cache is enabled, false otherwise.
-
isCacheEnabled
Description copied from interface:BlockCacheAPI to check whether or not, the cache is enabled.- Specified by:
isCacheEnabledin interfaceBlockCache- Returns:
- returns true if the cache is enabled, false otherwise.
-