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

   ### Purpose of this pull request
   
   Yes, I am contributing to Apache SeaTunnel.
   
   Fixes #13352.
   
   `JobMaster.preApplyResources()` replaced the shared `workerAssignedSlots` 
map of the slot allocation strategy with a brand-new map on every job 
submission and every single-pipeline restore. The strategy instance belongs to 
the `ResourceManager`, not to a job, so that reset wiped the in-flight 
allocation counters of every other job. With `SLOT_RATIO` / `SYSTEM_LOAD`, 
concurrent submissions and pipeline restores could then re-learn the same 
assignments or fall back to the stale `WorkerProfile` counts, concentrating 
requests on a subset of workers and feeding the retry/`NoEnoughResource` path. 
The same code also dereferenced `workerAssignedSlots` without any 
initialization, so an `applyResources()` call made before the first pre-apply 
could throw a `NullPointerException`, and concurrent selections could overwrite 
each other with a stale `WorkerProfile` count.
   
   What this PR changes:
   
   - `SlotRatioStrategy` and `SystemLoadStrategy` now keep their bookkeeping in 
a `ConcurrentMap<Long, ConcurrentMap<Address, SlotAssignedProfile>>` scoped by 
job id. A job's pre-apply only drops that job's counters, so other jobs' 
in-flight state survives.
   - `JobMaster.preApplyResources()` calls 
`ResourceManager#resetSlotAllocationState(jobId)` instead of replacing the 
strategy's global map. `JobMaster.cleanJob()` uses the same call to release the 
bookkeeping of a terminal job.
   - `SlotAllocationStrategy` gained a job-aware `selectWorker` overload and 
`resetJobState`; both have defaults so existing strategy implementations keep 
working.
   - Per-worker entries are seeded with `computeIfAbsent` (no null-map NPE, no 
lost initial count) and incremented with `merge` (no lost updates under 
concurrency).
   - `ResourceRequestHandler` passes the requesting job id to the strategy.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. This is internal master-side allocation bookkeeping. Configuration 
options, defaults, and the allocation strategy semantics for a single job are 
unchanged.
   
   ### How was this patch tested?
   
   - `./mvnw -pl seatunnel-engine/seatunnel-engine-server spotless:apply`
   - `./mvnw -pl seatunnel-engine/seatunnel-engine-server 
-Dtest=SlotAllocationStrategyTest,SystemLoadCalculateTest,ResourceRequestHandlerTest,JobMasterTest
 -DfailIfNoTests=false test` (33 tests passed)
   - `./mvnw -pl seatunnel-engine/seatunnel-engine-server 
-Dtest=JobMasterTest,JobMasterMasterFailoverResourceTest,StateTransitionCleanupTest,FakeResourceManagerTest,FakeResourceManagerForRequestSlotRetryTest,FakeResourceManagerForExternalExceptionTest
 -DfailIfNoTests=false test` (30 tests passed)
   
   The new `SlotAllocationStrategyTest` covers:
   
   - selecting a worker before any pre-apply reset (the former NPE path),
   - per-job resetting not clearing another job's counters for both strategies,
   - a job's own reset starting from fresh worker profiles,
   - 32 concurrent selections for each of two jobs producing exactly 32 
recorded slots per job, and dropping one job's state leaving the other intact.
   
   The existing `SystemLoadAllocateStrategyIT` still exercises the single-job 
allocation path; the observable behavior for one job is unchanged, so no E2E 
scenario was added or modified.
   


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