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

Method acquireChildPolicyReferences

balancer/rls/balancer.go:672–699  ·  view source on GitHub ↗

acquireChildPolicyReferences attempts to acquire references to childPolicyWrappers corresponding to the passed in targets. If there is no childPolicyWrapper corresponding to one of the targets, a new one is created and added to the BalancerGroup.

(targets []string)

Source from the content-addressed store, hash-verified

670// childPolicyWrapper corresponding to one of the targets, a new one is created
671// and added to the BalancerGroup.
672func (b *rlsBalancer) acquireChildPolicyReferences(targets []string) []*childPolicyWrapper {
673 b.stateMu.Lock()
674 var newChildPolicies []*childPolicyWrapper
675 for _, target := range targets {
676 // If the target exists in the LB policy's childPolicies map. a new
677 // reference is taken here and added to the new list.
678 if cpw := b.childPolicies[target]; cpw != nil {
679 cpw.acquireRef()
680 newChildPolicies = append(newChildPolicies, cpw)
681 continue
682 }
683
684 // If the target does not exist in the child policy map, then a new
685 // child policy wrapper is created and added to the new list.
686 cpw := newChildPolicyWrapper(target)
687 b.childPolicies[target] = cpw
688 b.bg.Add(target, b.childPolicyBuilder)
689 b.logger.Infof("Child policy %q added to BalancerGroup", target)
690 newChildPolicies = append(newChildPolicies, cpw)
691 if err := b.buildAndPushChildPolicyConfigs(target, b.lbCfg, &balancer.ClientConnState{
692 ResolverState: b.resolverState,
693 }); err != nil {
694 cpw.lamify(err)
695 }
696 }
697 b.stateMu.Unlock()
698 return newChildPolicies
699}
700
701// releaseChildPolicyReferences releases references to childPolicyWrappers
702// corresponding to the passed in targets. If the release reference was the last

Callers 1

Calls 8

newChildPolicyWrapperFunction · 0.85
acquireRefMethod · 0.80
lamifyMethod · 0.80
AddMethod · 0.65
InfofMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected