zhangshenghang opened a new pull request, #13540:
URL: https://github.com/apache/seatunnel/pull/13540
Yes. I am contributing this change to Apache SeaTunnel.
### Purpose of this change
Fix a Zeta engine resource leak: cancelling a job that a new active master
restored into the pending queue after a failover only removed the coordinator
bookkeeping, leaving the job's worker tasks running and its fixed slots
assigned forever. The change also adds the E2E regression guard that exposed it.
Closes #13536.
### Problem
With `dynamic-slot = false`, `slot-num = 3`, `job-schedule-strategy = WAIT`
and a 2-master + 1-worker cluster:
1. A streaming job owning all three fixed slots is `RUNNING`.
2. The active master is shut down. The standby takes over, recreates the
`JobMaster` (`CoordinatorService#restoreJobFromMasterActiveSwitch`) and
re-enters the job into the pending queue as `PENDING`. The worker still runs
the task groups deployed by the previous master and still owns their slots;
that is intentional, `JobMaster#getReusableSlot` reuses them on the next
dispatch.
3. Cancelling that job while it is `PENDING` on the new master.
`PhysicalPlan#cancelJob()` treats every `PENDING` job as "never started" and
moves it straight to `CANCELED` without cancelling any pipeline or releasing
slots. `CoordinatorService#cancelJob()` also removes the pending entry before
calling `JobMaster#cancelJob()`, so the later task-state callbacks cannot find
the `JobMaster` and cannot release anything either.
Result: the job is `CANCELED`, but `ResourceManager` keeps reporting the
cancelled job as the owner of all three slots and the worker tasks keep
running. The pending scheduler then retries forever (`obtained: 0 slots`), so a
savepoint restore parked behind the job can never be dispatched and the whole
fixed pool is permanently poisoned.
### Changes
- `PhysicalPlan#cancelJob()` and `#stopJob()` now detect a pending job whose
pipelines have already left `CREATED` (the failover-restored case) and, before
completing it as `CANCELED`:
- mark every pipeline as cancel-requested,
- force-stop its already-deployed task groups (sends the cancel operation
to the worker),
- release the persisted slot ownership through
`JobMaster#releasePipelineResource`.
- A plain pending job (no pipeline ever left `CREATED`) keeps the previous
direct-to-`CANCELED` fast path, so the normal pending-cancel semantics and cost
are unchanged.
- New `PendingRestoreMasterFailoverIT`: a 2-master + 1-worker split cluster
where a savepoint restore is parked behind a job occupying the whole fixed
pool, the active master fails over, the restored job is cancelled while
`PENDING`, and the queued restore must then reach `RUNNING` on the freed slots,
continue the savepoint checkpoint chain and leave the savepoint selectable.
### Why this needs an E2E test
The lost release only exists in the combination "restored as pending after a
master switch" + "still owns deployed task groups", which unit tests with
mocked coordinator state do not model. The assertions are on the real worker's
reported slot ownership (`WorkerProfile#getAssignedSlots`) and on the real
scheduler finally dispatching the queued restore, so a regression shows up as a
timeout instead of a silent leak.
### Verification
Failure on current `dev` (`ee0fb0d72f`), with the fix reverted:
```
DIAG after occupier cancel: occupierStatus=CANCELED, restoreStatus=PENDING,
slices={<cancelled job>=[0, 1, 2]}
Job pending-restore-master-failover (<job>) ... expected: <RUNNING> but was:
<PENDING> within 3 minutes
```
With the fix, five consecutive runs pass (`~48 s` each):
```
./mvnw -o -pl
seatunnel-engine/seatunnel-engine-server,seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base
\
-DskipUT=true -DskipIT=false -Dit.test=PendingRestoreMasterFailoverIT
-DfailIfNoTests=false verify
# Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
```
Formatting and style checks:
```
./mvnw -o -pl
seatunnel-engine/seatunnel-engine-server,seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base
spotless:apply
./mvnw -o -pl seatunnel-ci-tools -Dtest=ImportClassCheckTest
-DfailIfNoTests=false test
```
### Compatibility
No public API, REST API, configuration option, wire format or default value
changes. Only the cancellation/force-stop path of a job that is pending *and*
already has deployed task groups changes; plain pending jobs, running jobs,
savepoints and checkpoints keep their current behavior.
--
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]