Class LocalBufferPool
- All Implemented Interfaces:
AvailabilityProvider,BufferPool,BufferProvider,BufferRecycler
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,
- There is at least one
availableMemorySegments. - No subpartitions has reached
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
AvailabilityProvider.AvailabilityHelperNested classes/interfaces inherited from interface org.apache.flink.runtime.io.network.buffer.BufferRecycler
BufferRecycler.DummyBufferRecycler -
Field Summary
Fields inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
AVAILABLE -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddBufferListener(BufferListener listener) Adds a buffer availability listener to the buffer provider.intReturns the number of used buffers of this buffer pool.intEstimates the number of requested buffers.intReturns the maximum number of memory segments this buffer pool should use.intReturns the max overdraft buffer size of per gate.intReturns the number memory segments, which are currently held by this buffer pool.intintReturns the number of guaranteed (minimum number of) memory segments of this buffer pool.intReturns the current size of this buffer pool.booleanChecks whether this buffer pool has been destroyed.voidDestroy is called after the produce or consume phase of a task finishes.voidrecycle(org.apache.flink.core.memory.MemorySegment segment) Recycles theMemorySegmentto its originalBufferPoolinstance.Returns aBufferinstance from the buffer provider, if one is available.Returns aBufferBuilderinstance from the buffer provider.requestBufferBuilder(int targetChannel) Returns aBufferBuilderinstance from the buffer provider.Returns aBufferBuilderinstance from the buffer provider.requestBufferBuilderBlocking(int targetChannel) Returns aBufferBuilderinstance from the buffer provider.org.apache.flink.core.memory.MemorySegmentReturns aMemorySegmentinstance from the buffer provider.org.apache.flink.core.memory.MemorySegmentReturns aMemorySegmentinstance from the buffer provider.voidreserveSegments(int numberOfSegmentsToReserve) Reserves the target number of segments to this pool.voidsetMaxOverdraftBuffersPerGate(int maxOverdraftBuffersPerGate) Sets the max overdraft buffer size of per gate.voidsetNumBuffers(int numBuffers) Sets the current size of this buffer pool.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.flink.runtime.io.AvailabilityProvider
isApproximatelyAvailable, isAvailable
-
Method Details
-
reserveSegments
Description copied from interface:BufferPoolReserves the target number of segments to this pool. Will throw an exception if it can not allocate enough segments.- Specified by:
reserveSegmentsin interfaceBufferPool- Throws:
IOException
-
isDestroyed
public boolean isDestroyed()Description copied from interface:BufferPoolChecks whether this buffer pool has been destroyed.- Specified by:
isDestroyedin interfaceBufferPool- Specified by:
isDestroyedin interfaceBufferProvider
-
getNumberOfRequiredMemorySegments
public int getNumberOfRequiredMemorySegments()Description copied from interface:BufferPoolReturns the number of guaranteed (minimum number of) memory segments of this buffer pool.- Specified by:
getNumberOfRequiredMemorySegmentsin interfaceBufferPool
-
getMaxNumberOfMemorySegments
public int getMaxNumberOfMemorySegments()Description copied from interface:BufferPoolReturns the maximum number of memory segments this buffer pool should use.- Specified by:
getMaxNumberOfMemorySegmentsin interfaceBufferPool- Returns:
- maximum number of memory segments to use or -1 if unlimited
-
getEstimatedNumberOfRequestedMemorySegments
public int getEstimatedNumberOfRequestedMemorySegments()Estimates the number of requested buffers.- Returns:
- the same value as
getMaxNumberOfMemorySegments()for bounded pools. For unbounded pools it returns an approximation based upongetNumberOfRequiredMemorySegments()
-
getNumberOfRequestedMemorySegments
@VisibleForTesting public int getNumberOfRequestedMemorySegments() -
getNumberOfAvailableMemorySegments
public int getNumberOfAvailableMemorySegments()Description copied from interface:BufferPoolReturns the number memory segments, which are currently held by this buffer pool.- Specified by:
getNumberOfAvailableMemorySegmentsin interfaceBufferPool
-
getNumBuffers
public int getNumBuffers()Description copied from interface:BufferPoolReturns the current size of this buffer pool.The size of the buffer pool can change dynamically at runtime.
- Specified by:
getNumBuffersin interfaceBufferPool
-
bestEffortGetNumOfUsedBuffers
public int bestEffortGetNumOfUsedBuffers()Description copied from interface:BufferPoolReturns the number of used buffers of this buffer pool.- Specified by:
bestEffortGetNumOfUsedBuffersin interfaceBufferPool
-
requestBuffer
Description copied from interface:BufferProviderReturns aBufferinstance from the buffer provider, if one is available.- Specified by:
requestBufferin interfaceBufferProvider- Returns:
nullif no buffer is available or the buffer provider has been destroyed.
-
requestBufferBuilder
Description copied from interface:BufferProviderReturns aBufferBuilderinstance from the buffer provider. This equals toBufferProvider.requestBufferBuilder(int)with unknown target channel.- Specified by:
requestBufferBuilderin interfaceBufferProvider- Returns:
nullif no buffer is available or the buffer provider has been destroyed.
-
requestBufferBuilder
Description copied from interface:BufferProviderReturns aBufferBuilderinstance from the buffer provider.- Specified by:
requestBufferBuilderin interfaceBufferProvider- Parameters:
targetChannel- to which the request will be accounted to.- Returns:
nullif no buffer is available or the buffer provider has been destroyed.
-
requestBufferBuilderBlocking
Description copied from interface:BufferProviderReturns aBufferBuilderinstance from the buffer provider. This equals toBufferProvider.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.
- Specified by:
requestBufferBuilderBlockingin interfaceBufferProvider- Throws:
InterruptedException
-
requestMemorySegmentBlocking
public org.apache.flink.core.memory.MemorySegment requestMemorySegmentBlocking() throws InterruptedExceptionDescription copied from interface:BufferProviderReturns aMemorySegmentinstance 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.
- Specified by:
requestMemorySegmentBlockingin interfaceBufferProvider- Throws:
InterruptedException
-
requestBufferBuilderBlocking
Description copied from interface:BufferProviderReturns aBufferBuilderinstance 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.
- Specified by:
requestBufferBuilderBlockingin interfaceBufferProvider- Parameters:
targetChannel- to which the request will be accounted to.- Throws:
InterruptedException
-
requestMemorySegment
public org.apache.flink.core.memory.MemorySegment requestMemorySegment()Description copied from interface:BufferProviderReturns aMemorySegmentinstance from the buffer provider.- Specified by:
requestMemorySegmentin interfaceBufferProvider- Returns:
nullif no memory segment is available or the buffer provider has been destroyed.
-
recycle
public void recycle(org.apache.flink.core.memory.MemorySegment segment) Description copied from interface:BufferRecyclerRecycles theMemorySegmentto its originalBufferPoolinstance.- Specified by:
recyclein interfaceBufferRecycler- Parameters:
segment- The memory segment to be recycled.
-
lazyDestroy
public void lazyDestroy()Destroy is called after the produce or consume phase of a task finishes.- Specified by:
lazyDestroyin interfaceBufferPool
-
addBufferListener
Description copied from interface:BufferProviderAdds a buffer availability listener to the buffer provider.The operation fails with return value
false, when there is a buffer available or the buffer provider has been destroyed.- Specified by:
addBufferListenerin interfaceBufferProvider
-
setNumBuffers
public void setNumBuffers(int numBuffers) Description copied from interface:BufferPoolSets the current size of this buffer pool.The size needs to be greater or equal to the guaranteed number of memory segments.
- Specified by:
setNumBuffersin interfaceBufferPool
-
setMaxOverdraftBuffersPerGate
public void setMaxOverdraftBuffersPerGate(int maxOverdraftBuffersPerGate) Description copied from interface:BufferPoolSets the max overdraft buffer size of per gate.- Specified by:
setMaxOverdraftBuffersPerGatein interfaceBufferPool
-
getMaxOverdraftBuffersPerGate
public int getMaxOverdraftBuffersPerGate()Description copied from interface:BufferPoolReturns the max overdraft buffer size of per gate.- Specified by:
getMaxOverdraftBuffersPerGatein interfaceBufferPool
-
getAvailableFuture
- Specified by:
getAvailableFuturein interfaceAvailabilityProvider- Returns:
- a future that is completed if the respective provider is available.
-
toString
-