xds: have ClusterEndpointsBalancer cancel endpoint watcher only during shutdown

Previously when eds service name is changed, the old endpoint watcher is canceled immediately even it's in graceful switch period, so the old ClusterEndpointsBalancer won't receive any new updates. This behavior is not as good/clean as cancelling the old watch only once the old ClusterEndpointsBalancer is shutdown.
This commit is contained in:
ZHANG Dapeng 2020-02-14 11:11:15 -08:00 committed by GitHub
parent cd049ed48b
commit 92c9237fe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 19 deletions

View File

@ -69,9 +69,6 @@ final class EdsLoadBalancer extends LoadBalancer {
// Most recent XdsConfig. // Most recent XdsConfig.
@Nullable @Nullable
private XdsConfig xdsConfig; private XdsConfig xdsConfig;
// Most recent EndpointWatcher.
@Nullable
private EndpointWatcher endpointWatcher;
@Nullable @Nullable
private ObjectPool<XdsClient> xdsClientPool; private ObjectPool<XdsClient> xdsClientPool;
@Nullable @Nullable
@ -214,11 +211,7 @@ final class EdsLoadBalancer extends LoadBalancer {
new ClusterEndpointsBalancerFactory(clusterServiceName); new ClusterEndpointsBalancerFactory(clusterServiceName);
switchingLoadBalancer.switchTo(clusterEndpointsLoadBalancerFactory); switchingLoadBalancer.switchTo(clusterEndpointsLoadBalancerFactory);
} }
resolvedAddresses = resolvedAddresses.toBuilder()
.setLoadBalancingPolicyConfig(newXdsConfig)
.build();
switchingLoadBalancer.handleResolvedAddresses(resolvedAddresses); switchingLoadBalancer.handleResolvedAddresses(resolvedAddresses);
this.xdsConfig = newXdsConfig; this.xdsConfig = newXdsConfig;
} }
@ -263,16 +256,9 @@ final class EdsLoadBalancer extends LoadBalancer {
*/ */
private final class ClusterEndpointsBalancerFactory extends LoadBalancer.Factory { private final class ClusterEndpointsBalancerFactory extends LoadBalancer.Factory {
final String clusterServiceName; final String clusterServiceName;
@Nullable
final String oldClusterServiceName;
ClusterEndpointsBalancerFactory(String clusterServiceName) { ClusterEndpointsBalancerFactory(String clusterServiceName) {
this.clusterServiceName = clusterServiceName; this.clusterServiceName = clusterServiceName;
if (xdsConfig != null) {
oldClusterServiceName = xdsConfig.edsServiceName;
} else {
oldClusterServiceName = null;
}
} }
@Override @Override
@ -314,11 +300,6 @@ final class EdsLoadBalancer extends LoadBalancer {
endpointWatcher = new EndpointWatcherImpl(localityStore); endpointWatcher = new EndpointWatcherImpl(localityStore);
xdsClient.watchEndpointData(clusterServiceName, endpointWatcher); xdsClient.watchEndpointData(clusterServiceName, endpointWatcher);
if (EdsLoadBalancer.this.endpointWatcher != null) {
xdsClient.cancelEndpointDataWatch(
oldClusterServiceName, EdsLoadBalancer.this.endpointWatcher);
}
EdsLoadBalancer.this.endpointWatcher = endpointWatcher;
} }
// TODO(zddapeng): In handleResolvedAddresses() handle child policy change if any. // TODO(zddapeng): In handleResolvedAddresses() handle child policy change if any.