Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YifeiZhuang committed Feb 26, 2024
1 parent 72b2f9b commit 307943b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions util/src/main/java/io/grpc/util/OutlierDetectionLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
Set<SocketAddress> endpoint = ImmutableSet.copyOf(addressGroup.getAddresses());
endpoints.add(endpoint);
for (SocketAddress address : addressGroup.getAddresses()) {
addressEndpointMap.putIfAbsent(address, endpoint);
if (addressEndpointMap.containsKey(address)) {
logger.log(ChannelLogLevel.WARNING,
"Unexpected duplicated address {0} belongs to multiple endpoints", address);
}
addressEndpointMap.put(address, endpoint);
}
}
endpointTrackerMap.keySet().retainAll(endpoints);
Expand Down Expand Up @@ -496,8 +500,7 @@ public void streamClosed(Status status) {
}

/**
* Tracks additional information about a set of equivalent addresses needed for outlier
* detection.
* Tracks additional information about the endpoint needed for outlier detection.
*/
static class EndpointTracker {

Expand Down Expand Up @@ -662,7 +665,7 @@ public String toString() {
}

/**
* Maintains a mapping from addresses to their trackers.
* Maintains a mapping from endpoint (a set of addresses) to their trackers.
*/
static class EndpointTrackerMap extends ForwardingMap<Set<SocketAddress>, EndpointTracker> {
private final Map<Set<SocketAddress>, EndpointTracker> trackerMap;
Expand All @@ -685,12 +688,7 @@ void updateTrackerConfigs(OutlierDetectionLoadBalancerConfig config) {
/** Adds a new tracker for every given address. */
void putNewTrackers(OutlierDetectionLoadBalancerConfig config,
Set<Set<SocketAddress>> endpoints) {
for (Set<SocketAddress> endpointAddresses : endpoints) {
if (!trackerMap.containsKey(endpointAddresses)) {
EndpointTracker t = new EndpointTracker(config);
trackerMap.put(endpointAddresses, t);
}
}
endpoints.forEach(e -> trackerMap.putIfAbsent(e, new EndpointTracker(config)));
}

/** Resets the call counters for all the trackers in the map. */
Expand Down Expand Up @@ -886,10 +884,10 @@ static class FailurePercentageOutlierEjectionAlgorithm implements OutlierEjectio
@Override
public void ejectOutliers(EndpointTrackerMap trackerMap, long ejectionTimeNanos) {

// Only consider addresses that have the minimum request volume specified in the config.
// Only consider endpoints that have the minimum request volume specified in the config.
List<EndpointTracker> trackersWithVolume = trackersWithVolume(trackerMap,
config.failurePercentageEjection.requestVolume);
// If we don't have enough addresses with significant volume then there's nothing to do.
// If we don't have enough endpoints with significant volume then there's nothing to do.
if (trackersWithVolume.size() < config.failurePercentageEjection.minimumHosts
|| trackersWithVolume.size() == 0) {
return;
Expand Down

0 comments on commit 307943b

Please sign in to comment.