Merge pull request #948 from go-redis/fix/reload-more-often

Reload cluster state almost on any error
This commit is contained in:
Vladimir Mihailenco 2019-01-08 16:49:39 +02:00 committed by GitHub
commit d9c8076236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 24 deletions

View File

@ -844,15 +844,12 @@ func (c *ClusterClient) Watch(fn func(*Tx) error, keys ...string) error {
if err == nil { if err == nil {
break break
} }
if err != Nil {
if internal.IsRetryableError(err, true) {
c.state.LazyReload() c.state.LazyReload()
continue
} }
moved, ask, addr := internal.IsMovedError(err) moved, ask, addr := internal.IsMovedError(err)
if moved || ask { if moved || ask {
c.state.LazyReload()
node, err = c.nodes.GetOrCreate(addr) node, err = c.nodes.GetOrCreate(addr)
if err != nil { if err != nil {
return err return err
@ -868,6 +865,10 @@ func (c *ClusterClient) Watch(fn func(*Tx) error, keys ...string) error {
continue continue
} }
if internal.IsRetryableError(err, true) {
continue
}
return err return err
} }
@ -932,6 +933,9 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
if err == nil { if err == nil {
break break
} }
if err != Nil {
c.state.LazyReload()
}
// If slave is loading - pick another node. // If slave is loading - pick another node.
if c.opt.ReadOnly && internal.IsLoadingError(err) { if c.opt.ReadOnly && internal.IsLoadingError(err) {
@ -940,9 +944,23 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
continue continue
} }
if internal.IsRetryableError(err, true) { var moved bool
c.state.LazyReload() var addr string
moved, ask, addr = internal.IsMovedError(err)
if moved || ask {
node, err = c.nodes.GetOrCreate(addr)
if err != nil {
break
}
continue
}
if err == pool.ErrClosed {
node = nil
continue
}
if internal.IsRetryableError(err, true) {
// First retry the same node. // First retry the same node.
if attempt == 0 { if attempt == 0 {
continue continue
@ -956,24 +974,6 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
continue continue
} }
var moved bool
var addr string
moved, ask, addr = internal.IsMovedError(err)
if moved || ask {
c.state.LazyReload()
node, err = c.nodes.GetOrCreate(addr)
if err != nil {
break
}
continue
}
if err == pool.ErrClosed {
node = nil
continue
}
break break
} }