bhisevishal opened a new pull request, #41926:
URL: https://github.com/apache/beam/pull/41926
`AfterWatermark.pastEndOfWindow().withEarlyFirings(X)` documents that the
early trigger "fires repeatedly whenever the given `Trigger` fires". With a
composite `X`, such as `AfterFirst.of(timer, count)`, that does not hold for
runners that evaluate triggers with the state machines in `runners/core-java`,
for example the direct runner and the Dataflow legacy Java worker. After the
first early firing of a window, the early trigger fires on every later bundle,
so each bundle becomes its own pane.
**Cause.** After an early firing, `AfterWatermarkStateMachine` cleared only
the finished bit of the early subtrigger itself. The subtrigger of `AfterFirst`
(or `AfterAll`) that had fired stayed finished, and
`AfterFirstStateMachine.shouldFire` returns true as soon as any subtrigger is
finished. Late firings had the same pattern.
**Fix.** Call `resetTree()` on the early and on the late subtrigger after
each firing, as `RepeatedlyStateMachine` does. That clears the finished bits of
the whole subtrigger tree.
**Example.** One key, 62 elements in bundles of 4, session windows with a
10s gap, discarding panes, and this trigger:
```java
AfterWatermark.pastEndOfWindow()
.withEarlyFirings(
AfterFirst.of(
AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.standardMinutes(2)),
AfterPane.elementCountAtLeast(10)))
.withLateFirings(AfterPane.elementCountAtLeast(1))
```
| | Panes (number of elements) |
| :--- | :--- |
| Before | 12, then twelve panes of 4, then 2; all early |
| After | 12, 12, 12, 12, 12 early, then 2 at the end of the window |
A count-only early trigger already gives the second row. So does
`Repeatedly.forever(AfterFirst.of(AfterWatermark.pastEndOfWindow(), timer,
count))`, which works around the bug.
**Tests**
- `AfterWatermarkStateMachineTest`: new cases for `AfterFirst` and
`AfterAll` as early triggers, with fixed windows and with sessions, and for
`AfterFirst` as a late trigger.
- `SessionCompositeEarlyFiringsTest` (new): replays the burst above through
`ReduceFnRunner` with several triggers and checks the panes.
- Without the fix, `afterFirstEarlyFirings_batchesByCount` and the four new
`AfterWatermarkStateMachineTest` cases fail.
- These pass with the fix: `:runners:core-java:check`, `:rat`,
`:runners:direct-java:test`, `:runners:direct-java:needsRunnerTests` and
`:runners:google-cloud-dataflow-java:worker:test`.
**Notes for review**
- **Behavior change.** Pipelines that use a composite early or late trigger
with `AfterWatermark` on these runners emitted one pane per bundle after the
first firing. With this change they emit panes when the composite trigger is
ready again.
- **Not changed.** The firing at the end of the window.
- **Issue.** There is no GitHub issue for this yet.
--
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]