Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ringhash: don't recreate subConns when update doesn't change address information #5431

Merged
merged 7 commits into from Jul 7, 2022

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Jun 15, 2022

Ringhash LB policy receives address weights in BalancerAttributes. Existing code was doing the following:

  • set Attributes field in received addresses to nil
  • copy over weight information from BalancerAttributes field into deprecated Metadata field
  • use resolver.Address as a map key

As BalancerAttributes field was not being set to nil (after copying over the information to the Metadata field), addresses with the same information were being considered as different map keys, leading to subConns being recreated when there was no need for it.

This change does the following:

  • uses a resolver.AddressMap to store a map from resolver.Address to an internal value
  • resolver.AddressMap ignores BalancerAttributes, but takes into account Attributes

With this change, the ringhash policy is able distinguish between addresses which change only in their weight information, and therefore recreates subConns only when absolutely required. Also, as an added benefit, we stop abusing the deprecated Metadata field.

Fixes #5420

RELEASE NOTES:

  • ringhash: avoid recreating subChannels when update doesn't change address weight information

@easwars easwars requested a review from dfawley June 15, 2022 23:11
@easwars easwars added this to the 1.48 Release milestone Jun 15, 2022
// This is necessary (all the attributes need to be stripped) for the
// balancer to detect identical {address+weight} combination.
weightSum += a.Metadata.(uint32)
for _, a := range subConns.Keys() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's store Keys() in a local variable, since we range over it again later. We can also get it on the first line and use len(keys) instead of subConns.Len().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

xds/internal/balancer/ringhash/ringhash.go Outdated Show resolved Hide resolved
addrsSet[aNoAttrs] = struct{}{}
if scInfo, ok := b.subConns[aNoAttrs]; !ok {
modifiedAddr := addr
modifiedAddr.Attributes = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why clear Attributes? That seems wrong, since Attributes will affect subchannel creation. I think we should be clearing BalancerAttributes if anything (or just leave it alone since it doesn't matter for comparisons?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see line 240, we use the original addr for subchannel creation, thereby passing all the attributes that we received. This modifiedAddr is used only to key the subConns map and here we are interested only in the address weight, which is currently stored as part of the BalancerAttributes field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed this to not ignore Attributes.

// setWeightAttribute returns a copy of addr in which the Attributes field is
// updated with weight.
func setWeightAttribute(addr resolver.Address, weight uint32) resolver.Address {
addr.Attributes = addr.Attributes.WithValue(weightAttributeKey{}, weight)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BalancerAttributes?

Hold up, are we saying we want an AddressMap that is sensitive to BalancerAttributes (or at least this one), i.e. attributes that do not impact subchannel uniqueness? Because that's not what AddressMap is, currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not change the logic here wrt to what was being used from Attributes and from BalancerAttributes. And I sort of get the idea that the ringhash LB policy cares only about address weight when deciding whether it needs to recreate subConns.

But I also seem to get your point that it doesn't seem to be right to be ignoring Attributes while deciding on subchannel uniqueness. Let me check what the other implementations do. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the subConns map to work with the actual address. No modifications to either Attributes or BalancerAttributes.

@dfawley dfawley assigned easwars and unassigned dfawley Jun 17, 2022
@easwars
Copy link
Contributor Author

easwars commented Jun 23, 2022

The GH review page seems utterly broken now. It can't seem to keep track of comments even without a force push now. Sigh ...

@dfawley dfawley assigned dfawley and unassigned easwars Jun 28, 2022
@dfawley dfawley modified the milestones: 1.48 Release, 1.49 Release Jul 1, 2022
@dfawley dfawley assigned easwars and unassigned dfawley Jul 7, 2022
@easwars easwars merged commit 0d04c6f into grpc:master Jul 7, 2022
@easwars easwars deleted the ringhash_use_address_map branch July 7, 2022 20:04
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ringhash: must not recreate subConns when address contents have not changed
2 participants