Skip to content

Commit

Permalink
client: collapse shard errors
Browse files Browse the repository at this point in the history
When sharding requests, we previously would return a unique error
message per missing topic / partition / leader. This would show up as a
bunch of shards. While the errors were informative, they aren't really
any more actionable than one slightly less informative error. We also
don't need a dedicated error message, because we split the request
appropriately such that the user can tell what all topics / partitions
failed from the split request in the shard.
  • Loading branch information
twmb committed Oct 7, 2021
1 parent 63b2fd6 commit 19f4e9b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/kgo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1631,23 +1631,29 @@ func (cl *Client) fetchMappedMetadata(ctx context.Context, topics []string) (map
return mapping, nil
}

var (
errMissingTopic = errors.New("topic was not returned when looking up its metadata")
errMissingPartition = errors.New("partition was not returned when looking up its metadata")
errNoLeader = errors.New("partition has no leader from metadata lookup")
)

func missingOrCodeT(t string, exists bool, code int16) error {
if !exists {
return fmt.Errorf("topic %s was not returned when looking up metadata for the topic", t)
return errMissingTopic
}
return kerr.ErrorForCode(code)
}

func missingOrCodeP(t string, p int32, exists bool, code int16) error {
if !exists {
return fmt.Errorf("topic %s partition %d was not returned when looking up metadata for the topic", t, p)
return errMissingPartition
}
return kerr.ErrorForCode(code)
}

func noLeader(t string, p int32, l int32) error {
if l < 0 {
return fmt.Errorf("topic %s partition %d has no leader according to the metadata lookup", t, p)
return errNoLeader
}
return nil
}
Expand Down

0 comments on commit 19f4e9b

Please sign in to comment.