Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

fix stringShuffle function #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion zk/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion zk/dnshostprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion zk/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down