Skip to content

[Java] Bound pending Watch results per poll - #40294

Open
goutamadwant wants to merge 5 commits into
apache:masterfrom
goutamadwant:bound-watch-pending-results-v2
Open

goutamadwant wants to merge 5 commits into
apache:masterfrom
goutamadwant:bound-watch-pending-results-v2

Conversation

@goutamadwant

Copy link
Copy Markdown
Contributor

Addresses the remaining Java pending-result scalability item in #18459.

Watch currently keeps every distinct unseen output from a poll in checkpointed pending restriction state. A very large poll can therefore create an oversized state value.

What changes

  • Adds the opt-in Watch.Growth.withMaxPendingResults(int) API.
  • For finite, repeatable incomplete polls, keeps at most the configured number of oldest unseen outputs as pending work in each round.
  • Holds the watermark at or before the earliest omitted output and continues polling until omitted work can be recovered.
  • Defers a configured termination condition while a poll is truncated, avoiding silent loss of omitted outputs.
  • Preserves the existing first-output behavior for duplicate output keys.
  • Never limits PollResult.complete(), because its contract promises that the polling function will not be called again.

Compatibility and scope

The option is disabled by default, so existing pipelines retain their current behavior. It does not change the restriction coder or persisted state format.

When enabled, the PollFn must repeat omitted outputs in subsequent polls and must eventually return a finite set that can drain below the limit. A function that continuously returns more distinct unseen outputs than the limit can keep polling indefinitely; the API documentation and runtime logging make this behavior explicit.

The option bounds checkpointed pending outputs. It does not bound the list constructed by the polling function, transient hashes used during selection, or completed keys sharing a retained timestamp. It can be combined with withTimestampCursor() to time-bound completed-key state when output timestamps advance past the retention floor.

This PR covers the Java SDK. Equivalent Python behavior can be tracked separately.

Validation

  • :sdks:java:core:test --tests 'org.apache.beam.sdk.transforms.WatchTest' --no-build-cache --rerun-tasks - 30 tests passed
  • :runners:direct-java:needsRunnerTests --tests 'org.apache.beam.sdk.transforms.WatchTest.testManyResultsWithPendingLimit' --no-build-cache --rerun-tasks - passed; recovered 300 outputs over three bounded rounds
  • :sdks:java:core:checkstyleMain
  • :sdks:java:core:checkstyleTest
  • :sdks:java:core:spotlessJavaCheck
  • :sdks:java:core:javadoc
  • :sdks:java:core:spotbugsMain

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

See the Contributor Guide for more tips on making the review process smoother.

To check the build health, see BUILD_STATUS.md. See CI.md and the workflows README for GitHub Actions details and workflow triggers.

@github-actions

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@goutamadwant

Copy link
Copy Markdown
Contributor Author

retest this please

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @chamikaramj for label java.

This pull request likely touches a core component ("core" label). Please review with scrutiny.

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

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @chamikaramj

@github-actions

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @kennknowles for label java.

This pull request likely touches a core component ("core" label). Please review with scrutiny.

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)

@kennknowles kennknowles 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.

This is complex code that I don't know very well, so review will take some time. There may be someone better to review, but I am not sure.

* when output timestamps advance past the retention floor. It does not impose a count bound on
* completed keys that share a timestamp still at or above that floor.
*/
public Growth<InputT, OutputT, KeyT> withMaxPendingResults(int maxPendingResults) {

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.

This should be @Nullable Integer or otherwise have a way of explicitly indicating it is unset.

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @kennknowles @chamikaramj

@derrickaw

Copy link
Copy Markdown
Collaborator

Hi @goutamadwant, friendly ping to resolve merge conflicts and address one comment so far. Thanks

@goutamadwant

Copy link
Copy Markdown
Contributor Author

done @derrickaw
@kennknowles changed it to @Nullable Integer so null clears the limit. let me know if this looks good now! thanks

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @kennknowles @chamikaramj

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.04%. Comparing base (a8d6afd) to head (56e6eda).
⚠️ Report is 628 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40294      +/-   ##
==========================================
- Coverage   80.04%   80.04%   -0.01%     
==========================================
  Files         490      490              
  Lines       82916    82888      -28     
==========================================
- Hits        66373    66350      -23     
+ Misses      16543    16538       -5     

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

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @kennknowles @chamikaramj

@github-actions

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @Abacn for label java.
Backup reviewer: damccorm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

This pull request likely touches a core component ("core" label). Please review with scrutiny.

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)

@github-actions
github-actions Bot requested a review from Abacn November 10, 2026 12:26
@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @Abacn @chamikaramj

@github-actions

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @kennknowles for label java.
Backup reviewer: ahmedabu98 (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

This pull request likely touches a core component ("core" label). Please review with scrutiny.

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)

@github-actions github-actions Bot added the size/m M: 50-249 lines changed label Nov 29, 2026
@goutamadwant

Copy link
Copy Markdown
Contributor Author

I pushed 49c2e48b to resolve the changelog conflict. The Watch code and tests are unchanged.

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.

3 participants