1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Check Failing() before serving random node (#1825)

* Check Failing() before serving random node

* Revert condition

* Addressed review comments

* Fallback to random failing node
This commit is contained in:
Anatoly Rugalev
2021-07-17 18:20:48 +02:00
committed by GitHub
parent ce40cd942a
commit 62fc2c821b

View File

@ -595,8 +595,16 @@ func (c *clusterState) slotRandomNode(slot int) (*clusterNode, error) {
if len(nodes) == 0 {
return c.nodes.Random()
}
n := rand.Intn(len(nodes))
return nodes[n], nil
if len(nodes) == 1 {
return nodes[0], nil
}
randomNodes := rand.Perm(len(nodes))
for _, idx := range randomNodes {
if node := nodes[idx]; !node.Failing() {
return node, nil
}
}
return nodes[randomNodes[0]], nil
}
func (c *clusterState) slotNodes(slot int) []*clusterNode {