StephanEwen commented on a change in pull request #16655:
URL: https://github.com/apache/flink/pull/16655#discussion_r684775022



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/PendingCheckpoint.java
##########
@@ -500,6 +501,32 @@ private void fulfillFullyFinishedOperatorStates() {
         }
     }
 
+    private void fulfillSubtaskStateForPartiallyFinishedOperators() {
+        for (Execution finishedTask : checkpointPlan.getFinishedTasks()) {
+            ExecutionJobVertex jobVertex = 
finishedTask.getVertex().getJobVertex();
+            for (OperatorIDPair operatorIDPair : jobVertex.getOperatorIDs()) {
+                OperatorState operatorState =
+                        
operatorStates.get(operatorIDPair.getGeneratedOperatorID());

Review comment:
       I think we may have an issue here that we only work with the generated 
Operator ID, not also with the user-defined ID, same as above.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/metadata/MetadataV3Serializer.java
##########
@@ -114,8 +115,14 @@ protected void serializeOperatorState(OperatorState 
operatorState, DataOutputStr
                     operatorState.getSubtaskStates();
             dos.writeInt(subtaskStateMap.size());
             for (Map.Entry<Integer, OperatorSubtaskState> entry : 
subtaskStateMap.entrySet()) {
-                dos.writeInt(entry.getKey());
-                serializeSubtaskState(entry.getValue(), dos);
+                if (entry.getValue().isFinished()) {
+                    // We store a negative index for the finished subtask. In 
consideration
+                    // of the index 0, the negative index would start from -1.
+                    dos.writeInt(-(entry.getKey() + 1));

Review comment:
       With approach (2) I would actually be fine here.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/PendingCheckpoint.java
##########
@@ -347,6 +347,7 @@ public CompletedCheckpoint finalizeCheckpoint(
                 }
 
                 fulfillFullyFinishedOperatorStates();

Review comment:
       Inside this method, we map only the generated Operator IDs to the 
finished state.
   I think that means that when users explicitly define UIDs by naming their 
operations (which is recommended), then this doesn't work.
   
   On way is to map this finished state instance from both operator ids 
(generated and user-defined), but I am not a big fan of this solution :-/
   
   Side note: I think we need to clean this up at some point - the fact that 
both UIDs enter the runtime is wrong, that should be solved on the API level 
and the runtime only works with the resolved UID.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/OperatorSubtaskState.java
##########
@@ -59,6 +60,8 @@
 
     private static final Logger LOG = 
LoggerFactory.getLogger(OperatorSubtaskState.class);
 
+    public static final OperatorSubtaskState FINISHED = new 
OperatorSubtaskState(true);
+
     private static final long serialVersionUID = -2394696997971923995L;

Review comment:
       We usually change / bump the Serial Version UID when we change the 
class. Unless, we explicitly want serialization backwards compatibility. Is 
that the case here?

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/VertexFinishedStateChecker.java
##########
@@ -0,0 +1,217 @@
+/*
+ * 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.checkpoint;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.runtime.OperatorIDPair;
+import org.apache.flink.runtime.executiongraph.ExecutionJobVertex;
+import org.apache.flink.runtime.executiongraph.IntermediateResult;
+import org.apache.flink.runtime.jobgraph.DistributionPattern;
+import org.apache.flink.runtime.jobgraph.JobEdge;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import org.apache.flink.runtime.jobgraph.OperatorID;
+import org.apache.flink.util.FlinkRuntimeException;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This class encapsulates the operation that checks if there are illegal 
modification to the
+ * JobGraph when restoring from a checkpoint with partially or fully finished 
operator states.
+ *
+ * <p>As a whole, it ensures
+ *
+ * <ol>
+ *   <li>All the operators inside a JobVertex have the same finished state.
+ *   <li>The predecessors of a fully finished vertex must also be fully 
finished.
+ *   <li>The predecessors of a partially finished vertex
+ *       <ul>
+ *         <li>If connected via ALL_TO_ALL edge, the predecessor must be fully 
finished.
+ *         <li>If connected via POINTWISE edge, the predecessor must be 
partially finished or fully
+ *             finished.
+ *       </ul>
+ * </ol>
+ */
+public class VertexFinishedStateChecker {
+
+    private final Set<ExecutionJobVertex> vertices;
+
+    private final Map<OperatorID, OperatorState> operatorStates;
+
+    public VertexFinishedStateChecker(
+            Set<ExecutionJobVertex> vertices, Map<OperatorID, OperatorState> 
operatorStates) {
+        this.vertices = vertices;
+        this.operatorStates = operatorStates;
+    }
+
+    public void validateOperatorsFinishedState() {

Review comment:
       As mentioned in the high-level comment, let's think if we want to 
simplify this logic.
   Being able to explain to users what to expect is important. Also, simper 
logic has a lower chance of overlooking corner cases, of which there are some 
here, I suspect.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/metadata/MetadataV3Serializer.java
##########
@@ -114,8 +115,14 @@ protected void serializeOperatorState(OperatorState 
operatorState, DataOutputStr
                     operatorState.getSubtaskStates();
             dos.writeInt(subtaskStateMap.size());
             for (Map.Entry<Integer, OperatorSubtaskState> entry : 
subtaskStateMap.entrySet()) {
-                dos.writeInt(entry.getKey());
-                serializeSubtaskState(entry.getValue(), dos);
+                if (entry.getValue().isFinished()) {
+                    // We store a negative index for the finished subtask. In 
consideration
+                    // of the index 0, the negative index would start from -1.
+                    dos.writeInt(-(entry.getKey() + 1));

Review comment:
       From my side, we can do one of the following things:
   
     1. Bump the metadata format version. This is relatively simple.
     
       The tests are the most work here. We need to create Snapshots of V3 
metadata that we reload with the latest setup to ensure backwards compatibility.
   
     2. We can use the trick here, but then we should nit do this inline, but 
have two explicit static methods that we use, so that this is explicit:
       - `int encodeSubtaskIndex(int subtaskIndex, boolean isFinished)`
       - `SubtaskAndStatus decodeSubtaskAndStatus(int value)` (where 
`SubtaskAndStatus` is like an (int, boolean) tuple.) 

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/PendingCheckpoint.java
##########
@@ -347,6 +347,7 @@ public CompletedCheckpoint finalizeCheckpoint(
                 }
 
                 fulfillFullyFinishedOperatorStates();
+                fulfillSubtaskStateForPartiallyFinishedOperators();

Review comment:
       I think the fact that we need to deal with this in the 
`PendingCheckpoint` class shows some abstraction problem. See the top-level 
review comment for details.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to