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

All Known Implementing Classes:
DoubleBlockCache, LruBlockCache, SimpleBlockCache, SingleSizeCache, SlabCache

public interface BlockCache

Block cache interface. Anything that implements the Cacheable interface can be put in the cache. TODO: Add filename or hash of filename to block cache key.


Method Summary
 void cacheBlock(String blockName, Cacheable buf)
          Add block to cache (defaults to not in-memory).
 void cacheBlock(String blockName, Cacheable buf, boolean inMemory)
          Add block to cache.
 boolean evictBlock(String blockName)
          Evict block from cache.
 int evictBlocksByPrefix(String string)
          Evicts all blocks with name starting with the given prefix.
 Cacheable getBlock(String blockName, 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.
 void shutdown()
          Shutdown the cache.
 long size()
          Returns the total size of the block cache, in bytes.
 

Method Detail

cacheBlock

void cacheBlock(String blockName,
                Cacheable buf,
                boolean inMemory)
Add block to cache.

Parameters:
blockName - Zero-based file block number.
buf - The block contents wrapped in a ByteBuffer.
inMemory - Whether block should be treated as in-memory

cacheBlock

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

Parameters:
blockName - Zero-based file block number.
buf - The object to cache.

getBlock

Cacheable getBlock(String blockName,
                   boolean caching)
Fetch block from cache.

Parameters:
blockName - Block number to fetch.
caching - Whether this request has caching enabled (used for stats)
Returns:
Block or null if block is not in 2 cache.

evictBlock

boolean evictBlock(String blockName)
Evict block from cache.

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

evictBlocksByPrefix

int evictBlocksByPrefix(String string)
Evicts all blocks with name starting with the given prefix. This is necessary in cases we need to evict all blocks that belong to a particular HFile. In HFile v2 all blocks consist of the storefile name (UUID), an underscore, and the block offset in the file. An efficient implementation would avoid scanning all blocks in the cache.

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

getEvictedCount

long getEvictedCount()
Returns the number of evictions that have occurred.

Returns:
number of evictions

getBlockCount

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

Returns:
number of blocks in the cache

getBlockCacheColumnFamilySummaries

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

Parameters:
conf - HBaseConfiguration
Returns:
List of BlockCacheColumnFamilySummary
Throws:
IOException - exception


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