Skip to content

Commit 393f02b

Browse files
committed
Revert "xds: Convert CdsLb to XdsDepManager"
This reverts commit 297ab05. b/430347751 shows multiple concerning behaviors in the xDS stack with the new A74 config update model. XdsDepManager and CdsLB2 still seem to be working correctly, but the change is exacerbated issues in other parts of the stack, like RingHashConfig not having equals fixed in a8de9f0. Revert only for the v1.74.x release, leaving it on master.
1 parent 69b8cf5 commit 393f02b

12 files changed

+1036
-731
lines changed

xds/src/main/java/io/grpc/xds/CdsLoadBalancer2.java

Lines changed: 334 additions & 129 deletions
Large diffs are not rendered by default.

xds/src/main/java/io/grpc/xds/CdsLoadBalancerProvider.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
@Internal
3737
public class CdsLoadBalancerProvider extends LoadBalancerProvider {
3838

39+
private static final String CLUSTER_KEY = "cluster";
40+
3941
@Override
4042
public boolean isAvailable() {
4143
return true;
@@ -68,12 +70,9 @@ public ConfigOrError parseLoadBalancingPolicyConfig(
6870
*/
6971
static ConfigOrError parseLoadBalancingConfigPolicy(Map<String, ?> rawLoadBalancingPolicyConfig) {
7072
try {
71-
String cluster = JsonUtil.getString(rawLoadBalancingPolicyConfig, "cluster");
72-
Boolean isDynamic = JsonUtil.getBoolean(rawLoadBalancingPolicyConfig, "is_dynamic");
73-
if (isDynamic == null) {
74-
isDynamic = Boolean.FALSE;
75-
}
76-
return ConfigOrError.fromConfig(new CdsConfig(cluster, isDynamic));
73+
String cluster =
74+
JsonUtil.getString(rawLoadBalancingPolicyConfig, CLUSTER_KEY);
75+
return ConfigOrError.fromConfig(new CdsConfig(cluster));
7776
} catch (RuntimeException e) {
7877
return ConfigOrError.fromError(
7978
Status.UNAVAILABLE.withCause(e).withDescription(
@@ -90,28 +89,15 @@ static final class CdsConfig {
9089
* Name of cluster to query CDS for.
9190
*/
9291
final String name;
93-
/**
94-
* Whether this cluster was dynamically chosen, so the XdsDependencyManager may be unaware of
95-
* it without an explicit cluster subscription.
96-
*/
97-
final boolean isDynamic;
9892

9993
CdsConfig(String name) {
100-
this(name, false);
101-
}
102-
103-
CdsConfig(String name, boolean isDynamic) {
10494
checkArgument(name != null && !name.isEmpty(), "name is null or empty");
10595
this.name = name;
106-
this.isDynamic = isDynamic;
10796
}
10897

10998
@Override
11099
public String toString() {
111-
return MoreObjects.toStringHelper(this)
112-
.add("name", name)
113-
.add("isDynamic", isDynamic)
114-
.toString();
100+
return MoreObjects.toStringHelper(this).add("name", name).toString();
115101
}
116102
}
117103
}

xds/src/main/java/io/grpc/xds/RingHashLoadBalancerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private ConfigOrError parseLoadBalancingPolicyConfigInternal(
104104
}
105105
if (minRingSize <= 0 || maxRingSize <= 0 || minRingSize > maxRingSize) {
106106
return ConfigOrError.fromError(Status.UNAVAILABLE.withDescription(
107-
"Invalid 'minRingSize'/'maxRingSize'"));
107+
"Invalid 'mingRingSize'/'maxRingSize'"));
108108
}
109109
return ConfigOrError.fromConfig(
110110
new RingHashConfig(minRingSize, maxRingSize, requestHashHeader));

xds/src/main/java/io/grpc/xds/XdsClusterResource.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ static CdsUpdate processCluster(Cluster cluster,
172172
lbConfig.getPolicyName()).parseLoadBalancingPolicyConfig(
173173
lbConfig.getRawConfigValue());
174174
if (configOrError.getError() != null) {
175-
throw new ResourceInvalidException(
176-
"Failed to parse lb config for cluster '" + cluster.getName() + "': "
177-
+ configOrError.getError());
175+
throw new ResourceInvalidException(structOrError.getErrorDetail());
178176
}
179177

180178
updateBuilder.lbPolicyConfig(lbPolicyConfig);
@@ -211,10 +209,6 @@ private static StructOrError<CdsUpdate.Builder> parseAggregateCluster(Cluster cl
211209
} catch (InvalidProtocolBufferException e) {
212210
return StructOrError.fromError("Cluster " + clusterName + ": malformed ClusterConfig: " + e);
213211
}
214-
if (clusterConfig.getClustersList().isEmpty()) {
215-
return StructOrError.fromError("Cluster " + clusterName
216-
+ ": aggregate ClusterConfig.clusters must not be empty");
217-
}
218212
return StructOrError.fromStruct(CdsUpdate.forAggregate(
219213
clusterName, clusterConfig.getClustersList()));
220214
}

xds/src/main/java/io/grpc/xds/XdsConfig.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,6 @@ XdsConfig build() {
254254
}
255255

256256
public interface XdsClusterSubscriptionRegistry {
257-
Subscription subscribeToCluster(String clusterName);
258-
}
259-
260-
public interface Subscription extends Closeable {
261-
/** Release resources without throwing exceptions. */
262-
@Override
263-
void close();
257+
Closeable subscribeToCluster(String clusterName);
264258
}
265259
}

xds/src/main/java/io/grpc/xds/XdsDependencyManager.java

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
2020
import static com.google.common.base.Preconditions.checkNotNull;
21-
import static com.google.common.base.Preconditions.checkState;
2221
import static io.grpc.xds.client.XdsClient.ResourceUpdate;
2322

2423
import com.google.common.annotations.VisibleForTesting;
@@ -35,6 +34,8 @@
3534
import io.grpc.xds.client.XdsClient;
3635
import io.grpc.xds.client.XdsClient.ResourceWatcher;
3736
import io.grpc.xds.client.XdsResourceType;
37+
import java.io.Closeable;
38+
import java.io.IOException;
3839
import java.util.Collections;
3940
import java.util.HashMap;
4041
import java.util.HashSet;
@@ -55,43 +56,39 @@
5556
final class XdsDependencyManager implements XdsConfig.XdsClusterSubscriptionRegistry {
5657
public static final XdsClusterResource CLUSTER_RESOURCE = XdsClusterResource.getInstance();
5758
public static final XdsEndpointResource ENDPOINT_RESOURCE = XdsEndpointResource.getInstance();
58-
private static final int MAX_CLUSTER_RECURSION_DEPTH = 16; // Specified by gRFC A37
59+
private static final int MAX_CLUSTER_RECURSION_DEPTH = 16; // Matches C++
5960
private final String listenerName;
6061
private final XdsClient xdsClient;
62+
private final XdsConfigWatcher xdsConfigWatcher;
6163
private final SynchronizationContext syncContext;
6264
private final String dataPlaneAuthority;
63-
private XdsConfigWatcher xdsConfigWatcher;
6465

6566
private StatusOr<XdsConfig> lastUpdate = null;
6667
private final Map<XdsResourceType<?>, TypeWatchers<?>> resourceWatchers = new HashMap<>();
6768
private final Set<ClusterSubscription> subscriptions = new HashSet<>();
6869

69-
XdsDependencyManager(XdsClient xdsClient,
70+
XdsDependencyManager(XdsClient xdsClient, XdsConfigWatcher xdsConfigWatcher,
7071
SynchronizationContext syncContext, String dataPlaneAuthority,
7172
String listenerName, NameResolver.Args nameResolverArgs,
7273
ScheduledExecutorService scheduler) {
7374
this.listenerName = checkNotNull(listenerName, "listenerName");
7475
this.xdsClient = checkNotNull(xdsClient, "xdsClient");
76+
this.xdsConfigWatcher = checkNotNull(xdsConfigWatcher, "xdsConfigWatcher");
7577
this.syncContext = checkNotNull(syncContext, "syncContext");
7678
this.dataPlaneAuthority = checkNotNull(dataPlaneAuthority, "dataPlaneAuthority");
7779
checkNotNull(nameResolverArgs, "nameResolverArgs");
7880
checkNotNull(scheduler, "scheduler");
81+
82+
// start the ball rolling
83+
syncContext.execute(() -> addWatcher(new LdsWatcher(listenerName)));
7984
}
8085

8186
public static String toContextStr(String typeName, String resourceName) {
8287
return typeName + " resource " + resourceName;
8388
}
8489

85-
public void start(XdsConfigWatcher xdsConfigWatcher) {
86-
checkState(this.xdsConfigWatcher == null, "dep manager may not be restarted");
87-
this.xdsConfigWatcher = checkNotNull(xdsConfigWatcher, "xdsConfigWatcher");
88-
// start the ball rolling
89-
syncContext.execute(() -> addWatcher(new LdsWatcher(listenerName)));
90-
}
91-
9290
@Override
93-
public XdsConfig.Subscription subscribeToCluster(String clusterName) {
94-
checkState(this.xdsConfigWatcher != null, "dep manager must first be started");
91+
public Closeable subscribeToCluster(String clusterName) {
9592
checkNotNull(clusterName, "clusterName");
9693
ClusterSubscription subscription = new ClusterSubscription(clusterName);
9794

@@ -294,17 +291,10 @@ private static void addConfigForCluster(
294291
addConfigForCluster(clusters, childCluster, ancestors, tracer);
295292
StatusOr<XdsConfig.XdsClusterConfig> config = clusters.get(childCluster);
296293
if (!config.hasValue()) {
297-
// gRFC A37 says: If any of a CDS policy's watchers reports that the resource does not
298-
// exist the policy should report that it is in TRANSIENT_FAILURE. If any of the
299-
// watchers reports a transient ADS stream error, the policy should report that it is in
300-
// TRANSIENT_FAILURE if it has never passed a config to its child.
301-
//
302-
// But there's currently disagreement about whether that is actually what we want, and
303-
// that was not originally implemented in gRPC Java. So we're keeping Java's old
304-
// behavior for now and only failing the "leaves" (which is a bit arbitrary for a
305-
// cycle).
306-
leafNames.add(childCluster);
307-
continue;
294+
clusters.put(clusterName, StatusOr.fromStatus(Status.INTERNAL.withDescription(
295+
"Unable to get leaves for " + clusterName + ": "
296+
+ config.getStatus().getDescription())));
297+
return;
308298
}
309299
XdsConfig.XdsClusterConfig.ClusterChild children = config.getValue().getChildren();
310300
if (children instanceof AggregateConfig) {
@@ -336,11 +326,6 @@ private static void addConfigForCluster(
336326
child = new EndpointConfig(StatusOr.fromStatus(Status.UNAVAILABLE.withDescription(
337327
"Unknown type in cluster " + clusterName + " " + cdsUpdate.clusterType())));
338328
}
339-
if (clusters.containsKey(clusterName)) {
340-
// If a cycle is detected, we'll have detected it while recursing, so now there will be a key
341-
// present. We don't want to overwrite it with a non-error value.
342-
return;
343-
}
344329
clusters.put(clusterName, StatusOr.fromValue(
345330
new XdsConfig.XdsClusterConfig(clusterName, cdsUpdate, child)));
346331
}
@@ -422,7 +407,7 @@ public interface XdsConfigWatcher {
422407
void onUpdate(StatusOr<XdsConfig> config);
423408
}
424409

425-
private final class ClusterSubscription implements XdsConfig.Subscription {
410+
private final class ClusterSubscription implements Closeable {
426411
private final String clusterName;
427412
boolean closed; // Accessed from syncContext
428413

@@ -435,7 +420,7 @@ String getClusterName() {
435420
}
436421

437422
@Override
438-
public void close() {
423+
public void close() throws IOException {
439424
releaseSubscription(this);
440425
}
441426
}

xds/src/main/java/io/grpc/xds/XdsNameResolver.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ public void start(Listener2 listener) {
230230
ldsResourceName = XdsClient.canonifyResourceName(ldsResourceName);
231231
callCounterProvider = SharedCallCounterMap.getInstance();
232232

233-
resolveState = new ResolveState(ldsResourceName);
234-
resolveState.start();
233+
resolveState = new ResolveState(ldsResourceName); // auto starts
235234
}
236235

237236
private static String expandPercentS(String template, String replacement) {
@@ -654,14 +653,10 @@ class ResolveState implements XdsDependencyManager.XdsConfigWatcher {
654653
private ResolveState(String ldsResourceName) {
655654
authority = overrideAuthority != null ? overrideAuthority : encodedServiceAuthority;
656655
xdsDependencyManager =
657-
new XdsDependencyManager(xdsClient, syncContext, authority, ldsResourceName,
656+
new XdsDependencyManager(xdsClient, this, syncContext, authority, ldsResourceName,
658657
nameResolverArgs, scheduler);
659658
}
660659

661-
void start() {
662-
xdsDependencyManager.start(this);
663-
}
664-
665660
private void shutdown() {
666661
if (stopped) {
667662
return;

0 commit comments

Comments
 (0)