From 571b6275c15ffc3f05f66074a510ad23c47bcadc Mon Sep 17 00:00:00 2001 From: ZhouyihaiDing Date: Fri, 28 Jul 2017 13:53:09 -0700 Subject: [PATCH] update after review --- balancer.go | 4 ++-- clientconn.go | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/balancer.go b/balancer.go index e684f19f0bc7..4d5c35fae37a 100644 --- a/balancer.go +++ b/balancer.go @@ -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}} } diff --git a/clientconn.go b/clientconn.go index ead52dcea51a..b7ad211cc017 100644 --- a/clientconn.go +++ b/clientconn.go @@ -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. @@ -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 @@ -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 }