-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
|
||
// A no-op implementation of the balancerCache interface when caching is | ||
// disabled due to Options.SubBalancerCloseTimeout set to 0. | ||
type noopBalancerCache struct{} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 of0
.
- In fact, we could consider making the
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
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 thepriority
balancer, but inadvertently has been used by other LB policies that manage child policies.Fixes #6515
RELEASE NOTES:
rls
,weightedtarget
andclustermanager
LB policies