Skip to content

Commit f6afb63

Browse files
committed
A map for ClusterState is not required in ClusterResolverLoadBalancer which now holds only a single cluster's state.
1 parent 7c16de8 commit f6afb63

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

xds/src/main/java/io/grpc/xds/ClusterResolverLoadBalancer.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public LoadBalancer newLoadBalancer(Helper helper) {
168168
*/
169169
private final class ClusterResolverLbState extends LoadBalancer {
170170
private final Helper helper;
171-
private final Map<String, ClusterState> clusterStates = new HashMap<>();
171+
private ClusterState clusterState;
172172
private String cluster;
173173
private Object endpointLbConfig;
174174
private ResolvedAddresses resolvedAddresses;
@@ -187,18 +187,16 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
187187
endpointLbConfig = config.lbConfig;
188188
DiscoveryMechanism instance = config.discoveryMechanism;
189189
cluster = instance.cluster;
190-
ClusterState state;
191190
if (instance.type == DiscoveryMechanism.Type.EDS) {
192-
state = new EdsClusterState(instance.cluster, instance.edsServiceName,
191+
clusterState = new EdsClusterState(instance.cluster, instance.edsServiceName,
193192
instance.lrsServerInfo, instance.maxConcurrentRequests, instance.tlsContext,
194193
instance.filterMetadata, instance.outlierDetection);
195194
} else { // logical DNS
196-
state = new LogicalDnsClusterState(instance.cluster, instance.dnsHostName,
195+
clusterState = new LogicalDnsClusterState(instance.cluster, instance.dnsHostName,
197196
instance.lrsServerInfo, instance.maxConcurrentRequests, instance.tlsContext,
198197
instance.filterMetadata);
199198
}
200-
clusterStates.put(instance.cluster, state);
201-
state.start();
199+
clusterState.start();
202200
return Status.OK;
203201
}
204202

@@ -214,9 +212,7 @@ public void handleNameResolutionError(Status error) {
214212

215213
@Override
216214
public void shutdown() {
217-
for (ClusterState state : clusterStates.values()) {
218-
state.shutdown();
219-
}
215+
clusterState.shutdown();
220216
if (childLb != null) {
221217
childLb.shutdown();
222218
}
@@ -228,17 +224,16 @@ private void handleEndpointResourceUpdate() {
228224
List<String> priorities = new ArrayList<>(); // totally ordered priority list
229225

230226
Status endpointNotFound = Status.OK;
231-
ClusterState state = clusterStates.get(cluster);
232227
// Propagate endpoints to the child LB policy only after all clusters have been resolved.
233-
if (!state.resolved && state.status.isOk()) {
228+
if (!clusterState.resolved && clusterState.status.isOk()) {
234229
return;
235230
}
236-
if (state.result != null) {
237-
addresses.addAll(state.result.addresses);
238-
priorityChildConfigs.putAll(state.result.priorityChildConfigs);
239-
priorities.addAll(state.result.priorities);
231+
if (clusterState.result != null) {
232+
addresses.addAll(clusterState.result.addresses);
233+
priorityChildConfigs.putAll(clusterState.result.priorityChildConfigs);
234+
priorities.addAll(clusterState.result.priorities);
240235
} else {
241-
endpointNotFound = state.status;
236+
endpointNotFound = clusterState.status;
242237
}
243238
if (addresses.isEmpty()) {
244239
if (endpointNotFound.isOk()) {
@@ -271,13 +266,12 @@ private void handleEndpointResourceUpdate() {
271266
}
272267

273268
private void handleEndpointResolutionError() {
274-
ClusterState state = clusterStates.get(cluster);
275-
if (!state.status.isOk()) {
269+
if (!clusterState.status.isOk()) {
276270
if (childLb != null) {
277-
childLb.handleNameResolutionError(state.status);
271+
childLb.handleNameResolutionError(clusterState.status);
278272
} else {
279273
helper.updateBalancingState(
280-
TRANSIENT_FAILURE, new FixedResultPicker(PickResult.withError(state.status)));
274+
TRANSIENT_FAILURE, new FixedResultPicker(PickResult.withError(clusterState.status)));
281275
}
282276
}
283277
}
@@ -294,10 +288,8 @@ private RefreshableHelper(Helper delegate) {
294288

295289
@Override
296290
public void refreshNameResolution() {
297-
for (ClusterState state : clusterStates.values()) {
298-
if (state instanceof LogicalDnsClusterState) {
299-
((LogicalDnsClusterState) state).refresh();
300-
}
291+
if (clusterState instanceof LogicalDnsClusterState) {
292+
((LogicalDnsClusterState) clusterState).refresh();
301293
}
302294
}
303295

0 commit comments

Comments
 (0)