public class LocalBufferPool extends Object implements BufferPool
Buffer
instances from the NetworkBufferPool
.
Buffer requests are mediated to the network buffer pool to ensure deadlock free operation of the network stack by limiting the number of buffers per local buffer pool. It also implements the default mechanism for buffer recycling, which ensures that every buffer is ultimately returned to the network buffer pool.
The size of this pool can be dynamically changed at runtime (setNumBuffers(int)
. It
will then lazily return the required number of buffers to the NetworkBufferPool
to match
its new size.
New buffers can be requested only when numberOfRequestedMemorySegments <
currentPoolSize + maxOverdraftBuffersPerGate
. In other words, all buffers exceeding the
currentPoolSize will be dynamically regarded as overdraft buffers.
Availability is defined as returning a non-overdraft segment on a subsequent requestBuffer()
/ requestBufferBuilder()
and heaving a non-blocking requestBufferBuilderBlocking(int)
. In particular,
availableMemorySegments
.
maxBuffersPerChannel
.
To ensure this contract, the implementation eagerly fetches additional memory segments from
NetworkBufferPool
as long as it hasn't reached maxNumberOfMemorySegments
or one
subpartition reached the quota.
AvailabilityProvider.AvailabilityHelper
BufferRecycler.DummyBufferRecycler
AVAILABLE
Modifier and Type | Method and Description |
---|---|
boolean |
addBufferListener(BufferListener listener)
Adds a buffer availability listener to the buffer provider.
|
int |
bestEffortGetNumOfUsedBuffers()
Returns the number of used buffers of this buffer pool.
|
CompletableFuture<?> |
getAvailableFuture() |
int |
getEstimatedNumberOfRequestedMemorySegments()
Estimates the number of requested buffers.
|
int |
getExpectedNumberOfMemorySegments()
Returns the number of expected memory segments of this buffer pool, representing a value that
adequately satisfies the requirements for buffer usage.
|
int |
getMaxNumberOfMemorySegments()
Returns the maximum number of memory segments this buffer pool should use.
|
int |
getMaxOverdraftBuffersPerGate()
Returns the max overdraft buffer size of per gate.
|
int |
getMinNumberOfMemorySegments()
Returns the number of guaranteed (minimum number of) memory segments of this buffer pool.
|
int |
getNumberOfAvailableMemorySegments()
Returns the number memory segments, which are currently held by this buffer pool.
|
int |
getNumberOfRequestedMemorySegments() |
int |
getNumBuffers()
Returns the current size of this buffer pool.
|
boolean |
isDestroyed()
Checks whether this buffer pool has been destroyed.
|
void |
lazyDestroy()
Destroy is called after the produce or consume phase of a task finishes.
|
void |
recycle(MemorySegment segment)
Recycles the
MemorySegment to its original BufferPool instance. |
Buffer |
requestBuffer()
Returns a
Buffer instance from the buffer provider, if one is available. |
BufferBuilder |
requestBufferBuilder()
Returns a
BufferBuilder instance from the buffer provider. |
BufferBuilder |
requestBufferBuilder(int targetChannel)
Returns a
BufferBuilder instance from the buffer provider. |
BufferBuilder |
requestBufferBuilderBlocking()
Returns a
BufferBuilder instance from the buffer provider. |
BufferBuilder |
requestBufferBuilderBlocking(int targetChannel)
Returns a
BufferBuilder instance from the buffer provider. |
MemorySegment |
requestMemorySegment()
Returns a
MemorySegment instance from the buffer provider. |
MemorySegment |
requestMemorySegmentBlocking()
Returns a
MemorySegment instance from the buffer provider. |
void |
reserveSegments(int numberOfSegmentsToReserve)
Reserves the target number of segments to this pool.
|
void |
setMaxOverdraftBuffersPerGate(int maxOverdraftBuffersPerGate)
Sets the max overdraft buffer size of per gate.
|
void |
setNumBuffers(int numBuffers)
Sets the current size of this buffer pool.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
and, isApproximatelyAvailable, isAvailable, or
public void reserveSegments(int numberOfSegmentsToReserve) throws IOException
BufferPool
reserveSegments
in interface BufferPool
IOException
public boolean isDestroyed()
BufferPool
isDestroyed
in interface BufferPool
isDestroyed
in interface BufferProvider
public int getExpectedNumberOfMemorySegments()
BufferPool
getExpectedNumberOfMemorySegments
in interface BufferPool
public int getMinNumberOfMemorySegments()
BufferPool
getMinNumberOfMemorySegments
in interface BufferPool
public int getMaxNumberOfMemorySegments()
BufferPool
getMaxNumberOfMemorySegments
in interface BufferPool
public int getEstimatedNumberOfRequestedMemorySegments()
getMaxNumberOfMemorySegments()
for bounded pools. For
unbounded pools it returns an approximation based upon getExpectedNumberOfMemorySegments()
@VisibleForTesting public int getNumberOfRequestedMemorySegments()
public int getNumberOfAvailableMemorySegments()
BufferPool
getNumberOfAvailableMemorySegments
in interface BufferPool
public int getNumBuffers()
BufferPool
The size of the buffer pool can change dynamically at runtime.
getNumBuffers
in interface BufferPool
public int bestEffortGetNumOfUsedBuffers()
BufferPool
bestEffortGetNumOfUsedBuffers
in interface BufferPool
public Buffer requestBuffer()
BufferProvider
Buffer
instance from the buffer provider, if one is available.requestBuffer
in interface BufferProvider
null
if no buffer is available or the buffer provider has been destroyed.public BufferBuilder requestBufferBuilder()
BufferProvider
BufferBuilder
instance from the buffer provider. This equals to BufferProvider.requestBufferBuilder(int)
with unknown target channel.requestBufferBuilder
in interface BufferProvider
null
if no buffer is available or the buffer provider has been destroyed.public BufferBuilder requestBufferBuilder(int targetChannel)
BufferProvider
BufferBuilder
instance from the buffer provider.requestBufferBuilder
in interface BufferProvider
targetChannel
- to which the request will be accounted to.null
if no buffer is available or the buffer provider has been destroyed.public BufferBuilder requestBufferBuilderBlocking() throws InterruptedException
BufferProvider
BufferBuilder
instance from the buffer provider. This equals to BufferProvider.requestBufferBuilderBlocking(int)
with unknown target channel.
If there is no buffer available, the call will block until one becomes available again or the buffer provider has been destroyed.
requestBufferBuilderBlocking
in interface BufferProvider
InterruptedException
public MemorySegment requestMemorySegmentBlocking() throws InterruptedException
BufferProvider
MemorySegment
instance from the buffer provider.
If there is no memory segment available, the call will block until one becomes available again or the buffer provider has been destroyed.
requestMemorySegmentBlocking
in interface BufferProvider
InterruptedException
public BufferBuilder requestBufferBuilderBlocking(int targetChannel) throws InterruptedException
BufferProvider
BufferBuilder
instance from the buffer provider.
If there is no buffer available, the call will block until one becomes available again or the buffer provider has been destroyed.
requestBufferBuilderBlocking
in interface BufferProvider
targetChannel
- to which the request will be accounted to.InterruptedException
public MemorySegment requestMemorySegment()
BufferProvider
MemorySegment
instance from the buffer provider.requestMemorySegment
in interface BufferProvider
null
if no memory segment is available or the buffer provider has been
destroyed.public void recycle(MemorySegment segment)
BufferRecycler
MemorySegment
to its original BufferPool
instance.recycle
in interface BufferRecycler
segment
- The memory segment to be recycled.public void lazyDestroy()
lazyDestroy
in interface BufferPool
public boolean addBufferListener(BufferListener listener)
BufferProvider
The operation fails with return value false
, when there is a buffer available
or the buffer provider has been destroyed.
addBufferListener
in interface BufferProvider
public void setNumBuffers(int numBuffers)
BufferPool
The size needs to be greater or equal to the guaranteed number of memory segments.
setNumBuffers
in interface BufferPool
public void setMaxOverdraftBuffersPerGate(int maxOverdraftBuffersPerGate)
BufferPool
setMaxOverdraftBuffersPerGate
in interface BufferPool
public int getMaxOverdraftBuffersPerGate()
BufferPool
getMaxOverdraftBuffersPerGate
in interface BufferPool
public CompletableFuture<?> getAvailableFuture()
getAvailableFuture
in interface AvailabilityProvider
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.