Search in sources :

Example 11 with OperatorSnapshotFutures

use of org.apache.flink.streaming.api.operators.OperatorSnapshotFutures 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());
    }
}
Also used : OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures) CheckpointMetricsBuilder(org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) Test(org.junit.Test)

Example 12 with OperatorSnapshotFutures

use of org.apache.flink.streaming.api.operators.OperatorSnapshotFutures in project flink by apache.

the class SnapshotUtils method snapshot.

public static <OUT, OP extends StreamOperator<OUT>> TaggedOperatorSubtaskState snapshot(OP operator, int index, long timestamp, boolean isExactlyOnceMode, boolean isUnalignedCheckpoint, Configuration configuration, Path savepointPath) throws Exception {
    CheckpointOptions options = CheckpointOptions.forConfig(SavepointType.savepoint(SavepointFormatType.CANONICAL), AbstractFsCheckpointStorageAccess.encodePathAsReference(savepointPath), isExactlyOnceMode, isUnalignedCheckpoint, CheckpointOptions.NO_ALIGNED_CHECKPOINT_TIME_OUT);
    operator.prepareSnapshotPreBarrier(CHECKPOINT_ID);
    CheckpointStreamFactory storage = createStreamFactory(configuration, options);
    OperatorSnapshotFutures snapshotInProgress = operator.snapshotState(CHECKPOINT_ID, timestamp, options, storage);
    OperatorSubtaskState state = new OperatorSnapshotFinalizer(snapshotInProgress).getJobManagerOwnedState();
    operator.notifyCheckpointComplete(CHECKPOINT_ID);
    return new TaggedOperatorSubtaskState(index, state);
}
Also used : OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures) CheckpointStreamFactory(org.apache.flink.runtime.state.CheckpointStreamFactory) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) OperatorSnapshotFinalizer(org.apache.flink.streaming.api.operators.OperatorSnapshotFinalizer)

Example 13 with OperatorSnapshotFutures

use of org.apache.flink.streaming.api.operators.OperatorSnapshotFutures in project flink by apache.

the class AsyncCheckpointRunnable method cleanup.

/**
 * @return discarded full/incremental size (if available).
 */
private Tuple2<Long, Long> cleanup() throws Exception {
    LOG.debug("Cleanup AsyncCheckpointRunnable for checkpoint {} of {}.", checkpointMetaData.getCheckpointId(), taskName);
    Exception exception = null;
    // clean up ongoing operator snapshot results and non partitioned state handles
    long stateSize = 0, checkpointedSize = 0;
    for (OperatorSnapshotFutures operatorSnapshotResult : operatorSnapshotsInProgress.values()) {
        if (operatorSnapshotResult != null) {
            try {
                Tuple2<Long, Long> tuple2 = operatorSnapshotResult.cancel();
                stateSize += tuple2.f0;
                checkpointedSize += tuple2.f1;
            } catch (Exception cancelException) {
                exception = ExceptionUtils.firstOrSuppressed(cancelException, exception);
            }
        }
    }
    if (null != exception) {
        throw exception;
    }
    return Tuple2.of(stateSize, checkpointedSize);
}
Also used : OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) AsynchronousException(org.apache.flink.runtime.taskmanager.AsynchronousException)

Example 14 with OperatorSnapshotFutures

use of org.apache.flink.streaming.api.operators.OperatorSnapshotFutures in project flink by apache.

the class AsyncCheckpointRunnable method finalizeNonFinishedSnapshots.

private SnapshotsFinalizeResult finalizeNonFinishedSnapshots() throws Exception {
    TaskStateSnapshot jobManagerTaskOperatorSubtaskStates = new TaskStateSnapshot(operatorSnapshotsInProgress.size(), isTaskFinished);
    TaskStateSnapshot localTaskOperatorSubtaskStates = new TaskStateSnapshot(operatorSnapshotsInProgress.size(), isTaskFinished);
    long bytesPersistedDuringAlignment = 0;
    for (Map.Entry<OperatorID, OperatorSnapshotFutures> entry : operatorSnapshotsInProgress.entrySet()) {
        OperatorID operatorID = entry.getKey();
        OperatorSnapshotFutures snapshotInProgress = entry.getValue();
        // finalize the async part of all by executing all snapshot runnables
        OperatorSnapshotFinalizer finalizedSnapshots = new OperatorSnapshotFinalizer(snapshotInProgress);
        jobManagerTaskOperatorSubtaskStates.putSubtaskStateByOperatorID(operatorID, finalizedSnapshots.getJobManagerOwnedState());
        localTaskOperatorSubtaskStates.putSubtaskStateByOperatorID(operatorID, finalizedSnapshots.getTaskLocalState());
        bytesPersistedDuringAlignment += finalizedSnapshots.getJobManagerOwnedState().getResultSubpartitionState().getStateSize();
        bytesPersistedDuringAlignment += finalizedSnapshots.getJobManagerOwnedState().getInputChannelState().getStateSize();
    }
    return new SnapshotsFinalizeResult(jobManagerTaskOperatorSubtaskStates, localTaskOperatorSubtaskStates, bytesPersistedDuringAlignment);
}
Also used : OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) Map(java.util.Map) OperatorSnapshotFinalizer(org.apache.flink.streaming.api.operators.OperatorSnapshotFinalizer)

Example 15 with OperatorSnapshotFutures

use of org.apache.flink.streaming.api.operators.OperatorSnapshotFutures in project flink by apache.

the class FinishedOperatorChain method snapshotState.

@Override
public void snapshotState(Map<OperatorID, OperatorSnapshotFutures> operatorSnapshotsInProgress, CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions, Supplier<Boolean> isRunning, ChannelStateWriter.ChannelStateWriteResult channelStateWriteResult, CheckpointStreamFactory storage) throws Exception {
    for (StreamOperatorWrapper<?, ?> operatorWrapper : getAllOperators(true)) {
        StreamOperator<?> operator = operatorWrapper.getStreamOperator();
        if (operator == getMainOperator() || operator == getTailOperator()) {
            OperatorSnapshotFutures snapshotInProgress = new OperatorSnapshotFutures();
            snapshotChannelStates(operator, channelStateWriteResult, snapshotInProgress);
            operatorSnapshotsInProgress.put(operatorWrapper.getStreamOperator().getOperatorID(), snapshotInProgress);
        }
    }
}
Also used : OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures)

Aggregations

OperatorSnapshotFutures (org.apache.flink.streaming.api.operators.OperatorSnapshotFutures)21 Test (org.junit.Test)12 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)9 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)6 CheckpointException (org.apache.flink.runtime.checkpoint.CheckpointException)5 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)5 HashMap (java.util.HashMap)4 OperatorSubtaskState (org.apache.flink.runtime.checkpoint.OperatorSubtaskState)4 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)4 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 IOException (java.io.IOException)3 TimeoutException (java.util.concurrent.TimeoutException)3 CheckpointMetricsBuilder (org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder)3 DummyEnvironment (org.apache.flink.runtime.operators.testutils.DummyEnvironment)3 MockEnvironmentBuilder (org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder)3 AsynchronousException (org.apache.flink.runtime.taskmanager.AsynchronousException)3 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 JobID (org.apache.flink.api.common.JobID)2