use of org.apache.flink.runtime.io.network.api.StopMode in project flink by apache.
the class MultipleInputStreamTask method triggerStopWithSavepointAsync.
private CompletableFuture<Boolean> triggerStopWithSavepointAsync(CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions) {
CompletableFuture<Void> sourcesStopped = new CompletableFuture<>();
final StopMode stopMode = ((SavepointType) checkpointOptions.getCheckpointType()).shouldDrain() ? StopMode.DRAIN : StopMode.NO_DRAIN;
mainMailboxExecutor.execute(() -> {
setSynchronousSavepoint(checkpointMetaData.getCheckpointId());
FutureUtils.forward(FutureUtils.waitForAll(operatorChain.getSourceTaskInputs().stream().map(s -> s.getOperator().stop(stopMode)).collect(Collectors.toList())), sourcesStopped);
}, "stop chained Flip-27 source for stop-with-savepoint --drain");
return sourcesStopped.thenCompose(ignore -> triggerSourcesCheckpointAsync(checkpointMetaData, checkpointOptions));
}
use of org.apache.flink.runtime.io.network.api.StopMode in project flink by apache.
the class SourceOperatorStreamTaskTest method testSkipExecutionIfFinishedOnRestore.
@Test
public void testSkipExecutionIfFinishedOnRestore() throws Exception {
TaskStateSnapshot taskStateSnapshot = TaskStateSnapshot.FINISHED_ON_RESTORE;
LifeCycleMonitorSource testingSource = new LifeCycleMonitorSource(Boundedness.CONTINUOUS_UNBOUNDED, 10);
SourceOperatorFactory<Integer> sourceOperatorFactory = new SourceOperatorFactory<>(testingSource, WatermarkStrategy.noWatermarks());
List<Object> output = new ArrayList<>();
try (StreamTaskMailboxTestHarness<Integer> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(SourceOperatorStreamTask::new, BasicTypeInfo.INT_TYPE_INFO).setTaskStateSnapshot(1, taskStateSnapshot).addAdditionalOutput(new RecordOrEventCollectingResultPartitionWriter<StreamElement>(output, new StreamElementSerializer<>(IntSerializer.INSTANCE)) {
@Override
public void notifyEndOfData(StopMode mode) throws IOException {
broadcastEvent(new EndOfData(mode), false);
}
}).setupOperatorChain(sourceOperatorFactory).chain(new TestFinishedOnRestoreStreamOperator(), StringSerializer.INSTANCE).finish().build()) {
testHarness.getStreamTask().invoke();
testHarness.processAll();
assertThat(output, contains(Watermark.MAX_WATERMARK, new EndOfData(StopMode.DRAIN)));
LifeCycleMonitorSourceReader sourceReader = (LifeCycleMonitorSourceReader) ((SourceOperator<?, ?>) testHarness.getStreamTask().getMainOperator()).getSourceReader();
sourceReader.getLifeCycleMonitor().assertCallTimes(0, LifeCyclePhase.values());
}
}
use of org.apache.flink.runtime.io.network.api.StopMode in project flink by apache.
the class MultipleInputStreamTaskChainedSourcesCheckpointingTest method testSkipExecutionsIfFinishedOnRestoreWithSourceChained.
@Test
public void testSkipExecutionsIfFinishedOnRestoreWithSourceChained() throws Exception {
OperatorID firstSourceOperatorId = new OperatorID();
OperatorID secondSourceOperatorId = new OperatorID();
OperatorID nonSourceOperatorId = new OperatorID();
List<Object> output = new ArrayList<>();
try (StreamTaskMailboxTestHarness<String> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(MultipleInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO).modifyStreamConfig(config -> config.setCheckpointingEnabled(true)).modifyExecutionConfig(applyObjectReuse(objectReuse)).addInput(BasicTypeInfo.INT_TYPE_INFO).addAdditionalOutput(new RecordOrEventCollectingResultPartitionWriter<StreamElement>(output, new StreamElementSerializer<>(IntSerializer.INSTANCE)) {
@Override
public void notifyEndOfData(StopMode mode) throws IOException {
broadcastEvent(new EndOfData(mode), false);
}
}).addSourceInput(firstSourceOperatorId, new SourceOperatorFactory<>(new SourceOperatorStreamTaskTest.LifeCycleMonitorSource(Boundedness.CONTINUOUS_UNBOUNDED, 1), WatermarkStrategy.noWatermarks()), BasicTypeInfo.INT_TYPE_INFO).addSourceInput(secondSourceOperatorId, new SourceOperatorFactory<>(new SourceOperatorStreamTaskTest.LifeCycleMonitorSource(Boundedness.CONTINUOUS_UNBOUNDED, 1), WatermarkStrategy.noWatermarks()), BasicTypeInfo.INT_TYPE_INFO).setTaskStateSnapshot(1, TaskStateSnapshot.FINISHED_ON_RESTORE).setupOperatorChain(nonSourceOperatorId, new LifeCycleMonitorMultipleInputOperatorFactory()).chain(new TestFinishedOnRestoreStreamOperator(), StringSerializer.INSTANCE).finish().build()) {
testHarness.processElement(Watermark.MAX_WATERMARK);
assertThat(output, is(empty()));
testHarness.waitForTaskCompletion();
assertThat(output, contains(Watermark.MAX_WATERMARK, new EndOfData(StopMode.DRAIN)));
for (StreamOperatorWrapper<?, ?> wrapper : testHarness.getStreamTask().operatorChain.getAllOperators()) {
if (wrapper.getStreamOperator() instanceof SourceOperator<?, ?>) {
SourceOperatorStreamTaskTest.LifeCycleMonitorSourceReader sourceReader = (SourceOperatorStreamTaskTest.LifeCycleMonitorSourceReader) ((SourceOperator<?, ?>) wrapper.getStreamOperator()).getSourceReader();
sourceReader.getLifeCycleMonitor().assertCallTimes(0, LifeCyclePhase.values());
}
}
}
}
Aggregations