Search in sources :

Example 51 with CheckpointBarrier

use of org.apache.flink.runtime.io.network.api.CheckpointBarrier in project flink by apache.

the class MultipleInputStreamTaskChainedSourcesCheckpointingTest method testSourceCheckpointLast.

/**
 * In this scenario: 1a. network inputs are processed until CheckpointBarriers are processed 1b.
 * source records are processed at the same time 2. checkpoint is triggered via RPC 3. aligned
 * checkpoint is performed
 */
@Test
public void testSourceCheckpointLast() throws Exception {
    try (StreamTaskMailboxTestHarness<String> testHarness = buildTestHarness(objectReuse)) {
        testHarness.setAutoProcess(false);
        ArrayDeque<Object> expectedOutput = new ArrayDeque<>();
        CheckpointBarrier barrier = createBarrier(testHarness);
        addRecordsAndBarriers(testHarness, barrier);
        testHarness.processAll();
        Future<Boolean> checkpointFuture = testHarness.getStreamTask().triggerCheckpointAsync(metaData, barrier.getCheckpointOptions());
        processSingleStepUntil(testHarness, checkpointFuture::isDone);
        expectedOutput.add(new StreamRecord<>("42", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("42", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("42", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("44", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("44", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("47.0", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("47.0", TimestampAssigner.NO_TIMESTAMP));
        ArrayList<Object> actualOutput = new ArrayList<>(testHarness.getOutput());
        assertThat(actualOutput.subList(0, expectedOutput.size()), containsInAnyOrder(expectedOutput.toArray()));
        assertThat(actualOutput.get(expectedOutput.size()), equalTo(barrier));
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 52 with CheckpointBarrier

use of org.apache.flink.runtime.io.network.api.CheckpointBarrier in project flink by apache.

the class MultipleInputStreamTaskChainedSourcesCheckpointingTest method testSourceCheckpointLastUnaligned.

/**
 * In this scenario: 1. network inputs are processed until CheckpointBarriers are processed 2.
 * there are no source records to be processed 3. checkpoint is triggered on first received
 * CheckpointBarrier 4. unaligned checkpoint is performed at some point of time blocking the
 * source 5. more source records are added, that shouldn't be processed
 */
@Test
public void testSourceCheckpointLastUnaligned() throws Exception {
    boolean unaligned = true;
    try (StreamTaskMailboxTestHarness<String> testHarness = buildTestHarness(unaligned, objectReuse)) {
        testHarness.setAutoProcess(false);
        ArrayDeque<Object> expectedOutput = new ArrayDeque<>();
        addNetworkRecords(testHarness);
        CheckpointBarrier barrier = createBarrier(testHarness);
        addBarriers(testHarness, barrier);
        testHarness.processAll();
        addSourceRecords(testHarness, 1, 1337, 1337, 1337);
        testHarness.processAll();
        expectedOutput.add(new StreamRecord<>("44", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("44", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("47.0", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("47.0", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(barrier);
        assertThat(testHarness.getOutput(), containsInAnyOrder(expectedOutput.toArray()));
    }
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 53 with CheckpointBarrier

use of org.apache.flink.runtime.io.network.api.CheckpointBarrier in project flink by apache.

the class MultipleInputStreamTaskChainedSourcesCheckpointingTest method testOnlyOneSource.

@Test
public void testOnlyOneSource() throws Exception {
    try (StreamTaskMailboxTestHarness<String> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(MultipleInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO).modifyExecutionConfig(applyObjectReuse(objectReuse)).addSourceInput(new SourceOperatorFactory<>(new MockSource(Boundedness.BOUNDED, 1), WatermarkStrategy.noWatermarks()), BasicTypeInfo.INT_TYPE_INFO).setupOutputForSingletonOperatorChain(new MapToStringMultipleInputOperatorFactory(1)).build()) {
        testHarness.setAutoProcess(false);
        ArrayDeque<Object> expectedOutput = new ArrayDeque<>();
        addSourceRecords(testHarness, 0, 42, 43, 44);
        processSingleStepUntil(testHarness, () -> !testHarness.getOutput().isEmpty());
        expectedOutput.add(new StreamRecord<>("42", TimestampAssigner.NO_TIMESTAMP));
        CheckpointBarrier barrier = createBarrier(testHarness);
        Future<Boolean> checkpointFuture = testHarness.getStreamTask().triggerCheckpointAsync(metaData, barrier.getCheckpointOptions());
        processSingleStepUntil(testHarness, checkpointFuture::isDone);
        ArrayList<Object> actualOutput = new ArrayList<>(testHarness.getOutput());
        assertThat(actualOutput.subList(0, expectedOutput.size()), containsInAnyOrder(expectedOutput.toArray()));
        assertThat(actualOutput.get(expectedOutput.size()), equalTo(barrier));
    }
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) MapToStringMultipleInputOperatorFactory(org.apache.flink.streaming.runtime.tasks.MultipleInputStreamTaskTest.MapToStringMultipleInputOperatorFactory) Test(org.junit.Test)

Example 54 with CheckpointBarrier

use of org.apache.flink.runtime.io.network.api.CheckpointBarrier in project flink by apache.

the class MultipleInputStreamTaskChainedSourcesCheckpointingTest method testStopWithSavepointDrainWaitsForSourcesFinish.

/**
 * In this scenario:
 *
 * <ul>
 *   <li>Network inputs are processed until CheckpointBarriers for synchronous savepoint are
 *       processed.
 *   <li>RPC for stop-with-savepoint comes for sources
 *   <li>Sources keep being invoked until they return END_OF_DATA
 *   <li>Synchronous savepoint is triggered
 * </ul>
 */
@Test
public void testStopWithSavepointDrainWaitsForSourcesFinish() throws Exception {
    try (StreamTaskMailboxTestHarness<String> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(MultipleInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO).setCollectNetworkEvents().modifyExecutionConfig(applyObjectReuse(objectReuse)).modifyStreamConfig(config -> config.setCheckpointingEnabled(true)).addInput(BasicTypeInfo.STRING_TYPE_INFO).addSourceInput(new SourceOperatorFactory<>(new MockSource(Boundedness.CONTINUOUS_UNBOUNDED, 1), WatermarkStrategy.noWatermarks()), BasicTypeInfo.INT_TYPE_INFO).addSourceInput(new SourceOperatorFactory<>(new MockSource(Boundedness.CONTINUOUS_UNBOUNDED, 1), WatermarkStrategy.noWatermarks()), BasicTypeInfo.INT_TYPE_INFO).addInput(BasicTypeInfo.DOUBLE_TYPE_INFO).setupOutputForSingletonOperatorChain(new MapToStringMultipleInputOperatorFactory(4, true)).build()) {
        testHarness.setAutoProcess(false);
        ArrayDeque<Object> expectedOutput = new ArrayDeque<>();
        CheckpointBarrier barrier = createStopWithSavepointDrainBarrier();
        testHarness.processElement(new StreamRecord<>("44", TimestampAssigner.NO_TIMESTAMP), 0);
        testHarness.processEvent(new EndOfData(StopMode.DRAIN), 0);
        testHarness.processEvent(barrier, 0);
        testHarness.processElement(new StreamRecord<>(47d, TimestampAssigner.NO_TIMESTAMP), 1);
        testHarness.processEvent(new EndOfData(StopMode.DRAIN), 1);
        testHarness.processEvent(barrier, 1);
        addSourceRecords(testHarness, 1, Boundedness.CONTINUOUS_UNBOUNDED, 1, 2);
        addSourceRecords(testHarness, 2, Boundedness.CONTINUOUS_UNBOUNDED, 3, 4);
        testHarness.processAll();
        Future<Boolean> checkpointFuture = testHarness.getStreamTask().triggerCheckpointAsync(metaData, barrier.getCheckpointOptions());
        processSingleStepUntil(testHarness, checkpointFuture::isDone);
        expectedOutput.add(new StreamRecord<>("3", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("47.0", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("44", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("1", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("4", TimestampAssigner.NO_TIMESTAMP));
        expectedOutput.add(new StreamRecord<>("2", TimestampAssigner.NO_TIMESTAMP));
        ArrayList<Object> actualOutput = new ArrayList<>(testHarness.getOutput());
        assertThat(actualOutput.subList(0, expectedOutput.size()), containsInAnyOrder(expectedOutput.toArray()));
        assertThat(actualOutput.subList(actualOutput.size() - 3, actualOutput.size()), contains(new StreamRecord<>("FINISH"), new EndOfData(StopMode.DRAIN), barrier));
    }
}
Also used : MockSource(org.apache.flink.api.connector.source.mocks.MockSource) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) ArrayList(java.util.ArrayList) SourceOperatorFactory(org.apache.flink.streaming.api.operators.SourceOperatorFactory) ArrayDeque(java.util.ArrayDeque) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) EndOfData(org.apache.flink.runtime.io.network.api.EndOfData) MapToStringMultipleInputOperatorFactory(org.apache.flink.streaming.runtime.tasks.MultipleInputStreamTaskTest.MapToStringMultipleInputOperatorFactory) Test(org.junit.Test)

Example 55 with CheckpointBarrier

use of org.apache.flink.runtime.io.network.api.CheckpointBarrier in project flink by apache.

the class MultipleInputStreamTaskChainedSourcesCheckpointingTest method createBarrier.

private CheckpointBarrier createBarrier(StreamTaskMailboxTestHarness<String> testHarness) {
    StreamConfig config = testHarness.getStreamTask().getConfiguration();
    CheckpointOptions checkpointOptions = CheckpointOptions.forConfig(CheckpointType.CHECKPOINT, CheckpointStorageLocationReference.getDefault(), config.isExactlyOnceCheckpointMode(), config.isUnalignedCheckpointsEnabled(), config.getAlignedCheckpointTimeout().toMillis());
    return new CheckpointBarrier(metaData.getCheckpointId(), metaData.getTimestamp(), checkpointOptions);
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig)

Aggregations

CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)62 Test (org.junit.Test)43 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)14 ArrayDeque (java.util.ArrayDeque)8 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)8 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)8 ArrayList (java.util.ArrayList)7 CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)7 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)7 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)7 IOException (java.io.IOException)6 AbstractEvent (org.apache.flink.runtime.event.AbstractEvent)6 BufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferConsumer)6 CheckpointStorageLocationReference (org.apache.flink.runtime.state.CheckpointStorageLocationReference)6 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)5 EventAnnouncement (org.apache.flink.runtime.io.network.api.EventAnnouncement)5 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)5 TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)5 ByteBuffer (java.nio.ByteBuffer)4 RecordingChannelStateWriter (org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter)4