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
Modifier and TypeClassDescriptionclass
static enum
Nested classes/interfaces inherited from class org.apache.drill.exec.memory.Accountant
Accountant.AllocationOutcome
-
Field Summary
Fields inherited from class org.apache.drill.exec.memory.Accountant
ALLOW_LENIENCY, ALLOW_LENIENT_ALLOCATION, GRACE_MARGIN, MAX_GRACE, parent, reservation
-
Constructor Summary
ModifierConstructorDescriptionprotected
BaseAllocator
(BaseAllocator parentAllocator, String name, long initReservation, long maxAllocation) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Asserts (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.void
close()
Close this Accountant.io.netty.buffer.ByteBufAllocator
Returns 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 StringBuilder
indent
(StringBuilder sb, int indent) static boolean
isDebug()
static long
longNextPowerOfTwo
(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 int
nextPowerOfTwo
(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.void
read
(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.void
write
(DrillBuf buf, int length, OutputStream out) Write the contents of a DrillBuf to a stream.void
write
(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, setLimit
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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:BufferAllocator
Asserts (using java assertions) that the provided allocator is currently open. If assertions are disabled, this is a no-op.- Specified by:
assertOpen
in interfaceBufferAllocator
-
getName
Description copied from interface:BufferAllocator
Return 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:
getName
in interfaceBufferAllocator
-
getEmpty
Description copied from interface:BufferAllocator
Get 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:
getEmpty
in interfaceBufferAllocator
-
buffer
Description copied from interface:BufferAllocator
Allocate 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:
buffer
in 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:BufferAllocator
Allocate 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:
buffer
in 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:BufferAllocator
Returns the allocator this allocator falls back to when it needs more memory.- Specified by:
getAsByteBufAllocator
in interfaceBufferAllocator
- Returns:
- the underlying allocator used by this allocator
-
newChildAllocator
Description copied from interface:BufferAllocator
Create a new child allocator.- Specified by:
newChildAllocator
in 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:BufferAllocator
Create 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:
newReservation
in interfaceBufferAllocator
- Returns:
- the newly created reservation
-
close
public void close()Description copied from class:Accountant
Close this Accountant. This will release any reservation bytes back to a parent Accountant.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceBufferAllocator
- Overrides:
close
in 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:
toVerboseString
in 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:BufferAllocator
Read 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:
read
in 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:BufferAllocator
Reads the specified number of bytes into a new Drillbuf.- Specified by:
read
in 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:BufferAllocator
Write 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:
write
in interfaceBufferAllocator
- Parameters:
buf
- the Drillbuf to writeout
- the output stream- Throws:
IOException
- if a write error occurs
-
write
Description copied from interface:BufferAllocator
Write 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:
write
in 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
-