Skip to content

[Spark] Support splittable DoFn self-checkpointing in portable batch - #39331

Open
Eliaaazzz wants to merge 1 commit into
apache:masterfrom
Eliaaazzz:spark-portable-sdf
Open

[Spark] Support splittable DoFn self-checkpointing in portable batch#39331
Eliaaazzz wants to merge 1 commit into
apache:masterfrom
Eliaaazzz:spark-portable-sdf

Conversation

@Eliaaazzz

@Eliaaazzz Eliaaazzz commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Addresses #19468 for batch.

The problem

The portable Spark runner never passed a BundleCheckpointHandler to StageBundleFactory.getBundle, so a splittable DoFn that returns ProcessContinuation.resume() failed on its first bundle. Several SDF tests were skipped for this runner as a result.

The change

A batch stage containing a splittable DoFn now holds each residual in memory under a processing time timer, using the existing BundleCheckpointHandlers.StateAndTimerBundleCheckpointHandler with InMemoryTimerInternals and InMemoryStateInternals. This is the same model the portable Flink batch runner uses in FlinkExecutableStageFunction. Once the stage has drained its inputs, processing time advances to infinity and the held residuals are replayed until the SDK stops asking to resume, so a bounded restriction always runs out.

In the branch that also has user timers, the two drains alternate, since a replayed residual could set a timer and a fired timer could produce a residual. The fuser does not appear to produce a stage holding both today, so that loop is defensive.

What is deliberately still unsupported

  • Streaming self-checkpointing. A residual has nowhere to live across micro-batches, so the streaming path rejects it with a message naming Spark portable runner: support SDF #19468. This replaces today's failure with a clearer one rather than changing behaviour.
  • Unbounded splittable DoFn, which needs the above. UsesUnboundedSplittableParDo stays excluded and test_unbounded_source_read stays skipped.
  • Bundle finalization (Spark portable runner: support Bundle Finalization #19517). It is now rejected explicitly rather than run early: InMemoryFinalizer is documented to run after the runner has durably committed the bundle's output, which this runner cannot report. The portable Flink batch runner rejects it the same way. UsesBundleFinalizer stays excluded.

I had an earlier revision of this PR that also added a driver-side relay to carry residuals across micro-batches in streaming. I took it out: it depended on the staged RDD executing exactly once, which persist(MEMORY_ONLY) does not guarantee, and its watermark could stall for a stage that emits output without ever checkpointing. That is worth doing properly rather than approximately, so it is left for follow-up.

Testing

SparkExecutableStageFunctionTest.sdfResidualsAreReplayedUntilDrained drives a stage whose first bundle self-checkpoints with one residual and whose replay bundle returns none, and asserts that the original element and then the residual both reach the input receiver. It fails if the replay loop is short-circuited.

Unskips the bounded SDF tests in spark_runner_test.py and removes the UsesBoundedSplittableParDo exclusion from the portable ValidatesRunner task.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.76%. Comparing base (de21b1c) to head (b1428e7).

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #39331   +/-   ##
=========================================
  Coverage     54.76%   54.76%           
  Complexity     1716     1716           
=========================================
  Files          1066     1066           
  Lines        169075   169075           
  Branches       1255     1255           
=========================================
+ Hits          92589    92591    +2     
+ Misses        74269    74267    -2     
  Partials       2217     2217           
Flag Coverage Δ
python 79.71% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Eliaaazzz
Eliaaazzz force-pushed the spark-portable-sdf branch 2 times, most recently from 17df8a3 to d99c843 Compare July 15, 2026 14:25
@Eliaaazzz
Eliaaazzz force-pushed the spark-portable-sdf branch from d99c843 to 17970a7 Compare July 27, 2026 13:40
The portable Spark runner never passed a BundleCheckpointHandler to
StageBundleFactory.getBundle, so a splittable DoFn that self-checkpoints
failed on its first bundle and could not run at all.

In batch, a stage containing a splittable DoFn now holds each residual in
memory under a processing time timer, the way the portable Flink batch
runner does. Once the stage has drained its inputs, processing time
advances to infinity and the held residuals are replayed until the SDK
stops asking to resume, so a bounded restriction always runs out.

Streaming keeps rejecting self-checkpointing, with a message naming the
issue, since a residual has nowhere to live across micro-batches. Bundle
finalization is likewise rejected rather than run early, since this
runner cannot report that a bundle's output is durably committed.

Unskips the bounded splittable DoFn tests for the Spark runner.
@Eliaaazzz
Eliaaazzz force-pushed the spark-portable-sdf branch from 17970a7 to 6d61105 Compare August 2, 2026 15:03
@Eliaaazzz Eliaaazzz changed the title [Spark] Support SDF self-checkpointing and bundle finalization on the portable runner [Spark] Support splittable DoFn self-checkpointing in portable batch Aug 2, 2026
@Eliaaazzz
Eliaaazzz marked this pull request as ready for review August 2, 2026 15:03
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

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.

1 participant