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

   ### 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): #12985 
(admission/starvation), #12947 (partial allocation rollback), #13344 
(pre-applied slot cleanup).
   
   ### What happened
   
   The master chooses a target worker from each worker's last reported 
`WorkerProfile` snapshot. There is no reservation or lease for in-flight 
requests. A job submission creates one `ResourceRequestHandler` per task group, 
and all handlers fire concurrently against the same snapshot. Multiple requests 
can therefore select the same worker and the same logical capacity; the worker 
accepts some and returns `null` for the rest. The loser handlers retry 
immediately (three attempts, no delay), and if the snapshot has not caught up 
they can keep losing. Under `job-schedule-strategy: REJECT` (the default), this 
transient condition fails the whole job even though the cluster has enough free 
fixed slots.
   
   This is not about a missing cache refresh: `singleResourceRequestToMember()` 
does call `resourceManager.heartbeat(...)` for both success and `null` 
responses. The gap is that selection and allocation are not atomic and there is 
no reservation between them.
   
   ### Code path
   
   - Worker heartbeat cadence is 5s:
     
[`DefaultSlotService.java#L59`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/service/slot/DefaultSlotService.java#L59)
     
[`DefaultSlotService.java#L113-L155`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/service/slot/DefaultSlotService.java#L113-L155)
   
   - Worker selection is a pure read of `registerWorker`; it does not reserve 
anything:
     
[`ResourceRequestHandler.java#L278-L309`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/ResourceRequestHandler.java#L278-L309)
   
   - One handler is created per task group; each handler has its own retry loop:
     
[`ResourceUtils.java#L99-L112`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/ResourceUtils.java#L99-L112)
     
[`ResourceRequestHandler.java#L107-L173`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/ResourceRequestHandler.java#L107-L173)
   
   - Retry count is hard-coded to 3 and there is no sleep/backoff/jitter:
     
[`ResourceRequestHandler.java#L67`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/ResourceRequestHandler.java#L67)
   
   - Every response and heartbeat replaces the cached `WorkerProfile` without a 
version/timestamp, so an older response or heartbeat that completes late can 
overwrite a newer view:
     
[`AbstractResourceManager.java#L324-L334`](https://github.com/apache/seatunnel/blob/5e0e9c8e3f5c8b892df4392ca7567a06ea7f3dff/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/resourcemanager/AbstractResourceManager.java#L324-L334)
   
   ### Concrete scenario
   
   - One worker, `dynamic-slot: false`, `slot-num: 4`, `job-schedule-strategy: 
REJECT`.
   - Submit a job with 4 task groups (for example 2 readers + enumerator + 
committer).
   - All four handlers read the same snapshot showing 4 unassigned slots and 
may all choose the same worker.
   - The worker assigns the first slot, returns a fresh profile; successes 
update the master, but several handlers may already be in flight. The losers 
get `null`, retry immediately, and may still see a stale profile or lose again.
   - Any handler that exhausts its three attempts produces a 
`NoEnoughResourceException`; `preApplyResources()` then releases the successful 
slots and the job is rejected, even though the four slots were available.
   
   ### Impact
   
   - Spurious job failure under the default `REJECT` strategy.
   - Under `WAIT`, repeated partial allocation/release churn every 3s, 
transiently stealing slots from other jobs.
   - Worse with larger slot counts and higher parallelism, because more 
requests are in flight against the same snapshot.
   - Fixed slots make the failure permanent for that scheduling attempt; 
dynamic slots mask it by minting new slots.
   
   ### Expected behavior
   
   - The master should reserve a selected slot for the duration of the request 
so concurrent handlers cannot select it again, or allocation should happen 
atomically on the worker/partition that owns the resource decision.
   - Worker profiles used for placement should be versioned (for example a 
monotonically increasing profile epoch), so a late response/heartbeat cannot 
regress the cached view.
   - Retries should use a short backoff/jitter and should re-read the latest 
profile; a failure should report which workers were tried and why each rejected.
   
   ### Suggested fix direction
   
   1. Add a master-side reservation map (`Address + slotID -> reserved until`) 
consulted by `preCheckWorkerResource()`, cleared on success/failure/timeout.
   2. Add a profile version/epoch to `WorkerProfile` and ignore updates older 
than the cached version.
   3. Batch slot requests per worker (one request for N slots) so the worker 
can choose N distinct slots atomically.
   4. Add backoff/jitter between retries; make the retry count configurable.
   5. Add a concurrency test: N parallel task-group requests against one 
fixed-slot worker, assert no spurious `NoEnoughResourceException` when N <= 
slot-num.
   
   ### 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