Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Drain Mode as WindowedValue extension #34764

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
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

stankiewicz
Copy link
Contributor

Changes:

  • new capability to runner - extended element metadata, set capability for java sdk
  • new proto definition for element metadata
  • add coder changes for windowedValue to detect and parse element metadata and vice versa, to encode them if we have them.
  • add changes to windowedValue to expose elementMetadata object (autovalue, not proto)

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: 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, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@stankiewicz
Copy link
Contributor Author

@kennknowles ptal.

Copy link
Contributor

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

R: @robertwb for label java.

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).

@@ -360,7 +387,8 @@ public PaneInfo decode(final InputStream inStream) throws CoderException, IOExce
byte keyAndTag = (byte) inStream.read();
PaneInfo base = Preconditions.checkNotNull(BYTE_TO_PANE_INFO.get((byte) (keyAndTag & 0x0F)));
long index, onTimeIndex;
switch (Encoding.fromTag(keyAndTag)) {
boolean elementMetadata = (keyAndTag & 0x80) > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
boolean elementMetadata = (keyAndTag & 0x80) > 0;
boolean elementMetadata = keyAndTag < 0;

Comment on lines 390 to 391
boolean elementMetadata = (keyAndTag & 0x80) > 0;
switch (Encoding.fromTag((byte) (keyAndTag & 0x7F))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to ignore my codegolfing...

Suggested change
boolean elementMetadata = (keyAndTag & 0x80) > 0;
switch (Encoding.fromTag((byte) (keyAndTag & 0x7F))) {
boolean elementMetadata = keyAndTag < (keyAndTag &= 0x7f);
switch (Encoding.fromTag(keyAndTag) {

Copy link

codecov bot commented Apr 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.38%. Comparing base (3b00517) to head (7e3e75a).
Report is 247 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #34764   +/-   ##
=========================================
  Coverage     56.38%   56.38%           
- Complexity     3285     3288    +3     
=========================================
  Files          1174     1174           
  Lines        179401   179407    +6     
  Branches       3398     3399    +1     
=========================================
+ Hits         101158   101164    +6     
- Misses        74983    74984    +1     
+ Partials       3260     3259    -1     
Flag Coverage Δ
java 70.50% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@kennknowles kennknowles left a comment

Choose a reason for hiding this comment

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

Largely looks good to me. I need to think about the protocol maybe slightly more. We can probably do it incrementally and get started with changes that are benign and not used yet.

One random cleanup issue (which I hit also since I'm doing similar things with WindowedValue but for different extensions) is I wonder if we can flatten all the silly inheritance in the layers of WindowedValue. For performance ultimately all that matters is whether or not we optimize the coder (such as for batch use case with no timestamps or windows we don't bother encoding min timestamp and global window). And for coding it is much better not to have such implementation inheritance that causes all this toil. Plus the anti-pattern of "superclass that just holds fields"

@sjvanrossum
Copy link
Contributor

sjvanrossum commented Apr 30, 2025

@kennknowles the default object layout on recent JVMs (64 bit, 8 bytes alignment, 12 bytes object header, compressed references and class pointers) leaves 4 bytes of padding in SimpleWindowedValue:

org.apache.beam.sdk.util.WindowedValue$SimpleWindowedValue object internals:
OFF  SZ                                                TYPE DESCRIPTION                 VALUE
  0   8                                                     (object header: mark)       N/A
  8   4                                                     (object header: class)      N/A
 12   4                                    java.lang.Object SimpleWindowedValue.value   N/A
 16   4   org.apache.beam.sdk.transforms.windowing.PaneInfo SimpleWindowedValue.pane    N/A
 20   4                                                     (object alignment gap)
Instance size: 24 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

MinTimestampWindowedValue and TimestampedValueInGlobalWindow also have the same size, but TimestampedValueInGlobalWindow packs the timestamp field in the alignment gap.

org.apache.beam.sdk.util.WindowedValue$MinTimestampWindowedValue object internals:
OFF  SZ                                                TYPE DESCRIPTION                 VALUE
  0   8                                                     (object header: mark)       N/A
  8   4                                                     (object header: class)      N/A
 12   4                                    java.lang.Object SimpleWindowedValue.value   N/A
 16   4   org.apache.beam.sdk.transforms.windowing.PaneInfo SimpleWindowedValue.pane    N/A
 20   4                                                     (object alignment gap)
Instance size: 24 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

org.apache.beam.sdk.util.WindowedValue$TimestampedValueInGlobalWindow object internals:
OFF  SZ                                                TYPE DESCRIPTION                          VALUE
  0   8                                                     (object header: mark)                N/A
  8   4                                                     (object header: class)               N/A
 12   4                                    java.lang.Object SimpleWindowedValue.value            N/A
 16   4   org.apache.beam.sdk.transforms.windowing.PaneInfo SimpleWindowedValue.pane             N/A
 20   4                               org.joda.time.Instant TimestampedWindowedValue.timestamp   N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total

And for TimestampedValueInSingleWindow and TimestampedValueInMultipleWindows it spills over into the next word (timestamp fills the alignment gap, window/windows spills into the next word):

org.apache.beam.sdk.util.WindowedValue$TimestampedValueInSingleWindow object internals:
OFF  SZ                                                     TYPE DESCRIPTION                             VALUE
  0   8                                                          (object header: mark)                   N/A
  8   4                                                          (object header: class)                  N/A
 12   4                                         java.lang.Object SimpleWindowedValue.value               N/A
 16   4        org.apache.beam.sdk.transforms.windowing.PaneInfo SimpleWindowedValue.pane                N/A
 20   4                                    org.joda.time.Instant TimestampedWindowedValue.timestamp      N/A
 24   4   org.apache.beam.sdk.transforms.windowing.BoundedWindow TimestampedValueInSingleWindow.window   N/A
 28   4                                                          (object alignment gap)
Instance size: 32 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

org.apache.beam.sdk.util.WindowedValue$TimestampedValueInMultipleWindows object internals:
OFF  SZ                                                TYPE DESCRIPTION                                 VALUE
  0   8                                                     (object header: mark)                       N/A
  8   4                                                     (object header: class)                      N/A
 12   4                                    java.lang.Object SimpleWindowedValue.value                   N/A
 16   4   org.apache.beam.sdk.transforms.windowing.PaneInfo SimpleWindowedValue.pane                    N/A
 20   4                               org.joda.time.Instant TimestampedWindowedValue.timestamp          N/A
 24   4                                java.util.Collection TimestampedValueInMultipleWindows.windows   N/A
 28   4                                                     (object alignment gap)
Instance size: 32 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

With default object layout settings the addition of an extensions field would only increase the size of TimestampedValueInGlobalWindow by 8 bytes since it would spill into the next word, all the other subclasses should pack that field into the alignment gap. I'm not sure whether users of Beam commonly disable UseCompressedPointers or UseCompressedOops, but it would seem somewhat unlikely in my opinion since both of them would generally increase memory usage.

Compile time annotation processing to produce flat extensions (without a separate extensions container,
treating timestamp, window and windows as standard extensions) of all subclasses of WindowedValue might help make this a bit more manageable. Something like the mechanism behind PipelineOptions, but at compile time and backed by fields instead of a Map<String, Object>.

@kennknowles
Copy link
Member

Stating it here so that I remember - we should write a quite 1 pager separate from the DrainMode document about the extended metadata and have a top level thread on dev@. I think more people will be interested if it is something like "Extended per-element metadata proto". It is quite an alarming title that will bring out the performance experts :-)

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.

3 participants