@@ -139,12 +139,17 @@ func (edsImpl *edsBalancerImpl) handleChildPolicy(name string, config json.RawMe
139
139
continue
140
140
}
141
141
for lid , config := range bgwc .configs {
142
+ lidJSON , err := lid .ToString ()
143
+ if err != nil {
144
+ edsImpl .logger .Errorf ("failed to marshal LocalityID: %#v, skipping this locality" , lid )
145
+ continue
146
+ }
142
147
// TODO: (eds) add support to balancer group to support smoothly
143
148
// switching sub-balancers (keep old balancer around until new
144
149
// balancer becomes ready).
145
- bgwc .bg .Remove (lid . String () )
146
- bgwc .bg .Add (lid . String () , edsImpl .subBalancerBuilder )
147
- bgwc .bg .UpdateClientConnState (lid . String () , balancer.ClientConnState {
150
+ bgwc .bg .Remove (lidJSON )
151
+ bgwc .bg .Add (lidJSON , edsImpl .subBalancerBuilder )
152
+ bgwc .bg .UpdateClientConnState (lidJSON , balancer.ClientConnState {
148
153
ResolverState : resolver.State {Addresses : config .addrs },
149
154
})
150
155
// This doesn't need to manually update picker, because the new
@@ -282,6 +287,11 @@ func (edsImpl *edsBalancerImpl) handleEDSResponsePerPriority(bgwc *balancerGroup
282
287
// One balancer for each locality.
283
288
284
289
lid := locality .ID
290
+ lidJSON , err := lid .ToString ()
291
+ if err != nil {
292
+ edsImpl .logger .Errorf ("failed to marshal LocalityID: %#v, skipping this locality" , lid )
293
+ continue
294
+ }
285
295
newLocalitiesSet [lid ] = struct {}{}
286
296
287
297
newWeight := locality .Weight
@@ -316,8 +326,8 @@ func (edsImpl *edsBalancerImpl) handleEDSResponsePerPriority(bgwc *balancerGroup
316
326
config , ok := bgwc .configs [lid ]
317
327
if ! ok {
318
328
// A new balancer, add it to balancer group and balancer map.
319
- bgwc .stateAggregator .Add (lid . String () , newWeight )
320
- bgwc .bg .Add (lid . String () , edsImpl .subBalancerBuilder )
329
+ bgwc .stateAggregator .Add (lidJSON , newWeight )
330
+ bgwc .bg .Add (lidJSON , edsImpl .subBalancerBuilder )
321
331
config = & localityConfig {
322
332
weight : newWeight ,
323
333
}
@@ -340,23 +350,28 @@ func (edsImpl *edsBalancerImpl) handleEDSResponsePerPriority(bgwc *balancerGroup
340
350
341
351
if weightChanged {
342
352
config .weight = newWeight
343
- bgwc .stateAggregator .UpdateWeight (lid . String () , newWeight )
353
+ bgwc .stateAggregator .UpdateWeight (lidJSON , newWeight )
344
354
rebuildStateAndPicker = true
345
355
}
346
356
347
357
if addrsChanged {
348
358
config .addrs = newAddrs
349
- bgwc .bg .UpdateClientConnState (lid . String () , balancer.ClientConnState {
359
+ bgwc .bg .UpdateClientConnState (lidJSON , balancer.ClientConnState {
350
360
ResolverState : resolver.State {Addresses : newAddrs },
351
361
})
352
362
}
353
363
}
354
364
355
365
// Delete localities that are removed in the latest response.
356
366
for lid := range bgwc .configs {
367
+ lidJSON , err := lid .ToString ()
368
+ if err != nil {
369
+ edsImpl .logger .Errorf ("failed to marshal LocalityID: %#v, skipping this locality" , lid )
370
+ continue
371
+ }
357
372
if _ , ok := newLocalitiesSet [lid ]; ! ok {
358
- bgwc .stateAggregator .Remove (lid . String () )
359
- bgwc .bg .Remove (lid . String () )
373
+ bgwc .stateAggregator .Remove (lidJSON )
374
+ bgwc .bg .Remove (lidJSON )
360
375
delete (bgwc .configs , lid )
361
376
edsImpl .logger .Infof ("Locality %v deleted" , lid )
362
377
rebuildStateAndPicker = true
0 commit comments