1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-31 05:04:23 +03:00

Retry multiple commands more conservatively.

This commit is contained in:
Vladimir Mihailenco
2016-10-13 13:56:24 +03:00
parent 21cae7f9ab
commit 8558a92fa4
4 changed files with 53 additions and 43 deletions

39
ring.go
View File

@ -365,9 +365,7 @@ func (c *Ring) Pipelined(fn func(*Pipeline) error) ([]Cmder, error) {
return c.Pipeline().pipelined(fn)
}
func (c *Ring) pipelineExec(cmds []Cmder) error {
var retErr error
func (c *Ring) pipelineExec(cmds []Cmder) (firstErr error) {
cmdsMap := make(map[string][]Cmder)
for _, cmd := range cmds {
cmdInfo := c.cmdInfo(cmd.arg(0))
@ -379,14 +377,18 @@ func (c *Ring) pipelineExec(cmds []Cmder) error {
}
for i := 0; i <= c.opt.MaxRetries; i++ {
failedCmdsMap := make(map[string][]Cmder)
var failedCmdsMap map[string][]Cmder
for name, cmds := range cmdsMap {
if i > 0 {
resetCmds(cmds)
}
client, err := c.shardByName(name)
if err != nil {
setCmdsErr(cmds, err)
if retErr == nil {
retErr = err
if firstErr == nil {
firstErr = err
}
continue
}
@ -394,22 +396,25 @@ func (c *Ring) pipelineExec(cmds []Cmder) error {
cn, _, err := client.conn()
if err != nil {
setCmdsErr(cmds, err)
if retErr == nil {
retErr = err
if firstErr == nil {
firstErr = err
}
continue
}
if i > 0 {
resetCmds(cmds)
}
failedCmds, err := execCmds(cn, cmds)
retry, err := execCmds(cn, cmds)
client.putConn(cn, err, false)
if err != nil && retErr == nil {
retErr = err
if err == nil {
continue
}
if len(failedCmds) > 0 {
failedCmdsMap[name] = failedCmds
if firstErr == nil {
firstErr = err
}
if retry {
if failedCmdsMap == nil {
failedCmdsMap = make(map[string][]Cmder)
}
failedCmdsMap[name] = cmds
}
}
@ -419,5 +424,5 @@ func (c *Ring) pipelineExec(cmds []Cmder) error {
cmdsMap = failedCmdsMap
}
return retErr
return firstErr
}