Class AllocationManager.BufferLedger

java.lang.Object
org.apache.drill.exec.memory.AllocationManager.BufferLedger
Enclosing class:
AllocationManager

public class AllocationManager.BufferLedger extends Object
The reference manager that binds an allocator manager to a particular BaseAllocator. Also responsible for creating a set of DrillBufs that share a common fate and set of reference counts. As with AllocationManager, the only reason this is public is due to DrillBuf being in io.netty.buffer package.
  • Method Details

    • transferBalance

      public boolean transferBalance(AllocationManager.BufferLedger target)
      Transfer any balance the current ledger has to the target ledger. In the case that the current ledger holds no memory, no transfer is made to the new ledger.
      Parameters:
      target - The ledger to transfer ownership account to.
      Returns:
      Whether transfer fit within target ledgers limits.
    • print

      public void print(StringBuilder sb, int indent, BaseAllocator.Verbosity verbosity)
      Print the current ledger state to a the provided StringBuilder.
      Parameters:
      sb - The StringBuilder to populate.
      indent - The level of indentation to position the data.
      verbosity - The level of verbosity to print.
    • decrement

      public int decrement(int decrement)
      Decrement the ledger's reference count. If the ledger is decremented to zero, this ledger should release its ownership back to the AllocationManager
    • getLedgerForAllocator

      public AllocationManager.BufferLedger getLedgerForAllocator(BufferAllocator allocator)
      Returns the ledger associated with a particular BufferAllocator. If the BufferAllocator doesn't currently have a ledger associated with this AllocationManager, a new one is created. This is placed on BufferLedger rather than AllocationManager directly because DrillBufs don't have access to AllocationManager and they are the ones responsible for exposing the ability to associate multiple allocators with a particular piece of underlying memory. Note that this will increment the reference count of this ledger by one to ensure the ledger isn't destroyed before use.
      Parameters:
      allocator -
      Returns:
      The ledger associated with a particular BufferAllocator.
    • newDrillBuf

      public DrillBuf newDrillBuf(int offset, int length)
      Create a new DrillBuf associated with this AllocationManager and memory. Does not impact reference count. Typically used for slicing.
      Parameters:
      offset - The offset in bytes to start this new DrillBuf.
      length - The length in bytes that this DrillBuf will provide access to.
      Returns:
      A new DrillBuf that shares references with all DrillBufs associated with this BufferLedger
    • newDrillBuf

      public DrillBuf newDrillBuf(int offset, int length, BufferManager manager)
      Create a new DrillBuf associated with this AllocationManager and memory.
      Parameters:
      offset - The offset in bytes to start this new DrillBuf.
      length - The length in bytes that this DrillBuf will provide access to.
      manager - An optional BufferManager argument that can be used to manage expansion of this DrillBuf.
      Returns:
      A new DrillBuf that shares references with all DrillBufs associated with this BufferLedger.
    • getSize

      public int getSize()
      The total size (in bytes) of memory underlying this ledger.
      Returns:
      Size in bytes
    • getAccountedSize

      public int getAccountedSize()
      Amount of memory accounted for by this ledger. This is either getSize() if this is the owning ledger for the memory or zero in the case that this is not the owning ledger associated with this memory.
      Returns:
      Amount of accounted(owned) memory associated with this ledger.
    • getUnderlying

      protected UnsafeDirectLittleEndian getUnderlying()
      Package visible for debugging/verification only.
    • isOwningLedger

      protected boolean isOwningLedger()
      Package visible for debugging/verification only.