mirror of https://github.com/grpc/grpc-java.git
xds: Don't cache rdsName in XdsDepManager
We can easily compute the rdsName and avoiding the state means we don't need to override onResourceDoesNotExist() to keep the cache in-sync with the config.
This commit is contained in:
parent
4ee662fbcf
commit
6afacf589e
|
@ -567,7 +567,6 @@ final class XdsDependencyManager implements XdsConfig.XdsClusterSubscriptionRegi
|
||||||
|
|
||||||
private class LdsWatcher extends XdsWatcherBase<XdsListenerResource.LdsUpdate>
|
private class LdsWatcher extends XdsWatcherBase<XdsListenerResource.LdsUpdate>
|
||||||
implements RdsUpdateSupplier {
|
implements RdsUpdateSupplier {
|
||||||
String rdsName;
|
|
||||||
|
|
||||||
private LdsWatcher(String resourceName) {
|
private LdsWatcher(String resourceName) {
|
||||||
super(XdsListenerResource.getInstance(), resourceName);
|
super(XdsListenerResource.getInstance(), resourceName);
|
||||||
|
@ -582,22 +581,18 @@ final class XdsDependencyManager implements XdsConfig.XdsClusterSubscriptionRegi
|
||||||
|
|
||||||
HttpConnectionManager httpConnectionManager = update.httpConnectionManager();
|
HttpConnectionManager httpConnectionManager = update.httpConnectionManager();
|
||||||
List<VirtualHost> virtualHosts;
|
List<VirtualHost> virtualHosts;
|
||||||
String rdsName;
|
|
||||||
if (httpConnectionManager == null) {
|
if (httpConnectionManager == null) {
|
||||||
// TCP listener. Unsupported config
|
// TCP listener. Unsupported config
|
||||||
virtualHosts = Collections.emptyList(); // Not null, to not delegate to RDS
|
virtualHosts = Collections.emptyList(); // Not null, to not delegate to RDS
|
||||||
rdsName = null;
|
|
||||||
} else {
|
} else {
|
||||||
virtualHosts = httpConnectionManager.virtualHosts();
|
virtualHosts = httpConnectionManager.virtualHosts();
|
||||||
rdsName = httpConnectionManager.rdsName();
|
}
|
||||||
|
if (virtualHosts != null) {
|
||||||
|
updateRoutes(virtualHosts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virtualHosts != null) {
|
String rdsName = getRdsName(update);
|
||||||
// No RDS watcher since we are getting RDS updates via LDS
|
if (rdsName != null) {
|
||||||
updateRoutes(virtualHosts);
|
|
||||||
this.rdsName = null;
|
|
||||||
} else {
|
|
||||||
this.rdsName = rdsName;
|
|
||||||
addRdsWatcher(rdsName);
|
addRdsWatcher(rdsName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,20 +600,17 @@ final class XdsDependencyManager implements XdsConfig.XdsClusterSubscriptionRegi
|
||||||
maybePublishConfig();
|
maybePublishConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private String getRdsName(XdsListenerResource.LdsUpdate update) {
|
||||||
public void onResourceDoesNotExist(String resourceName) {
|
HttpConnectionManager httpConnectionManager = update.httpConnectionManager();
|
||||||
if (cancelled) {
|
if (httpConnectionManager == null) {
|
||||||
return;
|
// TCP listener. Unsupported config
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
return httpConnectionManager.rdsName();
|
||||||
checkArgument(resourceName().equals(resourceName), "Resource name does not match");
|
|
||||||
setDataAsStatus(Status.UNAVAILABLE.withDescription(
|
|
||||||
toContextString() + " does not exist" + nodeInfo()));
|
|
||||||
rdsName = null;
|
|
||||||
maybePublishConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private RdsWatcher getRdsWatcher(WatcherTracer tracer) {
|
private RdsWatcher getRdsWatcher(XdsListenerResource.LdsUpdate update, WatcherTracer tracer) {
|
||||||
|
String rdsName = getRdsName(update);
|
||||||
if (rdsName == null) {
|
if (rdsName == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -637,7 +629,7 @@ final class XdsDependencyManager implements XdsConfig.XdsClusterSubscriptionRegi
|
||||||
if (virtualHosts != null) {
|
if (virtualHosts != null) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
RdsWatcher rdsWatcher = getRdsWatcher(tracer);
|
RdsWatcher rdsWatcher = getRdsWatcher(getData().getValue(), tracer);
|
||||||
assert rdsWatcher != null;
|
assert rdsWatcher != null;
|
||||||
return rdsWatcher;
|
return rdsWatcher;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue