@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 FileIOEngine
to 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 evictions that have occurred.
|
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
FileNotFoundException
IOException
public BucketCache(String ioEngineName, long capacity, int writerThreadNum, int writerQLen, String persistencePath, int ioErrorsTolerationDuration) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf)
cacheBlock
in interface BlockCache
cacheKey
- block's cache keybuf
- block bufferpublic void cacheBlock(BlockCacheKey cacheKey, Cacheable cachedItem, boolean inMemory)
cacheBlock
in interface BlockCache
cacheKey
- 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 BlockCache
key
- 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)
BlockCache
evictBlock
in interface BlockCache
cacheKey
- Block to evictpublic void logStats()
public void shutdown()
BlockCache
shutdown
in interface BlockCache
public CacheStats getStats()
BlockCache
getStats
in interface BlockCache
public long heapSize()
public long size()
size
in interface BlockCache
public long getFreeSize()
BlockCache
getFreeSize
in interface BlockCache
public long getBlockCount()
BlockCache
getBlockCount
in interface BlockCache
public long getCurrentSize()
getCurrentSize
in interface BlockCache
public long getEvictedCount()
BlockCache
getEvictedCount
in interface BlockCache
public int evictBlocksByHfileName(String hfileName)
This is used for evict-on-close to remove all blocks of a specific HFile.
evictBlocksByHfileName
in interface BlockCache
public List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries(org.apache.hadoop.conf.Configuration conf)
BlockCache
getBlockCacheColumnFamilySummaries
in interface BlockCache
conf
- HBaseConfigurationCopyright © 2013 The Apache Software Foundation. All rights reserved.