Skip to content

Commit

Permalink
Check Failing() before serving random node (redis#1825)
Browse files Browse the repository at this point in the history
* Check Failing() before serving random node

* Revert condition

* Addressed review comments

* Fallback to random failing node
  • Loading branch information
AnatolyRugalev authored Jul 17, 2021
1 parent ce40cd9 commit 62fc2c8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 62fc2c8

Please sign in to comment.