Skip to content

Commit

Permalink
clientv3/balancer: only notify healthy addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Nov 9, 2017
1 parent 5b3aae5 commit c2deb20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 3 additions & 7 deletions clientv3/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,19 +365,15 @@ func (b *simpleBalancer) notifyAddrs(msg notifyMsg) {
}
}
b.mu.RLock()
addrs := b.addrs
pinAddr := b.pinAddr
downc := b.downc
b.mu.RUnlock()
addrs, hostPorts := b.liveAddrs()

var waitDown bool
if pinAddr != "" {
waitDown = true
for _, a := range addrs {
if a.Addr == pinAddr {
waitDown = false
}
}
_, ok := hostPorts[pinAddr]
waitDown = !ok
}

select {
Expand Down
8 changes: 4 additions & 4 deletions clientv3/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestBalancerGetUnblocking(t *testing.T) {
}

down1(errors.New("error"))
if addrs := <-sb.Notify(); len(addrs) != len(endpoints) {
t.Errorf("closing the only connection should triggered balancer to send the all endpoints via Notify chan so that we can establish a connection")
if addrs := <-sb.Notify(); len(addrs) != 2 {
t.Errorf("closing the only connection should triggered balancer to send the 2 endpoints via Notify chan so that we can establish a connection")
}
down2(errors.New("error"))
_, _, err = sb.Get(context.Background(), unblockingOpts)
Expand Down Expand Up @@ -121,8 +121,8 @@ func TestBalancerGetBlocking(t *testing.T) {
}

down1(errors.New("error"))
if addrs := <-sb.Notify(); len(addrs) != len(endpoints) {
t.Errorf("closing the only connection should triggered balancer to send the all endpoints via Notify chan so that we can establish a connection")
if addrs := <-sb.Notify(); len(addrs) != 2 {
t.Errorf("closing the only connection should triggered balancer to send the 2 endpoints via Notify chan so that we can establish a connection")
}
down2(errors.New("error"))
ctx, cancel = context.WithTimeout(context.Background(), time.Millisecond*100)
Expand Down

0 comments on commit c2deb20

Please sign in to comment.