lvyanquan commented on code in PR #4269:
URL: https://github.com/apache/flink-cdc/pull/4269#discussion_r2791645319


##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-iceberg/src/main/java/org/apache/flink/cdc/connectors/iceberg/sink/v2/IcebergCommitter.java:
##########
@@ -117,15 +148,47 @@ private void commit(List<WriteResultWrapper> 
writeResultWrappers) {
                 if (deleteFiles.isEmpty()) {
                     AppendFiles append = table.newAppend();
                     dataFiles.forEach(append::appendFile);
-                    append.commit();
+                    commitOperation(append, newFlinkJobId, operatorId, 
checkpointId);
                 } else {
                     RowDelta delta = table.newRowDelta();
                     dataFiles.forEach(delta::addRows);
                     deleteFiles.forEach(delta::addDeletes);
-                    delta.commit();
+                    commitOperation(delta, newFlinkJobId, operatorId, 
checkpointId);
+                }
+            }
+        }
+    }
+
+    private static long getMaxCommittedCheckpointId(
+            Iterable<Snapshot> ancestors, String flinkJobId, String 
operatorId) {
+        long lastCommittedCheckpointId = INITIAL_CHECKPOINT_ID;
+
+        for (Snapshot ancestor : ancestors) {
+            Map<String, String> summary = ancestor.summary();
+            String snapshotFlinkJobId = summary.get(SinkUtil.FLINK_JOB_ID);
+            String snapshotOperatorId = summary.get(SinkUtil.OPERATOR_ID);
+            if (flinkJobId.equals(snapshotFlinkJobId)
+                    && (snapshotOperatorId == null || 
snapshotOperatorId.equals(operatorId))) {
+                String value = 
summary.get(SinkUtil.MAX_COMMITTED_CHECKPOINT_ID);
+                if (value != null) {
+                    lastCommittedCheckpointId = Long.parseLong(value);
+                    break;
                 }
             }
         }
+
+        return lastCommittedCheckpointId;
+    }
+
+    private static void commitOperation(
+            SnapshotUpdate<?> operation,
+            String newFlinkJobId,
+            String operatorId,
+            long checkpointId) {
+        operation.set(SinkUtil.MAX_COMMITTED_CHECKPOINT_ID, 
Long.toString(checkpointId));
+        operation.set(SinkUtil.FLINK_JOB_ID, newFlinkJobId);
+        operation.set(SinkUtil.OPERATOR_ID, operatorId);
+        operation.commit();

Review Comment:
   PR description was updated.



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