Search in sources :

Example 1 with SequentialChannelStateReader

use of org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReader in project flink by apache.

the class StreamTask method restoreGates.

private CompletableFuture<Void> restoreGates() throws Exception {
    SequentialChannelStateReader reader = getEnvironment().getTaskStateManager().getSequentialChannelStateReader();
    reader.readOutputData(getEnvironment().getAllWriters(), !configuration.isGraphContainingLoops());
    operatorChain.initializeStateAndOpenOperators(createStreamTaskStateInitializer());
    IndexedInputGate[] inputGates = getEnvironment().getAllInputGates();
    channelIOExecutor.execute(() -> {
        try {
            reader.readInputData(inputGates);
        } catch (Exception e) {
            asyncExceptionHandler.handleAsyncException("Unable to read channel state", e);
        }
    });
    // We wait for all input channel state to recover before we go into RUNNING state, and thus
    // start checkpointing. If we implement incremental checkpointing of input channel state
    // we must make sure it supports CheckpointType#FULL_CHECKPOINT
    List<CompletableFuture<?>> recoveredFutures = new ArrayList<>(inputGates.length);
    for (InputGate inputGate : inputGates) {
        recoveredFutures.add(inputGate.getStateConsumedFuture());
        inputGate.getStateConsumedFuture().thenRun(() -> mainMailboxExecutor.execute(inputGate::requestPartitions, "Input gate request partitions"));
    }
    return CompletableFuture.allOf(recoveredFutures.toArray(new CompletableFuture[0])).thenRun(mailboxProcessor::suspend);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SequentialChannelStateReader(org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReader) ArrayList(java.util.ArrayList) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) AsynchronousException(org.apache.flink.runtime.taskmanager.AsynchronousException) FlinkException(org.apache.flink.util.FlinkException) RunnableWithException(org.apache.flink.util.function.RunnableWithException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) FutureUtils.assertNoException(org.apache.flink.util.concurrent.FutureUtils.assertNoException) CompletionException(java.util.concurrent.CompletionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate)

Example 2 with SequentialChannelStateReader

use of org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReader in project flink by apache.

the class ChannelPersistenceITCase method testReadWritten.

@Test
public void testReadWritten() throws Exception {
    byte[] inputChannelInfoData = randomBytes(1024);
    byte[] resultSubpartitionInfoData = randomBytes(1024);
    int partitionIndex = 0;
    SequentialChannelStateReader reader = new SequentialChannelStateReaderImpl(toTaskStateSnapshot(write(1L, singletonMap(new InputChannelInfo(0, 0), inputChannelInfoData), singletonMap(new ResultSubpartitionInfo(partitionIndex, 0), resultSubpartitionInfoData))));
    NetworkBufferPool networkBufferPool = new NetworkBufferPool(4, 1024);
    try {
        int numChannels = 1;
        InputGate gate = buildGate(networkBufferPool, numChannels);
        reader.readInputData(new InputGate[] { gate });
        assertArrayEquals(inputChannelInfoData, collectBytes(gate::pollNext, BufferOrEvent::getBuffer));
        BufferWritingResultPartition resultPartition = buildResultPartition(networkBufferPool, ResultPartitionType.PIPELINED, partitionIndex, numChannels);
        reader.readOutputData(new BufferWritingResultPartition[] { resultPartition }, false);
        ResultSubpartitionView view = resultPartition.createSubpartitionView(0, new NoOpBufferAvailablityListener());
        assertArrayEquals(resultSubpartitionInfoData, collectBytes(() -> Optional.ofNullable(view.getNextBuffer()), BufferAndBacklog::buffer));
    } finally {
        networkBufferPool.destroy();
    }
}
Also used : InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) SequentialChannelStateReaderImpl(org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReaderImpl) ResultSubpartitionInfo(org.apache.flink.runtime.checkpoint.channel.ResultSubpartitionInfo) SequentialChannelStateReader(org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReader) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) Test(org.junit.Test)

Aggregations

SequentialChannelStateReader (org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReader)2 InputGate (org.apache.flink.runtime.io.network.partition.consumer.InputGate)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 CheckpointException (org.apache.flink.runtime.checkpoint.CheckpointException)1 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)1 ResultSubpartitionInfo (org.apache.flink.runtime.checkpoint.channel.ResultSubpartitionInfo)1 SequentialChannelStateReaderImpl (org.apache.flink.runtime.checkpoint.channel.SequentialChannelStateReaderImpl)1 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)1 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)1 BufferWritingResultPartition (org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition)1 NoOpBufferAvailablityListener (org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener)1 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)1 IndexedInputGate (org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate)1 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)1 AsynchronousException (org.apache.flink.runtime.taskmanager.AsynchronousException)1 FlinkException (org.apache.flink.util.FlinkException)1