Class TinyLfuBlockCache
- java.lang.Object
-
- org.apache.accumulo.core.file.blockfile.cache.tinylfu.TinyLfuBlockCache
-
- All Implemented Interfaces:
BlockCache
public final class TinyLfuBlockCache extends Object implements BlockCache
A block cache that is memory bounded using the W-TinyLFU eviction algorithm. This implementation delegates to a Caffeine cache to provide concurrent O(1) read and write operations.- W-TinyLFU: http://arxiv.org/pdf/1512.00727.pdf
- Caffeine: https://github.com/ben-manes/caffeine
- Cache design: http://highscalability.com/blog/2016/1/25/design-of-a-modern-cache.html
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.accumulo.core.spi.cache.BlockCache
BlockCache.Loader, BlockCache.Stats
-
-
Constructor Summary
Constructors Constructor Description TinyLfuBlockCache(BlockCacheManager.Configuration conf, CacheType type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CacheEntrycacheBlock(String blockName, byte[] buffer)Add block to cache.CacheEntrygetBlock(String blockName)Fetch block from cache.CacheEntrygetBlock(String blockName, BlockCache.Loader loader)This method allows a cache to prevent concurrent loads of the same block.longgetMaxHeapSize()Get the maximum amount of on heap memory this cache will use.longgetMaxSize()Get the maximum size of this cache.BlockCache.StatsgetStats()Get the statistics of this cache.
-
-
-
Constructor Detail
-
TinyLfuBlockCache
public TinyLfuBlockCache(BlockCacheManager.Configuration conf, CacheType type)
-
-
Method Detail
-
getMaxHeapSize
public long getMaxHeapSize()
Description copied from interface:BlockCacheGet the maximum amount of on heap memory this cache will use.- Specified by:
getMaxHeapSizein interfaceBlockCache
-
getMaxSize
public long getMaxSize()
Description copied from interface:BlockCacheGet the maximum size of this cache.- Specified by:
getMaxSizein interfaceBlockCache- Returns:
- max size in bytes
-
getBlock
public CacheEntry getBlock(String blockName)
Description copied from interface:BlockCacheFetch block from cache.- Specified by:
getBlockin interfaceBlockCache- Parameters:
blockName- Block name to fetch.- Returns:
- Block or null if block is not in the cache.
-
cacheBlock
public CacheEntry cacheBlock(String blockName, byte[] buffer)
Description copied from interface:BlockCacheAdd block to cache.- Specified by:
cacheBlockin interfaceBlockCache- Parameters:
blockName- Zero-based file block number.buffer- The block contents wrapped in a ByteBuffer.
-
getStats
public BlockCache.Stats getStats()
Description copied from interface:BlockCacheGet the statistics of this cache.- Specified by:
getStatsin interfaceBlockCache- Returns:
- statistics
-
getBlock
public CacheEntry getBlock(String blockName, BlockCache.Loader loader)
Description copied from interface:BlockCacheThis method allows a cache to prevent concurrent loads of the same block. However a cache implementation is not required to prevent concurrent loads.SynchronousLoadingBlockCacheis an abstract class that a cache can extent which does prevent concurrent loading of the same block.- Specified by:
getBlockin interfaceBlockCache- Parameters:
blockName- Block name to fetchloader- If the block is not present in the cache, the loader can be called to load it.- Returns:
- Block or null if block is not in the cache or didn't load.
-
-