java.lang.Object
org.apache.hadoop.hbase.regionserver.Chunk
Direct Known Subclasses:
OffheapChunk, OnheapChunk

@Private public abstract class Chunk extends Object
A chunk of memory out of which allocations are sliced.
  • Field Details

  • Constructor Details

    • Chunk

      public Chunk(int size, int id, ChunkCreator.ChunkType chunkType)
      Create an uninitialized chunk. Note that memory is not allocated yet, so this is cheap.
      Parameters:
      size - in bytes
      id - the chunk id
    • Chunk

      public Chunk(int size, int id, ChunkCreator.ChunkType chunkType, boolean fromPool)
      Create an uninitialized chunk. Note that memory is not allocated yet, so this is cheap.
      Parameters:
      size - in bytes
      id - the chunk id
      fromPool - if the chunk is formed by pool
  • Method Details

    • getId

      int getId()
    • getChunkType

    • isFromPool

      boolean isFromPool()
    • isJumbo

      boolean isJumbo()
    • isIndexChunk

      boolean isIndexChunk()
    • isDataChunk

      boolean isDataChunk()
    • init

      public void init()
      Actually claim the memory for this chunk. This should only be called from the thread that constructed the chunk. It is thread-safe against other threads calling alloc(), who will block until the allocation is complete.
    • allocateDataBuffer

      abstract void allocateDataBuffer()
    • reset

      void reset()
      Reset the offset to UNINITIALIZED before before reusing an old chunk
    • alloc

      public int alloc(int size)
      Try to allocate size bytes from the chunk. If a chunk is tried to get allocated before init() call, the thread doing the allocation will be in busy-wait state as it will keep looping till the nextFreeOffset is set.
      Returns:
      the offset of the successful allocation, or -1 to indicate not-enough-space
    • getData

      Returns This chunk's backing data.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getNextFreeOffset