Class HsSubpartitionFileReaderImpl
- java.lang.Object
-
- org.apache.flink.runtime.io.network.partition.hybrid.HsSubpartitionFileReaderImpl
-
- All Implemented Interfaces:
Comparable<HsSubpartitionFileReader>,HsDataView,HsSubpartitionFileReader
public class HsSubpartitionFileReaderImpl extends Object implements HsSubpartitionFileReader
Default implementation ofHsSubpartitionFileReader.Note: This class is not thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHsSubpartitionFileReaderImpl.BufferIndexOrErrorIndicates a buffer with index or an error.static classHsSubpartitionFileReaderImpl.FactoryFactory ofHsSubpartitionFileReader.
-
Constructor Summary
Constructors Constructor Description HsSubpartitionFileReaderImpl(int subpartitionId, HsConsumerId consumerId, FileChannel dataFileChannel, HsSubpartitionConsumerInternalOperations operations, HsFileDataIndex dataIndex, int maxBufferReadAhead, java.util.function.Consumer<HsSubpartitionFileReader> fileReaderReleaser, ByteBuffer headerBuf)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(HsSubpartitionFileReader that)Provides priority calculation logic for io scheduler.Optional<ResultSubpartition.BufferAndBacklog>consumeBuffer(int nextBufferToConsume, Collection<Buffer> buffersToRecycle)Try to consume next buffer.booleanequals(Object o)voidfail(Throwable failureCause)Fail thisHsSubpartitionFileReadercaused by failureCause.intgetBacklog()Get the number of buffers whoseBuffer.DataTypeis buffer.Deque<HsSubpartitionFileReaderImpl.BufferIndexOrError>getLoadedBuffers()inthashCode()Buffer.DataTypepeekNextToConsumeDataType(int nextBufferToConsume, Collection<Buffer> buffersToRecycle)Get dataType of next buffer to consume.voidprepareForScheduling()Refresh downstream consumption progress for another round scheduling of reading.voidreadBuffers(Queue<org.apache.flink.core.memory.MemorySegment> buffers, BufferRecycler recycler)Read subpartition data into buffers.voidreleaseDataView()Release thisHsDataViewwhen related subpartition view is releasing.
-
-
-
Constructor Detail
-
HsSubpartitionFileReaderImpl
public HsSubpartitionFileReaderImpl(int subpartitionId, HsConsumerId consumerId, FileChannel dataFileChannel, HsSubpartitionConsumerInternalOperations operations, HsFileDataIndex dataIndex, int maxBufferReadAhead, java.util.function.Consumer<HsSubpartitionFileReader> fileReaderReleaser, ByteBuffer headerBuf)
-
-
Method Detail
-
readBuffers
public void readBuffers(Queue<org.apache.flink.core.memory.MemorySegment> buffers, BufferRecycler recycler) throws IOException
Read subpartition data into buffers.This transfers the ownership of used buffers to this class. It's this class' responsibility to release the buffers using the recycler when no longer needed.
Calling this method does not always use up all the provided buffers. It's this class' decision when to stop reading. Currently, it stops reading when: 1) buffers are used up, or 2) reaches the end of the subpartition data within the region, or 3) enough data have been read ahead the downstream consuming offset.
- Specified by:
readBuffersin interfaceHsSubpartitionFileReader- Parameters:
buffers- for reading, note that the ownership of the buffer taken out from the queue is transferred to this class, and the unused buffer must be returned.recycler- to return buffer to read buffer pool.- Throws:
IOException
-
fail
public void fail(Throwable failureCause)
Description copied from interface:HsSubpartitionFileReaderFail thisHsSubpartitionFileReadercaused by failureCause.- Specified by:
failin interfaceHsSubpartitionFileReader- Parameters:
failureCause- represents the reason why it failed.
-
prepareForScheduling
public void prepareForScheduling()
Refresh downstream consumption progress for another round scheduling of reading.- Specified by:
prepareForSchedulingin interfaceHsSubpartitionFileReader
-
compareTo
public int compareTo(HsSubpartitionFileReader that)
Provides priority calculation logic for io scheduler.- Specified by:
compareToin interfaceComparable<HsSubpartitionFileReader>
-
getLoadedBuffers
public Deque<HsSubpartitionFileReaderImpl.BufferIndexOrError> getLoadedBuffers()
-
consumeBuffer
public Optional<ResultSubpartition.BufferAndBacklog> consumeBuffer(int nextBufferToConsume, Collection<Buffer> buffersToRecycle) throws Throwable
Description copied from interface:HsDataViewTry to consume next buffer.Only invoked by consumer thread.
- Specified by:
consumeBufferin interfaceHsDataView- Parameters:
nextBufferToConsume- next buffer index to consume.buffersToRecycle- buffers to recycle if needed.- Returns:
- If the target buffer does exist, return buffer and next buffer's backlog, otherwise
return
Optional.empty(). - Throws:
Throwable
-
peekNextToConsumeDataType
public Buffer.DataType peekNextToConsumeDataType(int nextBufferToConsume, Collection<Buffer> buffersToRecycle)
Description copied from interface:HsDataViewGet dataType of next buffer to consume.- Specified by:
peekNextToConsumeDataTypein interfaceHsDataView- Parameters:
nextBufferToConsume- next buffer index to consumebuffersToRecycle- buffers to recycle if needed.- Returns:
- next buffer's dataType. If not found in memory, return
Buffer.DataType.NONE.
-
releaseDataView
public void releaseDataView()
Description copied from interface:HsDataViewRelease thisHsDataViewwhen related subpartition view is releasing.- Specified by:
releaseDataViewin interfaceHsDataView
-
getBacklog
public int getBacklog()
Description copied from interface:HsDataViewGet the number of buffers whoseBuffer.DataTypeis buffer.- Specified by:
getBacklogin interfaceHsDataView- Returns:
- backlog of this view's corresponding subpartition.
-
-