You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "dmvk (via GitHub)" <gi...@apache.org> on 2023/03/02 09:40:12 UTC

[GitHub] [flink] dmvk commented on a diff in pull request #21981: [FLINK-21450][runtime] Support LocalRecovery by AdaptiveScheduler

dmvk commented on code in PR #21981:
URL: https://github.com/apache/flink/pull/21981#discussion_r1122815464


##########
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/AdaptiveScheduler.java:
##########
@@ -784,7 +789,7 @@ public ArchivedExecutionGraph getArchivedExecutionGraph(
     }
 
     @Override
-    public void goToWaitingForResources() {
+    public void goToWaitingForResources(@Nullable ExecutionGraph executionGraph) {

Review Comment:
   nit: `previousExecutionGraph`



##########
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/StateTransitions.java:
##########
@@ -164,6 +166,6 @@ CompletableFuture<String> goToStopWithSavepoint(
     interface ToWaitingForResources extends StateTransitions {
 
         /** Transitions into the {@link WaitingForResources} state. */
-        void goToWaitingForResources();
+        void goToWaitingForResources(@Nullable ExecutionGraph executionGraph);

Review Comment:
   nit: (this appears to affect all implementations)
   
   ```suggestion
           void goToWaitingForResources(@Nullable ExecutionGraph previousExecutionGraph);
   ```



##########
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/allocator/JobAllocationsInformation.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.adaptive.allocator;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+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.jobgraph.JobVertexID;
+import org.apache.flink.runtime.state.KeyGroupRange;
+import org.apache.flink.runtime.state.KeyGroupRangeAssignment;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.emptyMap;
+
+/** Information about allocations of Job Vertices. */
+@Internal
+public class JobAllocationsInformation {
+
+    private final Map<JobVertexID, List<VertexAllocationInformation>> vertexAllocations;
+
+    JobAllocationsInformation(
+            Map<JobVertexID, List<VertexAllocationInformation>> vertexAllocations) {
+        this.vertexAllocations = vertexAllocations;
+    }
+
+    public static JobAllocationsInformation fromGraph(@Nullable ExecutionGraph graph) {
+        return graph == null ? empty() : new JobAllocationsInformation(calculateAllocations(graph));
+    }
+
+    public List<VertexAllocationInformation> getAllocations(JobVertexID jobVertexID) {
+        return vertexAllocations.getOrDefault(jobVertexID, emptyList());
+    }
+
+    private static Map<JobVertexID, List<VertexAllocationInformation>> calculateAllocations(
+            ExecutionGraph graph) {
+        final Map<JobVertexID, List<VertexAllocationInformation>> allocations = new HashMap<>();
+        for (ExecutionJobVertex vertex : graph.getVerticesTopologically()) {
+            JobVertexID jobVertexId = vertex.getJobVertexId();
+            for (ExecutionVertex executionVertex : vertex.getTaskVertices()) {
+                AllocationID allocationId =
+                        executionVertex.getCurrentExecutionAttempt().getAssignedAllocationID();
+                KeyGroupRange kgr =
+                        KeyGroupRangeAssignment.computeKeyGroupRangeForOperatorIndex(
+                                vertex.getMaxParallelism(),
+                                vertex.getParallelism(),
+                                executionVertex.getParallelSubtaskIndex());
+                allocations
+                        .computeIfAbsent(jobVertexId, ignored -> new ArrayList<>())
+                        .add(new VertexAllocationInformation(allocationId, jobVertexId, kgr));
+            }
+        }
+        return allocations;
+    }
+
+    public static JobAllocationsInformation empty() {
+        return new JobAllocationsInformation(emptyMap());
+    }
+
+    public boolean isEmpty() {
+        return vertexAllocations.isEmpty();
+    }
+
+    /** Information about the allocations of a single Job Vertex. */
+    public static class VertexAllocationInformation {
+        public final AllocationID allocationID;
+        public final JobVertexID jobVertexID;
+        public final KeyGroupRange keyGroupRange;

Review Comment:
   Should we have getters here instead? 🙄 
   
   ```suggestion
           public final AllocationID allocationID;
           public final JobVertexID jobVertexID;
           public final KeyGroupRange keyGroupRange;
   ```



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org