Skip to content

Commit

Permalink
Shuffle sentinel addrs once
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Feb 10, 2021
1 parent 8b19c31 commit 8d9ebc8
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
sentinelAddrs := make([]string, len(failoverOpt.SentinelAddrs))
copy(sentinelAddrs, failoverOpt.SentinelAddrs)

rand.Shuffle(len(sentinelAddrs), func(i, j int) {
sentinelAddrs[i], sentinelAddrs[j] = sentinelAddrs[j], sentinelAddrs[i]
})

failover := &sentinelFailover{
opt: failoverOpt,
sentinelAddrs: sentinelAddrs,
Expand Down Expand Up @@ -484,11 +488,6 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) {
_ = c.closeSentinel()
}

if c.opt.QuerySentinelRandomly {
rand.Shuffle(len(c.sentinelAddrs), func(i, j int) {
c.sentinelAddrs[i], c.sentinelAddrs[j] = c.sentinelAddrs[j], c.sentinelAddrs[i]
})
}
for i, sentinelAddr := range c.sentinelAddrs {
sentinel := NewSentinelClient(c.opt.sentinelOptions(sentinelAddr))

Expand Down Expand Up @@ -533,11 +532,6 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, useDisconnected bool)
}
_ = c.closeSentinel()
}
if c.opt.QuerySentinelRandomly {
rand.Shuffle(len(c.sentinelAddrs), func(i, j int) {
c.sentinelAddrs[i], c.sentinelAddrs[j] = c.sentinelAddrs[j], c.sentinelAddrs[i]
})
}

var sentinelReachable bool

Expand Down

0 comments on commit 8d9ebc8

Please sign in to comment.