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

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.CombinedBlockCache
All Implemented Interfaces:
Iterable<CachedBlock>, HeapSize, BlockCache

@InterfaceAudience.Private
public class CombinedBlockCache
extends Object
implements BlockCache, HeapSize

CombinedBlockCache is an abstraction layer that combines LruBlockCache and BucketCache. The smaller lruCache is used to cache bloom blocks and index blocks , the larger bucketCache is used to cache data blocks. getBlock reads first from the smaller lruCache before looking for the block in the bucketCache. Metrics are the combined size and hits and misses of both caches.


Constructor Summary
CombinedBlockCache(LruBlockCache lruCache, BucketCache bucketCache)
           
 
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.
 long heapSize()
           
 Iterator<CachedBlock> iterator()
           
 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

CombinedBlockCache

public CombinedBlockCache(LruBlockCache lruCache,
                          BucketCache bucketCache)
Method Detail

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.

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,
                          boolean repeat,
                          boolean updateCacheMetrics)
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)
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

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

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

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

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

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

iterator

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

getBlockCaches

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


Copyright © 2015 The Apache Software Foundation. All rights reserved.