-
Notifications
You must be signed in to change notification settings - Fork 15.3k
KAFKA-19280: Fix NoSuchElementException in UnifiedLog #19717
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -483,7 +483,7 @@ private void initializeTopicId() { | |
|
|
||
| if (partMetadataFile.exists()) { | ||
| Uuid fileTopicId = partMetadataFile.read().topicId(); | ||
| if (topicId.isPresent() && !topicId.get().equals(fileTopicId)) { | ||
| if (topicId.filter(x -> !x.equals(fileTopicId)).isPresent()) { | ||
| throw new InconsistentTopicIdException("Tried to assign topic ID " + topicId + " to log for topic partition " + topicPartition() + "," + | ||
| "but log already contained topic ID " + fileTopicId); | ||
| } | ||
|
|
@@ -645,10 +645,12 @@ public Optional<Long> firstUnstableOffset() { | |
| private LogOffsetMetadata fetchLastStableOffsetMetadata() throws IOException { | ||
| localLog.checkIfMemoryMappedBufferClosed(); | ||
|
|
||
| // cache the current high watermark to avoid a concurrent update invalidating the range check | ||
| // cache the current high watermark and the first unstable offset metadata to avoid a concurrent update | ||
| // invalidating the range check breaking the isPresent check | ||
| LogOffsetMetadata highWatermarkMetadata = fetchHighWatermarkMetadata(); | ||
| if (firstUnstableOffsetMetadata.isPresent() && firstUnstableOffsetMetadata.get().messageOffset < highWatermarkMetadata.messageOffset) { | ||
| LogOffsetMetadata lom = firstUnstableOffsetMetadata.get(); | ||
| Optional<LogOffsetMetadata> firstUnstableOffsetMetadataCopy = firstUnstableOffsetMetadata; | ||
| if (firstUnstableOffsetMetadataCopy.isPresent() && firstUnstableOffsetMetadataCopy.get().messageOffset < highWatermarkMetadata.messageOffset) { | ||
| LogOffsetMetadata lom = firstUnstableOffsetMetadataCopy.get(); | ||
| if (lom.messageOffsetOnly()) { | ||
| synchronized (lock) { | ||
| LogOffsetMetadata fullOffset = maybeConvertToOffsetMetadata(lom.messageOffset); | ||
|
|
@@ -671,8 +673,10 @@ private LogOffsetMetadata fetchLastStableOffsetMetadata() throws IOException { | |
| * beyond the high watermark. | ||
| */ | ||
| public long lastStableOffset() { | ||
| if (firstUnstableOffsetMetadata.isPresent() && firstUnstableOffsetMetadata.get().messageOffset < highWatermark()) { | ||
| return firstUnstableOffsetMetadata.get().messageOffset; | ||
| // cache the first unstable offset metadata to avoid a concurrent update breaking the isPresent check | ||
| Optional<LogOffsetMetadata> firstUnstableOffsetMetadataCopy = firstUnstableOffsetMetadata; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| if (firstUnstableOffsetMetadataCopy.isPresent() && firstUnstableOffsetMetadataCopy.get().messageOffset < highWatermark()) { | ||
| return firstUnstableOffsetMetadataCopy.get().messageOffset; | ||
| } else { | ||
| return highWatermark(); | ||
| } | ||
|
|
@@ -750,15 +754,15 @@ public void assignTopicId(Uuid topicId) { | |
| } | ||
| } else { | ||
| this.topicId = Optional.of(topicId); | ||
| if (partitionMetadataFile.isPresent()) { | ||
| PartitionMetadataFile file = partitionMetadataFile.get(); | ||
| if (!file.exists()) { | ||
| file.record(topicId); | ||
| scheduler().scheduleOnce("flush-metadata-file", this::maybeFlushMetadataFile); | ||
| } | ||
| } else { | ||
| logger.warn("The topic id {} will not be persisted to the partition metadata file since the partition is deleted", topicId); | ||
| } | ||
| partitionMetadataFile.ifPresentOrElse( | ||
| file -> { | ||
| if (!file.exists()) { | ||
| file.record(topicId); | ||
| scheduler().scheduleOnce("flush-metadata-file", this::maybeFlushMetadataFile); | ||
| } | ||
| }, | ||
| () -> logger.warn("The topic id {} will not be persisted to the partition metadata file since the partition is deleted", topicId) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
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.
Should we add a comment or update the comment just above?
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.
Done