Java Code Examples for org.apache.flink.runtime.executiongraph.Execution#getState()

The following examples show how to use org.apache.flink.runtime.executiongraph.Execution#getState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskDeploymentDescriptorFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
public static ShuffleDescriptor getConsumedPartitionShuffleDescriptor(
		ExecutionEdge edge,
		boolean allowUnknownPartitions) {
	IntermediateResultPartition consumedPartition = edge.getSource();
	Execution producer = consumedPartition.getProducer().getCurrentExecutionAttempt();

	ExecutionState producerState = producer.getState();
	Optional<ResultPartitionDeploymentDescriptor> consumedPartitionDescriptor =
		producer.getResultPartitionDeploymentDescriptor(consumedPartition.getPartitionId());

	ResultPartitionID consumedPartitionId = new ResultPartitionID(
		consumedPartition.getPartitionId(),
		producer.getAttemptId());

	return getConsumedPartitionShuffleDescriptor(
		consumedPartitionId,
		consumedPartition.getResultType(),
		consumedPartition.isConsumable(),
		producerState,
		allowUnknownPartitions,
		consumedPartitionDescriptor.orElse(null));
}
 
Example 2
Source File: TaskDeploymentDescriptorFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
public static ShuffleDescriptor getConsumedPartitionShuffleDescriptor(
		ExecutionEdge edge,
		boolean allowUnknownPartitions) {
	IntermediateResultPartition consumedPartition = edge.getSource();
	Execution producer = consumedPartition.getProducer().getCurrentExecutionAttempt();

	ExecutionState producerState = producer.getState();
	Optional<ResultPartitionDeploymentDescriptor> consumedPartitionDescriptor =
		producer.getResultPartitionDeploymentDescriptor(consumedPartition.getPartitionId());

	ResultPartitionID consumedPartitionId = new ResultPartitionID(
		consumedPartition.getPartitionId(),
		producer.getAttemptId());

	return getConsumedPartitionShuffleDescriptor(
		consumedPartitionId,
		consumedPartition.getResultType(),
		consumedPartition.isConsumable(),
		producerState,
		allowUnknownPartitions,
		consumedPartitionDescriptor.orElse(null));
}
 
Example 3
Source File: LegacyScheduler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public ExecutionState requestPartitionState(
		final IntermediateDataSetID intermediateResultId,
		final ResultPartitionID resultPartitionId) throws PartitionProducerDisposedException {

	mainThreadExecutor.assertRunningInMainThread();

	final Execution execution = executionGraph.getRegisteredExecutions().get(resultPartitionId.getProducerId());
	if (execution != null) {
		return execution.getState();
	}
	else {
		final IntermediateResult intermediateResult =
			executionGraph.getAllIntermediateResults().get(intermediateResultId);

		if (intermediateResult != null) {
			// Try to find the producing execution
			Execution producerExecution = intermediateResult
				.getPartitionById(resultPartitionId.getPartitionId())
				.getProducer()
				.getCurrentExecutionAttempt();

			if (producerExecution.getAttemptId().equals(resultPartitionId.getProducerId())) {
				return producerExecution.getState();
			} else {
				throw new PartitionProducerDisposedException(resultPartitionId);
			}
		} else {
			throw new IllegalArgumentException("Intermediate data set with ID "
				+ intermediateResultId + " not found.");
		}
	}
}
 
Example 4
Source File: CheckpointCoordinator.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Check if all tasks that we need to trigger are running. If not, abort the checkpoint.
 *
 * @return the executions need to be triggered.
 * @throws CheckpointException the exception fails checking
 */
private Execution[] getTriggerExecutions() throws CheckpointException {
	Execution[] executions = new Execution[tasksToTrigger.length];
	for (int i = 0; i < tasksToTrigger.length; i++) {
		Execution ee = tasksToTrigger[i].getCurrentExecutionAttempt();
		if (ee == null) {
			LOG.info(
				"Checkpoint triggering task {} of job {} is not being executed at the moment. Aborting checkpoint.",
				tasksToTrigger[i].getTaskNameWithSubtaskIndex(),
				job);
			throw new CheckpointException(
				CheckpointFailureReason.NOT_ALL_REQUIRED_TASKS_RUNNING);
		} else if (ee.getState() == ExecutionState.RUNNING) {
			executions[i] = ee;
		} else {
			LOG.info(
				"Checkpoint triggering task {} of job {} is not in state {} but {} instead. Aborting checkpoint.",
				tasksToTrigger[i].getTaskNameWithSubtaskIndex(),
				job,
				ExecutionState.RUNNING,
				ee.getState());
			throw new CheckpointException(
				CheckpointFailureReason.NOT_ALL_REQUIRED_TASKS_RUNNING);
		}
	}
	return executions;
}
 
Example 5
Source File: SchedulerBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public ExecutionState requestPartitionState(
	final IntermediateDataSetID intermediateResultId,
	final ResultPartitionID resultPartitionId) throws PartitionProducerDisposedException {

	mainThreadExecutor.assertRunningInMainThread();

	final Execution execution = executionGraph.getRegisteredExecutions().get(resultPartitionId.getProducerId());
	if (execution != null) {
		return execution.getState();
	}
	else {
		final IntermediateResult intermediateResult =
			executionGraph.getAllIntermediateResults().get(intermediateResultId);

		if (intermediateResult != null) {
			// Try to find the producing execution
			Execution producerExecution = intermediateResult
				.getPartitionById(resultPartitionId.getPartitionId())
				.getProducer()
				.getCurrentExecutionAttempt();

			if (producerExecution.getAttemptId().equals(resultPartitionId.getProducerId())) {
				return producerExecution.getState();
			} else {
				throw new PartitionProducerDisposedException(resultPartitionId);
			}
		} else {
			throw new IllegalArgumentException("Intermediate data set with ID "
				+ intermediateResultId + " not found.");
		}
	}
}
 
Example 6
Source File: SchedulerBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void deliverOperatorEventToCoordinator(
		final ExecutionAttemptID taskExecutionId,
		final OperatorID operatorId,
		final OperatorEvent evt) throws FlinkException {

	// Failure semantics (as per the javadocs of the method):
	// If the task manager sends an event for a non-running task or an non-existing operator
	// coordinator, then respond with an exception to the call. If task and coordinator exist,
	// then we assume that the call from the TaskManager was valid, and any bubbling exception
	// needs to cause a job failure.

	final Execution exec = executionGraph.getRegisteredExecutions().get(taskExecutionId);
	if (exec == null || exec.getState() != ExecutionState.RUNNING) {
		// This situation is common when cancellation happens, or when the task failed while the
		// event was just being dispatched asynchronously on the TM side.
		// It should be fine in those expected situations to just ignore this event, but, to be
		// on the safe, we notify the TM that the event could not be delivered.
		throw new TaskNotRunningException("Task is not known or in state running on the JobManager.");
	}

	final OperatorCoordinatorHolder coordinator = coordinatorMap.get(operatorId);
	if (coordinator == null) {
		throw new FlinkException("No coordinator registered for operator " + operatorId);
	}

	try {
		coordinator.handleEventFromOperator(exec.getParallelSubtaskIndex(), evt);
	} catch (Throwable t) {
		ExceptionUtils.rethrowIfFatalErrorOrOOM(t);
		handleGlobalFailure(t);
	}
}
 
Example 7
Source File: BackPressureRequestCoordinator.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Triggers a task back pressure stats request to all tasks.
 *
 * @param tasks Tasks to request.
 * @return A future of the completed task back pressure stats.
 */
CompletableFuture<BackPressureStats> triggerBackPressureRequest(ExecutionVertex[] tasks) {
	checkNotNull(tasks, "Tasks to request must not be null.");
	checkArgument(tasks.length >= 1, "No tasks to request.");

	// Execution IDs of running tasks
	ExecutionAttemptID[] triggerIds = new ExecutionAttemptID[tasks.length];
	Execution[] executions = new Execution[tasks.length];

	// Check that all tasks are RUNNING before triggering anything. The
	// triggering can still fail.
	for (int i = 0; i < triggerIds.length; i++) {
		Execution execution = tasks[i].getCurrentExecutionAttempt();
		if (execution != null && execution.getState() == ExecutionState.RUNNING) {
			executions[i] = execution;
			triggerIds[i] = execution.getAttemptId();
		} else {
			return FutureUtils.completedExceptionally(new IllegalStateException("Task " + tasks[i]
				.getTaskNameWithSubtaskIndex() + " is not running."));
		}
	}

	synchronized (lock) {
		if (isShutDown) {
			return FutureUtils.completedExceptionally(new IllegalStateException("Shut down."));
		}

		int requestId = requestIdCounter++;

		LOG.debug("Triggering task back pressure request {}.", requestId);

		PendingBackPressureRequest pending = new PendingBackPressureRequest(requestId, triggerIds);

		// Add the pending request before scheduling the discard task to
		// prevent races with removing it again.
		pendingRequests.put(requestId, pending);

		requestBackPressure(executions, requestId);

		return pending.getBackPressureStatsFuture();
	}
}