use of org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder in project flink by apache.
the class LocalStateForwardingTest method testReportingFromSnapshotToTaskStateManager.
/**
* This tests the forwarding of jm and tm-local state from the futures reported by the backends,
* through the async checkpointing thread to the {@link
* org.apache.flink.runtime.state.TaskStateManager}.
*/
@Test
public void testReportingFromSnapshotToTaskStateManager() throws Exception {
TestTaskStateManager taskStateManager = new TestTaskStateManager();
StreamMockEnvironment streamMockEnvironment = new StreamMockEnvironment(new Configuration(), new Configuration(), new ExecutionConfig(), 1024 * 1024, new MockInputSplitProvider(), 0, taskStateManager);
StreamTask testStreamTask = new StreamTaskTest.NoOpStreamTask(streamMockEnvironment);
CheckpointMetaData checkpointMetaData = new CheckpointMetaData(0L, 0L);
CheckpointMetricsBuilder checkpointMetrics = new CheckpointMetricsBuilder();
Map<OperatorID, OperatorSnapshotFutures> snapshots = new HashMap<>(1);
OperatorSnapshotFutures osFuture = new OperatorSnapshotFutures();
osFuture.setKeyedStateManagedFuture(createSnapshotResult(KeyedStateHandle.class));
osFuture.setKeyedStateRawFuture(createSnapshotResult(KeyedStateHandle.class));
osFuture.setOperatorStateManagedFuture(createSnapshotResult(OperatorStateHandle.class));
osFuture.setOperatorStateRawFuture(createSnapshotResult(OperatorStateHandle.class));
osFuture.setInputChannelStateFuture(createSnapshotCollectionResult(InputChannelStateHandle.class));
osFuture.setResultSubpartitionStateFuture(createSnapshotCollectionResult(ResultSubpartitionStateHandle.class));
OperatorID operatorID = new OperatorID();
snapshots.put(operatorID, osFuture);
AsyncCheckpointRunnable checkpointRunnable = new AsyncCheckpointRunnable(snapshots, checkpointMetaData, checkpointMetrics, 0L, testStreamTask.getName(), asyncCheckpointRunnable -> {
}, testStreamTask.getEnvironment(), testStreamTask, false, false, () -> true);
checkpointMetrics.setAlignmentDurationNanos(0L);
checkpointMetrics.setBytesProcessedDuringAlignment(0L);
checkpointRunnable.run();
TaskStateSnapshot lastJobManagerTaskStateSnapshot = taskStateManager.getLastJobManagerTaskStateSnapshot();
TaskStateSnapshot lastTaskManagerTaskStateSnapshot = taskStateManager.getLastTaskManagerTaskStateSnapshot();
OperatorSubtaskState jmState = lastJobManagerTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);
OperatorSubtaskState tmState = lastTaskManagerTaskStateSnapshot.getSubtaskStateByOperatorID(operatorID);
performCheck(osFuture.getKeyedStateManagedFuture(), jmState.getManagedKeyedState(), tmState.getManagedKeyedState());
performCheck(osFuture.getKeyedStateRawFuture(), jmState.getRawKeyedState(), tmState.getRawKeyedState());
performCheck(osFuture.getOperatorStateManagedFuture(), jmState.getManagedOperatorState(), tmState.getManagedOperatorState());
performCheck(osFuture.getOperatorStateRawFuture(), jmState.getRawOperatorState(), tmState.getRawOperatorState());
performCollectionCheck(osFuture.getInputChannelStateFuture(), jmState.getInputChannelState(), tmState.getInputChannelState());
performCollectionCheck(osFuture.getResultSubpartitionStateFuture(), jmState.getResultSubpartitionState(), tmState.getResultSubpartitionState());
}
use of org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder 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)));
}
}
use of org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder in project flink by apache.
the class StreamTaskFinalCheckpointsTest method testWaitingForPendingCheckpointsOnFinished.
@Test
public void testWaitingForPendingCheckpointsOnFinished() throws Exception {
long delayedCheckpointId = 2;
CompletingCheckpointResponder responder = new CompletingCheckpointResponder() {
@Override
public void acknowledgeCheckpoint(JobID jobID, ExecutionAttemptID executionAttemptID, long checkpointId, CheckpointMetrics checkpointMetrics, TaskStateSnapshot subtaskState) {
if (delayedCheckpointId == checkpointId) {
try {
// Give some potential time for the task to finish before the
// checkpoint is acknowledged, also do not notify its completion
Thread.sleep(CONCURRENT_EVENT_WAIT_PERIOD_MS);
} catch (InterruptedException e) {
throw new FlinkRuntimeException(e);
}
} else {
super.acknowledgeCheckpoint(jobID, executionAttemptID, checkpointId, checkpointMetrics, subtaskState);
}
}
};
try (StreamTaskMailboxTestHarness<String> harness = createTestHarness(responder)) {
// finish all data
harness.waitForTaskCompletion();
// trigger the final checkpoint
harness.streamTask.triggerCheckpointOnBarrier(new CheckpointMetaData(1, 101), CheckpointOptions.forCheckpointWithDefaultLocation(), new CheckpointMetricsBuilder().setBytesProcessedDuringAlignment(0L).setAlignmentDurationNanos(0L));
// trigger another checkpoint that we want to complete before finishing the task
harness.streamTask.triggerCheckpointOnBarrier(new CheckpointMetaData(delayedCheckpointId, 101), CheckpointOptions.forCheckpointWithDefaultLocation(), new CheckpointMetricsBuilder().setBytesProcessedDuringAlignment(0L).setAlignmentDurationNanos(0L));
harness.processAll();
harness.finishProcessing();
assertEquals(delayedCheckpointId, harness.getTaskStateManager().getReportedCheckpointId());
}
}
use of org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder in project flink by apache.
the class SubtaskCheckpointCoordinatorTest method testNotifyCheckpointAbortedDuringAsyncPhase.
@Test
public void testNotifyCheckpointAbortedDuringAsyncPhase() throws Exception {
MockEnvironment mockEnvironment = MockEnvironment.builder().build();
try (SubtaskCheckpointCoordinatorImpl subtaskCheckpointCoordinator = (SubtaskCheckpointCoordinatorImpl) new MockSubtaskCheckpointCoordinatorBuilder().setEnvironment(mockEnvironment).setExecutor(Executors.newSingleThreadExecutor()).setUnalignedCheckpointEnabled(true).build()) {
final BlockingRunnableFuture rawKeyedStateHandleFuture = new BlockingRunnableFuture();
OperatorSnapshotFutures operatorSnapshotResult = new OperatorSnapshotFutures(DoneFuture.of(SnapshotResult.empty()), rawKeyedStateHandleFuture, DoneFuture.of(SnapshotResult.empty()), DoneFuture.of(SnapshotResult.empty()), DoneFuture.of(SnapshotResult.empty()), DoneFuture.of(SnapshotResult.empty()));
final OperatorChain<String, AbstractStreamOperator<String>> operatorChain = operatorChain(new CheckpointOperator(operatorSnapshotResult));
long checkpointId = 42L;
subtaskCheckpointCoordinator.getChannelStateWriter().start(checkpointId, CheckpointOptions.forCheckpointWithDefaultLocation());
subtaskCheckpointCoordinator.checkpointState(new CheckpointMetaData(checkpointId, System.currentTimeMillis()), CheckpointOptions.forCheckpointWithDefaultLocation(), new CheckpointMetricsBuilder(), operatorChain, false, () -> false);
rawKeyedStateHandleFuture.awaitRun();
assertEquals(1, subtaskCheckpointCoordinator.getAsyncCheckpointRunnableSize());
assertFalse(rawKeyedStateHandleFuture.isCancelled());
subtaskCheckpointCoordinator.notifyCheckpointAborted(checkpointId, operatorChain, () -> true);
assertTrue(rawKeyedStateHandleFuture.isCancelled());
assertEquals(0, subtaskCheckpointCoordinator.getAsyncCheckpointRunnableSize());
}
}
use of org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder in project flink by apache.
the class SubtaskCheckpointCoordinatorTest method testNotifyCheckpointAbortedAfterAsyncPhase.
@Test
public void testNotifyCheckpointAbortedAfterAsyncPhase() throws Exception {
TestTaskStateManager stateManager = new TestTaskStateManager();
MockEnvironment mockEnvironment = MockEnvironment.builder().setTaskStateManager(stateManager).build();
try (SubtaskCheckpointCoordinatorImpl subtaskCheckpointCoordinator = (SubtaskCheckpointCoordinatorImpl) new MockSubtaskCheckpointCoordinatorBuilder().setEnvironment(mockEnvironment).build()) {
final OperatorChain<?, ?> operatorChain = getOperatorChain(mockEnvironment);
long checkpointId = 42L;
subtaskCheckpointCoordinator.checkpointState(new CheckpointMetaData(checkpointId, System.currentTimeMillis()), CheckpointOptions.forCheckpointWithDefaultLocation(), new CheckpointMetricsBuilder(), operatorChain, false, () -> false);
subtaskCheckpointCoordinator.notifyCheckpointAborted(checkpointId, operatorChain, () -> true);
assertEquals(0, subtaskCheckpointCoordinator.getAbortedCheckpointSize());
assertEquals(checkpointId, stateManager.getNotifiedAbortedCheckpointId());
}
}
Aggregations