zhangshenghang opened a new pull request, #13483:
URL: https://github.com/apache/seatunnel/pull/13483
Yes, I am contributing to Apache SeaTunnel.
### Purpose of this pull request
Fixes #13482. A Zeta job that reaches a terminal state **before any of its
pipelines starts** left one permanent entry per pipeline in the checkpoint-ID
counter store (`engine_checkpoint-id-map`). This PR removes those counters
during terminal job cleanup and adds an end-to-end regression test that covers
both affected terminal paths:
1. a job cancelled while it is waiting in the pending queue under
`ScheduleStrategy.WAIT`;
2. a job failed immediately by the resource pre-check under
`ScheduleStrategy.REJECT`.
### Root cause
- `CheckpointManager` constructs one `StateStoreCheckpointIDCounter` per
pipeline and calls `start()` during `JobMaster.init()`, which inserts an entry
into the counter state store before the job is scheduled.
- The only existing removal path is
`SubPlan.notifyCheckpointManagerPipelineEnd()` ->
`CheckpointManager.listenPipeline()` ->
`StateStoreCheckpointIDCounter.shutdown()`, which requires the pipeline state
machine to have run and reached an end state.
- A cancelled `PENDING` job (`CoordinatorService.cancelJob()` ->
`PhysicalPlan.cancelJob()`) and a job rejected by `preApplyResources()` never
run a `SubPlan`. `JobMaster.cleanJob()` only called `clearCheckpointIfNeed()`
(checkpoint storage cleanup) and `scheduleRemoveJobStateMaps()`, so their
counter entries stayed in the IMap forever. The map has no TTL or eviction, and
the entries also survive restarts when IMap persistence is enabled.
### Change
`CheckpointManager.clearCheckpointIfNeed(JobStatus)` now shuts down the
counter of every pipeline when the job itself is terminal (`FINISHED`,
`SAVEPOINT_DONE`, `CANCELED`, `FAILED`), mapping the job status to the matching
terminal `PipelineStatus`. The shutdown is idempotent, so pipelines already
cleaned by the normal lifecycle are unaffected, and non-terminal job states are
ignored so a master failover keeps the counters of a running job.
Removing counters for a terminal `FAILED` job does not affect restore: a
later restore creates fresh counters and sets them from the restored checkpoint
ID, while the checkpoint files themselves are still handled by the existing
`clearCheckpointIfNeed()` rules.
### Why this boundary has real regression risk
The leak is invisible from the job status, the checkpoint storage and the
REST API: the job is `CANCELED`/`FAILED`, checkpoint files are cleaned, yet the
counter map keeps growing. It only surfaces after many short-lived jobs (or as
persisted state after a restart), and it is easy to reintroduce because the
only existing cleanup is tied to the `SubPlan` state machine that these jobs
never enter.
### Why existing coverage does not reach it
- `CheckpointManagerTest` and `StateStoreCheckpointIDCounterTest` exercise
the counter directly against a mocked store; they never create a real
`JobMaster` for a job that is rejected or cancelled before scheduling.
- `SeaTunnelSlotIT` asserts the terminal status and slot release of
undersized jobs but never inspects the checkpoint-ID map.
- The E2E suite has no coverage for terminal cleanup of jobs that never
start a pipeline.
### The new E2E test
`CheckpointIdCounterTerminalCleanupIT` starts a real embedded cluster with
two fixed slots and submits `pending_jobs_streaming.conf` (three slots
required):
- **WAIT scenario:** asserts the job is `PENDING` *and* its counter key
exists, cancels the job, waits for `CANCELED`, then asserts no key for that job
remains.
- **REJECT scenario:** asserts the job reaches `FAILED` through the resource
pre-check, then asserts no key for that job remains.
`FakeSource`/`InMemory` are simple fixtures only; no Transform, SQL,
connector or format behavior is exercised. The test fails on unmodified `dev`
with the key still present after the 60-second cleanup window and passes with
the fix.
### Does this PR introduce any user-facing change?
No. This is an internal memory/state cleanup fix; configuration,
checkpoint/savepoint formats, public APIs and SPI contracts are unchanged. No
migration is needed.
### How was this patch tested?
```bash
# Before the fix: both scenarios fail with the counter key still present
JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home \
./mvnw -o -pl
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base \
-DskipUT=true -DskipIT=false -Dskip.spotless=true \
-Dit.test=CheckpointIdCounterTerminalCleanupIT -DfailIfNoTests=false verify
# After the fix: 2/2 pass
# Related engine unit tests: 22/22 pass
JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home \
./mvnw -o -pl seatunnel-engine/seatunnel-engine-server \
-Dskip.spotless=true -DskipIT=true \
-Dtest=CheckpointManagerTest,StateStoreCheckpointIDCounterTest,JobMasterTest
test
# Savepoint restore regression guard also passes together with the new test
JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home \
./mvnw -o -pl
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base \
-DskipUT=true -DskipIT=false -Dskip.spotless=true \
-Dit.test=CheckpointIdCounterTerminalCleanupIT,SavepointClusterRestartRestoreIT
\
-DfailIfNoTests=false verify
# Formatting
./mvnw -o -q -pl
seatunnel-engine/seatunnel-engine-server,seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base
spotless:check
```
--
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]