From 8d9ebc8459c6d3925c61ce3da78ac17118a118fd Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 10 Feb 2021 17:25:09 +0200 Subject: [PATCH] Shuffle sentinel addrs once --- sentinel.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/sentinel.go b/sentinel.go index 913d0141..3e8afb74 100644 --- a/sentinel.go +++ b/sentinel.go @@ -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, @@ -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)) @@ -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