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 2022/06/27 09:15:19 UTC

[GitHub] [flink] zhoulii commented on a diff in pull request #20080: [FLINK-28258] Introduce ExecutionHistory to host historical executions for each execution vertex

zhoulii commented on code in PR #20080:
URL: https://github.com/apache/flink/pull/20080#discussion_r907160500


##########
flink-tests/src/test/java/org/apache/flink/test/runtime/DefaultSchedulerLocalRecoveryITCase.java:
##########
@@ -90,7 +90,9 @@ private void assertNonLocalRecoveredTasksEquals(ArchivedExecutionGraph graph, in
                 continue;
             }
             AllocationID priorAllocation =
-                    vertex.getPriorExecutionAttempt(currentAttemptNumber - 1)
+                    vertex.getExecutionHistory()
+                            .getHistoricalExecution(currentAttemptNumber - 1)
+                            .get()
                             .getAssignedAllocationID();

Review Comment:
   We may need to check whether the result is null.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/ExecutionHistory.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.executiongraph;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * This class hosts the historical executions of an {@link ExecutionVertex} in a {@link
+ * LinkedHashMap} with a size bound. When the map grows beyond the size bound, elements are dropped
+ * from the head of the map (FIFO order). Note that the historical executions does not include the
+ * current execution attempt.
+ */
+public class ExecutionHistory implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private final BoundedLinkedHashMap<Integer, ArchivedExecution> historicalExecutions;
+
+    private int maxAttemptNumber;
+
+    public ExecutionHistory(int sizeLimit) {
+        super();
+        this.historicalExecutions = new BoundedLinkedHashMap(sizeLimit);

Review Comment:
   ```suggestion
           this.historicalExecutions = new BoundedLinkedHashMap<>(sizeLimit);
   ```



##########
flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/ExecutionHistory.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.executiongraph;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * This class hosts the historical executions of an {@link ExecutionVertex} in a {@link
+ * LinkedHashMap} with a size bound. When the map grows beyond the size bound, elements are dropped
+ * from the head of the map (FIFO order). Note that the historical executions does not include the
+ * current execution attempt.
+ */
+public class ExecutionHistory implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private final BoundedLinkedHashMap<Integer, ArchivedExecution> historicalExecutions;
+
+    private int maxAttemptNumber;
+
+    public ExecutionHistory(int sizeLimit) {
+        super();
+        this.historicalExecutions = new BoundedLinkedHashMap(sizeLimit);
+        this.maxAttemptNumber = -1;
+    }
+
+    ExecutionHistory(ExecutionHistory other) {
+        this.historicalExecutions = new BoundedLinkedHashMap<>(other.historicalExecutions);
+        this.maxAttemptNumber = other.maxAttemptNumber;
+    }
+
+    void add(ArchivedExecution execution) {
+        if (execution.getAttemptNumber() > maxAttemptNumber) {
+            maxAttemptNumber = execution.getAttemptNumber();
+        }
+
+        historicalExecutions.put(execution.getAttemptNumber(), execution);
+    }
+
+    public Optional<ArchivedExecution> getHistoricalExecution(int attemptNumber) {
+        if (isValidAttemptNumber(attemptNumber)) {
+            return Optional.ofNullable(historicalExecutions.get(attemptNumber));
+        } else {
+            throw new IllegalArgumentException("Invalid attempt number.");
+        }
+    }
+
+    public Collection<ArchivedExecution> getHistoricalExecutions() {
+        return Collections.unmodifiableCollection(historicalExecutions.values());
+    }
+
+    public boolean isValidAttemptNumber(int attemptNumber) {
+        return attemptNumber >= 0 && attemptNumber <= maxAttemptNumber;
+    }
+
+    private static class BoundedLinkedHashMap<K, V> extends LinkedHashMap<K, V> {
+        private final int sizeLimit;
+
+        private BoundedLinkedHashMap(int sizeLimit) {
+            this.sizeLimit = sizeLimit;
+        }
+
+        private BoundedLinkedHashMap(BoundedLinkedHashMap other) {

Review Comment:
   ```suggestion
           private BoundedLinkedHashMap(BoundedLinkedHashMap<? extends K, ? extends V> other) {
   ```



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