Search in sources :

Example 16 with CheckpointOptions

use of org.apache.flink.runtime.checkpoint.CheckpointOptions in project flink by apache.

the class AlternatingCheckpointsTest method testOutOfOrderBarrier.

@Test
public void testOutOfOrderBarrier() throws Exception {
    SingleInputGate inputGate = new SingleInputGateBuilder().setNumberOfChannels(2).build();
    TestInputChannel firstChannel = new TestInputChannel(inputGate, 0);
    TestInputChannel secondChannel = new TestInputChannel(inputGate, 1);
    inputGate.setInputChannels(firstChannel, secondChannel);
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    SingleCheckpointBarrierHandler barrierHandler = getTestBarrierHandlerFactory(target).create(inputGate);
    long checkpointId = 10;
    long outOfOrderSavepointId = 5;
    barrierHandler.processBarrier(new CheckpointBarrier(checkpointId, clock.relativeTimeMillis(), new CheckpointOptions(CHECKPOINT, getDefault())), new InputChannelInfo(0, 0), false);
    secondChannel.setBlocked(true);
    barrierHandler.processBarrier(new CheckpointBarrier(outOfOrderSavepointId, clock.relativeTimeMillis(), new CheckpointOptions(SavepointType.savepoint(SavepointFormatType.CANONICAL), getDefault())), new InputChannelInfo(0, 1), false);
    assertEquals(checkpointId, barrierHandler.getLatestCheckpointId());
    assertFalse(secondChannel.isBlocked());
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) Test(org.junit.Test)

Example 17 with CheckpointOptions

use of org.apache.flink.runtime.checkpoint.CheckpointOptions in project flink by apache.

the class LocalInputChannelTest method testCheckpointingInflightData.

@Test
public void testCheckpointingInflightData() throws Exception {
    SingleInputGate inputGate = new SingleInputGateBuilder().build();
    PipelinedResultPartition parent = (PipelinedResultPartition) PartitionTestUtils.createPartition(ResultPartitionType.PIPELINED, NoOpFileChannelManager.INSTANCE);
    ResultSubpartition subpartition = parent.getAllPartitions()[0];
    ResultSubpartitionView subpartitionView = subpartition.createReadView(() -> {
    });
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    final RecordingChannelStateWriter stateWriter = new RecordingChannelStateWriter();
    LocalInputChannel channel = createLocalInputChannel(inputGate, partitionManager, 0, 0, b -> b.setStateWriter(stateWriter));
    inputGate.setInputChannels(channel);
    channel.requestSubpartition();
    final CheckpointStorageLocationReference location = getDefault();
    CheckpointOptions options = CheckpointOptions.unaligned(CheckpointType.CHECKPOINT, location);
    stateWriter.start(0, options);
    final CheckpointBarrier barrier = new CheckpointBarrier(0, 123L, options);
    channel.checkpointStarted(barrier);
    // add 1 buffer before barrier and 1 buffer afterwards. Only the first buffer should be
    // written.
    subpartition.add(createFilledFinishedBufferConsumer(1));
    assertTrue(channel.getNextBuffer().isPresent());
    subpartition.add(EventSerializer.toBufferConsumer(barrier, true));
    assertTrue(channel.getNextBuffer().isPresent());
    subpartition.add(createFilledFinishedBufferConsumer(2));
    assertTrue(channel.getNextBuffer().isPresent());
    assertArrayEquals(stateWriter.getAddedInput().get(channel.getChannelInfo()).stream().mapToInt(Buffer::getSize).toArray(), new int[] { 1 });
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) PipelinedResultPartition(org.apache.flink.runtime.io.network.partition.PipelinedResultPartition) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) ResultSubpartition(org.apache.flink.runtime.io.network.partition.ResultSubpartition) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) RecordingChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) Test(org.junit.Test)

Example 18 with CheckpointOptions

use of org.apache.flink.runtime.checkpoint.CheckpointOptions in project flink by apache.

the class StreamTaskFinalCheckpointsTest method testOperatorSkipLifeCycleIfFinishedOnRestore.

@Test
public void testOperatorSkipLifeCycleIfFinishedOnRestore() throws Exception {
    try (StreamTaskMailboxTestHarness<String> harness = new StreamTaskMailboxTestHarnessBuilder<>(OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO).addInput(BasicTypeInfo.STRING_TYPE_INFO, 3).setCollectNetworkEvents().setTaskStateSnapshot(1, TaskStateSnapshot.FINISHED_ON_RESTORE).setupOperatorChain(new TestFinishedOnRestoreStreamOperator()).chain(new TestFinishedOnRestoreStreamOperator(), StringSerializer.INSTANCE).finish().build()) {
        // Finish the restore, including state initialization and open.
        harness.processAll();
        // Try trigger a checkpoint.
        harness.getTaskStateManager().getWaitForReportLatch().reset();
        CheckpointMetaData checkpointMetaData = new CheckpointMetaData(2, 2);
        CheckpointOptions checkpointOptions = new CheckpointOptions(CheckpointType.CHECKPOINT, getDefault());
        harness.streamTask.triggerCheckpointOnBarrier(checkpointMetaData, checkpointOptions, new CheckpointMetricsBuilder().setBytesProcessedDuringAlignment(0).setAlignmentDurationNanos(0));
        harness.getTaskStateManager().getWaitForReportLatch().await();
        assertEquals(2, harness.getTaskStateManager().getReportedCheckpointId());
        // Checkpoint notification.
        harness.streamTask.notifyCheckpointCompleteAsync(2);
        harness.streamTask.notifyCheckpointAbortAsync(3, 2);
        harness.processAll();
        // Finish & close operators.
        harness.processElement(Watermark.MAX_WATERMARK, 0, 0);
        harness.processElement(Watermark.MAX_WATERMARK, 0, 1);
        harness.processElement(Watermark.MAX_WATERMARK, 0, 2);
        harness.waitForTaskCompletion();
        harness.finishProcessing();
        assertThat(harness.getOutput(), contains(new CheckpointBarrier(checkpointMetaData.getCheckpointId(), checkpointMetaData.getTimestamp(), checkpointOptions), Watermark.MAX_WATERMARK, new EndOfData(StopMode.DRAIN)));
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) EndOfData(org.apache.flink.runtime.io.network.api.EndOfData) CheckpointMetricsBuilder(org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) Test(org.junit.Test)

Example 19 with CheckpointOptions

use of org.apache.flink.runtime.checkpoint.CheckpointOptions in project flink by apache.

the class SourceOperatorStreamTaskTest method executeAndWaitForCheckpoint.

private TaskStateSnapshot executeAndWaitForCheckpoint(long checkpointId, TaskStateSnapshot initialSnapshot, IntStream expectedRecords) throws Exception {
    try (StreamTaskMailboxTestHarness<Integer> testHarness = createTestHarness(checkpointId, initialSnapshot)) {
        // Add records to the splits.
        MockSourceSplit split = getAndMaybeAssignSplit(testHarness);
        // Add records to the split and update expected output.
        addRecords(split, NUM_RECORDS);
        // Process all the records.
        testHarness.processAll();
        CheckpointOptions checkpointOptions = CheckpointOptions.forCheckpointWithDefaultLocation();
        triggerCheckpointWaitForFinish(testHarness, checkpointId, checkpointOptions);
        // Build expected output to verify the results
        Queue<Object> expectedOutput = new LinkedList<>();
        expectedRecords.forEach(r -> expectedOutput.offer(new StreamRecord<>(r, TimestampAssigner.NO_TIMESTAMP)));
        // Add barrier to the expected output.
        expectedOutput.add(new CheckpointBarrier(checkpointId, checkpointId, checkpointOptions));
        assertEquals(checkpointId, testHarness.taskStateManager.getReportedCheckpointId());
        assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
        return testHarness.taskStateManager.getLastJobManagerTaskStateSnapshot();
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) MockSourceSplit(org.apache.flink.api.connector.source.mocks.MockSourceSplit) LinkedList(java.util.LinkedList)

Example 20 with CheckpointOptions

use of org.apache.flink.runtime.checkpoint.CheckpointOptions in project flink by apache.

the class SourceOperatorStreamTaskTest method testSnapshotAndAdvanceToEndOfEventTime.

@Test
public void testSnapshotAndAdvanceToEndOfEventTime() throws Exception {
    final int checkpointId = 1;
    try (StreamTaskMailboxTestHarness<Integer> testHarness = createTestHarness(checkpointId, null)) {
        getAndMaybeAssignSplit(testHarness);
        final CheckpointOptions checkpointOptions = new CheckpointOptions(SavepointType.terminate(SavepointFormatType.CANONICAL), CheckpointStorageLocationReference.getDefault());
        triggerCheckpointWaitForFinish(testHarness, checkpointId, checkpointOptions);
        Queue<Object> expectedOutput = new LinkedList<>();
        expectedOutput.add(Watermark.MAX_WATERMARK);
        expectedOutput.add(new EndOfData(StopMode.DRAIN));
        expectedOutput.add(new CheckpointBarrier(checkpointId, checkpointId, checkpointOptions));
        assertOutputEquals("Output was not correct.", expectedOutput, testHarness.getOutput());
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) EndOfData(org.apache.flink.runtime.io.network.api.EndOfData) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)43 Test (org.junit.Test)23 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)14 CheckpointStorageLocationReference (org.apache.flink.runtime.state.CheckpointStorageLocationReference)13 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)12 IOException (java.io.IOException)7 CheckpointMetricsBuilder (org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder)5 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)5 TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)5 List (java.util.List)4 Map (java.util.Map)4 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SnapshotType (org.apache.flink.runtime.checkpoint.SnapshotType)3 EndOfData (org.apache.flink.runtime.io.network.api.EndOfData)3 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)3 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)3 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)3 ByteBuffer (java.nio.ByteBuffer)2