mirror of
https://github.com/redis/go-redis.git
synced 2025-06-05 06:42:39 +03:00
fix: prevent routing reads to loading slave nodes
This commit is contained in:
parent
8ba559ca5d
commit
045948eb21
@ -445,6 +445,14 @@ func (n *clusterNode) SetLastLatencyMeasurement(t time.Time) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *clusterNode) Loading() bool {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
defer cancel()
|
||||
|
||||
err := n.Client.Ping(ctx).Err()
|
||||
return err != nil && isLoadingError(err)
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
type clusterNodes struct {
|
||||
@ -754,7 +762,8 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 2:
|
||||
if slave := nodes[1]; !slave.Failing() {
|
||||
slave := nodes[1]
|
||||
if !slave.Failing() && !slave.Loading() {
|
||||
return slave, nil
|
||||
}
|
||||
return nodes[0], nil
|
||||
@ -763,7 +772,7 @@ func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
|
||||
for i := 0; i < 10; i++ {
|
||||
n := rand.Intn(len(nodes)-1) + 1
|
||||
slave = nodes[n]
|
||||
if !slave.Failing() {
|
||||
if !slave.Failing() && !slave.Loading() {
|
||||
return slave, nil
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user