Skip to content

[Test][Zeta] Guard per-subtask checkpoint state restore for parallelism > 1 - #13489

Open
zhangshenghang wants to merge 3 commits into
apache:devfrom
zhangshenghang:zeta-parallel-restore-state
Open

zhangshenghang wants to merge 3 commits into
apache:devfrom
zhangshenghang:zeta-parallel-restore-state

Conversation

@zhangshenghang

Copy link
Copy Markdown
Member

Thanks for contributing to Apache SeaTunnel! This PR only adds test coverage and a test fixture option; it does not change engine, connector or configuration behaviour.

Background

CheckpointCoordinator#restoreTaskState(TaskLocation) does not restore a task's state directly from the checkpoint. It walks the (ActionStateKey, index) tuples of the checkpoint plan and remaps the saved subtask states onto the current parallelism of each action:

for (int i = index; i < actionState.getParallelism(); i += currentParallelism) { ... }

If that stride is derived from something that is always one per task (for example the pipelineTasks map, which is keyed by TaskLocation#getTaskVertexId() and therefore holds exactly one entry per subtask), subtask 0 absorbs the saved state of every subtask. With parallelism greater than one the duplicated state is handed back to a reader that already owns it, so the restored job re-reads and re-commits data the previous run had already committed. With parallelism one there is nothing to duplicate, which is why the existing restore tests cannot see the difference.

That regression was fixed in #12195, but its only test (CheckpointCoordinatorTest) fabricates an already-built plan and already-saved subtask states and calls the remap indirectly. SavepointRestoreIT, CheckpointRestoreWithStopIT and SavepointClusterRestartRestoreIT all run the checkpointable sequence fixture with parallelism = 1 and split_num = 1, so no end-to-end test ever restores two distinct per-subtask states onto two subtasks.

What this PR adds

  • ParallelSubtaskSavepointRestoreIT: an in-process one-master/one-worker Zeta cluster running a two-subtask pipeline where each reader owns one split of a finite sequence. The job is stopped with a real savepoint mid-stream, restored once, and must then commit every offset in [0, 4000) exactly once and end FINISHED. A duplicated subtask state makes a restored reader replay an already committed range, so the duplicate-offset assertion fails instead of the job silently breaking exactly-once.
  • An opt-in one_split_per_reader option on the e2e CheckpointableSequenceSource fixture (default false). The default keeps the historical behaviour so existing container tests are unaffected; the new mode is required because the old behaviour drains every pending split into the first reader, leaving the other subtasks with an empty checkpoint state and nothing to remap. Restore hands a reader's splits back through addSplitsBack before that reader registers, so those returned splits are held per reader and handed back when it registers.
  • stream_checkpointable_sequence_two_parallel_restore_template.conf: the job template (2 readers, 2 splits, local file sink with per-checkpoint transactions).

Verification

  • ./mvnw -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base -DskipUT -DskipIT=false -Dit.test=ParallelSubtaskSavepointRestoreIT verify — passes, 1 test, ~21s (JDK 17, in-process master + worker, no container needed).
  • ./mvnw spotless:apply on both touched modules.
  • The job is observed to reach SAVEPOINT_DONE with offsets from both splits committed before the restore, and FINISHED with all 4000 offsets committed exactly once after it.

Related: #12195 (regression this E2E guards). No new issue is filed because this is coverage for an already fixed defect; no production code is touched.

…sm > 1

CheckpointCoordinator#restoreTaskState remaps the saved subtask states onto
the current parallelism of each action. A stride that is always one per task
(for example the pipelineTasks map keyed by TaskLocation#getTaskVertexId())
makes the first subtask absorb the state of every other subtask. With
parallelism greater than one that duplicated state is handed back to a reader
that already owns it, so the restored job re-reads and re-commits data that
the previous run had already committed. With parallelism one there is nothing
to duplicate, which is why every existing restore E2E passes.

apache#12195 fixed this and only added a unit test that fabricates the plan and the
saved states. Add an E2E that actually restores two distinct per-subtask
states onto two subtasks: a two-parallel pipeline in which the checkpointable
sequence fixture gives each reader its own split, stopped with a real
savepoint and restored once, must commit every offset exactly once and end
FINISHED.

The fixture gets an opt-in one-split-per-reader assignment mode so both
parallel readers own checkpoint state; the previous behaviour (first reader
drains every pending split) is unchanged and remains the default.
@github-actions github-actions Bot added the e2e label Nov 27, 2026

@DanielLeens DanielLeens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for contributing to Apache SeaTunnel! I reviewed the complete current diff and followed its entry points and failure paths. The items below need attention before merging; I hope the concrete paths make the next step straightforward.

What problem does this PR solve?

User pain: A checkpoint remapping regression can restore another subtask's state and duplicate already committed rows.

Approach: Give each of two readers one sequence split, take a partial savepoint, restore and compare committed offset coverage.

In one sentence/example: Reader zero must resume only its own half of 0..3999, rather than replay reader one's saved half too.

1. Code changes

1.1 Core logic

Complete runtime path:

CheckpointableSequenceSource.createEnumerator -> one_split_per_reader=true
 -> enumerator assigns one sequence split per registered reader
 -> reader emits one offset/poll -> transactional LocalFile checkpoints
 -> both ranges observed -> savePointJob -> SAVEPOINT_DONE -> original JobMaster removed
 -> restoreExecutionContext with same job id -> restoreTaskState remaps action index/parallelism
 -> reader state handed back via addSplitsBack -> returnedSplits keyed by subtask
 -> restored readers drain -> LocalFile committed offsets -> FINISHED

Key findings and correctness:

  1. The new option defaults false, retaining existing fixture distribution; create/restore pass the same test-only option. The old constructor remains a false-default overload.
  2. Nonempty data from both split ranges establishes real parallel reader progress, unlike a one-split state test. Returned splits are routed to the reader that supplied them.
  3. Range uniqueness is checked while polling, but the terminal read only checks that both ranges occur; later duplicate commits can escape the completed oracle (Issue 1).
  4. The source has only about eight seconds of nominal emission per split at four milliseconds/poll. Observed warm-up does not freeze it until savepoint request execution; this remains a timing-dependent mid-stream precondition (Issue 2).
  5. This fixture mode is designed for equal split/reader counts and same-parallelism restoration, not a general rescaling scheduler; no production connector behavior is changed.

Before:

new CheckpointableSequenceSplitEnumerator(context, pendingSplits, awaitingRestoredSplits);

After (key path excerpt):

new CheckpointableSequenceSplitEnumerator(context, pendingSplits,
    awaitingRestoredSplits, config.get(ONE_SPLIT_PER_READER));
// true mode routes returned state to its original subtask
returnedSplits.computeIfAbsent(subtaskId, reader -> new ArrayDeque<>()).addAll(splits);

1.2 Compatibility

Fully compatible for production; changes are in test sources/resources only. The shared fixture option defaults false and retains the existing constructor overload. The true mode adds a test-only distribution contract; no production SPI, protocol or saved-state format is changed.

1.3 Performance and side effects

The source emits at most one offset per poll and the test reads roughly 4000 small committed offsets, so test data volume is bounded. The returnedSplits map is per-enumerator test state. No production thread, network, retry, checkpoint payload or connector memory behavior changes.

1.4 Errors, logging, and findings

Issue 1: Reassert the complete exactly-once oracle after FINISHED

  • Location: seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/ParallelSubtaskSavepointRestoreIT.java:247.
  • Description and risk: The polling loop exits as soon as it observes 4000 distinct offsets without duplicates. The restored job is still active then. It can commit extra replayed rows in a later checkpoint before FINISHED, especially in the incorrect state-remapping scenario where one reader receives both readers' saved splits. After FINISHED the code only asserts both ranges are represented, so those later duplicates need not fail the test.
  • Best improvement: After awaiting FINISHED, read the final committed files and run the same total-count, uniqueness and complete-range assertions on that terminal snapshot. Use one shared assertion helper for both snapshots so the final test cannot accept late replay.
  • Responsibility and trade-off: The test fixture owns deterministic split assignment and emission; the engine IT owns the terminal data oracle. Keep both fixes in those test boundaries. Changing CheckpointCoordinator to accommodate an ineffective fixture would be the wrong layer.
  • Severity: High; blocking: true.
  • Previously raised by another reviewer: No, unless explicitly attributed above.

Issue 2: Make partial savepoint progress a controlled precondition

  • Location: seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/ParallelSubtaskSavepointRestoreIT.java:168.
  • Description and risk: Both readers continue a finite 2000-offset range at four milliseconds per poll after warm-up. The test thread can be delayed between observing committed progress and invoking/completing savePointJob, allowing normal completion before the intended partial savepoint. Larger row counts or a longer sleep only move that window.
  • Best improvement: Gate source progress at a known nonterminal offset until the savepoint is requested/acknowledged, release it for restoration, and assert both serialized reader states. Keep timeouts only as watchdogs; do not depend on winning the remaining emission window.
  • Responsibility and trade-off: The test fixture owns deterministic split assignment and emission; the engine IT owns the terminal data oracle. Keep both fixes in those test boundaries. Changing CheckpointCoordinator to accommodate an ineffective fixture would be the wrong layer.
  • Severity: High; blocking: true.
  • Previously raised by another reviewer: No, unless explicitly attributed above.

Issue 3: Document the new fixture distribution state

  • Location: seatunnel-e2e/seatunnel-e2e-common/src/test/java/org/apache/seatunnel/e2e/source/checkpointable/CheckpointableSequenceSplitEnumerator.java:41.
  • Description and risk: oneSplitPerReader and signalNoMoreSplitsWhenDrained introduce nontrivial split-distribution and end-of-input semantics, but the field/helper lack their own invariant comments. The mode is not a general scheduler for split counts larger than reader counts.
  • Best improvement: Document the equal-split/reader fixture constraint, returned-state ownership and when no-more-splits may be signalled; keep the historical default explicit.
  • Responsibility and trade-off: The test fixture owns deterministic split assignment and emission; the engine IT owns the terminal data oracle. Keep both fixes in those test boundaries. Changing CheckpointCoordinator to accommodate an ineffective fixture would be the wrong layer.
  • Severity: Medium; blocking: false.
  • Previously raised by another reviewer: No, unless explicitly attributed above.

Community input: no independent technical finding or maintainer approval/change request was present in the collected discussion.

2. Code quality

2.1 Conventions

Reviewed all changed files for license, imports, naming, core-method and state-field comments. See the numbered findings for the required changes.

2.2 Test coverage and stability

Stability rating: High risk. High risk: polling for actual committed files is a strong signal, streams are closed, paths include unique suffixes and the restore waits for original JobMaster cleanup. However the final exactly-once oracle is incomplete and partial progress is not held deterministically. Also synchronous savepoint/cancel/status RPCs are not bounded by the later Awaitility waits; unconditional teardown is desirable.

2.3 Documentation

No product docs are required. New class/option Javadocs explain the intended regression and historical default; document the additional fixture state invariants noted in Issue 3.

3. Architecture

3.1 Change location

The test fixture owns deterministic split assignment and emission; the engine IT owns the terminal data oracle. Keep both fixes in those test boundaries. Changing CheckpointCoordinator to accommodate an ineffective fixture would be the wrong layer.

3.2 Maintainability

Keep the behavior, lifecycle ownership, and failure contract together. The test fixture owns deterministic split assignment and emission; the engine IT owns the terminal data oracle. Keep both fixes in those test boundaries. Changing CheckpointCoordinator to accommodate an ineffective fixture would be the wrong layer.

3.3 Extensibility

Prefer the existing component boundary and tests over unrelated shared abstractions.

3.4 Upgrade impact

Fully compatible for production; changes are in test sources/resources only. The shared fixture option defaults false and retains the existing constructor overload. The true mode adds a test-only distribution contract; no production SPI, protocol or saved-state format is changed.

4. Findings summary

Completeness check: All changed files and affected entry/failure paths were reviewed; configuration/serialization compatibility, test failure capability and stability, documentation/examples, change ownership, and current CI/conflict/review gates are covered above. No unreviewed source scope is claimed complete.

# Finding Location Severity
1 Reassert the complete exactly-once oracle after FINISHED seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/ParallelSubtaskSavepointRestoreIT.java:247 High
2 Make partial savepoint progress a controlled precondition seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base/src/test/java/org/apache/seatunnel/engine/e2e/ParallelSubtaskSavepointRestoreIT.java:168 High
3 Document the new fixture distribution state seatunnel-e2e/seatunnel-e2e-common/src/test/java/org/apache/seatunnel/e2e/source/checkpointable/CheckpointableSequenceSplitEnumerator.java:41 Medium

5. Merge recommendation

Merge after fixes

Blocking items: Issues 1, 2. Current-head CI and write-capable maintainer review remain independent requirements.

Non-blocking suggestions: Issue 3: Document the new fixture distribution state

Overall: the approach addresses a real path, but the listed blockers must be closed. Daniel has READ permission, so this COMMENT cannot dismiss historical requested changes or satisfy a write-capable maintainer approval gate.

CI and repository state: Signal pull request update: SUCCESS; Build: IN_PROGRESS; Build: queued. GitHub reports BLOCKED / REVIEW_REQUIRED.

Verification: Reviewed all changed files and the referenced call sites at 584291102500010ee75adf371f93cc6b483d7dc6 against merge base 39c74ce48b0fb5e0318326b8d57a42c7380c40c8. git diff --check passed. I did not build, run tests, or execute SeaTunnel locally.

Review time: 2026-11-27T03:49:31.828034-05:00

Local evidence: git fetch obtained head 584291102500010ee75adf371f93cc6b483d7dc6; git merge-base returned 39c74ce48b0fb5e0318326b8d57a42c7380c40c8; git diff --stat reports 5 files changed, 617 insertions(+), 3 deletions(-). git show and source searches were used for the entry points above. No local build, unit test, E2E, Docker run or service startup was executed.

…actly-once at FINISHED

Reviewer problems on PR apache#13489:
- Issue 1: after the restored job reached FINISHED the test only checked that
  both split ranges were represented, so rows replayed by a later checkpoint
  could not fail it and the exactly-once oracle was incomplete.
- Issue 2: the partial savepoint precondition was inferred from a timing
  window. Both readers kept draining a finite 2000-offset range at 4 ms per
  poll while the test prepared the savepoint, so the job could complete
  normally before the intended partial savepoint and the test could pass
  without exercising the partial-progress path.

Fix:
- Test fixture: add the test-only options pause_after_offsets_per_split and
  resume_file. Every reader parks at a deterministic, non-terminal offset of
  its own split (1000 of 2000) and only resumes once the resume file exists.
  The gate is honoured outside the checkpoint lock, so a checkpoint barrier can
  still snapshot the parked split state and cancellation stays responsive. The
  gate defaults to disabled (-1 / empty), keeping the historical behaviour for
  the other restore ITs.
- IT: wait until the sink holds exactly the parked prefix (1000 offsets of each
  split), so the savepoint provably interrupts a half-processed input, and
  require the committed snapshot to still be exactly that prefix after
  SAVEPOINT_DONE. Assert that the savepoint stores one distinct, non-empty
  source reader state per subtask, then release the gate and restore.
- IT: the complete exactly-once oracle (exact committed-line count, no
  duplicate, no gap, exact expected offset set) is now a single helper shared by
  the parked snapshot, the pre-restore snapshot, the draining snapshot and,
  without any retry, the terminal snapshot read after FINISHED.

Verification:
- ./mvnw -o -pl seatunnel-e2e/seatunnel-e2e-common -DskipTests install
  (connector-seatunnel-e2e-base resolves the fixture from the e2e-common
  test-jar, so the changed fixture had to be reinstalled)
- ./mvnw -o -q -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base spotless:apply
  -> OK, spotless:check OK for both modules
- ./mvnw -o -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base
  -DskipTests -Dspotless.check.skip=true -Dcheckstyle.skip=true test-compile
  -> BUILD SUCCESS
- ./mvnw -o -pl seatunnel-e2e/seatunnel-engine-e2e/connector-seatunnel-e2e-base
  -Dtest=ParallelSubtaskSavepointRestoreIT -DfailIfNoTests=false test
  -> Tests run: 1, Failures: 0, Errors: 0 (4 consecutive runs, ~20 s each,
     always "saved at checkpoint ... with 2000 committed offsets, both readers
     parked mid-split")
- Negative checks, both reverted afterwards:
  one_split_per_reader=false fails with "The savepoint must hold one
  CheckpointableSequenceSource state per parallel subtask, got 1 of 2";
  injecting one replayed offset after FINISHED fails the terminal oracle with
  "committed 4001 lines" although min/max/size still looked plausible.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants