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

   ### Purpose of this PR
   
   Fixes #13472.
   
   A savepoint restore keeps the source job id, so the restored run writes its 
periodic checkpoints into the same `<checkpoint-namespace>/<job-id>/` directory 
that holds the savepoint it was started from. When that restored run later 
reaches `CANCELED` (or `FINISHED`), the automatic cleanup called 
`CheckpointStorage#deleteCheckpoint(String jobId)`, which removes the whole job 
directory — including the savepoint. The job itself looked healthy (the cancel 
was clean and the restored run had been checkpointing normally), so the 
operator only noticed on the next restore, when the state was gone.
   
   `docs/en/engines/zeta/state-storage-and-recovery.md` documents a savepoint 
as operator-managed state that is "kept until manually deleted", and "can be 
deleted only if you are certain you will never restore that job from it". The 
cleanup contradicted that.
   
   ### Fix
   
   The automatic cleanup is now savepoint-aware:
   
   - `CheckpointService#deleteCheckpointDataKeepingSavepoints` lists the job's 
stored checkpoints, decodes the `CheckpointType` (it only lives inside the 
serialized `CompletedCheckpoint`; `PipelineState` carries no type), keeps 
`SAVEPOINT_TYPE` entries and deletes only the remaining periodic entries per 
pipeline.
   - If no savepoint exists, the previous behaviour is preserved and the job 
directory is removed as before.
   - If an entry cannot be classified (storage listing or deserialization 
failure), nothing is deleted: leaving periodic data behind is harmless, 
destroying a savepoint is not.
   - Both cleanup sites use it: `CheckpointManager#clearCheckpointIfNeed` 
(normal terminal cleanup) and 
`CoordinatorService#cleanupTerminalZombieCheckpointIfNecessary` 
(terminal-zombie cleanup after a master switch).
   
   Trade-off: cancelling a job that has a savepoint now reads the job's stored 
checkpoint entries once to classify them, instead of deleting the directory 
blindly. That is one extra listing/read per terminal job, and only until a type 
field becomes part of the checkpoint storage metadata (#11961).
   
   ### Tests
   
   - New E2E `SavepointSurvivesRestoredJobCancelIT` (in-process Zeta cluster, 
one pipeline): periodic checkpoint -> stop with savepoint -> restore (same job 
id) -> the restored run checkpoints again -> cancel -> assert the savepoint 
still exists, and then restore it a second time to prove the stored state is 
intact. On `dev` this test fails with `Savepoints left for job <id>: []`; with 
the fix it passes.
   - New unit `CheckpointStorageCleanupTest` covers the classification itself: 
savepoint kept + periodic deleted, no-savepoint still deletes everything, and 
undecodable entries keep all data.
   - `SavePointTest` (engine-server) and the existing savepoint E2E are run for 
regression.
   


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