Class BucketCache.RAMCache
java.lang.Object
org.apache.hadoop.hbase.io.hfile.bucket.BucketCache.RAMCache
- Enclosing class:
- BucketCache
Wrapped the delegate ConcurrentMap with maintaining its block's reference count.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ConcurrentHashMap<BlockCacheKey,BucketCache.RAMQueueEntry> Defined the map asConcurrentHashMapexplicitly here, because inget(BlockCacheKey)andputIfAbsent(BlockCacheKey, BucketCache.RAMQueueEntry), we need to guarantee the atomicity of map#computeIfPresent(key, func) and map#putIfAbsent(key, func). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(BlockCacheKey key) get(BlockCacheKey key) booleanhasBlocksForFile(String fileName) booleanisEmpty()putIfAbsent(BlockCacheKey key, BucketCache.RAMQueueEntry entry) Return the previous associated value, or null if absent.booleanremove(BlockCacheKey key) booleanremove(BlockCacheKey key, Consumer<BucketCache.RAMQueueEntry> action) Defined anConsumerhere, because once the removed entry release its reference count, then it's ByteBuffers may be recycled and accessing it outside this method will be thrown an exception.
-
Field Details
-
delegate
Defined the map asConcurrentHashMapexplicitly here, because inget(BlockCacheKey)andputIfAbsent(BlockCacheKey, BucketCache.RAMQueueEntry), we need to guarantee the atomicity of map#computeIfPresent(key, func) and map#putIfAbsent(key, func). Besides, the func method can execute exactly once only when the key is present(or absent) and under the lock context. Otherwise, the reference count of block will be messed up. Notice that theConcurrentSkipListMapcan not guarantee that.
-
-
Constructor Details
-
RAMCache
RAMCache()
-
-
Method Details
-
containsKey
-
get
-
putIfAbsent
Return the previous associated value, or null if absent. It has the same meaning asConcurrentMap.putIfAbsent(Object, Object) -
remove
-
remove
Defined anConsumerhere, because once the removed entry release its reference count, then it's ByteBuffers may be recycled and accessing it outside this method will be thrown an exception. the consumer will access entry to remove before release its reference count. Notice, don't change its reference count in theConsumer -
isEmpty
-
clear
-
hasBlocksForFile
-