Class BucketEntry

java.lang.Object
org.apache.hadoop.hbase.io.hfile.bucket.BucketEntry
All Implemented Interfaces:
HBaseReferenceCounted, org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted

@Private public class BucketEntry extends Object implements HBaseReferenceCounted
Item in cache. We expect this to be where most memory goes. Java uses 8 bytes just for object headers; after this, we want to use as little as possible - so we only use 8 bytes, but in order to do so we end up messing around with all this Java casting stuff. Offset stored as 5 bytes that make up the long. Doubt we'll see devices this big for ages. Offsets are divided by 256. So 5 bytes gives us 256TB or so.
  • Field Details

  • Constructor Details

  • Method Details

    • offset

      long offset()
    • setOffset

      private void setOffset(long value)
    • getLength

      public int getLength()
    • deserializerReference

    • setDeserializerReference

    • getAccessCounter

    • access

      void access(long accessCounter)
      Block has been accessed. Update its local access counter.
    • getPriority

    • getCachedTime

      public long getCachedTime()
    • getOnDiskSizeWithHeader

    • markAsEvicted

      boolean markAsEvicted()
      The 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.
      Returns:
      true if we deallocate this entry successfully.
    • isRpcRef

      boolean isRpcRef()
      Check whether have some RPC patch referring this block.
      For IOEngine.usesSharedMemory() is true(eg.ByteBufferIOEngine), there're two case:
      1. If current refCnt is greater than 1, there must be at least one referring RPC path;
      2. If current refCnt is equal to 1 and the markedAtEvicted is true, the it means backingMap has released its reference, the remaining reference can only be from RPC path.
      We use this check to decide whether we can free the block area: when cached size exceed the acceptable size, our eviction policy will choose those stale blocks without any RPC reference and the RPC referred block will be excluded.

      For IOEngine.usesSharedMemory() is false(eg.FileIOEngine), refCnt is always 1 until it is evicted from BucketCache.backingMap, so isRpcRef() is always return false.
      Returns:
      true to indicate there're some RPC referring the block.
    • wrapAsCacheable

      Throws:
      IOException
    • wrapAsCacheable

      Throws:
      IOException
    • withWriteLock

    • refCnt

      public int refCnt()
      Specified by:
      refCnt in interface org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted
    • retain

      public BucketEntry retain()
      Specified by:
      retain in interface org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted
    • release

      public boolean release()
      We've three cases to release refCnt now:
      1. BucketCache#evictBlock, it will release the backingMap's reference by force because we're closing file or clear the bucket cache or some corruption happen. when all rpc references gone, then free the area in bucketAllocator.
      2. BucketCache#returnBlock . when rpc shipped, we'll release the block, only when backingMap also release its refCnt (case.1 will do this) and no other rpc reference, then it will free the area in bucketAllocator.
      3.evict those block without any rpc reference if cache size exceeded. we'll only free those blocks with zero rpc reference count.
      Specified by:
      release in interface org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted
      Returns:
      true to indicate we've decreased to zero and do the de-allocation.