Repository navigation
[Fix][Zeta] Propagate transform startup failures - #13175
goutamadwant wants to merge 4 commits into
Conversation
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks a lot @goutamadwant for picking this up so quickly after #13132 and for keeping the scope tight. The fix is small and readable, and the tests are strong: the unit cases cover first, middle and last failure, map and flat-map, wrapped and unwrapped chains, and cleanup failures, and the LocalModeIT case runs a real job in both ALL and OFF thread-share modes with 0 and 1 rows. I reviewed head b0459914c4d03a3489f224c255567821f7628e3d and traced the full Zeta task lifecycle. I found no logic bug. I have one documentation item I would like added before merge, plus a few non-blocking notes.
What Problem Does This PR Solve?
Since #4148, TransformFlowLifeCycle.open() has caught every exception from t.open(), logged it, and kept going. A transform that failed to initialize could still be wired into a running task. Later transforms were opened anyway, and a job with no input rows could even finish as FINISHED. This PR makes the first transform open() failure stop task startup, cleans up the transform stage, keeps the original exception as the primary cause (cleanup failures are attached as suppressed), and rejects any later received() call.
1 Code Change Review
1.1 Core logic
TransformFlowLifeCycle.java:116-157: the whole open sequence now runs inside one try. On failure it records startupFailure, calls close(), adds any cleanup exception as suppressed, and rethrows the original exception:
} catch (Exception failure) {
startupFailure = failure;
try {
close();
} catch (Exception cleanupFailure) {
if (cleanupFailure != failure) {
failure.addSuppressed(cleanupFailure);
}
}
throw failure;
}TransformFlowLifeCycle.java:371-374 makes a failed-startup close run only once (failedStartupClosed CAS), so the blocking worker's later task.close() is a no-op for this stage. The successful-startup close path is unchanged. TransformFlowLifeCycle.java:169-171 is a guard on received(). In the real runtime it should be unreachable, because the task never reaches RUNNING (see below).
Runtime path I traced on this head:
TaskExecutionService worker thread
SeaTunnelTask.init()
convertFlowToActionLifeCycle() post-order: allCycles = [sink, transformChain, source] (SeaTunnelTask.java:406)
SeaTunnelTask.stateProcess() state = WAITING_RESTORE
for cycle in allCycles: cycle.open() (SeaTunnelTask.java:270)
SinkFlowLifeCycle.open() -> writer created (already open)
TransformFlowLifeCycle.open()
t0.open() ok, t1.open() throws E
startupFailure = E
close(): t0.close(), t1.close(), t2.close() (never opened), errorHandler.close(), future.complete()
throw E (cleanup failures added as suppressed)
SourceFlowLifeCycle.open() -> never called
state stays WAITING_RESTORE; READY_START is never reported; hook()/collect() never run
E propagates out of Task.call()
Cooperative (ALL/PART): CooperativeTaskWorker catch Throwable
-> tracker.exception(E); taskDone(); cancelAllTask() -> SeaTunnelTask.cancel() -> FlowLifeCycle::cancel
-> task.close() is NOT called (TaskExecutionService.java:1449-1456)
Blocking (OFF): BlockingWorker catch Throwable -> exception(E); finally taskDone(); task.close()
-> TransformFlowLifeCycle.close() returns early (CAS already taken) (TaskExecutionService.java:1314-1330)
TaskGroupExecutionTracker.taskDone(): last task -> future.complete(FAILED, E)
-> PhysicalVertex / SubPlan / JobMaster state machine -> job FAILED with E as root cause
Because startupFailure is set before close() runs inside open(), the double-close guard holds in both worker modes. The checkpoint path is not affected either: the task never reports READY_START, so no barrier reaches this lifecycle.
1.2 Compatibility
- No API, SPI, option or serialization changes.
startupFailureandfailedStartupClosedare runtime-only fields on a lifecycle object that is never checkpointed. Successful startup behaves exactly as before. - This is a user-visible behavior change. A job whose transform
open()throws used to keep running. With zero input rows it could even finish asFINISHED. It now fails at startup. Real examples includeLLMTransformandEmbeddingTransformfailing to build their model client,PythonTransformfailing to start its worker, andSQLTransformfailing to parse. The new behavior is correct, but the project records changes like this inincompatible-changes.md(see Issue 1).
1.3 Side effects
- Cleanup also calls
close()on later transforms that were never opened (TransformFlowLifeCycle.java:375-385). The IT asserts this (closes == 1for all three). Blocking mode already did this on dev, and each close is wrapped in try/catch, so a transform whoseclose()dereferences an open-time field only produces an ERROR log line. This is acceptable. - In cooperative mode, lifecycles opened before the transform chain are not closed (see Issue 2).
allCyclesis built post-order, so the sink writer is opened first. - The volatile read in
received()runs on the per-record hot path. On mainstream JVMs this is a plain load and is negligible.
1.4 Error handling and logging
The original exception stays primary, and cleanup failures are attached as suppressed (TransformFlowLifeCycle.java:148-154). This matches what #13132 asked for. The duplicate-log problem is gone too: the old log.error was removed, and the worker logs the exception once.
Issue 1: Behavior change is not recorded in incompatible-changes.md
- Location:
docs/en/introduction/concepts/incompatible-changes.md,docs/zh/introduction/concepts/incompatible-changes.md(not touched) - Problem: The PR description correctly calls this a user-facing change, but the "update
incompatible-changes.md" checkbox is unchecked.error-handling.mddescribes the new rule, but users who are upgrading read the incompatible-changes page. - Risk: After upgrading, a job that used to report
FINISHED(for example a zero-row batch, or a stream that never received data) now reportsFAILED, and users get no upgrade note. - Best improvement: Add a short
## deventry in both languages, in the same Description / Impact / Migration shape as nearby entries. Something like: "Zeta: a transformopen()failure now fails task startup. Previously it was logged and ignored. Fix the transform configuration or its external dependency. No config migration is needed.LOG/ROUTEdo not cover initialization errors." - Severity: Medium (docs, should fix before merge)
- Raised by another reviewer: No
Issue 2: In cooperative mode, lifecycles opened before the transform chain stay open after a startup failure
- Location:
SeaTunnelTask.java:406(post-orderallCycles),TaskExecutionService.java:1449-1456(notask.close()on the cooperative failure path),SourceFlowLifeCycle.java:200(cancel()only cancels the reader) - Problem: Under
ALL/PART, the sink lifecycle is opened beforeTransformFlowLifeCycle. After this PR, a transform open failure ends the task through the cooperative catch block, which never callstask.close(). The sink writer opened earlier (JDBC connection, Kafka producer, and so on) is never closed. The IT does not catch this becauseStartupSink's writerclose()is a no-op. - Risk: Before this PR, a transform open failure did not end the task, so this path was not reachable from transforms. It was already reachable from source and sink open failures. Over repeated restarts, external resources can leak on the worker.
- Best improvement: This matches the scope Daniel and you agreed in #13132 (task-wide teardown belongs to #12231 / #12391, which is still open), so I am not asking you to fix it here. Please add one line to the PR description saying the sink side of a cooperative startup failure relies on #12391. Optionally, add an IT assertion such as a sink-writer close counter, marked as expected-to-be-covered by #12391.
- Severity: Medium (pre-existing gap, out of agreed scope, non-blocking)
- Raised by another reviewer: No
Issue 3: Error thrown from t.open() skips stage cleanup
- Location:
TransformFlowLifeCycle.java:144 - Problem: Only
Exceptionis caught. ANoClassDefFoundError,ExceptionInInitializerErroror otherLinkageError(common when a plugin jar or native library is missing) still propagates, butstartupFailureis not set andclose()is not called for transforms that were already opened. Dev behaves the same way, so this is not a regression. - Best improvement: Optional. Catch
Throwable, do the same bookkeeping, and rethrow (wrapping only if needed for thethrows Exceptionsignature). Leaving it as is is also acceptable. - Severity: Low (non-blocking)
- Raised by another reviewer: No
2 Quality
2.1 Code standards
The code is clean and well-scoped. The comments at TransformFlowLifeCycle.java:146-147 and :371 explain why cleanup lives here and why the guard exists, which is exactly what a later reader needs. One nit: the one-line Javadoc on open() (:114) could mention that a second open() after a failure rethrows the recorded exception.
2.2 Tests and stability
TransformFlowLifeCycleCloseTest.failedStartupClosesPartialResourcesAndRejectsRows(12 cases): fails if the old catch-and-continue comes back, if later transforms are opened, or if close is skipped or repeated. Stable (pure mocks, no timing).startupFailureSurvivesChildAndErrorHandlerCleanupFailuresandfailedStartupClosesRouteWriterOnce: fail if the cleanup exception replaces the original, or if the double-close guard is lost. Stable. Minor: both inject the privateerrorHandlerfield through reflection (TransformFlowLifeCycleCloseTest.java:139,:174). Configuringtransform_error_handlerthrough job env options, as the IT does, would test the real wiring instead. Non-blocking.SeaTunnelTaskStateTest.transformOpenFailureStopsTaskBeforeReady: asserts the state machine stays atWAITING_RESTORE,READY_STARTis never reported, and the source is never opened. The[flow, sourceLifeCycle]order matches the real post-order. Stable.LocalModeIT.transformStartupFailureFailsEmptyAndNonemptyJobs: real local cluster, isolated cluster name and loopback-only networking, 60s / 10s Awaitility budgets, and a static observation map scoped per job id and cleaned infinally. Risk is low. The only timing dependency is the 10s cleanup await, which is generous for an in-JVM job.
2.3 Docs
The en/zh error-handling.md sections match each other and the code. The only gap is Issue 1.
3 Architecture
Cleanup is in the right owner. TransformFlowLifeCycle creates the child transforms and the error handler, so it is the right place to release them when its own startup fails. Moving that cleanup into SeaTunnelTask or the worker would mix this fix with #12391. With the guard at :371-374, the change also stays correct after #12391 makes cooperative teardown call task.close().
4 Issue table
| # | Location | Summary | Severity | Blocking |
|---|---|---|---|---|
| 1 | docs/{en,zh}/introduction/concepts/incompatible-changes.md |
Upgrade note for "transform open failure now fails startup" | Medium | Should fix before merge (docs only) |
| 2 | SeaTunnelTask.java:406, TaskExecutionService.java:1449-1456 |
Cooperative startup failure leaves the earlier-opened sink unclosed (pre-existing, #12391 scope) | Medium | No, please note it in the PR description |
| 3 | TransformFlowLifeCycle.java:144 |
Error from open() skips stage cleanup (same as dev) |
Low | No |
5 Merge recommendation
Ready to merge after fixes.
- CI: the
Buildcheck is green on headb0459914. The branch is 1 commit behinddevwith no conflicts. - Non-CI blockers: none in the code. Please add the
incompatible-changes.mdentry (Issue 1). Once it is in, I am happy to approve. - Non-blocking: Issue 2 (one line in the PR description pointing to #12391), Issue 3, and the reflection nit in the tests.
Thanks again, this is a careful and well-tested fix.
|
Added EN/ZH upgrade notes for transform open() failures now failing task startup, including empty jobs. The checklist is updated, and the description explicitly tracks cooperative sink cleanup in #12391. |
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks @goutamadwant for the quick follow-up, and for the clear note in your comment. I checked both points against the new head: the EN/ZH upgrade notes are in incompatible-changes.md, and the PR description now says that cooperative sink cleanup is tracked in #12231 / #12391. Both items from my last review are resolved. I re-reviewed the whole diff on head c0d5b16647712c38eab1c218a232368288fc00de, not only the new commit, and I found no new issues.
What Problem Does This PR Solve?
Since #4148, TransformFlowLifeCycle.open() caught each exception from t.open(), logged it, and kept going. A transform that failed to initialize could still be wired into a running task. A job with zero input rows could even finish as FINISHED. This PR stops startup at the first transform open() failure. It cleans up the transform stage, keeps the original exception as the primary cause with cleanup failures attached as suppressed, and rejects any later received() call (#13132).
1 Code Change Review
1.1 Core logic
New commit c0d5b166 changes docs only (docs/en|zh/introduction/concepts/incompatible-changes.md). The engine code is byte-for-byte the same as b0459914. I re-checked it on this head:
TransformFlowLifeCycle.java:116-157: the whole open sequence is inside onetry. On failure it setsstartupFailure(:145), callsclose(), adds any cleanup exception as suppressed, and rethrows the original exception. A secondopen()rethrows the recorded failure (:117-118).TransformFlowLifeCycle.java:372: thefailedStartupClosedCAS makes failed-startup cleanup run exactly once. On the successful-startup pathstartupFailureis null, soclose()is unchanged.TransformFlowLifeCycle.java:169-170: thereceived()guard. In the real runtime it cannot be reached, because the task never reportsREADY_START.
The runtime path is the same one I traced last time:
SeaTunnelTask.stateProcess() WAITING_RESTORE
allCycles (post-order) = [sink, transformChain, source] -> cycle.open()
TransformFlowLifeCycle.open(): tN.open() throws E
startupFailure = E -> close() once (CAS) -> throw E (cleanup errors suppressed)
SourceFlowLifeCycle.open() never runs; READY_START never reported; no checkpoint barrier
Task.call() throws E
Cooperative (ALL/PART): tracker.exception(E) -> taskDone() -> cancelAllTask() (no task.close())
Blocking (OFF): exception(E) -> taskDone() -> task.close() -> transform close() is a no-op (CAS taken)
TaskGroupExecutionTracker -> PhysicalVertex / SubPlan / JobMaster -> job FAILED, root cause E
1.2 Compatibility
- No API, SPI, option, default value or serialization changes. The two new fields are runtime-only and never checkpointed.
- The user-visible change from "log and continue" to "fail at startup" is now in the upgrade notes. EN
incompatible-changes.md:8-18and ZHincompatible-changes.md:7-15match each other. Both say what changed, show the oldFINISHED-with-zero-rows symptom, tell users what to fix before upgrading, explain whyLOG/ROUTEcannot recover an initialization failure, and say that configuration and checkpoint formats are unchanged. This resolves my previous Issue 1.
1.3 Side effects
- Same as before: later transforms that were never opened also get
close()called, and each call is wrapped in try/catch. Blocking mode ondevalready did this. - Under cooperative mode, a sink lifecycle opened before the transform chain is still not closed after a startup failure. That gap already existed and belongs to #12231 / #12391. The PR description now says so explicitly, which resolves my previous Issue 2.
1.4 Error handling and logging
The original exception stays primary and cleanup failures are suppressed, so the failure is logged once by the worker. Previous Issue 3 (an Error such as NoClassDefFoundError from t.open() skips stage cleanup, TransformFlowLifeCycle.java:144) is unchanged. dev behaves the same way, and this stays optional and non-blocking.
2 Quality
2.1 Code standards
No change since the last review. The comments at :146-147 and :371 explain why cleanup lives here and why the guard exists.
2.2 Tests and stability
Tests are unchanged and still match the code:
TransformFlowLifeCycleCloseTest(first, middle and last failure, map and flat-map, cleanup failures, ROUTE close-once): Stable, with pure mocks and no timing. The reflection-basederrorHandlerinjection nit is still non-blocking.SeaTunnelTaskStateTest.transformOpenFailureStopsTaskBeforeReady: Stable.LocalModeIT.transformStartupFailureFailsEmptyAndNonemptyJobs(0/1 rows xALL/OFF): Risk is low. It uses an isolated local cluster, and the only timing dependency is a generous 10s cleanup await.
2.3 Docs
error-handling.md and incompatible-changes.md both have EN/ZH parity and match the code.
3 Architecture
No change. Cleanup stays in TransformFlowLifeCycle, which owns the child transforms and the error handler. With the CAS guard it also stays correct once #12391 makes cooperative teardown call task.close().
4 Issue table
| # | Location | Summary | Severity | Status |
|---|---|---|---|---|
| 1 | docs/{en,zh}/introduction/concepts/incompatible-changes.md |
Upgrade note for the startup-failure behavior change | Medium | Fixed in c0d5b166 |
| 2 | SeaTunnelTask.java:406, TaskExecutionService.java:1449-1456 |
Cooperative startup failure leaves the earlier-opened sink unclosed (pre-existing, #12391) | Medium | Addressed: tracked in the PR description, out of scope |
| 3 | TransformFlowLifeCycle.java:144 |
Error from open() skips stage cleanup (same as dev) |
Low | Open, optional, non-blocking |
5 Merge recommendation
Ready to merge once CI is green.
- Non-CI blockers: none.
- CI:
Buildon this head is still running in the fork (https://github.com/goutamadwant/seatunnel/actions/runs/42581308287). All fourunit-testjobs (JDK 11/17, ubuntu/windows) have passed, and the integration-test jobs are queued or running. I will approve once it is green. - Branch: 1 commit behind
dev, with no conflicts. - Non-blocking: Issue 3 and the test reflection nit.
Thanks again, this is a careful, well-scoped fix, and the docs are clear.
|
Hi @goutamadwant, a short update now that the fork
Suggested next step: once #13203 is merged, merge the latest |
DanielLeens
left a comment
There was a problem hiding this comment.
Hi @goutamadwant, thanks for syncing dev.
Re-checked the new head a96d4ab1: the only change since my last review (c0d5b166) is a merge of the latest dev (4ee722e9). The PR's own diff is unchanged: the same 8 files with identical added and removed lines. The merge only resolved the incompatible-changes.md conflict with #13061. In both docs/en and docs/zh the Lance BIGINT entry and your Zeta transform-startup entry now sit under ## dev, and no conflict markers are left.
Previous review points
- Issue 1 (upgrade note) and Issue 2 (cooperative sink cleanup, tracked in #12391): still resolved.
- Issue 3 (
Errorfromopen()skips stage cleanup, same asdev) and the reflection nit in the test: still optional and non-blocking.
CI
- The fork
Buildrun on this head is still running: https://github.com/goutamadwant/seatunnel/actions/runs/42765840594. No job has failed yet. - Heads-up: this merge took
devat4ee722e9, one commit before #13203. That commit replaced the removedatmoz/sftp:alpine-3.7Docker image. This head still references the old tag, soconnector-file-sftp-it(JDK 11/17) will fail again, and a rerun won't fix it. The smallest next step is to merge the latestdevonce more (1 commit, #13203) and let CI run on that head.
Conclusion: Ready to merge
- Blockers (non-CI): None.
- I'll approve once
Buildis green on the head that includes #13203.
Thanks again for the careful fix!
DanielLeens
left a comment
There was a problem hiding this comment.
Re-checked the new head d152be1c, @goutamadwant: compared with the head I last reviewed (a96d4ab1), the only change is the Sync dev for current CI fixtures merge, and the PR's own net diff against dev is byte-identical (same files, same changed lines). Thanks for syncing.
Previous points: my earlier conclusion had no non-CI blocker, and the merge does not touch the PR's files, so nothing changes on the source side.
CI: the fork Build for this head has just started (no failures so far). Because the head moved, I am leaving this as a comment and will approve once that run is green.
Branch state: ahead, ahead 4 / behind 0 of dev; no conflicts reported.
Conclusion: Ready to merge
- Blockers (non-CI): none.
- Remaining gate: CI on this head.
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for the earlier sync. The CI fact cited in my previous comment has changed: Build 42979470569 has finished with failures, rather than remaining in progress. My previous source-level conclusion remains clear; this is a CI clarification, not another source review.
The failed lanes are all-connectors-part-5 (JDK 11/17) and the Python-transform integration lanes (JDK 11/17). I inspected the JDK 11 logs: PythonIT fails during setup because archive.ubuntu.com/security.ubuntu.com cannot resolve, apt cannot install python3, and the command exits 127. TestPythonTransformIT similarly fails in container preparation before its test methods run. This does not establish a regression in transform startup propagation.
The proposed prepared-image fix #13249 is still open; latest dev has not incorporated it. A sync alone therefore does not resolve this dependency. Please rerun the affected lanes once the runner/container DNS path is healthy, or rerun after that infrastructure fix lands. There is no reason to add unrelated Python dependencies to this transform-lifecycle PR. If the rerun still fails, retain the package-install output so we can separate setup failure from a real startup assertion.
Build and failing jobs. The branch's upstream drift is recorded separately; CI and effective maintainer approval remain the merge gates. No local tests were run.
Purpose of this pull request
Yes, I am contributing this fix to SeaTunnel.
Fixes #13132.
Stop Zeta task startup at the first transform initialization exception and propagate the original failure. Reject records after failed initialization, close transform-stage resources through their existing lifecycle owner, and preserve the startup failure when cleanup also throws. Guard failed-startup cleanup against a later worker close.
Cooperative task-wide cleanup of sink resources opened before a transform startup failure remains outside this PR and is tracked in #12231 / #12391.
Does this PR introduce any user-facing change?
Yes. Current
devlogs a transformopen()failure and continues opening the chain. This patch fails startup instead, including jobs with no input rows.LOGandROUTErow-error handling cannot recover an initialization failure. English and Chinese docs describe this behavior.Successful startup, transform interfaces and configuration remain unchanged.
How was this patch tested?
open()returned without throwing.verify: 95 tests passed, with no failures, errors or skips. Coverage includes first/middle/last failure, map/flat-map wrappers, task startup state, partial resource cleanup, cleanup failures, repeated close, ROUTE handler close delegation and healthy controls.LocalModeIT.transformStartupFailureFailsEmptyAndNonemptyJobs: four parameterized cases passed with 0/1 input rows and cooperativeALL/ blockingOFFmodes. Each case runs a failing job followed by a healthy job, eight jobs total. Assertions check job status, original failure text, later transforms staying unopened, zero output after failure and transform cleanup.git diff --checkpassed.Focused Maven selection:
./mvnw -Pci \ -pl seatunnel-engine/seatunnel-engine-server,seatunnel-engine/seatunnel-engine-client -am \ '-Dtest=*FlowLifeCycle*Test,SeaTunnelTaskStateTest,ErrorHandling*Test,ErrorHandler*Test' \ -Dsurefire.failIfNoSpecifiedTests=false verifyThe local test JVM used the existing Byte Buddy agent to work around Mockito self-attachment restrictions. No dependency or build configuration was changed. Full repository tests, the distributed/Docker matrix and Maven Failsafe were not run. Full-job tests use LOG wrappers. ROUTE cleanup uses a real handler with a mocked writer, without an external error sink.
Check list
New License Guide
incompatible-changes.mdto describe the incompatibility caused by this PR.