-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix producer topic metadata on-demand fetch when topic error happens #1125
fix producer topic metadata on-demand fetch when topic error happens #1125
Conversation
/cc @burke |
If |
@eapache Sorry for not making the description clear and correct firstly. The error maybe I have also updated the pr description. |
I'm not sure I agree. If the broker returns one of those errors the topic either doesn't exist or is fundamentally inaccessible. Leaving it in the metadata hash at that point would be extremely misleading to callers and would likely lead to other problems when trying to iterate over the set of topics.
I'm also not sure how this can happen. The |
Yes. That's right. But
The error maybe not all related with producer side configuration. Some errors are related with server side operations or status. |
OK, I understand. As mentioned, leaving it in the metadata would cause other issues. A better solution would be to keep a separate copy of the topics when not doing full metadata, and use that (in combination with |
I have thought that before i propose this PR. I think directly update the |
@eapache PTAL. |
client.go
Outdated
controllerID int32 // cluster controller broker id | ||
brokers map[int32]*Broker // maps broker ids to brokers | ||
metadata map[string]map[int32]*PartitionMetadata // maps topics to partition ids to metadata | ||
metadataTopics map[string]struct{} // topics that need to collect 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.
sarama defines a helper type called none
to make uses of struct{}
like this more explicit
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.
@eapache Done. PTAL.
thanks! |
This PR can help fix producer topic metadata on-demand fetch when topic error happens in metadata response.
There is an option
Full
inConfig
to config whether producer should fetch all topic metadata in a cluster or do it on-demand.This feature is added in #937.
But there is an situation where we may make on-demand topic metadata fetching fall back to empty once an topic error happens in metadata update.
For example, if
ErrUnknownTopicOrPartition
orErrInvalidTopic
orErrTopicAuthorizationFailed
or any other errors that will make theswitch
casecontinue
happens, the topic name will be deleted fromclient.metadata
. This will result in an empty topic slice when refresh topic metadata next time in https://github.com/Shopify/sarama/blob/master/client.go#L648-L666 fromclient.Topics()
which actually read topics fromclient.metadata
. Thus we lost the topic name which we need to periodically refresh metadata.We should not update
client.metadata
or delete any topic key from it.