mirror of https://github.com/grpc/grpc-java.git
xds: Remove EDS maybePublishConfig() avoidance in XdsDepManager (#12121)
The optimization makes the code more complicated. Yes, we know that maybePublishConfig() will do no work because of an outstanding watch, but we don't do this for other new watchers created and doing so would just make the code more bug-prone. This removes a difference in how different watcher types are handled.
This commit is contained in:
parent
6bad600592
commit
48d08e643e
|
@ -456,17 +456,15 @@ final class XdsDependencyManager implements XdsConfig.XdsClusterSubscriptionRegi
|
||||||
return logId.toString();
|
return logId.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the watcher was added, false if it already exists
|
private void addEdsWatcher(String edsServiceName, CdsWatcher parentContext) {
|
||||||
private boolean addEdsWatcher(String edsServiceName, CdsWatcher parentContext) {
|
|
||||||
EdsWatcher watcher
|
EdsWatcher watcher
|
||||||
= (EdsWatcher) getWatchers(XdsEndpointResource.getInstance()).get(edsServiceName);
|
= (EdsWatcher) getWatchers(XdsEndpointResource.getInstance()).get(edsServiceName);
|
||||||
if (watcher != null) {
|
if (watcher != null) {
|
||||||
watcher.addParentContext(parentContext); // Is a set, so don't need to check for existence
|
watcher.addParentContext(parentContext); // Is a set, so don't need to check for existence
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addWatcher(new EdsWatcher(edsServiceName, parentContext));
|
addWatcher(new EdsWatcher(edsServiceName, parentContext));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addClusterWatcher(String clusterName, Object parentContext, int depth) {
|
private void addClusterWatcher(String clusterName, Object parentContext, int depth) {
|
||||||
|
@ -823,13 +821,10 @@ final class XdsDependencyManager implements XdsConfig.XdsClusterSubscriptionRegi
|
||||||
switch (update.clusterType()) {
|
switch (update.clusterType()) {
|
||||||
case EDS:
|
case EDS:
|
||||||
setData(update);
|
setData(update);
|
||||||
if (!addEdsWatcher(getEdsServiceName(), this)) {
|
addEdsWatcher(getEdsServiceName(), this);
|
||||||
maybePublishConfig();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case LOGICAL_DNS:
|
case LOGICAL_DNS:
|
||||||
setData(update);
|
setData(update);
|
||||||
maybePublishConfig();
|
|
||||||
// no eds needed
|
// no eds needed
|
||||||
break;
|
break;
|
||||||
case AGGREGATE:
|
case AGGREGATE:
|
||||||
|
@ -856,27 +851,20 @@ final class XdsDependencyManager implements XdsConfig.XdsClusterSubscriptionRegi
|
||||||
setData(update);
|
setData(update);
|
||||||
Set<String> addedClusters = Sets.difference(newNames, oldNames);
|
Set<String> addedClusters = Sets.difference(newNames, oldNames);
|
||||||
addedClusters.forEach((cluster) -> addClusterWatcher(cluster, parentContext, depth));
|
addedClusters.forEach((cluster) -> addClusterWatcher(cluster, parentContext, depth));
|
||||||
|
|
||||||
if (addedClusters.isEmpty()) {
|
|
||||||
maybePublishConfig();
|
|
||||||
}
|
|
||||||
} else { // data was set to error status above
|
|
||||||
maybePublishConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (depth <= MAX_CLUSTER_RECURSION_DEPTH) {
|
} else if (depth <= MAX_CLUSTER_RECURSION_DEPTH) {
|
||||||
setData(update);
|
setData(update);
|
||||||
update.prioritizedClusterNames()
|
update.prioritizedClusterNames()
|
||||||
.forEach(name -> addClusterWatcher(name, parentContext, depth));
|
.forEach(name -> addClusterWatcher(name, parentContext, depth));
|
||||||
maybePublishConfig();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Status error = Status.UNAVAILABLE.withDescription(
|
Status error = Status.UNAVAILABLE.withDescription(
|
||||||
"aggregate cluster graph exceeds max depth at " + resourceName() + nodeInfo());
|
"aggregate cluster graph exceeds max depth at " + resourceName() + nodeInfo());
|
||||||
setDataAsStatus(error);
|
setDataAsStatus(error);
|
||||||
maybePublishConfig();
|
|
||||||
}
|
}
|
||||||
|
maybePublishConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEdsServiceName() {
|
public String getEdsServiceName() {
|
||||||
|
|
Loading…
Reference in New Issue