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
Nested ClassesModifier and TypeClassDescriptionstatic enumDescribes the type of outcome that occurred when trying to account for allocation of memory. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final Stringstatic final intstatic final intprotected final AccountantThe parent allocatorprotected final longThe amount of memory reserved for this allocator. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this Accountant.voidForce lenient allocation.longReturn the current amount of allocated memory that this Accountant is managing accounting for.longgetLimit()Return the current limit of this Accountant.longThe peak memory allocated by this Accountant.booleanvoidreleaseBytes(long size) booleanRequest lenient allocations: allows exceeding the allocation limit by the configured grace amount.voidsetLimit(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:
closein 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.
-