Skip to content
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

kgo: add TopicID to the FetchTopic type #794

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/kgo/record_and_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ func (p *FetchPartition) EachRecord(fn func(*Record)) {
type FetchTopic struct {
// Topic is the topic this is for.
Topic string
// TopicID is the ID of the topic, if your cluster supports returning
// topic IDs in fetch responses (Kafka 3.1+).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe add fetch request version? Will make it easier for someone using the API, I think.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End users generally don't actually know what version of Kafka introduced what version of a request. It's undocumented anywhere -- a person has to first know the version a field was introduced in, then figure out which KIP introduced that version, then figure out which version of Kafka the KIP was actually released in.

Mentioning the version of Kafka that introduced topic IDs in the fetch response circumvents that process and gets directly to the answer, IMO.

TopicID [16]byte
// Partitions contains individual partitions in the topic that were
// fetched.
Partitions []FetchPartition
Expand Down Expand Up @@ -560,6 +563,7 @@ func (fs Fetches) EachTopic(fn func(FetchTopic)) {
for topic, partitions := range topics {
fn(FetchTopic{
topic,
[16]byte{},
partitions,
})
}
Expand Down
1 change: 1 addition & 0 deletions pkg/kgo/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ func (s *source) handleReqResp(br *broker, req *fetchRequest, resp *kmsg.FetchRe

fetchTopic := FetchTopic{
Topic: topic,
TopicID: rt.TopicID,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, so if version >= 13, I should be assured that this is set?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's set if the broker returns it -- it's a new field in fetch response v13, yes -- and this will be all 0s if it is unset.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I assume all 0s is an invalid topic id.

Partitions: make([]FetchPartition, 0, len(rt.Partitions)),
}

Expand Down