From 4585ffb5d5ff0f9c673f02f26eaae6da208f83b4 Mon Sep 17 00:00:00 2001 From: luoshaojun1 Date: Thu, 11 Jun 2020 14:49:28 +0800 Subject: [PATCH] fix stringShuffle function --- zk/conn.go | 2 +- zk/dnshostprovider.go | 2 +- zk/util.go | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/zk/conn.go b/zk/conn.go index da9503a2..60bd4779 100644 --- a/zk/conn.go +++ b/zk/conn.go @@ -188,7 +188,7 @@ func Connect(servers []string, sessionTimeout time.Duration, options ...connOpti } // Randomize the order of the servers to avoid creating hotspots - stringShuffle(srvs) + srvs = stringShuffle(srvs) ec := make(chan Event, eventChanSize) conn := &Conn{ diff --git a/zk/dnshostprovider.go b/zk/dnshostprovider.go index f4bba8d0..a50f71d2 100644 --- a/zk/dnshostprovider.go +++ b/zk/dnshostprovider.go @@ -50,7 +50,7 @@ func (hp *DNSHostProvider) Init(servers []string) error { } // Randomize the order of the servers to avoid creating hotspots - stringShuffle(found) + found = stringShuffle(found) hp.servers = found hp.curr = -1 diff --git a/zk/util.go b/zk/util.go index f40a5b15..e7476f45 100644 --- a/zk/util.go +++ b/zk/util.go @@ -47,11 +47,12 @@ func FormatServers(servers []string) []string { } // stringShuffle performs a Fisher-Yates shuffle on a slice of strings -func stringShuffle(s []string) { +func stringShuffle(s []string) []string { for i := len(s) - 1; i > 0; i-- { j := rand.Intn(i + 1) s[i], s[j] = s[j], s[i] } + return s } // validatePath will make sure a path is valid before sending the request