public class TieredStorageMemoryManagerImpl extends Object implements TieredStorageMemoryManager
TieredStorageMemoryManager
. This is to request or recycle buffers
from LocalBufferPool
for different memory owners, for example, the tiers, the buffer
accumulator, etc.
Note that the TieredStorageMemorySpec
s 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 and Description |
---|
TieredStorageMemoryManagerImpl(float numTriggerReclaimBuffersRatio,
boolean mayReclaimBuffer)
The constructor of the
TieredStorageMemoryManagerImpl . |
Modifier and Type | Method and Description |
---|---|
boolean |
ensureCapacity(int numAdditionalBuffers)
Try best to reserve enough buffers that are guaranteed reclaimable along with the additional
ones.
|
int |
getBufferPoolSize() |
int |
getMaxNonReclaimableBuffers(Object owner)
Return the number of the non-reclaimable buffers for the owner.
|
void |
listenBufferReclaimRequest(Runnable onBufferReclaimRequest)
Register a listener to listen the buffer reclaim request from the
TieredStorageMemoryManager . |
int |
numOwnerRequestedBuffer(Object owner)
Return the number of requested buffers belonging to a specific owner.
|
void |
release()
Release all the resources(if exists) and check the state of the
TieredStorageMemoryManager . |
BufferBuilder |
requestBufferBlocking(Object owner)
Request a
BufferBuilder instance for a specific owner. |
void |
setMetricGroup(TaskIOMetricGroup metricGroup)
Set the
TaskIOMetricGroup for this memory manager. |
void |
setup(BufferPool bufferPool,
List<TieredStorageMemorySpec> storageMemorySpecs)
Setup the
TieredStorageMemoryManager . |
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.
|
public TieredStorageMemoryManagerImpl(float numTriggerReclaimBuffersRatio, boolean mayReclaimBuffer)
TieredStorageMemoryManagerImpl
.numTriggerReclaimBuffersRatio
- the buffer pool usage ratio of requesting each tiered
storage to reclaim buffersmayReclaimBuffer
- indicate whether buffer reclaiming is supportedpublic void setup(BufferPool bufferPool, List<TieredStorageMemorySpec> storageMemorySpecs)
TieredStorageMemoryManager
TieredStorageMemoryManager
. When setting up the manager, the TieredStorageMemorySpec
s for different tiered storages should be ready to indicate each
tiered storage's memory requirement specs.setup
in interface TieredStorageMemoryManager
bufferPool
- the local buffer poolstorageMemorySpecs
- the memory specs for different tiered storagespublic void setMetricGroup(TaskIOMetricGroup metricGroup)
TieredStorageMemoryManager
TaskIOMetricGroup
for this memory manager.setMetricGroup
in interface TieredStorageMemoryManager
metricGroup
- the metric group to setpublic void listenBufferReclaimRequest(Runnable onBufferReclaimRequest)
TieredStorageMemoryManager
TieredStorageMemoryManager
.
When the left buffers in the BufferPool
are not enough, TieredStorageMemoryManager
will try to reclaim the buffers from the memory owners.
listenBufferReclaimRequest
in interface TieredStorageMemoryManager
onBufferReclaimRequest
- a Runnable
to process the buffer reclaim requestpublic BufferBuilder requestBufferBlocking(Object owner)
TieredStorageMemoryManager
BufferBuilder
instance for a specific owner. The TieredStorageMemoryManagerImpl
will 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.
requestBufferBlocking
in interface TieredStorageMemoryManager
owner
- the owner to request bufferpublic int getMaxNonReclaimableBuffers(Object owner)
TieredStorageMemoryManager
Note that the available buffers are calculated dynamically based on some conditions, for
example, the state of the BufferPool
, the TieredStorageMemorySpec
of 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.
getMaxNonReclaimableBuffers
in interface TieredStorageMemoryManager
public boolean ensureCapacity(int numAdditionalBuffers)
TieredStorageMemoryManager
Note that the available buffers are calculated dynamically based on some conditions, for
example, the state of the BufferPool
, the TieredStorageMemorySpec
of the
owner, etc. So the caller should always ensure capacity before requesting non-reclaimable
buffers.
ensureCapacity
in interface TieredStorageMemoryManager
numAdditionalBuffers
- the number of buffers that need to also be reserved in addition
to guaranteed reclaimable buffers.public int numOwnerRequestedBuffer(Object owner)
TieredStorageMemoryManager
numOwnerRequestedBuffer
in interface TieredStorageMemoryManager
owner
- the owner of requesting bufferspublic void transferBufferOwnership(Object oldOwner, Object newOwner, Buffer buffer)
TieredStorageMemoryManager
transferBufferOwnership
in interface TieredStorageMemoryManager
oldOwner
- the old owner of one buffernewOwner
- the new owner of one bufferbuffer
- the buffer to transfer the ownershippublic void release()
TieredStorageMemoryManager
TieredStorageMemoryManager
.release
in interface TieredStorageMemoryManager
public int getBufferPoolSize()
getBufferPoolSize
in interface TieredStorageMemoryManager
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.