Java Code Examples for org.apache.flink.runtime.executiongraph.ExecutionJobVertex#getOperatorIDs()

The following examples show how to use org.apache.flink.runtime.executiongraph.ExecutionJobVertex#getOperatorIDs() . 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: StateAssignmentOperation.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies that all operator states can be mapped to an execution job vertex.
 *
 * @param allowNonRestoredState if false an exception will be thrown if a state could not be mapped
 * @param operatorStates operator states to map
 * @param tasks task to map to
 */
private static void checkStateMappingCompleteness(
		boolean allowNonRestoredState,
		Map<OperatorID, OperatorState> operatorStates,
		Set<ExecutionJobVertex> tasks) {

	Set<OperatorID> allOperatorIDs = new HashSet<>();
	for (ExecutionJobVertex executionJobVertex : tasks) {
		for (OperatorIDPair operatorIDPair : executionJobVertex.getOperatorIDs()) {
			allOperatorIDs.add(operatorIDPair.getGeneratedOperatorID());
			operatorIDPair.getUserDefinedOperatorID().ifPresent(allOperatorIDs::add);
		}
	}
	for (Map.Entry<OperatorID, OperatorState> operatorGroupStateEntry : operatorStates.entrySet()) {
		OperatorState operatorState = operatorGroupStateEntry.getValue();
		//----------------------------------------find operator for state---------------------------------------------

		if (!allOperatorIDs.contains(operatorGroupStateEntry.getKey())) {
			if (allowNonRestoredState) {
				LOG.info("Skipped checkpoint state for operator {}.", operatorState.getOperatorID());
			} else {
				throw new IllegalStateException("There is no operator for the state " + operatorState.getOperatorID());
			}
		}
	}
}
 
Example 2
Source File: StateAssignmentOperation.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void assignTaskStateToExecutionJobVertices(
		ExecutionJobVertex executionJobVertex,
		Map<OperatorInstanceID, List<OperatorStateHandle>> subManagedOperatorState,
		Map<OperatorInstanceID, List<OperatorStateHandle>> subRawOperatorState,
		Map<OperatorInstanceID, List<KeyedStateHandle>> subManagedKeyedState,
		Map<OperatorInstanceID, List<KeyedStateHandle>> subRawKeyedState,
		int newParallelism) {

	List<OperatorID> operatorIDs = executionJobVertex.getOperatorIDs();

	for (int subTaskIndex = 0; subTaskIndex < newParallelism; subTaskIndex++) {

		Execution currentExecutionAttempt = executionJobVertex.getTaskVertices()[subTaskIndex]
			.getCurrentExecutionAttempt();

		TaskStateSnapshot taskState = new TaskStateSnapshot(operatorIDs.size());
		boolean statelessTask = true;

		for (OperatorID operatorID : operatorIDs) {
			OperatorInstanceID instanceID = OperatorInstanceID.of(subTaskIndex, operatorID);

			OperatorSubtaskState operatorSubtaskState = operatorSubtaskStateFrom(
				instanceID,
				subManagedOperatorState,
				subRawOperatorState,
				subManagedKeyedState,
				subRawKeyedState);

			if (operatorSubtaskState.hasState()) {
				statelessTask = false;
			}
			taskState.putSubtaskStateByOperatorID(operatorID, operatorSubtaskState);
		}

		if (!statelessTask) {
			JobManagerTaskRestore taskRestore = new JobManagerTaskRestore(restoreCheckpointId, taskState);
			currentExecutionAttempt.setInitialState(taskRestore);
		}
	}
}
 
Example 3
Source File: StateAssignmentOperation.java    From flink with Apache License 2.0 5 votes vote down vote up
private void assignTaskStateToExecutionJobVertices(
		ExecutionJobVertex executionJobVertex,
		Map<OperatorInstanceID, List<OperatorStateHandle>> subManagedOperatorState,
		Map<OperatorInstanceID, List<OperatorStateHandle>> subRawOperatorState,
		Map<OperatorInstanceID, List<KeyedStateHandle>> subManagedKeyedState,
		Map<OperatorInstanceID, List<KeyedStateHandle>> subRawKeyedState,
		int newParallelism) {

	List<OperatorID> operatorIDs = executionJobVertex.getOperatorIDs();

	for (int subTaskIndex = 0; subTaskIndex < newParallelism; subTaskIndex++) {

		Execution currentExecutionAttempt = executionJobVertex.getTaskVertices()[subTaskIndex]
			.getCurrentExecutionAttempt();

		TaskStateSnapshot taskState = new TaskStateSnapshot(operatorIDs.size());
		boolean statelessTask = true;

		for (OperatorID operatorID : operatorIDs) {
			OperatorInstanceID instanceID = OperatorInstanceID.of(subTaskIndex, operatorID);

			OperatorSubtaskState operatorSubtaskState = operatorSubtaskStateFrom(
				instanceID,
				subManagedOperatorState,
				subRawOperatorState,
				subManagedKeyedState,
				subRawKeyedState);

			if (operatorSubtaskState.hasState()) {
				statelessTask = false;
			}
			taskState.putSubtaskStateByOperatorID(operatorID, operatorSubtaskState);
		}

		if (!statelessTask) {
			JobManagerTaskRestore taskRestore = new JobManagerTaskRestore(restoreCheckpointId, taskState);
			currentExecutionAttempt.setInitialState(taskRestore);
		}
	}
}
 
Example 4
Source File: StateAssignmentOperation.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private void assignAttemptState(ExecutionJobVertex executionJobVertex, List<OperatorState> operatorStates) {

		List<OperatorID> operatorIDs = executionJobVertex.getOperatorIDs();

		//1. first compute the new parallelism
		checkParallelismPreconditions(operatorStates, executionJobVertex);

		int newParallelism = executionJobVertex.getParallelism();

		List<KeyGroupRange> keyGroupPartitions = createKeyGroupPartitions(
			executionJobVertex.getMaxParallelism(),
			newParallelism);

		final int expectedNumberOfSubTasks = newParallelism * operatorIDs.size();

		/*
		 * Redistribute ManagedOperatorStates and RawOperatorStates from old parallelism to new parallelism.
		 *
		 * The old ManagedOperatorStates with old parallelism 3:
		 *
		 * 		parallelism0 parallelism1 parallelism2
		 * op0   states0,0    state0,1	   state0,2
		 * op1
		 * op2   states2,0    state2,1	   state1,2
		 * op3   states3,0    state3,1     state3,2
		 *
		 * The new ManagedOperatorStates with new parallelism 4:
		 *
		 * 		parallelism0 parallelism1 parallelism2 parallelism3
		 * op0   state0,0	  state0,1 	   state0,2		state0,3
		 * op1
		 * op2   state2,0	  state2,1 	   state2,2		state2,3
		 * op3   state3,0	  state3,1 	   state3,2		state3,3
		 */
		Map<OperatorInstanceID, List<OperatorStateHandle>> newManagedOperatorStates =
			new HashMap<>(expectedNumberOfSubTasks);
		Map<OperatorInstanceID, List<OperatorStateHandle>> newRawOperatorStates =
			new HashMap<>(expectedNumberOfSubTasks);

		reDistributePartitionableStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			newManagedOperatorStates,
			newRawOperatorStates);

		Map<OperatorInstanceID, List<KeyedStateHandle>> newManagedKeyedState =
			new HashMap<>(expectedNumberOfSubTasks);
		Map<OperatorInstanceID, List<KeyedStateHandle>> newRawKeyedState =
			new HashMap<>(expectedNumberOfSubTasks);

		reDistributeKeyedStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			keyGroupPartitions,
			newManagedKeyedState,
			newRawKeyedState);

		/*
		 *  An executionJobVertex's all state handles needed to restore are something like a matrix
		 *
		 * 		parallelism0 parallelism1 parallelism2 parallelism3
		 * op0   sh(0,0)     sh(0,1)       sh(0,2)	    sh(0,3)
		 * op1   sh(1,0)	 sh(1,1)	   sh(1,2)	    sh(1,3)
		 * op2   sh(2,0)	 sh(2,1)	   sh(2,2)		sh(2,3)
		 * op3   sh(3,0)	 sh(3,1)	   sh(3,2)		sh(3,3)
		 *
		 */
		assignTaskStateToExecutionJobVertices(
			executionJobVertex,
			newManagedOperatorStates,
			newRawOperatorStates,
			newManagedKeyedState,
			newRawKeyedState,
			newParallelism);
	}
 
Example 5
Source File: StateAssignmentOperation.java    From flink with Apache License 2.0 4 votes vote down vote up
private void assignAttemptState(ExecutionJobVertex executionJobVertex, List<OperatorState> operatorStates) {

		List<OperatorID> operatorIDs = executionJobVertex.getOperatorIDs();

		//1. first compute the new parallelism
		checkParallelismPreconditions(operatorStates, executionJobVertex);

		int newParallelism = executionJobVertex.getParallelism();

		List<KeyGroupRange> keyGroupPartitions = createKeyGroupPartitions(
			executionJobVertex.getMaxParallelism(),
			newParallelism);

		final int expectedNumberOfSubTasks = newParallelism * operatorIDs.size();

		/*
		 * Redistribute ManagedOperatorStates and RawOperatorStates from old parallelism to new parallelism.
		 *
		 * The old ManagedOperatorStates with old parallelism 3:
		 *
		 * 		parallelism0 parallelism1 parallelism2
		 * op0   states0,0    state0,1	   state0,2
		 * op1
		 * op2   states2,0    state2,1	   state1,2
		 * op3   states3,0    state3,1     state3,2
		 *
		 * The new ManagedOperatorStates with new parallelism 4:
		 *
		 * 		parallelism0 parallelism1 parallelism2 parallelism3
		 * op0   state0,0	  state0,1 	   state0,2		state0,3
		 * op1
		 * op2   state2,0	  state2,1 	   state2,2		state2,3
		 * op3   state3,0	  state3,1 	   state3,2		state3,3
		 */
		Map<OperatorInstanceID, List<OperatorStateHandle>> newManagedOperatorStates =
			new HashMap<>(expectedNumberOfSubTasks);
		Map<OperatorInstanceID, List<OperatorStateHandle>> newRawOperatorStates =
			new HashMap<>(expectedNumberOfSubTasks);

		reDistributePartitionableStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			newManagedOperatorStates,
			newRawOperatorStates);

		Map<OperatorInstanceID, List<KeyedStateHandle>> newManagedKeyedState =
			new HashMap<>(expectedNumberOfSubTasks);
		Map<OperatorInstanceID, List<KeyedStateHandle>> newRawKeyedState =
			new HashMap<>(expectedNumberOfSubTasks);

		reDistributeKeyedStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			keyGroupPartitions,
			newManagedKeyedState,
			newRawKeyedState);

		/*
		 *  An executionJobVertex's all state handles needed to restore are something like a matrix
		 *
		 * 		parallelism0 parallelism1 parallelism2 parallelism3
		 * op0   sh(0,0)     sh(0,1)       sh(0,2)	    sh(0,3)
		 * op1   sh(1,0)	 sh(1,1)	   sh(1,2)	    sh(1,3)
		 * op2   sh(2,0)	 sh(2,1)	   sh(2,2)		sh(2,3)
		 * op3   sh(3,0)	 sh(3,1)	   sh(3,2)		sh(3,3)
		 *
		 */
		assignTaskStateToExecutionJobVertices(
			executionJobVertex,
			newManagedOperatorStates,
			newRawOperatorStates,
			newManagedKeyedState,
			newRawKeyedState,
			newParallelism);
	}
 
Example 6
Source File: Checkpoints.java    From flink with Apache License 2.0 4 votes vote down vote up
public static CompletedCheckpoint loadAndValidateCheckpoint(
		JobID jobId,
		Map<JobVertexID, ExecutionJobVertex> tasks,
		CompletedCheckpointStorageLocation location,
		ClassLoader classLoader,
		boolean allowNonRestoredState) throws IOException {

	checkNotNull(jobId, "jobId");
	checkNotNull(tasks, "tasks");
	checkNotNull(location, "location");
	checkNotNull(classLoader, "classLoader");

	final StreamStateHandle metadataHandle = location.getMetadataHandle();
	final String checkpointPointer = location.getExternalPointer();

	// (1) load the savepoint
	final CheckpointMetadata checkpointMetadata;
	try (InputStream in = metadataHandle.openInputStream()) {
		DataInputStream dis = new DataInputStream(in);
		checkpointMetadata = loadCheckpointMetadata(dis, classLoader, checkpointPointer);
	}

	// generate mapping from operator to task
	Map<OperatorID, ExecutionJobVertex> operatorToJobVertexMapping = new HashMap<>();
	for (ExecutionJobVertex task : tasks.values()) {
		for (OperatorIDPair operatorIDPair : task.getOperatorIDs()) {
			operatorToJobVertexMapping.put(operatorIDPair.getGeneratedOperatorID(), task);
			operatorIDPair.getUserDefinedOperatorID().ifPresent(id -> operatorToJobVertexMapping.put(id, task));
		}
	}

	// (2) validate it (parallelism, etc)
	HashMap<OperatorID, OperatorState> operatorStates = new HashMap<>(checkpointMetadata.getOperatorStates().size());
	for (OperatorState operatorState : checkpointMetadata.getOperatorStates()) {

		ExecutionJobVertex executionJobVertex = operatorToJobVertexMapping.get(operatorState.getOperatorID());

		if (executionJobVertex != null) {

			if (executionJobVertex.getMaxParallelism() == operatorState.getMaxParallelism()
					|| !executionJobVertex.isMaxParallelismConfigured()) {
				operatorStates.put(operatorState.getOperatorID(), operatorState);
			} else {
				String msg = String.format("Failed to rollback to checkpoint/savepoint %s. " +
								"Max parallelism mismatch between checkpoint/savepoint state and new program. " +
								"Cannot map operator %s with max parallelism %d to new program with " +
								"max parallelism %d. This indicates that the program has been changed " +
								"in a non-compatible way after the checkpoint/savepoint.",
						checkpointMetadata,
						operatorState.getOperatorID(),
						operatorState.getMaxParallelism(),
						executionJobVertex.getMaxParallelism());

				throw new IllegalStateException(msg);
			}
		} else if (allowNonRestoredState) {
			LOG.info("Skipping savepoint state for operator {}.", operatorState.getOperatorID());
		} else {
			if (operatorState.getCoordinatorState() != null) {
				throwNonRestoredStateException(checkpointPointer, operatorState.getOperatorID());
			}

			for (OperatorSubtaskState operatorSubtaskState : operatorState.getStates()) {
				if (operatorSubtaskState.hasState()) {
					throwNonRestoredStateException(checkpointPointer, operatorState.getOperatorID());
				}
			}

			LOG.info("Skipping empty savepoint state for operator {}.", operatorState.getOperatorID());
		}
	}

	// (3) convert to checkpoint so the system can fall back to it
	CheckpointProperties props = CheckpointProperties.forSavepoint(false);

	return new CompletedCheckpoint(
			jobId,
			checkpointMetadata.getCheckpointId(),
			0L,
			0L,
			operatorStates,
			checkpointMetadata.getMasterStates(),
			props,
			location);
}
 
Example 7
Source File: StateAssignmentOperation.java    From flink with Apache License 2.0 4 votes vote down vote up
private void assignAttemptState(ExecutionJobVertex executionJobVertex, List<OperatorState> operatorStates) {

		List<OperatorIDPair> operatorIDs = executionJobVertex.getOperatorIDs();

		//1. first compute the new parallelism
		checkParallelismPreconditions(operatorStates, executionJobVertex);

		int newParallelism = executionJobVertex.getParallelism();

		List<KeyGroupRange> keyGroupPartitions = createKeyGroupPartitions(
			executionJobVertex.getMaxParallelism(),
			newParallelism);

		final int expectedNumberOfSubTasks = newParallelism * operatorIDs.size();

		/*
		 * Redistribute ManagedOperatorStates and RawOperatorStates from old parallelism to new parallelism.
		 *
		 * The old ManagedOperatorStates with old parallelism 3:
		 *
		 * 		parallelism0 parallelism1 parallelism2
		 * op0   states0,0    state0,1	   state0,2
		 * op1
		 * op2   states2,0    state2,1	   state1,2
		 * op3   states3,0    state3,1     state3,2
		 *
		 * The new ManagedOperatorStates with new parallelism 4:
		 *
		 * 		parallelism0 parallelism1 parallelism2 parallelism3
		 * op0   state0,0	  state0,1 	   state0,2		state0,3
		 * op1
		 * op2   state2,0	  state2,1 	   state2,2		state2,3
		 * op3   state3,0	  state3,1 	   state3,2		state3,3
		 */
		Map<OperatorInstanceID, List<OperatorStateHandle>> newManagedOperatorStates = reDistributePartitionableStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			OperatorSubtaskState::getManagedOperatorState,
			RoundRobinOperatorStateRepartitioner.INSTANCE);
		Map<OperatorInstanceID, List<OperatorStateHandle>> newRawOperatorStates = reDistributePartitionableStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			OperatorSubtaskState::getRawOperatorState,
			RoundRobinOperatorStateRepartitioner.INSTANCE);
		final Map<OperatorInstanceID, List<InputChannelStateHandle>> newInputChannelState = reDistributePartitionableStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			OperatorSubtaskState::getInputChannelState,
			channelStateNonRescalingRepartitioner("input channel"));
		final Map<OperatorInstanceID, List<ResultSubpartitionStateHandle>> newResultSubpartitionState = reDistributePartitionableStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			OperatorSubtaskState::getResultSubpartitionState,
			channelStateNonRescalingRepartitioner("result subpartition"));

		Map<OperatorInstanceID, List<KeyedStateHandle>> newManagedKeyedState = new HashMap<>(expectedNumberOfSubTasks);
		Map<OperatorInstanceID, List<KeyedStateHandle>> newRawKeyedState = new HashMap<>(expectedNumberOfSubTasks);

		reDistributeKeyedStates(
			operatorStates,
			newParallelism,
			operatorIDs,
			keyGroupPartitions,
			newManagedKeyedState,
			newRawKeyedState);

		/*
		 *  An executionJobVertex's all state handles needed to restore are something like a matrix
		 *
		 * 		parallelism0 parallelism1 parallelism2 parallelism3
		 * op0   sh(0,0)     sh(0,1)       sh(0,2)	    sh(0,3)
		 * op1   sh(1,0)	 sh(1,1)	   sh(1,2)	    sh(1,3)
		 * op2   sh(2,0)	 sh(2,1)	   sh(2,2)		sh(2,3)
		 * op3   sh(3,0)	 sh(3,1)	   sh(3,2)		sh(3,3)
		 *
		 */
		assignTaskStateToExecutionJobVertices(
			executionJobVertex,
			newManagedOperatorStates,
			newRawOperatorStates,
			newInputChannelState,
			newResultSubpartitionState,
			newManagedKeyedState,
			newRawKeyedState,
			newParallelism);
	}
 
Example 8
Source File: StateAssignmentOperation.java    From flink with Apache License 2.0 4 votes vote down vote up
private void assignTaskStateToExecutionJobVertices(
		ExecutionJobVertex executionJobVertex,
		Map<OperatorInstanceID, List<OperatorStateHandle>> subManagedOperatorState,
		Map<OperatorInstanceID, List<OperatorStateHandle>> subRawOperatorState,
		Map<OperatorInstanceID, List<InputChannelStateHandle>> inputChannelStates,
		Map<OperatorInstanceID, List<ResultSubpartitionStateHandle>> resultSubpartitionStates,
		Map<OperatorInstanceID, List<KeyedStateHandle>> subManagedKeyedState,
		Map<OperatorInstanceID, List<KeyedStateHandle>> subRawKeyedState,
		int newParallelism) {

	List<OperatorIDPair> operatorIDs = executionJobVertex.getOperatorIDs();

	for (int subTaskIndex = 0; subTaskIndex < newParallelism; subTaskIndex++) {

		Execution currentExecutionAttempt = executionJobVertex.getTaskVertices()[subTaskIndex]
			.getCurrentExecutionAttempt();

		TaskStateSnapshot taskState = new TaskStateSnapshot(operatorIDs.size());
		boolean statelessTask = true;

		for (OperatorIDPair operatorID : operatorIDs) {
			OperatorInstanceID instanceID = OperatorInstanceID.of(subTaskIndex, operatorID.getGeneratedOperatorID());

			OperatorSubtaskState operatorSubtaskState = operatorSubtaskStateFrom(
				instanceID,
				subManagedOperatorState,
				subRawOperatorState,
				inputChannelStates,
				resultSubpartitionStates,
				subManagedKeyedState,
				subRawKeyedState);

			if (operatorSubtaskState.hasState()) {
				statelessTask = false;
			}
			taskState.putSubtaskStateByOperatorID(operatorID.getGeneratedOperatorID(), operatorSubtaskState);
		}

		if (!statelessTask) {
			JobManagerTaskRestore taskRestore = new JobManagerTaskRestore(restoreCheckpointId, taskState);
			currentExecutionAttempt.setInitialState(taskRestore);
		}
	}
}