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

   Yes, I am contributing this change to Apache SeaTunnel.
   
   ### Purpose of this pull request
   
   Fixes #13467.
   
   A stop-with-savepoint request whose final checkpoint fails because the 
worker owning the barrier exits can leave the job stuck in `DOING_SAVEPOINT` 
forever. The stop path is entered correctly (`PhysicalPlan#savepointFailed()` 
logs "stop all pipelines with checkpoint fallback"), but it loses a race with 
the pipeline restore that the same worker loss triggered.
   
   **Root cause.** `SubPlan#prepareRestorePipeline()` increments the restore 
counter, resets the pipeline and sleeps `job.retry.interval.seconds` before 
redeploying it. During that sleep, `stopPipelineWithCheckpointFallback()` -> 
`forceStopPipeline()` records the stop through `JobMaster#neverNeedRestore()` 
(`needRestore = false`) and force-stops the vertices. The wait then returned 
`true` unconditionally and `stateProcess()` called `restorePipeline()`, 
redeploying the pipeline behind the stop. Because `PhysicalPlan#stopJob()` 
deliberately does not set the job state in its `DOING_SAVEPOINT` branch (it 
relies on the pipeline end callback to resolve `SAVEPOINT_DONE`/`CANCELED`), 
and the pipeline restored instead of ending, no callback ever decides the job 
state. The job stays in `DOING_SAVEPOINT` with no active pipeline.
   
   **Fix.** After the restore interval, re-check `jobMaster.isNeedRestore()`; 
when a stop/cancel was requested while the pipeline was waiting, return `false` 
so the pipeline follows the normal `subPlanDone()` path and the job resolves to 
a terminal state. The existing `needRestore` contract ("if the job or pipeline 
is cancelled by the user, needRestore is false") is now also honored by the 
restore path that was already in flight.
   
   ### Regression coverage
   
   The second commit is a test-only E2E, `WorkerFailureDuringSavepointIT`, plus 
a test sink fixture whose writer parks in `snapshotState()` until a release 
marker file exists.
   
   **Why this is a boundary with real regression risk.** The two competing 
state machines are independent: the pipeline restore is driven by task/member 
loss, the stop is driven by the aborted savepoint. Nothing surfaces the lost 
stop as a task error; the client already receives a savepoint failure either 
way, so only the job's final status exposes it. A job that never leaves 
`DOING_SAVEPOINT` also never releases its resources.
   
   **Why existing coverage does not reach it.**
   
   - `CancelDuringSavepointIT` covers a cancel that races a parked savepoint; 
that is a second live command, not a task failure, and the job ends `CANCELED` 
by construction.
   - `SavePointBusySourceTest#testSavepointFailureReportsErrorAndStopsJob` 
covers a savepoint that times out while every worker stays healthy, so no 
restore competes with the stop.
   - `SplitClusterWorkerRestartAfterFinalCheckpointIT` covers a worker loss 
after the final checkpoint, not while a savepoint barrier is pending.
   - `CheckpointCoordinatorFailoverIT` covers master failover and periodic 
checkpoints, not a worker loss inside a savepoint.
   - apache/seatunnel#12134 covers a **master** failover during a savepoint; 
here the master survives and only a worker exits, so the job is not 
re-initialized at all.
   
   **What the test does.** One master and two workers run in the JVM test 
cluster, so a second worker remains available and the pipeline really restores 
instead of failing for lack of resources.
   
   1. Submit a STREAMING job with `checkpoint.interval = 600000`, take a 
savepoint, and restore the job from it to establish a real recovery point.
   2. Arm the hold, request a second savepoint, verify through the master's 
checkpoint overview that the parked checkpoint is an in-progress 
`SAVEPOINT_TYPE` checkpoint, and verify the request is still in flight.
   3. Locate the task group that drives the sink writer (Zeta chains source, 
transform and sink into one group, so the writer is reached through the group's 
`TransformSeaTunnelTask`) and shut down exactly the worker that executes it. 
The second worker stays alive.
   4. Release the park and require: the savepoint request fails; the job leaves 
`DOING_SAVEPOINT` and reaches `FAILED` or `CANCELED` (and stays terminal); the 
aborted checkpoint is not stored as a savepoint; the sole recovery savepoint is 
still the original one; and the surviving master/worker pair schedules and 
finishes a follow-up job.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. The fix only makes an already-requested stop win; configuration options, 
defaults and successful savepoint behavior are unchanged.
   
   ### How was this patch tested?
   
   Formatting:
   
   ```
   ./mvnw -o -pl 
seatunnel-engine/seatunnel-engine-server,seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base
 spotless:check
   ```
   
   Focused server tests (including the new 
`SubPlanTest#shouldNotRestoreWhenStopIsRequestedWhileWaiting`):
   
   ```
   ./mvnw -o -pl seatunnel-engine/seatunnel-engine-server \
     
-Dtest=SubPlanTest,StateTransitionCleanupTest,JobMasterTest,SavePointTest,SavePointBusySourceTest,CheckpointErrorRestoreEndTest
 \
     -DfailIfNoTests=false test
   ```
   
   `Tests run: 53, Failures: 0, Errors: 0, Skipped: 1`.
   
   New E2E:
   
   ```
   ./mvnw -o -pl 
seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base \
     -DskipUT=true -DskipIT=false \
     -Dit.test='WorkerFailureDuringSavepointIT' -DfailIfNoTests=false verify
   ```
   
   `Tests run: 1, Failures: 0, Errors: 0` in about 21 s, passed three 
consecutive local runs.
   
   Against the unpatched `dev` the same test fails deterministically:
   
   ```
   A failed stop-with-savepoint must stop the job, but the status is 
DOING_SAVEPOINT
   ... expected: <true> but was: <false> within 5 minutes
   ```
   
   with the master logged `savepoint failed, stop all pipelines with checkpoint 
fallback` and the pipeline logged `Begin to cancel other tasks in this 
pipeline` immediately afterwards, which is the exact race described above.
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License 
Notice — not applicable
   * [ ] If necessary, please update the documentation to describe the new 
feature — not applicable, bug fix
   * [ ] If necessary, please update `incompatible-changes.md` — not applicable
   * [ ] Connector contribution checklist — not applicable
   


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