Class TieredStorageMemoryManagerImpl
- java.lang.Object
-
- org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage.TieredStorageMemoryManagerImpl
-
- All Implemented Interfaces:
TieredStorageMemoryManager
public class TieredStorageMemoryManagerImpl extends Object implements TieredStorageMemoryManager
The implementation forTieredStorageMemoryManager. This is to request or recycle buffers fromLocalBufferPoolfor different memory owners, for example, the tiers, the buffer accumulator, etc.Note that the
TieredStorageMemorySpecs of the tiered storages should be ready when setting up the memory manager. Only after the setup process is finished, the tiered storage can request buffers from this manager.
-
-
Constructor Summary
Constructors Constructor Description TieredStorageMemoryManagerImpl(float numTriggerReclaimBuffersRatio, boolean mayReclaimBuffer)The constructor of theTieredStorageMemoryManagerImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanensureCapacity(int numAdditionalBuffers)Try best to reserve enough buffers that are guaranteed reclaimable along with the additional ones.BufferPoolgetBufferPool()Expose and get the internalBufferPool.intgetMaxNonReclaimableBuffers(Object owner)Return the number of the non-reclaimable buffers for the owner.voidlistenBufferReclaimRequest(Runnable onBufferReclaimRequest)Register a listener to listen the buffer reclaim request from theTieredStorageMemoryManager.intnumOwnerRequestedBuffer(Object owner)Return the number of requested buffers belonging to a specific owner.voidrelease()Release all the resources(if exists) and check the state of theTieredStorageMemoryManager.BufferBuilderrequestBufferBlocking(Object owner)Request aBufferBuilderinstance for a specific owner.voidsetMetricGroup(TaskIOMetricGroup metricGroup)Set theTaskIOMetricGroupfor this memory manager.voidsetup(BufferPool bufferPool, List<TieredStorageMemorySpec> storageMemorySpecs)Setup theTieredStorageMemoryManager.voidtransferBufferOwnership(Object oldOwner, Object newOwner, Buffer buffer)Notify the memory manager that transferring one buffer's ownership from the old owner to the new owner.
-
-
-
Constructor Detail
-
TieredStorageMemoryManagerImpl
public TieredStorageMemoryManagerImpl(float numTriggerReclaimBuffersRatio, boolean mayReclaimBuffer)The constructor of theTieredStorageMemoryManagerImpl.- Parameters:
numTriggerReclaimBuffersRatio- the buffer pool usage ratio of requesting each tiered storage to reclaim buffersmayReclaimBuffer- indicate whether buffer reclaiming is supported
-
-
Method Detail
-
setup
public void setup(BufferPool bufferPool, List<TieredStorageMemorySpec> storageMemorySpecs)
Description copied from interface:TieredStorageMemoryManagerSetup theTieredStorageMemoryManager. When setting up the manager, theTieredStorageMemorySpecs for different tiered storages should be ready to indicate each tiered storage's memory requirement specs.- Specified by:
setupin interfaceTieredStorageMemoryManager- Parameters:
bufferPool- the local buffer poolstorageMemorySpecs- the memory specs for different tiered storages
-
setMetricGroup
public void setMetricGroup(TaskIOMetricGroup metricGroup)
Description copied from interface:TieredStorageMemoryManagerSet theTaskIOMetricGroupfor this memory manager.- Specified by:
setMetricGroupin interfaceTieredStorageMemoryManager- Parameters:
metricGroup- the metric group to set
-
listenBufferReclaimRequest
public void listenBufferReclaimRequest(Runnable onBufferReclaimRequest)
Description copied from interface:TieredStorageMemoryManagerRegister a listener to listen the buffer reclaim request from theTieredStorageMemoryManager.When the left buffers in the
BufferPoolare not enough,TieredStorageMemoryManagerwill try to reclaim the buffers from the memory owners.- Specified by:
listenBufferReclaimRequestin interfaceTieredStorageMemoryManager- Parameters:
onBufferReclaimRequest- aRunnableto process the buffer reclaim request
-
getBufferPool
public BufferPool getBufferPool()
Description copied from interface:TieredStorageMemoryManagerExpose and get the internalBufferPool. Please note that this method is a temporary workaround for the remote tier plugin and may be removed at any time in the future. We strongly advise that users do not rely on this method.- Specified by:
getBufferPoolin interfaceTieredStorageMemoryManager
-
requestBufferBlocking
public BufferBuilder requestBufferBlocking(Object owner)
Description copied from interface:TieredStorageMemoryManagerRequest aBufferBuilderinstance for a specific owner. TheTieredStorageMemoryManagerImplwill not check whether a buffer can be requested. The manager only records the number of requested buffers. If the buffers is not enough to meet the request, the manager will request each tiered storage to reclaim their requested buffers as much as possible.This is not thread safe and is expected to be called only from the task thread.
- Specified by:
requestBufferBlockingin interfaceTieredStorageMemoryManager- Parameters:
owner- the owner to request buffer- Returns:
- the requested buffer
-
getMaxNonReclaimableBuffers
public int getMaxNonReclaimableBuffers(Object owner)
Description copied from interface:TieredStorageMemoryManagerReturn the number of the non-reclaimable buffers for the owner.Note that the available buffers are calculated dynamically based on some conditions, for example, the state of the
BufferPool, theTieredStorageMemorySpecof the owner, etc. So the caller should always check before requesting non-reclaimable buffers.When invoking this method, the caller should be aware that the return value may occasionally be negative. This is due to the possibility of the buffer pool size shrinking to a point where it is smaller than the buffers owned by other users. In such cases, the maximum non-reclaimable buffer value returned may be negative.
- Specified by:
getMaxNonReclaimableBuffersin interfaceTieredStorageMemoryManager
-
ensureCapacity
public boolean ensureCapacity(int numAdditionalBuffers)
Description copied from interface:TieredStorageMemoryManagerTry best to reserve enough buffers that are guaranteed reclaimable along with the additional ones.Note that the available buffers are calculated dynamically based on some conditions, for example, the state of the
BufferPool, theTieredStorageMemorySpecof the owner, etc. So the caller should always ensure capacity before requesting non-reclaimable buffers.- Specified by:
ensureCapacityin interfaceTieredStorageMemoryManager- Parameters:
numAdditionalBuffers- the number of buffers that need to also be reserved in addition to guaranteed reclaimable buffers.- Returns:
- True if the capacity meets the requirements, false otherwise.
-
numOwnerRequestedBuffer
public int numOwnerRequestedBuffer(Object owner)
Description copied from interface:TieredStorageMemoryManagerReturn the number of requested buffers belonging to a specific owner.- Specified by:
numOwnerRequestedBufferin interfaceTieredStorageMemoryManager- Parameters:
owner- the owner of requesting buffers- Returns:
- the number of requested buffers belonging to the owner.
-
transferBufferOwnership
public void transferBufferOwnership(Object oldOwner, Object newOwner, Buffer buffer)
Description copied from interface:TieredStorageMemoryManagerNotify the memory manager that transferring one buffer's ownership from the old owner to the new owner.- Specified by:
transferBufferOwnershipin interfaceTieredStorageMemoryManager- Parameters:
oldOwner- the old owner of one buffernewOwner- the new owner of one bufferbuffer- the buffer to transfer the ownership
-
release
public void release()
Description copied from interface:TieredStorageMemoryManagerRelease all the resources(if exists) and check the state of theTieredStorageMemoryManager.- Specified by:
releasein interfaceTieredStorageMemoryManager
-
-