SEZ9 commented on issue #13351:
URL: https://github.com/apache/seatunnel/issues/13351#issuecomment-7152613408
@zhangshenghang I went looking for this one because #13433 (my PR) claimed
to fix it and the review showed it did not. I ended up with a reproduction of
the symptom you describe, but through a different mechanism. Posting the
evidence before anyone writes more code, because the fix depends on a semantic
choice that I think is yours to make.
## The reported mechanism is not reachable
Traced against `dev` at `a76348f1f9`:
- `preApplyResourcesForAll` iterates `physicalPlan.getPipelineList()`, so
the whole-job pre-apply installs **every** pipeline's task group keys before
`jobMaster.run()`.
- That path also covers a job restored after a master switch:
`restoreJobFromMasterActiveSwitch` puts the job into `pendingJobQueue`, so it
reaches `pendingJobSchedule()` → `jobMaster.preApplyResources()` like any other.
- `PhysicalVertex.taskGroupLocation` is `final` and nothing removes entries.
So the restore-time `putAll` at `JobMaster.java:601` only ever **replaces
values of keys that already exist**. A `HashMap` does not insert or resize
there, so it cannot drop an entry or expose a half-resized table. @DanielLeens
reached the same conclusion independently in the review of #13433.
## What does reproduce the symptom
The symptom is real and it needs **no concurrency at all** — it is
deterministic and single-threaded, which is part of why I think this is the
actual cause.
`SubPlan.java:880-884`, the `FAILED`/`CANCELED` branch:
```java
if (checkNeedRestore(state) && prepareRestorePipeline()) {
jobMaster.releasePipelineResource(this); // 1. this pipeline's slots
go back
jobMaster.preApplyResources(this); // 2. returns boolean --
discarded
restorePipeline(); // 3. runs either way
}
```
1. `releasePipelineResource(subPlan)` releases the pipeline's slots and
removes its `ownedSlotProfilesIMap` entry.
2. `preApplyResources(subPlan)` fails when there is no free capacity. Its
failure branch (`JobMaster.java:610-659`) releases the slots **it** acquired
and returns `false` — and it never touches
`physicalPlan.preApplyResourceFutures`. The shared map therefore still holds
the *previous* futures, whose slots step 1 just released.
3. The `boolean` is discarded, so `restorePipeline()` proceeds. It performs
no resource re-verification.
4. `ResourceUtils.applyResourceForPipeline` then reads those stale futures.
Its only completeness check is `futures.size() != slotProfiles.size()`
(`ResourceUtils.java:69`). Stale futures join to **non-null** `SlotProfile`s,
so the sizes match, no `NoEnoughResourceException` is thrown, and
`setOwnedSlotProfiles` (`ResourceUtils.java:67`) writes the released slots back
into `ownedSlotProfilesIMap` as if the pipeline owned them.
### Measured
I wrote a throwaway probe on top of the
`JobMasterMasterFailoverResourceTest` fixture (fixed-slot, `slot-num = 5`):
whole-job pre-apply, record the owned profiles, then `releasePipelineResource`
→ occupy every free slot with another job → `preApplyResources(subPlan)` → read
through `applyResourceForPipeline`.
```
[probe] futures still resolvable after the failed re-apply: 3
[probe] of those, profiles identical to the released ones: 3
[probe] applyResourceForPipeline threw NoEnoughResource: false
[probe] it handed out 3 slot profiles
[probe] of which already released before the restore: 3
[probe] ownedSlotProfilesIMap after the read: 3 entries
```
Every slot handed to the restoring pipeline was one that had already been
released. Identical output on two consecutive runs. The probe is not a PR — it
exists to answer this question, and I'm happy to clean it up into a regression
test once the intended behaviour is settled.
## Relationship to the neighbouring issues
- **#13344** looks like the other half of what this issue describes. "A slot
acquired but neither consumed nor released" matches its mechanism directly:
slots held only in `preApplyResourceFutures`, never persisted to
`ownedSlotProfilesIMap`, with no release path when the job is cancelled. I
don't think that part is this issue.
- **#13348** (restore retry budget) is where the answer below probably
belongs, since a failed re-apply has to consume something.
- **#13433** should be read as hardening only. I've already changed its
`Closes #13351` to a plain reference and rewritten its Javadoc, since the
mechanism it stated was the unreachable one. What it does still fix is a
genuine structural race I found while re-checking: `historyExecutionAddress`
(`JobMaster.java:182`) is a plain `HashSet` that every restoring pipeline
inserts into from its own thread.
## The question for you
What should a restoring pipeline do when the re-apply fails?
1. **Fail the pipeline** — check the `boolean` and route to the failure path
instead of `restorePipeline()`. Simplest, but turns a transient shortage into a
pipeline failure, which is the "transient failure amplified into a permanent
one" pattern that keeps coming up in reviews.
2. **Consume a restore attempt and retry** — treat it as a failed restore
and go through the retry budget (#13348). Probably the right behaviour, but it
needs that budget to exist in a defined form.
3. **Harden the reader** — have `applyResourceForPipeline` verify the
profiles are still active rather than only counting them, so a stale slot
becomes an explicit failure instead of a silent reuse. Narrower and defensive;
worth doing regardless of 1 or 2, because today the reader cannot distinguish
"pre-applied" from "pre-applied and since released".
My own preference is 3 first, because it converts a silent wrong answer into
a clear error without changing restore policy, and then 2 once the retry budget
is settled. But the failure semantics are a design decision in your area, so
I'd rather you picked.
Also worth noting separately:
`JobMasterMasterFailoverResourceTest.testRestoreRejectsSlotReassignedWithinSameJob`
fails on my machine on unmodified `dev` with
`SeaTunnelEngineRetryableException: Can not get coordinator service from an
active master node.` — it calls `server.getCoordinatorService()` before this
member has become the active master. My probe hit the same thing until I added
a retry. That is a local-flakiness fix I can send separately if you'd like.
--
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]