Skip to content

[DebeziumIO] Implement startOffset for Kafka (#28248)#37750

Draft
tkaymak wants to merge 4 commits intoapache:masterfrom
tkaymak:fix_debezium_allow_offset
Draft

[DebeziumIO] Implement startOffset for Kafka (#28248)#37750
tkaymak wants to merge 4 commits intoapache:masterfrom
tkaymak:fix_debezium_allow_offset

Conversation

@tkaymak
Copy link
Contributor

@tkaymak tkaymak commented Mar 3, 2026

Implement withStartOffset for Debezium to handle restarts. (Addresses #28248)

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial startOffset capability to DebeziumIO, allowing users to define a specific point for Debezium connectors to begin or resume data consumption. This enhancement is vital for building resilient data pipelines that can recover from failures or planned shutdowns without losing data or re-processing unnecessary events. The implementation spans across the Go, Java, and Python SDKs, providing a unified experience for managing change data capture streams.

Highlights

  • DebeziumIO Start Offset Implementation: Introduced a startOffset feature for DebeziumIO in both Go and Java SDKs, allowing users to specify a point from which the Debezium connector should resume consuming changes.
  • Cross-language Compatibility: The startOffset functionality is integrated across the Go, Java, and Python SDKs, ensuring consistent behavior for DebeziumIO users regardless of their chosen language.
  • Offset Parsing and Handling: The Java SDK now includes logic to parse startOffset values provided as key-value strings, automatically converting numeric parts to Long where appropriate, facilitating flexible offset specification.
  • Improved Restart Capabilities: This feature significantly enhances the robustness of Debezium-based pipelines by enabling them to gracefully restart from a known good state, preventing reprocessing of already handled data.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • sdks/go/pkg/beam/io/xlang/debeziumio/debezium.go
    • Added StartOffset field to the readFromDebeziumSchema struct to hold offset configuration.
    • Implemented a new StartOffset function that serves as a read option to configure the starting offset for the Debezium connector.
  • sdks/java/io/debezium/src/main/java/org/apache/beam/io/debezium/DebeziumIO.java
    • Added getStartOffset and setStartOffset abstract methods to the Read and Builder classes, respectively, to manage the new offset property.
    • Introduced the withStartOffset builder method, allowing users to specify a map of key-value pairs representing the desired starting offset for the Debezium connector, complete with detailed Javadoc.
  • sdks/java/io/debezium/src/main/java/org/apache/beam/io/debezium/DebeziumTransformRegistrar.java
    • Imported HashMap for map manipulation.
    • Added a startOffset field to the Configuration class and its corresponding setter method.
    • Implemented logic within buildExternal to parse the list of startOffset strings into a Map<String, Object>, converting numeric values to Long where applicable, before applying it to the readTransform.
  • sdks/java/io/debezium/src/main/java/org/apache/beam/io/debezium/KafkaSourceConsumerFn.java
    • Modified the getInitialRestriction method to pass the newly introduced startOffset from the spec to the OffsetHolder.
  • sdks/java/io/debezium/src/test/java/org/apache/beam/io/debezium/DebeziumIOTest.java
    • Added static imports for assertEquals and assertNull.
    • Imported ImmutableMap for easier map creation in tests.
    • Included new test cases to verify that withStartOffset correctly stores the offset, handles null offsets, throws exceptions for invalid null input, and that getInitialRestriction properly utilizes the provided start offset.
  • sdks/python/apache_beam/io/debezium.py
    • Imported Dict and Union from typing.
    • Extended ReadFromDebeziumSchema to include an optional start_offset field, defined as a list of strings.
    • Updated the ReadFromDebezium constructor to accept a start_offset parameter and included comprehensive documentation for its usage and format.
    • Passed the start_offset parameter to the ReadFromDebeziumSchema during initialization.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

Assigning reviewers:

R: @tvalentyn for label python.
R: @ahmedabu98 for label java.
R: @jrmccluskey for label go.

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

@tvalentyn
Copy link
Contributor

Hi @an2x @johnjcasey @Dippatel98 - could you please help find a reviewer for this? Thanks

@tkaymak
Copy link
Contributor Author

tkaymak commented Mar 3, 2026

@tvalentyn maybe @Abacn can have a look (?)

@Abacn
Copy link
Contributor

Abacn commented Mar 4, 2026

Thanks, this change allows user to provide an offset that was obtained elsewhere. It now supports to read from an offset, yet not completely resolve #28248, as restarting the pipeline that have set the offset would still start from the same offset.

I had a (yet materialized) idea of restartable offset. Basically we can provide an "OffsetRetainer" interface to 1. read offset on pipeline startup; 2. write offset on checkpointing, and expose as a configuration for the IO. And we can then provide a built-in FileSystem based OffsetRetainer for user to use.

When pipeline is running, it continuously write committed offset to external location (gcs, kafka, etc) of choice; when pipeline starts or restarts, it tries to read from the same location at first.

If you prefer to go for current change for now, let me take a closer look for this PR. Or we can work on a more concrete solution.

@tkaymak
Copy link
Contributor Author

tkaymak commented Mar 4, 2026

@Abacn thank you for comment. I think your solution sounds like a much better vision, and we should aim for that.

@tkaymak tkaymak marked this pull request as draft March 4, 2026 08:34
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