Skip to content

Commit

Permalink
Responded to Menghan's implementation change
Browse files Browse the repository at this point in the history
  • Loading branch information
zasweq committed Mar 22, 2022
1 parent 48f844b commit 3848f2c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions internal/balancergroup/balancergroup.go
Expand Up @@ -165,10 +165,18 @@ func (sbc *subBalancerWrapper) stopBalancer() {
sbc.balancer = nil
}

func (sbc *subBalancerWrapper) gracefulSwitch() {
func (sbc *subBalancerWrapper) gracefulSwitch(builder balancer.Builder) {
sbc.builder = builder
b := sbc.balancer
sbc.group.logger.Infof("Switching child policy %v to type %v", sbc.id, sbc.builder.Name())
b.SwitchTo(sbc.builder)
// Even if you get an add and it persists builder but doesn't start
// balancer, this would leave graceful switch being nil, in which we are
// correctly overwriting with the recent builder here as well to use later.
// The graceful switch balancer's presence is an invariant of whether the
// balancer group is closed or not (if closed, nil, if started, present).
if sbc.balancer != nil {
sbc.group.logger.Infof("Switching child policy %v to type %v", sbc.id, sbc.builder.Name())
b.SwitchTo(sbc.builder)
}
}

// BalancerGroup takes a list of balancers, and make them into one balancer.
Expand Down Expand Up @@ -351,15 +359,7 @@ func (bg *BalancerGroup) UpdateBuilder(id string, builder balancer.Builder) {
// simply ignore it if not present, don't error
return
}
sbc.builder = builder
// Even if you get an add and it persists builder but doesn't start
// balancer, this would leave graceful switch being nil, in which we are
// correctly overwriting with the recent builder here as well to use later.
// The graceful switch balancer's presence is an invariant of whether the
// balancer group is closed or not (if closed, nil, if started, present).
if sbc.balancer != nil {
sbc.gracefulSwitch()
}
sbc.gracefulSwitch(builder)
bg.outgoingMu.Unlock()
}

Expand Down

0 comments on commit 3848f2c

Please sign in to comment.