Class ChannelStateWriterImpl
- java.lang.Object
-
- org.apache.flink.runtime.checkpoint.channel.ChannelStateWriterImpl
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ChannelStateWriter
@Internal @ThreadSafe public class ChannelStateWriterImpl extends Object implements ChannelStateWriter
ChannelStateWriter
implemented usingCheckpointStateOutputStreams
. Internally, it has by default- one stream per checkpoint; having multiple streams would mean more files written and more connections opened (and more latency on restore)
- one thread; having multiple threads means more connections, couples with the implementation and increases complexity
Thread-safety: this class is thread-safe when used with a thread-safe
executor
(e.g. defaultChannelStateWriteRequestExecutorImpl
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter
ChannelStateWriter.ChannelStateWriteResult, ChannelStateWriter.NoOpChannelStateWriter
-
-
Field Summary
-
Fields inherited from interface org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter
NO_OP, SEQUENCE_NUMBER_RESTORED, SEQUENCE_NUMBER_UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description ChannelStateWriterImpl(JobVertexID jobVertexID, String taskName, int subtaskIndex, SupplierWithException<CheckpointStorageWorkerView,? extends IOException> checkpointStorageWorkerViewSupplier, ChannelStateWriteRequestExecutorFactory channelStateExecutorFactory, int maxSubtasksPerChannelStateFile)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort(long checkpointId, Throwable cause, boolean cleanup)
Aborts the checkpoint and fails pending result for this checkpoint.void
addInputData(long checkpointId, InputChannelInfo info, int startSeqNum, CloseableIterator<Buffer> iterator)
Add in-flight buffers from theInputChannel
.void
addOutputData(long checkpointId, ResultSubpartitionInfo info, int startSeqNum, Buffer... data)
Add in-flight buffers from theResultSubpartition
.void
addOutputDataFuture(long checkpointId, ResultSubpartitionInfo info, int startSeqNum, CompletableFuture<List<Buffer>> dataFuture)
Add in-flight bufferFuture from theResultSubpartition
.void
close()
void
finishInput(long checkpointId)
Finalize write of channel state data for the given checkpoint id.void
finishOutput(long checkpointId)
Finalize write of channel state data for the given checkpoint id.ChannelStateWriter.ChannelStateWriteResult
getAndRemoveWriteResult(long checkpointId)
Must be called afterChannelStateWriter.start(long, CheckpointOptions)
once.ChannelStateWriter.ChannelStateWriteResult
getWriteResult(long checkpointId)
void
start(long checkpointId, CheckpointOptions checkpointOptions)
Initiate write of channel state for the given checkpoint id.
-
-
-
Constructor Detail
-
ChannelStateWriterImpl
public ChannelStateWriterImpl(JobVertexID jobVertexID, String taskName, int subtaskIndex, SupplierWithException<CheckpointStorageWorkerView,? extends IOException> checkpointStorageWorkerViewSupplier, ChannelStateWriteRequestExecutorFactory channelStateExecutorFactory, int maxSubtasksPerChannelStateFile)
-
-
Method Detail
-
start
public void start(long checkpointId, CheckpointOptions checkpointOptions)
Description copied from interface:ChannelStateWriter
Initiate write of channel state for the given checkpoint id.- Specified by:
start
in interfaceChannelStateWriter
-
addInputData
public void addInputData(long checkpointId, InputChannelInfo info, int startSeqNum, CloseableIterator<Buffer> iterator)
Description copied from interface:ChannelStateWriter
Add in-flight buffers from theInputChannel
. Must be called afterChannelStateWriter.start(long,CheckpointOptions)
and beforeChannelStateWriter.finishInput(long)
. Buffers are recycled after they are written or exception occurs.- Specified by:
addInputData
in interfaceChannelStateWriter
startSeqNum
- sequence number of the 1st passed buffer. It is intended to use for incremental snapshots. If no data is passed it is ignored.iterator
- zero or more data buffers ordered by their sequence numbers- See Also:
ChannelStateWriter.SEQUENCE_NUMBER_RESTORED
,ChannelStateWriter.SEQUENCE_NUMBER_UNKNOWN
-
addOutputData
public void addOutputData(long checkpointId, ResultSubpartitionInfo info, int startSeqNum, Buffer... data)
Description copied from interface:ChannelStateWriter
Add in-flight buffers from theResultSubpartition
. Must be called afterChannelStateWriter.start(long, org.apache.flink.runtime.checkpoint.CheckpointOptions)
and beforeChannelStateWriter.finishOutput(long)
. Buffers are recycled after they are written or exception occurs.- Specified by:
addOutputData
in interfaceChannelStateWriter
startSeqNum
- sequence number of the 1st passed buffer. It is intended to use for incremental snapshots. If no data is passed it is ignored.data
- zero or more data buffers ordered by their sequence numbers- See Also:
ChannelStateWriter.SEQUENCE_NUMBER_RESTORED
,ChannelStateWriter.SEQUENCE_NUMBER_UNKNOWN
-
addOutputDataFuture
public void addOutputDataFuture(long checkpointId, ResultSubpartitionInfo info, int startSeqNum, CompletableFuture<List<Buffer>> dataFuture) throws IllegalArgumentException
Description copied from interface:ChannelStateWriter
Add in-flight bufferFuture from theResultSubpartition
. Must be called afterChannelStateWriter.start(long, org.apache.flink.runtime.checkpoint.CheckpointOptions)
and beforeChannelStateWriter.finishOutput(long)
. Buffers are recycled after they are written or exception occurs.The method will be called when the unaligned checkpoint is enabled and received an aligned barrier.
- Specified by:
addOutputDataFuture
in interfaceChannelStateWriter
- Throws:
IllegalArgumentException
-
finishInput
public void finishInput(long checkpointId)
Description copied from interface:ChannelStateWriter
Finalize write of channel state data for the given checkpoint id. Must be called afterChannelStateWriter.start(long, CheckpointOptions)
and all of the input data of the given checkpoint added. When bothChannelStateWriter.finishInput(long)
andChannelStateWriter.finishOutput(long)
were called the results can be (eventually) obtained usingChannelStateWriter.getAndRemoveWriteResult(long)
- Specified by:
finishInput
in interfaceChannelStateWriter
-
finishOutput
public void finishOutput(long checkpointId)
Description copied from interface:ChannelStateWriter
Finalize write of channel state data for the given checkpoint id. Must be called afterChannelStateWriter.start(long, CheckpointOptions)
and all of the output data of the given checkpoint added. When bothChannelStateWriter.finishInput(long)
andChannelStateWriter.finishOutput(long)
were called the results can be (eventually) obtained usingChannelStateWriter.getAndRemoveWriteResult(long)
- Specified by:
finishOutput
in interfaceChannelStateWriter
-
abort
public void abort(long checkpointId, Throwable cause, boolean cleanup)
Description copied from interface:ChannelStateWriter
Aborts the checkpoint and fails pending result for this checkpoint.- Specified by:
abort
in interfaceChannelStateWriter
cleanup
- true ifChannelStateWriter.getAndRemoveWriteResult(long)
is not supposed to be called afterwards.
-
getAndRemoveWriteResult
public ChannelStateWriter.ChannelStateWriteResult getAndRemoveWriteResult(long checkpointId)
Description copied from interface:ChannelStateWriter
Must be called afterChannelStateWriter.start(long, CheckpointOptions)
once.- Specified by:
getAndRemoveWriteResult
in interfaceChannelStateWriter
-
getWriteResult
@VisibleForTesting public ChannelStateWriter.ChannelStateWriteResult getWriteResult(long checkpointId)
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-