org.apache.hadoop.hbase.io.hfile.slab
Class SingleSizeCache

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.slab.SingleSizeCache
All Implemented Interfaces:
HeapSize, BlockCache

public class SingleSizeCache
extends Object
implements BlockCache, HeapSize

SingleSizeCache is a slab allocated cache that caches elements up to a single size. It uses a slab allocator (Slab.java) to divide a direct bytebuffer, into evenly sized blocks. Any cached data will take up exactly 1 block. An exception will be thrown if the cached data cannot fit into the blockSize of this SingleSizeCache. Eviction and LRUness is taken care of by Guava's MapMaker, which creates a ConcurrentLinkedHashMap.


Field Summary
static long CACHE_FIXED_OVERHEAD
           
 
Constructor Summary
SingleSizeCache(int blockSize, int numBlocks, org.apache.hadoop.hbase.io.hfile.slab.SlabItemActionWatcher master)
          Default constructor.
 
Method Summary
 void cacheBlock(BlockCacheKey blockName, Cacheable toBeCached)
          Add block to cache (defaults to not in-memory).
 void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory)
          Add block to cache.
 boolean evictBlock(BlockCacheKey key)
          Evicts the block
 int evictBlocksByHfileName(String hfileName)
          Evicts all blocks for the given HFile.
 Cacheable getBlock(BlockCacheKey key, boolean caching, boolean repeat)
          Fetch block from cache.
 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.
 long getOccupiedSize()
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_FIXED_OVERHEAD

public static final long CACHE_FIXED_OVERHEAD
Constructor Detail

SingleSizeCache

public SingleSizeCache(int blockSize,
                       int numBlocks,
                       org.apache.hadoop.hbase.io.hfile.slab.SlabItemActionWatcher master)
Default constructor. Specify the size of the blocks, number of blocks, and the SlabCache this cache will be assigned to.

Parameters:
blockSize - the size of each block, in bytes
numBlocks - the number of blocks of blockSize this cache will hold.
master - the SlabCache this SingleSlabCache is assigned to.
Method Detail

cacheBlock

public void cacheBlock(BlockCacheKey blockName,
                       Cacheable toBeCached)
Description copied from interface: BlockCache
Add block to cache (defaults to not in-memory).

Specified by:
cacheBlock in interface BlockCache
Parameters:
blockName - The block's cache key.
toBeCached - The object to cache.

getBlock

public Cacheable getBlock(BlockCacheKey key,
                          boolean caching,
                          boolean repeat)
Description copied from interface: BlockCache
Fetch block from cache.

Specified by:
getBlock in interface BlockCache
Parameters:
key - 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) HFileReaderV2.readBlock(long, long, boolean, boolean, boolean, BlockType)
Returns:
Block or null if block is not in 2 cache.

evictBlock

public boolean evictBlock(BlockCacheKey key)
Evicts the block

Specified by:
evictBlock in interface BlockCache
Parameters:
key - the key of the entry we are going to evict
Returns:
the evicted ByteBuffer

logStats

public void logStats()

shutdown

public void shutdown()
Description copied from interface: BlockCache
Shutdown the cache.

Specified by:
shutdown in interface BlockCache

heapSize

public long heapSize()
Specified by:
heapSize in interface HeapSize
Returns:
Approximate 'exclusive deep size' of implementing object. Includes count of payload and hosting object sizings.

size

public long size()
Description copied from interface: BlockCache
Returns the total size of the block cache, in bytes.

Specified by:
size in interface BlockCache
Returns:
size of cache, in bytes

getFreeSize

public long getFreeSize()
Description copied from interface: BlockCache
Returns the free size of the block cache, in bytes.

Specified by:
getFreeSize in interface BlockCache
Returns:
free space in cache, in bytes

getOccupiedSize

public long getOccupiedSize()

getEvictedCount

public long getEvictedCount()
Description copied from interface: BlockCache
Returns the number of evictions that have occurred.

Specified by:
getEvictedCount in interface BlockCache
Returns:
number of evictions

getStats

public CacheStats getStats()
Description copied from interface: BlockCache
Get the statistics for this block cache.

Specified by:
getStats in interface BlockCache
Returns:
Stats

getBlockCount

public long getBlockCount()
Description copied from interface: BlockCache
Returns the number of blocks currently cached in the block cache.

Specified by:
getBlockCount in interface BlockCache
Returns:
number of blocks in the cache

cacheBlock

public void cacheBlock(BlockCacheKey cacheKey,
                       Cacheable buf,
                       boolean inMemory)
Description copied from interface: BlockCache
Add block to cache.

Specified by:
cacheBlock in interface BlockCache
Parameters:
cacheKey - The block's cache key.
buf - The block contents wrapped in a ByteBuffer.
inMemory - Whether block should be treated as in-memory

evictBlocksByHfileName

public int evictBlocksByHfileName(String hfileName)
Description copied from interface: BlockCache
Evicts all blocks for the given HFile.

Specified by:
evictBlocksByHfileName in interface BlockCache
Returns:
the number of blocks evicted

getCurrentSize

public long getCurrentSize()
Description copied from interface: BlockCache
Returns the occupied size of the block cache, in bytes.

Specified by:
getCurrentSize in interface BlockCache
Returns:
occupied space in cache, in bytes

getBlockCacheColumnFamilySummaries

public List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries(org.apache.hadoop.conf.Configuration conf)
Description copied from interface: BlockCache
Performs a BlockCache summary and returns a List of BlockCacheColumnFamilySummary objects. This method could be fairly heavyweight in that it evaluates the entire HBase file-system against what is in the RegionServer BlockCache.

The contract of this interface is to return the List in sorted order by Table name, then ColumnFamily.

Specified by:
getBlockCacheColumnFamilySummaries in interface BlockCache
Parameters:
conf - HBaseConfiguration
Returns:
List of BlockCacheColumnFamilySummary


Copyright © 2014 The Apache Software Foundation. All Rights Reserved.