public class BufferLedger extends Object implements ValueWithKeyIncluded<BufferAllocator>, ReferenceManager
AllocationManager
to
BufferAllocator
and a set of ArrowBuf
. The set of
ArrowBufs managed by this reference manager share a common
fate (same reference count).Modifier and Type | Class and Description |
---|---|
class |
BufferLedger.TransferResult
The outcome of a Transfer.
|
NO_OP, NO_OP_ERROR_MESSAGE
Modifier and Type | Method and Description |
---|---|
ArrowBuf |
deriveBuffer(ArrowBuf sourceBuffer,
long index,
long length)
Derive a new ArrowBuf from a given source ArrowBuf.
|
long |
getAccountedSize()
How much memory is accounted for by this ledger.
|
AllocationManager |
getAllocationManager()
Get the
AllocationManager used by this BufferLedger. |
BufferAllocator |
getAllocator()
Get the buffer allocator associated with this reference manager.
|
BufferAllocator |
getKey() |
int |
getRefCount()
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.
|
ArrowBuf |
retain(ArrowBuf srcBuffer,
BufferAllocator target)
Create a new ArrowBuf that is associated with an alternative allocator for the purposes of
memory ownership and accounting.
|
void |
retain(int increment)
Increment the ledger's reference count for associated
underlying memory chunk by the given amount.
|
BufferLedger.TransferResult |
transferOwnership(ArrowBuf srcBuffer,
BufferAllocator target)
Transfer the memory accounting ownership of this ArrowBuf to another allocator.
|
public BufferAllocator getKey()
getKey
in interface ValueWithKeyIncluded<BufferAllocator>
public BufferAllocator getAllocator()
getAllocator
in interface ReferenceManager
public int getRefCount()
getRefCount
in interface ReferenceManager
public boolean release()
AllocationManager
will
decide since tracks the usage of memory chunk across multiple reference
managers and allocators.release
in interface ReferenceManager
public boolean release(int decrement)
AllocationManager
will
decide since tracks the usage of memory chunk across multiple reference
managers and allocators.release
in interface ReferenceManager
decrement
- amount to decrease the reference count bypublic void retain()
retain
in interface ReferenceManager
public void retain(int increment)
retain
in interface ReferenceManager
increment
- amount to increase the reference count bypublic ArrowBuf deriveBuffer(ArrowBuf sourceBuffer, long index, long length)
This method is also used as a helper for transferring ownership and retain to target allocator.
deriveBuffer
in interface ReferenceManager
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 memorypublic ArrowBuf retain(ArrowBuf srcBuffer, BufferAllocator target)
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.
retain
in interface ReferenceManager
srcBuffer
- source ArrowBuftarget
- The target allocator to create an association with.public BufferLedger.TransferResult transferOwnership(ArrowBuf srcBuffer, BufferAllocator target)
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.
transferOwnership
in interface ReferenceManager
target
- The allocator to transfer ownership to.srcBuffer
- source ArrowBufpublic long getSize()
getSize
in interface ReferenceManager
public long getAccountedSize()
getAccountedSize
in interface ReferenceManager
public AllocationManager getAllocationManager()
AllocationManager
used by this BufferLedger.Copyright © 2023 The Apache Software Foundation. All rights reserved.