Repository navigation
[FileWrites] Implementing evictWritersWhenFull option in WriteFiles - #40200
Merged
Merged
Conversation
damccorm
reviewed
Sep 21, 2026
Contributor
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
damccorm
approved these changes
Sep 21, 2026
damccorm
left a comment
Contributor
There was a problem hiding this comment.
Thanks - rerunning a failed precommit (I think it was just a flake) before merging
Contributor
|
Assigning reviewers: R: @Abacn 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 Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Merged
3 tasks
kennknowles
pushed a commit
that referenced
this pull request
Sep 22, 2026
kennknowles
added a commit
that referenced
this pull request
Sep 22, 2026
…evictWritersWhenFull option in WriteFiles (#40200)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Java SDK - FileIO] Add
withEvictWritersWhenFulloption toWriteFilesSummary & Motivation
When
WriteFilesis configured with runner-determined sharding (WriteUnshardedBundlesToTempFiles), each bundle caps the number of concurrently open writers atmaxNumWritersPerBundle(DEFAULT_MAX_NUM_WRITERS_PER_BUNDLE = 20) to bound worker memory usage (for example, each GCS writer allocates up to a 64 MB upload buffer by default).Currently, when a bundle encounters more distinct writer keys
(window, pane, destination)thanmaxNumWritersPerBundle,WriteFilesonly offers two choices:maxNumWritersPerBundlewriters in the bundle are emitted tounwrittenRecordsTagand routed through an extraGroupByKeyshuffle stage (GroupUnwritten->WriteUnwritten->DropShardNum->Flatten).withNoSpilling(): Eliminates theGroupUnwrittenshuffle stage by settingmaxNumWritersPerBundle = -1, which allows an unbounded number of concurrent writers per bundle and risks worker OOMs when writing to many dynamic destinations.In pipelines where the input
PCollectionwithin a bundle is already grouped or ordered by writer key (e.g., upstreamGroupByKey/Reshuffleby destination or table), a writer for an earlier destination is completely finished once the bundle moves on to the next destination. Keeping those 20 finished writers open until@FinishBundleforces all subsequent destinations in the bundle to spill over a secondGroupByKeyshuffle while holding 20 idle writer buffers in memory.This PR introduces
WriteFiles.withEvictWritersWhenFull()/WriteFiles.withEvictWritersWhenFull(boolean). When enabled, reachingmaxNumWritersPerBundleevicts the oldest open writer in the bundle in FIFO order (flushing and closing its temporary file and releasing its buffer) and opens a new writer inline, completely avoiding theGroupUnwrittenshuffle spill stage while strictly bounding concurrent writer memory tomaxNumWritersPerBundle.Changes Made
WriteFiles:getEvictWritersWhenFull()(defaulting tofalse),withEvictWritersWhenFull(), andwithEvictWritersWhenFull(boolean evictWritersWhenFull).<p><b>Warning:</b>in the Javadocs explaining that this option should only be used when the inputPCollectionelements within a bundle are grouped or ordered by writer keys (destination/window/pane), and warning that randomly ordered inputs across more destinations thanmaxNumWritersPerBundlewill repeatedly close and reopen writers, producing many small files.WriteUnshardedBundlesToTempFiles.expand:if (getMaxNumWritersPerBundle() < 0 || getEvictWritersWhenFull())so that when writer eviction is enabled, theGroupUnwritten(GroupByKey),WriteUnwritten,DropShardNum, andFlattentransforms are omitted from the pipeline graph.maxNumWritersPerBundleand allowed it to be set to more than 20 (DEFAULT value).Testing (
WriteFilesTest)Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
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, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.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
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.