Class HsMemoryDataManager
- java.lang.Object
-
- org.apache.flink.runtime.io.network.partition.hybrid.HsMemoryDataManager
-
- All Implemented Interfaces:
HsMemoryDataManagerOperation,HsSpillingInfoProvider
public class HsMemoryDataManager extends Object implements HsSpillingInfoProvider, HsMemoryDataManagerOperation
This class is responsible for managing data in memory.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.io.network.partition.hybrid.HsSpillingInfoProvider
HsSpillingInfoProvider.ConsumeStatus, HsSpillingInfoProvider.ConsumeStatusWithId, HsSpillingInfoProvider.SpillStatus
-
-
Constructor Summary
Constructors Constructor Description HsMemoryDataManager(int numSubpartitions, int bufferSize, BufferPool bufferPool, HsSpillingStrategy spillStrategy, HsFileDataIndex fileDataIndex, Path dataFilePath, BufferCompressor bufferCompressor, long poolSizeCheckInterval)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(ByteBuffer record, int targetChannel, Buffer.DataType dataType)Append record toHsMemoryDataManager, It will be managed byHsSubpartitionMemoryDataManagerwitch it belongs to.voidclose()Close thisHsMemoryDataManager, it means no data can append to memory and all buffer taken by this class will recycle.Deque<BufferIndexAndChannel>getBuffersInOrder(int subpartitionId, HsSpillingInfoProvider.SpillStatus spillStatus, HsSpillingInfoProvider.ConsumeStatusWithId consumeStatusWithId)Get all buffers with the expected status from the subpartition.List<Integer>getNextBufferIndexToConsume(HsConsumerId consumerId)Get all subpartition's next buffer index to consume of specific consumer.intgetNumSubpartitions()Get the number of downstream consumers.intgetNumTotalRequestedBuffers()Get total number of buffers requested from buffer pool.intgetNumTotalUnSpillBuffers()Get total number of not decided to spill buffers.intgetPoolSize()Get the current size of buffer pool.voidmarkBufferReleasedFromFile(int subpartitionId, int bufferIndex)This method is called when buffer should mark as released inHsFileDataIndex.voidonBufferConsumed(BufferIndexAndChannel consumedBuffer)This method is called when buffer is consumed.voidonBufferFinished()This method is called when buffer is finished.voidonConsumerReleased(int subpartitionId, HsConsumerId consumerId)This method is called when consumer is decided to released.voidonDataAvailable(int subpartitionId, Collection<HsConsumerId> consumerIds)This method is called when subpartition data become available.HsDataViewregisterNewConsumer(int subpartitionId, HsConsumerId consumerId, HsSubpartitionConsumerInternalOperations viewOperations)RegisterHsSubpartitionConsumerInternalOperationstosubpartitionViewOperationsMap.BufferBuilderrequestBufferFromPool()Request buffer from buffer pool.voidsetOutputMetrics(HsOutputMetrics metrics)
-
-
-
Constructor Detail
-
HsMemoryDataManager
public HsMemoryDataManager(int numSubpartitions, int bufferSize, BufferPool bufferPool, HsSpillingStrategy spillStrategy, HsFileDataIndex fileDataIndex, Path dataFilePath, BufferCompressor bufferCompressor, long poolSizeCheckInterval) throws IOException- Throws:
IOException
-
-
Method Detail
-
append
public void append(ByteBuffer record, int targetChannel, Buffer.DataType dataType) throws IOException
Append record toHsMemoryDataManager, It will be managed byHsSubpartitionMemoryDataManagerwitch it belongs to.- Parameters:
record- to be managed by this class.targetChannel- target subpartition of this record.dataType- the type of this record. In other words, is it data or event.- Throws:
IOException
-
registerNewConsumer
public HsDataView registerNewConsumer(int subpartitionId, HsConsumerId consumerId, HsSubpartitionConsumerInternalOperations viewOperations)
RegisterHsSubpartitionConsumerInternalOperationstosubpartitionViewOperationsMap. It is used to obtain the consumption progress of the subpartition.
-
close
public void close()
Close thisHsMemoryDataManager, it means no data can append to memory and all buffer taken by this class will recycle.
-
setOutputMetrics
public void setOutputMetrics(HsOutputMetrics metrics)
-
getPoolSize
public int getPoolSize()
Description copied from interface:HsSpillingInfoProviderGet the current size of buffer pool.- Specified by:
getPoolSizein interfaceHsSpillingInfoProvider
-
getNumSubpartitions
public int getNumSubpartitions()
Description copied from interface:HsSpillingInfoProviderGet the number of downstream consumers.- Specified by:
getNumSubpartitionsin interfaceHsSpillingInfoProvider- Returns:
- Number of subpartitions.
-
getNumTotalRequestedBuffers
public int getNumTotalRequestedBuffers()
Description copied from interface:HsSpillingInfoProviderGet total number of buffers requested from buffer pool.- Specified by:
getNumTotalRequestedBuffersin interfaceHsSpillingInfoProvider
-
getNumTotalUnSpillBuffers
public int getNumTotalUnSpillBuffers()
Description copied from interface:HsSpillingInfoProviderGet total number of not decided to spill buffers.- Specified by:
getNumTotalUnSpillBuffersin interfaceHsSpillingInfoProvider
-
getBuffersInOrder
public Deque<BufferIndexAndChannel> getBuffersInOrder(int subpartitionId, HsSpillingInfoProvider.SpillStatus spillStatus, HsSpillingInfoProvider.ConsumeStatusWithId consumeStatusWithId)
Description copied from interface:HsSpillingInfoProviderGet all buffers with the expected status from the subpartition.- Specified by:
getBuffersInOrderin interfaceHsSpillingInfoProvider- Parameters:
subpartitionId- target buffers belong to.spillStatus- expected buffer spill status.consumeStatusWithId- expected buffer consume status and consumer id.- Returns:
- all buffers satisfy specific status of this subpartition, This queue must be sorted according to bufferIndex from small to large, in other words, head is the buffer with the minimum bufferIndex in the current subpartition.
-
getNextBufferIndexToConsume
public List<Integer> getNextBufferIndexToConsume(HsConsumerId consumerId)
Description copied from interface:HsSpillingInfoProviderGet all subpartition's next buffer index to consume of specific consumer.- Specified by:
getNextBufferIndexToConsumein interfaceHsSpillingInfoProvider- Parameters:
consumerId- of the target downstream consumer.- Returns:
- A list containing all subpartition's next buffer index to consume of specific consumer, if the downstream subpartition view has not been registered, the corresponding return value is -1.
-
markBufferReleasedFromFile
public void markBufferReleasedFromFile(int subpartitionId, int bufferIndex)Description copied from interface:HsMemoryDataManagerOperationThis method is called when buffer should mark as released inHsFileDataIndex.- Specified by:
markBufferReleasedFromFilein interfaceHsMemoryDataManagerOperation- Parameters:
subpartitionId- the subpartition that target buffer belong to.bufferIndex- index of buffer to mark as released.
-
requestBufferFromPool
public BufferBuilder requestBufferFromPool() throws InterruptedException
Description copied from interface:HsMemoryDataManagerOperationRequest buffer from buffer pool.- Specified by:
requestBufferFromPoolin interfaceHsMemoryDataManagerOperation- Returns:
- requested buffer.
- Throws:
InterruptedException
-
onBufferConsumed
public void onBufferConsumed(BufferIndexAndChannel consumedBuffer)
Description copied from interface:HsMemoryDataManagerOperationThis method is called when buffer is consumed.- Specified by:
onBufferConsumedin interfaceHsMemoryDataManagerOperation- Parameters:
consumedBuffer- target buffer to mark as consumed.
-
onBufferFinished
public void onBufferFinished()
Description copied from interface:HsMemoryDataManagerOperationThis method is called when buffer is finished.- Specified by:
onBufferFinishedin interfaceHsMemoryDataManagerOperation
-
onDataAvailable
public void onDataAvailable(int subpartitionId, Collection<HsConsumerId> consumerIds)Description copied from interface:HsMemoryDataManagerOperationThis method is called when subpartition data become available.- Specified by:
onDataAvailablein interfaceHsMemoryDataManagerOperation- Parameters:
subpartitionId- the subpartition's identifier that this consumer belongs to.consumerIds- the consumer's identifier which need notify data available.
-
onConsumerReleased
public void onConsumerReleased(int subpartitionId, HsConsumerId consumerId)Description copied from interface:HsMemoryDataManagerOperationThis method is called when consumer is decided to released.- Specified by:
onConsumerReleasedin interfaceHsMemoryDataManagerOperation- Parameters:
subpartitionId- the subpartition's identifier that this consumer belongs to.consumerId- the consumer's identifier which decided to be released.
-
-