Repository navigation
[Fix][Transform-V2] Forward lifecycle callbacks to per-table transforms - #13180
goutamadwant wants to merge 1 commit into
Conversation
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks a lot for this careful fix, @goutamadwant. The lifecycle gap in the multi-table wrapper is real, and the PR closes it with a clear ownership model, solid partial-failure handling and a native Zeta test. I reviewed the current head c085127c6d0d721211c654a7f5c7d7865e7a7537.
What Problem Does This PR Solve?
AbstractMultiCatalogTransform builds and owns one transform per table in transformMap, but it did not override open() / close(). On dev, the wrapper therefore inherited the no-op defaults from SeaTunnelTransform, so its per-table children never got startup or cleanup callbacks from the engine. PythonMultiCatalogTransform was the only wrapper with a hand-written close(). This PR forwards both callbacks to the owned children (Fixes #13131).
1 Code Change Review
1.1 Core logic
- New
TransformLifecycle(seatunnel-transforms-v2/.../common/TransformLifecycle.java:33-180): identity-deduplicated child list,open()runs once, stops at the first failure, records it, closes all children and rethrows it.close()runs once, tries every child, keeps the first failure and adds the rest as suppressed. Plugin calls run outside the monitor (:131-145), so a Pythonclose()can still interrupt anopen()that is blocked. AbstractMultiCatalogTransform.java:172-188now overridesopen()/close()and delegates to a lazily created,transientlifecycle.orderedChildren()(:190-203) uses input-table order and then the remaining map entries. Duplicates are removed by identity in the lifecycle constructor.- Constructor and composed-rule build failures release children that were already built (
:165-168,:228-231). ChainedMapTransform/ChainedFlatMapTransformnow use the same owner, so composed children are closed once and close failures are no longer lost.SQLTransform,CalciteTransform,EmbeddingTransformandLLMTransformnow makeopen()idempotent. It reuses a resource that schema discovery already built and refuses to open afterclose().close()is idempotent and nulls the resource.
Runtime flow on Zeta after this PR:
client: wrapper ctor -> buildTransform per table (schema discovery may call child tryOpen())
-> serialized in LogicalDag (lifecycle/closed/engine fields are transient)
worker: TransformFlowLifeCycle.open() -> wrapper.open() -> TransformLifecycle.open()
-> child.open() for each owned child, in order (SQL/Calcite/LLM/Embedding: init once)
-> on failure: close all children, rethrow original failure -> task fails
worker: TransformFlowLifeCycle.close() -> wrapper.close() -> each child.close() once,
first failure kept, the rest suppressed
On the normal path, every Zeta job that uses a multi-table transform reaches this change (TransformFlowLifeCycle.open() calls t.open() on the wrapper). So this is a main-path change, not only an edge-case fix.
1.2 Compatibility
- No option, default, public signature or SPI change. All new fields are
transient, and theserialVersionUIDs stay the same, so the serialized form of the wrappers and children is unchanged. transformMapis only assigned in the constructor, so caching the child list on the firstlifecycle()call is safe.- There is one intended behavior change: a child
open()failure now fails the task at startup instead of surfacing lazily on the first row. That is the correct contract, and the PR description explains it. - The new "closed means no reopen" guard is safe for Zeta, Flink and Spark, because each runtime instance comes from deserialization. The new
LocalModeITcovers this for Zeta.
1.3 Side effects
- SQL / Calcite engines and model clients are now created eagerly in
open()instead of on the first row. The cost is the same, only earlier. PythonMultiCatalogTransform.close()now goes through the shared owner, so it also covers partial-startup cleanup.
1.4 Error handling / logging
Failure retention and suppression look correct. Two small non-blocking observations:
Issue 1
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/common/TransformLifecycle.java:89 - Problem:
open()catches onlyException. If a child throws anError, the children that already opened are not closed, andstartupFailurestays unset. ALinkageError/NoClassDefFoundErroris a realistic case for plugins with missing jars. Thefinallyblock resetsopening, so a lateropen()would retry. - Risk: Low. The task fails anyway, but resources opened by earlier children may be released only by the later
close()from the engine. - Best improvement: catch
Throwablehere (rethrowing as-is), or add anErrorbranch that also runsclose(). - Severity: Low (non-blocking)
- Raised by another reviewer: No
Issue 2
- Location:
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/nlpmodel/embedding/EmbeddingTransform.java:93-214(similarlyLLMTransform.java:80) - Problem:
open()holdssynchronized (this)while it builds the remote client and callsmodel.dimension(), which can make a network call.close()takes the same monitor (:416). A cancel that arrives during a slowopen()therefore waits until the HTTP call returns or times out. This differs a little from the guide text, which says a child that supports cancellation must allowclose()during initialization. - Risk: Low. Cancellation is delayed, but nothing leaks.
- Best improvement: none required for this PR. Optionally, add a short comment that these model transforms do not support cancellation during
open(). - Severity: Low (non-blocking)
- Raised by another reviewer: No
2 Quality
2.1 Standards
- Nit:
AbstractMultiCatalogTransform.java:57and:196use the fully qualified@lombok.SneakyThrows. The siblingTransformLifecycleimportslombok.SneakyThrows, so importing it here too would be consistent. Also, the constructor's lambda can only throw unchecked exceptions, socatch (RuntimeException failure)would remove the need for@SneakyThrowson the constructor. Non-blocking. - New class has the ASF header and class-level Javadoc. Key methods carry comments that explain the ownership and failure rules.
2.2 Tests
AbstractMultiCatalogTransformTest(+429) covers successful startup, partial failure, constructor cleanup, repeated and concurrent callbacks, identity children, composed rules and serialization. The new per-transform tests (SQL, Calcite, Embedding, LLM, Python) check reuse and once-only close.LocalModeIT.multiTableLifecycleForEmptyAndNonemptyJobs(seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/.../LocalModeIT.java) runs real Zeta jobs for Map/FlatMap × empty/non-empty × ALL/OFF thread sharing. It asserts exact open/close/map/output counts and that no resources leak. Each run uses its own cluster name and checkpoint dir, and the static observation map is cleaned up infinally.- Stability: Stable. Each run starts its own Hazelcast node, and the 60s/10s Awaitility budgets give enough headroom for a single-row batch job. It passed in
engine-v2-iton both JDK 11 and 17 in the fork run.
2.3 Docs
The EN and ZH contribute-transform-v2-guide.md sections match in content and describe the ownership rules accurately.
3 Architecture
The fix sits in the right place: the generic owner (AbstractMultiCatalogTransform) and the composed chains, with no engine changes. Per-transform changes stay inside each transform. Putting the lifecycle in one package-private class avoids copying the close-all-and-suppress loop into every wrapper.
4 Issue table
| # | Location | Severity | Blocking |
|---|---|---|---|
| 1 | TransformLifecycle.java:89 (Error not covered by startup cleanup) |
Low | No |
| 2 | EmbeddingTransform.java:93, LLMTransform.java:80 (monitor held across remote init) |
Low | No |
| nit | AbstractMultiCatalogTransform.java:57,196 (FQN @lombok.SneakyThrows) |
Nit | No |
CI status
The apache-side Build check is red. The real run is in your fork: https://github.com/goutamadwant/seatunnel/actions/runs/42435490469. Two jobs failed, and neither failure comes from this diff:
all-connectors-it-7 (11, ubuntu-latest): https://github.com/goutamadwant/seatunnel/actions/runs/42435490469/job/128660256539. It failed before Maven started. Every attempt to downloadmaven-wrapper-3.1.0.jarfromrepo.maven.apache.orgreturned404 Not Found, so the job ended withCould not find or load main class org.apache.maven.wrapper.MavenWrapperMain. This is an infrastructure problem, and the same job passed on JDK 17.doris-connector-it (11, ubuntu-latest): https://github.com/goutamadwant/seatunnel/actions/runs/42435490469/job/128660256583.DorisMultiReadITfailed withContainerLaunchException: Timed out waiting for container port to openforapache/doris:doris-all-in-one-2.1.0. The other 49 Doris tests passed, and the same job passed on JDK 17. The Doris path does not use transforms.
The jobs this change can affect are all green on JDK 11 and 17: unit-test (ubuntu and windows), engine-v2-it, transform-v2-it parts 1 and 2. Could you re-run the failed jobs, or sync the latest dev (the branch is 1 commit behind) and push to trigger CI again? I will approve once the Build check is green.
5 Merge recommendation
Ready to merge after fixes. The only blocker is CI: the two failures above are infrastructure problems and need a green re-run. There are no blocking code findings. Issues 1–2 and the nit are optional improvements.
Thanks again for the thorough work on this, especially the native Zeta coverage.
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks @goutamadwant for re-running CI. CI was previously the only remaining blocker; CI is now passing, so I am changing my conclusion to approve.
The fork run https://github.com/goutamadwant/seatunnel/actions/runs/42435490469 (attempt 2) on head c085127c is fully green: 85 jobs passed, 11 skipped, none failed. That includes all-connectors-it-7 (11, ubuntu-latest) and doris-connector-it (11, ubuntu-latest), the two jobs that failed on infrastructure last time. The apache-side Build check is green as well.
My source review on this head is unchanged: no blocking findings. Issues 1-2 (catching Error in TransformLifecycle.open(), and the monitor held during remote model init) and the @lombok.SneakyThrows nit are still optional follow-ups.
Conclusion: Approve
|
Thanks for working on this, @goutamadwant. I opened #13131 while working through the lifecycle prerequisites for STIP-44 (#13099), and I was also preparing a fix. I reproduced the To avoid overlapping work, would you prefer that I share the patch for inclusion here, or open a focused follow-up after this PR merges? Happy to coordinate, and this does not need to hold up the current PR. |
|
Thanks @JAEKWANG97 for reproducing this and for coordinating instead of pushing a competing change. For context, this is Issue 1 from my review: From the reviewer side, my suggestion is a focused follow-up PR after this one merges. The current head |
|
Thanks @JAEKWANG97. That follow-up scope and the links to #13131 / #13099 match the plan we discussed. No additional change is needed in this PR from my side; the existing technical approval stands, subject to the maintainer merge gate. |
Purpose of this pull request
I’m contributing this fix to SeaTunnel so multi-table wrappers initialize and release the per-table transforms they own.
Fixes #13131.
Engine-side failure propagation remains in #13132 / #13175. This patch contains no engine production changes.
Does this PR introduce any user-facing change?
Yes. On
dev, affected multi-table wrappers currently skip child initialization and cleanup. They now forward both callbacks, release schema-time resources and retain startup/cleanup failures without duplicate callbacks.No configuration options, dependencies or public method signatures change. All seven affected serialization UIDs remain unchanged.
How was this patch tested?
Validated locally with JDK 11:
Unit-test commands:
Native integration exercised
LocalModeIT.multiTableLifecycleForEmptyAndNonemptyJobsthrough JUnit Platform, with assertions for resource and output counts.Check list
New License Guide
incompatible-changes.mdto describe the incompatibility caused by this PR.