@InterfaceAudience.Private public class BucketCache extends Object implements BlockCache, HeapSize
BucketAllocator to allocate/free block, and use
ramCache and backingMap in order to
determine whether a given element hit. It could uses memory
ByteBufferIOEngine or file FileIOEngineto store/read the
block data.
Eviction is using similar algorithm as
LruBlockCache
BucketCache could be used as mainly a block cache(see
CombinedBlockCache), combined with LruBlockCache to decrease CMS and
fragment by GC.
Also could be used as a secondary cache(e.g. using Fusionio to store block)
to enlarge cache space by
LruBlockCache.setVictimCache(org.apache.hadoop.hbase.io.hfile.bucket.BucketCache)| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_ERROR_TOLERATION_DURATION |
| Constructor and Description |
|---|
BucketCache(String ioEngineName,
long capacity,
int writerThreadNum,
int writerQLen,
String persistencePath) |
BucketCache(String ioEngineName,
long capacity,
int writerThreadNum,
int writerQLen,
String persistencePath,
int ioErrorsTolerationDuration) |
| Modifier and Type | Method and Description |
|---|---|
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.
|
void |
cacheBlockWithWait(BlockCacheKey cacheKey,
Cacheable cachedItem,
boolean inMemory,
boolean wait)
Cache the block to ramCache
|
boolean |
evictBlock(BlockCacheKey cacheKey)
Evict block from cache.
|
int |
evictBlocksByHfileName(String hfileName)
Evicts all blocks for a specific HFile.
|
Cacheable |
getBlock(BlockCacheKey key,
boolean caching,
boolean repeat)
Get the buffer of the block with the specified key.
|
List<BlockCacheColumnFamilySummary> |
getBlockCacheColumnFamilySummaries(org.apache.hadoop.conf.Configuration conf)
Performs a BlockCache summary and returns a List of BlockCacheColumnFamilySummary objects.
|
long |
getBlockCount()
Returns the number of blocks currently cached in the block cache.
|
long |
getCurrentSize()
Returns the occupied size of the block cache, in bytes.
|
long |
getEvictedCount()
Returns the number of blocks that have been evicted.
|
long |
getFreeSize()
Returns the free size of the block cache, in bytes.
|
CacheStats |
getStats()
Get the statistics for this block cache.
|
long |
heapSize() |
void |
logStats() |
void |
shutdown()
Shutdown the cache.
|
long |
size()
Returns the total size of the block cache, in bytes.
|
public static final int DEFAULT_ERROR_TOLERATION_DURATION
public BucketCache(String ioEngineName, long capacity, int writerThreadNum, int writerQLen, String persistencePath) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic BucketCache(String ioEngineName, long capacity, int writerThreadNum, int writerQLen, String persistencePath, int ioErrorsTolerationDuration) throws FileNotFoundException, IOException
FileNotFoundExceptionIOExceptionpublic void cacheBlock(BlockCacheKey cacheKey, Cacheable buf)
cacheBlock in interface BlockCachecacheKey - block's cache keybuf - block bufferpublic void cacheBlock(BlockCacheKey cacheKey, Cacheable cachedItem, boolean inMemory)
cacheBlock in interface BlockCachecacheKey - block's cache keycachedItem - block bufferinMemory - if block is in-memorypublic void cacheBlockWithWait(BlockCacheKey cacheKey, Cacheable cachedItem, boolean inMemory, boolean wait)
cacheKey - block's cache keycachedItem - block bufferinMemory - if block is in-memorywait - if true, blocking wait when queue is fullpublic Cacheable getBlock(BlockCacheKey key, boolean caching, boolean repeat)
getBlock in interface BlockCachekey - block's cache keycaching - true if the caller caches blocks on cache missesrepeat - Whether this is a repeat lookup for the same blockHFileReaderV2.readBlock(long, long, boolean, boolean, boolean, BlockType)public boolean evictBlock(BlockCacheKey cacheKey)
BlockCacheevictBlock in interface BlockCachecacheKey - Block to evictpublic void logStats()
public void shutdown()
BlockCacheshutdown in interface BlockCachepublic CacheStats getStats()
BlockCachegetStats in interface BlockCachepublic long size()
BlockCachesize in interface BlockCachepublic long getFreeSize()
BlockCachegetFreeSize in interface BlockCachepublic long getBlockCount()
BlockCachegetBlockCount in interface BlockCachepublic long getCurrentSize()
BlockCachegetCurrentSize in interface BlockCachepublic long getEvictedCount()
BlockCachegetEvictedCount in interface BlockCachepublic int evictBlocksByHfileName(String hfileName)
This is used for evict-on-close to remove all blocks of a specific HFile.
evictBlocksByHfileName in interface BlockCachepublic List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries(org.apache.hadoop.conf.Configuration conf)
BlockCachegetBlockCacheColumnFamilySummaries in interface BlockCacheconf - HBaseConfigurationCopyright © 2014 The Apache Software Foundation. All Rights Reserved.