@InterfaceAudience.Private public class CombinedBlockCache extends Object implements ResizableBlockCache, HeapSize
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.Modifier and Type | Class and Description |
---|---|
static class |
CombinedBlockCache.CombinedCacheStats |
Modifier and Type | Field and Description |
---|---|
protected CombinedBlockCache.CombinedCacheStats |
combinedCacheStats |
protected FirstLevelBlockCache |
l1Cache |
protected BlockCache |
l2Cache |
private static org.slf4j.Logger |
LOG |
Constructor and Description |
---|
CombinedBlockCache(FirstLevelBlockCache l1Cache,
BlockCache l2Cache) |
Modifier and Type | Method and Description |
---|---|
Optional<Boolean> |
blockFitsIntoTheCache(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.
|
Cacheable |
getBlock(BlockCacheKey cacheKey,
boolean caching,
boolean repeat,
boolean updateCacheMetrics)
Fetch block from cache.
|
Cacheable |
getBlock(BlockCacheKey cacheKey,
boolean caching,
boolean repeat,
boolean updateCacheMetrics,
BlockType blockType)
Fetch block from cache.
|
BlockCache[] |
getBlockCaches()
Returns The list of sub blockcaches that make up this one; returns null if no sub caches.
|
long |
getBlockCount()
Returns the number of blocks currently cached in the block cache.
|
Optional<Integer> |
getBlockSize(BlockCacheKey key)
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 |
getCurrentDataSize()
Returns the occupied size of data blocks, in bytes.
|
long |
getCurrentSize()
Returns the occupied size of the block cache, in bytes.
|
long |
getDataBlockCount()
Returns the number of data blocks currently cached in the block cache.
|
FirstLevelBlockCache |
getFirstLevelCache() |
long |
getFreeSize()
Returns the free size of the block cache, in bytes.
|
Optional<Map<String,Pair<String,Long>>> |
getFullyCachedFiles()
Returns the list of fully cached files
|
long |
getMaxSize()
Returns the Max size of the block cache, in bytes.
|
Optional<Map<String,Long>> |
getRegionCachedInfo()
Returns an Optional containing a map of regions and the percentage of how much of it has been
cached so far.
|
int |
getRpcRefCount(BlockCacheKey cacheKey) |
BlockCache |
getSecondLevelCache() |
CacheStats |
getStats()
Get the statistics for this block cache.
|
long |
heapSize()
Return the approximate 'exclusive deep size' of implementing object.
|
Optional<Boolean> |
isAlreadyCached(BlockCacheKey key)
Checks whether the block for the passed key is already cached.
|
Iterator<CachedBlock> |
iterator()
Returns Iterator over the blocks in the cache.
|
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).
|
void |
setMaxSize(long size)
Sets the max heap size that can be used by the BlockCache.
|
Optional<Boolean> |
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) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isMetaBlock
forEach, spliterator
protected final FirstLevelBlockCache l1Cache
protected final BlockCache l2Cache
protected final CombinedBlockCache.CombinedCacheStats combinedCacheStats
private static final org.slf4j.Logger LOG
public CombinedBlockCache(FirstLevelBlockCache l1Cache, BlockCache l2Cache)
public long heapSize()
HeapSize
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory)
BlockCache
cacheBlock
in interface BlockCache
cacheKey
- The block's cache key.buf
- The block contents wrapped in a ByteBuffer.inMemory
- Whether block should be treated as in-memorypublic void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory, boolean waitWhenCache)
BlockCache
cacheBlock
in interface BlockCache
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.public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf)
BlockCache
cacheBlock
in interface BlockCache
cacheKey
- The block's cache key.buf
- The object to cache.public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics)
BlockCache
getBlock
in interface BlockCache
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 notprivate void updateBlockMetrics(Cacheable block, BlockCacheKey key, BlockCache cache, boolean caching)
public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics, BlockType blockType)
BlockCache
getBlock
in interface BlockCache
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
- BlockTypeprivate Cacheable getBlockWithType(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics)
public boolean evictBlock(BlockCacheKey cacheKey)
BlockCache
evictBlock
in interface BlockCache
cacheKey
- Block to evictpublic int evictBlocksByHfileName(String hfileName)
BlockCache
evictBlocksByHfileName
in interface BlockCache
public CacheStats getStats()
BlockCache
getStats
in interface BlockCache
public void shutdown()
BlockCache
shutdown
in interface BlockCache
public long size()
BlockCache
size
in interface BlockCache
public long getMaxSize()
BlockCache
getMaxSize
in interface BlockCache
public long getCurrentDataSize()
BlockCache
getCurrentDataSize
in interface BlockCache
public long getFreeSize()
BlockCache
getFreeSize
in interface BlockCache
public long getCurrentSize()
BlockCache
getCurrentSize
in interface BlockCache
public long getBlockCount()
BlockCache
getBlockCount
in interface BlockCache
public long getDataBlockCount()
BlockCache
getDataBlockCount
in interface BlockCache
public Iterator<CachedBlock> iterator()
BlockCache
iterator
in interface Iterable<CachedBlock>
iterator
in interface BlockCache
public BlockCache[] getBlockCaches()
BlockCache
getBlockCaches
in interface BlockCache
public Optional<Map<String,Pair<String,Long>>> getFullyCachedFiles()
getFullyCachedFiles
in interface BlockCache
public Optional<Map<String,Long>> getRegionCachedInfo()
BlockCache
getRegionCachedInfo
in interface BlockCache
public void setMaxSize(long size)
ResizableBlockCache
setMaxSize
in interface ResizableBlockCache
size
- The max heap size.public int getRpcRefCount(BlockCacheKey cacheKey)
public FirstLevelBlockCache getFirstLevelCache()
public BlockCache getSecondLevelCache()
public void notifyFileCachingCompleted(org.apache.hadoop.fs.Path fileName, int totalBlockCount, int dataBlockCount, long size)
BlockCache
notifyFileCachingCompleted
in interface BlockCache
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.public Optional<Boolean> blockFitsIntoTheCache(HFileBlock block)
BlockCache
blockFitsIntoTheCache
in interface BlockCache
block
- the block we want to check if fits into the cache.public Optional<Boolean> shouldCacheFile(String fileName)
BlockCache
shouldCacheFile
in interface BlockCache
fileName
- to check if it should be cached.public Optional<Boolean> isAlreadyCached(BlockCacheKey key)
BlockCache
isAlreadyCached
in interface BlockCache
key
- for the block we want to check if it's already in the cache.public Optional<Integer> getBlockSize(BlockCacheKey key)
BlockCache
getBlockSize
in interface BlockCache
key
- for the block we want to check if it's already in the cache.Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.