Use fresh cluster state after sleeping

This commit is contained in:
Vladimir Mihailenco 2018-02-27 14:50:08 +02:00
parent 9df09066e2
commit cc47cf2439
1 changed files with 16 additions and 17 deletions

View File

@ -682,18 +682,23 @@ func (c *ClusterClient) Process(cmd Cmder) error {
} }
func (c *ClusterClient) defaultProcess(cmd Cmder) error { func (c *ClusterClient) defaultProcess(cmd Cmder) error {
_, node, err := c.cmdSlotAndNode(cmd) var node *clusterNode
if err != nil {
cmd.setErr(err)
return err
}
var ask bool var ask bool
for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ { for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
if attempt > 0 { if attempt > 0 {
time.Sleep(c.retryBackoff(attempt)) time.Sleep(c.retryBackoff(attempt))
} }
if node == nil {
var err error
_, node, err = c.cmdSlotAndNode(cmd)
if err != nil {
cmd.setErr(err)
break
}
}
var err error
if ask { if ask {
pipe := node.Client.Pipeline() pipe := node.Client.Pipeline()
_ = pipe.Process(NewCmd("ASKING")) _ = pipe.Process(NewCmd("ASKING"))
@ -717,9 +722,8 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
} }
if internal.IsRetryableError(err, true) { if internal.IsRetryableError(err, true) {
var nodeErr error node, err = c.nodes.Random()
node, nodeErr = c.nodes.Random() if err != nil {
if nodeErr != nil {
break break
} }
continue continue
@ -731,20 +735,15 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
if moved || ask { if moved || ask {
c.lazyReloadState() c.lazyReloadState()
var nodeErr error node, err = c.nodes.GetOrCreate(addr)
node, nodeErr = c.nodes.GetOrCreate(addr) if err != nil {
if nodeErr != nil {
break break
} }
continue continue
} }
if err == pool.ErrClosed { if err == pool.ErrClosed {
_, node, err = c.cmdSlotAndNode(cmd) node = nil
if err != nil {
cmd.setErr(err)
break
}
continue continue
} }