-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Use trigger state to know if a window is new and optimize reads #37574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arunpandianp
wants to merge
22
commits into
apache:master
Choose a base branch
from
arunpandianp:MArkNewWindow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
28957f5
Use trigger state to know if a window is new
arunpandianp b24494f
Change TriggerState finished bitset coder to a SentinelBitSetCoder
arunpandianp a4ff2c6
fix style
arunpandianp c55b4cb
fix style
arunpandianp cf5050e
fix style
arunpandianp 848617b
fix style
arunpandianp 493fa8f
fix style
arunpandianp 0d929f1
address comment
arunpandianp 3ffeca7
Merge branch 'sentinelbitsetcoder' into MArkNewWindow
arunpandianp c1e0eba
Merge remote-tracking branch 'beam/master' into MArkNewWindow
arunpandianp 55b300c
add tests and improve setKnownEmpty
arunpandianp 8ffe18b
doc fix
arunpandianp ae4a5b2
improve persist
arunpandianp 64f8899
improve persist
arunpandianp de2a32e
Enable isNewWindowOptimization on non merging windows only
arunpandianp 3d8f6c5
Add todo to prevent global window state growth
arunpandianp 9bb4861
spotless
arunpandianp b2c9e74
Merge remote-tracking branch 'beam/master' into MArkNewWindow
arunpandianp 168431d
Address comments
arunpandianp ba4766f
Refactor
arunpandianp ebb5d6f
Trigger validate runner
arunpandianp 3650cfc
Fix conflict & add todo
arunpandianp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.github/trigger_files/beam_PostCommit_Java_ValidatesRunner_Dataflow_Streaming.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run!", | ||
| "modification": 7, | ||
| "modification": 1, | ||
| } |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,13 +63,16 @@ public class TriggerStateMachineRunner<W extends BoundedWindow> { | |
|
|
||
| private final ExecutableTriggerStateMachine rootTrigger; | ||
| private final TriggerStateMachineContextFactory<W> contextFactory; | ||
| private final boolean useNewWindowOptimization; | ||
|
|
||
| public TriggerStateMachineRunner( | ||
| ExecutableTriggerStateMachine rootTrigger, | ||
| TriggerStateMachineContextFactory<W> contextFactory) { | ||
| TriggerStateMachineContextFactory<W> contextFactory, | ||
| boolean useNewWindowOptimization) { | ||
| checkState(rootTrigger.getTriggerIndex() == 0); | ||
| this.rootTrigger = rootTrigger; | ||
| this.contextFactory = contextFactory; | ||
| this.useNewWindowOptimization = useNewWindowOptimization; | ||
| } | ||
|
|
||
| private FinishedTriggersBitSet readFinishedBits(ValueState<BitSet> state) { | ||
|
|
@@ -81,9 +84,11 @@ private FinishedTriggersBitSet readFinishedBits(ValueState<BitSet> state) { | |
| } | ||
|
|
||
| @Nullable BitSet bitSet = state.read(); | ||
| return bitSet == null | ||
| ? FinishedTriggersBitSet.emptyWithCapacity(rootTrigger.getFirstIndexAfterSubtree()) | ||
| : FinishedTriggersBitSet.fromBitSet(bitSet); | ||
| if (bitSet == null) { | ||
| return FinishedTriggersBitSet.emptyWithCapacity(rootTrigger.getFirstIndexAfterSubtree()); | ||
| } | ||
|
|
||
| return FinishedTriggersBitSet.fromBitSet(bitSet); | ||
| } | ||
|
|
||
| private void clearFinishedBits(ValueState<BitSet> state) { | ||
|
|
@@ -99,19 +104,29 @@ public boolean isClosed(StateAccessor<?> state) { | |
| return readFinishedBits(state.access(FINISHED_BITS_TAG)).isFinished(rootTrigger); | ||
| } | ||
|
|
||
| public void prefetchIsClosed(StateAccessor<?> state) { | ||
| /** Return true if the window is new (no trigger state has ever been persisted). */ | ||
| public boolean isNew(StateAccessor<?> state) { | ||
| return isFinishedSetNeeded() && state.access(FINISHED_BITS_TAG).read() == null; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| public BitSet getFinishedBits(StateAccessor<?> state) { | ||
| return readFinishedBits(state.access(FINISHED_BITS_TAG)).getBitSet(); | ||
| } | ||
|
|
||
| public void prefetchFinishedSet(StateAccessor<?> state) { | ||
| if (isFinishedSetNeeded()) { | ||
| state.access(FINISHED_BITS_TAG).readLater(); | ||
| } | ||
| } | ||
|
|
||
| public void prefetchForValue(W window, StateAccessor<?> state) { | ||
| prefetchIsClosed(state); | ||
| prefetchFinishedSet(state); | ||
| rootTrigger.invokePrefetchOnElement(contextFactory.createPrefetchContext(window, rootTrigger)); | ||
| } | ||
|
|
||
| public void prefetchShouldFire(W window, StateAccessor<?> state) { | ||
| prefetchIsClosed(state); | ||
| prefetchFinishedSet(state); | ||
| rootTrigger.invokePrefetchShouldFire(contextFactory.createPrefetchContext(window, rootTrigger)); | ||
| } | ||
|
|
||
|
|
@@ -180,13 +195,23 @@ public void onFire(W window, Timers timers, StateAccessor<?> state) throws Excep | |
| persistFinishedSet(state, finishedSet); | ||
| } | ||
|
|
||
| private void persistFinishedSet( | ||
| StateAccessor<?> state, FinishedTriggersBitSet modifiedFinishedSet) { | ||
| @VisibleForTesting | ||
| void persistFinishedSet(StateAccessor<?> state, FinishedTriggersBitSet modifiedFinishedSet) { | ||
| if (!isFinishedSetNeeded()) { | ||
| return; | ||
| } | ||
|
|
||
| ValueState<BitSet> finishedSetState = state.access(FINISHED_BITS_TAG); | ||
|
|
||
| if (useNewWindowOptimization) { | ||
| if (finishedSetState.read() == null | ||
| || !readFinishedBits(finishedSetState).equals(modifiedFinishedSet)) { | ||
| // Write a value even if the bitset was empty | ||
| finishedSetState.write(modifiedFinishedSet.getBitSet()); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (!readFinishedBits(finishedSetState).equals(modifiedFinishedSet)) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: before this PR this check always returned true due to equals method missing in FinishedTriggersBitSet. With the added equals method, won't be writing finishedSetState every time. |
||
| if (modifiedFinishedSet.getBitSet().isEmpty()) { | ||
| finishedSetState.clear(); | ||
|
|
||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.