Class ByteBuffAllocator

java.lang.Object
org.apache.hadoop.hbase.io.ByteBuffAllocator
Direct Known Subclasses:
DeallocateRewriteByteBuffAllocator

@Private public class ByteBuffAllocator extends Object
ByteBuffAllocator is used for allocating/freeing the ByteBuffers from/to NIO ByteBuffer pool, and it provide high-level interfaces for upstream. when allocating desired memory size, it will return ByteBuff, if we are sure that those ByteBuffers have reached the end of life cycle, we must do the ByteBuff.release() to return back the buffers to the pool, otherwise ByteBuffers leak will happen, and the NIO ByteBuffer pool may be exhausted. there's possible that the desired memory size is large than ByteBufferPool has, we'll downgrade to allocate ByteBuffers from heap which meaning the GC pressure may increase again. Of course, an better way is increasing the ByteBufferPool size if we detected this case.

On the other hand, for better memory utilization, we have set an lower bound named minSizeForReservoirUse in this allocator, and if the desired size is less than minSizeForReservoirUse, the allocator will just allocate the ByteBuffer from heap and let the JVM free its memory, because it's too wasting to allocate a single fixed-size ByteBuffer for some small objects.

We recommend to use this class to allocate/free ByteBuff in the RPC layer or the entire read/write path, because it hide the details of memory management and its APIs are more friendly to the upper layer.