Shuffle sentinel addrs once

This commit is contained in:
Vladimir Mihailenco 2021-02-10 17:25:09 +02:00
parent 8b19c31049
commit 8d9ebc8459
1 changed files with 4 additions and 10 deletions

View File

@ -173,6 +173,10 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
sentinelAddrs := make([]string, len(failoverOpt.SentinelAddrs)) sentinelAddrs := make([]string, len(failoverOpt.SentinelAddrs))
copy(sentinelAddrs, failoverOpt.SentinelAddrs) copy(sentinelAddrs, failoverOpt.SentinelAddrs)
rand.Shuffle(len(sentinelAddrs), func(i, j int) {
sentinelAddrs[i], sentinelAddrs[j] = sentinelAddrs[j], sentinelAddrs[i]
})
failover := &sentinelFailover{ failover := &sentinelFailover{
opt: failoverOpt, opt: failoverOpt,
sentinelAddrs: sentinelAddrs, sentinelAddrs: sentinelAddrs,
@ -484,11 +488,6 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) {
_ = c.closeSentinel() _ = 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 { for i, sentinelAddr := range c.sentinelAddrs {
sentinel := NewSentinelClient(c.opt.sentinelOptions(sentinelAddr)) sentinel := NewSentinelClient(c.opt.sentinelOptions(sentinelAddr))
@ -533,11 +532,6 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, useDisconnected bool)
} }
_ = c.closeSentinel() _ = 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 var sentinelReachable bool