gaoyunhaii commented on a change in pull request #14734:
URL: https://github.com/apache/flink/pull/14734#discussion_r570164405



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/CheckpointBrief.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.runtime.executiongraph.Execution;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.ExecutionVertex;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * The brief of one checkpoint, indicating which tasks to trigger, waiting for 
acknowledge or commit
+ * for one specific checkpoint.
+ */
+public class CheckpointBrief {

Review comment:
       I think I would prefer more to `CheckpointPlan` since it is more easy to 
understand and do not have overlaps. I changed it to `CheckpointPlan`.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/CheckpointBriefCalculator.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.api.common.JobID;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.Execution;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.ExecutionVertex;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** Computes the tasks to trigger, wait or commit for each checkpoint. */
+public class CheckpointBriefCalculator {
+    private static final Logger LOG = 
LoggerFactory.getLogger(CheckpointBriefCalculator.class);
+
+    private final JobID jobId;
+
+    private final List<ExecutionVertex> tasksToTrigger;
+
+    private final List<ExecutionVertex> tasksToWait;
+
+    private final List<ExecutionVertex> tasksToCommitTo;
+
+    public CheckpointBriefCalculator(
+            JobID jobId,
+            List<ExecutionVertex> tasksToTrigger,
+            List<ExecutionVertex> tasksToWait,
+            List<ExecutionVertex> tasksToCommitTo) {
+
+        this.jobId = jobId;
+        this.tasksToTrigger = Collections.unmodifiableList(tasksToTrigger);
+        this.tasksToWait = Collections.unmodifiableList(tasksToWait);
+        this.tasksToCommitTo = Collections.unmodifiableList(tasksToCommitTo);
+    }
+
+    public CheckpointBrief calculateCheckpointBrief() throws 
CheckpointException {
+        List<Execution> tasksToTrigger = getTriggerExecutions();
+        Map<ExecutionAttemptID, ExecutionVertex> tasksToWait = getAckTasks();
+
+        return new CheckpointBrief(
+                Collections.unmodifiableList(tasksToTrigger), tasksToWait, 
tasksToCommitTo);

Review comment:
       I also agree with that make it unmodifiable would be more clean and more 
error-prone. Thus I made it unmodifiable and copy in `PendingCheckpoint`. 
   
   I also make the variables inline.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/PendingCheckpoint.java
##########
@@ -142,6 +145,7 @@ public PendingCheckpoint(
         this.checkpointId = checkpointId;
         this.checkpointTimestamp = checkpointTimestamp;
         this.notYetAcknowledgedTasks = checkNotNull(verticesToConfirm);
+        this.tasksToCommitTo = checkNotNull(tasksToCommitTo);

Review comment:
       I also more tend to store `CheckpointPlan` to `PendingCheckpoint`. We 
also do it in the second PR since there would be multiple collections to pass. 
I then change it in this PR and store `CheckpointPlan` in `PendingCheckpoint`. 

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/CheckpointCoordinator.java
##########
@@ -350,13 +340,15 @@ public CheckpointCoordinator(
                         this.minPauseBetweenCheckpoints,
                         this.pendingCheckpoints::size,
                         
this.checkpointsCleaner::getNumberOfCheckpointsToClean);
+
         this.cachedTasksById =
-                new LinkedHashMap<ExecutionAttemptID, 
ExecutionVertex>(tasksToWaitFor.length) {
+                new LinkedHashMap<ExecutionAttemptID, ExecutionVertex>(
+                        attemptMappingProvider.getNumberOfTasks()) {
 
                     @Override
                     protected boolean removeEldestEntry(
                             Map.Entry<ExecutionAttemptID, ExecutionVertex> 
eldest) {
-                        return size() > 
CheckpointCoordinator.this.tasksToWaitFor.length;
+                        return size() > 
attemptMappingProvider.getNumberOfTasks();

Review comment:
       I think it would be much more clear to move cache to 
`ExecutionAttemptMappingProvider`.  I then moved it to 
`ExecutionAttemptMappingProvider`.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/ExecutionGraph.java
##########
@@ -464,7 +459,13 @@ public void failJobDueToTaskFailure(
                         checkpointsCleaner,
                         new 
ScheduledExecutorServiceAdapter(checkpointCoordinatorTimer),
                         SharedStateRegistry.DEFAULT_FACTORY,
-                        failureManager);
+                        failureManager,
+                        new CheckpointBriefCalculator(
+                                getJobID(),
+                                sourceAndAllVertices.f0,
+                                sourceAndAllVertices.f1,
+                                sourceAndAllVertices.f1),
+                        new 
ExecutionAttemptMappingProvider(sourceAndAllVertices.f1));

Review comment:
       I also more like to move the creation to be inside 
`CheckpointPlanCalculator`. However, since currently the unit tests relies on 
passing mock vertices directly on creating `CheckpointCoordinator`, thus I 
think we may postpone the change to the next PR, in the second PR we would 
refactor the current tests to be based on real `ExecutionGraph` and then we 
could move the creation into inside `CheckpointPlanCalculator`.
   
   I'm a little concern for make `ExecutionAttemptMappingProvider` to be depend 
on `CheckpointPlanCalculator` since logically I think the two components should 
be for two separate purposes. Besides, we would also adjust the logic of the 
`CheckpointPlanCalculator` in the next PR. Do you think it would be also ok to 
separate the two components and make them all depends on ExecutionGraph~?




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to