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

balancergroup: do not cache closed sub-balancers by default #6523

Merged
merged 3 commits into from
Aug 10, 2023

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Aug 9, 2023

Internal tracking issue: b/291228739

This PR changes the behavior of the balancergroup package to only cache deleted sub-balancers when a cache timeout is specified explicitly by the caller. This caching feature was supposed to be only used by the priority balancer, but inadvertently has been used by other LB policies that manage child policies.

Fixes #6515

RELEASE NOTES:

  • balancergroup: do not cache closed sub-balancers by default; affects rls, weightedtarget and clustermanager LB policies

@easwars easwars requested a review from dfawley August 9, 2023 18:40
@easwars easwars added this to the 1.58 Release milestone Aug 9, 2023

// A no-op implementation of the balancerCache interface when caching is
// disabled due to Options.SubBalancerCloseTimeout set to 0.
type noopBalancerCache struct{}
Copy link
Member

Choose a reason for hiding this comment

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

Do you think this should go into the cache package for other places to be able to share it? And make the constructor for a timeout cache return it if the timeout is zero?

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 thought about this for a while. I feel that it does not make a whole lot of sense for a type that provides caching functionality to also provide a way to disable the same.

  • I feel that doing so would unnecessary add more complexity to the package providing the cache.
    • We would need to define an interface and create multiple implementations of it.
  • Also, I don't see other usages of this cache where caching might have to be disabled.
    • In fact, we could consider making the cache.NewTimeoutCache return an error if passed a timeout of 0.

Instead explicitly handling the no-caching case in the balancergroup makes more sense because it makes things very clear to the reader of the code as to how and where caching is being done.

Copy link
Member

Choose a reason for hiding this comment

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

I'm good with the current version. I think if there is a nop implementation then it makes the most sense in the cache package. But just not calling the cache when it's disabled is a perfectly reasonable implementation too.

type noopBalancerCache struct{}

func (noopBalancerCache) Add(_ interface{}, _ interface{}, cb func()) (interface{}, bool) {
cb()
Copy link
Member

Choose a reason for hiding this comment

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

Executing this callback synchronously could theoretically cause problems with a pattern like:

b.Lock()
b.cache.Add(blah, blah, func() { b.Lock(); do something; b.Unlock(); })
b.Unlock()

I wonder if we should just go cb() now while seeing this, or wait until we run into that problem, which may never happen anyway.

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 agree go cb() should have been what the noop implementation should have done. The problem probably doesn't happen with the current implementation of the timeout cache because the timer callback is invoked in a separate goroutine even if the timeout value is 0.

@dfawley dfawley assigned easwars and unassigned dfawley Aug 9, 2023
@easwars easwars assigned dfawley and unassigned easwars Aug 10, 2023
@dfawley dfawley assigned easwars and unassigned dfawley Aug 10, 2023
@easwars easwars merged commit bb41067 into grpc:master Aug 10, 2023
10 checks passed
@easwars easwars deleted the balancergroup_idle_cache branch August 10, 2023 19:35
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2024
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.

Cache child policies after deletion only where appropriate
2 participants