Skip to content

Fix schema change routing for shared multi-table sinks - #11015

Merged
davidzollo merged 15 commits into
apache:devfrom
DanielLeens:david_st3451_shared_sink_schema_change
Aug 2, 2026
Merged

davidzollo merged 15 commits into
apache:devfrom
DanielLeens:david_st3451_shared_sink_schema_change

Conversation

@DanielLeens

@DanielLeens DanielLeens commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add physical-sink-aware schema-change routing for shared multi-table sinks so sibling writers freeze related queues before applying DDL
  • fix MySQL CDC same-name table DDL resolution across multiple databases by resolving unqualified DDL against the current database instead of pinning every table to the first match
  • add focused parser coverage plus a MySQL CDC E2E that verifies two databases with the same table name keep their data and DDL isolated after routing to different sink databases
  • harden the MySQL CDC E2E containers for CI by copying init SQL into the container and using mapped SeaTunnel ports instead of fixed host bindings
  • extend the schema evolution docs in English and Chinese with multi-database and multi-table routing guidance and concrete examples

Validation

  • ./mvnw spotless:apply -pl seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e -am -DskipTests -Dmaven.test.skip=true -nsu
  • Full runnable E2E was not rerun locally in this update because the requested verification path is GitHub Actions on this PR.

Notes

  • The new MySQL CDC E2E covers DDL on same-name tables from different source databases and asserts that each downstream database continues to receive only its own table's data after schema evolution.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I went through the full diff and traced the shared-schema-evolution path end to end.

What this PR is fixing:

  • Before this change, a multi-table job could route multiple upstream tables into the same physical sink table, but schema changes were still dispatched only by logical source-table identity.
  • That meant one sub-writer could already apply the DDL to the physical table while sibling sub-writers that write to the same physical table kept using stale in-memory schema.
  • The new getPhysicalSinkTableIdentifier() hook plus the queue/barrier coordination in MultiTableSinkWriter closes that gap: older rows are drained first, then the schema change is fanned out to every sibling writer that shares the same rendered sink table.

Call chain I checked:
SchemaOperator broadcast
-> MultiTableSinkWriter.applySchemaChange(...)
-> collectSchemaChangeDispatchTargets(...)
-> enqueueSchemaChangeBarrier(...)
-> each MultiTableWriterRunnable drains older rows
-> last queue reaching the barrier runs applySchemaChangeToTarget(...)
-> JDBC / StarRocks writers refresh both logical and physical sink schema.

I did not find a source-side blocker in the current head. The new unit / connector tests also line up with the intended runtime behavior, and the API addition is backward compatible because the new method has a safe default implementation.

I'm approving from the code-review side. The current Build check is still queued, so the merge gate is not green yet, and I also recorded that the branch is currently behind_by=6 with compare status diverged. At the moment that is queue metadata rather than a separate review blocker, because there is no stale failing CI signal to act on yet.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I re-reviewed the latest head end to end.

What this PR solves

  • User pain: shared multi-table sinks need schema-change routing that keeps per-physical-table writers consistent when upstream schema events arrive.
  • Fix approach: extend the multi-table sink writer path with explicit schema-change dispatch/barrier handling and back it with focused unit/integration coverage.
  • One-line summary: I do not see a reopened source-level blocker in the shared multi-table schema-change path on the current head, and the latest follow-up commits stay in the test-stabilization layer rather than changing the core routing contract again.

Runtime / review path I checked

Schema-change path for shared multi-table sinks
  -> source-side schema change reaches MultiTableSinkWriter
  -> SchemaChangeBarrier / SchemaChangeDispatchTarget coordinate which writer(s) must observe the event
  -> MultiTableWriterRunnable applies the schema-change handling before later row writes continue
  -> the latest MySQL CDC E2E follow-up waits for the incremental-read phase before driving the DDL step on the current head

Current status on the latest head

  • The core schema-change routing surface in seatunnel-api is unchanged in direction from the version I already approved from the source-review side.
  • The latest head mainly tightens the follow-up test timing in the MySQL schema-evolution path.
  • I do not see a reopened code-level blocker in the current revision.
  • The remaining merge gate is the current Build run, which is still in progress on this head.

Review conclusion

Conclusion: can merge after fixes

  1. Blocking items
  • Please let the current Build check settle green on this head.
  1. Suggested follow-up
  • None on the current source diff from my side.

Thanks again for pushing through the routing and coverage details here.

@DanielLeens
DanielLeens force-pushed the david_st3451_shared_sink_schema_change branch from fb3bb5e to 0f3aa1c Compare July 4, 2026 01:18
@DanielLeens

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up commits. I rechecked the latest head against the shared multi-table schema-change path again.

Current state on the latest head

  • I do not see a reopened source-side blocker in the shared physical-table schema-change routing path.
  • The latest head still looks consistent on the core flow:
    source schema change -> MultiTableSinkWriter dispatch/barrier -> per-writer drain -> shared physical sink schema refresh.
  • The current Build run is still queued, so the remaining gate is CI rather than a new code-side blocker from Daniel's side.

So from the Daniel technical-review side, the current revision still looks clear to me. Once the current Build settles green, this should be ready for the usual maintainer-side merge step.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the latest head from Daniel's side. I still do not see a new source-side blocker on this head; the thing that changed since the earlier round is the CI / merge-gate fact, not the code-side conclusion.

Current gate

  • The current Build check is still failing.
  • This branch is also behind the latest dev (behind_by=37, compare status: diverged).

Next step

  • Since the remaining blocker here is the stale CI / merge gate rather than a newly identified source issue, the lowest-cost next step is to sync the latest dev and rerun Build first.
  • If Build still fails after the sync, we can narrow it down again on the refreshed head.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up commit. I re-reviewed the latest head a065e999a87a from scratch against the full current diff, including the queued schema-change coordination path, the MySQL CDC parser fix, the JDBC/StarRocks shared physical sink updates, and the new UT/E2E coverage.

What this PR fixes

  • User pain: in a multi-table sink where several logical source tables resolve to the same physical sink table, a schema change from one source table can update the external table while sibling writers keep their stale in-memory schema and continue writing rows with the old shape.
  • Fix approach: route schema-change handling through the same ordered queue workers as rows, collect sibling writers by resolved physical sink identifier, and coordinate all queue workers with a shared barrier before applying the DDL fan-out.
  • In one sentence: this makes shared physical sink schema evolution an in-band, ordered operation instead of a side-channel update that can race sibling writes.

Full runtime path checked

CDC schema change event
  -> MultiTableSinkWriter.applySchemaChange(event)
      -> subSinkErrorCheck()
      -> hasSourceMatchedWriter(event)
      -> ensureQueueWorkersSubmitted()
      -> enqueueSchemaChangeBarrier(event)
          -> enqueue one schema-change queue element into every worker queue
          -> older queued rows drain first
          -> SchemaChangeBarrier waits until all queue workers reach the barrier
          -> last arriving worker runs dispatchSchemaChangeToTargets(event)
              -> collect source-matched writer
              -> read SupportSchemaEvolutionSinkWriter.getPhysicalSinkTableIdentifier()
              -> add sibling writers with the same physical sink identifier
              -> applySchemaChangeToTarget(...) for each target
          -> release all parked queue workers
          -> surface any schema-change failure through the existing table-failure path

JDBC shared physical sink case
  -> AbstractJdbcSinkWriter.applySchemaChange(event)
      -> tableSchema = event.getChangeAfter().getTableSchema()
      -> reOpenOutputFormat(event)
          -> prepareCommit()
          -> apply DDL against sinkTablePath
          -> rebuild/open JdbcOutputFormat with the updated schema

MySQL multi-database parser case
  -> MySqlSchemaChangeResolver.createDdlParser(...)
      -> CustomMySqlAntlrDdlParser(dbzConfig)
          -> parseQualifiedTableId(...) now resolves from the current DDL/current database
          -> same table name across different databases is no longer pinned to the first table path

Current findings

  • MultiTableSinkWriter.java:343-454 now sends schema changes through the ordered worker queues and waits on SchemaChangeBarrier before mutating the sink schema.
  • MultiTableSinkWriter.java:376-425 preserves the legacy source-table match first, then fans out only to sibling writers that explicitly report the same physical sink table.
  • SupportSchemaEvolutionSinkWriter.java:35-48 keeps backward compatibility by making the new physical-sink identifier method optional by default.
  • AbstractJdbcSinkWriter.java and StarRocksSinkWriter.java now expose resolved physical sink identifiers, so the new fan-out is used by the concrete shared-table writers that need it.
  • CustomMySqlAntlrDdlParser.java no longer binds later DDL to the first table path, which is important for the new same-table-name / multi-database E2E case.
  • I did not find a source-level blocker on this head.

Test coverage and stability

  • MultiTableSinkWriterSchemaChangeBroadcastTest covers same physical sink fan-out, non-shared isolation, first schema change after startup, queued-row ordering, and worker-failure fail-fast behavior.
  • JdbcSinkWriterSharedPhysicalTableSchemaChangeTest covers the production JDBC path with a real SQLite table and sibling writer after a drop-column schema change.
  • The MySQL CDC E2E change waits for incremental-read evidence and compares source/sink schema/data with Awaitility, so it avoids the most fragile fixed-sleep pattern.
  • The small 200 ms sleeps in the queue-barrier UTs are used only while a monitor is intentionally held, with latch and join assertions around them. I do not see a high-risk flaky pattern from those sleeps.
  • Stability rating: stable.

Compatibility / side effects

  • API compatibility: compatible. The new SPI method has a default Optional.empty() implementation.
  • Config/defaults/protocol: unchanged.
  • Serialization/checkpoint shape: unchanged by this PR.
  • Performance: schema-change events now briefly park all multi-table writer queues at the barrier, which is the right tradeoff for preserving row/schema ordering. Normal row writes do not gain a new hot-path dependency.
  • Error handling: schema-change failures are surfaced through the existing IOException / table-failure path; worker death before the barrier releases pending schema-change requests instead of hanging.

Existing community feedback

I did not find non-Daniel review findings or inline comments on this PR during this pass.

Merge conclusion

Conclusion: can merge after CI

  1. Blocking items
  1. Suggested follow-up
  • None from this source review round.

Overall, this is a careful fix for a real shared-sink schema-evolution race. The main path is hit by normal multi-table schema-change handling, the compatibility boundary is conservative, and the regression coverage is focused on the risky ordering cases. Once the queued Build check finishes green, I do not see a code-side reason to hold this PR from Daniel's review side.

@SEZ9 SEZ9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I re-reviewed the latest head a065e999a87a from scratch.

What this PR fixes

  • User pain: In shared multi-table sinks, a DDL applied through one sub-writer mutated the physical table while sibling writers kept flushing rows with a stale schema, and MySQL CDC pinned unqualified DDL for same-name tables to the first matching database, corrupting routing across databases.
  • Fix approach: Route schema changes through the writer queues as barrier elements (QueueElement) so all sub-writers sharing a getPhysicalSinkTableIdentifier() freeze and apply the DDL in order, and resolve unqualified DDL in CustomMySqlAntlrDdlParser against the binlog's current database instead of the first table-filter match; adds parser unit coverage, a two-database same-table-name MySQL CDC E2E, hardened E2E container setup, and EN/ZH routing docs.
  • One-line summary: The coordination and parser logic look sound and well-documented, but the queue-element and IOException conversion changes touch hot paths (write/snapshotState) and new API surface (SupportSchemaEvolutionSinkWriter default method), so I focused my recheck on ordering guarantees, error-channel compatibility, and the deadlock risk of barrier fan-out across sibling queues.

Runtime chain I rechecked

SourceReader emits SchemaChangeEvent
  -> SinkFlowLifeCycle.received(SchemaChangeEvent)
    -> MultiTableSinkWriter.applySchemaChange(event)  MultiTableSinkWriter.java:~336
      -> subSinkErrorCheck() -> currentSubSinkFailure()  MultiTableSinkWriter.java:~298 (now returns IOException instead of throwing RuntimeException)
      -> hasSourceMatchedWriter(event)  MultiTableSinkWriter.java:~352 (legacy source-table short-circuit for unrelated events)
      -> ensureQueueWorkersSubmitted()
      -> enqueueSchemaChangeBarrier(event)  (barrier QueueElement pushed into every related BlockingQueue<MultiTableWriterRunnable.QueueElement>, blockingQueues declared MultiTableSinkWriter.java:~84)
        -> MultiTableWriterRunnable.run() dequeues QueueElement, distinguishes row vs. schema-change barrier
          -> collectSchemaChangeDispatchTargets(event)  MultiTableSinkWriter.java:~372
            -> primary match on SinkIdentifier.getTableIdentifier() == event.tablePath().getFullName()
            -> fan-out to siblings via SupportSchemaEvolutionSinkWriter.getPhysicalSinkTableIdentifier()  SupportSchemaEvolutionSinkWriter.java:45 (default Optional.empty() preserves legacy source-only routing)
          -> executeWithTableRetry(..., MultiTableFailurePhase.CHECKPOINT, () -> ((SupportSchemaEvolutionSinkWriter) writer).applySchemaChange(event))

Upstream DDL resolution (MySQL CDC):
  MySqlStreamingChangeEventSource binlog DDL string
    -> CustomMySqlAntlrDdlParser.parse(ddl)  CustomMySqlAntlrDdlParser.java (changed: unqualified table names resolved against parser's current database via setCurrentDatabase instead of first table-filter match)
      -> SchemaChangeEvent.tablePath() carries the correct database, which is the key applySchemaChange routes on above

Findings

Issue 1: Possible public API change in seatunnel-api/src/test/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriterTest.java

  • Location: seatunnel-api/src/test/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriterTest.java
  • Why it matters: A public/protected signature appears to be removed or changed. Verify backward compatibility for downstream connectors.
  • Severity: High

Issue 2: Possible public API change in seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/parser/CustomMySqlAntlrDdlParser.java

  • Location: seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/parser/CustomMySqlAntlrDdlParser.java
  • Why it matters: A public/protected signature appears to be removed or changed. Verify backward compatibility for downstream connectors.
  • Severity: High

Review conclusion

Conclusion: can merge after the blocking items are fixed

1. Blocking items

  • Issue 1: Possible public API change in seatunnel-api/src/test/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriterTest.java
  • Issue 2: Possible public API change in seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/parser/CustomMySqlAntlrDdlParser.java

Nice progress overall — once the blocking points above are addressed this should be in good shape. Happy to discuss.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SEZ9 for the additional review. My previous note had the source side cleared from Daniel's earlier pass, but your latest CHANGES_REQUESTED review adds new concrete merge gates, so this PR is no longer just waiting on CI from Daniel's earlier comment.

No new commit has landed after that review yet. Please address the latest requested changes first; I will re-review the updated head from scratch once it is pushed.

@DanielLeens

Copy link
Copy Markdown
Contributor Author

Rechecked the current head a065e999a87a against the latest dev after the CI / merge-gate fact changed.

Runtime path rechecked

CDC schema change event
  -> MultiTableSinkWriter.applySchemaChange(event)
      -> subSinkErrorCheck()
      -> hasSourceMatchedWriter(event)
      -> ensureQueueWorkersSubmitted()
      -> enqueueSchemaChangeBarrier(event)
          -> enqueue one schema-change queue element into every worker queue
          -> older queued rows drain first
          -> SchemaChangeBarrier waits until all queue workers reach the barrier
          -> last arriving worker runs dispatchSchemaChangeToTargets(event)
              -> collect source-matched writer
              -> read SupportSchemaEvolutionSinkWriter.getPhysicalSinkTableIdentifier()
              -> add sibling writers with the same physical sink identifier
              -> applySchemaChangeToTarget(...) for each target
          -> release all parked queue workers
          -> surface any schema-change failure through the existing table-failure path

JDBC shared physical sink case
  -> AbstractJdbcSinkWriter.applySchemaChange(event)
      -> tableSchema = event.getChangeAfter().getTableSchema()
      -> reOpenOutputFormat(event)
          -> prepareCommit()
          -> apply DDL against sinkTablePath
          -> rebuild/open JdbcOutputFormat with the updated schema

MySQL multi-database parser case
  -> MySqlSchemaChangeResolver.createDdlParser(...)
      -> CustomMySqlAntlrDdlParser(dbzConfig)
          -> parseQualifiedTableId(...) now resolves from the current DDL/current database
          -> same table name across different databases is no longer pinned to the first table path

Merge conclusion

Conclusion: source blocker cleared from Daniel's side; sync latest dev and rerun CI first

  1. Blocking items
  1. Lowest-cost next step
  • Please sync with the latest dev and rerun the failing gate first.
  • If it still fails on the updated head, I can help narrow down the new failure from there.

Daniel only has READ permission on this repository, so a write-capable maintainer may still need to handle the final approval / dismissal step once the gate is clear.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this in my previous review — that's on me. I re-reviewed the latest head from scratch. The constructor compatibility issue raised by @SEZ9 is resolved in e214cff8, but I found one carryover blocker in the queue/barrier lifecycle. This was already present in the previous version; it was not introduced by the latest commit.

Blocking: a worker can exit just before the barrier is enqueued, leaving schema evolution waiting forever

MultiTableSinkWriter.applySchemaChange() performs its last worker-error check at MultiTableSinkWriter.java:350, then creates and enqueues the barrier at MultiTableSinkWriter.java:433-449. A queue worker that fails in that interval runs failPendingSchemaChangeRequests() (MultiTableWriterRunnable.java:139-150) before the barrier exists. The coordinator can then enqueue the new request into that already-dead worker's queue and wait indefinitely in SchemaChangeBarrier.awaitCompletion() (SchemaChangeBarrier.java:100-108), because no thread remains to reach or fail that participant.

The current tests cover both neighboring cases — failure after the barrier is already queued and failure before entering applySchemaChange() — but not this lost-notification window.

Please make barrier registration/enqueue and worker terminal notification a no-loss protocol. For example, publish an active barrier before the final worker-state check and have every worker terminal transition fail it, or use bounded waiting with repeated worker liveness/error checks. A deterministic regression test should force the worker to fail after the final error check but before its barrier request is enqueued.

Current gate: this PR is still a draft, the latest Build was queued when reviewed, and the branch is diverged from dev (ahead_by=10, behind_by=32). The source blocker above must be fixed independently of those gates. Since this is Daniel's own PR, this is a technical self-check and does not count as an independent approval.

@SEZ9 SEZ9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I re-reviewed the latest head e214cff8780f from scratch.

Findings

Issue 1: Possible public API change in seatunnel-api/src/test/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriterTest.java

  • Location: seatunnel-api/src/test/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriterTest.java
  • Why it matters: A public/protected signature appears to be removed or changed. Verify backward compatibility for downstream connectors.
  • Severity: High

Issue 2: Possible public API change in seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/parser/CustomMySqlAntlrDdlParser.java

  • Location: seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/parser/CustomMySqlAntlrDdlParser.java
  • Why it matters: A public/protected signature appears to be removed or changed. Verify backward compatibility for downstream connectors.
  • Severity: High

Review conclusion

Conclusion: can merge after the blocking items are fixed

1. Blocking items

  • Issue 1: Possible public API change in seatunnel-api/src/test/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriterTest.java
  • Issue 2: Possible public API change in seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/parser/CustomMySqlAntlrDdlParser.java

Nice progress overall — once the blocking points above are addressed this should be in good shape. Happy to discuss.

@DanielLeens

Copy link
Copy Markdown
Contributor Author

Thanks @SEZ9 for taking another look. I rechecked the two compatibility warnings against the exact unchanged head, but they do not describe public API removals:

  • MultiTableSinkWriterTest.java is test code; its test/helper signatures are not a downstream connector API.
  • CustomMySqlAntlrDdlParser keeps the original two-argument constructor as a deprecated compatibility overload and delegates to the new constructor, so source and binary call sites remain available.

The real blocker on this head remains the barrier-enqueue/worker-exit lost-notification window from my latest self-review. This follow-up only disposes the new external findings; it does not clear that existing blocker or act as an independent approval for my own PR.

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review note for the current head after the latest base sync: I rechecked the shared multi-table schema-change routing path, barrier behavior, JDBC/StarRocks writer integration, and multi-database E2E coverage.

The concrete compatibility concern is closed: the previous CustomMySqlAntlrDdlParser constructor is preserved and covered by a regression. The other automated warning pointed only at a test helper and does not identify a production API removal. I do not see a remaining source-level blocker or unrelated current-diff hunk.

The required Build is queued, so the technical verdict is clear_waiting_ci. Because I am the author, this self-review is not an independent approval; one maintainer review is still required.

@SEZ9

SEZ9 commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks @DanielLeens for the detailed recheck — that clears up both of my compatibility warnings.

  • MultiTableSinkWriterTest.java being test code means the signature change there isn't a downstream-facing API, so I'm dropping Issue 1.
  • Keeping the original two-argument CustomMySqlAntlrDdlParser constructor as a deprecated overload that delegates to the new one addresses the source/binary compatibility concern in Issue 2, so that's resolved from my side as well.

That said, this doesn't unblock the PR yet. Remaining asks before merge:

  1. Fix the barrier-enqueue/worker-exit lost-notification window flagged in Daniel's self-review — that's now the real blocker on this head. Please push a fix (or explain why the window can't be hit in practice) so it can be re-verified.
  2. Sync with the latest dev — the branch has diverged (ahead 9 / behind 9), and the current Build gate is failing: https://github.com/apache/seatunnel/runs/86601189863. Please rebase/merge and rerun CI. If it still fails on the updated head, share the log and we can help narrow it down.

Once the lost-notification fix lands and CI is green on a synced head, I'll do the final review pass and handle the approval/merge step. Thanks both for the thorough work here.

@DanielLeens DanielLeens left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What problem this PR solves

  • User pain: When several logical source tables map to one physical JDBC/StarRocks sink, source-only DDL routing updates the external table while sibling writers retain stale serializers/schema.
  • Fix approach: Writers expose the resolved physical sink ID; MultiTableSinkWriter inserts a schema barrier into every data queue, waits for older rows to drain, selects the source writer plus siblings with the same physical ID, refreshes all, then releases data.
  • One-line summary: Schema changes and rows are now ordered across all sub-writers sharing one real destination table.
  • Before: db_a.users and db_b.users both write ods.users; after db_a ADD COLUMN, the sibling still writes the old row shape.
  • After: A barrier freezes both queues, refreshes both writers sharing the physical ID, then allows later rows to continue.

1. Code-change review

1.1 Core logic and real call/execution chain

  • Behavior before: A schema event is synchronously dispatched only to the source-keyed writer, allowing siblings to continue old-schema rows after external DDL.
  • Behavior after: An in-band barrier queues behind all prior rows, freezes every worker, and fans out to the source writer plus siblings sharing the physical sink.
  • Normal-path hit: conditional — A multi-table CDC schema event hits when a source-matched writer exists; unrelated events return immediately, and empty physical ID retains source-only routing.

Changed files, classes, and methods

  • seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/SupportSchemaEvolutionSinkWriter.java:34-49 getPhysicalSinkTableIdentifier — A default Optional.empty hook lets opt-in connectors expose the resolved destination.
  • seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriter.java:84-520 typed queues/applySchemaChange/dispatch targets/barrier publication — Publishes markers to all queues, selects source plus shared-physical targets, and unifies the IOException failure channel.
  • seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableWriterRunnable.java:40-250 QueueElement worker loop — Processes rows and schema markers FIFO and fails pending requests on worker failure.
  • seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/multitablesink/SchemaChangeBarrier.java:1-128 SchemaChangeBarrier — A shared latch dispatches once after all workers arrive and releases after success/failure.
  • seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/AbstractJdbcSinkWriter.java:180-260 JDBC physical ID/applySchemaChange — Exposes sinkTablePath and flushes/runs DDL/rebuilds the output format.
  • seatunnel-connectors-v2/connector-starrocks/src/main/java/org/apache/seatunnel/connectors/seatunnel/starrocks/sink/StarRocksSinkWriter.java:140-230 StarRocks physical ID/applySchemaChange — Exposes the resolved path and rebuilds serializer/manager.

Effective prerequisites

  • JDBC/StarRocks writers return a stable resolved physical identifier and all queue workers are submitted and can reach the marker.

Conditions where the change does not apply

  • Connectors without a physical ID retain legacy source-only routing; unrelated table events do not start a barrier.

  • Recovery, exception, async, serialization, and concurrency paths: FIFO markers plus a shared latch prevent post-DDL rows from overtaking; the post-enqueue subSinkErrorCheck closes the worker-exit/lost-notification window; failures propagate as IOException and release the barrier. Checkpoint-state format is unchanged, and prepareCommit/snapshot still check/drain queues.

Multi-table Sink Writer contract audit

  • Applicable: false
  • Sink implements SupportMultiTableSink: Not reported by GitHub
  • createWriter returns the required subclass: Not reported by GitHub
  • optionRule contains the replica option: Not reported by GitHub
  • Evidence: The special contract is not applicable: this PR changes existing MultiTableSinkWriter coordination and adds no SupportMultiTableSinkWriter implementation.

1.2 Compatibility impact

  • Classification: fully_compatible (fully compatible)
  • API: Adds a default SPI method; existing implementations remain binary/source compatible.
  • SPI: Default Optional.empty preserves opt-out legacy behavior.
  • Configuration: No option/default is removed or changed.
  • Defaults: Legacy source-only routing is the empty-hook default.
  • Protocol and serialization: No external protocol or checkpoint-serialization change.
  • Checkpoint/restore: Only queue ordering changes; serialized state does not.
  • Historical behavior: The two-argument parser constructor remains as a deprecated delegating overload.
  • Migration guidance: No migration; connectors can opt into physical IDs.
  • Incompatible-changes documentation: Fully compatible; no entry required.

1.3 Performance and side effects

  • CPU: Each DDL performs an O(writer-count) target scan; not on the per-row hot path.
  • Memory: One control marker per queue plus small target sets.
  • GC: Low-frequency DDL objects with no material GC effect.
  • Network: Each physical-target writer performs connector-specific DDL/refresh; no added data-path network.
  • Lock contention: The barrier intentionally pauses all queue workers during DDL.
  • Concurrency safety: FIFO plus shared latch and failure recheck closes the current race.
  • Retry: Connector executeWithTableRetry remains; failure-policy continue/abort semantics remain.
  • Idempotency: The target set is deduplicated for one schema event; external-DDL idempotency follows connector contracts.
  • Resource release: Barrier success/failure both release workers; pending requests fail on worker error.
  • Overall: DDL-coordination overhead is bounded and required for consistency.

1.4 Error handling and logging

  • Exception propagation: Worker/runtime errors use IOException consistently and restore the interrupt flag.
  • Context: Failure summaries retain table/phase/connector context.
  • Log levels: Lifecycle/failure logging is appropriate.
  • Sensitive information: No secrets added.
  • Overall: The post-enqueue failure check fixes lost notification; the barrier does not hang.

1.5 Diff integrity, deletion ledger, and scope audit

  • intended_change_correctness: pass
  • diff_integrity: pass
  • deletion_ledger: total=211, classified=211, unclassified=0
  • Reconciliation: 211 = 211 + 0

Scope and base-drift items

  • No out-of-scope hunk, stale-base change, or merge artifact requires a separate ledger entry.

  • Out-of-scope hunk conclusion: None found; 22 files cover API coordination, connector hooks, focused tests/E2E, bilingual docs, and affected CI-stability support.

  • Stale-base conclusion: Diverged ahead 12/behind 11 is recorded; no rollback.

  • Merge-artifact conclusion: No deleted/renamed file, conflict marker, or merge artifact; mergeable=true.

2. Code-quality assessment

2.1 Code conventions, title format, and comments

  • Title format: The title lacks the strict [Type][Module] prefix, a non-blocking metadata recommendation; functional scope is clear.
  • Code conventions: git diff --check is clean; public/default SPI and complex barrier methods have comments.
  • Comment completeness: Physical-sink identity, barrier, and failure-channel contracts are documented.

2.2 Test coverage and stability

  • Unit tests: covered — API tests cover source-only/shared fan-out/backlog/failure/null Optional/continue mode.
  • Component tests: covered — A JDBC test covers two logical writers sharing a physical table.
  • Engine integration tests: covered — Queue/barrier/checkpoint entry points are composition-tested in API tests.
  • E2E: covered — MySQL E2E adds two-database same-name table schema changes.
  • Regression tests: covered — Parser compatibility and worker failure before/after barrier publication are covered.
  • Stability classification: stable

Test-stability evidence

  • seatunnel-api/src/test/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriterSchemaChangeBroadcastTest.java:1-695
    • Trigger: Bounded joins/latches control queue/barrier races.
    • Probability basis: No unbounded wait; E2E uses polling rather than correctness sleeps.
    • Analysis: Stable by static design; runtime evidence is limited by the failed/incomplete Build gate.

Missing scenarios

  • The exact-head Build did not complete Sanity/Helm aggregation and needs rerun/green.

2.3 Documentation

  • User-visible change: true
  • docs/en: Adds multi-database/table placeholder/routing examples and collapsed-table compatibility/key warnings.
  • docs/zh: Chinese is semantically aligned with English.
  • Examples: Examples cover different sink DBs, one sink DB, and wildcard routing.
  • Configuration truth: multi_table_sink_replica/placeholders match code/current docs.
  • URL truth: The relative placeholder-doc link is valid.

2.4 Local-validation boundary and GitHub CI evidence

  • Local boundary: Only static diff/source/concurrency-chain and exact-head GitHub CI were reviewed; compile/tests/E2E were not run locally.

Local execution boundary

  • compilation: not_executed — Not executed; current-head GitHub CI is the runtime evidence.
  • unit_tests: not_executed — Not executed.
  • integration_tests: not_executed — Not executed.
  • e2e: not_executed — Not executed.
  • packaging: not_executed — Not executed.
  • docker: not_executed — Not executed.
  • service_start: not_executed — Not executed.
  • real_job: not_executed — Not executed.

Actually executed review commands

  • git diff --stat cc7836dc46bf92afd95f9b61cb910c3bfbb55457...b7d01677710263a076405e968230a2a51625d639
    • Result: passed
    • Explanation: Confirmed 22 files, 2380 additions, and 211 deletions.
  • git diff --unified=0 cc7836dc46bf92afd95f9b61cb910c3bfbb55457...b7d01677710263a076405e968230a2a51625d639
    • Result: passed
    • Explanation: Completed all hunk/call/concurrency/deletion audit.
  • git diff --check cc7836dc46bf92afd95f9b61cb910c3bfbb55457...b7d01677710263a076405e968230a2a51625d639
    • Result: passed
    • Explanation: Clean.

Required checks

Complete status-check rollup

3. Architecture assessment

3.1 Solution type: precise fix / workaround / long-term design

  • Type: long_term_design
  • Assessment: The physical-identity hook plus in-band queue barrier is precise long-term coordination, not a workaround.

3.2 Maintainability

Connectors only expose resolved destinations and keep DDL/serializer rebuild local; API owns generic coordination.

3.3 Extensibility

New connectors can opt in through the default SPI; empty retains legacy behavior.

3.4 Historical-version compatibility

Fully compatible default hook and deprecated parser overload.

4. Disposition ledger for findings from other reviewers

  • total=2, confirmed=0, resolved_in_current_head=0
  • rejected_with_same_proposition_evidence=2, not_applicable_with_reason=0, unresolved=0
  • Reconciliation: 2 = 0 + 0 + 2 + 0 + 0

review-4733730265-issue-1 — SEZ9

  • Original proposition: An apparent signature change in MultiTableSinkWriterTest may be a downstream public API break.
  • Location: seatunnel-api/src/test/java/.../MultiTableSinkWriterTest.java
  • Thread: #11015 (review)
  • Current-head evidence: The referenced type/helper is under src/test/java and is not packaged as production API/SPI.
  • Disposition: rejected_with_same_proposition_evidence
  • Daniel disposition: Rejected with same-proposition evidence; SEZ9 accepted it in issuecomment-5077822229.

review-4733730265-issue-2 — SEZ9

  • Original proposition: The CustomMySqlAntlrDdlParser constructor change may break downstream source/binary calls.
  • Location: seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/org/apache/seatunnel/connectors/seatunnel/cdc/mysql/source/parser/CustomMySqlAntlrDdlParser.java
  • Thread: #11015 (review)
  • Current-head evidence: The original two-argument constructor remains as a deprecated delegating overload, and a regression test invokes it.
  • Disposition: rejected_with_same_proposition_evidence
  • Daniel disposition: Rejected with same-proposition evidence; SEZ9 accepted it in issuecomment-5077822229.

5. Formal findings

No blocking finding was identified; the remaining risks and test blind spots are fully recorded in Sections 2 and 3.

6. Findings summary

ID Finding Location Severity Merge gate
- No formal finding - - -

7. Merge conclusion

Conclusion:can merge after gates are satisfied

Blocking items

  • No source, documentation, compatibility, test-completeness, conflict, or diff-integrity blocker remains.

Non-blocking recommendations

  • No additional non-blocking finding is recorded.

Overall assessment

The current race fix, focused unit/JDBC/E2E coverage, and bilingual docs form a coherent end-to-end solution with no source blocker.

Better alternative implementation and trade-offs

  • Alternative: A central shared physical writer could remove sibling broadcast but requires a much larger connector lifecycle/state redesign.
  • Trade-offs: The current opt-in SPI plus barrier is narrower and backward compatible, at the cost of an O(writers) scan and all-queue pause during DDL.

8. GitHub publication and reply readback

  • Publication event: COMMENT
  • Publisher identity: DanielLeens (repository permission READ)
  • Reviewed commit: b7d01677710263a076405e968230a2a51625d639
  • This complete report is the submitted GitHub Review body. Its immutable review ID, URL, state, and submission time are verified from the GitHub API immediately after creation and retained in the local bilingual evidence.
  • Any precise line-thread replies are separate GitHub objects and are likewise verified individually.

@davidzollo
davidzollo marked this pull request as ready for review July 31, 2026 22:31

@davidzollo davidzollo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1
LGTM

@davidzollo

Copy link
Copy Markdown
Contributor

@nzw921rx Please help review this PR when you're free, thx

@nzw921rx nzw921rx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants