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
Modifier and TypeFieldDescription(package private) final ConcurrentHashMap<BlockCacheKey,
BucketCache.RAMQueueEntry> Defined the map asConcurrentHashMap
explicitly 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(BlockCacheKey key) get
(BlockCacheKey key) boolean
hasBlocksForFile
(String fileName) boolean
isEmpty()
putIfAbsent
(BlockCacheKey key, BucketCache.RAMQueueEntry entry) Return the previous associated value, or null if absent.boolean
remove
(BlockCacheKey key) boolean
remove
(BlockCacheKey key, Consumer<BucketCache.RAMQueueEntry> action) Defined anConsumer
here, 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 asConcurrentHashMap
explicitly 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 theConcurrentSkipListMap
can 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 anConsumer
here, 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
-