Repository navigation
[Fix][Connector-V2] Run the final Databend CDC merge when the writer closes - #12848
Conversation
…closes On Flink 1.15-1.18 the aggregated committer drops commits that arrive after end of data and is never closed, so CDC rows written after the last completed checkpoint stay in the raw table. The writer's close-time merge was meant to cover this but never ran, because executeBatch() resets batchCount before performMerge() checks it. Track unmerged CDC rows with a separate flag.
DanielLeens
left a comment
There was a problem hiding this comment.
Review Report
Scope
Yes — this review covers the Apache SeaTunnel Databend CDC writer's final-merge tracking and its focused close-path tests.
Verification
- Reviewed the PR head
3be4814c0011e6e4f4ee4ab7eda3a13329622e31against the currentdevbase. - Traced CDC batch execution, batch-count reset, merge eligibility, merge-success state reset, close ordering, and resource cleanup.
- Reviewed the two added close-path tests for already-flushed CDC rows and an untouched writer.
- The mandatory
Buildworkflow is still in progress at review time; no completed failing check was available to attribute to this change. - No live Databend run was performed because it requires the external CDC sink environment; the behavior is covered by focused mocks and should run in CI.
Findings
High
None found in the reviewed source.
Medium
None found in the reviewed source.
Low
None found in the reviewed source.
Required Fixes
No source changes requested from this review.
Suggested Tests
- Let the mandatory Build workflow complete on the current head.
- Run the Databend connector unit tests, including both new close-path cases.
- In a Databend CDC environment, flush a full batch, close with
batchCount == 0, and verify that the raw-table changes are merged into the target table exactly once.
Runtime Before/After
Before: a CDC batch could be successfully flushed to the raw table and reset batchCount to zero, causing close() to skip the final merge even though unmerged changes existed.
After: the writer records successful CDC flushes independently of batchCount, performs the required final merge on close, and clears that marker only after a successful merge.
Backward Compatibility
The change preserves existing CDC SQL and public connector configuration. It corrects the close-time delivery behavior for data already accepted by the raw table.
Risks
The merge marker is writer-local and depends on the existing close lifecycle. The supplied tests cover the key zero-batch-count regression; an end-to-end CDC close test remains useful to validate behavior against a real Databend stream.
Review Status
No source-level blocker found; waiting for the required Build workflow to finish successfully.
Remaining Concerns
Please recheck the mandatory CI result on the current head, especially the Databend connector test suite.
nzw921rx
left a comment
There was a problem hiding this comment.
+1 LGTM
Non-blocking follow-up: abortPrepare() should also clear hasUnmergedCdcRows, so a writer closed after an aborted checkpoint does not merge that batch while DatabendSinkAggregatedCommitter is in the aborted state. A small abortPrepare() + close() test would cover it. Cleaning up the aborted raw rows can be a separate issue.
Purpose of this pull request
Fixes #12847.
In CDC mode the Databend sink writes rows to a raw table and moves them to the target table with
MERGE INTO. On Flink 1.15–1.18 the aggregated committer runs in a separate global committer task that drops commits arriving after end of data and is never closed, so if no checkpoint completes after the last insert, theMERGEnever runs.DatabendCDCSinkITfails this way on Flink 1.18 (expected: <3> but was: <0>), and Flink 1.15 was disabled for the same symptom in #11624.DatabendSinkWriter.close()already tries a finalMERGE, butperformMerge()checksbatchCount, whichexecuteBatch()has just reset to 0, so it never runs.This PR tracks CDC rows written to the raw table but not yet merged with a flag, so the writer's final
MERGEruns when there is something to merge.The writer and the aggregated committer may now both merge the same stream. That is safe: when several
MERGEs read one stream at the same time, one applies the rows and the others merge nothing (tested below).Before: on Flink 1.15–1.18 the job finishes with the rows in the raw table and an empty target table.
After: the writer merges the remaining rows when it closes, on every engine.
Does this PR introduce any user-facing change?
Bug fix only: on Flink 1.15–1.18, CDC rows written after the last completed checkpoint now reach the target table. No config or API change.
How was this patch tested?
DatabendSinkWriterTest: added tests thatclose()merges after a CDC batch was flushed and skips the merge when nothing was written. The first fails without the fix. 15/15 pass on JDK 11 and 17.DatabendCDCSinkITwithcheckpoint.interval = 30000, so no checkpoint completes before the writes (deterministic repro):dev): fails on Flink 1.18 withexpected: <3> but was: <0>; Flink 1.20, Spark 3.3 and Zeta pass;DatabendCDCSinkITwith the defaultcheckpoint.interval = 1000: passes on all four engines.datafuselabs/databend:nightlyimage used by the IT: 9 simultaneousMERGEs from one stream, and 8 writers inserting and merging while another session merged every 200 ms. No errors, no duplicate rows, and every row reached the target table.Check list
New License Guide
incompatible-changes.mdto describe the incompatibility caused by this PR.