You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/08/29 04:03:53 UTC

[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #2556: [engine][checkpoint] checkpoint flow

Hisoka-X commented on code in PR #2556:
URL: https://github.com/apache/incubator-seatunnel/pull/2556#discussion_r956874778


##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/checkpoint/CheckpointManager.java:
##########
@@ -28,24 +40,60 @@
  */
 public class CheckpointManager {
 
+    private final Long jobId;
+
+    private final NodeEngine nodeEngine;
+
+    private final Map<Long, Integer> subtaskWithPipelines;
+
+    private final Map<Long, Address> subtaskWithAddresses;
+
     /**
      * key: the pipeline id of the job;
      * <br> value: the checkpoint plan of the pipeline;
      */
-    private final Map<Long, CheckpointPlan> checkpointPlanMap;
+    private final Map<Integer, CheckpointPlan> checkpointPlanMap;
 
     /**
      * key: the pipeline id of the job;
      * <br> value: the checkpoint coordinator of the pipeline;
      */
-    private final Map<Long, CheckpointCoordinator> coordinatorMap;
+    private final Map<Integer, CheckpointCoordinator> coordinatorMap;
+
+    private final CheckpointCoordinatorConfiguration config;
 
-    public CheckpointManager(Map<Long, CheckpointPlan> checkpointPlanMap) {
+    public CheckpointManager(long jobId, NodeEngine nodeEngine, Map<Integer, CheckpointPlan> checkpointPlanMap, CheckpointCoordinatorConfiguration config) {
+        this.jobId = jobId;
+        this.nodeEngine = nodeEngine;
         this.checkpointPlanMap = checkpointPlanMap;
+        this.config = config;
         this.coordinatorMap = new HashMap<>(checkpointPlanMap.size());
+        this.subtaskWithPipelines = checkpointPlanMap.values().stream().flatMap(plan -> plan.getPipelineTaskIds().keySet().stream().map(taskId -> Tuple2.tuple2(taskId, plan.getPipelineId()))).collect(Collectors.toMap(Tuple2::f0, Tuple2::f1));
+        this.subtaskWithAddresses = new HashMap<>(subtaskWithPipelines.size());

Review Comment:
   remove init capcity maybe better



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/NodeEngineUtil.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.seatunnel.engine.server;

Review Comment:
   can put this util to `org.apache.seatunnel.engine.server.utils`?



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/checkpoint/CheckpointCoordinator.java:
##########
@@ -42,11 +54,60 @@ public class CheckpointCoordinator {
 
     private final CheckpointCoordinatorConfiguration config;
 
-    public CheckpointCoordinator(CheckpointPlan plan,
+    public CheckpointCoordinator(CheckpointManager manager,
+                                 long jobId,
+                                 CheckpointPlan plan,
                                  CheckpointCoordinatorConfiguration config) {
+        this.checkpointManager = manager;
+        this.jobId = jobId;
+        this.pipelineId = plan.getPipelineId();
         this.plan = plan;
         this.config = config;
         this.pendingCheckpoints = new LinkedHashMap<>();
         this.completedCheckpoints = new LinkedHashMap<>();
     }
+
+    protected void acknowledgeTask(TaskAcknowledgeOperation ackOperation) {
+        final long checkpointId = ackOperation.getCheckpointId();
+        final PendingCheckpoint pendingCheckpoint = pendingCheckpoints.get(checkpointId);
+        if (pendingCheckpoint == null) {
+            LOG.debug("job: {}, pipeline: {}, the checkpoint({}) don't exist.", jobId, pipelineId, checkpointId);
+            return;
+        }
+        pendingCheckpoint.acknowledgeTask(ackOperation.getTaskInfo(), ackOperation.getStates());
+        if (pendingCheckpoint.isFullyAcknowledged()) {
+            CompletedCheckpoint completedCheckpoint = completePendingCheckpoint(pendingCheckpoint);
+            pendingCheckpoints.remove(checkpointId);
+            completedCheckpoints.put(checkpointId, completedCheckpoint);
+        }
+    }
+
+    public CompletedCheckpoint completePendingCheckpoint(PendingCheckpoint pendingCheckpoint) {
+        notifyCheckpointCompleted(pendingCheckpoint.getCheckpointId());

Review Comment:
   this is a async operation, maybe you should call `InvocationFuture::join` one by one.



-- 
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: commits-unsubscribe@seatunnel.apache.org

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