rokadepiyush49-rgb commented on issue #17961:
URL: https://github.com/apache/beam/issues/17961#issuecomment-7051082490
Hi @kennknowles, I've cloned the repo and traced this on current master
(`36fd8ac`).
**Problem**
`TriggerStateMachineRunner.isFinishedSetNeeded()` only skips the
`FINISHED_BITS` state for `DefaultTriggerStateMachine` (the TODO next to it).
Other trees whose bitset is always empty between calls still read that state on
every element and every `shouldFire`.
**What I found while tracing**
- Under `Repeatedly.forever(...)` with once-style children (`AfterPane`,
`AfterProcessingTime`, `AfterWatermark.pastEndOfWindow()`, and
`AfterFirst`/`AfterAll` of those), a child's bit is set and then cleared by
`resetTree()` in the same `onFire`. `onMerge` only sets it if a merging window
already had it set, so nothing is ever stored.
- "The root never finishes" isn't enough on its own:
- `AfterWatermark` with late firings never finishes, but the early child's
bit records the early → late switch across calls.
- `AfterEach` keeps earlier children's bits between firings.
- Since #37574, `isNew()` uses this state to tell whether a window has been
seen before when `useNewWindowOptimization` is on. Skipping it for more
triggers would quietly turn that optimisation off for them.
```mermaid
flowchart TD
S["isFinishedSetNeeded()"] --> D{"root is DefaultTrigger?"}
D -- "yes" --> SKIP["skip FINISHED_BITS (as today)"]
D -- "no" --> W{"useNewWindowOptimization?"}
W -- "yes" --> NEED["read/write bitset (as today)"]
W -- "no" --> T{"can any node keep a bit set between calls?"}
T -- "no: Repeatedly over once-style triggers" --> SKIP
T -- "yes or unknown: OrFinally, AfterEach, late AfterWatermark" --> NEED
```
**Proposed approach**
- Add a conservative recursive check in the runner (no public API change).
It returns "not needed" only for the safe shapes above and "needed" for
everything else.
- Keep the current behaviour whenever `useNewWindowOptimization` is on.
- In `TriggerStateMachineRunnerTest`, assert that
`Repeatedly.forever(AfterPane...)` never touches `FINISHED_BITS`, and that
`AfterEach`, `orFinally` and early/late `AfterWatermark` behave as before. Run
`ReduceFnRunnerTest` as a regression check.
Does that rule match what you had in mind? I saw @Moemenmohamed24 asked
about this in July. If they're not working on it, can I take this issue?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]