mirror of https://github.com/grpc/grpc-go.git
grpc: handle RemoveSubConn inline in balancerWrapper (#6228)
This commit is contained in:
parent
b15382715d
commit
21a339ce4a
|
|
@ -102,10 +102,6 @@ type switchToUpdate struct {
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
type subConnUpdate struct {
|
|
||||||
acbw *acBalancerWrapper
|
|
||||||
}
|
|
||||||
|
|
||||||
// watcher is a long-running goroutine which reads updates from a channel and
|
// watcher is a long-running goroutine which reads updates from a channel and
|
||||||
// invokes corresponding methods on the underlying balancer. It ensures that
|
// invokes corresponding methods on the underlying balancer. It ensures that
|
||||||
// these methods are invoked in a synchronous fashion. It also ensures that
|
// these methods are invoked in a synchronous fashion. It also ensures that
|
||||||
|
|
@ -132,8 +128,6 @@ func (ccb *ccBalancerWrapper) watcher() {
|
||||||
ccb.handleResolverError(update.err)
|
ccb.handleResolverError(update.err)
|
||||||
case *switchToUpdate:
|
case *switchToUpdate:
|
||||||
ccb.handleSwitchTo(update.name)
|
ccb.handleSwitchTo(update.name)
|
||||||
case *subConnUpdate:
|
|
||||||
ccb.handleRemoveSubConn(update.acbw)
|
|
||||||
default:
|
default:
|
||||||
logger.Errorf("ccBalancerWrapper.watcher: unknown update %+v, type %T", update, update)
|
logger.Errorf("ccBalancerWrapper.watcher: unknown update %+v, type %T", update, update)
|
||||||
}
|
}
|
||||||
|
|
@ -289,14 +283,6 @@ func (ccb *ccBalancerWrapper) handleSwitchTo(name string) {
|
||||||
ccb.curBalancerName = builder.Name()
|
ccb.curBalancerName = builder.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleRemoveSucConn handles a request from the underlying balancer to remove
|
|
||||||
// a subConn.
|
|
||||||
//
|
|
||||||
// See comments in RemoveSubConn() for more details.
|
|
||||||
func (ccb *ccBalancerWrapper) handleRemoveSubConn(acbw *acBalancerWrapper) {
|
|
||||||
ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ccb *ccBalancerWrapper) close() {
|
func (ccb *ccBalancerWrapper) close() {
|
||||||
ccb.closed.Fire()
|
ccb.closed.Fire()
|
||||||
<-ccb.done.Done()
|
<-ccb.done.Done()
|
||||||
|
|
@ -326,21 +312,11 @@ func (ccb *ccBalancerWrapper) NewSubConn(addrs []resolver.Address, opts balancer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ccb *ccBalancerWrapper) RemoveSubConn(sc balancer.SubConn) {
|
func (ccb *ccBalancerWrapper) RemoveSubConn(sc balancer.SubConn) {
|
||||||
// Before we switched the ccBalancerWrapper to use gracefulswitch.Balancer, it
|
|
||||||
// was required to handle the RemoveSubConn() method asynchronously by pushing
|
|
||||||
// the update onto the update channel. This was done to avoid a deadlock as
|
|
||||||
// switchBalancer() was holding cc.mu when calling Close() on the old
|
|
||||||
// balancer, which would in turn call RemoveSubConn().
|
|
||||||
//
|
|
||||||
// With the use of gracefulswitch.Balancer in ccBalancerWrapper, handling this
|
|
||||||
// asynchronously is probably not required anymore since the switchTo() method
|
|
||||||
// handles the balancer switch by pushing the update onto the channel.
|
|
||||||
// TODO(easwars): Handle this inline.
|
|
||||||
acbw, ok := sc.(*acBalancerWrapper)
|
acbw, ok := sc.(*acBalancerWrapper)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ccb.updateCh.Put(&subConnUpdate{acbw: acbw})
|
ccb.cc.removeAddrConn(acbw.getAddrConn(), errConnDrain)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ccb *ccBalancerWrapper) UpdateAddresses(sc balancer.SubConn, addrs []resolver.Address) {
|
func (ccb *ccBalancerWrapper) UpdateAddresses(sc balancer.SubConn, addrs []resolver.Address) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue