Skip to content

Make FailoverClient(sentinel mode) more robust #1655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Feb 10, 2021
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, allowDisconnected boo
rand.Shuffle(len(c.sentinelAddrs), func(i, j int) { c.sentinelAddrs[i], c.sentinelAddrs[j] = c.sentinelAddrs[j], c.sentinelAddrs[i] })
}

allowedFlags := make([]string, 0)
if allowDisconnected {
allowedFlags = append(allowedFlags, "disconnected")
}

var sentinelReachable bool

for i, sentinelAddr := range c.sentinelAddrs {
Expand All @@ -547,7 +552,7 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, allowDisconnected boo
continue
}
sentinelReachable = true
addrs := parseSlaveAddrs(slaves)
addrs := parseSlaveAddrs(slaves, allowedFlags...)
if len(addrs) == 0 {
continue
}
Expand All @@ -560,9 +565,8 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, allowDisconnected boo

if sentinelReachable {
return []string{}, nil
} else {
return []string{}, errors.New("redis: all sentinels specified in configuration are unreachable")
}
return []string{}, errors.New("redis: all sentinels specified in configuration are unreachable")
}

func (c *sentinelFailover) getMasterAddr(ctx context.Context, sentinel *SentinelClient) string {
Expand Down