Skip to content

Commit 58beff1

Browse files
authored
balancergroup: add method to exitIdle a sub-balancer (#4994)
This is required for the RLS LB policy. At pick time, if the RLS picker finds one of its child policies in IDLE, it needs to be able to ask it to exit idle.
1 parent 6f8796b commit 58beff1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

internal/balancergroup/balancergroup.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,13 @@ func (bg *BalancerGroup) ExitIdle() {
506506
}
507507
bg.outgoingMu.Unlock()
508508
}
509+
510+
// ExitIdleOne instructs the sub-balancer `id` to exit IDLE state, if
511+
// appropriate and possible.
512+
func (bg *BalancerGroup) ExitIdleOne(id string) {
513+
bg.outgoingMu.Lock()
514+
if config := bg.idToBalancerConfig[id]; config != nil {
515+
config.exitIdle()
516+
}
517+
bg.outgoingMu.Unlock()
518+
}

internal/balancergroup/balancergroup_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,29 @@ func (s) TestBalancerGroupBuildOptions(t *testing.T) {
509509
t.Fatal(err)
510510
}
511511
}
512+
513+
func (s) TestBalancerExitIdleOne(t *testing.T) {
514+
const balancerName = "stub-balancer-test-balancergroup-exit-idle-one"
515+
exitIdleCh := make(chan struct{}, 1)
516+
stub.Register(balancerName, stub.BalancerFuncs{
517+
ExitIdle: func(*stub.BalancerData) {
518+
exitIdleCh <- struct{}{}
519+
},
520+
})
521+
cc := testutils.NewTestClientConn(t)
522+
bg := New(cc, balancer.BuildOptions{}, nil, nil)
523+
bg.Start()
524+
defer bg.Close()
525+
526+
// Add the stub balancer build above as a child policy.
527+
builder := balancer.Get(balancerName)
528+
bg.Add(testBalancerIDs[0], builder)
529+
530+
// Call ExitIdle on the child policy.
531+
bg.ExitIdleOne(testBalancerIDs[0])
532+
select {
533+
case <-time.After(time.Second):
534+
t.Fatal("Timeout when waiting for ExitIdle to be invoked on child policy")
535+
case <-exitIdleCh:
536+
}
537+
}

0 commit comments

Comments
 (0)