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
Modifier and TypeFieldDescriptionprotected AtomicInteger
Total number of allocations satisfied from this bufferprivate final ChunkCreator.ChunkType
protected ByteBuffer
Actual underlying dataprivate final boolean
private final int
protected AtomicInteger
Offset for the next allocation, or the sentinel value -1 which implies that the chunk is still uninitialized.protected static final int
protected final int
Size of chunk in bytesprotected static final int
-
Constructor Summary
ConstructorDescriptionChunk
(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 TypeMethodDescriptionint
alloc
(int size) Try to allocatesize
bytes from the chunk.(package private) abstract void
(package private) ChunkCreator.ChunkType
(package private) ByteBuffer
getData()
Returns This chunk's backing data.(package private) int
getId()
(package private) int
void
init()
Actually claim the memory for this chunk.(package private) boolean
(package private) boolean
(package private) boolean
(package private) boolean
isJumbo()
(package private) void
reset()
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 allocatesize
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
-
getNextFreeOffset
int getNextFreeOffset()
-