Skip to content

Commit

Permalink
core: Delay start of outlier detection tracking
Browse files Browse the repository at this point in the history
Tracking can't be started when a subchannel is created as the addresses
are not known at that point. Delay the start of tracking until the
subchannel has started and goes into the READY state.
  • Loading branch information
temawi committed Aug 21, 2022
1 parent 20ab369 commit 288a33d
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions core/src/main/java/io/grpc/util/OutlierDetectionLoadBalancer.java
Expand Up @@ -199,24 +199,7 @@ protected Helper delegate() {
public Subchannel createSubchannel(CreateSubchannelArgs args) {
// Subchannels are wrapped so that we can monitor call results and to trigger failures when
// we decide to eject the subchannel.
OutlierDetectionSubchannel subchannel = new OutlierDetectionSubchannel(
delegate.createSubchannel(args));

// If the subchannel is associated with a single address that is also already in the map
// the subchannel will be added to the map and be included in outlier detection.
List<EquivalentAddressGroup> addressGroups = subchannel.getAllAddresses();
if (hasSingleAddress(addressGroups)
&& trackerMap.containsKey(addressGroups.get(0).getAddresses().get(0))) {
AddressTracker tracker = trackerMap.get(addressGroups.get(0).getAddresses().get(0));
tracker.addSubchannel(subchannel);

// If this address has already been ejected, we need to immediately eject this Subchannel.
if (tracker.ejectionTimeNanos != null) {
subchannel.eject();
}
}

return subchannel;
return new OutlierDetectionSubchannel(delegate.createSubchannel(args));
}

@Override
Expand Down Expand Up @@ -345,6 +328,24 @@ class OutlierDetectionSubchannelStateListener implements SubchannelStateListener
@Override
public void onSubchannelState(ConnectivityStateInfo newState) {
lastSubchannelState = newState;

if (newState.getState().equals(ConnectivityState.READY)) {
// If the subchannel is associated with a single address that is also already in the map
// the subchannel will be added to the map and be included in outlier detection.
List<EquivalentAddressGroup> addressGroups = getAllAddresses();
if (hasSingleAddress(addressGroups)
&& trackerMap.containsKey(addressGroups.get(0).getAddresses().get(0))) {
AddressTracker tracker = trackerMap.get(addressGroups.get(0).getAddresses().get(0));
tracker.addSubchannel(OutlierDetectionSubchannel.this);

// If this address has already been ejected, we need to immediately eject this
// Subchannel.
if (tracker.ejectionTimeNanos != null) {
eject();
}
}
}

if (!ejected) {
delegate.onSubchannelState(newState);
}
Expand Down

0 comments on commit 288a33d

Please sign in to comment.