Skip to content

Commit

Permalink
Use fresh cluster state after sleeping
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Feb 27, 2018
1 parent 9df0906 commit cc47cf2
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,18 +682,23 @@ func (c *ClusterClient) Process(cmd Cmder) error {
}

func (c *ClusterClient) defaultProcess(cmd Cmder) error {
_, node, err := c.cmdSlotAndNode(cmd)
if err != nil {
cmd.setErr(err)
return err
}

var node *clusterNode
var ask bool
for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
if attempt > 0 {
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 {
pipe := node.Client.Pipeline()
_ = pipe.Process(NewCmd("ASKING"))
Expand All @@ -717,9 +722,8 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
}

if internal.IsRetryableError(err, true) {
var nodeErr error
node, nodeErr = c.nodes.Random()
if nodeErr != nil {
node, err = c.nodes.Random()
if err != nil {
break
}
continue
Expand All @@ -731,20 +735,15 @@ func (c *ClusterClient) defaultProcess(cmd Cmder) error {
if moved || ask {
c.lazyReloadState()

var nodeErr error
node, nodeErr = c.nodes.GetOrCreate(addr)
if nodeErr != nil {
node, err = c.nodes.GetOrCreate(addr)
if err != nil {
break
}
continue
}

if err == pool.ErrClosed {
_, node, err = c.cmdSlotAndNode(cmd)
if err != nil {
cmd.setErr(err)
break
}
node = nil
continue
}

Expand Down

0 comments on commit cc47cf2

Please sign in to comment.