You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "dev-donghwan (via GitHub)" <gi...@apache.org> on 2026/07/24 07:52:11 UTC

[PR] [FLINK-40216][cdc-base] Preserve assignment order of splits across restore to keep meta groups consistent [flink-cdc]

dev-donghwan opened a new pull request, #4489:
URL: https://github.com/apache/flink-cdc/pull/4489

   Jira: https://issues.apache.org/jira/browse/FLINK-40216
   
   ### Problem
   
   On restore, `SnapshotSplitAssigner` re-sorts `assignedSplits` lexicographically by split id (`t:0, t:1, t:10, t:11, t:2, ...`), while during a normal run the map holds them in assignment order (`t:0, t:1, t:2, ...`). Since `IncrementalSourceEnumerator` partitions `getFinishedSplitInfos()` into meta groups positionally (`Lists.partition`), the same group id maps to different splits before and after a restore.
   
   A reader that had synchronized only part of the meta groups before the restart resumes requesting from its next group id against the re-partitioned list: some `FinishedSnapshotSplitInfo` are received twice, others never. `StreamSplit#isCompletedSplit` only compares sizes, so the corrupted split is considered complete, and `IncrementalSourceStreamFetcher#shouldEmit` silently drops change events in the key ranges of the missing chunks — permanent data loss. Depending on timing it can instead surface as the `"invalid request meta group id"` error.
   
   The MySQL connector had the identical defect and fixed it in FLINK-38218; as noted there, other connectors using `SnapshotSplitAssigner` from `flink-cdc-base` are prone to the same issue. This PR ports that fix to `flink-cdc-base`, covering all connectors on the base incremental framework (Postgres, MongoDB, Oracle, SqlServer, Db2).
   
   ### Changes
   
   * `PendingSplitsStateSerializer` / `SnapshotPendingSplitsState`: deserialize `assignedSplits` (and related maps) into a `LinkedHashMap` — the serialized form already preserves iteration order — and declare the order contract on the fields.
   * `SnapshotSplitAssigner`: remove the lexicographic re-sort in the restore constructor.
   * `HybridSplitAssigner#createStreamSplit`: remove the lexicographic sort; build `finishedSnapshotSplitInfos` in assignment order.
   * `IncrementalSourceReader`: replace the order-dependent last-group deduplication (`getExistedSplitsOfLastGroup`) with the order-agnostic prefix-discard approach from FLINK-38218.
   * `StreamSplit`: guard against duplicated split infos (`ensureNoDuplicates`), mirroring `MySqlBinlogSplit`.
   
   ### Tests
   
   * `MetaGroupOrderingTest` (new): restores an assigner from a checkpoint taken mid meta-group synchronization and asserts (a) `getFinishedSplitInfos()` preserves assignment order after restore, and (b) a resuming reader receives every split exactly once. On current master both fail deterministically (with 12 chunks and `chunk-meta.group.size=2`, the reader ends up with `t:4`/`t:5` duplicated and `t:10`/`t:11` never delivered); with this fix both pass. This is the base-side counterpart of `MySqlSnapshotSplitAssignerTest#testFinishedSnapshotSplitInfosAreInOrderOfAssignment`.
   * `PendingSplitsStateSerializerTest`: serde round-trip preserves assignment order.
   * `StreamSplitTest`: duplicate split infos are rejected.
   
   ### Note
   
   This is independent of the metadata-transmission protocol redesign discussed in FLINK-38270. Unifying the MySQL connector's own copy of this logic with `flink-cdc-base` is possible follow-up work, out of scope here.
   


-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40216][cdc-base] Preserve assignment order of splits across restore to keep meta groups consistent [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang commented on code in PR #4489:
URL: https://github.com/apache/flink-cdc/pull/4489#discussion_r4347985597


##########
flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/main/java/org/apache/flink/cdc/connectors/base/source/assigner/state/SnapshotPendingSplitsState.java:
##########
@@ -154,7 +154,7 @@ public List<SchemalessSnapshotSplit> getRemainingSplits() {
         return remainingSplits;
     }
 
-    public Map<String, SchemalessSnapshotSplit> getAssignedSplits() {
+    public LinkedHashMap<String, SchemalessSnapshotSplit> getAssignedSplits() {

Review Comment:
   Overall, the approach looks sound: preserving assignment order across restore keeps meta-group IDs stable, and the reader-side prefix handling follows that invariant.
   
   One compatibility detail: changing the public `SnapshotPendingSplitsState#getAssignedSplits()` return type from `Map` to `LinkedHashMap` changes its JVM method descriptor (`()Ljava/util/Map;` to `()Ljava/util/LinkedHashMap;`). An out-of-tree connector compiled against the previous `flink-cdc-base` could therefore hit `NoSuchMethodError` after upgrading. The 11-argument public constructor also narrows its `assignedSplits` parameter from `Map` to `LinkedHashMap`, breaking existing source and binary callers.
   
   Could we keep those public signatures as `Map` and preserve the required iteration order internally with a `LinkedHashMap` copy? A small compatibility test using a caller compiled against the old signatures would help cover this upgrade path.



-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40216][cdc-base] Preserve assignment order of splits across restore to keep meta groups consistent [flink-cdc]

Posted by "dev-donghwan (via GitHub)" <gi...@apache.org>.
dev-donghwan commented on code in PR #4489:
URL: https://github.com/apache/flink-cdc/pull/4489#discussion_r4349248157


##########
flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/main/java/org/apache/flink/cdc/connectors/base/source/assigner/state/SnapshotPendingSplitsState.java:
##########
@@ -154,7 +154,7 @@ public List<SchemalessSnapshotSplit> getRemainingSplits() {
         return remainingSplits;
     }
 
-    public Map<String, SchemalessSnapshotSplit> getAssignedSplits() {
+    public LinkedHashMap<String, SchemalessSnapshotSplit> getAssignedSplits() {

Review Comment:
   Thanks for catching this, @leonardBang. That was my mistake: I narrowed the public signatures to the concrete type where the `Map` interface should have stayed.
   
   Addressed in 423b4d4:
   - `SnapshotPendingSplitsState` is now identical to master. The constructor parameter and `getAssignedSplits()` are back to `Map`, and the existing constructor already copies into a `LinkedHashMap`, so the assignment order is preserved internally.
   - `SnapshotSplitAssigner` accepts a `Map` and copies it into its `LinkedHashMap` field.
   - Added `SnapshotPendingSplitsStateTest`, which checks that the public constructor/getter descriptors still use `Map` (what callers compiled against older versions link against), and that the iteration order of the given map is kept. Against the previous revision this test fails to compile.
   



-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40216][cdc-base] Preserve assignment order of splits across restore to keep meta groups consistent [flink-cdc]

Posted by "leonardBang (via GitHub)" <gi...@apache.org>.
leonardBang merged PR #4489:
URL: https://github.com/apache/flink-cdc/pull/4489


-- 
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: issues-unsubscribe@flink.apache.org

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


Re: [PR] [FLINK-40216][cdc-base] Preserve assignment order of splits across restore to keep meta groups consistent [flink-cdc]

Posted by "dev-donghwan (via GitHub)" <gi...@apache.org>.
dev-donghwan commented on PR #4489:
URL: https://github.com/apache/flink-cdc/pull/4489#issuecomment-6314297236

   Rebased onto the latest master (including FLINK-40697) and updated the description with test results.
   
   @loserwang1024 since this revisits the restore-time sort from FLINK-34634, I thought you might be the right person to take a look whenever you have time. Thanks!


-- 
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: issues-unsubscribe@flink.apache.org

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