Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpclb: skip fallback if the LB is already in fallback mode #8253

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java
Expand Up @@ -259,11 +259,19 @@ void handleAddresses(
serviceName,
newLbAddressGroups,
newBackendServers);
fallbackBackendList = newBackendServers;
if (newLbAddressGroups.isEmpty()) {
// No balancer address: close existing balancer connection and enter fallback mode
// immediately.
// No balancer address: close existing balancer connection and prepare to enter fallback
// mode. If there is no successful backend connection, it enters fallback mode immediately.
// Otherwise, fallback does not happen until backend connections are lost. This behavior
// might be different from other languages (e.g., existing balancer connection is not
// closed in C-core), but we aren't changing it at this time.
shutdownLbComm();
syncContext.execute(new FallbackModeTask(NO_LB_ADDRESS_PROVIDED_STATUS));
if (!usingFallbackBackends) {
fallbackReason = NO_LB_ADDRESS_PROVIDED_STATUS;
cancelFallbackTimer();
maybeUseFallbackBackends();
}
} else {
startLbComm(newLbAddressGroups);
// Avoid creating a new RPC just because the addresses were updated, as it can cause a
Expand All @@ -281,7 +289,6 @@ void handleAddresses(
TimeUnit.MILLISECONDS, timerService);
}
}
fallbackBackendList = newBackendServers;
if (usingFallbackBackends) {
// Populate the new fallback backends to round-robin list.
useFallbackBackends();
Expand Down
29 changes: 27 additions & 2 deletions grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java
Expand Up @@ -1452,8 +1452,11 @@ public void grpclbFallback_breakLbStreamBeforeFallbackTimerExpires() {
public void grpclbFallback_noBalancerAddress() {
InOrder inOrder = inOrder(helper, subchannelPool);

// Create just backend addresses
List<EquivalentAddressGroup> backendList = createResolvedBackendAddresses(2);
// Create 5 distinct backends
List<EquivalentAddressGroup> backends = createResolvedBackendAddresses(5);

// Name resolver gives the first two backend addresses
List<EquivalentAddressGroup> backendList = backends.subList(0, 2);
deliverResolvedAddresses(backendList, Collections.<EquivalentAddressGroup>emptyList());

assertThat(logs).containsAtLeast(
Expand All @@ -1474,6 +1477,28 @@ public void grpclbFallback_noBalancerAddress() {
.createOobChannel(ArgumentMatchers.<EquivalentAddressGroup>anyList(), anyString());
logs.clear();

/////////////////////////////////////////////////////////////////////////////////////////
// Name resolver sends new resolution results with new backend addr but no balancer addr
/////////////////////////////////////////////////////////////////////////////////////////
// Name resolver then gives the last three backends
backendList = backends.subList(2, 5);
deliverResolvedAddresses(backendList, Collections.<EquivalentAddressGroup>emptyList());

assertThat(logs).containsAtLeast(
"INFO: [grpclb-<api.google.com>] Using fallback backends",
"INFO: [grpclb-<api.google.com>] "
+ "Using RR list=[[[FakeSocketAddress-fake-address-2]/{}], "
+ "[[FakeSocketAddress-fake-address-3]/{}], "
+ "[[FakeSocketAddress-fake-address-4]/{}]], drop=[null, null, null]",
"INFO: [grpclb-<api.google.com>] "
+ "Update balancing state to CONNECTING: picks=[BUFFER_ENTRY], "
+ "drops=[null, null, null]")
.inOrder();

// Shift to use updated backends
fallbackTestVerifyUseOfFallbackBackendLists(inOrder, backendList);
logs.clear();

///////////////////////////////////////////////////////////////////////////////////////
// Name resolver sends new resolution results without any backend addr or balancer addr
///////////////////////////////////////////////////////////////////////////////////////
Expand Down