Skip to content

Commit

Permalink
update after review
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouyihaiDing committed Jul 28, 2017
1 parent 181dc4f commit 571b627
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ type pickFirst struct {
*roundRobin
}

// PickFirstBalancer is a simple balancer for testing multi-addresses in one addrConn.
// pickFirstBalancer is a simple balancer for testing multi-addresses in one addrConn.
// By using this balancer, all address shares the same addrConn.
// Although it wrapped by RoundRobin balancer, the logic of all methods work fine because
// balancer.Get() returns the address Up by resetTransport()
// balancer. Get() returns the address Up by resetTransport().
func pickFirstBalancer(r naming.Resolver) Balancer {
return &pickFirst{&roundRobin{r: r}}
}
11 changes: 5 additions & 6 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func (cc *ClientConn) lbWatcher(doneChan chan struct{}) {
}
}
} else {
// Not pickFirst. All remains the same but changing addr to []Address{addr}
// Not pickFirst, create a new addrConn for each address.
var (
add []Address // Addresses need to setup connections.
del []*addrConn // Connections need to tear down.
Expand Down Expand Up @@ -694,8 +694,8 @@ func (cc *ClientConn) scWatcher() {
}
}

// UpdateAddresses checks whether current address in the updating list, Update the list if true.
func (cc *ClientConn) UpdateAddresses(addrs []Address) bool {
// addressesUpdated checks whether current address in the updating list, Update the list if true.
func (cc *ClientConn) addressesUpdated(addrs []Address) bool {
if len(cc.conns) == 0 {
// No addrconn. Should go resetting addrconn.
return false
Expand Down Expand Up @@ -748,11 +748,10 @@ func (cc *ClientConn) resetAddrConn(addrs []Address, block bool, tearDownErr err
// if current transport in addrs, just change lists to update order and new addresses
// not work for roundrobin
cc.mu.Lock()
_, isPickFirst := cc.dopts.balancer.(*pickFirst)
if isPickFirst {
if _, isPickFirst := cc.dopts.balancer.(*pickFirst); isPickFirst {
// If Current address in use in the updating list, just update the list.
// Otherwise, teardown current addrconn and create a new one.
if cc.UpdateAddresses(addrs) {
if cc.addressesUpdated(addrs) {
cc.mu.Unlock()
return nil
}
Expand Down

0 comments on commit 571b627

Please sign in to comment.