DanielLeens opened a new issue, #13497:
URL: https://github.com/apache/seatunnel/issues/13497

   ### 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 `ee0fb0d72f6`), when a `BATCH` job is 
submitted **without** `checkpoint.interval` configured in `env`, 
`JobMaster.createJobCheckpointConfig(...)` disables periodic checkpointing 
(`jobCheckpointConfig.setCheckpointEnable(false)`). During normal execution, 
`CheckpointCoordinator.allTaskReady()` respects this flag and does not schedule 
periodic checkpoints.
   
   However, if a **Master failover** occurs while the `BATCH` job's tasks are 
already running on a surviving worker (`alreadyStarted == true`), the newly 
elected Master's `CheckpointCoordinator.restoreCoordinator(true)` **ignores 
`coordinatorConfig.isCheckpointEnable() == false`**:
   
   1. It immediately invokes `tryTriggerPendingCheckpoint(CHECKPOINT_TYPE)`, 
which also does not check `isCheckpointEnable()`, firing spurious periodic 
`CHECKPOINT_TYPE` barriers onto the batch tasks, persisting snapshots to 
`CheckpointStorage`, and starting a repeating periodic checkpoint schedule 
using the engine's default `checkpoint.interval`.
   2. Worse, `startTriggerPendingCheckpoint(...)` **still guards timeout 
scheduling with `if (coordinatorConfig.isCheckpointEnable())`**, so every 
illegally triggered periodic checkpoint runs **without any checkpoint timeout 
future** (`setCheckpointTimeOutFuture` is skipped). If any subtask stalls on 
the unexpected barrier, `pendingCounter` stays `> 0` and the pipeline's final 
`COMPLETED_POINT_TYPE` close barrier can hang indefinitely.
   
   ### Root Cause Analysis
   
   1. **Initial startup checks `isCheckpointEnable()`:**
      - `CheckpointCoordinator.allTaskReady()` 
(`seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/checkpoint/CheckpointCoordinator.java:487`):
        ```java
        if (coordinatorConfig.isCheckpointEnable()) {
            LOG.info("checkpoint is enabled, start schedule trigger pending 
checkpoint.");
            
scheduleTriggerPendingCheckpoint(coordinatorConfig.getCheckpointInterval());
        } else {
            LOG.info(
                    "checkpoint is disabled, because in batch mode and 
'checkpoint.interval' of env is missing.");
        }
        ```
   
   2. **Master failover recovery omits the `isCheckpointEnable()` check:**
      - `CheckpointCoordinator.restoreCoordinator(boolean alreadyStarted)` 
(`CheckpointCoordinator.java:726-783`, specifically lines `774-779`):
        ```java
        if (readyToCloseStartingTask.size() == 
plan.getStartingSubtasks().size()) {
            // All sources already finished before failover; complete the job 
now.
            tryTriggerPendingCheckpoint(CheckpointType.COMPLETED_POINT_TYPE);
        } else {
            tryTriggerPendingCheckpoint(CHECKPOINT_TYPE);
        }
        ```
      - When `alreadyStarted == true` and sources are still running, line `778` 
unconditionally calls `tryTriggerPendingCheckpoint(CHECKPOINT_TYPE)` even when 
`coordinatorConfig.isCheckpointEnable()` is `false`.
      - In `tryTriggerPendingCheckpoint(CheckpointType)` 
(`CheckpointCoordinator.java:805`), there is no guard against 
`checkpointType.isGeneralCheckpoint() && 
!coordinatorConfig.isCheckpointEnable()`. Because `latestTriggerTimestamp` 
starts at `0` on the restored coordinator, `currentTimestamp - 0 >= 
checkpointInterval` evaluates to `true`, immediately triggering a periodic 
checkpoint and scheduling subsequent periodic checkpoints via 
`scheduleTriggerPendingCheckpoint(coordinatorConfig.getCheckpointInterval())`.
   
   3. **Timeout guard is skipped because `isCheckpointEnable()` is `false`:**
      - In `startTriggerPendingCheckpoint(...)` 
(`CheckpointCoordinator.java:1075`):
        ```java
        if (coordinatorConfig.isCheckpointEnable()) {
            ...
            
pendingCheckpoint.setCheckpointTimeOutFuture(scheduler.schedule(...));
        }
        ```
      - Thus the spuriously triggered periodic checkpoints have no timeout 
protection at all.
   
   ### Expected Behavior
   
   After Master failover (`restoreCoordinator(true)`), a `BATCH` job with 
`coordinatorConfig.isCheckpointEnable() == false` should continue running 
**without** triggering any periodic `CHECKPOINT_TYPE` checkpoints (keeping 
stored checkpoint count at `0` and `checkpointIdCounter` unchanged), only 
performing the normal final `COMPLETED_POINT_TYPE` close when all starting 
subtasks report `readyToClose`.
   
   ### How to Reproduce
   
   1. Start a 2-node embedded Zeta cluster (`node1` as initial Master with 
`slot-num = 1`, `node2` as standby Master + Worker with `slot-num = 4`), with 
engine default `checkpoint.interval = 1500` ms and `localfile` checkpoint 
storage.
   2. Occupy `node1`'s single slot (or use a Master-only `node1` and Worker 
`node2`) so all task groups of the batch job run on `node2`.
   3. Submit a `BATCH` job **without** `checkpoint.interval` in `env` (for 
example, `FakeSource` with `row.num = 24`, `split.num = 25`, 
`split.read-interval = 500` -> `Console` sink).
   4. Wait until the job is `RUNNING` on `node2`, then wait `2500 ms` (`> 1500 
ms` engine default interval) and inspect 
`checkpointStorage.getAllCheckpoints(jobId)` and `checkpointIdCounter.get()`:
      - **Before Master failover**: `ckptCount = 0`, `idCounter = 1`, 
`jobStatus = RUNNING` (periodic checkpointing is disabled as expected).
   5. Shut down `node1` (`node1.shutdown()`) to trigger Master failover to 
`node2` while the batch tasks remain running on `node2` (`alreadyStarted == 
true`).
   6. Wait for `node2` to become active Master and restore `JobMaster`, then 
wait `3500 ms` and inspect `checkpointStorage.getAllCheckpoints(jobId)` and 
`checkpointIdCounter.get()`:
      - **Observed actual behavior**: `ckptCount = 3`, `idCounter = 4`, 
`jobStatus = RUNNING` — periodic checkpoints are illegally triggered and 
persisted every `1500 ms` without any timeout future until the batch job 
finishes.
   
   ### Suggested Fix Direction
   
   1. Guard `restoreCoordinator(boolean alreadyStarted)` 
(`CheckpointCoordinator.java:777-779`) to match `allTaskReady()`:
      ```java
      if (readyToCloseStartingTask.size() == plan.getStartingSubtasks().size()) 
{
          tryTriggerPendingCheckpoint(CheckpointType.COMPLETED_POINT_TYPE);
      } else if (coordinatorConfig.isCheckpointEnable()) {
          tryTriggerPendingCheckpoint(CHECKPOINT_TYPE);
      } else {
          LOG.info(
                  "checkpoint is disabled, because in batch mode and 
'checkpoint.interval' of env is missing.");
      }
      ```
   2. Add a defensive guard in `tryTriggerPendingCheckpoint(CheckpointType)` so 
general periodic checkpoints (`checkpointType.isGeneralCheckpoint()`) are 
rejected whenever `!coordinatorConfig.isCheckpointEnable()`.
   3. Add a unit test on `CheckpointCoordinator.restoreCoordinator(true)` with 
`isCheckpointEnable() == false` (and/or a 2-node Master failover integration 
test) asserting zero periodic checkpoints are triggered and 
`checkpointIdCounter` remains unchanged.
   
   ### Call for Contributors
   
   This is a clean, self-contained Zeta checkpoint coordinator bug with a 
deterministic reproduction and a straightforward fix. **Community contributors 
are very welcome to claim and fix this issue!** Please leave a comment below if 
you'd like to take it on.
   
   ### SeaTunnel Version
   
   dev (`ee0fb0d72f6`)
   
   ### 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]

Reply via email to