Skip to content

Commit 61a1f77

Browse files
authored
balancer/weightedroundrobin: migrate to StateListener (#6530)
1 parent 175c84c commit 61a1f77

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

balancer/weightedroundrobin/balancer.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ func (b *wrrBalancer) updateAddresses(addrs []resolver.Address) {
154154
wsc = wsci.(*weightedSubConn)
155155
} else {
156156
// addr is a new address (not existing in b.subConns).
157-
sc, err := b.cc.NewSubConn([]resolver.Address{addr}, balancer.NewSubConnOptions{})
157+
var sc balancer.SubConn
158+
sc, err := b.cc.NewSubConn([]resolver.Address{addr}, balancer.NewSubConnOptions{
159+
StateListener: func(state balancer.SubConnState) {
160+
b.updateSubConnState(sc, state)
161+
},
162+
})
158163
if err != nil {
159164
b.logger.Warningf("Failed to create new SubConn for address %v: %v", addr, err)
160165
continue
@@ -205,6 +210,10 @@ func (b *wrrBalancer) ResolverError(err error) {
205210
}
206211

207212
func (b *wrrBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
213+
b.logger.Errorf("UpdateSubConnState(%v, %+v) called unexpectedly", sc, state)
214+
}
215+
216+
func (b *wrrBalancer) updateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
208217
wsc := b.scMap[sc]
209218
if wsc == nil {
210219
b.logger.Errorf("UpdateSubConnState called with an unknown SubConn: %p, %v", sc, state)

0 commit comments

Comments
 (0)