Skip to content

Commit

Permalink
internal/balancergroup: remove usage of UpdateSubConnState (#6528)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley authored Aug 10, 2023
1 parent 5da2731 commit ebc3c51
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions internal/balancergroup/balancergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ func (sbc *subBalancerWrapper) exitIdle() (complete bool) {
return true
}

func (sbc *subBalancerWrapper) updateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
b := sbc.balancer
if b == nil {
// This sub-balancer was closed. This can happen when EDS removes a
// locality. The balancer for this locality was already closed, and the
// SubConns are being deleted. But SubConn state change can still
// happen.
return
}
b.UpdateSubConnState(sc, state)
}

func (sbc *subBalancerWrapper) updateClientConnState(s balancer.ClientConnState) error {
sbc.ccState = &s
b := sbc.balancer
Expand Down Expand Up @@ -244,7 +232,7 @@ type BalancerGroup struct {
// incomingMu guards all operations in the direction:
// Sub-balancer-->ClientConn. Including NewSubConn, RemoveSubConn. It also
// guards the map from SubConn to balancer ID, so updateSubConnState needs
// to hold it shortly to find the sub-balancer to forward the update.
// to hold it shortly to potentially delete from the map.
//
// UpdateState is called by the balancer state aggretator, and it will
// decide when and whether to call.
Expand Down Expand Up @@ -449,12 +437,11 @@ func (bg *BalancerGroup) connect(sb *subBalancerWrapper) {

// Following are actions from the parent grpc.ClientConn, forward to sub-balancers.

// updateSubConnState handles the state for the subconn. It finds the
// corresponding balancer and forwards the update to cb.
// updateSubConnState forwards the update to cb and updates scToSubBalancer if
// needed.
func (bg *BalancerGroup) updateSubConnState(sc balancer.SubConn, state balancer.SubConnState, cb func(balancer.SubConnState)) {
bg.incomingMu.Lock()
config, ok := bg.scToSubBalancer[sc]
if !ok {
if _, ok := bg.scToSubBalancer[sc]; !ok {
bg.incomingMu.Unlock()
return
}
Expand All @@ -467,16 +454,14 @@ func (bg *BalancerGroup) updateSubConnState(sc balancer.SubConn, state balancer.
bg.outgoingMu.Lock()
if cb != nil {
cb(state)
} else {
config.updateSubConnState(sc, state)
}
bg.outgoingMu.Unlock()
}

// UpdateSubConnState handles the state for the subconn. It finds the
// corresponding balancer and forwards the update.
func (bg *BalancerGroup) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
bg.updateSubConnState(sc, state, nil)
bg.logger.Errorf("UpdateSubConnState(%v, %+v) called unexpectedly", sc, state)
}

// UpdateClientConnState handles ClientState (including balancer config and
Expand Down

0 comments on commit ebc3c51

Please sign in to comment.