@@ -91,6 +91,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
91
91
checkNotNull (config , "missing priority lb config" );
92
92
priorityNames = config .priorities ;
93
93
priorityConfigs = config .childConfigs ;
94
+ Status status = Status .OK ;
94
95
Set <String > prioritySet = new HashSet <>(config .priorities );
95
96
ArrayList <String > childKeys = new ArrayList <>(children .keySet ());
96
97
for (String priority : childKeys ) {
@@ -105,12 +106,18 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
105
106
for (String priority : priorityNames ) {
106
107
ChildLbState childLbState = children .get (priority );
107
108
if (childLbState != null ) {
108
- childLbState .updateResolvedAddresses ();
109
+ Status newStatus = childLbState .updateResolvedAddresses ();
110
+ if (!newStatus .isOk ()) {
111
+ status = newStatus ;
112
+ }
109
113
}
110
114
}
111
115
handlingResolvedAddresses = false ;
112
- tryNextPriority ();
113
- return Status .OK ;
116
+ Status newStatus = tryNextPriority ();
117
+ if (!newStatus .isOk ()) {
118
+ status = newStatus ;
119
+ }
120
+ return status ;
114
121
}
115
122
116
123
@ Override
@@ -140,7 +147,7 @@ public void shutdown() {
140
147
children .clear ();
141
148
}
142
149
143
- private void tryNextPriority () {
150
+ private Status tryNextPriority () {
144
151
for (int i = 0 ; i < priorityNames .size (); i ++) {
145
152
String priority = priorityNames .get (i );
146
153
if (!children .containsKey (priority )) {
@@ -151,8 +158,7 @@ private void tryNextPriority() {
151
158
// Calling the child's updateResolvedAddresses() can result in tryNextPriority() being
152
159
// called recursively. We need to be sure to be done with processing here before it is
153
160
// called.
154
- child .updateResolvedAddresses ();
155
- return ; // Give priority i time to connect.
161
+ return child .updateResolvedAddresses (); // Give priority i time to connect.
156
162
}
157
163
ChildLbState child = children .get (priority );
158
164
child .reactivate ();
@@ -165,23 +171,24 @@ private void tryNextPriority() {
165
171
children .get (p ).deactivate ();
166
172
}
167
173
}
168
- return ;
174
+ return Status . OK ;
169
175
}
170
176
if (child .failOverTimer != null && child .failOverTimer .isPending ()) {
171
177
updateOverallState (priority , child .connectivityState , child .picker );
172
- return ; // Give priority i time to connect.
178
+ return Status . OK ; // Give priority i time to connect.
173
179
}
174
180
if (priority .equals (currentPriority ) && child .connectivityState != TRANSIENT_FAILURE ) {
175
181
// If the current priority is not changed into TRANSIENT_FAILURE, keep using it.
176
182
updateOverallState (priority , child .connectivityState , child .picker );
177
- return ;
183
+ return Status . OK ;
178
184
}
179
185
}
180
186
// TODO(zdapeng): Include error details of each priority.
181
187
logger .log (XdsLogLevel .DEBUG , "All priority failed" );
182
188
String lastPriority = priorityNames .get (priorityNames .size () - 1 );
183
189
SubchannelPicker errorPicker = children .get (lastPriority ).picker ;
184
190
updateOverallState (lastPriority , TRANSIENT_FAILURE , errorPicker );
191
+ return Status .OK ;
185
192
}
186
193
187
194
private void updateOverallState (
@@ -228,7 +235,11 @@ public void run() {
228
235
Status .UNAVAILABLE .withDescription ("Connection timeout for priority " + priority )));
229
236
logger .log (XdsLogLevel .DEBUG , "Priority {0} failed over to next" , priority );
230
237
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
+ }
232
243
}
233
244
}
234
245
@@ -279,10 +290,10 @@ void tearDown() {
279
290
* resolvedAddresses}, or when priority lb receives a new resolved addresses while the child
280
291
* already exists.
281
292
*/
282
- void updateResolvedAddresses () {
293
+ Status updateResolvedAddresses () {
283
294
PriorityLbConfig config =
284
295
(PriorityLbConfig ) resolvedAddresses .getLoadBalancingPolicyConfig ();
285
- lb .handleResolvedAddresses (
296
+ return lb .acceptResolvedAddresses (
286
297
resolvedAddresses .toBuilder ()
287
298
.setAddresses (AddressFilter .filter (resolvedAddresses .getAddresses (), priority ))
288
299
.setLoadBalancingPolicyConfig (config .childConfigs .get (priority ).childConfig )
@@ -331,7 +342,11 @@ public void updateBalancingState(final ConnectivityState newState,
331
342
// If we are currently handling newly resolved addresses, let's not try to reconfigure as
332
343
// the address handling process will take care of that to provide an atomic config update.
333
344
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
+ }
335
350
}
336
351
}
337
352
0 commit comments