Class Chunk
java.lang.Object
org.apache.hadoop.hbase.regionserver.Chunk
- Direct Known Subclasses:
OffheapChunk,OnheapChunk
A chunk of memory out of which allocations are sliced.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AtomicIntegerTotal number of allocations satisfied from this bufferprivate final ChunkCreator.ChunkTypeprotected ByteBufferActual underlying dataprivate final booleanprivate final intprotected AtomicIntegerOffset for the next allocation, or the sentinel value -1 which implies that the chunk is still uninitialized.protected static final intprotected final intSize of chunk in bytesprotected static final int -
Constructor Summary
ConstructorsConstructorDescriptionChunk(int size, int id, ChunkCreator.ChunkType chunkType) Create an uninitialized chunk.Chunk(int size, int id, ChunkCreator.ChunkType chunkType, boolean fromPool) Create an uninitialized chunk. -
Method Summary
Modifier and TypeMethodDescriptionintalloc(int size) Try to allocatesizebytes from the chunk.(package private) abstract void(package private) ChunkCreator.ChunkType(package private) ByteBuffergetData()Returns This chunk's backing data.(package private) intgetId()(package private) intvoidinit()Actually claim the memory for this chunk.(package private) boolean(package private) boolean(package private) boolean(package private) booleanisJumbo()(package private) voidreset()Reset the offset to UNINITIALIZED before before reusing an old chunktoString()
-
Field Details
-
data
Actual underlying data -
UNINITIALIZED
- See Also:
-
OOM
- See Also:
-
nextFreeOffset
Offset for the next allocation, or the sentinel value -1 which implies that the chunk is still uninitialized. -
allocCount
Total number of allocations satisfied from this buffer -
size
Size of chunk in bytes -
id
-
chunkType
-
fromPool
-
-
Constructor Details
-
Chunk
Create an uninitialized chunk. Note that memory is not allocated yet, so this is cheap.- Parameters:
size- in bytesid- the chunk id
-
Chunk
Create an uninitialized chunk. Note that memory is not allocated yet, so this is cheap.- Parameters:
size- in bytesid- the chunk idfromPool- 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
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
-
reset
void reset()Reset the offset to UNINITIALIZED before before reusing an old chunk -
alloc
Try to allocatesizebytes 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
-
getNextFreeOffset
int getNextFreeOffset()
-