mirror of https://github.com/grpc/grpc-java.git
A map for ClusterState is not required in ClusterResolverLoadBalancer which now holds only a single cluster's state.
This commit is contained in:
parent
7c16de891e
commit
f6afb635f9
|
@ -168,7 +168,7 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
*/
|
*/
|
||||||
private final class ClusterResolverLbState extends LoadBalancer {
|
private final class ClusterResolverLbState extends LoadBalancer {
|
||||||
private final Helper helper;
|
private final Helper helper;
|
||||||
private final Map<String, ClusterState> clusterStates = new HashMap<>();
|
private ClusterState clusterState;
|
||||||
private String cluster;
|
private String cluster;
|
||||||
private Object endpointLbConfig;
|
private Object endpointLbConfig;
|
||||||
private ResolvedAddresses resolvedAddresses;
|
private ResolvedAddresses resolvedAddresses;
|
||||||
|
@ -187,18 +187,16 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
endpointLbConfig = config.lbConfig;
|
endpointLbConfig = config.lbConfig;
|
||||||
DiscoveryMechanism instance = config.discoveryMechanism;
|
DiscoveryMechanism instance = config.discoveryMechanism;
|
||||||
cluster = instance.cluster;
|
cluster = instance.cluster;
|
||||||
ClusterState state;
|
|
||||||
if (instance.type == DiscoveryMechanism.Type.EDS) {
|
if (instance.type == DiscoveryMechanism.Type.EDS) {
|
||||||
state = new EdsClusterState(instance.cluster, instance.edsServiceName,
|
clusterState = new EdsClusterState(instance.cluster, instance.edsServiceName,
|
||||||
instance.lrsServerInfo, instance.maxConcurrentRequests, instance.tlsContext,
|
instance.lrsServerInfo, instance.maxConcurrentRequests, instance.tlsContext,
|
||||||
instance.filterMetadata, instance.outlierDetection);
|
instance.filterMetadata, instance.outlierDetection);
|
||||||
} else { // logical DNS
|
} else { // logical DNS
|
||||||
state = new LogicalDnsClusterState(instance.cluster, instance.dnsHostName,
|
clusterState = new LogicalDnsClusterState(instance.cluster, instance.dnsHostName,
|
||||||
instance.lrsServerInfo, instance.maxConcurrentRequests, instance.tlsContext,
|
instance.lrsServerInfo, instance.maxConcurrentRequests, instance.tlsContext,
|
||||||
instance.filterMetadata);
|
instance.filterMetadata);
|
||||||
}
|
}
|
||||||
clusterStates.put(instance.cluster, state);
|
clusterState.start();
|
||||||
state.start();
|
|
||||||
return Status.OK;
|
return Status.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,9 +212,7 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
for (ClusterState state : clusterStates.values()) {
|
clusterState.shutdown();
|
||||||
state.shutdown();
|
|
||||||
}
|
|
||||||
if (childLb != null) {
|
if (childLb != null) {
|
||||||
childLb.shutdown();
|
childLb.shutdown();
|
||||||
}
|
}
|
||||||
|
@ -228,17 +224,16 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
List<String> priorities = new ArrayList<>(); // totally ordered priority list
|
List<String> priorities = new ArrayList<>(); // totally ordered priority list
|
||||||
|
|
||||||
Status endpointNotFound = Status.OK;
|
Status endpointNotFound = Status.OK;
|
||||||
ClusterState state = clusterStates.get(cluster);
|
|
||||||
// Propagate endpoints to the child LB policy only after all clusters have been resolved.
|
// Propagate endpoints to the child LB policy only after all clusters have been resolved.
|
||||||
if (!state.resolved && state.status.isOk()) {
|
if (!clusterState.resolved && clusterState.status.isOk()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state.result != null) {
|
if (clusterState.result != null) {
|
||||||
addresses.addAll(state.result.addresses);
|
addresses.addAll(clusterState.result.addresses);
|
||||||
priorityChildConfigs.putAll(state.result.priorityChildConfigs);
|
priorityChildConfigs.putAll(clusterState.result.priorityChildConfigs);
|
||||||
priorities.addAll(state.result.priorities);
|
priorities.addAll(clusterState.result.priorities);
|
||||||
} else {
|
} else {
|
||||||
endpointNotFound = state.status;
|
endpointNotFound = clusterState.status;
|
||||||
}
|
}
|
||||||
if (addresses.isEmpty()) {
|
if (addresses.isEmpty()) {
|
||||||
if (endpointNotFound.isOk()) {
|
if (endpointNotFound.isOk()) {
|
||||||
|
@ -271,13 +266,12 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleEndpointResolutionError() {
|
private void handleEndpointResolutionError() {
|
||||||
ClusterState state = clusterStates.get(cluster);
|
if (!clusterState.status.isOk()) {
|
||||||
if (!state.status.isOk()) {
|
|
||||||
if (childLb != null) {
|
if (childLb != null) {
|
||||||
childLb.handleNameResolutionError(state.status);
|
childLb.handleNameResolutionError(clusterState.status);
|
||||||
} else {
|
} else {
|
||||||
helper.updateBalancingState(
|
helper.updateBalancingState(
|
||||||
TRANSIENT_FAILURE, new FixedResultPicker(PickResult.withError(state.status)));
|
TRANSIENT_FAILURE, new FixedResultPicker(PickResult.withError(clusterState.status)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,10 +288,8 @@ final class ClusterResolverLoadBalancer extends LoadBalancer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshNameResolution() {
|
public void refreshNameResolution() {
|
||||||
for (ClusterState state : clusterStates.values()) {
|
if (clusterState instanceof LogicalDnsClusterState) {
|
||||||
if (state instanceof LogicalDnsClusterState) {
|
((LogicalDnsClusterState) clusterState).refresh();
|
||||||
((LogicalDnsClusterState) state).refresh();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue