-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add Support for Kafka Connect commit validation #14506
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
Conversation
|
@kumarpritam863 you might be interested in this PR also |
| private Snapshot latestSnapshot(TableMetadata metadata, String branch) { | ||
| if (branch == null) { | ||
| return metadata.currentSnapshot(); | ||
| } | ||
| return metadata.snapshot(metadata.ref(branch).snapshotId()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we can move this to SnapshotUtil
|
|
||
| private Map<Integer, Long> lastCommittedOffsetsForTable(TableMetadata metadata, String branch) { | ||
| Snapshot snapshot = latestSnapshot(metadata, branch); | ||
| while (snapshot != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] we can get an iterable of ancestors from the SnapshotUtils
| Map<Integer, Long> lastCommittedOffsets = lastCommittedOffsetsForTable(base, branch); | ||
|
|
||
| if (expectedOffsets == null || expectedOffsets.isEmpty()) { | ||
| return; // there are no stored offsets, so assume we're starting with new offsets | ||
| } | ||
|
|
||
| if (!expectedOffsets.equals(lastCommittedOffsets)) { | ||
| throw new CommitFailedException( | ||
| "Latest offsets do not match expected offsets for this commit."); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[doubt] wouldn't this be lastCommittedOffset ?
if expectedOffset is null and lastCommittedOffset is non empty then we should fail ?
| Map<Integer, Long> lastCommittedOffsets = lastCommittedOffsetsForTable(base, branch); | |
| if (expectedOffsets == null || expectedOffsets.isEmpty()) { | |
| return; // there are no stored offsets, so assume we're starting with new offsets | |
| } | |
| if (!expectedOffsets.equals(lastCommittedOffsets)) { | |
| throw new CommitFailedException( | |
| "Latest offsets do not match expected offsets for this commit."); | |
| } | |
| }; | |
| Map<Integer, Long> lastCommittedOffsets = lastCommittedOffsetsForTable(base, branch); | |
| if (lastCommittedOffsets == null || lastCommittedOffsets.isEmpty()) { | |
| return; // there are no stored offsets, so assume we're starting with new offsets | |
| } | |
| // handle case for expectedOffsets being null too | |
| if (!lastCommittedOffsets.equals(expectedOffsets)) { | |
| throw new CommitFailedException( | |
| "Committed offsets do not match expected offsets for this commit."); | |
| } | |
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I debated this, but I'm not sure what the expected behavior should be in that case. It seems likely that we want to error in that case as well, but the scenario around it is less clear to me.
|
Closed in favor of #14510 |
This PR depends on #14503 which adds commit validation.
The changes in this PR ensure that the expected commit offsets are not updated when table is refreshed during the commit process. This prevents a concurrent KC committer from updating the offsets resulting in duplicate processing of events.