org.apache.hadoop.hbase.io.hfile
Class DoubleBlockCache

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

public class DoubleBlockCache
extends Object
implements BlockCache, HeapSize

DoubleBlockCache is an abstraction layer that combines two caches, the smaller onHeapCache and the larger offHeapCache. CacheBlock attempts to cache the block in both caches, while readblock reads first from the faster on heap cache before looking for the block in the off heap cache. Metrics are the combined size and hits and misses of both caches.


Constructor Summary
DoubleBlockCache(long onHeapSize, long offHeapSize, long onHeapBlockSize, long offHeapBlockSize, org.apache.hadoop.conf.Configuration conf)
          Default constructor.
 
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)
          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.
 CacheStats getStats()
          Get the statistics for this block cache.
 long heapSize()
           
 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
 

Constructor Detail

DoubleBlockCache

public DoubleBlockCache(long onHeapSize,
                        long offHeapSize,
                        long onHeapBlockSize,
                        long offHeapBlockSize,
                        org.apache.hadoop.conf.Configuration conf)
Default constructor. Specify maximum size and expected average block size (approximation is fine).

All other factors will be calculated based on defaults specified in this class.

Parameters:
onHeapSize - maximum size of the onHeapCache, in bytes.
offHeapSize - maximum size of the offHeapCache, in bytes.
onHeapBlockSize - average block size of the on heap cache.
offHeapBlockSize - average block size for the off heap cache
conf - configuration file. currently used only by the off heap cache.
Method Detail

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

cacheBlock

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

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

getBlock

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

Specified by:
getBlock in interface BlockCache
Parameters:
cacheKey - Block to fetch.
caching - Whether this request has caching enabled (used for stats)
Returns:
Block or null if block is not in 2 cache.

evictBlock

public boolean evictBlock(BlockCacheKey cacheKey)
Description copied from interface: BlockCache
Evict block from cache.

Specified by:
evictBlock in interface BlockCache
Parameters:
cacheKey - Block to evict
Returns:
true if block existed and was evicted, false if not

getStats

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

Specified by:
getStats in interface BlockCache
Returns:
Stats

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

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

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

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

getBlockCacheColumnFamilySummaries

public List<BlockCacheColumnFamilySummary> getBlockCacheColumnFamilySummaries(org.apache.hadoop.conf.Configuration conf)
                                                                       throws IOException
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
Throws:
IOException - exception

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


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