Class MemStoreLABImpl

java.lang.Object
org.apache.hadoop.hbase.regionserver.MemStoreLABImpl
All Implemented Interfaces:
MemStoreLAB

@Private public class MemStoreLABImpl extends Object implements MemStoreLAB
A memstore-local allocation buffer.

The MemStoreLAB is basically a bump-the-pointer allocator that allocates big (2MB) byte[] chunks from and then doles it out to threads that request slices into the array.

The purpose of this class is to combat heap fragmentation in the regionserver. By ensuring that all Cells in a given memstore refer only to large chunks of contiguous memory, we ensure that large blocks get freed up when the memstore is flushed.

Without the MSLAB, the byte array allocated during insertion end up interleaved throughout the heap, and the old generation gets progressively more fragmented until a stop-the-world compacting collection occurs.

TODO: we should probably benchmark whether word-aligning the allocations would provide a performance improvement - probably would speed up the Bytes.toLong/Bytes.toInt calls in KeyValue, but some of those are cached anyway. The chunks created by this MemStoreLAB can get pooled at ChunkCreator. When the Chunk comes from pool, it can be either an on heap or an off heap backed chunk. The chunks, which this MemStoreLAB creates on its own (when no chunk available from pool), those will be always on heap backed.

NOTE:if user requested to work with MSLABs (whether on- or off-heap), in CompactingMemStore ctor, the CompactingMemStore.indexType could only be CompactingMemStore.IndexType.CHUNK_MAP,that is to say the immutable segments using MSLABs are going to use CellChunkMap as their index.