KAFKA-19280: Fix NoSuchElementException in UnifiedLog#19717
Merged
Conversation
mimaison
reviewed
May 16, 2025
mimaison
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR (and catching the issue!). Looks good overall, just left a couple of suggestions
| LogOffsetMetadata highWatermarkMetadata = fetchHighWatermarkMetadata(); | ||
| if (firstUnstableOffsetMetadata.isPresent() && firstUnstableOffsetMetadata.get().messageOffset < highWatermarkMetadata.messageOffset) { | ||
| LogOffsetMetadata lom = firstUnstableOffsetMetadata.get(); | ||
| Optional<LogOffsetMetadata> firstUnstableOffsetMetadataCopy = firstUnstableOffsetMetadata; |
Member
There was a problem hiding this comment.
Should we add a comment or update the comment just above?
| public long lastStableOffset() { | ||
| if (firstUnstableOffsetMetadata.isPresent() && firstUnstableOffsetMetadata.get().messageOffset < highWatermark()) { | ||
| return firstUnstableOffsetMetadata.get().messageOffset; | ||
| Optional<LogOffsetMetadata> firstUnstableOffsetMetadataCopy = firstUnstableOffsetMetadata; |
Member
There was a problem hiding this comment.
Maybe worth adding a comment. There are a few places in this class where we say we cache a value to avoid concurrency issues.
Member
Author
|
Thanks for the review @mimaison. Ready for re-review |
|
I opened #22609 to address this. The details are in the PR; happy to adjust based on what you'd prefer. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In FETCH requests and TXN_OFFSET_COMMIT requests, on current trunk we
run into a race condition inside UnifiedLog, causing a
NoSuchElementExceptioninUnifiedLog.fetchLastStableOffsetMetadata(UnifiedLog.java:651).The cause is that the line a performing an
isPresentcheck on avolatile Optional before accessing it in
get, leaving the door open toa race condition when the optional changes between
isPresentandget. This change takes a copy of the volatile variable first.Reviewers: Mickael Maison mickael.maison@gmail.com, wilmerdooley wilmer@snovon.com