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
-
Field Summary
Modifier and TypeFieldDescriptionprotected final CombinedBlockCache.CombinedCacheStats
protected final FirstLevelBlockCache
protected final BlockCache
private static final org.slf4j.Logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionblockFitsIntoTheCache
(HFileBlock block) Checks whether there's enough space left in the cache to accommodate the passed block.void
cacheBlock
(BlockCacheKey cacheKey, Cacheable buf) Add block to cache (defaults to not in-memory).void
cacheBlock
(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory) Add block to cache.void
cacheBlock
(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory, boolean waitWhenCache) Add block to cache.boolean
evictBlock
(BlockCacheKey cacheKey) Evict block from cache.int
evictBlocksByHfileName
(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.long
Returns 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 Cacheable
getBlockWithType
(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) long
Returns the occupied size of data blocks, in bytes.long
Returns the occupied size of the block cache, in bytes.long
Returns the number of data blocks currently cached in the block cache.long
Returns the free size of the block cache, in bytes.Returns the list of fully cached fileslong
Returns the Max size of the block cache, in bytes.int
getRpcRefCount
(BlockCacheKey cacheKey) getStats()
Get the statistics for this block cache.long
heapSize()
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.void
notifyFileBlockEvicted
(String fileName) Notifies the cache implementation that the given file had a block evictedvoid
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).void
setMaxSize
(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.void
shutdown()
Shutdown the cache.long
size()
Returns the total size of the block cache, in bytes.private void
updateBlockMetrics
(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, wait
Methods inherited from interface org.apache.hadoop.hbase.io.hfile.BlockCache
isMetaBlock
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
l1Cache
-
l2Cache
-
combinedCacheStats
-
LOG
-
-
Constructor Details
-
CombinedBlockCache
-
-
Method Details
-
heapSize
Description copied from interface:HeapSize
Return the approximate 'exclusive deep size' of implementing object. Includes count of payload and hosting object sizings. -
cacheBlock
Description copied from interface:BlockCache
Add block to cache.- Specified by:
cacheBlock
in 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:BlockCache
Add block to cache.- Specified by:
cacheBlock
in 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:BlockCache
Add block to cache (defaults to not in-memory).- Specified by:
cacheBlock
in 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:BlockCache
Fetch block from cache.- Specified by:
getBlock
in 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:BlockCache
Evict block from cache.- Specified by:
evictBlock
in interfaceBlockCache
- Parameters:
cacheKey
- Block to evict- Returns:
- true if block existed and was evicted, false if not
-
evictBlocksByHfileName
Description copied from interface:BlockCache
Evicts all blocks for the given HFile.- Specified by:
evictBlocksByHfileName
in interfaceBlockCache
- Returns:
- the number of blocks evicted
-
getStats
Description copied from interface:BlockCache
Get the statistics for this block cache.- Specified by:
getStats
in interfaceBlockCache
-
shutdown
Description copied from interface:BlockCache
Shutdown the cache.- Specified by:
shutdown
in interfaceBlockCache
-
size
Description copied from interface:BlockCache
Returns the total size of the block cache, in bytes.- Specified by:
size
in interfaceBlockCache
- Returns:
- size of cache, in bytes
-
getMaxSize
Description copied from interface:BlockCache
Returns the Max size of the block cache, in bytes.- Specified by:
getMaxSize
in interfaceBlockCache
- Returns:
- size of cache, in bytes
-
getCurrentDataSize
Description copied from interface:BlockCache
Returns the occupied size of data blocks, in bytes.- Specified by:
getCurrentDataSize
in interfaceBlockCache
- Returns:
- occupied space in cache, in bytes
-
getFreeSize
Description copied from interface:BlockCache
Returns the free size of the block cache, in bytes.- Specified by:
getFreeSize
in interfaceBlockCache
- Returns:
- free space in cache, in bytes
-
getCurrentSize
Description copied from interface:BlockCache
Returns the occupied size of the block cache, in bytes.- Specified by:
getCurrentSize
in interfaceBlockCache
- Returns:
- occupied space in cache, in bytes
-
getBlockCount
Description copied from interface:BlockCache
Returns the number of blocks currently cached in the block cache.- Specified by:
getBlockCount
in interfaceBlockCache
- Returns:
- number of blocks in the cache
-
getDataBlockCount
Description copied from interface:BlockCache
Returns the number of data blocks currently cached in the block cache.- Specified by:
getDataBlockCount
in interfaceBlockCache
- Returns:
- number of blocks in the cache
-
iterator
Description copied from interface:BlockCache
Returns Iterator over the blocks in the cache.- Specified by:
iterator
in interfaceBlockCache
- Specified by:
iterator
in interfaceIterable<CachedBlock>
-
getBlockCaches
Description copied from interface:BlockCache
Returns The list of sub blockcaches that make up this one; returns null if no sub caches.- Specified by:
getBlockCaches
in interfaceBlockCache
-
getFullyCachedFiles
Returns the list of fully cached files- Specified by:
getFullyCachedFiles
in 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:ResizableBlockCache
Sets the max heap size that can be used by the BlockCache.- Specified by:
setMaxSize
in 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:BlockCache
Notifies the cache implementation that the given file has been fully cached (all its blocks made into the cache).- Specified by:
notifyFileCachingCompleted
in interfaceBlockCache
- Parameters:
fileName
- the file that has been completely cached.
-
notifyFileBlockEvicted
Description copied from interface:BlockCache
Notifies the cache implementation that the given file had a block evicted- Specified by:
notifyFileBlockEvicted
in interfaceBlockCache
- Parameters:
fileName
- the file had a block evicted.
-
blockFitsIntoTheCache
Description copied from interface:BlockCache
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.- Specified by:
blockFitsIntoTheCache
in 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:BlockCache
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.- Specified by:
shouldCacheFile
in 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:BlockCache
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.- Specified by:
isAlreadyCached
in 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:BlockCache
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.- Specified by:
getBlockSize
in 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.
-