Class PinotDataBuffer
- java.lang.Object
-
- org.apache.pinot.segment.spi.memory.PinotDataBuffer
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
BasePinotLBuffer,PinotByteBuffer
@ThreadSafe public abstract class PinotDataBuffer extends Object implements Closeable
The classPinotDataBufferis the byte buffer for Pinot data that resides in off-heap memory.The byte buffer may be memory mapped (MMAP) or direct allocated (DIRECT).
Supports buffers larger than 2GB.
This class will also track the number and memory usage of the buffers.
NOTE: All the accesses to the buffer are unchecked for performance reason. Behavior of accessing buffer with invalid index is undefined.
Backward-compatible:
- Index file (forward index, inverted index, dictionary) is always big-endian
- Star-tree file is always little-endian
- Temporary buffer should be allocated using native-order for performance
-
-
Field Summary
Fields Modifier and Type Field Description static intBULK_BYTES_PROCESSING_THRESHOLDstatic ByteOrderNATIVE_ORDERstatic ByteOrderNON_NATIVE_ORDER
-
Constructor Summary
Constructors Modifier Constructor Description protectedPinotDataBuffer(boolean closeable)
-
Method Summary
Modifier and Type Method Description static PinotDataBufferallocateDirect(long size, ByteOrder byteOrder, String description)Allocates a buffer using direct memory.voidclose()voidcopyTo(long offset, byte[] buffer)abstract voidcopyTo(long offset, byte[] buffer, int destOffset, int size)abstract voidcopyTo(long offset, PinotDataBuffer buffer, long destOffset, long size)abstract voidflush()static longgetAllocationFailureCount()static List<String>getBufferInfo()abstract bytegetByte(int offset)abstract bytegetByte(long offset)abstract chargetChar(int offset)abstract chargetChar(long offset)static longgetDirectBufferCount()static longgetDirectBufferUsage()abstract doublegetDouble(int offset)abstract doublegetDouble(long offset)abstract floatgetFloat(int offset)abstract floatgetFloat(long offset)abstract intgetInt(int offset)abstract intgetInt(long offset)abstract longgetLong(int offset)abstract longgetLong(long offset)static longgetMmapBufferCount()static longgetMmapBufferUsage()abstract shortgetShort(int offset)abstract shortgetShort(long offset)static PinotDataBufferloadBigEndianFile(File file)Allocates a buffer using direct memory and loads a big-endian file into the buffer.static PinotDataBufferloadFile(File file, long offset, long size, ByteOrder byteOrder, String description)Allocates a buffer using direct memory and loads a file into the buffer.static PinotDataBuffermapFile(File file, boolean readOnly, long offset, long size, ByteOrder byteOrder, String description)Memory maps a file into a buffer.static PinotDataBuffermapReadOnlyBigEndianFile(File file)Memory maps a read-only big-endian file into a buffer.abstract ByteOrderorder()abstract voidputByte(int offset, byte value)abstract voidputByte(long offset, byte value)abstract voidputChar(int offset, char value)abstract voidputChar(long offset, char value)abstract voidputDouble(int offset, double value)abstract voidputDouble(long offset, double value)abstract voidputFloat(int offset, float value)abstract voidputFloat(long offset, float value)abstract voidputInt(int offset, int value)abstract voidputInt(long offset, int value)abstract voidputLong(int offset, long value)abstract voidputLong(long offset, long value)abstract voidputShort(int offset, short value)abstract voidputShort(long offset, short value)voidreadFrom(long offset, byte[] buffer)abstract voidreadFrom(long offset, byte[] buffer, int srcOffset, int size)abstract voidreadFrom(long offset, File file, long srcOffset, long size)abstract voidreadFrom(long offset, ByteBuffer buffer)abstract voidrelease()abstract longsize()ByteBuffertoDirectByteBuffer(long offset, int size)abstract ByteBuffertoDirectByteBuffer(long offset, int size, ByteOrder byteOrder)PinotDataBufferview(long start, long end)Creates a view of the range [start, end) of this buffer with the current byte order.abstract PinotDataBufferview(long start, long end, ByteOrder byteOrder)Creates a view of the range [start, end) of this buffer with the given byte order.
-
-
-
Field Detail
-
NATIVE_ORDER
public static final ByteOrder NATIVE_ORDER
-
NON_NATIVE_ORDER
public static final ByteOrder NON_NATIVE_ORDER
-
BULK_BYTES_PROCESSING_THRESHOLD
public static final int BULK_BYTES_PROCESSING_THRESHOLD
- See Also:
- Constant Field Values
-
-
Method Detail
-
allocateDirect
public static PinotDataBuffer allocateDirect(long size, ByteOrder byteOrder, @Nullable String description)
Allocates a buffer using direct memory.NOTE: The contents of the allocated buffer are not defined.
- Parameters:
size- The size of the bufferbyteOrder- The byte order of the buffer (big-endian or little-endian)description- The description of the buffer- Returns:
- The buffer allocated
-
loadFile
public static PinotDataBuffer loadFile(File file, long offset, long size, ByteOrder byteOrder, @Nullable String description) throws IOException
Allocates a buffer using direct memory and loads a file into the buffer.- Throws:
IOException
-
loadBigEndianFile
public static PinotDataBuffer loadBigEndianFile(File file) throws IOException
Allocates a buffer using direct memory and loads a big-endian file into the buffer.- Throws:
IOException
-
mapFile
public static PinotDataBuffer mapFile(File file, boolean readOnly, long offset, long size, ByteOrder byteOrder, @Nullable String description) throws IOException
Memory maps a file into a buffer.NOTE: If the file gets extended, the contents of the extended portion of the file are not defined.
- Throws:
IOException
-
mapReadOnlyBigEndianFile
public static PinotDataBuffer mapReadOnlyBigEndianFile(File file) throws IOException
Memory maps a read-only big-endian file into a buffer.- Throws:
IOException
-
getDirectBufferCount
public static long getDirectBufferCount()
-
getDirectBufferUsage
public static long getDirectBufferUsage()
-
getMmapBufferCount
public static long getMmapBufferCount()
-
getMmapBufferUsage
public static long getMmapBufferUsage()
-
getAllocationFailureCount
public static long getAllocationFailureCount()
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getByte
public abstract byte getByte(int offset)
-
getByte
public abstract byte getByte(long offset)
-
putByte
public abstract void putByte(int offset, byte value)
-
putByte
public abstract void putByte(long offset, byte value)
-
getChar
public abstract char getChar(int offset)
-
getChar
public abstract char getChar(long offset)
-
putChar
public abstract void putChar(int offset, char value)
-
putChar
public abstract void putChar(long offset, char value)
-
getShort
public abstract short getShort(int offset)
-
getShort
public abstract short getShort(long offset)
-
putShort
public abstract void putShort(int offset, short value)
-
putShort
public abstract void putShort(long offset, short value)
-
getInt
public abstract int getInt(int offset)
-
getInt
public abstract int getInt(long offset)
-
putInt
public abstract void putInt(int offset, int value)
-
putInt
public abstract void putInt(long offset, int value)
-
getLong
public abstract long getLong(int offset)
-
getLong
public abstract long getLong(long offset)
-
putLong
public abstract void putLong(int offset, long value)
-
putLong
public abstract void putLong(long offset, long value)
-
getFloat
public abstract float getFloat(int offset)
-
getFloat
public abstract float getFloat(long offset)
-
putFloat
public abstract void putFloat(int offset, float value)
-
putFloat
public abstract void putFloat(long offset, float value)
-
getDouble
public abstract double getDouble(int offset)
-
getDouble
public abstract double getDouble(long offset)
-
putDouble
public abstract void putDouble(int offset, double value)
-
putDouble
public abstract void putDouble(long offset, double value)
-
copyTo
public abstract void copyTo(long offset, byte[] buffer, int destOffset, int size)
-
copyTo
public void copyTo(long offset, byte[] buffer)
-
copyTo
public abstract void copyTo(long offset, PinotDataBuffer buffer, long destOffset, long size)
-
readFrom
public abstract void readFrom(long offset, byte[] buffer, int srcOffset, int size)
-
readFrom
public void readFrom(long offset, byte[] buffer)
-
readFrom
public abstract void readFrom(long offset, ByteBuffer buffer)
-
readFrom
public abstract void readFrom(long offset, File file, long srcOffset, long size) throws IOException- Throws:
IOException
-
size
public abstract long size()
-
order
public abstract ByteOrder order()
-
view
public abstract PinotDataBuffer view(long start, long end, ByteOrder byteOrder)
-
view
public PinotDataBuffer view(long start, long end)
-
toDirectByteBuffer
public abstract ByteBuffer toDirectByteBuffer(long offset, int size, ByteOrder byteOrder)
-
toDirectByteBuffer
public ByteBuffer toDirectByteBuffer(long offset, int size)
-
flush
public abstract void flush()
-
release
public abstract void release() throws IOException- Throws:
IOException
-
-