mirror of https://github.com/grpc/grpc-go.git
				
				
				
			some touchups
This commit is contained in:
		
							parent
							
								
									53fe56a73e
								
							
						
					
					
						commit
						26c0af8adc
					
				
							
								
								
									
										14
									
								
								balancer.go
								
								
								
								
							
							
						
						
									
										14
									
								
								balancer.go
								
								
								
								
							|  | @ -115,6 +115,8 @@ func (rr *roundRobin) watchAddrUpdates(w naming.Watcher) error { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | 	rr.mu.Lock() | ||||||
|  | 	defer rr.mu.Unlock() | ||||||
| 	for _, update := range updates { | 	for _, update := range updates { | ||||||
| 		addr := Address{ | 		addr := Address{ | ||||||
| 			Addr:     update.Addr, | 			Addr:     update.Addr, | ||||||
|  | @ -122,15 +124,15 @@ func (rr *roundRobin) watchAddrUpdates(w naming.Watcher) error { | ||||||
| 		} | 		} | ||||||
| 		switch update.Op { | 		switch update.Op { | ||||||
| 		case naming.Add: | 		case naming.Add: | ||||||
| 			var exisit bool | 			var exist bool | ||||||
| 			for _, v := range rr.open { | 			for _, v := range rr.open { | ||||||
| 				if addr == v { | 				if addr == v { | ||||||
| 					exisit = true | 					exist = true | ||||||
| 					grpclog.Println("grpc: The name resolver wanted to add an existing address: ", addr) | 					grpclog.Println("grpc: The name resolver wanted to add an existing address: ", addr) | ||||||
| 					break | 					break | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			if exisit { | 			if exist { | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			rr.open = append(rr.open, addr) | 			rr.open = append(rr.open, addr) | ||||||
|  | @ -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.
 | 	// Make a copy of rr.open and write it onto rr.addrCh so that gRPC internals gets notified.
 | ||||||
| 	open := make([]Address, len(rr.open)) | 	open := make([]Address, len(rr.open)) | ||||||
| 	rr.mu.Lock() |  | ||||||
| 	defer rr.mu.Unlock() |  | ||||||
| 	copy(open, rr.open) | 	copy(open, rr.open) | ||||||
| 	if rr.done { | 	if rr.done { | ||||||
| 		return ErrClientConnClosing | 		return ErrClientConnClosing | ||||||
|  | @ -160,6 +160,8 @@ func (rr *roundRobin) watchAddrUpdates(w naming.Watcher) error { | ||||||
| 
 | 
 | ||||||
| func (rr *roundRobin) Start(target string) error { | func (rr *roundRobin) Start(target string) error { | ||||||
| 	if rr.r == nil { | 	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 | 		return nil | ||||||
| 	} | 	} | ||||||
| 	w, err := rr.r.Resolve(target) | 	w, err := rr.r.Resolve(target) | ||||||
|  | @ -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) { | func (rr *roundRobin) Get(ctx context.Context, opts BalancerGetOptions) (addr Address, put func(), err error) { | ||||||
| 	var ch chan struct{} | 	var ch chan struct{} | ||||||
| 	rr.mu.Lock() | 	rr.mu.Lock() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue