Search in sources :

Example 1 with CheckpointDeclineTaskNotReadyException

use of org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineTaskNotReadyException in project flink by apache.

the class Task method triggerCheckpointBarrier.

// ------------------------------------------------------------------------
//  Notifications on the invokable
// ------------------------------------------------------------------------
/**
	 * Calls the invokable to trigger a checkpoint, if the invokable implements the interface
	 * {@link StatefulTask}.
	 * 
	 * @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, long checkpointTimestamp, final CheckpointOptions checkpointOptions) {
    final AbstractInvokable invokable = this.invokable;
    final CheckpointMetaData checkpointMetaData = new CheckpointMetaData(checkpointID, checkpointTimestamp);
    if (executionState == ExecutionState.RUNNING && invokable != null) {
        if (invokable instanceof StatefulTask) {
            // build a local closure
            final StatefulTask statefulTask = (StatefulTask) invokable;
            final String taskName = taskNameWithSubtask;
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    // activate safety net for checkpointing thread
                    LOG.debug("Creating FileSystem stream leak safety net for {}", Thread.currentThread().getName());
                    FileSystemSafetyNet.initializeSafetyNetForThread();
                    try {
                        boolean success = statefulTask.triggerCheckpoint(checkpointMetaData, checkpointOptions);
                        if (!success) {
                            checkpointResponder.declineCheckpoint(getJobID(), getExecutionId(), checkpointID, new CheckpointDeclineTaskNotReadyException(taskName));
                        }
                    } 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);
                        }
                    } finally {
                        // close and de-activate safety net for checkpointing thread
                        LOG.debug("Ensuring all FileSystem streams are closed for {}", Thread.currentThread().getName());
                        FileSystemSafetyNet.closeSafetyNetAndGuardedResourcesForThread();
                    }
                }
            };
            executeAsyncCallRunnable(runnable, String.format("Checkpoint Trigger for %s (%s).", taskNameWithSubtask, executionId));
        } else {
            checkpointResponder.declineCheckpoint(jobId, executionId, checkpointID, new CheckpointDeclineTaskNotCheckpointingException(taskNameWithSubtask));
            LOG.error("Task received a checkpoint request, but is not a checkpointing task - {} ({}).", taskNameWithSubtask, executionId);
        }
    } else {
        LOG.debug("Declining checkpoint request for non-running task {} ({}).", taskNameWithSubtask, executionId);
        // send back a message that we did not do the checkpoint
        checkpointResponder.declineCheckpoint(jobId, executionId, checkpointID, new CheckpointDeclineTaskNotReadyException(taskNameWithSubtask));
    }
}
Also used : StatefulTask(org.apache.flink.runtime.jobgraph.tasks.StatefulTask) CheckpointDeclineTaskNotCheckpointingException(org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineTaskNotCheckpointingException) CheckpointDeclineTaskNotReadyException(org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineTaskNotReadyException) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) CheckpointDeclineTaskNotCheckpointingException(org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineTaskNotCheckpointingException) TimeoutException(java.util.concurrent.TimeoutException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) CheckpointDeclineTaskNotReadyException(org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineTaskNotReadyException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)1 CheckpointDeclineTaskNotCheckpointingException (org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineTaskNotCheckpointingException)1 CheckpointDeclineTaskNotReadyException (org.apache.flink.runtime.checkpoint.decline.CheckpointDeclineTaskNotReadyException)1 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)1 AbstractInvokable (org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable)1 StatefulTask (org.apache.flink.runtime.jobgraph.tasks.StatefulTask)1 PartitionProducerDisposedException (org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException)1