Class BufferLedger
- All Implemented Interfaces:
ReferenceManager
,ValueWithKeyIncluded<BufferAllocator>
AllocationManager
to BufferAllocator
and a
set of ArrowBuf
. The set of ArrowBufs managed by this reference manager share a common
fate (same reference count).-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The outcome of a Transfer. -
Field Summary
Fields inherited from interface org.apache.arrow.memory.ReferenceManager
NO_OP, NO_OP_ERROR_MESSAGE
-
Method Summary
Modifier and TypeMethodDescriptionderiveBuffer
(ArrowBuf sourceBuffer, long index, long length) Derive a new ArrowBuf from a given source ArrowBuf.long
How much memory is accounted for by this ledger.Get theAllocationManager
used by this BufferLedger.Get the buffer allocator associated with this reference manager.getKey()
int
Get this ledger's reference count.long
getSize()
Total size (in bytes) of memory underlying this reference manager.boolean
release()
Decrement the ledger's reference count by 1 for the associated underlying memory chunk.boolean
release
(int decrement) Decrement the ledger's reference count for the associated underlying memory chunk.void
retain()
Increment the ledger's reference count for associated underlying memory chunk by 1.void
retain
(int increment) Increment the ledger's reference count for associated underlying memory chunk by the given amount.retain
(ArrowBuf srcBuffer, BufferAllocator target) Create a new ArrowBuf that is associated with an alternative allocator for the purposes of memory ownership and accounting.transferOwnership
(ArrowBuf srcBuffer, BufferAllocator target) Transfer the memory accounting ownership of this ArrowBuf to another allocator.
-
Method Details
-
getKey
- Specified by:
getKey
in interfaceValueWithKeyIncluded<BufferAllocator>
-
getAllocator
Get the buffer allocator associated with this reference manager.- Specified by:
getAllocator
in interfaceReferenceManager
- Returns:
- buffer allocator
-
getRefCount
public int getRefCount()Get this ledger's reference count.- Specified by:
getRefCount
in interfaceReferenceManager
- Returns:
- reference count
-
release
public boolean release()Decrement the ledger's reference count by 1 for the associated underlying memory chunk. If the reference count drops to 0, it implies that no ArrowBufs managed by this reference manager need access to the memory chunk. In that case, the ledger should inform the allocation manager about releasing its ownership for the chunk. Whether or not the memory chunk will be released is something thatAllocationManager
will decide since tracks the usage of memory chunk across multiple reference managers and allocators.- Specified by:
release
in interfaceReferenceManager
- Returns:
- true if the new ref count has dropped to 0, false otherwise
-
release
public boolean release(int decrement) Decrement the ledger's reference count for the associated underlying memory chunk. If the reference count drops to 0, it implies that no ArrowBufs managed by this reference manager need access to the memory chunk. In that case, the ledger should inform the allocation manager about releasing its ownership for the chunk. Whether or not the memory chunk will be released is something thatAllocationManager
will decide since tracks the usage of memory chunk across multiple reference managers and allocators.- Specified by:
release
in interfaceReferenceManager
- Parameters:
decrement
- amount to decrease the reference count by- Returns:
- true if the new ref count has dropped to 0, false otherwise
-
retain
public void retain()Increment the ledger's reference count for associated underlying memory chunk by 1.- Specified by:
retain
in interfaceReferenceManager
-
retain
public void retain(int increment) Increment the ledger's reference count for associated underlying memory chunk by the given amount.- Specified by:
retain
in interfaceReferenceManager
- Parameters:
increment
- amount to increase the reference count by
-
deriveBuffer
Derive a new ArrowBuf from a given source ArrowBuf. The new derived ArrowBuf will share the same reference count as rest of the ArrowBufs associated with this ledger. This operation is typically used for slicing -- creating new ArrowBufs from a compound ArrowBuf starting at a particular index in the underlying memory and having access to a particular length (in bytes) of data in memory chunk.This method is also used as a helper for transferring ownership and retain to target allocator.
- Specified by:
deriveBuffer
in interfaceReferenceManager
- Parameters:
sourceBuffer
- source ArrowBufindex
- index (relative to source ArrowBuf) new ArrowBuf should be derived fromlength
- length (bytes) of data in underlying memory that derived buffer will have access to in underlying memory- Returns:
- derived buffer
-
retain
Create a new ArrowBuf that is associated with an alternative allocator for the purposes of memory ownership and accounting. This has no impact on the reference counting for the current ArrowBuf except in the situation where the passed in Allocator is the same as the current buffer.This operation has no impact on the reference count of this ArrowBuf. The newly created ArrowBuf with either have a reference count of 1 (in the case that this is the first time this memory is being associated with the target allocator or in other words allocation manager currently doesn't hold a mapping for the target allocator) or the current value of the reference count for the target allocator-reference manager combination + 1 in the case that the provided allocator already had an association to this underlying memory.
- Specified by:
retain
in interfaceReferenceManager
- Parameters:
srcBuffer
- source ArrowBuftarget
- The target allocator to create an association with.- Returns:
- A new ArrowBuf which shares the same underlying memory as the provided ArrowBuf.
-
transferOwnership
Transfer the memory accounting ownership of this ArrowBuf to another allocator. This will generate a new ArrowBuf that carries an association with the underlying memory of this ArrowBuf. If this ArrowBuf is connected to the owning BufferLedger of this memory, that memory ownership/accounting will be transferred to the target allocator. If this ArrowBuf does not currently own the memory underlying it (and is only associated with it), this does not transfer any ownership to the newly created ArrowBuf.This operation has no impact on the reference count of this ArrowBuf. The newly created ArrowBuf with either have a reference count of 1 (in the case that this is the first time this memory is being associated with the new allocator) or the current value of the reference count for the other AllocationManager/BufferLedger combination + 1 in the case that the provided allocator already had an association to this underlying memory.
Transfers will always succeed, even if that puts the other allocator into an overlimit situation. This is possible due to the fact that the original owning allocator may have allocated this memory out of a local reservation whereas the target allocator may need to allocate new memory from a parent or RootAllocator. This operation is done n a mostly-lockless but consistent manner. As such, the overlimit==true situation could occur slightly prematurely to an actual overlimit==true condition. This is simply conservative behavior which means we may return overlimit slightly sooner than is necessary.
- Specified by:
transferOwnership
in interfaceReferenceManager
- Parameters:
target
- The allocator to transfer ownership to.srcBuffer
- source ArrowBuf- Returns:
- A new transfer result with the impact of the transfer (whether it was overlimit) as well as the newly created ArrowBuf.
-
getSize
public long getSize()Total size (in bytes) of memory underlying this reference manager.- Specified by:
getSize
in interfaceReferenceManager
- Returns:
- Size (in bytes) of the memory chunk
-
getAccountedSize
public long getAccountedSize()How much memory is 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.- Specified by:
getAccountedSize
in interfaceReferenceManager
- Returns:
- Amount of accounted(owned) memory associated with this ledger.
-
getAllocationManager
Get theAllocationManager
used by this BufferLedger.- Returns:
- The AllocationManager used by this BufferLedger.
-