zhangshenghang opened a new pull request, #13651:
URL: https://github.com/apache/seatunnel/pull/13651

   Yes, I am contributing to Apache SeaTunnel.
   
   Fixes #13648.
   
   ### Problem
   
   When the active Zeta master is lost while a checkpoint is in flight (barrier 
dispatched, not every task acknowledged), the surviving master publishes the 
next checkpoint with the same id that the dead master had already allocated for 
the interrupted checkpoint.
   
   Checkpoint ids come from the per-pipeline counter in the shared counter 
state store, and `StateStoreCheckpointIDCounter#getAndIncrement()` persists the 
increment at trigger time. On failover, `CheckpointManager` rebuilds each 
coordinator from the latest **completed** checkpoint and unconditionally did:
   
   ```java
   long checkpointId = pipelineState.getCheckpointId();
   idCounter.setCount(checkpointId + 1);   // rewinds the counter when a 
checkpoint was in flight
   ```
   
   If checkpoint `N` completed and `N+1` was in flight, the counter already 
held `N+2`, but the new master rewound it to `N+1`, so the next checkpoint 
reused `N+1`. `TaskAcknowledgeOperation` carries no trigger epoch — 
acknowledgements are matched to the pending checkpoint by id only — so a task 
still inside `snapshotState()` for the pre-failover barrier can acknowledge the 
re-used id. The published checkpoint can then mix task state from before and 
after the failover: a torn checkpoint that can later be restored.
   
   ### Fix
   
   The counter is now only ever moved forward:
   
   ```java
   long nextCheckpointId = Math.max(idCounter.get(), checkpointId + 1);
   idCounter.setCount(nextCheckpointId);
   ```
   
   This preserves checkpoint-ID monotonicity for both master failover and 
savepoint/checkpoint restore. `CheckpointManagerTest` gets a focused regression 
case for the counter value.
   
   ### E2E coverage added
   
   `MasterFailoverCheckpointInFlightIT`: two dedicated master-only members plus 
one worker, a streaming `FakeSource -> test-only sink` pipeline, 
`dynamic-slot=false`, `slot-num=4`, `checkpoint.interval=1000`, 
`checkpoint.timeout=300000`.
   
   1. The first checkpoint completes normally, so the pipeline has a real 
checkpoint sequence.
   2. The test arms a gate and the sink writer parks inside `snapshotState()`, 
so the second checkpoint's barrier reaches the tasks and is acknowledged by 
nobody.
   3. The active master (resolved from the job master, not assumed) is shut 
down. The surviving master and the worker form the cluster and take the job 
over.
   4. The interrupted checkpoint must never appear in checkpoint storage.
   5. The writer is released and acknowledges its old barrier; the next 
checkpoint published by the new master must carry an id strictly greater than 
the in-flight one.
   6. The job stays `RUNNING` and cancels cleanly to `CANCELED`.
   
   ### Pre-fix reproduction (negative control)
   
   On pristine `origin/dev` `e7f08dc52e` with the unmodified engine, the new 
E2E fails in 15.6s:
   
   ```
   AssertionFailedError: The checkpoint id must not be re-issued across a 
master failover:
   checkpoint 2 was already allocated and partially acknowledged before the 
failover,
   but the next stored checkpoint is 2 ==> expected: <true> but was: <false>
   ```
   
   With the one-line fix and the same test, the next stored checkpoint is `3`.
   
   ### Verification
   
   - `MasterFailoverCheckpointInFlightIT`: four consecutive green runs after 
the fix (15.758s, 15.793s, 15.793s, 15.785s), the last run with the module's 
spotless check enabled.
   - `CheckpointManagerTest`: 10/10 green, including the new 
`testMasterFailoverRestoreMustNotReuseInFlightCheckpointId`.
   - `spotless:check` exit 0 for both touched modules.
   - No connector, transform, SQL, format or source/sink business logic is 
changed; the test sink is a simple `FakeSource -> discarding sink` fixture 
whose only behaviour is parking `snapshotState`.
   
   ### Why existing coverage missed it
   
   `CheckpointManagerTest` only restores from a completed checkpoint when the 
counter is absent, so the rewind never had a visible effect. 
`CheckpointCoordinatorFailoverIT` switches the master between checkpoints and 
only asserts that ids grow after the new master is already running; it never 
kills the master with a checkpoint in flight.
   


-- 
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