Package org.apache.drill.exec.memory
Class BaseAllocator
java.lang.Object
org.apache.drill.exec.memory.Accountant
org.apache.drill.exec.memory.BaseAllocator
- All Implemented Interfaces:
AutoCloseable,BufferAllocator
- Direct Known Subclasses:
RootAllocator
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassstatic enumNested classes/interfaces inherited from class org.apache.drill.exec.memory.Accountant
Accountant.AllocationOutcome -
Field Summary
FieldsFields inherited from class org.apache.drill.exec.memory.Accountant
ALLOW_LENIENCY, ALLOW_LENIENT_ALLOCATION, GRACE_MARGIN, MAX_GRACE, parent, reservation -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseAllocator(BaseAllocator parentAllocator, String name, long initReservation, long maxAllocation) -
Method Summary
Modifier and TypeMethodDescriptionvoidAsserts (using java assertions) that the provided allocator is currently open.buffer(int initialRequestSize) Allocate a new or reused buffer of the provided size.buffer(int initialRequestSize, BufferManager manager) Allocate a new or reused buffer of the provided size.voidclose()Close this Accountant.io.netty.buffer.ByteBufAllocatorReturns the allocator this allocator falls back to when it needs more memory.getEmpty()Get a reference to the empty buffer associated with this allocator.byte[]getName()Return the name of this allocator.static StringBuilderindent(StringBuilder sb, int indent) static booleanisDebug()static longlongNextPowerOfTwo(long val) Rounds up the provided value to the nearest power of two.newChildAllocator(String name, long initReservation, long maxAllocation) Create a new child allocator.Create an allocation reservation.static intnextPowerOfTwo(int val) Rounds up the provided value to the nearest power of two.read(int length, InputStream in) Reads the specified number of bytes into a new Drillbuf.voidread(DrillBuf buf, int length, InputStream in) Read the contents of a DrillBuf from a stream.toString()Provide a verbose string of the current allocator state.voidwrite(DrillBuf buf, int length, OutputStream out) Write the contents of a DrillBuf to a stream.voidwrite(DrillBuf buf, OutputStream out) Write the contents of a DrillBuf to a stream.Methods inherited from class org.apache.drill.exec.memory.Accountant
forceLenient, getAllocatedMemory, getLimit, getPeakMemoryAllocation, isOverLimit, releaseBytes, setLenient, setLimitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.drill.exec.memory.BufferAllocator
getAllocatedMemory, getLimit, getPeakMemoryAllocation, isOverLimit, setLenient, setLimit
-
Field Details
-
DEBUG_ALLOCATOR
- See Also:
-
DEBUG_LOG_LENGTH
public static final int DEBUG_LOG_LENGTH- See Also:
-
DEBUG
public static final boolean DEBUG
-
-
Constructor Details
-
BaseAllocator
protected BaseAllocator(BaseAllocator parentAllocator, String name, long initReservation, long maxAllocation) throws OutOfMemoryException - Throws:
OutOfMemoryException
-
-
Method Details
-
assertOpen
public void assertOpen()Description copied from interface:BufferAllocatorAsserts (using java assertions) that the provided allocator is currently open. If assertions are disabled, this is a no-op.- Specified by:
assertOpenin interfaceBufferAllocator
-
getName
Description copied from interface:BufferAllocatorReturn the name of this allocator. This is a human readable name that can help debugging. Typically provides coordinates about where this allocator was created- Specified by:
getNamein interfaceBufferAllocator
-
getEmpty
Description copied from interface:BufferAllocatorGet a reference to the empty buffer associated with this allocator. Empty buffers are special because we don't worry about them leaking or managing reference counts on them since they don't actually point to any memory.- Specified by:
getEmptyin interfaceBufferAllocator
-
buffer
Description copied from interface:BufferAllocatorAllocate a new or reused buffer of the provided size. Note that the buffer may technically be larger than the requested size for rounding purposes. However, the buffer's capacity will be set to the configured size.- Specified by:
bufferin interfaceBufferAllocator- Parameters:
initialRequestSize- The size in bytes.- Returns:
- a new DrillBuf, or null if the request can't be satisfied
-
buffer
Description copied from interface:BufferAllocatorAllocate a new or reused buffer of the provided size. Note that the buffer may technically be larger than the requested size for rounding purposes. However, the buffer's capacity will be set to the configured size.- Specified by:
bufferin interfaceBufferAllocator- Parameters:
initialRequestSize- The size in bytes.manager- A buffer manager to manage reallocation.- Returns:
- a new DrillBuf, or null if the request can't be satisfied
-
getAsByteBufAllocator
public io.netty.buffer.ByteBufAllocator getAsByteBufAllocator()Description copied from interface:BufferAllocatorReturns the allocator this allocator falls back to when it needs more memory.- Specified by:
getAsByteBufAllocatorin interfaceBufferAllocator- Returns:
- the underlying allocator used by this allocator
-
newChildAllocator
Description copied from interface:BufferAllocatorCreate a new child allocator.- Specified by:
newChildAllocatorin interfaceBufferAllocator- Parameters:
name- the name of the allocator.initReservation- the initial space reservation (obtained from this allocator)maxAllocation- maximum amount of space the new allocator can allocate- Returns:
- the new allocator, or null if it can't be created
-
newReservation
Description copied from interface:BufferAllocatorCreate an allocation reservation. A reservation is a way of building up a request for a buffer whose size is not known in advance. See .- Specified by:
newReservationin interfaceBufferAllocator- Returns:
- the newly created reservation
-
close
public void close()Description copied from class:AccountantClose this Accountant. This will release any reservation bytes back to a parent Accountant.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBufferAllocator- Overrides:
closein classAccountant
-
toString
-
toVerboseString
Provide a verbose string of the current allocator state. Includes the state of all child allocators, along with historical logs of each object and including stacktraces.- Specified by:
toVerboseStringin interfaceBufferAllocator- Returns:
- A Verbose string of current allocator state.
-
nextPowerOfTwo
public static int nextPowerOfTwo(int val) Rounds up the provided value to the nearest power of two.- Parameters:
val- An integer value.- Returns:
- The closest power of two of that value.
-
longNextPowerOfTwo
public static long longNextPowerOfTwo(long val) Rounds up the provided value to the nearest power of two.- Parameters:
val- An integer long value.- Returns:
- The closest power of two of that value.
-
indent
-
isDebug
public static boolean isDebug() -
getIOBuffer
public byte[] getIOBuffer() -
read
Description copied from interface:BufferAllocatorRead the contents of a DrillBuf from a stream. Use this method, rather than calling the DrillBuf.writeBytes() method, because this method avoids repeated heap allocation for the intermediate heap buffer. The buffer must have already been allocated.- Specified by:
readin interfaceBufferAllocator- Parameters:
buf- the buffer to read with space already allocatedlength- number of bytes to readin- input stream from which to read data- Throws:
IOException- if a read error occurs
-
read
Description copied from interface:BufferAllocatorReads the specified number of bytes into a new Drillbuf.- Specified by:
readin interfaceBufferAllocator- Parameters:
length- number of bytes to readin- input stream from which to read data- Returns:
- the buffer holding the data read from the stream
- Throws:
IOException- if a read error occurs
-
write
Description copied from interface:BufferAllocatorWrite the contents of a DrillBuf to a stream. Use this method, rather than calling the DrillBuf.getBytes() method, because this method avoids repeated heap allocation for the intermediate heap buffer. Uses the reader and writer indexes to determine the number of bytes to write. Useful only for bufs created using those indexes.- Specified by:
writein interfaceBufferAllocator- Parameters:
buf- the Drillbuf to writeout- the output stream- Throws:
IOException- if a write error occurs
-
write
Description copied from interface:BufferAllocatorWrite the contents of a DrillBuf to a stream. Use this method, rather than calling the DrillBuf.getBytes() method, because this method avoids repeated heap allocation for the intermediate heap buffer. Writes the specified number of bytes starting from the head of the given Drillbuf.- Specified by:
writein interfaceBufferAllocator- Parameters:
buf- the Drillbuf to writelength- the number of bytes to read. Must be less than or equal to number of bytes allocated in the buffer.out- the output stream- Throws:
IOException- if a write error occurs
-