Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
if (addresses.isEmpty()) {
Status status = Status.UNAVAILABLE
.withDescription("No usable endpoint from cluster: " + clusterName);
delegate.handleNameResolutionError(status);
return status;
return fail(status);
}
Object gracefulConfig = GracefulSwitchLoadBalancer.createLoadBalancingPolicyConfig(
lbRegistry.getProvider(PRIORITY_POLICY_NAME),
Expand Down Expand Up @@ -223,6 +222,7 @@ public void shutdown() {
@CheckReturnValue // don't forget to return up the stack after the fail call
private Status fail(Status error) {
delegate.shutdown();
delegate = new GracefulSwitchLoadBalancer(cdsLbHelper);
addBackendServicePickDetailsLabel = false;
helper.updateBalancingState(
TRANSIENT_FAILURE, new FixedResultPicker(PickResult.withError(error)));
Expand Down
53 changes: 53 additions & 0 deletions xds/src/test/java/io/grpc/xds/ClusterResolverLoadBalancerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -62,6 +63,7 @@
import io.grpc.HttpConnectProxiedSocketAddress;
import io.grpc.InternalEquivalentAddressGroup;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.FixedResultPicker;
import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancer.PickDetailsConsumer;
import io.grpc.LoadBalancer.PickResult;
Expand Down Expand Up @@ -887,6 +889,57 @@ public void handleEdsResource_noHealthyEndpoint() {
assertPicker(pickerCaptor.getValue(), expectedStatus, null);
}

@Test
public void handleEdsResource_allEndpointsRemovedAfterReady_failsAndRecovers() {
ClusterLoadAssignment clusterLoadAssignment = ClusterLoadAssignment.newBuilder()
.setClusterName(EDS_SERVICE_NAME)
.addEndpoints(LocalityLbEndpoints.newBuilder()
.setLoadBalancingWeight(UInt32Value.of(100))
.setLocality(LOCALITY1)
.addLbEndpoints(newSocketLbEndpoint("127.0.0.1", 8000)))
.build();
controlPlaneService.setXdsConfig(ADS_TYPE_URL_EDS, ImmutableMap.of(
EDS_SERVICE_NAME, clusterLoadAssignment));
startXdsDepManager();

FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
childBalancer.helper.updateBalancingState(
ConnectivityState.READY, new FixedResultPicker(PickResult.withNoResult()));
verify(helper).updateBalancingState(eq(ConnectivityState.READY), any());

// An empty ClusterLoadAssignment must not leave the previous READY picker in place
controlPlaneService.setXdsConfig(ADS_TYPE_URL_EDS, ImmutableMap.of(
EDS_SERVICE_NAME,
ClusterLoadAssignment.newBuilder().setClusterName(EDS_SERVICE_NAME).build()));

assertThat(childBalancer.shutdown).isTrue();
assertThat(childBalancers).isEmpty();
verify(helper).updateBalancingState(
eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
Status expectedStatus = Status.UNAVAILABLE
.withDescription("No usable endpoint from cluster: " + CLUSTER);
assertPicker(pickerCaptor.getValue(), expectedStatus, null);

// Endpoints come back: a new child policy is created
controlPlaneService.setXdsConfig(ADS_TYPE_URL_EDS, ImmutableMap.of(
EDS_SERVICE_NAME, clusterLoadAssignment.toBuilder()
.setEndpoints(0, clusterLoadAssignment.getEndpoints(0).toBuilder()
.setLbEndpoints(0, newSocketLbEndpoint("127.0.0.2", 8000)))
.build()));

FakeLoadBalancer newChildBalancer = Iterables.getOnlyElement(childBalancers);
assertThat(newChildBalancer).isNotSameInstanceAs(childBalancer);
assertThat(newChildBalancer.shutdown).isFalse();
assertAddressesEqual(
Arrays.asList(new EquivalentAddressGroup(newInetSocketAddress("127.0.0.2", 8000))),
newChildBalancer.addresses);

// The new child's READY state reaches the channel, replacing the error picker
newChildBalancer.helper.updateBalancingState(
ConnectivityState.READY, new FixedResultPicker(PickResult.withNoResult()));
verify(helper, times(2)).updateBalancingState(eq(ConnectivityState.READY), any());
}

@Test
public void onlyLogicalDnsCluster_endpointsResolved() {
boolean originalVal = LoadStatsManager2.isEnabledOrcaLrsPropagation;
Expand Down
Loading