You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "DanielLeens (via GitHub)" <gi...@apache.org> on 2026/04/20 06:56:06 UTC
Re: [PR] [Feature][Core] Error Data Bypass Capability for Transform & Sink (Dead Letter Queue) [seatunnel]
DanielLeens commented on PR #10306:
URL: https://github.com/apache/seatunnel/pull/10306#issuecomment-4278480441
Hi @zhangshenghang, thanks for working on this. The goal is valuable: SeaTunnel does need a carefully designed row-level error bypass / DLQ capability. I reviewed the full PR locally on branch `seatunnel-review-10306` against merge base `123eedc0b3ba77a976e1c718cae5ccc1f5dece1d` and PR head `3b6ac252749d9164070f76812374e01407606247`. The diff is large: 85 files, 9487 insertions, 32 deletions.
# What This PR Solves
- User pain point: today, one dirty row in a Transform or Sink can fail the whole SeaTunnel job. For large JDBC loads, users often want to keep valid rows moving while recording bad rows for later investigation and backfill.
- Fix approach: this PR adds an experimental engine-level `ErrorHandler`, `SupportRowLevelError`, row error collectors, Zeta Transform/Sink wrappers, and JDBC row-level classification based on SQLState `22` / `23`.
- One sentence: this is trying to add a DLQ-like path so a single bad record does not always bring down the whole job.
Simple example: if a MySQL target table has `name VARCHAR(10)` and one order has a longer name, the old behavior fails the job; this PR aims to write that bad row into an error table and let other valid orders continue.
# 1. Code Change Review
## 1.1 Core Logic Analysis
The main changed path is:
```text
env.sink_error_handler / env.transform_error_handler
-> SeaTunnelTask.getEnvOptions()
Zeta Transform path
-> TransformFlowLifeCycle.open() [TransformFlowLifeCycle.java:80-94]
-> initErrorHandlingTransforms() [TransformFlowLifeCycle.java:225-280]
-> wraps SeaTunnelMapTransform / SeaTunnelFlatMapTransform
-> TransformFlowLifeCycle.received(data) [TransformFlowLifeCycle.java:134-145]
-> wrapper catches row-level errors
-> ErrorHandler.onError(...)
-> map returns null / flatMap returns empty
Zeta Sink path
-> SinkFlowLifeCycle.restoreState() [SinkFlowLifeCycle.java:344-374]
-> initRowErrorCollectorIfNeed() [SinkFlowLifeCycle.java:377-404]
-> sink.createWriter(writerContext)
-> wrapWriterIfNeed() [SinkFlowLifeCycle.java:406-448]
-> wraps the writer with ErrorHandlingSinkWriter
-> SinkFlowLifeCycle.received(data) [SinkFlowLifeCycle.java:285-291]
-> ErrorHandlingSinkWriter.write()
-> delegate.write()
-> if the connector says this is a row-level error
-> ErrorHandler.onError(...)
-> DefaultErrorSinkWriter.write()
-> enqueue error row [DefaultErrorSinkWriter.java:118-139]
-> background worker writes it later [DefaultErrorSinkWriter.java:314-344]
Checkpoint path
-> SinkFlowLifeCycle.received(Barrier) [SinkFlowLifeCycle.java:211-267]
-> writer.prepareCommit(checkpointId)
-> writer.snapshotState(checkpointId)
-> ErrorHandlingSinkWriter.snapshotState()
-> delegates only to the main writer [ErrorHandlingSinkWriter.java:123-126]
-> runningTask.ack(barrier) [SinkFlowLifeCycle.java:267]
```
Before this PR, `SinkWriter.Context` had no row-error collector:
```java
interface Context extends Serializable {
int getIndexOfSubtask();
MetricsContext getMetricsContext();
EventListener getEventListener();
}
```
After this PR:
```java
default Optional<RowErrorCollector> getRowErrorCollector() {
return Optional.empty();
}
```
Before this PR, `SinkFlowLifeCycle.restoreState()` created the sink writer directly:
```java
this.writerContext =
new SinkWriterContext(sinkAction.getParallelism(), indexID, metricsContext, eventListener);
this.writer = sinkAction.getSink().createWriter(writerContext);
```
After this PR, it initializes row-error handling and wraps the writer:
```java
initRowErrorCollectorIfNeed();
this.writerContext =
new SinkWriterContext(
sinkAction.getParallelism(), indexID, metricsContext, eventListener,
stageRowErrorCollector);
this.writer = sinkAction.getSink().createWriter(writerContext);
wrapWriterIfNeed();
```
Key findings:
- The normal Zeta Sink path does hit this PR.
- The normal Zeta Transform path also hits this PR.
- Flink/Spark translation paths do not hit these wrappers.
- The implementation is an experimental architecture seed, not a stable merge-ready implementation yet.
- The biggest correctness gap is that routed error rows are asynchronous and not checkpoint-aware.
## 1.2 Compatibility Impact
Current judgment: partially compatible.
Default behavior remains compatible because the new feature is disabled by default. However, the PR adds new API/SPI surface (`SupportRowLevelError`, `RowErrorCollector`, `RowErrorEvent`, `RowErrorPhase`, `SinkWriter.Context#getRowErrorCollector()`), new user-facing env configuration, and new error-table semantics. Once enabled, the behavior changes from fail-fast to skip-and-route for selected row-level errors.
This must be clearly documented as experimental, Zeta-only unless Flink/Spark support is added, and not yet a full exactly-once DLQ guarantee.
## 1.3 Performance / Side Effects
This path adds extra CPU and allocation on error rows, especially when stack traces or original data are included. The default queue capacity is 10000, so high error rates may increase memory and GC pressure. ROUTE mode adds another sink write path and network traffic. Locking can increase around JDBC batch handling, synchronized error sink writes, and multi-table writer processing. The major side effect is semantic rather than raw performance: the error sink is not coordinated with checkpoint/committer lifecycle.
## 1.4 Error Handling And Logs
The code avoids logging full option values in some places, which is good. But the following issues block merge.
Issue 1: The PR currently does not compile in CI
- Location: `seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSinkWriter.java:58`
- Description: the CI run `23198728587` fails in `connector-jdbc` compilation. The log reports `cannot find symbol class SchemaCoordinator` and `cannot find symbol class FlushEvent` in `JdbcSinkWriter.java`.
- Risk: the branch is not buildable, so the feature cannot reach a reliable test stage.
- Suggested fix: first fix the missing API/import alignment and rerun CI until at least `connector-jdbc` compiles cleanly.
- Severity: High
Issue 2: The PR has real merge conflicts with current `dev`
- Location: `seatunnel-api/src/main/java/org/apache/seatunnel/api/sink/multitablesink/MultiTableSinkWriter.java:113`
- Description: local `git merge-tree` reports `changed in both` for `MultiTableSinkWriter.java`, `JdbcOutputFormat.java`, and `SinkFlowLifeCycle.java`, with conflict markers around the multi-table writer changes. GitHub also reports `mergeable=CONFLICTING` and `mergeStateStatus=DIRTY`.
- Risk: this PR cannot be merged, and conflict resolution touches core sink lifecycle and schema-evolution code.
- Suggested fix: rebase/merge latest `dev`, resolve the three conflicting files carefully, and re-review the sink lifecycle after conflict resolution.
- Severity: High
Issue 3: Routed error rows are not checkpoint-aware and can be lost after checkpoint ack
- Location: `seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/task/error/ErrorHandlingSinkWriter.java:123`
- Description: `DefaultErrorSinkWriter.write()` only enqueues the error row, while a background thread writes it later. During checkpoint, `ErrorHandlingSinkWriter.snapshotState()` only delegates to the main writer and does not flush/snapshot the error sink queue. `SinkFlowLifeCycle` can then ack the barrier.
- Risk: the main pipeline can checkpoint progress after dropping a bad row, while the corresponding DLQ row is still only in memory. A crash in that window loses the error record.
- Suggested fix: either make the error sink checkpoint-aware and flush/commit it with the barrier, or make ROUTE synchronous until the semantics are safe. If neither is intended, this must be explicitly downgraded to best-effort logging and should not be described as a reliable DLQ.
- Severity: High
Issue 4: Background error sink failures may be swallowed on close
- Location: `seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/task/error/DefaultErrorSinkWriter.java:143`
- Description: `drainLoop()` stores failures in `workerFailure`, and `write()` checks it before later writes. But `close()` does not check `workerFailure` after the worker exits. If the last asynchronous write fails and no later write occurs, close can return successfully.
- Risk: the job may be reported successful while error rows were not written.
- Suggested fix: check `workerFailure` after `waitForWorkerTermination()` in `close()` and throw it. Please also add a focused unit test for “last worker write fails, close must fail.”
- Severity: High
Issue 5: The docs/config look like a general SeaTunnel feature, but the implementation is Zeta-only
- Location: `docs/en/introduction/configuration/error-handling.md:3`
- Description: docs say “In SeaTunnel” and expose generic `env.*_error_handler` config, but the implementation is wired only through Zeta `TransformFlowLifeCycle` and `SinkFlowLifeCycle`. The new E2E explicitly disables Spark and Flink.
- Risk: users may configure the feature on Flink/Spark and expect it to work, while the actual execution path does not use these wrappers.
- Suggested fix: either add Flink/Spark support, or clearly document and fail fast that this is currently Zeta-only.
- Severity: Medium
Issue 6: Several added E2E config files fail `git diff --check`
- Location: `seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/resources/error-handling/sink_error_handler_log_max_error_records.conf:83`
- Description: local `git diff --check upstream/dev...HEAD` reports extra blank lines at EOF in multiple new config files.
- Risk: formatting/code-quality checks remain red.
- Suggested fix: remove the extra EOF blank lines and rerun formatting checks.
- Severity: Low
# 2. Code Quality
The code direction is understandable, but the branch is not merge-ready because it does not compile, conflicts with current `dev`, and has unresolved lifecycle semantics. The tests cover many handler/queue branches, but they do not cover checkpoint recovery with pending error rows or the close-time background failure path.
# 3. Architecture
This is a long-term architecture seed, not a complete long-term solution yet. The `SupportRowLevelError` idea is useful, but the error sink needs to be part of the same reliability model as the main sink. Otherwise, the main job can move forward while the error path remains best-effort.
# 4. Issue Summary
| # | Issue | Location | Severity |
|---|---|---|---|
| 1 | PR does not compile in CI | `JdbcSinkWriter.java:58` | High |
| 2 | Merge conflicts with current `dev` | `MultiTableSinkWriter.java:113` | High |
| 3 | Error sink queue is not checkpoint-aware | `ErrorHandlingSinkWriter.java:123` | High |
| 4 | Background error sink failure can be swallowed on close | `DefaultErrorSinkWriter.java:143` | High |
| 5 | Docs/config imply general support, but implementation is Zeta-only | `docs/en/introduction/configuration/error-handling.md:3` | Medium |
| 6 | E2E config files fail diff check | `sink_error_handler_log_max_error_records.conf:83` | Low |
# 5. Merge Decision
### Conclusion: not recommended to merge
Blocking items:
- Issue 1: the branch must compile first.
- Issue 2: the branch must be rebased/resolved against current `dev`.
- Issue 3: routed error rows must not be acknowledged past checkpoint while still only in an in-memory async queue.
- Issue 4: async error sink failures must be propagated during close.
Recommended but non-blocking after the above:
- Issue 5: clarify or implement engine support scope.
- Issue 6: clean up formatting.
Overall: the feature is worth pursuing, but the current implementation should not be merged as-is. A safer path is to first narrow it to a Zeta + JDBC experimental feature with explicit docs and fail-fast validation, then make the error sink either checkpoint-aware or synchronous enough that users do not lose the very records they enabled DLQ to preserve.
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org