MCPcopy
hub / github.com/grpc/grpc-go / handleChildPolicyConfigUpdate

Method handleChildPolicyConfigUpdate

balancer/rls/balancer.go:388–448  ·  view source on GitHub ↗

handleChildPolicyConfigUpdate handles updates to service config fields which influence child policy configuration. Caller must hold lb.stateMu.

(newCfg *lbConfig, ccs *balancer.ClientConnState)

Source from the content-addressed store, hash-verified

386//
387// Caller must hold lb.stateMu.
388func (b *rlsBalancer) handleChildPolicyConfigUpdate(newCfg *lbConfig, ccs *balancer.ClientConnState) {
389 // Update child policy builder first since other steps are dependent on this.
390 if b.childPolicyBuilder == nil || b.childPolicyBuilder.Name() != newCfg.childPolicyName {
391 b.logger.Infof("Child policy changed to %q", newCfg.childPolicyName)
392 b.childPolicyBuilder = balancer.Get(newCfg.childPolicyName)
393 for _, cpw := range b.childPolicies {
394 // If the child policy has changed, we need to remove the old policy
395 // from the BalancerGroup and add a new one. The BalancerGroup takes
396 // care of closing the old one in this case.
397 b.bg.Remove(cpw.target)
398 b.bg.Add(cpw.target, b.childPolicyBuilder)
399 }
400 }
401
402 configSentToDefault := false
403 if b.lbCfg.defaultTarget != newCfg.defaultTarget {
404 // If the default target has changed, create a new childPolicyWrapper for
405 // the new target if required. If a new wrapper is created, add it to the
406 // childPolicies map and the BalancerGroup.
407 b.logger.Infof("Default target in LB config changing from %q to %q", b.lbCfg.defaultTarget, newCfg.defaultTarget)
408 cpw := b.childPolicies[newCfg.defaultTarget]
409 if cpw == nil {
410 cpw = newChildPolicyWrapper(newCfg.defaultTarget)
411 b.childPolicies[newCfg.defaultTarget] = cpw
412 b.bg.Add(newCfg.defaultTarget, b.childPolicyBuilder)
413 b.logger.Infof("Child policy %q added to BalancerGroup", newCfg.defaultTarget)
414 }
415 if err := b.buildAndPushChildPolicyConfigs(newCfg.defaultTarget, newCfg, ccs); err != nil {
416 cpw.lamify(err)
417 }
418
419 // If an old default exists, release its reference. If this was the last
420 // reference, remove the child policy from the BalancerGroup and remove the
421 // corresponding entry the childPolicies map.
422 if b.defaultPolicy != nil {
423 if b.defaultPolicy.releaseRef() {
424 delete(b.childPolicies, b.lbCfg.defaultTarget)
425 b.bg.Remove(b.defaultPolicy.target)
426 }
427 }
428 b.defaultPolicy = cpw
429 configSentToDefault = true
430 }
431
432 // No change in configuration affecting child policies. Return early.
433 if b.lbCfg.childPolicyName == newCfg.childPolicyName && b.lbCfg.childPolicyTargetField == newCfg.childPolicyTargetField && childPolicyConfigEqual(b.lbCfg.childPolicyConfig, newCfg.childPolicyConfig) {
434 return
435 }
436
437 // If fields affecting child policy configuration have changed, the changes
438 // are pushed to the childPolicyWrapper which handles them appropriately.
439 for _, cpw := range b.childPolicies {
440 if configSentToDefault && cpw.target == newCfg.defaultTarget {
441 // Default target has already been taken care of.
442 continue
443 }
444 if err := b.buildAndPushChildPolicyConfigs(cpw.target, newCfg, ccs); err != nil {
445 cpw.lamify(err)

Callers 1

UpdateClientConnStateMethod · 0.95

Calls 10

GetFunction · 0.92
newChildPolicyWrapperFunction · 0.85
childPolicyConfigEqualFunction · 0.85
lamifyMethod · 0.80
releaseRefMethod · 0.80
NameMethod · 0.65
InfofMethod · 0.65
AddMethod · 0.65
RemoveMethod · 0.45

Tested by

no test coverage detected