DanielLeens opened a new issue, #13482: URL: https://github.com/apache/seatunnel/issues/13482
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22bug%22) and found no similar issues. ### What happened In the SeaTunnel Zeta engine (`dev` at `39c74ce48b0`), whenever a submitted job reaches a terminal state **before** its `SubPlan` pipelines ever start running — specifically: 1. A job waiting in `pendingJobQueue` under `ScheduleStrategy.WAIT` is canceled via `cancelJob(jobId)`, or 2. A job fails immediately with `NoEnoughResourceException` under `ScheduleStrategy.REJECT` because `preApplyResources()` cannot obtain enough slots its per-pipeline checkpoint ID counter entries initialized during `JobMaster.init()` are **never removed** from `checkpointCounterStore` (backed by Hazelcast IMap `engine_checkpoint-id-map` / `Constant.IMAP_CHECKPOINT_ID`). Because `engine_checkpoint-id-map` has no TTL or eviction policy, every canceled `PENDING` job and every `REJECT`-failed job leaks one entry per pipeline permanently in cluster memory (and in IMap external storage when persistence is enabled). ### Root Cause Analysis 1. **Counter entries are eagerly created during `JobMaster.init()`, before scheduling:** - `CoordinatorService.submitJob()` calls `jobMaster.init(...)` -> `initCheckPointManager(...)` -> `new CheckpointManager(...)`. - In `CheckpointManager` (`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/checkpoint/CheckpointManager.java:161-167`), every pipeline constructs a `StateStoreCheckpointIDCounter` and immediately invokes `idCounter.start()`, calling `checkpointCounterStore.initializeIfAbsent(key, INITIAL_CHECKPOINT_ID)`. 2. **Counter removal is only wired to `SubPlan` termination:** - `StateStoreCheckpointIDCounter.shutdown(PipelineStatus)` (which calls `checkpointCounterStore.remove(key)` when `pipelineStatus.isEndState()`) is only invoked via `CheckpointManager.listenPipeline(int pipelineId, PipelineStatus pipelineStatus)`. - `CheckpointManager.listenPipeline(...)` is **only** called from `SubPlan.notifyCheckpointManagerPipelineEnd(PipelineStatus)` (`SubPlan.java:375-383`), which only executes if the `SubPlan` state machine actually ran and reached a terminal state. 3. **Pre-execution termination paths bypass `SubPlan` completely and `JobMaster.cleanJob()` does not clean up counters:** - **PENDING cancel**: `CoordinatorService.cancelJob(jobId)` removes the job from `pendingJobQueue` and calls `runningJobMaster.cancelJob()` -> `PhysicalPlan.cancelJob()`, which directly sets `JobStatus.CANCELED` and calls `completeJobEndFuture(...)` -> `JobMaster.cleanJob()`. - **REJECT insufficient resources**: `CoordinatorService` (around `NoEnoughResourceException`, lines 536–544) directly sets `JobStatus.FAILED` and calls `completeJobEndFuture(...)` -> `JobMaster.cleanJob()`. - `JobMaster.cleanJob()` (`JobMaster.java:1041-1046`) calls `checkpointManager.clearCheckpointIfNeed(physicalPlan.getJobStatus())` (which only deletes external checkpoint storage) and `scheduleRemoveJobStateMaps()` (which cleans up `runningJobStateIMap`, `runningJobStateTimestampsIMap`, `ownedSlotProfilesIMap`, `runningJobInfoIMap`, `metricsImap`), but **never** removes the job's entries from `checkpointCounterStore` / `IMAP_CHECKPOINT_ID`. ### Expected Behavior When any job reaches a terminal state (`FINISHED`, `CANCELED`, `FAILED`, `SAVEPOINT_DONE`), all of its per-pipeline checkpoint ID counter entries in `checkpointCounterStore` (`engine_checkpoint-id-map`) should be cleanly removed — regardless of whether the job's `SubPlan`s ever started running. ### How to Reproduce #### Scenario A: Canceling a `PENDING` job under `ScheduleStrategy.WAIT` 1. Start a single-node embedded Zeta cluster with fixed slots (`dynamic-slot: false`, `slot-num: 5`) and `schedule-strategy: WAIT`. 2. Submit a normal batch job (`normalJobId`) as a control and wait until it reaches `FINISHED`. - Observe `checkpointCounterStore` / `IMap<String, Long>` (`Constant.IMAP_CHECKPOINT_ID`) for key `convertLongIntToBase64(normalJobId, 1)` -> **not present** (`false`, properly cleaned up by `SubPlan`). 3. Submit a streaming job (`holderJobId`) consuming 2 of the 5 slots and wait until it is `RUNNING`. 4. Submit a 5-slot batch job (`pendingJobId`, e.g., `batch_slot_not_enough.conf`) so it enters `JobStatus.PENDING` in `pendingJobQueue`. - Observe `IMAP_CHECKPOINT_ID` contains key `convertLongIntToBase64(pendingJobId, 1)` with value `1L`. 5. Call `client.cancelJob(pendingJobId)` and wait until `coordinator.getJobStatus(pendingJobId) == JobStatus.CANCELED`. Also cancel `holderJobId` until `CANCELED`. 6. Inspect `IMAP_CHECKPOINT_ID` / `checkpointCounterStore`: - `holderJobId` key is removed (`false`). - **`pendingJobId` key is still present with value `1L` (`mapSize == 1`), leaked permanently.** #### Scenario B: Job rejected under `ScheduleStrategy.REJECT` 1. Start a single-node embedded Zeta cluster with fixed slots (`dynamic-slot: false`, `slot-num: 2`) and `schedule-strategy: REJECT`. 2. Submit a 5-slot batch job (`rejectedJobId`, e.g., `batch_slot_not_enough.conf`). 3. Wait for the job to terminate (`JobStatus.FAILED` with `NoEnoughResourceException`). 4. Inspect `IMAP_CHECKPOINT_ID` / `checkpointCounterStore`: - **`rejectedJobId` key `convertLongIntToBase64(rejectedJobId, 1)` is still present with value `1L` (`mapSize == 1`), leaked permanently.** ### Suggested Fix Direction - In `CheckpointManager`, provide a job-level terminal cleanup method (or extend `clearCheckpointIfNeed(JobStatus)` / add `shutdownAllCheckpointIdCounters(JobStatus)`) that iterates all coordinators in `coordinatorMap` when `jobStatus.isEndState()` and invokes `checkpointIdCounter.shutdown(...)` (mapping terminal `JobStatus` to a terminal `PipelineStatus`) so every pipeline counter key is idempotently removed during `JobMaster.cleanJob()`. - Also verify partial-initialization failure handling in `JobMaster.init()` / `CheckpointManager` constructor so partially initialized counters are cleaned up if `init()` throws. - Add regression unit/E2E tests verifying zero leftover keys in `checkpointCounterStore` (`IMAP_CHECKPOINT_ID`) after both `PENDING` cancellation and `REJECT` resource-exhaustion failure. ### Call for Contributors This is a well-scoped, self-contained Zeta engine bug with clear reproduction steps and low blast radius. **Community contributors are very welcome to pick this up and submit a PR!** Feel free to comment below if you'd like to claim it or discuss the cleanup design. ### SeaTunnel Version dev (`39c74ce48b0`) ### Are you willing to submit a 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]
