Package org.apache.drill.exec.memory
Class Accountant
java.lang.Object
org.apache.drill.exec.memory.Accountant
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
BaseAllocator
Provides a concurrent way to manage account for memory usage without locking. Used as basis for Allocators. All
operations are threadsafe (except for close).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Describes the type of outcome that occurred when trying to account for allocation of memory. -
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
static final String
static final int
static final int
protected final Accountant
The parent allocatorprotected final long
The amount of memory reserved for this allocator. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this Accountant.void
Force lenient allocation.long
Return the current amount of allocated memory that this Accountant is managing accounting for.long
getLimit()
Return the current limit of this Accountant.long
The peak memory allocated by this Accountant.boolean
void
releaseBytes
(long size) boolean
Request lenient allocations: allows exceeding the allocation limit by the configured grace amount.void
setLimit
(long newLimit) Set the maximum amount of memory that can be allocated in the this Accountant before failing an allocation.
-
Field Details
-
ALLOW_LENIENT_ALLOCATION
- See Also:
-
GRACE_MARGIN
public static final int GRACE_MARGIN- See Also:
-
MAX_GRACE
public static final int MAX_GRACE- See Also:
-
ALLOW_LENIENCY
public static final boolean ALLOW_LENIENCY -
parent
The parent allocator -
reservation
protected final long reservationThe amount of memory reserved for this allocator. Releases below this amount of memory will not be returned to the parent Accountant until this Accountant is closed.
-
-
Constructor Details
-
Accountant
-
-
Method Details
-
setLenient
public boolean setLenient()Request lenient allocations: allows exceeding the allocation limit by the configured grace amount. The request is granted only if strict limits are not required.- Returns:
- true if the leniency was granted, false if the current execution mode, or system property, disallows leniency
-
forceLenient
public void forceLenient()Force lenient allocation. Used for testing to avoid the need to muck with global settings (assertions or system properties.) Do not use in production code! -
releaseBytes
public void releaseBytes(long size) -
setLimit
public void setLimit(long newLimit) Set the maximum amount of memory that can be allocated in the this Accountant before failing an allocation.- Parameters:
newLimit
- The limit in bytes.
-
isOverLimit
public boolean isOverLimit() -
close
public void close()Close this Accountant. This will release any reservation bytes back to a parent Accountant.- Specified by:
close
in interfaceAutoCloseable
-
getLimit
public long getLimit()Return the current limit of this Accountant.- Returns:
- Limit in bytes.
-
getAllocatedMemory
public long getAllocatedMemory()Return the current amount of allocated memory that this Accountant is managing accounting for. Note this does not include reservation memory that hasn't been allocated.- Returns:
- Currently allocate memory in bytes.
-
getPeakMemoryAllocation
public long getPeakMemoryAllocation()The peak memory allocated by this Accountant.- Returns:
- The peak allocated memory in bytes.
-