Skip to content

[Iceberg CDC sink] Split late data and create commit windows - #40006

Merged
ahmedabu98 merged 3 commits into
apache:masterfrom
ahmedabu98:cdc-commit-windows
Sep 14, 2026
Merged

ahmedabu98 merged 3 commits into
apache:masterfrom
ahmedabu98:cdc-commit-windows

Conversation

@ahmedabu98

@ahmedabu98 ahmedabu98 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Adds the CDC sink's windowing stage:

  • CommitWindows groups each destination's keyed changes into event-time commit windows and sorts them by primary key and sequence number via SortValues transform
  • SplitLateData diverts every late pane to a replayable dead-letter output instead of letting it reach a window the committer may already have sealed.

Part of #39979


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.

@ahmedabu98 ahmedabu98 changed the title [Iceberg] Split late data and create commit windows [Iceberg CDC sink] Split late data and create commit windows Sep 3, 2026
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @chamikaramj for label java.

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

@chamikaramj chamikaramj left a comment

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.

Thanks!

*/
final class CommitWindows
extends PTransform<
PCollection<KV<KV<String, Integer>, KV<byte[], CdcRecord>>>, CommitWindows.Result> {

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.

PCollection<KV<KV<String, Integer>, KV<byte[], CdcRecord>>> is pretty hard to follow.

Shall we introduce new types to simplify this ? For example,

ShardIdentifier -> KV<String, Integer>

SortKeyAndRecord -> KV<byte[], CdcRecord>

Alternatively we can use Beam Rows or AutoValue classes with schema here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added DestinationShard instead of KV<String, Integer>.

Doing SortKeyAndRecord would be a little more complicated since the SortValues transform requires the value part to be of type KV<byte[], Object>. We can technically add adapters before/after to convert from SortKeyAndRecord to KV<byte[], CdcRecord> and back, but it would need an additional custom coder and I don't think is necessary

return new Result(input.getPipeline(), sorted, deadLetter, deadLetterSchema);
}

/** Applies the commit-window assignment for the input's boundedness; see the class Javadoc. */

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.

for the input's boundedness -> based on whether input is bounded or not ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Commit-window assignment is applied in both cases. Added some more language to clarify


/**
* Splits late data in {@link CommitWindows}: every {@linkplain PaneInfo.Timing#LATE late} pane is
* diverted to a DLQ side output; on-time and early panes pass through unchanged.

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.

We can't actually commit late data instead of sending to DLQ ? (probably reasonable but just to double check).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, if we let late data through to the commit stage, it'll just get skipped since its window would have already been committed. Better to capture it here and provide it in the DLQ

Coder<?> valueCoder = ((KvCoder<?, ?>) inputCoder).getValueCoder();
checkArgument(
valueCoder instanceof KvCoder, "expected a KvCoder input value coder, got %s", valueCoder);
Coder<?> recordCoder = ((KvCoder<?, ?>) valueCoder).getValueCoder();

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.

This kind of casts can be brittel and can be avoided by introducing new types as mentioned in the other comment I believe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Introducing a new SortKeyAndRecord type will also need its own custom coder, which we'll still have to extract here using casting.

onTimeUnsorted.apply(
"SortBySeqKind",
SortValues.create(
BufferedExternalSorter.options().withMemoryMB(config.getSorterMemoryMB())));

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.

This could lead to OOMs since we are sorting entire windows per shard. Let's make sure there's enough memory for the default case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In-memory usage of the sorter is controlled by config.getSorterMemoryMB(). Anything over that is spilled over into on-disk files. I used 100MB because that's already the default in BufferedExternalSorter. We're just re-using it here and allowing the user to override.

"EventTimeWindows",
Window.<KV<KV<String, Integer>, KV<byte[], CdcRecord>>>into(
FixedWindows.of(
checkStateNotNull(

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.

Do this check early ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes it will be checked earlier in the top-level class (coming in a later PR)

@github-actions github-actions Bot added iceberg Iceberg IO connector and removed iceberg Iceberg IO connector labels Sep 14, 2026
@ahmedabu98

Copy link
Copy Markdown
Contributor Author

Thanks @chamikaramj, can you PTAL?

@ahmedabu98
ahmedabu98 merged commit 544e40f into apache:master Sep 14, 2026
23 checks passed
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