Skip to content

Commit 71ed97a

Browse files
committed
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.
1 parent 1fd29bc commit 71ed97a

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ private interface RdsUpdateSupplier {
566566

567567
private class LdsWatcher extends XdsWatcherBase<XdsListenerResource.LdsUpdate>
568568
implements RdsUpdateSupplier {
569-
String rdsName;
570569

571570
private LdsWatcher(String resourceName) {
572571
super(XdsListenerResource.getInstance(), resourceName);
@@ -581,43 +580,36 @@ public void onChanged(XdsListenerResource.LdsUpdate update) {
581580

582581
HttpConnectionManager httpConnectionManager = update.httpConnectionManager();
583582
List<VirtualHost> virtualHosts;
584-
String rdsName;
585583
if (httpConnectionManager == null) {
586584
// TCP listener. Unsupported config
587585
virtualHosts = Collections.emptyList(); // Not null, to not delegate to RDS
588-
rdsName = null;
589586
} else {
590587
virtualHosts = httpConnectionManager.virtualHosts();
591-
rdsName = httpConnectionManager.rdsName();
592588
}
593-
594589
if (virtualHosts != null) {
595-
// No RDS watcher since we are getting RDS updates via LDS
596590
updateRoutes(virtualHosts);
597-
this.rdsName = null;
598-
} else {
599-
this.rdsName = rdsName;
591+
}
592+
593+
String rdsName = getRdsName(update);
594+
if (rdsName != null) {
600595
addRdsWatcher(rdsName);
601596
}
602597

603598
setData(update);
604599
maybePublishConfig();
605600
}
606601

607-
@Override
608-
public void onResourceDoesNotExist(String resourceName) {
609-
if (cancelled) {
610-
return;
602+
private String getRdsName(XdsListenerResource.LdsUpdate update) {
603+
HttpConnectionManager httpConnectionManager = update.httpConnectionManager();
604+
if (httpConnectionManager == null) {
605+
// TCP listener. Unsupported config
606+
return null;
611607
}
612-
613-
checkArgument(resourceName().equals(resourceName), "Resource name does not match");
614-
setDataAsStatus(Status.UNAVAILABLE.withDescription(
615-
toContextString() + " does not exist" + nodeInfo()));
616-
rdsName = null;
617-
maybePublishConfig();
608+
return httpConnectionManager.rdsName();
618609
}
619610

620-
private RdsWatcher getRdsWatcher(WatcherTracer tracer) {
611+
private RdsWatcher getRdsWatcher(XdsListenerResource.LdsUpdate update, WatcherTracer tracer) {
612+
String rdsName = getRdsName(update);
621613
if (rdsName == null) {
622614
return null;
623615
}
@@ -636,7 +628,7 @@ public RdsUpdateSupplier getRouteSource(WatcherTracer tracer) {
636628
if (virtualHosts != null) {
637629
return this;
638630
}
639-
RdsWatcher rdsWatcher = getRdsWatcher(tracer);
631+
RdsWatcher rdsWatcher = getRdsWatcher(getData().getValue(), tracer);
640632
assert rdsWatcher != null;
641633
return rdsWatcher;
642634
}

0 commit comments

Comments
 (0)