Skip to content

Commit

Permalink
some touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
iamqizhao committed May 25, 2016
1 parent 53fe56a commit 26c0af8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,24 @@ func (rr *roundRobin) watchAddrUpdates(w naming.Watcher) error {
if err != nil {
return err
}
rr.mu.Lock()
defer rr.mu.Unlock()
for _, update := range updates {
addr := Address{
Addr: update.Addr,
Metadata: update.Metadata,
}
switch update.Op {
case naming.Add:
var exisit bool
var exist bool
for _, v := range rr.open {
if addr == v {
exisit = true
exist = true
grpclog.Println("grpc: The name resolver wanted to add an existing address: ", addr)
break
}
}
if exisit {
if exist {
continue
}
rr.open = append(rr.open, addr)
Expand All @@ -148,8 +150,6 @@ func (rr *roundRobin) watchAddrUpdates(w naming.Watcher) error {
}
// Make a copy of rr.open and write it onto rr.addrCh so that gRPC internals gets notified.
open := make([]Address, len(rr.open))
rr.mu.Lock()
defer rr.mu.Unlock()
copy(open, rr.open)
if rr.done {
return ErrClientConnClosing
Expand All @@ -160,6 +160,8 @@ func (rr *roundRobin) watchAddrUpdates(w naming.Watcher) error {

func (rr *roundRobin) Start(target string) error {
if rr.r == nil {
// If there is no name resolver installed, it is not needed to
// do name resolution. In this case, rr.addrCh stays nil.
return nil
}
w, err := rr.r.Resolve(target)
Expand Down Expand Up @@ -213,7 +215,7 @@ func (rr *roundRobin) down(addr Address, err error) {
}
}

// Get returns the next addr in the rotation. It blocks if there is no address available.
// Get returns the next addr in the rotation.
func (rr *roundRobin) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) {
var ch chan struct{}
rr.mu.Lock()
Expand Down

0 comments on commit 26c0af8

Please sign in to comment.