Class Accountant

java.lang.Object
org.apache.drill.exec.memory.Accountant
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
BaseAllocator

@ThreadSafe public class Accountant extends Object implements AutoCloseable
Provides a concurrent way to manage account for memory usage without locking. Used as basis for Allocators. All operations are threadsafe (except for close).
  • Field Details

    • ALLOW_LENIENT_ALLOCATION

      public static final String 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

      protected final Accountant parent
      The parent allocator
    • reservation

      protected final long reservation
      The 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

      public Accountant(Accountant parent, long reservation, long maxAllocation)
  • 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 interface AutoCloseable
    • 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.