New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xds: eds reuse priority names for the same existing locality #9287
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,12 @@ | |
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.Nullable; | ||
|
@@ -342,6 +345,8 @@ void shutdown() { | |
private final class EdsClusterState extends ClusterState implements EdsResourceWatcher { | ||
@Nullable | ||
private final String edsServiceName; | ||
private Map<Locality, String> localityPriorityNames = new HashMap<>(); | ||
int priorityNameGenId = 1; | ||
|
||
private EdsClusterState(String name, @Nullable String edsServiceName, | ||
@Nullable ServerInfo lrsServerInfo, @Nullable Long maxConcurrentRequests, | ||
|
@@ -385,10 +390,10 @@ public void run() { | |
List<DropOverload> dropOverloads = update.dropPolicies; | ||
List<EquivalentAddressGroup> addresses = new ArrayList<>(); | ||
Map<String, Map<Locality, Integer>> prioritizedLocalityWeights = new HashMap<>(); | ||
List<String> sortedPriorityNames = generatePriorityNames(name, localityLbEndpoints); | ||
for (Locality locality : localityLbEndpoints.keySet()) { | ||
LocalityLbEndpoints localityLbInfo = localityLbEndpoints.get(locality); | ||
int priority = localityLbInfo.priority(); | ||
String priorityName = priorityName(name, priority); | ||
String priorityName = localityPriorityNames.get(locality); | ||
boolean discard = true; | ||
for (LbEndpoint endpoint : localityLbInfo.endpoints()) { | ||
if (endpoint.isHealthy()) { | ||
|
@@ -426,23 +431,56 @@ public void run() { | |
logger.log(XdsLogLevel.INFO, | ||
"Cluster {0} has no usable priority/locality/endpoint", update.clusterName); | ||
} | ||
List<String> priorities = new ArrayList<>(prioritizedLocalityWeights.keySet()); | ||
Collections.sort(priorities); | ||
sortedPriorityNames.retainAll(prioritizedLocalityWeights.keySet()); | ||
Map<String, PriorityChildConfig> priorityChildConfigs = | ||
generateEdsBasedPriorityChildConfigs( | ||
name, edsServiceName, lrsServerInfo, maxConcurrentRequests, tlsContext, | ||
endpointLbPolicy, lbRegistry, prioritizedLocalityWeights, dropOverloads); | ||
status = Status.OK; | ||
resolved = true; | ||
result = new ClusterResolutionResult(addresses, priorityChildConfigs, priorities, | ||
localityWeights); | ||
result = new ClusterResolutionResult(addresses, priorityChildConfigs, | ||
sortedPriorityNames, localityWeights); | ||
handleEndpointResourceUpdate(); | ||
} | ||
} | ||
|
||
syncContext.execute(new EndpointsUpdated()); | ||
} | ||
|
||
private List<String> generatePriorityNames(String name, | ||
Map<Locality, LocalityLbEndpoints> localityLbEndpoints) { | ||
TreeMap<Integer, List<Locality>> todo = new TreeMap<>(); | ||
for (Locality locality : localityLbEndpoints.keySet()) { | ||
int priority = localityLbEndpoints.get(locality).priority(); | ||
if (!todo.containsKey(priority)) { | ||
todo.put(priority, new ArrayList<>()); | ||
} | ||
todo.get(priority).add(locality); | ||
} | ||
Map<Locality, String> newNames = new HashMap<>(); | ||
Set<String> usedNames = new HashSet<>(); | ||
List<String> ret = new ArrayList<>(); | ||
for (Integer priority: todo.keySet()) { | ||
String foundName = ""; | ||
for (Locality locality : todo.get(priority)) { | ||
if (localityPriorityNames.containsKey(locality) | ||
&& usedNames.add(localityPriorityNames.get(locality))) { | ||
foundName = localityPriorityNames.get(locality); | ||
break; | ||
} | ||
} | ||
if ("".equals(foundName)) { | ||
foundName = String.format("%s[priority%d]", name, priorityNameGenId++); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we only have to update tests in ClusterResolverLoadBalancerTest, let's change "priority" to "child" like we had briefly discussed. There aren't that many occurrences in ClusterResolverLoadBalancerTest to keep around this confusion. |
||
} | ||
for (Locality locality : todo.get(priority)) { | ||
newNames.put(locality, foundName); | ||
} | ||
ret.add(foundName); | ||
} | ||
localityPriorityNames = newNames; | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void onResourceDoesNotExist(final String resourceName) { | ||
syncContext.execute(new Runnable() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections.emptyMap()
would make it a bit more obvious the reference is modified instead of the map itself.