@InterfaceAudience.Private public class BucketCache extends Object implements BlockCache, HeapSize
BucketAllocator to allocate/free blocks, and uses
BucketCache#ramCache and BucketCache#backingMap in order to
determine if a given element is in the cache. The bucket cache can use on-heap or
off-heap memory ByteBufferIOEngine or in a file FileIOEngine to
store/read the block data.
Eviction is via a similar algorithm as used in
LruBlockCache
BucketCache can be used as mainly a block cache (see
CombinedBlockCache), combined with
LruBlockCache to decrease CMS GC and heap fragmentation.
It also can be used as a secondary cache (e.g. using a file on ssd/fusionio to store
blocks) to enlarge cache space via
LruBlockCache.setVictimCache(org.apache.hadoop.hbase.io.hfile.BlockCache)
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_ERROR_TOLERATION_DURATION |
| 构造器和说明 |
|---|
BucketCache(String ioEngineName,
long capacity,
int blockSize,
int[] bucketSizes,
int writerThreadNum,
int writerQLen,
String persistencePath) |
BucketCache(String ioEngineName,
long capacity,
int blockSize,
int[] bucketSizes,
int writerThreadNum,
int writerQLen,
String persistencePath,
int ioErrorsTolerationDuration,
org.apache.hadoop.conf.Configuration conf) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
cacheBlock(BlockCacheKey cacheKey,
Cacheable buf)
Cache the block with the specified name and buffer.
|
void |
cacheBlock(BlockCacheKey cacheKey,
Cacheable cachedItem,
boolean inMemory)
Cache the block with the specified name and buffer.
|
boolean |
evictBlock(BlockCacheKey cacheKey)
Evict block from cache.
|
boolean |
evictBlock(BlockCacheKey cacheKey,
boolean deletedBlock) |
int |
evictBlocksByHfileName(String hfileName)
Evicts all blocks for a specific HFile.
|
BucketAllocator |
getAllocator() |
Cacheable |
getBlock(BlockCacheKey key,
boolean caching,
boolean repeat,
boolean updateCacheMetrics)
Get the buffer of the block with the specified key.
|
BlockCache[] |
getBlockCaches() |
long |
getBlockCount()
Returns the number of blocks currently cached in the block cache.
|
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.
|
long |
getFreeSize()
Returns the free size of the block cache, in bytes.
|
String |
getIoEngine() |
long |
getMaxSize()
Returns the Max size of the block cache, in bytes.
|
long |
getRealCacheSize() |
int |
getRefCount(BlockCacheKey cacheKey) |
CacheStats |
getStats()
Get the statistics for this block cache.
|
long |
heapSize() |
Iterator<CachedBlock> |
iterator() |
void |
logStats() |
void |
returnBlock(BlockCacheKey cacheKey,
Cacheable block)
Called when the scanner using the block decides to return the block once its usage
is over.
|
void |
shutdown()
Shutdown the cache.
|
long |
size()
Returns the total size of the block cache, in bytes.
|
protected void |
startWriterThreads()
Called by the constructor to start the writer threads.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static final int DEFAULT_ERROR_TOLERATION_DURATION
public BucketCache(String ioEngineName, long capacity, int blockSize, int[] bucketSizes, int writerThreadNum, int writerQLen, String persistencePath) throws FileNotFoundException, IOException
public BucketCache(String ioEngineName, long capacity, int blockSize, int[] bucketSizes, int writerThreadNum, int writerQLen, String persistencePath, int ioErrorsTolerationDuration, org.apache.hadoop.conf.Configuration conf) throws FileNotFoundException, IOException
protected void startWriterThreads()
public long getMaxSize()
BlockCachegetMaxSize 在接口中 BlockCachepublic String getIoEngine()
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf)
cacheBlock 在接口中 BlockCachecacheKey - block's cache keybuf - block bufferpublic void cacheBlock(BlockCacheKey cacheKey, Cacheable cachedItem, boolean inMemory)
cacheBlock 在接口中 BlockCachecacheKey - block's cache keycachedItem - block bufferinMemory - if block is in-memorypublic Cacheable getBlock(BlockCacheKey key, boolean caching, boolean repeat, boolean updateCacheMetrics)
getBlock 在接口中 BlockCachekey - block's cache keycaching - true if the caller caches blocks on cache missesrepeat - Whether this is a repeat lookup for the same blockupdateCacheMetrics - Whether we should update cache metrics or notpublic boolean evictBlock(BlockCacheKey cacheKey)
BlockCacheevictBlock 在接口中 BlockCachecacheKey - Block to evictpublic boolean evictBlock(BlockCacheKey cacheKey, boolean deletedBlock)
public void logStats()
public long getRealCacheSize()
public void shutdown()
BlockCacheshutdown 在接口中 BlockCachepublic CacheStats getStats()
BlockCachegetStats 在接口中 BlockCachepublic BucketAllocator getAllocator()
public long size()
BlockCachesize 在接口中 BlockCachepublic long getCurrentDataSize()
BlockCachegetCurrentDataSize 在接口中 BlockCachepublic long getFreeSize()
BlockCachegetFreeSize 在接口中 BlockCachepublic long getBlockCount()
BlockCachegetBlockCount 在接口中 BlockCachepublic long getDataBlockCount()
BlockCachegetDataBlockCount 在接口中 BlockCachepublic long getCurrentSize()
BlockCachegetCurrentSize 在接口中 BlockCachepublic int evictBlocksByHfileName(String hfileName)
This is used for evict-on-close to remove all blocks of a specific HFile.
evictBlocksByHfileName 在接口中 BlockCachepublic Iterator<CachedBlock> iterator()
iterator 在接口中 Iterable<CachedBlock>iterator 在接口中 BlockCachepublic BlockCache[] getBlockCaches()
getBlockCaches 在接口中 BlockCachepublic void returnBlock(BlockCacheKey cacheKey, Cacheable block)
BlockCacheCacheable.MemoryType.returnBlock 在接口中 BlockCachecacheKey - the cache key of the blockblock - the hfileblock to be returnedpublic int getRefCount(BlockCacheKey cacheKey)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.