Skip to content

Commit f60ed8a

Browse files
committedJan 11, 2021
eds/lrs: handle nil when LRS is disabled (#4086)
1 parent 39242ac commit f60ed8a

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed
 

‎xds/internal/balancer/edsbalancer/eds_impl_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,33 @@ func (s) TestEDS_LoadReport(t *testing.T) {
746746
t.Errorf("store.stats() returned unexpected diff (-want +got):\n%s", diff)
747747
}
748748
}
749+
750+
// TestEDS_LoadReportDisabled covers the case that LRS is disabled. It makes
751+
// sure the EDS implementation isn't broken (doesn't panic).
752+
func (s) TestEDS_LoadReportDisabled(t *testing.T) {
753+
lsWrapper := &loadStoreWrapper{}
754+
lsWrapper.updateServiceName(testClusterNames[0])
755+
// Not calling lsWrapper.updateLoadStore(loadStore) because LRS is disabled.
756+
cw := &xdsClientWrapper{
757+
loadWrapper: lsWrapper,
758+
}
759+
760+
cc := testutils.NewTestClientConn(t)
761+
edsb := newEDSBalancerImpl(cc, nil, cw, nil)
762+
edsb.enqueueChildBalancerStateUpdate = edsb.updateState
763+
764+
// One localities, with one backend.
765+
clab1 := testutils.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
766+
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
767+
edsb.handleEDSResponse(parseEDSRespProtoForTesting(clab1.Build()))
768+
sc1 := <-cc.NewSubConnCh
769+
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
770+
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
771+
772+
// Test roundrobin with two subconns.
773+
p1 := <-cc.NewPickerCh
774+
// We call picks to make sure they don't panic.
775+
for i := 0; i < 10; i++ {
776+
p1.Pick(balancer.PickInfo{})
777+
}
778+
}

‎xds/internal/balancer/edsbalancer/xds_client_wrapper.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,33 @@ func (lsw *loadStoreWrapper) updateLoadStore(store *load.Store) {
7272
func (lsw *loadStoreWrapper) CallStarted(locality string) {
7373
lsw.mu.RLock()
7474
defer lsw.mu.RUnlock()
75-
lsw.perCluster.CallStarted(locality)
75+
if lsw.perCluster != nil {
76+
lsw.perCluster.CallStarted(locality)
77+
}
7678
}
7779

7880
func (lsw *loadStoreWrapper) CallFinished(locality string, err error) {
7981
lsw.mu.RLock()
8082
defer lsw.mu.RUnlock()
81-
lsw.perCluster.CallFinished(locality, err)
83+
if lsw.perCluster != nil {
84+
lsw.perCluster.CallFinished(locality, err)
85+
}
8286
}
8387

8488
func (lsw *loadStoreWrapper) CallServerLoad(locality, name string, val float64) {
8589
lsw.mu.RLock()
8690
defer lsw.mu.RUnlock()
87-
lsw.perCluster.CallServerLoad(locality, name, val)
91+
if lsw.perCluster != nil {
92+
lsw.perCluster.CallServerLoad(locality, name, val)
93+
}
8894
}
8995

9096
func (lsw *loadStoreWrapper) CallDropped(category string) {
9197
lsw.mu.RLock()
9298
defer lsw.mu.RUnlock()
93-
lsw.perCluster.CallDropped(category)
99+
if lsw.perCluster != nil {
100+
lsw.perCluster.CallDropped(category)
101+
}
94102
}
95103

96104
// xdsclientWrapper is responsible for getting the xds client from attributes or

‎xds/internal/balancer/lrs/balancer.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,33 @@ func (lsw *loadStoreWrapper) updateLoadStore(store *load.Store) {
187187
func (lsw *loadStoreWrapper) CallStarted(locality string) {
188188
lsw.mu.RLock()
189189
defer lsw.mu.RUnlock()
190-
lsw.perCluster.CallStarted(locality)
190+
if lsw.perCluster != nil {
191+
lsw.perCluster.CallStarted(locality)
192+
}
191193
}
192194

193195
func (lsw *loadStoreWrapper) CallFinished(locality string, err error) {
194196
lsw.mu.RLock()
195197
defer lsw.mu.RUnlock()
196-
lsw.perCluster.CallFinished(locality, err)
198+
if lsw.perCluster != nil {
199+
lsw.perCluster.CallFinished(locality, err)
200+
}
197201
}
198202

199203
func (lsw *loadStoreWrapper) CallServerLoad(locality, name string, val float64) {
200204
lsw.mu.RLock()
201205
defer lsw.mu.RUnlock()
202-
lsw.perCluster.CallServerLoad(locality, name, val)
206+
if lsw.perCluster != nil {
207+
lsw.perCluster.CallServerLoad(locality, name, val)
208+
}
203209
}
204210

205211
func (lsw *loadStoreWrapper) CallDropped(category string) {
206212
lsw.mu.RLock()
207213
defer lsw.mu.RUnlock()
208-
lsw.perCluster.CallDropped(category)
214+
if lsw.perCluster != nil {
215+
lsw.perCluster.CallDropped(category)
216+
}
209217
}
210218

211219
type xdsClientWrapper struct {

0 commit comments

Comments
 (0)
Please sign in to comment.