zhangshenghang opened a new pull request, #13493:
URL: https://github.com/apache/seatunnel/pull/13493

   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 the 
`synchronized` `SubPlan#stateProcess()` and used a plain 
`Thread.sleep(interval)` while it held the SubPlan monitor. 
`SubPlan#cancelPipeline()` is `synchronized` on the same object, so the cancel 
request blocked on the monitor for the whole remaining interval. 
`PhysicalPlan#stateProcess()` sets `neverNeedRestore()` *before* calling 
`cancelPipeline()`, so when the sleep finally ended the already-authorized 
restore path ran `releasePipelineResource` + `preApplyResources` + 
`restorePipeline()` for a job whose `needRestore` was already false, deployed a 
zombie attempt, and only then did the blocked cancel tear it down.
   
   ### What this PR changes
   
   - The backoff is now waited out with `Object#wait()` instead of 
`Thread.sleep()` while `stateProcess()` holds the SubPlan monitor. Waiting 
releases the monitor, so `cancelPipeline()` runs immediately and can move the 
pipeline to `CANCELING`; `cancelPipeline()` calls `notifyAll()` after recording 
the request so the waiter does not have to wait for the pause to expire.
   - The wait is bounded (`RESTORE_BACKOFF_POLL_MILLIS`), so a revocation that 
does not call `cancelPipeline()` (force stop via `stopJob()`, or a checkpoint 
error that clears `needRestore`) is noticed within a fraction of a second.
   - After the wait, the restore is re-authorized: if the job's `needRestore` 
flag 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.
   - The delay and retry budget for retries that are *not* cancelled are 
unchanged.
   
   This is complementary to #12510: that PR re-checks `needRestore` around 
`preApplyResources` and 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`):
   
   1. waits until attempt 1 has failed and the pipeline sits in the backoff 
(restore counter 1, pipeline status `CREATED`);
   2. cancels the job and requires it to reach `CANCELED` well before the 60 s 
interval could expire (deadline 30 s);
   3. requires the terminal state and pipeline `CANCELED` to 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;
   4. control: submits the same failing pipeline with a 3 s interval and one 
retry *without* cancelling it, and requires the next attempt to still wait for 
the interval (>= 2 s observed) and to consume the configured retry budget (job 
ends `FAILED`).
   
   Reproduction on the unmodified base `39c74ce48b` (fix temporarily reverted, 
same command):
   
   ```
   Cancelling a job during its 60s restore backoff must not wait for the 
backoff to expire, but it took 60153 ms
   Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 69.114 s
   ```
   
   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).
   - Adjacent cancellation contract 
`SplitClusterFaultToleranceIT#testStreamJobCancelResolvesWhenWorkerCrashesBeforeCancelAck`
 — pass (11.5 s).
   - `seatunnel-engine-server` unit tests `StateTransitionCleanupTest` and 
`SubPlanDeploymentTest` — 22 tests pass.
   - `./mvnw spotless:apply` applied.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to