From 62c05198d8428021677acfca2ffefe68fabd4f31 Mon Sep 17 00:00:00 2001 From: Wade Smith Date: Mon, 28 Aug 2023 15:19:14 +1000 Subject: [PATCH] Search for a secondary pool with connections 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. --- cluster.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cluster.go b/cluster.go index 54a1d4e..f1d36da 100644 --- a/cluster.go +++ b/cluster.go @@ -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 {