@@ -168,8 +168,8 @@ public LoadBalancer newLoadBalancer(Helper helper) {
168168 */
169169 private final class ClusterResolverLbState extends LoadBalancer {
170170 private final Helper helper ;
171- private final List <String > clusters = new ArrayList <>();
172171 private final Map <String , ClusterState > clusterStates = new HashMap <>();
172+ private String cluster ;
173173 private Object endpointLbConfig ;
174174 private ResolvedAddresses resolvedAddresses ;
175175 private LoadBalancer childLb ;
@@ -186,7 +186,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
186186 (ClusterResolverConfig ) resolvedAddresses .getLoadBalancingPolicyConfig ();
187187 endpointLbConfig = config .lbConfig ;
188188 DiscoveryMechanism instance = config .discoveryMechanism ;
189- clusters . add ( instance .cluster ) ;
189+ cluster = instance .cluster ;
190190 ClusterState state ;
191191 if (instance .type == DiscoveryMechanism .Type .EDS ) {
192192 state = new EdsClusterState (instance .cluster , instance .edsServiceName ,
@@ -228,24 +228,22 @@ private void handleEndpointResourceUpdate() {
228228 List <String > priorities = new ArrayList <>(); // totally ordered priority list
229229
230230 Status endpointNotFound = Status .OK ;
231- for (String cluster : clusters ) {
232- ClusterState state = clusterStates .get (cluster );
233- // Propagate endpoints to the child LB policy only after all clusters have been resolved.
234- if (!state .resolved && state .status .isOk ()) {
235- return ;
236- }
237- if (state .result != null ) {
238- addresses .addAll (state .result .addresses );
239- priorityChildConfigs .putAll (state .result .priorityChildConfigs );
240- priorities .addAll (state .result .priorities );
241- } else {
242- endpointNotFound = state .status ;
243- }
231+ ClusterState state = clusterStates .get (cluster );
232+ // Propagate endpoints to the child LB policy only after all clusters have been resolved.
233+ if (!state .resolved && state .status .isOk ()) {
234+ return ;
235+ }
236+ if (state .result != null ) {
237+ addresses .addAll (state .result .addresses );
238+ priorityChildConfigs .putAll (state .result .priorityChildConfigs );
239+ priorities .addAll (state .result .priorities );
240+ } else {
241+ endpointNotFound = state .status ;
244242 }
245243 if (addresses .isEmpty ()) {
246244 if (endpointNotFound .isOk ()) {
247245 endpointNotFound = Status .UNAVAILABLE .withDescription (
248- "No usable endpoint from cluster(s): " + clusters );
246+ "No usable endpoint from cluster(s): " + cluster );
249247 } else {
250248 endpointNotFound =
251249 Status .UNAVAILABLE .withCause (endpointNotFound .getCause ())
@@ -273,22 +271,13 @@ private void handleEndpointResourceUpdate() {
273271 }
274272
275273 private void handleEndpointResolutionError () {
276- boolean allInError = true ;
277- Status error = null ;
278- for (String cluster : clusters ) {
279- ClusterState state = clusterStates .get (cluster );
280- if (state .status .isOk ()) {
281- allInError = false ;
282- } else {
283- error = state .status ;
284- }
285- }
286- if (allInError ) {
274+ ClusterState state = clusterStates .get (cluster );
275+ if (!state .status .isOk ()) {
287276 if (childLb != null ) {
288- childLb .handleNameResolutionError (error );
277+ childLb .handleNameResolutionError (state . status );
289278 } else {
290279 helper .updateBalancingState (
291- TRANSIENT_FAILURE , new FixedResultPicker (PickResult .withError (error )));
280+ TRANSIENT_FAILURE , new FixedResultPicker (PickResult .withError (state . status )));
292281 }
293282 }
294283 }
0 commit comments