-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-16310 ListOffsets doesn't report the offset with maxTimestamp a… #15621
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
52 commits
Select commit
Hold shift + click to select a range
a7d6288
KAFKA-16310 ListOffsets doesn't report the offset with maxTimestamp a…
chia7712 bd32d03
Merge branch 'trunk' into KAFKA-16310
chia7712 0f18cae
Merge branch 'trunk' into KAFKA-16310
chia7712 2c00cee
add more tests
chia7712 5278cd1
Merge branch 'trunk' into KAFKA-16310
chia7712 90d33e0
revert code and add comments
chia7712 f11b877
Merge branch 'trunk' into KAFKA-16310
chia7712 5180f2d
adjust comments
chia7712 79561cd
adjust comments
chia7712 726de99
adjust comments
chia7712 29137ae
ranem offsetOfMaxTimestampSoFar to shallowOffsetOfMaxTimestampSoFar
chia7712 1cf8ca4
Merge branch 'trunk' into KAFKA-16310
chia7712 ac729a6
Merge branch 'trunk' into KAFKA-16310
chia7712 2297b52
apply luke patch
chia7712 a1fbc6c
Merge branch 'trunk' into KAFKA-16310
chia7712 9505115
Merge branch 'trunk' into KAFKA-16310
chia7712 b4b1332
address comments
chia7712 609b6ab
address comments
chia7712 a535095
tweak
chia7712 3bd1451
fix build
chia7712 3dca50c
Merge branch 'trunk' into KAFKA-16310
chia7712 8e1878a
fix bug
chia7712 e78d09a
address comments
chia7712 f084c89
revise comment
chia7712 d0f6a9a
fix failed test
chia7712 7aebd43
address comment
chia7712 88f8c6a
fix
chia7712 8a7ed30
return noneif no batch
chia7712 d1fb7b1
Merge branch 'trunk' into KAFKA-16310
chia7712 4785371
address comment
chia7712 cfb12b6
Merge branch 'trunk' into KAFKA-16310
chia7712 79b5226
address reviews
chia7712 e6fa99f
give more time to sync
chia7712 0106386
Merge branch 'trunk' into KAFKA-16310
chia7712 3debf0b
revise test
chia7712 20fa22f
revise test
chia7712 b06dfcc
set lastLeader to -1
chia7712 afa36f4
Merge branch 'trunk' into KAFKA-16310
chia7712 07f1330
Merge branch 'trunk' into KAFKA-16310
chia7712 ace94e4
set log.retention.ms
chia7712 9af7513
Merge branch 'trunk' into KAFKA-16310
chia7712 8b1005e
address comments
chia7712 58b5e2f
Merge branch 'trunk' into KAFKA-16310
chia7712 728e7bb
fix failed tests
chia7712 e21447e
Merge branch 'trunk' into KAFKA-16310
chia7712 9e22f2d
Merge branch 'trunk' into KAFKA-16310
chia7712 fe2d7c9
fix testResponseIncludesLeaderEpoch
chia7712 2dee703
fix failed test
chia7712 b0afa6d
Merge branch 'trunk' into KAFKA-16310
chia7712 581242c
address comments
chia7712 d42fe26
Merge branch 'trunk' into KAFKA-16310
chia7712 d12fce2
Merge branch 'trunk' into KAFKA-16310
chia7712 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
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
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
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 |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Iterator; | ||
| import java.util.Optional; | ||
| import java.util.OptionalLong; | ||
|
|
||
| /** | ||
|
|
@@ -245,4 +246,23 @@ public interface RecordBatch extends Iterable<Record> { | |
| * @return Whether this is a batch containing control records | ||
| */ | ||
| boolean isControlBatch(); | ||
|
|
||
| /** | ||
| * iterate all records to find the offset of max timestamp. | ||
| * noted: | ||
| * 1) that the earliest offset will return if there are multi records having same (max) timestamp | ||
| * 2) it always returns None if the {@link RecordBatch#magic()} is equal to {@link RecordBatch#MAGIC_VALUE_V0} | ||
| * @return offset of max timestamp | ||
| */ | ||
| default Optional<Long> offsetOfMaxTimestamp() { | ||
| if (magic() == RecordBatch.MAGIC_VALUE_V0) return Optional.empty(); | ||
|
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. @junrao the short-circuit is added |
||
| long maxTimestamp = maxTimestamp(); | ||
| try (CloseableIterator<Record> iter = streamingIterator(BufferSupplier.create())) { | ||
| while (iter.hasNext()) { | ||
| Record record = iter.next(); | ||
| if (maxTimestamp == record.timestamp()) return Optional.of(record.offset()); | ||
| } | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
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
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
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
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
Oops, something went wrong.
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.
hi @junrao I rewrite whole comments to list all cases. please take a look at it, thanks!