Skip to content

[Test][Zeta] Add E2E coverage for savepoint barrier injection against a busy source (apache/seatunnel#11473) - #12141

Merged
nzw921rx merged 1 commit into
apache:devfrom
DanielLeens:zeta-savepoint-busy-source-barrier
Sep 7, 2026
Merged

nzw921rx merged 1 commit into
apache:devfrom
DanielLeens:zeta-savepoint-busy-source-barrier

Conversation

@DanielLeens

Copy link
Copy Markdown
Contributor

Purpose of this pull request

Add E2E regression coverage for the literal mechanism behind #11473 ("[Bug] [Zeta] stop-job with savepoint hangs in DOING_SAVEPOINT"), fixed by #11489: a savepoint requested while the source is busy emitting a very large split must still get its barrier injected and complete, through the real multi-node path.

The gap

#11489 fixed the hang on two ends: FakeSourceReader#pollNext now emits at most MAX_ROWS_PER_POLL rows per call and requeues the remainder of the split, so the checkpoint lock that SourceFlowLifeCycle#triggerBarrier needs is released between batches; and JobMaster#savePoint now leaves DOING_SAVEPOINT deterministically when a savepoint cannot complete.

Existing coverage of that fix:

  • SavePointBusySourceTest (seatunnel-engine-server): reproduces the busy split, but only inside a single in-process server and by calling CoordinatorService#savePoint directly. The barrier never crosses a node boundary and no client is involved.
  • SavepointPreconditionRecoveryIT ([Test][E2E] Guard stop-with-savepoint hang when precondition is rejected #12035): E2E, but it exercises a different branch of the same fix, the TASK_NOT_ALL_READY_WHEN_SAVEPOINT precondition rejection that restores the job to RUNNING. No busy source and no starved barrier are involved there.

The #11473 mechanism itself, a barrier that has to be injected into a source mid-split, with the trigger dispatched over the network by CheckpointBarrierTriggerOperation and the request coming from a real client, had no E2E coverage.

What the new test does

SavepointBusySourceBarrierIT (connector-seatunnel-e2e-base, same harness as SavepointPreconditionRecoveryIT):

  1. Starts a split master/worker cluster and submits the reproduction job from the issue verbatim (stream_fake_busy_split_to_console_savepoint.conf: one FakeSource split of 100,000,000 rows, split.read-interval = 10, checkpoint.interval = 10000, checkpoint.timeout = 60000, Console sink with log.print.data = false).
  2. Waits until SourceReceivedCount is positive and still growing between two samples, i.e. the reader is provably mid-split, then fires a real SeaTunnelClient#savePointJob from a separate thread.
  3. Requires the request to complete within 120 s (a TimeoutException is reported as the [Bug] [Zeta] stop-job with savepoint hangs in DOING_SAVEPOINT #11473 hang; an ExecutionException is the [Fix][Zeta] Fix stop-with-savepoint hang in DOING_SAVEPOINT #11489 failure exit, which is equally a regression here), then requires SAVEPOINT_DONE.
  4. Mid-split proof: the SourceReceivedCount recorded in the finished-job history must be at least the last live sample and strictly below the split size. Pre-fix the barrier could only pass after the whole split drained (or never, once the checkpoint expired).
  5. Restores the job from that savepoint via restoreExecutionContext (RestoreMode.SAVEPOINT, which only accepts a savepoint-type checkpoint), waits for the restored source to emit again, and takes a second stop-with-savepoint against the restored, still-busy source.

The bound of 120 s deliberately exceeds the job's checkpoint.timeout (60 s), so a starved barrier surfaces as a checkpoint expiry and a failed request instead of a silent hang past the bound.

Why it is not flaky

  • The busy condition is not timing-guessed: at the observed generation rates (tens of thousands of rows per second) the 100M-row split takes tens of minutes, so every request lands mid-split, and the test only fires after metrics show the counter growing.
  • All waits are bounded Awaitility polls; metric reads that fail transiently during deployment/teardown are logged and retried instead of aborting the poll.
  • Before the restore, the test waits for the coordinator to release the finished job id; otherwise CoordinatorService#submitJob treats the still-registered id as already running and silently skips the restore.

Verification

Local run (macOS, JDK 8, full -am install of the upstream modules from this branch, then verify -pl connector-seatunnel-e2e-base -DskipUT=true -DskipIT=false -Dit.test=SavepointBusySourceBarrierIT), 4 consecutive passes:

Run Result Elapsed
1 Tests run: 1, Failures: 0, Errors: 0 17.9 s
2 (INFO logging) Tests run: 1, Failures: 0, Errors: 0 18.0 s
3 Tests run: 1, Failures: 0, Errors: 0 18.2 s
4 (INFO logging) Tests run: 1, Failures: 0, Errors: 0 18.7 s

Trace from run 4 (checkpoint coordinator / job master at INFO):

turned from state SCHEDULED to RUNNING
FakeSourceReader - wait split!
turned from state RUNNING to DOING_SAVEPOINT
save point checkpoint is created, ... checkpoint id: 1
turned from state DOING_SAVEPOINT to SAVEPOINT_DONE
stop-with-savepoint (initial run) ... completed in 737 ms
SourceReceivedCount was 16187 right before the savepoint request and 77824 when the pipeline finished (split size 100000000)
Restore checkpoint, ... checkpointId=1, checkpointType=SAVEPOINT_TYPE
turned from state SCHEDULED to RUNNING
turned from state RUNNING to DOING_SAVEPOINT
save point checkpoint is created, ... checkpoint id: 2
turned from state DOING_SAVEPOINT to SAVEPOINT_DONE
stop-with-savepoint (restored run) ... completed in 236 ms
(restored): SourceReceivedCount was 109138 right before the second savepoint request and 118784 when the pipeline finished

Both barriers landed on a 4096-row batch boundary (77824 = 19 x 4096, 118784 = 29 x 4096) with the split far from drained, which is exactly the lock release added by #11489. No timeout checkpoint / CHECKPOINT_EXPIRED events, no transient metric failures.

./mvnw spotless:check -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base passes.

Does this PR introduce any user-facing change?

No. Test-only: one new IT class and one new test job config under connector-seatunnel-e2e-base/src/test.

How was this patch tested?

See Verification above; CI runs the new IT as part of the engine E2E module.

Check list

🤖 Generated with Claude Code

…source (apache#11473)

Issue apache#11473 reported that a REST stop-job with isStopWithSavePoint=true
against a plain streaming FakeSource -> Console job never completed and
left the job in DOING_SAVEPOINT forever. PR apache#11489 fixed it on two ends:
FakeSourceReader#pollNext now emits bounded batches and requeues the rest
of the split, so the checkpoint lock that SourceFlowLifeCycle#triggerBarrier
needs is released between batches and the savepoint barrier can be
injected mid-split; and JobMaster#savePoint leaves DOING_SAVEPOINT
deterministically when a savepoint cannot complete.

The fix's own SavePointBusySourceTest reproduces the busy split only in a
single in-process server, calling CoordinatorService#savePoint directly,
so the barrier never crosses a node boundary and no client is involved.
SavepointPreconditionRecoveryIT (apache#12035) covers a different branch of the
same fix, the TASK_NOT_ALL_READY_WHEN_SAVEPOINT precondition rejection,
which never involves a busy source. The literal apache#11473 mechanism had no
E2E coverage through the real multi-node path.

SavepointBusySourceBarrierIT runs the issue's reproduction job (one
100,000,000-row FakeSource split into a Console sink) on a split
master/worker cluster, waits until job metrics show the reader actively
emitting its split, fires a real SeaTunnelClient#savePointJob request,
and requires it to complete within a bound that deliberately exceeds the
job's checkpoint.timeout, so a starved barrier fails cleanly instead of
hanging. It proves the barrier landed mid-split by requiring the finished
job's SourceReceivedCount to sit strictly between the last live sample
and the split size, then restores the job from that savepoint
(RestoreMode.SAVEPOINT), verifies the restored source resumes emitting,
and takes a second stop-with-savepoint against the restored, still-busy
source. Passed four consecutive local runs (17.9-18.7s each); both
barriers landed on a 4096-row batch boundary with the split far from
drained.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added the e2e label Sep 6, 2026

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Problem Does This PR Solve?

  • User pain point: #11473 reported that stop-job --savepoint against a plain streaming FakeSource -> Console job never completed and left the job stuck in DOING_SAVEPOINT forever, holding its slots hostage. The fix landed in #11489, but no test exercised the actual multi-node mechanism end to end: the existing SavePointBusySourceTest reproduces the busy split only inside a single in-process server (calling CoordinatorService#savePoint directly, no client, no node boundary), and SavepointPreconditionRecoveryIT covers a completely different branch of the same fix (the TASK_NOT_ALL_READY_WHEN_SAVEPOINT precondition rejection).
  • Fix approach: this PR adds SavepointBusySourceBarrierIT, which drives the literal #11473 reproduction job (one 100,000,000-row FakeSource split into a Console sink) through a real split master/worker cluster, waits until job metrics prove the source is actively mid-split, fires a real SeaTunnelClient#savePointJob request, and requires it to complete within a bound that deliberately exceeds checkpoint.timeout so a starved barrier fails cleanly instead of hanging. It then proves the savepoint is genuinely usable by restoring the job from it and repeating the same busy-split savepoint against the restored run.
  • One-sentence summary: a well-targeted, real end-to-end regression test that closes the coverage gap left by #11489 for the exact scenario reported in #11473.

1. Code Change Review

1.1 Core Logic Analysis

This is a test-only addition (one new *IT class + one new .conf resource, no production code touched). I traced every claim the test's javadoc makes against the current dev head (f0c459055706, fetched fresh for this review) rather than trusting the PR description at face value:

  • FakeSourceReader#pollNext (seatunnel-connectors-v2/connector-fake/.../FakeSourceReader.java) genuinely caps emission at MAX_ROWS_PER_POLL = 4096 per call and requeues the remainder of the split, releasing output.getCheckpointLock() between batches — exactly the mechanism the test's javadoc describes and the mechanism that starved the barrier pre-fix.
  • JobMaster#savePoint() (seatunnel-engine-server/.../master/JobMaster.java:1283) has the deterministic finally branch the test relies on: when the savepoint doesn't complete and it isn't the "not all tasks ready" precondition, it calls physicalPlan.savepointFailed() instead of leaving the job stuck in DOING_SAVEPOINT.

Runtime path exercised by the test:

SeaTunnelClient#savePointJob(jobId)
  -> JobMaster#savePoint() [master]
       -> checkpointManager.triggerSavePointsAndWaitComplete()
            -> CheckpointBarrierTriggerOperation dispatched to worker
                 -> SourceFlowLifeCycle#triggerBarrier acquires checkpoint lock
                      (contends with FakeSourceReader#pollNext's per-batch lock hold)
  -> waitSavepointCompleted() blocks the test's async CompletableFuture
  -> job reaches SAVEPOINT_DONE, CoordinatorService releases the JobMaster
  -> engineClient.getJobMetricsSummary(jobId) reads the finished-job SourceReceivedCount

The mid-split proof (rowsAtSavepoint < SPLIT_ROW_NUM) and the "metrics were actually captured" proof (rowsAtSavepoint >= rowsBeforeSavepoint) are both real, non-vacuous assertions: if the metrics path returned stale/zero data after release, the first assertion would fail loudly rather than pass by accident. I also confirmed getJobMetricsSummary/restoreExecutionContext(filePath, jobConfig, seaTunnelConfig, jobId) signatures match SeaTunnelClient exactly as used.

I additionally confirmed via the real CI run (fork run 34012353379, job "engine-v2-it (11, ubuntu-latest)") that this exact test executed and passed: Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 19.617 s. This is not a theoretical trace — the barrier-mid-split scenario was actually reproduced and actually passed in CI.

1.2 Compatibility Impact

Fully compatible. No production code, config option, protocol, or serialization format is touched. Purely additive test coverage.

1.3 Performance / Side-Effect Analysis

No production hot path is touched. The test itself spins up an isolated two-node Hazelcast cluster per run (standard pattern for this test suite) and is cleaned up in a finally block (engineClient.close(), both nodes' shutdown()), so no thread/port/resource leak across test runs. Measured CI cost is modest (~20s), well inside typical E2E budgets for this module.

1.4 Error Handling and Logging

readSourceReceivedCount deliberately swallows RuntimeException from a metrics RPC that can transiently fail while task groups are being deployed/torn down, logs it at WARN, and returns -1 so the surrounding Awaitility poll simply retries rather than aborting on a single transient miss — this is the correct pattern for polling code and doesn't hide a real failure (the poll's own assertion still requires eventual success within the bound).

No issues found here.

2. Code Quality Assessment

2.1 Coding Standards

Comments are thorough and exceed the bar: every non-trivial method and constant has a javadoc explaining the "why" (e.g. why SAVEPOINT_COMPLETION_TIMEOUT_SECONDS deliberately exceeds checkpoint.timeout, why the restore reuses the same job id and what awaitJobReleasedByCoordinator protects against). License header present. No wildcard imports.

2.2 Test Coverage and Test Stability

Stability rating: Stable.

  • All waits are Awaitility-based with explicit, generous bounds (120s) and short poll intervals (200ms) — no raw Thread.sleep anywhere in the test.
  • No shared/static mutable state between test runs.
  • Resources (client, master node, worker node) are deterministically released in finally.
  • The mid-split race window is constructed deterministically (100M rows at 4096/batch with a 10ms minimum read interval physically cannot drain within the test's bounds), not by chance timing — this is what makes the "mid-split" assertion reliable rather than a coin flip.
  • Verified against a real, currently-green CI run rather than only against a diff.

This test closes a real, previously-uncovered gap: no existing test exercised the busy-split savepoint scenario across a real node boundary with a real client.

2.3 Documentation Updates

Not applicable — test-only change, no user-visible behavior changed.

3. Architectural Soundness

3.1 Elegance of the Solution

Precise fix for a real coverage gap. The test is scoped exactly to the mechanism #11489 fixed and deliberately avoids re-testing the precondition-rejection branch already covered by SavepointPreconditionRecoveryIT.

3.2 Maintainability

High. The javadoc is detailed enough that a future maintainer investigating a savepoint regression would understand both the historical bug and why this specific test exists without needing to read #11473/#11489 first.

3.3 Extensibility

The helper methods (awaitSourceActivelyEmitting, stopWithSavepointWithinBound, awaitJobReleasedByCoordinator) are generically useful and could be reused by future savepoint/checkpoint E2E tests in this package with minimal changes.

3.4 Historical-Version Compatibility

Not applicable — no serialization, checkpoint format, or protocol change involved.

4. Issue Summary

No issues found — table intentionally empty.

Number Issue Location Severity
— None found — —

5. Merge Recommendation

Conclusion: Ready to merge

  1. Blockers — None.
  2. Recommended fixes — non-blocking:
    • Purely optional: the per-node getSeaTunnelConfig cluster-bootstrap boilerplate is duplicated with sibling ITs like SavepointPreconditionRecoveryIT; a shared test utility could reduce duplication in the future, but that's a nice-to-have, not something this PR should be blocked on.

Overall assessment: this is exactly the kind of white-box, real-path regression test this project should have more of — it traces a specific historical bug through the real client/master/worker boundary rather than unit-testing the fix in isolation, and I independently verified both the production-code premise (the fix is genuinely present in current dev) and the CI execution (the test actually ran and passed, not just compiled). No concerns. Approving.

@nzw921rx nzw921rx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@nzw921rx
nzw921rx added this pull request to the merge queue Sep 7, 2026
Merged via the queue into apache:dev with commit 0821d8a Sep 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants