mirror of https://github.com/grpc/grpc-java.git
xsd: wrr_locality to not propagate locality weight attribute (#9158)
WrrLocalityLoadBalancer should remove the locality weights attribute from Resolved addresses after using the information. Not propagating this attribute will make it impossible for another child wrr_locality from working. This is not a supported situation and this change make the failure happen earlier and to be more obvious as to the cause.
This commit is contained in:
parent
0fd8a6fcea
commit
36d1d5fe45
|
|
@ -80,6 +80,14 @@ final class WrrLocalityLoadBalancer extends LoadBalancer {
|
|||
wrrLocalityConfig.childPolicy));
|
||||
}
|
||||
|
||||
// Remove the locality weights attribute now that we have consumed it. This is done simply for
|
||||
// ease of debugging for the unsupported (and unlikely) scenario where WrrLocalityConfig has
|
||||
// another wrr_locality as the child policy. The missing locality weight attribute would make
|
||||
// the child wrr_locality fail early.
|
||||
resolvedAddresses = resolvedAddresses.toBuilder()
|
||||
.setAttributes(resolvedAddresses.getAttributes().toBuilder()
|
||||
.discard(InternalXdsAttributes.ATTR_LOCALITY_WEIGHTS).build()).build();
|
||||
|
||||
switchLb.switchTo(wrrLocalityConfig.childPolicy.getProvider());
|
||||
switchLb.handleResolvedAddresses(
|
||||
resolvedAddresses.toBuilder()
|
||||
|
|
|
|||
|
|
@ -112,7 +112,6 @@ public class WrrLocalityLoadBalancerTest {
|
|||
new WeightedPolicySelection(1, childPolicy));
|
||||
assertThat(wtConfig.targets).containsEntry(localityTwo.toString(),
|
||||
new WeightedPolicySelection(2, childPolicy));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -154,6 +153,22 @@ public class WrrLocalityLoadBalancerTest {
|
|||
verify(mockChildLb).handleNameResolutionError(Status.DEADLINE_EXCEEDED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localityWeightAttributeNotPropagated() {
|
||||
Locality locality = Locality.create("region1", "zone1", "subzone1");
|
||||
PolicySelection childPolicy = new PolicySelection(mockProvider, null);
|
||||
|
||||
WrrLocalityConfig wlConfig = new WrrLocalityConfig(childPolicy);
|
||||
Map<Locality, Integer> localityWeights = ImmutableMap.of(locality, 1);
|
||||
deliverAddresses(wlConfig, localityWeights);
|
||||
|
||||
// Assert that the child policy and the locality weights were correctly mapped to a
|
||||
// WeightedTargetConfig.
|
||||
verify(mockChildLb).handleResolvedAddresses(resolvedAddressesCaptor.capture());
|
||||
assertThat(resolvedAddressesCaptor.getValue().getAttributes()
|
||||
.get(InternalXdsAttributes.ATTR_LOCALITY_WEIGHTS)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shutdown() {
|
||||
deliverAddresses(new WrrLocalityConfig(new PolicySelection(mockProvider, null)),
|
||||
|
|
|
|||
Loading…
Reference in New Issue