You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/06/14 02:44:38 UTC

[GitHub] [flink] shuai-xu commented on a change in pull request #8688: [FLINK-12760] [runtime] Implement ExecutionGraph to InputsLocationsRetriever Adapter

shuai-xu commented on a change in pull request #8688: [FLINK-12760] [runtime] Implement ExecutionGraph to InputsLocationsRetriever Adapter
URL: https://github.com/apache/flink/pull/8688#discussion_r293643179
 
 

 ##########
 File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/EGBasedInputsLocationsRetriever.java
 ##########
 @@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.scheduler;
+
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionEdge;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.ExecutionJobVertex;
+import org.apache.flink.runtime.executiongraph.ExecutionVertex;
+import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID;
+import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * An implementation of {@link InputsLocationsRetriever} based on the {@link ExecutionGraph}.
+ */
+public class EGBasedInputsLocationsRetriever implements InputsLocationsRetriever {
+
+	private final ExecutionGraph executionGraph;
+
+	public EGBasedInputsLocationsRetriever(ExecutionGraph executionGraph) {
+		this.executionGraph = checkNotNull(executionGraph);
+	}
+
+	@Override
+	public Collection<Collection<ExecutionVertexID>> getConsumedResultPartitionsProducers(
+			ExecutionVertexID executionVertexId) {
+		ExecutionVertex ev = getExecutionVertex(executionVertexId);
+
+		List<Collection<ExecutionVertexID>> resultPartitionProducers = new ArrayList<>(ev.getNumberOfInputs());
+		for (int i = 0 ; i < ev.getNumberOfInputs(); i++) {
+			ExecutionEdge[] inputEdges = ev.getInputEdges(i);
+			List<ExecutionVertexID> producers = new ArrayList<>(inputEdges.length);
+			for (ExecutionEdge inputEdge : inputEdges) {
+				ExecutionVertex producer = inputEdge.getSource().getProducer();
+				producers.add(new ExecutionVertexID(producer.getJobvertexId(), producer.getParallelSubtaskIndex()));
+			}
+			resultPartitionProducers.add(producers);
+
+		}
+		return resultPartitionProducers;
+	}
+
+	@Override
+	public Optional<CompletableFuture<TaskManagerLocation>> getTaskManagerLocation(ExecutionVertexID executionVertexId) {
+		ExecutionVertex ev = getExecutionVertex(executionVertexId);
+
+		if (ev.getExecutionState() != ExecutionState.CREATED) {
+			return Optional.of(ev.getCurrentTaskManagerLocationFuture());
+		} else {
+			return Optional.empty();
+		}
+	}
+
+	private ExecutionVertex getExecutionVertex(ExecutionVertexID executionVertexId) {
+
+		ExecutionJobVertex ejv = executionGraph.getJobVertex(executionVertexId.getJobVertexId());
+		if (ejv == null || ejv.getParallelism() <= executionVertexId.getSubtaskIndex()) {
+			throw new IllegalArgumentException(String.format("Failed to find execution {} in execution graph.", executionVertexId));
 
 Review comment:
   Done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services