Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
16 changes: 12 additions & 4 deletions pkg/kgo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,10 @@ func (cl *Client) Request(ctx context.Context, req kmsg.Request) (kmsg.Response,
// set to true. This function cannot be used to request topics via TopicID;
// the direct topic name must be used.
func (cl *Client) RequestCachedMetadata(ctx context.Context, req *kmsg.MetadataRequest, limit time.Duration) (*kmsg.MetadataResponse, error) {
topics := make([]string, 0, len(req.Topics))
var topics []string
if req.Topics != nil {
topics = make([]string, 0, len(req.Topics))
}
for _, t := range req.Topics {
if t.Topic == nil || *t.Topic == "" {
return nil, errors.New("unable to request cached metadata with a missing topic name (topic IDs are not supported)")
Expand Down Expand Up @@ -2652,7 +2655,7 @@ func (cl *Client) maybeDeleteMappedMetadata(unknownTopic bool, ts ...string) (sh
func (cl *Client) fetchCachedMappedMetadata(limit time.Duration, ts ...string) (map[string]mappedMetadataTopic, []string) {
cl.mappedMetaMu.Lock()
defer cl.mappedMetaMu.Unlock()
if cl.mappedMeta == nil {
if len(cl.mappedMeta) == 0 {
return nil, ts
}
cached := make(map[string]mappedMetadataTopic)
Expand Down Expand Up @@ -2682,15 +2685,20 @@ func (cl *Client) fetchMappedMetadata(ctx context.Context, topics []string, useC
needed := topics
if useCache {
intoMapped, needed = cl.fetchCachedMappedMetadata(limit, topics...)
if len(needed) == 0 {
// If intoMapped is nil, we have no cached topics at all and
// need to force a metadata load to satisfy broker/controller
// aspects of the metadata response. We have either never
// issued a metadata request, or the cached data (of no topics)
// could be super old. Cache age is only tracked per topic.
if intoMapped != nil && len(needed) == 0 {
return intoMapped, nil
}
}
if intoMapped == nil {
intoMapped = make(map[string]mappedMetadataTopic)
}

_, _, err := cl.fetchMetadataForTopics(ctx, false, needed, intoMapped)
_, _, err := cl.fetchMetadataForTopics(ctx, topics == nil, needed, intoMapped)
return intoMapped, err
}

Expand Down