Skip to content

Commit

Permalink
xds: Delegate more RingHashLB address updates to MultiChildLB
Browse files Browse the repository at this point in the history
Since 0447497 RingHashLB has not used
acceptResolvedAddressesInternal(). At the time that was needed because
deactivated children were part of MultiChildLB. But in 9de8e44, the
logic of RingHashLB and MultiChildLB.acceptResolvedAddressesInternal()
converged, so it can now swap back to using the base class for more
logic.
  • Loading branch information
ejona86 committed Aug 12, 2024
1 parent b5989a5 commit fd8734f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
6 changes: 3 additions & 3 deletions util/src/main/java/io/grpc/util/MultiChildLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected final AcceptResolvedAddrRetVal acceptResolvedAddressesInternal(
return new AcceptResolvedAddrRetVal(Status.OK, getRemovedChildren(newChildren.keySet()));
}

protected final void addMissingChildren(Map<Object, ChildLbState> newChildren) {
private void addMissingChildren(Map<Object, ChildLbState> newChildren) {
// Do adds and identify reused children
for (Map.Entry<Object, ChildLbState> entry : newChildren.entrySet()) {
final Object key = entry.getKey();
Expand All @@ -241,7 +241,7 @@ protected final void addMissingChildren(Map<Object, ChildLbState> newChildren) {
}
}

protected final void updateChildrenWithResolvedAddresses(ResolvedAddresses resolvedAddresses,
private void updateChildrenWithResolvedAddresses(ResolvedAddresses resolvedAddresses,
Map<Object, ChildLbState> newChildren) {
for (Map.Entry<Object, ChildLbState> entry : newChildren.entrySet()) {
Object childConfig = entry.getValue().getConfig();
Expand All @@ -256,7 +256,7 @@ protected final void updateChildrenWithResolvedAddresses(ResolvedAddresses resol
/**
* Identifies which children have been removed (are not part of the newChildKeys).
*/
protected final List<ChildLbState> getRemovedChildren(Set<Object> newChildKeys) {
private List<ChildLbState> getRemovedChildren(Set<Object> newChildKeys) {
List<ChildLbState> removedChildren = new ArrayList<>();
// Do removals
for (Object key : ImmutableList.copyOf(childLbStates.keySet())) {
Expand Down
16 changes: 4 additions & 12 deletions xds/src/main/java/io/grpc/xds/RingHashLoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,11 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {

try {
resolvingAddresses = true;
// Subclass handles any special manipulation to create appropriate types of ChildLbStates
Map<Object, ChildLbState> newChildren = createChildLbMap(resolvedAddresses);

if (newChildren.isEmpty()) {
addressValidityStatus = Status.UNAVAILABLE.withDescription(
"Ring hash lb error: EDS resolution was successful, but there were no valid addresses");
handleNameResolutionError(addressValidityStatus);
return addressValidityStatus;
AcceptResolvedAddrRetVal acceptRetVal = acceptResolvedAddressesInternal(resolvedAddresses);
if (!acceptRetVal.status.isOk()) {
return acceptRetVal.status;
}

addMissingChildren(newChildren);
updateChildrenWithResolvedAddresses(resolvedAddresses, newChildren);

// Now do the ringhash specific logic with weights and building the ring
RingHashConfig config = (RingHashConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
if (config == null) {
Expand Down Expand Up @@ -145,7 +137,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
// clusters and resolver can remove them in service config.
updateOverallBalancingState();

shutdownRemoved(getRemovedChildren(newChildren.keySet()));
shutdownRemoved(acceptRetVal.removedChildren);
} finally {
this.resolvingAddresses = false;
}
Expand Down

0 comments on commit fd8734f

Please sign in to comment.