fix some comments
This commit is contained in:
@ -88,7 +88,7 @@ type Balancer interface {
|
|||||||
// custom Balancer.
|
// custom Balancer.
|
||||||
//
|
//
|
||||||
// If opts.BlockingWait is true, it should return a connected address or
|
// If opts.BlockingWait is true, it should return a connected address or
|
||||||
// block if there is no connected address. It respects the timeout or
|
// block if there is no connected address. It should respect the timeout or
|
||||||
// cancellation of ctx when blocking. If opts.BlockingWait is false (for fail-fast
|
// cancellation of ctx when blocking. If opts.BlockingWait is false (for fail-fast
|
||||||
// RPCs), it should return an address it has notified via Notify(...) immediately
|
// RPCs), it should return an address it has notified via Notify(...) immediately
|
||||||
// instead of blocking.
|
// instead of blocking.
|
||||||
@ -137,6 +137,7 @@ func RoundRobin(r naming.Resolver) Balancer {
|
|||||||
|
|
||||||
type roundRobin struct {
|
type roundRobin struct {
|
||||||
r naming.Resolver
|
r naming.Resolver
|
||||||
|
w []naming.Watcher
|
||||||
open []Address // all the addresses the client should potentially connect
|
open []Address // all the addresses the client should potentially connect
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
addrCh chan []Address // the channel to notify gRPC internals the list of addresses the client should connect to.
|
addrCh chan []Address // the channel to notify gRPC internals the list of addresses the client should connect to.
|
||||||
@ -149,6 +150,7 @@ type roundRobin struct {
|
|||||||
func (rr *roundRobin) watchAddrUpdates(w naming.Watcher) error {
|
func (rr *roundRobin) watchAddrUpdates(w naming.Watcher) error {
|
||||||
updates, err := w.Next()
|
updates, err := w.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
grpclog.Println("grpc: the naming watcher stops working due to %v.", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rr.mu.Lock()
|
rr.mu.Lock()
|
||||||
@ -204,6 +206,7 @@ func (rr *roundRobin) Start(target string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
rr.w = []naming.Watcher{w}
|
||||||
rr.addrCh = make(chan []Address)
|
rr.addrCh = make(chan []Address)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -314,6 +317,9 @@ func (rr *roundRobin) Close() error {
|
|||||||
rr.mu.Lock()
|
rr.mu.Lock()
|
||||||
defer rr.mu.Unlock()
|
defer rr.mu.Unlock()
|
||||||
rr.done = true
|
rr.done = true
|
||||||
|
for _, w := range rr.w {
|
||||||
|
w.Close()
|
||||||
|
}
|
||||||
if rr.waitCh != nil {
|
if rr.waitCh != nil {
|
||||||
close(rr.waitCh)
|
close(rr.waitCh)
|
||||||
rr.waitCh = nil
|
rr.waitCh = nil
|
||||||
|
@ -66,7 +66,8 @@ type Resolver interface {
|
|||||||
// Watcher watches for the updates on the specified target.
|
// Watcher watches for the updates on the specified target.
|
||||||
type Watcher interface {
|
type Watcher interface {
|
||||||
// Next blocks until an update or error happens. It may return one or more
|
// Next blocks until an update or error happens. It may return one or more
|
||||||
// updates. The first call should get the full set of the results.
|
// updates. The first call should get the full set of the results. It only
|
||||||
|
// returns the error Watcher cannot recover.
|
||||||
Next() ([]*Update, error)
|
Next() ([]*Update, error)
|
||||||
// Close closes the Watcher.
|
// Close closes the Watcher.
|
||||||
Close()
|
Close()
|
||||||
|
Reference in New Issue
Block a user