Copilot commented on code in PR #4269:
URL: https://github.com/apache/flink-cdc/pull/4269#discussion_r2786171694
##########
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:
##########
@@ -56,6 +57,8 @@ public class IcebergCommitter implements
Committer<WriteResultWrapper> {
public static final String TABLE_GROUP_KEY = "table";
+ public static final String CHECKPOINT_SUMMARY_NAME =
"flink-cdc-checkpoint-id";
+
Review Comment:
The idempotency check uses only the Flink checkpointId stored under
`flink-cdc-checkpoint-id`. Checkpoint IDs restart from the initial value when a
job is started without restoring state (or when running a different job against
the same table), so this can incorrectly skip legitimate new commits and cause
data loss. Consider also persisting a job-scoped identifier (e.g., Flink JobID
or a generated sink run UUID persisted in writer state) in the snapshot summary
and require both to match before skipping.
##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-iceberg/src/test/java/org/apache/flink/cdc/connectors/iceberg/sink/v2/IcebergWriterStateTest.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.cdc.connectors.iceberg.sink.v2;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/** A test for {@link IcebergWriterStateTest}. */
Review Comment:
The class-level Javadoc links to `IcebergWriterStateTest` (itself) rather
than the class under test. This should reference `IcebergWriterState` (and/or
`IcebergWriterStateSerializer`) to avoid misleading documentation.
```suggestion
/** Tests for {@link IcebergWriterState} and {@link
IcebergWriterStateSerializer}. */
```
##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-iceberg/src/main/java/org/apache/flink/cdc/connectors/iceberg/sink/v2/IcebergSink.java:
##########
@@ -92,20 +97,48 @@ public SimpleVersionedSerializer<WriteResultWrapper>
getCommittableSerializer()
@Override
public SinkWriter<Event> createWriter(InitContext context) {
+ long lastCheckpointId =
+ context.getRestoredCheckpointId()
+ .orElse(CheckpointIDCounter.INITIAL_CHECKPOINT_ID - 1);
return new IcebergWriter(
catalogOptions,
context.getTaskInfo().getIndexOfThisSubtask(),
context.getTaskInfo().getAttemptNumber(),
- zoneId);
+ zoneId,
+ lastCheckpointId);
}
@Override
public SinkWriter<Event> createWriter(WriterInitContext context) {
+ long lastCheckpointId =
+ context.getRestoredCheckpointId()
+ .orElse(CheckpointIDCounter.INITIAL_CHECKPOINT_ID - 1);
return new IcebergWriter(
catalogOptions,
context.getTaskInfo().getIndexOfThisSubtask(),
context.getTaskInfo().getAttemptNumber(),
- zoneId);
+ zoneId,
+ lastCheckpointId);
+ }
+
+ @Override
+ public StatefulSinkWriter<Event, IcebergWriterState> restoreWriter(
+ WriterInitContext context, Collection<IcebergWriterState>
writerStates) {
+ // No need to read checkpointId from state
+ long lastCheckpointId =
+ context.getRestoredCheckpointId()
+ .orElse(CheckpointIDCounter.INITIAL_CHECKPOINT_ID - 1);
+ return new IcebergWriter(
+ catalogOptions,
+ context.getTaskInfo().getIndexOfThisSubtask(),
+ context.getTaskInfo().getAttemptNumber(),
+ zoneId,
+ lastCheckpointId);
+ }
Review Comment:
`restoreWriter(...)` ignores the provided `writerStates`, and
`IcebergWriter.snapshotState(...)` currently only stores the checkpoint id but
that state is never used to restore the writer. This adds checkpointed writer
state overhead without affecting behavior; either remove
`SupportsWriterState/StatefulSinkWriter` entirely and rely on
`getRestoredCheckpointId()`, or actually derive `lastCheckpointId` (and any
future writer identity) from the restored `writerStates` for correctness and
clarity.
--
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]