zhangshenghang opened a new issue, #13345: URL: https://github.com/apache/seatunnel/issues/13345
### 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 (not duplicate of this state-filtering path): #9589, #11437, #11458, #12509. ### What happened After an active-master failover, `JobMaster.preApplyResources()` requests or reuses a slot for **every pipeline and every vertex**, without checking the vertex/pipeline execution state. For vertices that will not be (re)deployed, the newly allocated slot is never consumed by `ResourceUtils.applyResourceForPipeline()`, is never persisted to `ownedSlotProfilesIMap`, and is never released. In fixed-slot mode this permanently consumes capacity; if the pool is full, the restored job can fail resource pre-apply and stay `PENDING` forever under `WAIT` even though the vertices that actually need slots already hold them. ### Why this happens (verified in code) 1. The job-level pre-apply iterates all pipelines and all vertices: [`JobMaster.java#L673-L731`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/master/JobMaster.java#L673-L731) 2. `PhysicalPlanGenerator` includes every pipeline for a restore-mode job (`isRestoreJob() == true`), and every non-`FINISHED` pipeline for a normal job. It does **not** filter individual vertices by `ExecutionState`: [`PhysicalPlanGenerator.java#L173-L183`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/PhysicalPlanGenerator.java#L173-L183) 3. For a `RUNNING` pipeline, `restorePipelineState()` never calls `applyResourceForPipeline()`. It only calls `restoreExecutionState()` on each vertex and starts the state process: [`SubPlan.java#L689-L713`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/SubPlan.java#L689-L713) 4. `PhysicalVertex.stateProcess()` does not deploy a vertex in `FINISHED`, `FAILED`, or `CANCELED` state: [`PhysicalVertex.java#L694-L723`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/PhysicalVertex.java#L694-L723) 5. `releasePipelineResource()` requires an `ownedSlotProfilesIMap` entry. For a terminal pipeline whose entry was already removed by `subPlanDone()`, it returns early and releases nothing: [`JobMaster.java#L998-L1004`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/master/JobMaster.java#L998-L1004) 6. If the same pipeline later restores, `preApplyResources(subPlan)` does `putAll()` into `physicalPlan.getPreApplyResourceFutures()`, overwriting the failover-time future for that task group. The previous `SlotProfile` is then unreachable: [`JobMaster.java#L728-L729`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/master/JobMaster.java#L728-L729) ### Concrete scenarios - A `RUNNING` streaming pipeline contains a bounded source reader group that already `FINISHED` (or a vertex that already `FAILED`). Its old slot was released by `releaseTaskGroupResource()`, so `slotActiveCheck()` returns false; failover pre-apply allocates a new slot for it. The vertex is never redeployed and the new slot is never released. - A pipeline was in `SCHEDULED`/`DEPLOYING` when the master died. On restore, `restorePipelineState()` cancels and restarts it. The job-level pre-apply slots are overwritten by the per-pipeline restore pre-apply, so the first allocation is leaked. - A restore-mode job (`--restore`) contains a pipeline that already `FINISHED`. `PhysicalPlanGenerator` includes it, pre-apply allocates slots for all of its vertices, and `restorePipelineState()`/`subPlanDone()` never deploy them or release the allocation. ### Impact - Every failover can leak one fixed slot per non-active vertex, plus all slots of terminal pipelines in restore-mode jobs. - A restored job may fail `preApplyResources()` because it tries to allocate slots for work that does not need them. Under `WAIT` it then waits forever; under `REJECT` it fails, even though the running pipeline could resume immediately with its retained slots. - This is the residual part of #9589/#11437 that the #11458 reuse fix does not cover: reuse works for still-active slots, but there is no "skip vertices that need no slot" rule. ### Expected behavior - Pre-apply must be state-aware: - `RUNNING`/`DEPLOYING` vertices: reuse the active slot if it is still valid. - `FINISHED`/`CANCELED` vertices: request nothing; they will not be deployed. - `FAILED` vertices: let the pipeline restore path decide, rather than pre-allocating at job level. - Pipelines in a terminal state (`FINISHED`/`CANCELED`/`FAILED` with no restore) should not be pre-applied at all. - Any pre-applied `SlotProfile` that the pipeline state machine does not consume must be released explicitly. ### Suggested fix direction 1. Pass the current `ExecutionState`/`PipelineStatus` into `preApplyResourcesForSubPlan()` and skip vertices/pipelines that do not need deployment. 2. For `RUNNING` pipelines, do not run job-level pre-apply at all; only validate/reuse the persisted active slots. 3. When a pipeline is restarted, release the previous `preApplyResourceFutures` entry for that task group before replacing it (or keep a set of consumed profiles and release the rest). 4. Add an integration test: fixed-slot single worker, one finished pipeline plus one running pipeline; kill the active master; assert the job resumes and `getUnassignedSlots()` is unchanged. ### 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]
