Skip to content

[Bug] [Zeta] Checkpoint ID counter entries permanently leak in checkpointCounterStore (engine_checkpoint-id-map) when jobs terminate before pipelines start (PENDING cancel / REJECT) #13482

In review

Description

@DanielLeens

Search before asking

  • I had searched in the issues 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 SubPlans 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

Activity

  1. hutiefang76 commented on Nov 26, 2026

    @hutiefang76
    Collaborator

    Yes, I'd like to contribute to Apache SeaTunnel on #13482. Before editing, could you confirm these three points?

    1. Should this PR cover terminal cleanup for PENDING cancellation and REJECT, including partial checkpoint-manager initialization failure, or should partial initialization be a separate follow-up?
    2. Should the changes stay in CheckpointManager/JobMaster cleanup and the existing engine tests, preserving the state-store SPI, checkpoint/savepoint formats, and recovery behavior? [Improve][Zeta] Exclude engine_checkpoint-id-map from IMap persistence #13031 changes persistence of the map; this scope would remove the abandoned counters themselves.
    3. Alongside Spotless, verify and the affected unit tests, would embedded WAIT/PENDING-cancel and REJECT regressions with normal-finish and non-terminal controls meet acceptance, or is another E2E validation required?

    I have not run the reproductions yet and will wait for confirmation before changing code.

  2. zhangshenghang commented on Nov 26, 2026

    @zhangshenghang
    Member

    I reproduced both paths on dev and opened #13483 with a fix plus E2E coverage: the terminal job cleanup now shuts down every pipeline's checkpoint-ID counter, including pipelines that never started. The new CheckpointIdCounterTerminalCleanupIT fails on unmodified dev for both PENDING-cancel and REJECT, and passes with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions