org.apache.hadoop.hbase.io.hfile
Interface BlockCache

All Superinterfaces:
Iterable<CachedBlock>
All Known Implementing Classes:
BucketCache, CombinedBlockCache, DoubleBlockCache, LruBlockCache, SingleSizeCache, SlabCache

@InterfaceAudience.Private
public interface BlockCache
extends Iterable<CachedBlock>

Block cache interface. Anything that implements the Cacheable interface can be put in the cache.


Method Summary
 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.
 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.
 BlockCache[] getBlockCaches()
           
 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 getFreeSize()
          Returns the free size of the block cache, in bytes.
 CacheStats getStats()
          Get the statistics for this block cache.
 Iterator<CachedBlock> iterator()
           
 void shutdown()
          Shutdown the cache.
 long size()
          Returns the total size of the block cache, in bytes.
 

Method Detail

cacheBlock

void cacheBlock(BlockCacheKey cacheKey,
                Cacheable buf,
                boolean inMemory)
Add block to cache.

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

void cacheBlock(BlockCacheKey cacheKey,
                Cacheable buf)
Add block to cache (defaults to not in-memory).

Parameters:
cacheKey - The block's cache key.
buf - The object to cache.

getBlock

Cacheable getBlock(BlockCacheKey cacheKey,
                   boolean caching,
                   boolean repeat,
                   boolean updateCacheMetrics)
Fetch block from cache.

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.

evictBlock

boolean evictBlock(BlockCacheKey cacheKey)
Evict block from cache.

Parameters:
cacheKey - Block to evict
Returns:
true if block existed and was evicted, false if not

evictBlocksByHfileName

int evictBlocksByHfileName(String hfileName)
Evicts all blocks for the given HFile.

Returns:
the number of blocks evicted

getStats

CacheStats getStats()
Get the statistics for this block cache.

Returns:
Stats

shutdown

void shutdown()
Shutdown the cache.


size

long size()
Returns the total size of the block cache, in bytes.

Returns:
size of cache, in bytes

getFreeSize

long getFreeSize()
Returns the free size of the block cache, in bytes.

Returns:
free space in cache, in bytes

getCurrentSize

long getCurrentSize()
Returns the occupied size of the block cache, in bytes.

Returns:
occupied space in cache, in bytes

getBlockCount

long getBlockCount()
Returns the number of blocks currently cached in the block cache.

Returns:
number of blocks in the cache

iterator

Iterator<CachedBlock> iterator()
Specified by:
iterator in interface Iterable<CachedBlock>
Returns:
Iterator over the blocks in the cache.

getBlockCaches

BlockCache[] getBlockCaches()
Returns:
The list of sub blockcaches that make up this one; returns null if no sub caches.


Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.