zhangshenghang opened a new issue, #13348:
URL: https://github.com/apache/seatunnel/issues/13348

   ### Search before asking
   
   - [x] I searched existing issues and PRs before filing this report.
   - [x] This report is based on source analysis at commit 
[`5e0e9c8e3f`](https://github.com/apache/seatunnel/commit/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff);
 line numbers may drift on `dev`.
   - [x] Related existing work (different aspects): #12509 / PR #12510 (stop 
deployment when `preApplyResources` fails), #12985 (starvation-safe admission), 
#12947 (partial allocation rollback), #12202 (scheduler wedge).
   
   ### What happened
   
   When a pipeline fails and is restored, Zeta first releases **all** slots of 
that pipeline (including slots on healthy workers that are still running fine), 
then re-applies for the whole pipeline. If re-application loses a race for the 
fixed pool, the resulting `NoEnoughResourceException` is treated as a pipeline 
failure and consumes one unit of the job's failure-retry budget 
(`job.retry.times`, default 3, every `job.retry.interval.seconds`, default 3s). 
A transient allocation race can therefore permanently fail a pipeline.
   
   This is distinct from #12509 / PR #12510: stopping deployment after a failed 
`preApplyResources()` avoids deploying with stale slots, but the failed 
allocation still increments `pipelineRestoreNum`. Even with #12510 merged, 
three unlucky allocation races are enough to exhaust the pipeline's restore 
budget.
   
   ### Code path
   
   1. The `FAILED`/`CANCELED` branch releases the pipeline's whole slot map, 
ignores the boolean result of `preApplyResources(this)`, and continues to 
`restorePipeline()`:
      
[`SubPlan.java#L878-L885`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/SubPlan.java#L878-L885)
   
   2. `prepareRestorePipeline()` increments `pipelineRestoreNum` and sleeps 
before the next attempt:
      
[`SubPlan.java#L609-L639`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/SubPlan.java#L609-L639)
   
   3. `canRestorePipeline()` gates on `pipelineRestoreNum < 
pipelineMaxRestoreNum`; the default is `job.retry.times = 3`:
      
[`SubPlan.java#L417-L419`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/SubPlan.java#L417-L419)
      
[`EnvCommonOptions.java#L48-L60`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-api/src/main/java/org/apache/seatunnel/api/options/EnvCommonOptions.java#L48-L60)
   
   4. If the new allocation is still incomplete when the pipeline enters 
`SCHEDULED`, `ResourceUtils.applyResourceForPipeline()` throws 
`NoEnoughResourceException`, which becomes a pipeline failure and burns another 
restore:
      
[`ResourceUtils.java#L42-L73`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/ResourceUtils.java#L42-L73)
   
   5. `ResourceUtils` already contains a TODO acknowledging that there is no 
wait/backoff for resources:
      
[`ResourceUtils.java#L50`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/ResourceUtils.java#L50)
   
   ### Why fixed slots make it worse
   
   - `releasePipelineResource()` releases the entire pipeline, so healthy task 
groups lose their slots too. Another job's pending-job pre-apply, or another 
pipeline of the same job restoring concurrently, can take those slots before 
this pipeline re-applies.
   - Fixed-slot capacity is static; there is no spare pool to absorb the window 
between release and re-acquire.
   - Multiple pipelines in one job each have their own restore loop and budget, 
so they compete with each other and can consume each other's chances.
   - The existing `SplitClusterFaultToleranceIT` contains a disabled probe for 
this exact contention and documents that "a pipeline that races several 
siblings for a momentarily-shrunken slot pool can burn its entire retry budget 
on pure allocation timing and permanently fail" (around lines 1875-1935).
   
   ### Impact
   
   - A transient resource race (or a child pipeline finishing/failing at the 
wrong moment) can permanently fail a pipeline that would have recovered seconds 
later.
   - Healthy slots are exposed to other jobs during every restore, increasing 
contention for the whole cluster.
   - Under `WAIT`, the job-level scheduler may be waiting while the 
pipeline-level restore loop is already burning its own budget; the two retry 
mechanisms are not coordinated.
   
   ### Expected behavior
   
   - Resource allocation shortfall during restore is a *wait* condition, not a 
task failure. It must not consume `job.retry.times`.
   - A restoring pipeline should keep the slots it still owns on healthy 
workers (sticky allocation) and only request slots for task groups that 
actually need a new slot.
   - If a full-pipeline reallocation is unavoidable, acquire the new set before 
releasing the old one where possible, or reserve the pipeline's slots so other 
jobs cannot take them during the window.
   
   ### Suggested fix direction
   
   1. Separate `pipelineRestoreNum` (task failures) from a resource-wait 
counter; allocation shortfall should return to a waiting state with backoff and 
not increment the failure budget.
   2. Make `releasePipelineResource()` release only slots whose task groups are 
actually being recreated, or introduce a per-job reservation that prevents the 
released slots from being assigned to other jobs until the restore completes.
   3. Check the return value of `preApplyResources(this)` and wait/retry 
resource acquisition without entering the deploy path (complements #12509 / 
#12510).
   4. Add an integration test with 4 pipelines and an 8-slot worker (the shape 
of the disabled probe) asserting that transient post-kill contention never 
permanently fails a pipeline.
   
   ### SeaTunnel version
   
   `dev` (analyzed at `5e0e9c8e3f`).
   
   ### Zeta or Flink or Spark Version
   
   Zeta.
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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