mirror of https://github.com/grpc/grpc-java.git
xds: fix bug for name resolution error propagation in prioirty_lb
This commit is contained in:
parent
5cfbe1061a
commit
eb6c3415d2
|
|
@ -101,11 +101,15 @@ final class PriorityLoadBalancer extends LoadBalancer {
|
|||
@Override
|
||||
public void handleNameResolutionError(Status error) {
|
||||
logger.log(XdsLogLevel.WARNING, "Received name resolution error: {0}", error);
|
||||
if (children.isEmpty()) {
|
||||
updateOverallState(TRANSIENT_FAILURE, new ErrorPicker(error));
|
||||
}
|
||||
boolean gotoTransientFailure = true;
|
||||
for (ChildLbState child : children.values()) {
|
||||
child.lb.handleNameResolutionError(error);
|
||||
if (priorityNames.contains(child.priority)) {
|
||||
child.lb.handleNameResolutionError(error);
|
||||
gotoTransientFailure = false;
|
||||
}
|
||||
}
|
||||
if (gotoTransientFailure) {
|
||||
updateOverallState(TRANSIENT_FAILURE, new ErrorPicker(error));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -214,6 +214,43 @@ public class PriorityLoadBalancerTest {
|
|||
verify(barBalancer0, never()).shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleNameResolutionError() {
|
||||
Object fooConfig0 = new Object();
|
||||
PolicySelection fooPolicy0 = new PolicySelection(fooLbProvider, null, fooConfig0);
|
||||
Object fooConfig1 = new Object();
|
||||
PolicySelection fooPolicy1 = new PolicySelection(fooLbProvider, null, fooConfig1);
|
||||
|
||||
PriorityLbConfig priorityLbConfig =
|
||||
new PriorityLbConfig(ImmutableMap.of("p0", fooPolicy0), ImmutableList.of("p0"));
|
||||
priorityLb.handleResolvedAddresses(
|
||||
ResolvedAddresses.newBuilder()
|
||||
.setAddresses(ImmutableList.<EquivalentAddressGroup>of())
|
||||
.setLoadBalancingPolicyConfig(priorityLbConfig)
|
||||
.build());
|
||||
LoadBalancer fooLb0 = Iterables.getOnlyElement(fooBalancers);
|
||||
Status status = Status.DATA_LOSS.withDescription("fake error");
|
||||
priorityLb.handleNameResolutionError(status);
|
||||
verify(fooLb0).handleNameResolutionError(status);
|
||||
|
||||
priorityLbConfig =
|
||||
new PriorityLbConfig(ImmutableMap.of("p1", fooPolicy1), ImmutableList.of("p1"));
|
||||
priorityLb.handleResolvedAddresses(
|
||||
ResolvedAddresses.newBuilder()
|
||||
.setAddresses(ImmutableList.<EquivalentAddressGroup>of())
|
||||
.setLoadBalancingPolicyConfig(priorityLbConfig)
|
||||
.build());
|
||||
assertThat(fooBalancers).hasSize(2);
|
||||
LoadBalancer fooLb1 = Iterables.getLast(fooBalancers);
|
||||
status = Status.UNAVAILABLE.withDescription("fake error");
|
||||
priorityLb.handleNameResolutionError(status);
|
||||
// fooLb0 is deactivated but not yet deleted. However, because it is delisted by the latest
|
||||
// address update, name resolution error will not be propagated to it.
|
||||
verify(fooLb0, never()).shutdown();
|
||||
verify(fooLb0, never()).handleNameResolutionError(status);
|
||||
verify(fooLb1).handleNameResolutionError(status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typicalPriorityFailOverFlow() {
|
||||
PolicySelection policy0 = new PolicySelection(fooLbProvider, null, new Object());
|
||||
|
|
|
|||
Loading…
Reference in New Issue