Skip to content

Commit

Permalink
Response to code review
Browse files Browse the repository at this point in the history
  • Loading branch information
larry-safran committed Aug 2, 2023
1 parent 9cbf03f commit 13d783b
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 109 deletions.
35 changes: 35 additions & 0 deletions api/src/main/java/io/grpc/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ public abstract class LoadBalancer {
@NameResolver.ResolutionResultAttr
public static final Attributes.Key<Map<String, ?>> ATTR_HEALTH_CHECKING_CONFIG =
Attributes.Key.create("internal:health-checking-config");

public static final SubchannelPicker EMPTY_PICKER = new SubchannelPicker() {
@Override
public PickResult pickSubchannel(PickSubchannelArgs args) {
return PickResult.withNoResult();
}

@Override
public String toString() {
return "EMPTY_PICKER";
}
};

private int recursionCount;

/**
Expand Down Expand Up @@ -1398,4 +1411,26 @@ public abstract static class Factory {
*/
public abstract LoadBalancer newLoadBalancer(Helper helper);
}

public static final class ErrorPicker extends SubchannelPicker {

private final Status error;

public ErrorPicker(Status error) {
this.error = checkNotNull(error, "error");
}

@Override
public PickResult pickSubchannel(PickSubchannelArgs args) {
return PickResult.withError(error);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("error", error)
.toString();
}
}

}
15 changes: 11 additions & 4 deletions util/src/main/java/io/grpc/util/MultiChildLoadBalancer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 The gRPC Authors
* Copyright 2023 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,10 @@
import javax.annotation.Nullable;

/**
* The top-level load balancing policy.
* A base load balancing policy for those policies which has multiple children such as
* ClusterManager or the petiole policies.
*
* @since 1.58
*/
public abstract class MultiChildLoadBalancer extends LoadBalancer {

Expand All @@ -60,9 +63,13 @@ protected MultiChildLoadBalancer(Helper helper) {
logger.log(Level.FINE, "Created");
}

protected abstract SubchannelPicker getInitialPicker();
protected SubchannelPicker getInitialPicker() {
return EMPTY_PICKER;
}

protected abstract SubchannelPicker getErrorPicker(Status error);
protected SubchannelPicker getErrorPicker(Status error) {
return new ErrorPicker(error);
}

protected abstract Map<Object, PolicySelection> getPolicySelectionMap(
ResolvedAddresses resolvedAddresses);
Expand Down
1 change: 0 additions & 1 deletion xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import io.grpc.xds.XdsClusterResource.CdsUpdate;
import io.grpc.xds.XdsClusterResource.CdsUpdate.ClusterType;
import io.grpc.xds.XdsLogger.XdsLogLevel;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
Expand Down
4 changes: 1 addition & 3 deletions xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.grpc.xds;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.grpc.xds.XdsSubchannelPickers.BUFFER_PICKER;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
Expand Down Expand Up @@ -46,7 +45,6 @@
import io.grpc.xds.ThreadSafeRandom.ThreadSafeRandomImpl;
import io.grpc.xds.XdsLogger.XdsLogLevel;
import io.grpc.xds.XdsNameResolverProvider.CallCounterProvider;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import io.grpc.xds.internal.security.SslContextProviderSupplier;
import io.grpc.xds.orca.OrcaPerRequestUtil;
import io.grpc.xds.orca.OrcaPerRequestUtil.OrcaPerRequestReportListener;
Expand Down Expand Up @@ -173,7 +171,7 @@ public void shutdown() {
private final class ClusterImplLbHelper extends ForwardingLoadBalancerHelper {
private final AtomicLong inFlights;
private ConnectivityState currentState = ConnectivityState.IDLE;
private SubchannelPicker currentPicker = BUFFER_PICKER;
private SubchannelPicker currentPicker = LoadBalancer.EMPTY_PICKER;
private List<DropOverload> dropPolicies = Collections.emptyList();
private long maxConcurrentRequests = DEFAULT_PER_CLUSTER_MAX_CONCURRENT_REQUESTS;
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

package io.grpc.xds;

import static io.grpc.xds.XdsSubchannelPickers.BUFFER_PICKER;

import com.google.common.base.MoreObjects;
import io.grpc.InternalLogId;
import io.grpc.Status;
import io.grpc.internal.ServiceConfigUtil.PolicySelection;
import io.grpc.util.MultiChildLoadBalancer;
import io.grpc.xds.ClusterManagerLoadBalancerProvider.ClusterManagerConfig;
import io.grpc.xds.XdsLogger.XdsLogLevel;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -45,7 +42,7 @@ class ClusterManagerLoadBalancer extends MultiChildLoadBalancer {

@Override
protected SubchannelPicker getInitialPicker() {
return BUFFER_PICKER;
return EMPTY_PICKER;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import io.grpc.xds.XdsClient.ResourceWatcher;
import io.grpc.xds.XdsEndpointResource.EdsUpdate;
import io.grpc.xds.XdsLogger.XdsLogLevel;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
Expand Down
6 changes: 2 additions & 4 deletions xds/src/main/java/io/grpc/xds/PriorityLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static io.grpc.ConnectivityState.IDLE;
import static io.grpc.ConnectivityState.READY;
import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
import static io.grpc.xds.XdsSubchannelPickers.BUFFER_PICKER;

import io.grpc.ConnectivityState;
import io.grpc.InternalLogId;
Expand All @@ -36,7 +35,6 @@
import io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig;
import io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig;
import io.grpc.xds.XdsLogger.XdsLogLevel;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -149,7 +147,7 @@ private void tryNextPriority() {
ChildLbState child =
new ChildLbState(priority, priorityConfigs.get(priority).ignoreReresolution);
children.put(priority, child);
updateOverallState(priority, CONNECTING, BUFFER_PICKER);
updateOverallState(priority, CONNECTING, LoadBalancer.EMPTY_PICKER);
// Calling the child's updateResolvedAddresses() can result in tryNextPriority() being
// called recursively. We need to be sure to be done with processing here before it is
// called.
Expand Down Expand Up @@ -210,7 +208,7 @@ private final class ChildLbState {
@Nullable ScheduledHandle deletionTimer;
@Nullable String policy;
ConnectivityState connectivityState = CONNECTING;
SubchannelPicker picker = BUFFER_PICKER;
SubchannelPicker picker = LoadBalancer.EMPTY_PICKER;

ChildLbState(final String priority, boolean ignoreReresolution) {
this.priority = priority;
Expand Down
1 change: 0 additions & 1 deletion xds/src/main/java/io/grpc/xds/RingHashLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import io.grpc.Status;
import io.grpc.SynchronizationContext;
import io.grpc.xds.XdsLogger.XdsLogLevel;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.Collections;
Expand Down
6 changes: 2 additions & 4 deletions xds/src/main/java/io/grpc/xds/WeightedTargetLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static io.grpc.ConnectivityState.IDLE;
import static io.grpc.ConnectivityState.READY;
import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
import static io.grpc.xds.XdsSubchannelPickers.BUFFER_PICKER;

import com.google.common.collect.ImmutableMap;
import io.grpc.ConnectivityState;
Expand All @@ -34,7 +33,6 @@
import io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedPolicySelection;
import io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedTargetConfig;
import io.grpc.xds.XdsLogger.XdsLogLevel;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -159,7 +157,7 @@ private void updateOverallBalancingState() {
if (overallState == TRANSIENT_FAILURE) {
picker = new WeightedRandomPicker(errorPickers);
} else {
picker = XdsSubchannelPickers.BUFFER_PICKER;
picker = LoadBalancer.EMPTY_PICKER;
}
} else {
picker = new WeightedRandomPicker(childPickers);
Expand Down Expand Up @@ -191,7 +189,7 @@ private static ConnectivityState aggregateState(
private final class ChildHelper extends ForwardingLoadBalancerHelper {
String name;
ConnectivityState currentState = CONNECTING;
SubchannelPicker currentPicker = BUFFER_PICKER;
SubchannelPicker currentPicker = LoadBalancer.EMPTY_PICKER;

private ChildHelper(String name) {
this.name = name;
Expand Down
1 change: 0 additions & 1 deletion xds/src/main/java/io/grpc/xds/WrrLocalityLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedPolicySelection;
import io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedTargetConfig;
import io.grpc.xds.XdsLogger.XdsLogLevel;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
Expand Down
63 changes: 0 additions & 63 deletions xds/src/main/java/io/grpc/xds/XdsSubchannelPickers.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import io.grpc.internal.ServiceConfigUtil.PolicySelection;
import io.grpc.testing.TestMethodDescriptors;
import io.grpc.xds.ClusterManagerLoadBalancerProvider.ClusterManagerConfig;
import io.grpc.xds.XdsSubchannelPickers.ErrorPicker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down
Loading

0 comments on commit 13d783b

Please sign in to comment.