Bläddra i källkod

dcwareRR: fix shuffling hosts (#1356)

Chris Bannister 6 år sedan
förälder
incheckning
bd5f930c61
1 ändrade filer med 2 tillägg och 1 borttagningar
  1. 2 1
      policies.go

+ 2 - 1
policies.go

@@ -873,6 +873,7 @@ func roundRobbin(hosts []*HostInfo) NextHost {
 func (d *dcAwareRR) Pick(q ExecutableQuery) NextHost {
 	local := d.localHosts.get()
 	remote := d.remoteHosts.get()
+
 	hosts := make([]*HostInfo, len(local)+len(remote))
 	n := copy(hosts, local)
 	copy(hosts[n:], remote)
@@ -880,7 +881,7 @@ func (d *dcAwareRR) Pick(q ExecutableQuery) NextHost {
 	// TODO: use random chose-2 but that will require plumbing information
 	// about connection/host load to here
 	r := rand.New(randSource())
-	for _, l := range [][]*HostInfo{local, remote} {
+	for _, l := range [][]*HostInfo{hosts[:len(local)], hosts[len(local):]} {
 		r.Shuffle(len(l), func(i, j int) {
 			l[i], l[j] = l[j], l[i]
 		})