@InterfaceAudience.Private class BucketEntry extends Object implements HBaseReferenceCounted
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
BucketEntry.BucketEntryHandler<T> |
Modifier and Type | Field and Description |
---|---|
private long |
accessCounter |
(package private) ByteBuffAllocator |
allocator |
private long |
cachedTime
Time this block was cached.
|
(package private) static Comparator<BucketEntry> |
COMPARATOR |
(package private) byte |
deserializerIndex
The index of the deserializer that can deserialize this BucketEntry content.
|
private int |
length |
(package private) AtomicBoolean |
markedAsEvicted |
private byte |
offset1 |
private int |
offsetBase |
private BlockPriority |
priority |
private RefCnt |
refCnt
The RefCnt means how many paths are referring the
BucketEntry , there are two cases:
1.If the IOEngine.usesSharedMemory() is false(eg.FileIOEngine ),the refCnt is
always 1 until this BucketEntry is evicted from BucketCache.backingMap .Even
if the corresponding HFileBlock is referenced by RPC reading, the refCnt should not
increase. |
Constructor and Description |
---|
BucketEntry(long offset,
int length,
long accessCounter,
boolean inMemory,
Function<BucketEntry,ByteBuffAllocator.Recycler> createRecycler,
ByteBuffAllocator allocator) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
access(long accessCounter)
Block has been accessed.
|
(package private) CacheableDeserializer<Cacheable> |
deserializerReference() |
(package private) long |
getAccessCounter() |
(package private) long |
getCachedTime() |
int |
getLength() |
BlockPriority |
getPriority() |
(package private) boolean |
isRpcRef()
Check whether have some RPC patch referring this block.
For IOEngine.usesSharedMemory() is true(eg.ByteBufferIOEngine ), there're two
case: 1. |
(package private) boolean |
markAsEvicted()
The
BucketCache will try to release its reference to this BucketEntry many times. |
(package private) long |
offset() |
int |
refCnt() |
boolean |
release()
We've three cases to release refCnt now:
1. |
BucketEntry |
retain() |
(package private) void |
setDeserializerReference(CacheableDeserializer<Cacheable> deserializer) |
private void |
setOffset(long value) |
(package private) <T> T |
withWriteLock(IdReadWriteLock<Long> offsetLock,
BucketEntry.BucketEntryHandler<T> handler) |
(package private) Cacheable |
wrapAsCacheable(ByteBuff buf) |
(package private) Cacheable |
wrapAsCacheable(ByteBuffer[] buffers) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
release, retain, touch, touch
static final Comparator<BucketEntry> COMPARATOR
private int offsetBase
private int length
private byte offset1
byte deserializerIndex
CacheableDeserializerIdManager
for hosting of index to serializers.private volatile long accessCounter
private BlockPriority priority
private final RefCnt refCnt
The RefCnt means how many paths are referring theBucketEntry
, there are two cases: 1.If theIOEngine.usesSharedMemory()
is false(eg.FileIOEngine
),the refCnt is always 1 until thisBucketEntry
is evicted fromBucketCache.backingMap
.Even if the correspondingHFileBlock
is referenced by RPC reading, the refCnt should not increase. 2.If theIOEngine.usesSharedMemory()
is true(eg.ByteBufferIOEngine
),each RPC reading path is considering as one path, theBucketCache.backingMap
reference is also considered a path. NOTICE that if two read RPC path hit the sameBucketEntry
, then theHFileBlock
s the two RPC referred will share the same refCnt instance with theBucketEntry
,so the refCnt will increase or decrease as the following: (1) when writerThread flush the block into IOEngine and add the bucketEntry into backingMap, the refCnt ++; (2) If BucketCache evict the block and move the bucketEntry out of backingMap, the refCnt--; it usually happen when HFile is closing or someone call the clearBucketCache by force. (3) The read RPC path start to refer the block which is backend by the memory area in bucketEntry, then refCnt ++ ; (4) The read RPC patch shipped the response, and release the block. then refCnt--; Once the refCnt decrease to zero, then theBucketAllocator
will free the block area.
final AtomicBoolean markedAsEvicted
final ByteBuffAllocator allocator
private final long cachedTime
BucketEntry(long offset, int length, long accessCounter, boolean inMemory, Function<BucketEntry,ByteBuffAllocator.Recycler> createRecycler, ByteBuffAllocator allocator)
createRecycler
- used to free this BucketEntry
when refCnt
becoming 0. NOTICE that ByteBuffAllocator.NONE
could only be used
for test.long offset()
private void setOffset(long value)
public int getLength()
CacheableDeserializer<Cacheable> deserializerReference()
void setDeserializerReference(CacheableDeserializer<Cacheable> deserializer)
long getAccessCounter()
void access(long accessCounter)
public BlockPriority getPriority()
long getCachedTime()
boolean markAsEvicted()
BucketCache
will try to release its reference to this BucketEntry many times. we
must make sure the idempotent, otherwise it'll decrease the RPC's reference count in advance,
then for RPC memory leak happen.boolean isRpcRef()
IOEngine.usesSharedMemory()
is true(eg.ByteBufferIOEngine
), there're two
case: IOEngine.usesSharedMemory()
is false(eg.FileIOEngine
),
refCnt
is always 1 until it is evicted from BucketCache.backingMap
,
so isRpcRef()
is always return false.Cacheable wrapAsCacheable(ByteBuffer[] buffers) throws IOException
IOException
Cacheable wrapAsCacheable(ByteBuff buf) throws IOException
IOException
<T> T withWriteLock(IdReadWriteLock<Long> offsetLock, BucketEntry.BucketEntryHandler<T> handler)
public int refCnt()
refCnt
in interface org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted
public BucketEntry retain()
retain
in interface org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted
public boolean release()
BucketEntry#markStaleAsEvicted()
do.release
in interface org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.