util: Remove MultiChildLB.getImmutableChildMap()

No usages actually needed a map nor a copy.
This commit is contained in:
Eric Anderson 2024-07-29 11:40:05 -07:00
parent c120e364d2
commit 778a00b623
2 changed files with 6 additions and 13 deletions

View File

@ -26,7 +26,6 @@ import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.grpc.Attributes; import io.grpc.Attributes;
import io.grpc.ConnectivityState; import io.grpc.ConnectivityState;
import io.grpc.EquivalentAddressGroup; import io.grpc.EquivalentAddressGroup;
@ -281,11 +280,6 @@ public abstract class MultiChildLoadBalancer extends LoadBalancer {
return helper; return helper;
} }
@VisibleForTesting
public final ImmutableMap<Object, ChildLbState> getImmutableChildMap() {
return ImmutableMap.copyOf(childLbStates);
}
@VisibleForTesting @VisibleForTesting
public final Collection<ChildLbState> getChildLbStates() { public final Collection<ChildLbState> getChildLbStates() {
return childLbStates.values(); return childLbStates.values();

View File

@ -27,7 +27,6 @@ import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.collect.HashMultiset; import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multiset; import com.google.common.collect.Multiset;
import com.google.common.primitives.UnsignedInteger; import com.google.common.primitives.UnsignedInteger;
import io.grpc.Attributes; import io.grpc.Attributes;
@ -42,6 +41,7 @@ import io.grpc.xds.client.XdsLogger;
import io.grpc.xds.client.XdsLogger.XdsLogLevel; import io.grpc.xds.client.XdsLogger.XdsLogLevel;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -213,7 +213,7 @@ final class RingHashLoadBalancer extends MultiChildLoadBalancer {
overallState = TRANSIENT_FAILURE; overallState = TRANSIENT_FAILURE;
} }
RingHashPicker picker = new RingHashPicker(syncContext, ring, getImmutableChildMap()); RingHashPicker picker = new RingHashPicker(syncContext, ring, getChildLbStates());
getHelper().updateBalancingState(overallState, picker); getHelper().updateBalancingState(overallState, picker);
this.currentConnectivityState = overallState; this.currentConnectivityState = overallState;
} }
@ -345,13 +345,12 @@ final class RingHashLoadBalancer extends MultiChildLoadBalancer {
private RingHashPicker( private RingHashPicker(
SynchronizationContext syncContext, List<RingEntry> ring, SynchronizationContext syncContext, List<RingEntry> ring,
ImmutableMap<Object, ChildLbState> subchannels) { Collection<ChildLbState> children) {
this.syncContext = syncContext; this.syncContext = syncContext;
this.ring = ring; this.ring = ring;
pickableSubchannels = new HashMap<>(subchannels.size()); pickableSubchannels = new HashMap<>(children.size());
for (Map.Entry<Object, ChildLbState> entry : subchannels.entrySet()) { for (ChildLbState childLbState : children) {
ChildLbState childLbState = entry.getValue(); pickableSubchannels.put((Endpoint)childLbState.getKey(),
pickableSubchannels.put((Endpoint)entry.getKey(),
new SubchannelView(childLbState, childLbState.getCurrentState())); new SubchannelView(childLbState, childLbState.getCurrentState()));
} }
} }