Skip to content

Commit

Permalink
Search for a secondary pool with connections
Browse files Browse the repository at this point in the history
When executing a command on a secondary node in a cluster, search the
pools for the secondaries that have available connections. This allows
the client to avoid secondary nodes that are having issues.
  • Loading branch information
Wade Smith committed Aug 28, 2023
1 parent a23d6b1 commit 62c0519
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,25 @@ func (c *Cluster) clientForKey(key string, random, secondary bool) (Client, stri

if primAddr == "" {
return fmt.Errorf("could not find primary address for key %q", key)
} else if secondary {
}

if secondary {
for addr = range c.secondaries[primAddr] {
client = c.pools[addr]
if p, ok := client.(*pool); ok {
if p.conns.len() == 0 {
continue
}
}

break
}
}
if addr == "" {
addr = primAddr
client = c.pools[addr]
}

client = c.pools[addr]
return nil
})
if err != nil {
Expand Down

0 comments on commit 62c0519

Please sign in to comment.