use of org.apache.flink.streaming.api.operators.StreamTaskStateInitializerImpl in project flink by apache.
the class StreamOperatorContextBuilder method build.
StreamOperatorStateContext build(Logger logger) throws IOException {
final Environment environment = new SavepointEnvironment.Builder(ctx, maxParallelism).setConfiguration(configuration).setSubtaskIndex(split.getSplitNumber()).setPrioritizedOperatorSubtaskState(split.getPrioritizedOperatorSubtaskState()).build();
StateBackend stateBackend;
try {
stateBackend = StateBackendLoader.fromApplicationOrConfigOrDefault(applicationStateBackend, TernaryBoolean.FALSE, configuration, ctx.getUserCodeClassLoader(), logger);
} catch (DynamicCodeLoadingException e) {
throw new IOException("Failed to load state backend", e);
}
StreamTaskStateInitializer initializer = new StreamTaskStateInitializerImpl(environment, stateBackend);
try {
return initializer.streamOperatorStateContext(operatorState.getOperatorID(), operatorState.getOperatorID().toString(), new NeverFireProcessingTimeService(), keyContext, keySerializer, registry, ctx.getMetricGroup(), 1.0, false);
} catch (Exception e) {
throw new IOException("Failed to restore state backend", e);
}
}
use of org.apache.flink.streaming.api.operators.StreamTaskStateInitializerImpl in project flink by apache.
the class SubtaskCheckpointCoordinatorTest method testNotifyCheckpointSubsumed.
@Test
public void testNotifyCheckpointSubsumed() throws Exception {
TestTaskStateManager stateManager = new TestTaskStateManager();
MockEnvironment mockEnvironment = MockEnvironment.builder().setTaskStateManager(stateManager).build();
try (SubtaskCheckpointCoordinatorImpl subtaskCheckpointCoordinator = (SubtaskCheckpointCoordinatorImpl) new MockSubtaskCheckpointCoordinatorBuilder().setEnvironment(mockEnvironment).setUnalignedCheckpointEnabled(true).build()) {
StreamMap<String, String> streamMap = new StreamMap<>((MapFunction<String, String>) value -> value);
streamMap.setProcessingTimeService(new TestProcessingTimeService());
final OperatorChain<String, AbstractStreamOperator<String>> operatorChain = operatorChain(streamMap);
StreamTaskStateInitializerImpl stateInitializer = new StreamTaskStateInitializerImpl(mockEnvironment, new TestStateBackend());
operatorChain.initializeStateAndOpenOperators(stateInitializer);
long checkpointId = 42L;
subtaskCheckpointCoordinator.getChannelStateWriter().start(checkpointId, CheckpointOptions.forCheckpointWithDefaultLocation());
subtaskCheckpointCoordinator.checkpointState(new CheckpointMetaData(checkpointId, System.currentTimeMillis()), CheckpointOptions.forCheckpointWithDefaultLocation(), new CheckpointMetricsBuilder(), operatorChain, false, () -> false);
long notifySubsumeCheckpointId = checkpointId + 1L;
// notify checkpoint aborted before execution.
subtaskCheckpointCoordinator.notifyCheckpointSubsumed(notifySubsumeCheckpointId, operatorChain, () -> true);
assertEquals(notifySubsumeCheckpointId, ((TestStateBackend.TestKeyedStateBackend<?>) streamMap.getKeyedStateBackend()).getSubsumeCheckpointId());
}
}
Aggregations