Skip to content

Commit

Permalink
balancer/weightedroundrobin: migrate to StateListener (#6530)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley authored Aug 9, 2023
1 parent 175c84c commit 61a1f77
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion balancer/weightedroundrobin/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ func (b *wrrBalancer) updateAddresses(addrs []resolver.Address) {
wsc = wsci.(*weightedSubConn)
} else {
// addr is a new address (not existing in b.subConns).
sc, err := b.cc.NewSubConn([]resolver.Address{addr}, balancer.NewSubConnOptions{})
var sc balancer.SubConn
sc, err := b.cc.NewSubConn([]resolver.Address{addr}, balancer.NewSubConnOptions{
StateListener: func(state balancer.SubConnState) {
b.updateSubConnState(sc, state)
},
})
if err != nil {
b.logger.Warningf("Failed to create new SubConn for address %v: %v", addr, err)
continue
Expand Down Expand Up @@ -205,6 +210,10 @@ func (b *wrrBalancer) ResolverError(err error) {
}

func (b *wrrBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
b.logger.Errorf("UpdateSubConnState(%v, %+v) called unexpectedly", sc, state)
}

func (b *wrrBalancer) updateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
wsc := b.scMap[sc]
if wsc == nil {
b.logger.Errorf("UpdateSubConnState called with an unknown SubConn: %p, %v", sc, state)
Expand Down

0 comments on commit 61a1f77

Please sign in to comment.