@@ -82,16 +82,20 @@ public void uncaughtException(Thread t, Throwable e) {
82
82
}
83
83
});
84
84
85
- private final Map <ServerInfo , LoadStatsManager2 > loadStatsManagerMap =
86
- new HashMap <>();
87
- final Map < ServerInfo , LoadReportClient > serverLrsClientMap =
88
- new HashMap <>();
85
+ private final Map <ServerInfo , LoadStatsManager2 > loadStatsManagerMap = new HashMap <>();
86
+ final Map < ServerInfo , LoadReportClient > serverLrsClientMap = new HashMap <>();
87
+ /** Map of authority to its active control plane client (affected by xds fallback). */
88
+ private final Map < String , ControlPlaneClient > activeCpClients = new HashMap <>();
89
89
90
90
private final Map <ServerInfo , ControlPlaneClient > serverCpClientMap = new HashMap <>();
91
+
92
+ /** Maps resource type to the corresponding map of subscribers (keyed by subscriber name). */
91
93
private final Map <XdsResourceType <? extends ResourceUpdate >,
92
94
Map <String , ResourceSubscriber <? extends ResourceUpdate >>>
93
95
resourceSubscribers = new HashMap <>();
96
+ /** Maps typeUrl to the corresponding XdsResourceType. */
94
97
private final Map <String , XdsResourceType <?>> subscribedResourceTypeUrls = new HashMap <>();
98
+
95
99
private final XdsTransportFactory xdsTransportFactory ;
96
100
private final Bootstrapper .BootstrapInfo bootstrapInfo ;
97
101
private final ScheduledExecutorService timeService ;
@@ -103,10 +107,6 @@ public void uncaughtException(Thread t, Throwable e) {
103
107
private final XdsLogger logger ;
104
108
private volatile boolean isShutdown ;
105
109
private final MessagePrettyPrinter messagePrinter ;
106
- /**
107
- * Map of authority to its active control plane client.
108
- */
109
- private Map <String , ControlPlaneClient > activeCpClients = new HashMap <>();
110
110
111
111
public XdsClientImpl (
112
112
XdsTransportFactory xdsTransportFactory ,
@@ -172,7 +172,7 @@ public Collection<String> getSubscribedResources(
172
172
@ Override
173
173
public Collection <String > getSubscribedResources (
174
174
ServerInfo serverInfo , XdsResourceType <? extends ResourceUpdate > type , String authority ) {
175
- return getSubscribedResources (serverInfo , type , authority , false );
175
+ return getSubscribedResources (serverInfo , type , authority , true );
176
176
}
177
177
178
178
private Collection <String > getSubscribedResources (ServerInfo serverInfo , XdsResourceType <?
@@ -183,44 +183,21 @@ private Collection<String> getSubscribedResources(ServerInfo serverInfo, XdsReso
183
183
ControlPlaneClient controlPlaneClient = serverCpClientMap .get (serverInfo );
184
184
for (String key : resources .keySet ()) {
185
185
ResourceSubscriber <? extends ResourceUpdate > resource = resources .get (key );
186
- if (resource .controlPlaneClient .equals (controlPlaneClient ) &&
187
- (!useAuthority || Objects .equals (authority , resource .authority ))) {
186
+ if (resource .controlPlaneClient .equals (controlPlaneClient )
187
+ && (!useAuthority || Objects .equals (authority , resource .authority ))) {
188
188
builder .add (key );
189
189
}
190
190
}
191
191
Collection <String > retVal = builder .build ();
192
192
return retVal .isEmpty () ? null : retVal ;
193
193
}
194
194
195
- @ Override
196
- public Collection <String > getAllResources (XdsResourceType <?> type ) {
197
- if (!resourceSubscribers .containsKey (type )) {
198
- return null ;
199
- }
200
- return ImmutableList .copyOf (resourceSubscribers .get (type ).keySet ());
201
- }
202
-
203
- @ Override
204
- public Collection <String > getAllResources (XdsResourceType <?> type , String authority ) {
205
- if (!resourceSubscribers .containsKey (type )) {
206
- return null ;
207
- }
208
-
209
- List <String > matchingResources = new ArrayList <>();
210
- for (ResourceSubscriber <?> resource : resourceSubscribers .get (type ).values ()) {
211
- if (Objects .equals (authority , resource .authority )) {
212
- matchingResources .add (resource .resource );
213
- }
214
- }
215
- return matchingResources ;
216
- }
217
-
218
195
219
196
// As XdsClient APIs becomes resource agnostic, subscribed resource types are dynamic.
220
197
// ResourceTypes that do not have subscribers does not show up in the snapshot keys.
221
198
@ Override
222
199
public ListenableFuture <Map <XdsResourceType <?>, Map <String , ResourceMetadata >>>
223
- getSubscribedResourcesMetadataSnapshot () {
200
+ getSubscribedResourcesMetadataSnapshot () {
224
201
final SettableFuture <Map <XdsResourceType <?>, Map <String , ResourceMetadata >>> future =
225
202
SettableFuture .create ();
226
203
syncContext .execute (new Runnable () {
@@ -290,17 +267,22 @@ public void run() {
290
267
if (subscriber == null ) {
291
268
logger .log (XdsLogLevel .WARNING , "double cancel of resource watch for {0}:{1}" ,
292
269
type .typeName (), resourceName );
270
+ return ;
293
271
}
294
272
subscriber .removeWatcher (watcher );
295
273
if (!subscriber .isWatched ()) {
296
274
subscriber .cancelResourceWatch ();
297
275
resourceSubscribers .get (type ).remove (resourceName );
298
- if (subscriber .controlPlaneClient != null ) {
299
- subscriber .controlPlaneClient .adjustResourceSubscription (type , subscriber .authority );
276
+ ControlPlaneClient controlPlaneClient = subscriber .controlPlaneClient ;
277
+ if (controlPlaneClient != null ) {
278
+ controlPlaneClient .adjustResourceSubscription (type , subscriber .authority );
300
279
}
301
280
if (resourceSubscribers .get (type ).isEmpty ()) {
302
281
resourceSubscribers .remove (type );
303
282
subscribedResourceTypeUrls .remove (type .typeUrl ());
283
+ if (controlPlaneClient != null ) {
284
+ controlPlaneClient .removeNonceForType (type );
285
+ }
304
286
}
305
287
}
306
288
}
@@ -432,7 +414,6 @@ private ControlPlaneClient getOrCreateControlPlaneClient(ServerInfo serverInfo)
432
414
syncContext ,
433
415
backoffPolicyProvider ,
434
416
stopwatchSupplier ,
435
- this ,
436
417
messagePrinter
437
418
);
438
419
@@ -1015,8 +996,8 @@ private void internalHandleStreamReady(
1015
996
return ;
1016
997
}
1017
998
1018
- if (activeCpClient .isReady () &&
1019
- compareCpClients (activeCpClient , controlPlaneClient , authority ) < 0 ) {
999
+ if (activeCpClient .isReady ()
1000
+ && compareCpClients (activeCpClient , controlPlaneClient , authority ) < 0 ) {
1020
1001
logger .log (XdsLogLevel .INFO , "Ignoring stream restart for lower priority server {0}" ,
1021
1002
serverInfo .target ());
1022
1003
return ;
@@ -1027,7 +1008,7 @@ private void internalHandleStreamReady(
1027
1008
resourceSubscribers .values ()) {
1028
1009
for (ResourceSubscriber <? extends ResourceUpdate > subscriber : subscriberMap .values ()) {
1029
1010
if (subscriber .controlPlaneClient == controlPlaneClient
1030
- && subscriber .authority == authority ) {
1011
+ && Objects . equals ( subscriber .authority , authority ) ) {
1031
1012
subscriber .restartTimer ();
1032
1013
}
1033
1014
}
@@ -1036,9 +1017,10 @@ private void internalHandleStreamReady(
1036
1017
if (activeCpClient != controlPlaneClient ) {
1037
1018
activeCpClients .put (authority , controlPlaneClient );
1038
1019
updateRootResources (controlPlaneClient , authority , false );
1039
- controlPlaneClient .sendDiscoveryRequests (authority );
1040
1020
}
1041
1021
1022
+ controlPlaneClient .sendDiscoveryRequests (authority );
1023
+
1042
1024
// Shutdown any lower priority control plane clients.
1043
1025
Iterator <ControlPlaneClient > iterator = serverCpClientMap .values ().iterator ();
1044
1026
while (iterator .hasNext ()) {
@@ -1049,7 +1031,6 @@ private void internalHandleStreamReady(
1049
1031
}
1050
1032
}
1051
1033
}
1052
-
1053
1034
}
1054
1035
1055
1036
private int compareCpClients (ControlPlaneClient base , ControlPlaneClient other ,
@@ -1059,10 +1040,13 @@ private int compareCpClients(ControlPlaneClient base, ControlPlaneClient other,
1059
1040
}
1060
1041
1061
1042
ImmutableList <ServerInfo > serverInfos = getServerInfos (authority );
1062
- if (!serverInfos .contains (base .getServerInfo ()) || !serverInfos .contains (other .getServerInfo ())) {
1043
+ ServerInfo baseServerInfo = base .getServerInfo ();
1044
+ ServerInfo otherServerInfo = other .getServerInfo ();
1045
+
1046
+ if (!serverInfos .contains (baseServerInfo ) || !serverInfos .contains (otherServerInfo )) {
1063
1047
return -100 ; // At least one of them isn't serving this authority
1064
1048
}
1065
1049
1066
- return serverInfos .indexOf (base . getServerInfo ()) - serverInfos .indexOf (other . getServerInfo () );
1050
+ return serverInfos .indexOf (baseServerInfo ) - serverInfos .indexOf (otherServerInfo );
1067
1051
}
1068
1052
}
0 commit comments