@@ -91,6 +91,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
9191 checkNotNull (config , "missing priority lb config" );
9292 priorityNames = config .priorities ;
9393 priorityConfigs = config .childConfigs ;
94+ Status status = Status .OK ;
9495 Set <String > prioritySet = new HashSet <>(config .priorities );
9596 ArrayList <String > childKeys = new ArrayList <>(children .keySet ());
9697 for (String priority : childKeys ) {
@@ -105,12 +106,18 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
105106 for (String priority : priorityNames ) {
106107 ChildLbState childLbState = children .get (priority );
107108 if (childLbState != null ) {
108- childLbState .updateResolvedAddresses ();
109+ Status newStatus = childLbState .updateResolvedAddresses ();
110+ if (!newStatus .isOk ()) {
111+ status = newStatus ;
112+ }
109113 }
110114 }
111115 handlingResolvedAddresses = false ;
112- tryNextPriority ();
113- return Status .OK ;
116+ Status newStatus = tryNextPriority ();
117+ if (!newStatus .isOk ()) {
118+ status = newStatus ;
119+ }
120+ return status ;
114121 }
115122
116123 @ Override
@@ -140,7 +147,7 @@ public void shutdown() {
140147 children .clear ();
141148 }
142149
143- private void tryNextPriority () {
150+ private Status tryNextPriority () {
144151 for (int i = 0 ; i < priorityNames .size (); i ++) {
145152 String priority = priorityNames .get (i );
146153 if (!children .containsKey (priority )) {
@@ -151,8 +158,7 @@ private void tryNextPriority() {
151158 // Calling the child's updateResolvedAddresses() can result in tryNextPriority() being
152159 // called recursively. We need to be sure to be done with processing here before it is
153160 // called.
154- child .updateResolvedAddresses ();
155- return ; // Give priority i time to connect.
161+ return child .updateResolvedAddresses (); // Give priority i time to connect.
156162 }
157163 ChildLbState child = children .get (priority );
158164 child .reactivate ();
@@ -165,23 +171,24 @@ private void tryNextPriority() {
165171 children .get (p ).deactivate ();
166172 }
167173 }
168- return ;
174+ return Status . OK ;
169175 }
170176 if (child .failOverTimer != null && child .failOverTimer .isPending ()) {
171177 updateOverallState (priority , child .connectivityState , child .picker );
172- return ; // Give priority i time to connect.
178+ return Status . OK ; // Give priority i time to connect.
173179 }
174180 if (priority .equals (currentPriority ) && child .connectivityState != TRANSIENT_FAILURE ) {
175181 // If the current priority is not changed into TRANSIENT_FAILURE, keep using it.
176182 updateOverallState (priority , child .connectivityState , child .picker );
177- return ;
183+ return Status . OK ;
178184 }
179185 }
180186 // TODO(zdapeng): Include error details of each priority.
181187 logger .log (XdsLogLevel .DEBUG , "All priority failed" );
182188 String lastPriority = priorityNames .get (priorityNames .size () - 1 );
183189 SubchannelPicker errorPicker = children .get (lastPriority ).picker ;
184190 updateOverallState (lastPriority , TRANSIENT_FAILURE , errorPicker );
191+ return Status .OK ;
185192 }
186193
187194 private void updateOverallState (
@@ -228,7 +235,11 @@ public void run() {
228235 Status .UNAVAILABLE .withDescription ("Connection timeout for priority " + priority )));
229236 logger .log (XdsLogLevel .DEBUG , "Priority {0} failed over to next" , priority );
230237 currentPriority = null ; // reset currentPriority to guarantee failover happen
231- tryNextPriority ();
238+ Status status = tryNextPriority ();
239+ if (!status .isOk ()) {
240+ // A child had a problem with the addresses/config. Request it to be refreshed
241+ helper .refreshNameResolution ();
242+ }
232243 }
233244 }
234245
@@ -279,10 +290,10 @@ void tearDown() {
279290 * resolvedAddresses}, or when priority lb receives a new resolved addresses while the child
280291 * already exists.
281292 */
282- void updateResolvedAddresses () {
293+ Status updateResolvedAddresses () {
283294 PriorityLbConfig config =
284295 (PriorityLbConfig ) resolvedAddresses .getLoadBalancingPolicyConfig ();
285- lb .handleResolvedAddresses (
296+ return lb .acceptResolvedAddresses (
286297 resolvedAddresses .toBuilder ()
287298 .setAddresses (AddressFilter .filter (resolvedAddresses .getAddresses (), priority ))
288299 .setLoadBalancingPolicyConfig (config .childConfigs .get (priority ).childConfig )
@@ -331,7 +342,11 @@ public void updateBalancingState(final ConnectivityState newState,
331342 // If we are currently handling newly resolved addresses, let's not try to reconfigure as
332343 // the address handling process will take care of that to provide an atomic config update.
333344 if (!handlingResolvedAddresses ) {
334- tryNextPriority ();
345+ Status status = tryNextPriority ();
346+ if (!status .isOk ()) {
347+ // A child had a problem with the addresses/config. Request it to be refreshed
348+ helper .refreshNameResolution ();
349+ }
335350 }
336351 }
337352
0 commit comments