-
Notifications
You must be signed in to change notification settings - Fork 14.6k
KAFKA-19658: Tweak org.apache.kafka.clients.consumer.OffsetAndMetadata #20451
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
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.
@DL1231: LGTM
* Normalizes leader epoch values for comparison and hashing. | ||
* Both null and negative values are considered equivalent (representing absent/unknown epoch). | ||
*/ | ||
private Integer normalizeLeaderEpoch(Integer leaderEpoch) { |
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.
nit: Since this method doesn't use any instance members we can make it static
or remove the leaderEpoch
parameter.
/** | ||
* Normalizes leader epoch values for comparison and hashing. | ||
* Both null and negative values are considered equivalent (representing absent/unknown epoch). | ||
*/ | ||
private Integer normalizeLeaderEpoch(Integer leaderEpoch) { | ||
return (leaderEpoch == null || leaderEpoch < 0) ? null : leaderEpoch; | ||
} | ||
|
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.
Can we use the existing leaderEpoch
method to normalize the leaderEpoch
? It already maps null
and negatives to Optional.empty()
.
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.
Good catch.
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.
+1 |
assertEquals(5, consumer.committed(Set.of(TP)).get(TP).offset()); | ||
metadata = consumer.committed(Set.of(TP)).get(TP); | ||
assertEquals(5, metadata.offset()); | ||
assertEquals("metadata", metadata.metadata()); |
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.
Please update the docs of OffsetAndMetadata#metadata()
to remind that the method never return null
equals()
,hashCode()
, andtoString()
methods inOffsetAndMetadata
.Reviewers: TengYao Chi [email protected], Sean Quah
[email protected], Chia-Ping Tsai [email protected]