util: Remove child policy config from MultiChildLB state

The child policy config should be refreshed every address update, so it
shouldn't be stored in the ChildLbState. In addition, none of the
current usages actually used what was stored in the ChildLbState in a
meaningful way (it was always null).

ResolvedAddresses was also removed from createChildLbState(), as nothing
in it should be needed for creation; it varies over time and the values
passed at creation are immutable.
This commit is contained in:
Eric Anderson 2024-07-25 18:21:26 -07:00
parent 10d6002cbd
commit 01389774d5
6 changed files with 23 additions and 43 deletions

View File

@ -90,7 +90,7 @@ public abstract class MultiChildLoadBalancer extends LoadBalancer {
if (existingChildLbState != null) { if (existingChildLbState != null) {
childLbMap.put(endpoint, existingChildLbState); childLbMap.put(endpoint, existingChildLbState);
} else { } else {
childLbMap.put(endpoint, createChildLbState(endpoint, null, resolvedAddresses)); childLbMap.put(endpoint, createChildLbState(endpoint));
} }
} }
return childLbMap; return childLbMap;
@ -99,9 +99,8 @@ public abstract class MultiChildLoadBalancer extends LoadBalancer {
/** /**
* Override to create an instance of a subclass. * Override to create an instance of a subclass.
*/ */
protected ChildLbState createChildLbState(Object key, Object policyConfig, protected ChildLbState createChildLbState(Object key) {
ResolvedAddresses resolvedAddresses) { return new ChildLbState(key, pickFirstLbProvider);
return new ChildLbState(key, pickFirstLbProvider, policyConfig);
} }
/** /**
@ -133,11 +132,9 @@ public abstract class MultiChildLoadBalancer extends LoadBalancer {
* Override this if your keys are not of type Endpoint. * Override this if your keys are not of type Endpoint.
* @param key Key to identify the ChildLbState * @param key Key to identify the ChildLbState
* @param resolvedAddresses list of addresses which include attributes * @param resolvedAddresses list of addresses which include attributes
* @param childConfig a load balancing policy config. This field is optional.
* @return a fully loaded ResolvedAddresses object for the specified key * @return a fully loaded ResolvedAddresses object for the specified key
*/ */
protected ResolvedAddresses getChildAddresses(Object key, ResolvedAddresses resolvedAddresses, protected ResolvedAddresses getChildAddresses(Object key, ResolvedAddresses resolvedAddresses) {
Object childConfig) {
Endpoint endpointKey; Endpoint endpointKey;
if (key instanceof EquivalentAddressGroup) { if (key instanceof EquivalentAddressGroup) {
endpointKey = new Endpoint((EquivalentAddressGroup) key); endpointKey = new Endpoint((EquivalentAddressGroup) key);
@ -160,7 +157,7 @@ public abstract class MultiChildLoadBalancer extends LoadBalancer {
return resolvedAddresses.toBuilder() return resolvedAddresses.toBuilder()
.setAddresses(Collections.singletonList(eagToUse)) .setAddresses(Collections.singletonList(eagToUse))
.setAttributes(Attributes.newBuilder().set(IS_PETIOLE_POLICY, true).build()) .setAttributes(Attributes.newBuilder().set(IS_PETIOLE_POLICY, true).build())
.setLoadBalancingPolicyConfig(childConfig) .setLoadBalancingPolicyConfig(null)
.build(); .build();
} }
@ -226,10 +223,8 @@ public abstract class MultiChildLoadBalancer extends LoadBalancer {
private void updateChildrenWithResolvedAddresses(ResolvedAddresses resolvedAddresses, private void updateChildrenWithResolvedAddresses(ResolvedAddresses resolvedAddresses,
Map<Object, ChildLbState> newChildren) { Map<Object, ChildLbState> newChildren) {
for (Map.Entry<Object, ChildLbState> entry : newChildren.entrySet()) { for (Map.Entry<Object, ChildLbState> entry : newChildren.entrySet()) {
Object childConfig = entry.getValue().getConfig();
ChildLbState childLbState = childLbStates.get(entry.getKey()); ChildLbState childLbState = childLbStates.get(entry.getKey());
ResolvedAddresses childAddresses = ResolvedAddresses childAddresses = getChildAddresses(entry.getKey(), resolvedAddresses);
getChildAddresses(entry.getKey(), resolvedAddresses, childConfig);
childLbState.setResolvedAddresses(childAddresses); // update child childLbState.setResolvedAddresses(childAddresses); // update child
childLbState.lb.handleResolvedAddresses(childAddresses); // update child LB childLbState.lb.handleResolvedAddresses(childAddresses); // update child LB
} }
@ -328,15 +323,13 @@ public abstract class MultiChildLoadBalancer extends LoadBalancer {
public class ChildLbState { public class ChildLbState {
private final Object key; private final Object key;
private ResolvedAddresses resolvedAddresses; private ResolvedAddresses resolvedAddresses;
private final Object config;
private final LoadBalancer lb; private final LoadBalancer lb;
private ConnectivityState currentState; private ConnectivityState currentState;
private SubchannelPicker currentPicker = new FixedResultPicker(PickResult.withNoResult()); private SubchannelPicker currentPicker = new FixedResultPicker(PickResult.withNoResult());
public ChildLbState(Object key, LoadBalancer.Factory policyFactory, Object childConfig) { public ChildLbState(Object key, LoadBalancer.Factory policyFactory) {
this.key = key; this.key = key;
this.config = childConfig;
this.lb = policyFactory.newLoadBalancer(createChildHelper()); this.lb = policyFactory.newLoadBalancer(createChildHelper());
this.currentState = CONNECTING; this.currentState = CONNECTING;
} }
@ -400,10 +393,6 @@ public abstract class MultiChildLoadBalancer extends LoadBalancer {
resolvedAddresses = newAddresses; resolvedAddresses = newAddresses;
} }
private Object getConfig() {
return config;
}
@VisibleForTesting @VisibleForTesting
public final ResolvedAddresses getResolvedAddresses() { public final ResolvedAddresses getResolvedAddresses() {
return resolvedAddresses; return resolvedAddresses;

View File

@ -96,9 +96,8 @@ final class RoundRobinLoadBalancer extends MultiChildLoadBalancer {
} }
@Override @Override
protected ChildLbState createChildLbState(Object key, Object policyConfig, protected ChildLbState createChildLbState(Object key) {
ResolvedAddresses resolvedAddresses) { return new ChildLbState(key, pickFirstLbProvider) {
return new ChildLbState(key, pickFirstLbProvider, policyConfig) {
@Override @Override
protected ChildLbStateHelper createChildHelper() { protected ChildLbStateHelper createChildHelper() {
return new ChildLbStateHelper() { return new ChildLbStateHelper() {

View File

@ -70,8 +70,7 @@ class ClusterManagerLoadBalancer extends MultiChildLoadBalancer {
} }
@Override @Override
protected ResolvedAddresses getChildAddresses(Object key, ResolvedAddresses resolvedAddresses, protected ResolvedAddresses getChildAddresses(Object key, ResolvedAddresses resolvedAddresses) {
Object unusedChildConfig) {
ClusterManagerConfig config = (ClusterManagerConfig) ClusterManagerConfig config = (ClusterManagerConfig)
resolvedAddresses.getLoadBalancingPolicyConfig(); resolvedAddresses.getLoadBalancingPolicyConfig();
Object childConfig = config.childPolicies.get(key); Object childConfig = config.childPolicies.get(key);
@ -87,7 +86,7 @@ class ClusterManagerLoadBalancer extends MultiChildLoadBalancer {
for (String key : config.childPolicies.keySet()) { for (String key : config.childPolicies.keySet()) {
ChildLbState child = getChildLbState(key); ChildLbState child = getChildLbState(key);
if (child == null) { if (child == null) {
child = new ClusterManagerLbState(key, GracefulSwitchLoadBalancerFactory.INSTANCE, null); child = new ClusterManagerLbState(key, GracefulSwitchLoadBalancerFactory.INSTANCE);
} }
newChildPolicies.put(key, child); newChildPolicies.put(key, child);
} }
@ -204,9 +203,8 @@ class ClusterManagerLoadBalancer extends MultiChildLoadBalancer {
@Nullable @Nullable
ScheduledHandle deletionTimer; ScheduledHandle deletionTimer;
public ClusterManagerLbState(Object key, LoadBalancer.Factory policyFactory, public ClusterManagerLbState(Object key, LoadBalancer.Factory policyFactory) {
Object childConfig) { super(key, policyFactory);
super(key, policyFactory, childConfig);
} }
@Override @Override

View File

@ -126,9 +126,8 @@ final class LeastRequestLoadBalancer extends MultiChildLoadBalancer {
} }
@Override @Override
protected ChildLbState createChildLbState(Object key, Object policyConfig, protected ChildLbState createChildLbState(Object key) {
ResolvedAddresses unused) { return new LeastRequestLbState(key, pickFirstLbProvider);
return new LeastRequestLbState(key, pickFirstLbProvider, policyConfig);
} }
private void updateBalancingState(ConnectivityState state, SubchannelPicker picker) { private void updateBalancingState(ConnectivityState state, SubchannelPicker picker) {
@ -320,9 +319,8 @@ final class LeastRequestLoadBalancer extends MultiChildLoadBalancer {
protected class LeastRequestLbState extends ChildLbState { protected class LeastRequestLbState extends ChildLbState {
private final AtomicInteger activeRequests = new AtomicInteger(0); private final AtomicInteger activeRequests = new AtomicInteger(0);
public LeastRequestLbState(Object key, LoadBalancerProvider policyProvider, public LeastRequestLbState(Object key, LoadBalancerProvider policyProvider) {
Object childConfig) { super(key, policyProvider);
super(key, policyProvider, childConfig);
} }
int getActiveRequests() { int getActiveRequests() {

View File

@ -219,9 +219,8 @@ final class RingHashLoadBalancer extends MultiChildLoadBalancer {
} }
@Override @Override
protected ChildLbState createChildLbState(Object key, Object policyConfig, protected ChildLbState createChildLbState(Object key) {
ResolvedAddresses resolvedAddresses) { return new ChildLbState(key, lazyLbFactory);
return new ChildLbState(key, lazyLbFactory, null);
} }
private Status validateAddrList(List<EquivalentAddressGroup> addrList) { private Status validateAddrList(List<EquivalentAddressGroup> addrList) {

View File

@ -148,10 +148,8 @@ final class WeightedRoundRobinLoadBalancer extends MultiChildLoadBalancer {
} }
@Override @Override
protected ChildLbState createChildLbState(Object key, Object policyConfig, protected ChildLbState createChildLbState(Object key) {
ResolvedAddresses unused) { return new WeightedChildLbState(key, pickFirstLbProvider);
ChildLbState childLbState = new WeightedChildLbState(key, pickFirstLbProvider, policyConfig);
return childLbState;
} }
@Override @Override
@ -289,9 +287,8 @@ final class WeightedRoundRobinLoadBalancer extends MultiChildLoadBalancer {
private OrcaReportListener orcaReportListener; private OrcaReportListener orcaReportListener;
public WeightedChildLbState( public WeightedChildLbState(Object key, LoadBalancerProvider policyProvider) {
Object key, LoadBalancerProvider policyProvider, Object childConfig) { super(key, policyProvider);
super(key, policyProvider, childConfig);
} }
@Override @Override