Interface TieredStorageMemoryManager
-
- All Known Implementing Classes:
TieredStorageMemoryManagerImpl
public interface TieredStorageMemoryManagerTheTieredStorageMemoryManageris to request or recycle buffers fromLocalBufferPoolfor different memory owners, for example, the tiers, the buffer accumulator, etc. Note that the logic for requesting and recycling buffers is consistent for these owners.The buffers managed by
TieredStorageMemoryManageris categorized into two types: non-reclaimable buffers which cannot be immediately released and reclaimable buffers which can be reclaimed quickly and safely. Non-reclaimable buffers necessitates waiting for other operations to complete before releasing it, such as downstream consumption. On the other hand, reclaimable buffers can be freed up at any time, enabling rapid memory recycling for tasks such as flushing memory to disk or remote storage.The
TieredStorageMemoryManagerdoes not provide strict memory limitations on any user can request. Instead, it only simply provides memory usage hints to memory users. It is very important to note that only users with non-reclaimable should check the memory hints by callinggetMaxNonReclaimableBuffersbefore requesting buffers.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description 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 fromBufferPoolfor 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.
-
-
-
Method Detail
-
setup
void setup(BufferPool bufferPool, List<TieredStorageMemorySpec> storageMemorySpecs)
Setup theTieredStorageMemoryManager. When setting up the manager, theTieredStorageMemorySpecs for different tiered storages should be ready to indicate each tiered storage's memory requirement specs.- Parameters:
bufferPool- the local buffer poolstorageMemorySpecs- the memory specs for different tiered storages
-
setMetricGroup
void setMetricGroup(TaskIOMetricGroup metricGroup)
Set theTaskIOMetricGroupfor this memory manager.- Parameters:
metricGroup- the metric group to set
-
listenBufferReclaimRequest
void listenBufferReclaimRequest(Runnable onBufferReclaimRequest)
Register 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.- Parameters:
onBufferReclaimRequest- aRunnableto process the buffer reclaim request
-
requestBufferBlocking
BufferBuilder requestBufferBlocking(Object owner)
Request aBufferBuilderinstance fromBufferPoolfor a specific owner. TheTieredStorageMemoryManagerImplwill not check whether a buffer can be requested. The manager only records the number of requested buffers. If the buffers in theBufferPoolis not enough, 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.
- Parameters:
owner- the owner to request buffer- Returns:
- the requested buffer
-
getMaxNonReclaimableBuffers
int getMaxNonReclaimableBuffers(Object owner)
Return 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.
-
numOwnerRequestedBuffer
int numOwnerRequestedBuffer(Object owner)
Return the number of requested buffers belonging to a specific owner.- Parameters:
owner- the owner of requesting buffers- Returns:
- the number of requested buffers belonging to the owner.
-
transferBufferOwnership
void transferBufferOwnership(Object oldOwner, Object newOwner, Buffer buffer)
Notify the memory manager that transferring one buffer's ownership from the old owner to the new owner.- Parameters:
oldOwner- the old owner of one buffernewOwner- the new owner of one bufferbuffer- the buffer to transfer the ownership
-
release
void release()
Release all the resources(if exists) and check the state of theTieredStorageMemoryManager.
-
-