Skip to content

Fix DataflowOutputCounter calculation for ValueInEmptyWindows - #39487

Open
shunping wants to merge 3 commits into
apache:masterfrom
shunping:fix-gbk-metrics
Open

Fix DataflowOutputCounter calculation for ValueInEmptyWindows#39487
shunping wants to merge 3 commits into
apache:masterfrom
shunping:fix-gbk-metrics

Conversation

@shunping

Copy link
Copy Markdown
Collaborator

When processing shuffle or streaming data in Dataflow Legacy Runner (e.g., from GroupingShuffleReader or WindowingWindmillReader), KeyedWorkItems are wrapped inside a ValueInEmptyWindows (windows.size() == 0).

Previously, DataflowOutputCounter.update() counted these as 1 element. This caused inaccurate element counts because:

  1. A KeyedWorkItem can contain multiple elements.
  2. Elements may belong to multiple windows and need to be fanned out accordingly.
  3. KeyedWorkItems containing only timers were incorrectly incrementing element counters.

Internal bug id: 509652238

When processing shuffle or streaming data in Dataflow Legacy Runner
(e.g., from GroupingShuffleReader or WindowingWindmillReader),
KeyedWorkItems are wrapped inside a ValueInEmptyWindows (windows.size() == 0).

Previously, DataflowOutputCounter.update() counted these as 1 element.
This caused inaccurate element counts because:
1. A KeyedWorkItem can contain multiple elements.
2. Elements may belong to multiple windows and need to be fanned out accordingly.
3. KeyedWorkItems containing only timers were incorrectly incrementing element counters.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@shunping
shunping marked this pull request as ready for review July 25, 2026 03:57
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@shunping
shunping requested a review from scwhittle July 25, 2026 03:57
KeyedWorkItem<?, ?> keyedWorkItem = (KeyedWorkItem<?, ?>) value;
long totalElementCount = 0;
// Iterate only through elementsIterable and ignore timers in KeyedWorkItem.
for (WindowedValue<?> element : keyedWorkItem.elementsIterable()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned this might hurt performance by adding another decoding of all the input

WindmillKeyedWorkItem is decoding as it iterates so the extra iteration is going to redecode everything. We could change WindmillKeyedWorkItem to decode once and cache, but that might have unintended effects as well since we are changing from keeping 1 element decoded in memory at time to all of them decoded at once.

This case and the extra iteration in ReduceFnRunner are just trying to observe the windows. We could optimize those by extending KeyedWorkItem interface to include a new
Iterable<WindowedValue<?>> elementWindowsIterable().
A default impl could just to retun elementsIterable().
But WindmillKeyedWorkItem could return a cheaper iterable that skips decoding the values, just the window metadata. And we could use the new method here and in ReduceFnRunner when we are collecting the windows.

Thoughts? @kennknowles if other ideas for interface

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey added as fallback since no labels match configuration

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants