Skip to content

Commit

Permalink
kgo: ensure we always have at least one shard
Browse files Browse the repository at this point in the history
Non sharded requests always have one shard; that was a given before.
Sharded requests could avoid having any shards if the request actually
does not need to be issued. Rather than avoiding returning no shards,
this issues the request to any broker. This is not detrimental and makes
it easier to always know that there is at least one shard.
  • Loading branch information
twmb committed Nov 19, 2020
1 parent 9d1238b commit 5b3da02
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/kgo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ type ResponseShard struct {

// RequestSharded performs the same logic as Request, but returns all responses
// from any broker that the request was split to. This always returns at least
// one shard.
// one shard. If the request does not need to be issued (describing no groups),
// this issues the request to a random broker just to ensure that one shard
// exists.
//
// There are only a few requests that are strongly recommended to explicitly
// use RequestSharded; the rest can by default use Request. These few requests
Expand Down Expand Up @@ -1214,6 +1216,17 @@ func (cl *Client) handleShardedReq(ctx context.Context, req kmsg.Request) ([]Res
return
}

// If the request actually does not need to be issued, we issue
// it to a random broker. There is no benefit to this, but at
// least we will return one shard.
if len(issues) == 0 {
issues = []issueShard{{
req: try.req,
any: true,
}}
reshardable = true
}

for i := range issues {
tries := try.tries
myIssue := issues[i]
Expand Down

0 comments on commit 5b3da02

Please sign in to comment.