xds: always update priority LB connectivity state (#9527)

Removes the option of skipping the update of the priority LB state when
the failover timer is pending.

This consistency facilitates a future change weher we delay child LB
status updates if the priority LB is performing an update. The upcoming
priority LB policy gRFC also does not require this update to ever be
skipped.
This commit is contained in:
Terry Wilson 2022-09-08 08:49:07 -07:00 committed by GitHub
parent 6bafca93a7
commit 53a2d50695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 10 deletions

View File

@ -99,9 +99,7 @@ final class PriorityLoadBalancer extends LoadBalancer {
children.get(priority).updateResolvedAddresses();
}
}
// Not to report connecting in case a pending priority bumps up on top of the current READY
// priority.
tryNextPriority(false);
tryNextPriority();
}
@Override
@ -128,7 +126,7 @@ final class PriorityLoadBalancer extends LoadBalancer {
children.clear();
}
private void tryNextPriority(boolean reportConnecting) {
private void tryNextPriority() {
for (int i = 0; i < priorityNames.size(); i++) {
String priority = priorityNames.get(i);
if (!children.containsKey(priority)) {
@ -153,9 +151,7 @@ final class PriorityLoadBalancer extends LoadBalancer {
return;
}
if (child.failOverTimer != null && child.failOverTimer.isPending()) {
if (reportConnecting) {
updateOverallState(priority, CONNECTING, BUFFER_PICKER);
}
updateOverallState(priority, child.connectivityState, child.picker);
return; // Give priority i time to connect.
}
if (priority.equals(currentPriority) && child.connectivityState != TRANSIENT_FAILURE) {
@ -216,7 +212,7 @@ final class PriorityLoadBalancer extends LoadBalancer {
Status.UNAVAILABLE.withDescription("Connection timeout for priority " + priority));
logger.log(XdsLogLevel.DEBUG, "Priority {0} failed over to next", priority);
currentPriority = null; // reset currentPriority to guarantee failover happen
tryNextPriority(true);
tryNextPriority();
}
}
@ -324,7 +320,7 @@ final class PriorityLoadBalancer extends LoadBalancer {
seenReadyOrIdleSinceTransientFailure = false;
failOverTimer.cancel();
}
tryNextPriority(true);
tryNextPriority();
}
});
}

View File

@ -23,6 +23,7 @@ import static io.grpc.ConnectivityState.READY;
import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
import static io.grpc.xds.XdsSubchannelPickers.BUFFER_PICKER;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
@ -675,7 +676,7 @@ public class PriorityLoadBalancerTest {
.setAddresses(ImmutableList.<EquivalentAddressGroup>of())
.setLoadBalancingPolicyConfig(priorityLbConfig)
.build());
verify(helper).updateBalancingState(eq(CONNECTING), eq(BUFFER_PICKER));
verify(helper, times(2)).updateBalancingState(eq(CONNECTING), isA(SubchannelPicker.class));
// LB shutdown and subchannel state change can happen simultaneously. If shutdown runs first,
// any further balancing state update should be ignored.