use of org.apache.flink.runtime.taskmanager.AsynchronousException in project flink by apache.
the class ChangelogStateBackend method restore.
@SuppressWarnings({ "unchecked", "rawtypes" })
private <K> ChangelogKeyedStateBackend<K> restore(Environment env, String operatorIdentifier, KeyGroupRange keyGroupRange, TtlTimeProvider ttlTimeProvider, Collection<KeyedStateHandle> stateHandles, BaseBackendBuilder<K> baseBackendBuilder) throws Exception {
StateChangelogStorage<?> changelogStorage = Preconditions.checkNotNull(env.getTaskStateManager().getStateChangelogStorage(), "Changelog storage is null when creating and restoring" + " the ChangelogKeyedStateBackend.");
String subtaskName = env.getTaskInfo().getTaskNameWithSubtasks();
ExecutionConfig executionConfig = env.getExecutionConfig();
Collection<ChangelogStateBackendHandle> stateBackendHandles = castHandles(stateHandles);
ChangelogKeyedStateBackend<K> keyedStateBackend = ChangelogBackendRestoreOperation.restore(changelogStorage.createReader(), env.getUserCodeClassLoader().asClassLoader(), stateBackendHandles, baseBackendBuilder, (baseBackend, baseState) -> new ChangelogKeyedStateBackend(baseBackend, subtaskName, executionConfig, ttlTimeProvider, changelogStorage.createWriter(operatorIdentifier, keyGroupRange), baseState, env.getCheckpointStorageAccess()));
PeriodicMaterializationManager periodicMaterializationManager = new PeriodicMaterializationManager(checkNotNull(env.getMainMailboxExecutor()), checkNotNull(env.getAsyncOperationsThreadPool()), subtaskName, (message, exception) -> env.failExternally(new AsynchronousException(message, exception)), keyedStateBackend, executionConfig.getPeriodicMaterializeIntervalMillis(), executionConfig.getMaterializationMaxAllowedFailures());
// keyedStateBackend is responsible to close periodicMaterializationManager
// This indicates periodicMaterializationManager binds to the keyedStateBackend
// However PeriodicMaterializationManager can not be part of keyedStateBackend
// because of cyclic reference
keyedStateBackend.registerCloseable(periodicMaterializationManager);
periodicMaterializationManager.start();
return keyedStateBackend;
}
use of org.apache.flink.runtime.taskmanager.AsynchronousException in project flink by apache.
the class StreamTaskTest method streamTaskAsyncExceptionHandler_handleException_forwardsMessageProperly.
/**
* This test checks the async exceptions handling wraps the message and cause as an
* AsynchronousException and propagates this to the environment.
*/
@Test
public void streamTaskAsyncExceptionHandler_handleException_forwardsMessageProperly() {
MockEnvironment mockEnvironment = MockEnvironment.builder().build();
RuntimeException expectedException = new RuntimeException("RUNTIME EXCEPTION");
final StreamTask.StreamTaskAsyncExceptionHandler asyncExceptionHandler = new StreamTask.StreamTaskAsyncExceptionHandler(mockEnvironment);
mockEnvironment.setExpectedExternalFailureCause(AsynchronousException.class);
final String expectedErrorMessage = "EXPECTED_ERROR MESSAGE";
asyncExceptionHandler.handleAsyncException(expectedErrorMessage, expectedException);
// expect an AsynchronousException containing the supplied error details
Optional<? extends Throwable> actualExternalFailureCause = mockEnvironment.getActualExternalFailureCause();
final Throwable actualException = actualExternalFailureCause.orElseThrow(() -> new AssertionError("Expected exceptional completion"));
assertThat(actualException, instanceOf(AsynchronousException.class));
assertThat(actualException.getMessage(), is("EXPECTED_ERROR MESSAGE"));
assertThat(actualException.getCause(), is(expectedException));
}
use of org.apache.flink.runtime.taskmanager.AsynchronousException in project flink by apache.
the class AsyncCheckpointRunnable method handleExecutionException.
private void handleExecutionException(Exception e) {
boolean didCleanup = false;
AsyncCheckpointState currentState = asyncCheckpointState.get();
while (AsyncCheckpointState.DISCARDED != currentState) {
if (asyncCheckpointState.compareAndSet(currentState, AsyncCheckpointState.DISCARDED)) {
didCleanup = true;
try {
cleanup();
} catch (Exception cleanupException) {
e.addSuppressed(cleanupException);
}
Exception checkpointException = new Exception("Could not materialize checkpoint " + checkpointMetaData.getCheckpointId() + " for operator " + taskName + '.', e);
if (isTaskRunning.get()) {
// failing the task.
try {
Optional<CheckpointException> underlyingCheckpointException = ExceptionUtils.findThrowable(checkpointException, CheckpointException.class);
// If this failure is already a CheckpointException, do not overwrite the
// original CheckpointFailureReason
CheckpointFailureReason reportedFailureReason = underlyingCheckpointException.map(exception -> exception.getCheckpointFailureReason()).orElse(CheckpointFailureReason.CHECKPOINT_ASYNC_EXCEPTION);
taskEnvironment.declineCheckpoint(checkpointMetaData.getCheckpointId(), new CheckpointException(reportedFailureReason, checkpointException));
} catch (Exception unhandled) {
AsynchronousException asyncException = new AsynchronousException(unhandled);
asyncExceptionHandler.handleAsyncException("Failure in asynchronous checkpoint materialization", asyncException);
}
} else {
// We never decline checkpoint after task is not running to avoid unexpected job
// failover, which caused by exceeding checkpoint tolerable failure threshold.
LOG.info("Ignore decline of checkpoint {} as task is not running anymore.", checkpointMetaData.getCheckpointId());
}
currentState = AsyncCheckpointState.DISCARDED;
} else {
currentState = asyncCheckpointState.get();
}
}
if (!didCleanup) {
LOG.trace("Caught followup exception from a failed checkpoint thread. This can be ignored.", e);
}
}
Aggregations