Repository navigation
[Fix][Zeta] Do not block cancellation on the pipeline retry backoff - #13493
zhangshenghang wants to merge 3 commits into
Conversation
A failed pipeline sleeps for job.retry.interval.seconds inside prepareRestorePipeline(), which runs under the SubPlan monitor. cancelPipeline() is synchronized on the same object, so a cancel issued during the backoff blocked for the whole remaining interval; because the job's needRestore flag was already cleared before that block, the woken restore path still allocated slots and deployed another attempt of the cancelled job. Wait for the backoff with Object.wait() so the monitor is released and cancelPipeline() can run, notify the waiter from cancelPipeline(), and check the cancel/stop/checkpoint-error revocation after the wait so the authorized restore is abandoned instead of redeploying a zombie attempt. The configured delay and retry budget are unchanged for retries that are not cancelled.
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for contributing to Apache SeaTunnel! I reviewed the complete current diff and followed its entry points and failure paths. The items below need attention before merging; I hope the concrete paths make the next step straightforward.
What problem does this PR solve?
User pain: Cancelling a failed pipeline during its retry backoff can wait the entire interval and still deploy another attempt.
Approach: Replace monitor-held sleep with bounded Object.wait, notify on cancellation and recheck revocation before allocating/deploying.
In one sentence/example: A cancel during a 60-second retry pause should stop promptly instead of opening another sink writer after the pause.
1. Code changes
1.1 Core logic
Complete runtime path:
writer failure -> vertex completion callback -> SubPlan.updatePipelineState(FAILED)
-> synchronized stateProcess -> checkNeedRestore -> prepareRestorePipeline under restoreLock
-> reset to CREATED -> awaitRestoreBackoff [679-705], Object.wait releases SubPlan monitor
concurrent job cancellation -> neverNeedRestore -> synchronized cancelPipeline [502-514]
-> markCancelRequested -> notifyAll -> checkpoint cancel -> CANCELING
waiter reacquires monitor -> isRestoreRevoked [715-716]
-> skip release/preApply/restore; cancellation owns terminal transition
uncancelled deadline -> releasePipelineResource -> preApplyResources -> restorePipeline
Key findings and correctness:
- The changed path is retry/recovery, not a healthy pipeline or initial submission. The old monitor-held Thread.sleep really excluded cancelPipeline; wait releases that same monitor.
- The loop uses monotonic time, rechecks predicates after wakeups and polls non-notifying revocation at 200ms. It still consumes an executor thread during backoff; it is not a nonblocking scheduler redesign.
- The post-wait check skips resource allocation when cancellation was observed. This is a targeted backoff fix, not a universal atomic fence for all later allocation/cancellation races.
- The test observes CREATED/restore count and writer construction, but its short-interval control measures remaining time from a later observation; Issue 1 is independent of source correctness. Interrupted wait restores interrupt status and returns; interruption alone does not set a revocation predicate.
Before:
Thread.sleep(pipelineRestoreIntervalSeconds * 1000);
After (key path excerpt):
awaitRestoreBackoff();
// wait releases SubPlan monitor
// cancelPipeline: markCancelRequested(); notifyAll();
if (isRestoreRevoked()) {
if (isRunning) { cancelPipeline(); }
return;
}
1.2 Compatibility
Fully compatible at API/configuration/protocol/checkpoint-format level. Existing retry settings keep their values; only cancellation responsiveness in the retry path changes. Healthy execution and source/sink SPI are unchanged.
1.3 Performance and side effects
The retry now wakes at most five times per second per backing-off pipeline instead of one long sleep, with notifyAll on cancel. There is no per-record cost or new pool. The executor thread and restoreLock remain occupied for the interval; monitor release allows cancellation progress. Logs occur on revocation rather than each poll. No checkpoint payload or sink commit/idempotence changes.
1.4 Errors, logging, and findings
Issue 1: Measure retry delay from its actual start, not a late observation
- Location:
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/CancelDuringPipelineRetryBackoffIT.java:220. - Description and risk: The control polls for CREATED during a three-second backoff, then starts its own timer and requires at least two more seconds before another writer opens. CREATED identifies a window, not its beginning: if the test thread first observes it 1.5 seconds after the backoff began, a correct three-second retry arrives 1.5 seconds later and fails this assertion. A longer scheduling pause can miss the window entirely.
- Best improvement: Use an explicit test signal at backoff entry and a controlled release/clock, or capture the actual retry start/deadline and assert against that. Keep the uncancelled retry-budget control, but do not require a minimum remaining duration after an asynchronous poll.
- Responsibility and trade-off: SubPlan owns retry state, its monitor and cancellation; this is the appropriate smallest change boundary. A scheduled continuation could avoid holding an executor thread, but would require generation fencing and broader lifecycle tests. That redesign is unnecessary for this focused responsiveness fix.
- Severity: High; blocking: true.
- Previously raised by another reviewer: No, unless explicitly attributed above.
Issue 2: Document the fixture factory responsibility
- Location:
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/RetryBackoffFailingSinkFactory.java:29. - Description and risk: The new AutoService factory introduces the RetryBackoffFail plugin and is part of the regression fixture discovery path, but has no class-level explanation of its test-only always-failing behavior.
- Best improvement: Add concise class Javadoc explaining test-only registration and why it must not be packaged as a production connector.
- Responsibility and trade-off: SubPlan owns retry state, its monitor and cancellation; this is the appropriate smallest change boundary. A scheduled continuation could avoid holding an executor thread, but would require generation fencing and broader lifecycle tests. That redesign is unnecessary for this focused responsiveness fix.
- Severity: Medium; blocking: false.
- Previously raised by another reviewer: No, unless explicitly attributed above.
Community input: no independent technical finding or maintainer approval/change request was present in the collected discussion.
2. Code quality
2.1 Conventions
Reviewed all changed files for license, imports, naming, core-method and state-field comments. See the numbered findings for the required changes.
2.2 Test coverage and stability
Stability rating: High risk. High risk: explicit state polling and writer counts are useful, and the 60-second versus 30-second cancellation separation detects the original long wait. However the 3-second control can fail on a correct engine when its observer is delayed; see Issue 1. The new failing sink is test-only AutoService registration with a dedicated identifier and bounded batch configs. The shared writer counter is reset only at test start; cluster teardown is essential to stop late callbacks.
2.3 Documentation
No option or successful data-result change requires new connector docs. The SubPlan helper Javadoc describes monitor ownership and revocation. Its checkpoint-error example should be kept precise: handleCheckpointError changes pipeline state, while actual revocation here is cancelRequested, needRestore or isRunning.
3. Architecture
3.1 Change location
SubPlan owns retry state, its monitor and cancellation; this is the appropriate smallest change boundary. A scheduled continuation could avoid holding an executor thread, but would require generation fencing and broader lifecycle tests. That redesign is unnecessary for this focused responsiveness fix.
3.2 Maintainability
Keep the behavior, lifecycle ownership, and failure contract together. SubPlan owns retry state, its monitor and cancellation; this is the appropriate smallest change boundary. A scheduled continuation could avoid holding an executor thread, but would require generation fencing and broader lifecycle tests. That redesign is unnecessary for this focused responsiveness fix.
3.3 Extensibility
Prefer the existing component boundary and tests over unrelated shared abstractions.
3.4 Upgrade impact
Fully compatible at API/configuration/protocol/checkpoint-format level. Existing retry settings keep their values; only cancellation responsiveness in the retry path changes. Healthy execution and source/sink SPI are unchanged.
4. Findings summary
Completeness check: All changed files and affected entry/failure paths were reviewed; configuration/serialization compatibility, test failure capability and stability, documentation/examples, change ownership, and current CI/conflict/review gates are covered above. No unreviewed source scope is claimed complete.
| # | Finding | Location | Severity |
|---|---|---|---|
| 1 | Measure retry delay from its actual start, not a late observation | seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/CancelDuringPipelineRetryBackoffIT.java:220 |
High |
| 2 | Document the fixture factory responsibility | seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/RetryBackoffFailingSinkFactory.java:29 |
Medium |
5. Merge recommendation
Merge after fixes
Blocking items: Issues 1. Current-head CI and write-capable maintainer review remain independent requirements.
Non-blocking suggestions: Issue 2: Document the fixture factory responsibility
Overall: the approach addresses a real path, but the listed blockers must be closed. Daniel has READ permission, so this COMMENT cannot dismiss historical requested changes or satisfy a write-capable maintainer approval gate.
CI and repository state: Signal pull request update: SUCCESS; Build: QUEUED; Build: queued. GitHub reports BLOCKED / REVIEW_REQUIRED.
Verification: Reviewed all changed files and the referenced call sites at fef376d6b87e258049b285500804c034b48520a2 against merge base 39c74ce48b0fb5e0318326b8d57a42c7380c40c8. git diff --check passed. I did not build, run tests, or execute SeaTunnel locally.
Review time: 2026-11-27T03:49:31.821806-05:00
Local evidence: git fetch obtained head fef376d6b87e258049b285500804c034b48520a2; git merge-base returned 39c74ce48b0fb5e0318326b8d57a42c7380c40c8; git diff --stat reports 7 files changed, 662 insertions(+), 1 deletion(-). git show and source searches were used for the entry points above. No local build, unit test, E2E, Docker run or service startup was executed.
Review finding on PR apache#13493 (Issue 1, blocking): the uncancelled-retry control started its timer when the polling loop first observed pipeline status CREATED, not when the retry backoff actually began. The measured delay was therefore only the remaining part of the interval, so a correct engine could fail the "waited at least 2s" assertion when the observation was late, and a late observation could shrink the interval enough that the cancel assertion passed without proving the cancellation interrupted the wait. Fix: - RetryBackoffFailingSinkWriter now records the nanoTime of its first failed write, the earliest instant at which the engine can possibly start backing off, and exposes it together with a reset so a second job is anchored to its own failure. - The cancellable job asserts that the terminal CANCELED state arrives within half the retry interval of that write failure, and that the cancel request itself is issued while the backoff is still running. The deadline no longer depends on when the status poll saw CREATED. - The control asserts that the second attempt is not deployed before the configured interval has elapsed since its own failure, with an explicit upper deadline, instead of requiring a minimum remaining duration after an asynchronous poll. - Both anchors are asserted to postdate their job submission, so a stale fixture timestamp cannot make either assertion vacuous. Verification: - ./mvnw -o -q -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base spotless:apply - ./mvnw -o -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base -DskipTests -Dspotless.check.skip=true -Dcheckstyle.skip=true test-compile - ./mvnw -o -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base -Dtest=CancelDuringPipelineRetryBackoffIT -DfailIfNoTests=false test passes: CANCELED 216 ms after the cancel request / 296 ms after the write failure; control retry 3126 ms after its failure for a 3s interval. - Negative check: with SubPlan#prepareRestorePipeline temporarily restored to the old monitor-held Thread.sleep, the same test fails at the new assertion with "reached CANCELED 60255 ms after the write failure that started the backoff and 60168 ms after the cancel request".
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for improving the timing anchor. I reread the full current diff and cancellation/retry call chain. Measuring from the first failed write closes the earlier remaining-duration arithmetic problem, but the same Issue 1 still has a transient-state polling gap in the control; I have narrowed the existing finding rather than introduced a new number.
What problem does this PR solve?
User pain: cancelling a failed pipeline during retry backoff can wait for the entire configured interval and permit another deployment.
Approach: replace monitor-held sleep with bounded Object.wait, wake on cancel and check revocation before resource acquisition, plus cancellation and uncancelled-control coverage.
In one sentence: cancellation should interrupt a retry delay while an authorized retry still honors its interval.
1. Code changes
1.1 Core logic
Complete runtime path:
Failed task -> SubPlan.stateProcess FAILED/CANCELED (seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/SubPlan.java:956)
-> retry budget check -> reset and record attempt -> awaitRestoreBackoff
-> wait releases SubPlan monitor but retains restore serialization
-> cancel thread marks cancellation / needRestore=false and notifies monitor
-> timed poll or notification rechecks revocation
-> revoked: cancel pipeline and skip resource/deployment path
-> authorized timeout: release prior slots -> preApplyResources -> restorePipeline
Test -> first failed-write timestamp -> CREATED observation -> cancel
Control -> three-second CREATED window -> observe next writer and FAILED retry budget
Key findings and correctness:
- All seven changed files and the failure/cancellation/reset/resource paths were reread at the latest head.
- The production wait uses monotonic time, handles spurious wakeups with a remaining-duration loop and caps revocation polling at 200ms. Normal cancel notifies the same monitor; post-wait revocation is checked before allocating another attempt.
- The timestamp addition fixes the previous minimum-remaining-delay calculation: it no longer starts the lower-bound timer at a late CREATED observation.
- Existing Issue 1 is narrowed but not closed: the control still must catch the transient three-second CREATED state, and its observed next-writer time is not the actual writer-open time. These are the same asynchronous-window problem from the prior review, not a newly numbered source defect.
- The always-failing batch fixture makes retry budget exhaustion observable. No new persistence or serialization contract is introduced.
Before:
Thread.sleep(pipelineRestoreIntervalSeconds * 1000);After:
while (!isRestoreRevoked()) {
// remaining duration uses System.nanoTime(); wait releases this monitor
wait(Math.max(1L, Math.min(200L, remainingMillis)));
}
// stateProcess rechecks revocation before allocating/restoring.1.2 Compatibility
Fully compatible in API, configuration names/defaults, task protocol and checkpoint encoding. Cancellation latency intentionally improves; uncancelled retries retain the same configured interval and budget.
1.3 Performance and side effects
The retry executor thread remains occupied, but Object.wait releases the SubPlan monitor and checks revocation at most every 200ms. This removes long monitor contention without a per-row lock or growing buffer. Cancellation avoids another slot acquisition/deployment; interruption and the prior reset/callback lifecycle were traced.
1.4 Errors, logging, and findings
Issue 1: Remove the required transient-window observation from the retry control
- Location:
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/CancelDuringPipelineRetryBackoffIT.java:282. - Description and risk: This is the narrowed continuation of prior Issue 1. Anchoring the start at first failed write fixes the old remaining-duration arithmetic, but the control still calls awaitPipelineInRetryBackoff and requires restoreNum=1 plus CREATED during a three-second interval. A correct run can leave that state before a delayed test thread observes it and the control then times out for 180 seconds. In addition, retryDelayMillis is sampled after a poll sees OPENED grow; a delayed observer can report at least three seconds even if an incorrect engine opened the retry immediately. The new anchor alone therefore does not remove the asynchronous window or establish the claimed minimum actual retry delay.
- Best improvement: Record the actual second writer-open timestamp in the fixture and assert against its own first failure. Make the uncancelled control wait for durable attempt/final-state evidence rather than require observing CREATED. For cancellation, use an explicit backoff-entry handshake with a controlled release so scheduling delay cannot consume the success budget before the action is issued.
- Responsibility and trade-off: SubPlan owns retry state, its monitor and cancellation. Keep the correction here; a broader scheduled-continuation redesign is unnecessary. Fixture observation must record the events being asserted.
- Severity: High; blocking: true.
- Previously raised by another reviewer: No, unless explicitly attributed above.
Issue 2: Document the fixture factory responsibility
- Location:
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/RetryBackoffFailingSinkFactory.java:29. - Description and risk: Existing Issue 2 is unchanged: the AutoService factory is the discovery entry point for a test-only always-failing sink but has no class-level explanation.
- Best improvement: Add concise Javadoc describing test-only registration and intended failing behavior.
- Responsibility and trade-off: SubPlan owns retry state, its monitor and cancellation. Keep the correction here; a broader scheduled-continuation redesign is unnecessary. Fixture observation must record the events being asserted.
- Severity: Medium; blocking: false.
- Previously raised by another reviewer: No, unless explicitly attributed above.
Community input: no independent technical finding or maintainer approval/change request was present in the collected discussion.
2. Code quality
2.1 Conventions
Reviewed all changed files for license, imports, naming, core-method and state-field comments. See the numbered findings for the required changes.
2.2 Test coverage and stability
Stability rating: High risk. The first-failure clock is reset between jobs and is in the same JVM as the task writers. The monotonic anchor improves timing evidence. However, seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/CancelDuringPipelineRetryBackoffIT.java:265-299 still polls a transient three-second control state and timestamps only a later observer; Issue 1 remains a high-risk stability/oracle gap. The main cancellation still uses its existing client API, and no local timeout/reproduction test is claimed. Rating: High risk for the required transient-window control, not a claim that current CI reproduced a failure.
2.3 Documentation
No new user option. Existing EN/ZH retry interval descriptions remain applicable; the test factory comment is the retained optional documentation request.
3. Architecture
3.1 Change location
SubPlan owns retry state, its monitor and cancellation. Keep the correction here; a broader scheduled-continuation redesign is unnecessary. Fixture observation must record the events being asserted.
3.2 Maintainability
Keep the behavior, lifecycle ownership, and failure contract together. SubPlan owns retry state, its monitor and cancellation. Keep the correction here; a broader scheduled-continuation redesign is unnecessary. Fixture observation must record the events being asserted.
3.3 Extensibility
Prefer the existing component boundary and tests over unrelated shared abstractions.
3.4 Upgrade impact
Fully compatible in API, configuration names/defaults, task protocol and checkpoint encoding. Cancellation latency intentionally improves; uncancelled retries retain the same configured interval and budget.
4. Findings summary
Completeness check: All changed files and affected entry/failure paths were reviewed; configuration/serialization compatibility, test failure capability and stability, documentation/examples, change ownership, and current CI/conflict/review gates are covered above. No unreviewed source scope is claimed complete.
| # | Finding | Location | Severity |
|---|---|---|---|
| 1 | Remove the required transient-window observation from the retry control | seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/CancelDuringPipelineRetryBackoffIT.java:282 |
High |
| 2 | Document the fixture factory responsibility | seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/retrybackoff/RetryBackoffFailingSinkFactory.java:29 |
Medium |
5. Merge recommendation
Merge after fixes
Blocking items: Issues 1. Current-head CI and write-capable maintainer review remain independent requirements.
Non-blocking suggestions: Issue 2: Document the fixture factory responsibility
Overall: the approach addresses a real path, but the listed blockers must be closed. Daniel has READ permission, so this COMMENT cannot dismiss historical requested changes or satisfy a write-capable maintainer approval gate.
CI and repository state: Signal pull request update: SUCCESS; Build: QUEUED; Build: pending. GitHub reports BLOCKED / REVIEW_REQUIRED.
Verification: Reviewed all changed files and the referenced call sites at cd13511073e1aa72e340ca69b2a02fcb98cd2316 against merge base ee0fb0d72f67edbcd6caf08360fd354fa68e002f. git diff --check passed. I did not build, run tests, or execute SeaTunnel locally.
Review time: 2026-11-27T05:38:55.439590-05:00
Local evidence: git fetch obtained head cd13511073e1aa72e340ca69b2a02fcb98cd2316; git merge-base returned ee0fb0d72f67edbcd6caf08360fd354fa68e002f; git diff --stat reports 7 files changed, 780 insertions(+), 1 deletion(-). git show and source searches were used for the entry points above. No local build, unit test, E2E, Docker run or service startup was executed.
Yes, I am contributing this change to Apache SeaTunnel.
Purpose of this pull request
Fixes #13488.
Cancelling a Zeta job while one of its pipelines sleeps in the retry backoff (
job.retry.interval.seconds) currently blocks for the whole remaining interval and then still allocates slots and deploys one more attempt of the job the user just cancelled.Root cause.
SubPlan#prepareRestorePipeline()runs inside thesynchronizedSubPlan#stateProcess()and used a plainThread.sleep(interval)while it held the SubPlan monitor.SubPlan#cancelPipeline()issynchronizedon the same object, so the cancel request blocked on the monitor for the whole remaining interval.PhysicalPlan#stateProcess()setsneverNeedRestore()before callingcancelPipeline(), so when the sleep finally ended the already-authorized restore path ranreleasePipelineResource+preApplyResources+restorePipeline()for a job whoseneedRestorewas already false, deployed a zombie attempt, and only then did the blocked cancel tear it down.What this PR changes
Object#wait()instead ofThread.sleep()whilestateProcess()holds the SubPlan monitor. Waiting releases the monitor, socancelPipeline()runs immediately and can move the pipeline toCANCELING;cancelPipeline()callsnotifyAll()after recording the request so the waiter does not have to wait for the pause to expire.RESTORE_BACKOFF_POLL_MILLIS), so a revocation that does not callcancelPipeline()(force stop viastopJob(), or a checkpoint error that clearsneedRestore) is noticed within a fraction of a second.needRestoreflag was cleared, a cancel was requested, or the pipeline state process was already stopped, the restore is abandoned (cancelPipeline()is invoked when the pipeline is still live) instead of releasing/applying resources and redeploying. No slots are requested and no tasks are deployed for the cancelled job.This is complementary to #12510: that PR re-checks
needRestorearoundpreApplyResourcesand owns the resource-allocation failure path. This PR owns the backoff wake-up, which #12510's patch explicitly leaves unchanged.E2E coverage added
CancelDuringPipelineRetryBackoffIT(in-JVM master/worker cluster, new deterministic always-failing test sink,job.retry.times = 3,job.retry.interval.seconds = 60):CREATED);CANCELEDwell before the 60 s interval could expire (deadline 30 s);CANCELEDto be stable, the restore counter to stay at 1, and no second sink writer ever to be created — i.e. no zombie attempt was deployed;FAILED).Reproduction on the unmodified base
39c74ce48b(fix temporarily reverted, same command):With this change the same test passes in 17.3 s (including the control scenario).
Validation
./mvnw -B -T 1 verify -DskipUT=true -DfailIfNoTests=false -Dlicense.skipAddThirdParty=true -Dskip.spotless=true --no-snapshot-updates -pl :connector-seatunnel-e2e-base,:connector-console-seatunnel-e2e -am -Pci -Dit.test=CancelDuringPipelineRetryBackoffIT— pass (17.3 s).SplitClusterFaultToleranceIT#testStreamJobCancelResolvesWhenWorkerCrashesBeforeCancelAck— pass (11.5 s).seatunnel-engine-serverunit testsStateTransitionCleanupTestandSubPlanDeploymentTest— 22 tests pass../mvnw spotless:applyapplied.