Skip to content

Commit

Permalink
Prefer ready pools when selecting one at random
Browse files Browse the repository at this point in the history
When choosing a random pool in a cluster to send a command to (for
example, when calling CLUSTER SLOTS to synchronise the cluster's
topology) prefer selecting a pool that reports that it has available
connections.
  • Loading branch information
Wade Smith committed Aug 28, 2023
1 parent e3f42da commit 2e5f2c2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,18 @@ func assertKeysSlot(keys []string) error {

// may return nil, nil if no pool for the addr.
func (c *Cluster) rpool(addr string) (client Client, err error) {
type ready interface {
Ready() bool
}

err = c.proc.WithRLock(func() error {
if addr == "" {
for _, client = range c.pools {
if r, ok := client.(ready); ok {
if !r.Ready() {
continue
}
}
return nil
}
return errors.New("no Clients available")
Expand Down

0 comments on commit 2e5f2c2

Please sign in to comment.