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

   ### Contribution acknowledgement
   
   Yes — I am contributing this change to **Apache SeaTunnel**, and I confirm 
it follows the project's contribution conventions (English PR 
title/description, one focused change, formatting and E2E validated locally). 
This is a test-only change: no production code, configuration default, REST/API 
or data format is modified.
   
   ### What this PR does
   
   Adds `PipelineRestoreCheckpointWindowIT`, an E2E regression guard for the 
**checkpoint scheduling window of a mid-run pipeline restore** in the Zeta 
engine.
   
   The fixture is a single in-JVM Zeta node with four fixed slots and one 
STREAMING `FakeSource -> RestoreWindowTest` pipeline (`checkpoint.interval = 
2000`, `checkpoint.timeout = 60000`, `job.retry.times = 3`). The test-only sink 
is stateful: its writer state is a tiny row counter. After two completed 
checkpoints the test arms exactly one row failure; the pipeline goes FAILED, 
restores, and the **restored** writer parks inside the engine's 
`SeaTunnelSink#restoreWriter` call. The test then:
   
   1. Samples the checkpoint monitor for a full trigger period (`4 s`) while 
the restored task group is still being re-created, and requires that the job 
stays `RUNNING`, no checkpoint is in progress, the pipeline's `triggered` 
counter does not move, and no checkpoint newer than the boundary appears in the 
history.
   2. Requires the state passed to the restored writer to be **exactly** the 
state stored by the boundary checkpoint.
   3. Releases the writer and requires the first completed checkpoint 
afterwards to be **exactly `boundary + 1`** – the restore must neither consume 
nor skip a checkpoint id – with `triggered` advanced by exactly one, `failed == 
0`, `restored == 1`, and a state that includes the restored rows plus the rows 
written after the restore.
   4. Cancels the job and requires `CANCELED`, so the restore path leaves a 
cancellable lifecycle behind.
   
   Only `FakeSource` and a test-tree sink are used as fixtures; no Transform, 
SQL, connector or format behavior is exercised.
   
   ### Why this boundary has real regression risk
   
   A mid-run pipeline restore reuses the job and its checkpoint bookkeeping but 
re-creates the task group: the failure path shuts the checkpoint coordinator's 
scheduler down, `restoreCoordinator` recreates it through the RESET cleanup and 
leaves the coordinator marked "not all tasks ready", and the next periodic 
trigger is only armed from `allTaskReady()` once every restored task reported 
`READY_START`.
   
   Two independent pieces must agree for the window to be safe:
   
   1. **No periodic trigger may create a checkpoint while the restored task 
group is being re-created.** A trigger that slips in allocates a checkpoint id 
and injects a barrier into task groups that cannot acknowledge it yet, so the 
id is permanently consumed; the checkpoint then expires at `checkpoint.timeout` 
and fails the freshly restored coordinator, which burns a `job.retry.times` 
attempt and can end a job whose restored task group is perfectly healthy.
   2. **The restored task group must apply the writer state assigned by the 
checkpoint plan before the next snapshot.** Otherwise the first post-restore 
checkpoint silently drops everything written before the failure. The job keeps 
reporting RUNNING and checkpoints keep completing, so neither the job status 
nor the completed-checkpoint counter exposes the data-loss window; only 
comparing the restored state with the durable state catches it.
   
   ### Why the existing coverage does not reach it
   
   - `CheckpointSingleFlightIT` (open PR) holds a checkpoint in flight with all 
tasks ready, so its trigger sees a live task group.
   - `CheckpointExpiryPipelineScopeIT` (open PR) lets a checkpoint expire and 
restores a pipeline, but its assertions start after the restore and it never 
samples a trigger period inside the restore.
   - `SavepointPreconditionRecoveryIT` only rejects a savepoint before tasks 
are ready on a fresh job.
   - `CheckpointRestoreWithStopIT` / `SavepointRestoreIT` restore a stopped job 
on a cluster where no checkpoint timer is armed across the restore.
   - `CheckpointCoordinatorFailoverIT` switches the master between checkpoints; 
it never re-creates a task group under a live job.
   
   No existing test holds a task group inside its restore for longer than a 
trigger period and checks both the trigger count and the recovered state.
   
   ### Negative control
   
   Temporarily arming a periodic trigger at the end of `restoreCoordinator` (in 
the `alreadyStarted == false` branch) and dropping the `isAllTaskReady` early 
return in `tryTriggerPendingCheckpoint` makes the test fail as intended:
   
   ```
   a periodic checkpoint was triggered while the pipeline was restoring; 
checkpoint ids: [2, 1]
   ==> expected: <2> but was: <3>
   ```
   
   Both changes were reverted, the pristine engine was rebuilt, and the test is 
green again.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Test-only change: one E2E class, one test-tree sink family and one job 
fixture.
   
   ### How was this patch tested?
   
   ```
   JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home \
     ./mvnw -o -q -pl 
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base spotless:apply
   
   JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home \
     ./mvnw -o -pl 
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base \
     -DskipUT=true -DskipIT=false -Dit.test=PipelineRestoreCheckpointWindowIT \
     -DfailIfNoTests=false -Dskip.spotless=true -Drat.skip=true 
-Dmaven.javadoc.skip=true verify
   ```
   
   Result: `Tests run: 1, Failures: 0, Errors: 0, Skipped: 0` (about 13.3 s on 
JDK 17), reproduced on four consecutive runs. `spotless:apply` reports no 
remaining changes.
   


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