zhangshenghang opened a new issue, #13344: URL: https://github.com/apache/seatunnel/issues/13344
### 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 duplicates of this specific path): #9589, #11437, #12119, #12126. ### What happened In fixed-slot mode (`dynamic-slot: false`), `CoordinatorService.pendingJobSchedule()` pre-applies **all** slots for a queued job before `JobMaster.run()`. The resulting `SlotProfile`s are stored only in `PhysicalPlan.preApplyResourceFutures` (an in-memory map). They are **not** persisted to `ownedSlotProfilesIMap`. If the job is cancelled while it is still `PENDING`, or if the pending scheduler epoch is invalidated (master step-down / scheduler generation change), no code path releases those slots. Fixed-slot capacity is not elastic and there is no worker-side lease, so the capacity is lost until the worker restarts. The same problem also applies to slots that *are* already persisted: after a master failover, a restored job may reuse slots through `ownedSlotProfilesIMap`, but if the job is rejected or cancelled while still `PENDING`, pipeline cleanup never runs and those persisted slots are not released either. ### Failure path (verified in code) 1. `CoordinatorService.pendingJobSchedule()` calls `jobMaster.preApplyResources()` before `jobMaster.run()`: [`CoordinatorService.java#L437-L440`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java#L437-L440) 2. `JobMaster.preApplyResources()` only stores the futures in `physicalPlan`; it does not write slot ownership anywhere: [`JobMaster.java#L586-L605`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/master/JobMaster.java#L586-L605) 3. The only place that persists slot ownership is `ResourceUtils.applyResourceForPipeline()` -> `setOwnedSlotProfiles()`. That method runs only when a pipeline reaches `SCHEDULED` and is about to deploy: [`ResourceUtils.java#L67`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/ResourceUtils.java#L67) 4. Cancelling a pending job removes it from the queue and calls `jobMaster.cancelJob()`: [`CoordinatorService.java#L1589-L1610`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java#L1589-L1610) 5. `PhysicalPlan.cancelJob()` for a job whose status is `<= PENDING` directly sets `CANCELED`, completes `jobEndFuture`, and never touches slots: [`PhysicalPlan.java#L198-L215`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/PhysicalPlan.java#L198-L215) 6. `JobMaster.cleanJob()` only clears checkpoints/history/state maps; it does not release slots: [`JobMaster.java#L1041-L1046`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/master/JobMaster.java#L1041-L1046) 7. `releasePipelineResource()` requires an `ownedSlotProfilesIMap` entry and returns immediately when there is none: [`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) 8. The stale-scheduler-epoch branch interrupts the `JobMaster` and removes it from the pending queue without releasing anything: [`CoordinatorService.java#L447-L455`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java#L447-L455) 9. For a restored job under `REJECT`, `completeFailJob()` marks the job `FAILED` but does not run pipeline cleanup or release retained slots: [`CoordinatorService.java#L528-L543`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/CoordinatorService.java#L528-L543) ### Impact - Permanent loss of fixed-slot capacity. `getUnassignedSlots()` never returns the leaked slots, so later jobs under `WAIT` wait forever and later jobs under `REJECT` fail. - A master step-down can poison the new master's fixed pool even though the new master did nothing wrong. - The leaked slots are not visible in `ownedSlotProfilesIMap`, so a later master cannot reuse or release them. - This is specific to fixed slots; dynamic slots mask it because new slots can always be minted. ### Reproduction - Cluster: 1 worker, `dynamic-slot: false`, `slot-num: 4`, `job-schedule-strategy: WAIT`. - Submit a job that needs 4 slots and arrange the cancel/reject to happen after `preApplyResources()` succeeds but before `jobMaster.run()` reaches `SCHEDULED` (for example by blocking the coordinator executor or by injecting a delayed cancel in a test). - Observe: - the worker still reports all 4 slots as assigned; - `ResourceManager#getUnassignedSlots()` returns 0; - a second 1-slot job never runs under `WAIT` (or fails under `REJECT`). A focused unit test can mock the `ResourceManager`, run `pendingJobSchedule()`, cancel the `JobMaster` inside the executor hand-off window, and assert that every acquired `SlotProfile` was released. ### Expected behavior - Cancelling, stopping, rejecting, or invalidating a pending job must release every slot acquired for that job, including: - pre-applied slots that were never persisted, and - persisted/reused slots in `ownedSlotProfilesIMap` for pipelines that were never redeployed. - Either persist pre-applied allocations as soon as they are granted (with an explicit job/pipeline owner and a `PENDING`/`PRE_APPLIED` state), or add a job-scoped cleanup path that releases both `preApplyResourceFutures` and `ownedSlotProfilesIMap` entries. ### Suggested fix direction 1. Introduce a persistent "pending allocations" record, or write the pre-applied profile map to `ownedSlotProfilesIMap` immediately with an `isDeployed=false` marker. 2. On every terminal path (`cancelJob`, `stopJob`, `completeFailJob`, stale scheduler epoch, `preApplyResources` failure), call a job-scoped `releaseAllOwnedAndPreAppliedSlots(jobId)` before completing the job. 3. Make the release idempotent and tolerate profiles that were already released/reassigned (the sequence check in `DefaultSlotService#releaseSlot` already provides this). 4. Add a regression test that asserts the worker's unassigned slot count returns to `slot-num` after each terminal path. ### 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]
