@InterfaceAudience.Private public class MemcachedBlockCache extends Object implements BlockCache
Modifier and Type | Class and Description |
---|---|
private static class |
MemcachedBlockCache.HFileBlockTranscoder
Class to encode and decode an HFileBlock to and from memecached's resulting byte arrays.
|
Modifier and Type | Field and Description |
---|---|
private CacheStats |
cacheStats |
private net.spy.memcached.MemcachedClient |
client |
private static org.apache.commons.logging.Log |
LOG |
static int |
MAX_SIZE |
static String |
MEMCACHED_CONFIG_KEY |
static long |
MEMCACHED_DEFAULT_TIMEOUT |
static String |
MEMCACHED_OPTIMEOUT_KEY |
static boolean |
MEMCACHED_OPTIMIZE_DEFAULT |
static String |
MEMCACHED_OPTIMIZE_KEY |
static String |
MEMCACHED_TIMEOUT_KEY |
private MemcachedBlockCache.HFileBlockTranscoder |
tc |
Constructor and Description |
---|
MemcachedBlockCache(org.apache.hadoop.conf.Configuration c) |
Modifier and Type | Method and Description |
---|---|
void |
cacheBlock(BlockCacheKey cacheKey,
Cacheable buf)
Add block to cache (defaults to not in-memory).
|
void |
cacheBlock(BlockCacheKey cacheKey,
Cacheable buf,
boolean inMemory,
boolean cacheDataInL1)
Add block to cache.
|
boolean |
evictBlock(BlockCacheKey cacheKey)
Evict block from cache.
|
int |
evictBlocksByHfileName(String hfileName)
This method does nothing so that memcached can handle all evictions.
|
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.
|
private static final org.apache.commons.logging.Log LOG
public static final int MAX_SIZE
public static final String MEMCACHED_CONFIG_KEY
public static final String MEMCACHED_TIMEOUT_KEY
public static final String MEMCACHED_OPTIMEOUT_KEY
public static final String MEMCACHED_OPTIMIZE_KEY
public static final long MEMCACHED_DEFAULT_TIMEOUT
public static final boolean MEMCACHED_OPTIMIZE_DEFAULT
private final net.spy.memcached.MemcachedClient client
private final MemcachedBlockCache.HFileBlockTranscoder tc
private final CacheStats cacheStats
public MemcachedBlockCache(org.apache.hadoop.conf.Configuration c) throws IOException
IOException
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory, boolean cacheDataInL1)
BlockCache
cacheBlock
in interface BlockCache
cacheKey
- The block's cache key.buf
- The block contents wrapped in a ByteBuffer.inMemory
- Whether block should be treated as in-memorycacheDataInL1
- If multi-tier block cache deploy -- i.e. has an L1 and L2 tier -- then
if this flag is true, cache data blocks up in the L1 tier (meta blocks are probably being
cached in L1 already).public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf)
BlockCache
cacheBlock
in interface BlockCache
cacheKey
- The block's cache key.buf
- The object to cache.public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics)
BlockCache
getBlock
in interface BlockCache
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 notpublic boolean evictBlock(BlockCacheKey cacheKey)
BlockCache
evictBlock
in interface BlockCache
cacheKey
- Block to evictpublic int evictBlocksByHfileName(String hfileName)
evictBlocksByHfileName
in interface BlockCache
public CacheStats getStats()
BlockCache
getStats
in interface BlockCache
public void shutdown()
BlockCache
shutdown
in interface BlockCache
public long size()
BlockCache
size
in interface BlockCache
public long getFreeSize()
BlockCache
getFreeSize
in interface BlockCache
public long getCurrentSize()
BlockCache
getCurrentSize
in interface BlockCache
public long getBlockCount()
BlockCache
getBlockCount
in interface BlockCache
public Iterator<CachedBlock> iterator()
iterator
in interface Iterable<CachedBlock>
iterator
in interface BlockCache
public BlockCache[] getBlockCaches()
getBlockCaches
in interface BlockCache
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.