Search in sources :

Example 1 with CheckpointableTask

use of org.apache.flink.runtime.jobgraph.tasks.CheckpointableTask in project flink by apache.

the class Task method triggerCheckpointBarrier.

// ------------------------------------------------------------------------
// Notifications on the invokable
// ------------------------------------------------------------------------
/**
 * Calls the invokable to trigger a checkpoint.
 *
 * @param checkpointID The ID identifying the checkpoint.
 * @param checkpointTimestamp The timestamp associated with the checkpoint.
 * @param checkpointOptions Options for performing this checkpoint.
 */
public void triggerCheckpointBarrier(final long checkpointID, final long checkpointTimestamp, final CheckpointOptions checkpointOptions) {
    final TaskInvokable invokable = this.invokable;
    final CheckpointMetaData checkpointMetaData = new CheckpointMetaData(checkpointID, checkpointTimestamp, System.currentTimeMillis());
    if (executionState == ExecutionState.RUNNING) {
        checkState(invokable instanceof CheckpointableTask, "invokable is not checkpointable");
        try {
            ((CheckpointableTask) invokable).triggerCheckpointAsync(checkpointMetaData, checkpointOptions).handle((triggerResult, exception) -> {
                if (exception != null || !triggerResult) {
                    declineCheckpoint(checkpointID, CheckpointFailureReason.TASK_FAILURE, exception);
                    return false;
                }
                return true;
            });
        } catch (RejectedExecutionException ex) {
            // This may happen if the mailbox is closed. It means that the task is shutting
            // down, so we just ignore it.
            LOG.debug("Triggering checkpoint {} for {} ({}) was rejected by the mailbox", checkpointID, taskNameWithSubtask, executionId);
            declineCheckpoint(checkpointID, CheckpointFailureReason.CHECKPOINT_DECLINED_TASK_CLOSING);
        } catch (Throwable t) {
            if (getExecutionState() == ExecutionState.RUNNING) {
                failExternally(new Exception("Error while triggering checkpoint " + checkpointID + " for " + taskNameWithSubtask, t));
            } else {
                LOG.debug("Encountered error while triggering checkpoint {} for " + "{} ({}) while being not in state running.", checkpointID, taskNameWithSubtask, executionId, t);
            }
        }
    } else {
        LOG.debug("Declining checkpoint request for non-running task {} ({}).", taskNameWithSubtask, executionId);
        // send back a message that we did not do the checkpoint
        declineCheckpoint(checkpointID, CheckpointFailureReason.CHECKPOINT_DECLINED_TASK_NOT_READY);
    }
}
Also used : TaskInvokable(org.apache.flink.runtime.jobgraph.tasks.TaskInvokable) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) CheckpointableTask(org.apache.flink.runtime.jobgraph.tasks.CheckpointableTask) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TaskNotRunningException(org.apache.flink.runtime.operators.coordination.TaskNotRunningException) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) InvocationTargetException(java.lang.reflect.InvocationTargetException) FlinkException(org.apache.flink.util.FlinkException) RunnableWithException(org.apache.flink.util.function.RunnableWithException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 CheckpointException (org.apache.flink.runtime.checkpoint.CheckpointException)1 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)1 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)1 CheckpointableTask (org.apache.flink.runtime.jobgraph.tasks.CheckpointableTask)1 TaskInvokable (org.apache.flink.runtime.jobgraph.tasks.TaskInvokable)1 TaskNotRunningException (org.apache.flink.runtime.operators.coordination.TaskNotRunningException)1 FlinkException (org.apache.flink.util.FlinkException)1 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)1 WrappingRuntimeException (org.apache.flink.util.WrappingRuntimeException)1 RunnableWithException (org.apache.flink.util.function.RunnableWithException)1