Conversation
…BundleHandler to where StateAppendRequest and StateGetRequest are constructed
Summary of ChangesHello @LEEKYE, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Apache Beam Fn Harness by introducing mechanisms to optimize state management for stateful DoFns. It allows the runner to signal whether a bundle has no initial state or if it's the final bundle for specific keys, meaning no further state needs to be committed. By propagating these flags, the system can intelligently skip unnecessary state read and write operations, improving efficiency for certain stateful processing scenarios. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an optimization to skip state get and append operations based on hints from the runner, has_no_state and only_bundle_for_keys. The changes correctly propagate these flags through various layers of the state management code. However, I've identified a few areas where these new flags are not fully utilized, potentially leading to missed optimizations. Specifically, MultimapUserState and OrderedListUserState do not seem to use onlyBundleForKeys to skip append operations, and CachingStateIterable doesn't propagate hasNoState to its underlying iterator, which would prevent skipping state fetches. Addressing these points will ensure the optimization is fully effective.
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/MultimapUserState.java
Show resolved
Hide resolved
| boolean hasNoState, | ||
| boolean onlyBundleForKeys) { |
There was a problem hiding this comment.
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java
Show resolved
Hide resolved
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
/gemini review |
There was a problem hiding this comment.
Code Review
The pull request correctly introduces optimizations to skip state requests when the runner indicates that no state exists or that the current bundle is the only one for the given keys. However, there is a critical bug in StateFetchingIterators.java where has_no_state can lead to a NullPointerException. Additionally, the only_bundle_for_keys optimization is missing in OrderedListUserState.java and can be made more efficient in BagUserState.java.
| LazyBlockingStateFetchingIterator( | ||
| BeamFnStateClient beamFnStateClient, StateRequest stateRequestForFirstChunk, | ||
| boolean hasNoState) { | ||
| this.beamFnStateClient = beamFnStateClient; | ||
| this.stateRequestForFirstChunk = stateRequestForFirstChunk; | ||
| this.continuationToken = stateRequestForFirstChunk.getGet().getContinuationToken(); | ||
| this.hasNoState = hasNoState; | ||
| } |
There was a problem hiding this comment.
If hasNoState is true, the continuationToken should be initialized to null. This ensures that hasNext() returns false and prevents next() from being called. Currently, if hasNoState is true, continuationToken is still initialized from the request, hasNext() returns true, and next() eventually throws a NullPointerException because prefetchedResponse is never initialized in prefetch().
| LazyBlockingStateFetchingIterator( | |
| BeamFnStateClient beamFnStateClient, StateRequest stateRequestForFirstChunk, | |
| boolean hasNoState) { | |
| this.beamFnStateClient = beamFnStateClient; | |
| this.stateRequestForFirstChunk = stateRequestForFirstChunk; | |
| this.continuationToken = stateRequestForFirstChunk.getGet().getContinuationToken(); | |
| this.hasNoState = hasNoState; | |
| } | |
| LazyBlockingStateFetchingIterator( | |
| BeamFnStateClient beamFnStateClient, StateRequest stateRequestForFirstChunk, | |
| boolean hasNoState) { | |
| this.beamFnStateClient = beamFnStateClient; | |
| this.stateRequestForFirstChunk = stateRequestForFirstChunk; | |
| this.continuationToken = | |
| hasNoState ? null : stateRequestForFirstChunk.getGet().getContinuationToken(); | |
| this.hasNoState = hasNoState; | |
| } |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an optimization to omit state commits for stateful DoFns by propagating has_no_state and only_bundle_for_keys flags. The changes are well-propagated through the state management classes.
My main concern is a potential NullPointerException in LazyBlockingStateFetchingIterator when has_no_state is true, which I've detailed in a comment. I've also suggested a minor simplification that can be applied after fixing the bug.
Otherwise, the logic to skip state reads and writes based on these new flags seems correct across the different state implementations (BagUserState, MultimapUserState, OrderedListUserState).
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java
Show resolved
Hide resolved
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java
Outdated
Show resolved
Hide resolved
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an optimization to omit state commits for stateful DoFns when the runner indicates it's not necessary, using two new flags: has_no_state and only_bundle_for_keys. The changes correctly propagate these flags from ProcessBundleHandler down to the various state management classes.
The implementation for skipping state fetches (has_no_state) and state appends (only_bundle_for_keys) looks good. However, I've found a few inconsistencies where state clears are not being skipped when only_bundle_for_keys is true. This could lead to unnecessary RPCs to the runner. I've left comments in BagUserState, MultimapUserState, and OrderedListUserState to address this. I also found a minor performance improvement opportunity in BagUserState to avoid unnecessary encoding.
Overall, this is a valuable optimization, and with the suggested fixes, it will be more robust and consistent.
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/BagUserState.java
Outdated
Show resolved
Hide resolved
|
|
||
| // Persist pending key-values | ||
| if (!pendingAdds.isEmpty()) { | ||
| if (!pendingAdds.isEmpty() && !onlyBundleForKeys) { |
| if (onlyBundleForKeys) { | ||
| pendingAdds.clear(); | ||
| return; | ||
| } |
There was a problem hiding this comment.
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/BagUserState.java
Outdated
Show resolved
Hide resolved
|
R: @apanich |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
|
assign set of reviewers |
|
Assigning reviewers: R: @Abacn for label java. 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). |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an optimization to omit state get/append operations in stateful DoFns by propagating has_no_state and only_bundle_for_keys flags. The changes are well-contained and consistently applied across various state management classes. The logic to skip state operations based on these flags appears correct. As noted in the description, adding comprehensive unit tests will be essential to validate these optimizations and prevent any potential regressions.
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/BagUserState.java
Show resolved
Hide resolved
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/state/StateFetchingIterators.java
Outdated
Show resolved
Hide resolved
…te/StateFetchingIterators.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.