xds: Clean up updateChildState() (#6127)

This commit is contained in:
ZHANG Dapeng 2019-09-06 14:40:46 -07:00 committed by GitHub
parent a234ada5a9
commit d86eb711c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 35 deletions

View File

@ -206,8 +206,6 @@ interface LocalityStore {
} }
} }
ConnectivityState newState = null;
List<WeightedChildPicker> childPickers = new ArrayList<>(newLocalities.size());
for (XdsLocality newLocality : newLocalities) { for (XdsLocality newLocality : newLocalities) {
if (!edsResponsLocalityInfo.containsKey(newLocality)) { if (!edsResponsLocalityInfo.containsKey(newLocality)) {
@ -215,8 +213,8 @@ interface LocalityStore {
} }
// Assuming standard mode only (EDS response with a list of endpoints) for now. // Assuming standard mode only (EDS response with a list of endpoints) for now.
List<EquivalentAddressGroup> newEags = localityInfoMap.get(newLocality).eags; final List<EquivalentAddressGroup> newEags = localityInfoMap.get(newLocality).eags;
LocalityLbInfo localityLbInfo; final LocalityLbInfo localityLbInfo;
ChildHelper childHelper; ChildHelper childHelper;
if (oldLocalities.contains(newLocality)) { if (oldLocalities.contains(newLocality)) {
LocalityLbInfo oldLocalityLbInfo = localityMap.get(newLocality); LocalityLbInfo oldLocalityLbInfo = localityMap.get(newLocality);
@ -243,18 +241,18 @@ interface LocalityStore {
} }
} }
updatedLocalityMap.put(newLocality, localityLbInfo); updatedLocalityMap.put(newLocality, localityLbInfo);
// In extreme case handleResolvedAddresses() may trigger updateBalancingState() immediately,
// so execute handleResolvedAddresses() after all the setup in this method is complete.
helper.getSynchronizationContext().execute(new Runnable() {
@Override
public void run() {
// TODO: put endPointWeights into attributes for WRR. // TODO: put endPointWeights into attributes for WRR.
localityLbInfo.childBalancer localityLbInfo.childBalancer
.handleResolvedAddresses( .handleResolvedAddresses(
ResolvedAddresses.newBuilder().setAddresses(newEags).build()); ResolvedAddresses.newBuilder().setAddresses(newEags).build());
if (localityLbInfo.childHelper.currentChildState == READY) {
childPickers.add(
new WeightedChildPicker(
localityInfoMap.get(newLocality).localityWeight,
localityLbInfo.childHelper.currentChildPicker));
} }
newState = aggregateState(newState, childHelper.currentChildState); });
} }
// Add deactivated localities to localityMap to keep track of them. // Add deactivated localities to localityMap to keep track of them.
@ -286,7 +284,7 @@ interface LocalityStore {
}); });
edsResponsLocalityInfo = ImmutableMap.copyOf(localityInfoMap); edsResponsLocalityInfo = ImmutableMap.copyOf(localityInfoMap);
updatePicker(newState, childPickers); onChildStateUpdated();
} }
@Override @Override
@ -320,9 +318,7 @@ interface LocalityStore {
new DeletionTask(), DELAYED_DELETION_TIMEOUT_MINUTES, new DeletionTask(), DELAYED_DELETION_TIMEOUT_MINUTES,
TimeUnit.MINUTES, helper.getScheduledExecutorService()); TimeUnit.MINUTES, helper.getScheduledExecutorService());
updateChildState( onChildStateUpdated();
locality, localityLbInfo.childHelper.currentChildState,
localityLbInfo.childHelper.currentChildPicker);
} }
@Override @Override
@ -356,12 +352,7 @@ interface LocalityStore {
return overallState; return overallState;
} }
private void updateChildState( private void onChildStateUpdated() {
XdsLocality locality, ConnectivityState newChildState, SubchannelPicker newChildPicker) {
if (!localityMap.containsKey(locality)) {
return;
}
List<WeightedChildPicker> childPickers = new ArrayList<>(); List<WeightedChildPicker> childPickers = new ArrayList<>();
ConnectivityState overallState = null; ConnectivityState overallState = null;
@ -370,15 +361,8 @@ interface LocalityStore {
continue; continue;
} }
LocalityLbInfo localityLbInfo = localityMap.get(l); LocalityLbInfo localityLbInfo = localityMap.get(l);
ConnectivityState childState; ConnectivityState childState = localityLbInfo.childHelper.currentChildState;
SubchannelPicker childPicker; SubchannelPicker childPicker = localityLbInfo.childHelper.currentChildPicker;
if (l.equals(locality)) {
childState = newChildState;
childPicker = newChildPicker;
} else {
childState = localityLbInfo.childHelper.currentChildState;
childPicker = localityLbInfo.childHelper.currentChildPicker;
}
overallState = aggregateState(overallState, childState); overallState = aggregateState(overallState, childState);
@ -487,7 +471,7 @@ interface LocalityStore {
newPicker, orcaPerRequestUtil)); newPicker, orcaPerRequestUtil));
// delegate to parent helper // delegate to parent helper
updateChildState(locality, newState, currentChildPicker); onChildStateUpdated();
} }
@Override @Override