-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Use k8s.io/utils/lru instead of github.com/golang/groupcache/lru #128507
Use k8s.io/utils/lru instead of github.com/golang/groupcache/lru #128507
Conversation
e692401
to
2ae2bd0
Compare
2ae2bd0
to
3e04366
Compare
/kind cleanup |
@@ -2654,7 +2654,7 @@ func assertState(s state) step { | |||
} | |||
if len(s.absentOwnerCache) != ctx.gc.absentOwnerCache.cache.Len() { | |||
// only way to inspect is to drain them all, but that's ok because we're failing the test anyway | |||
ctx.gc.absentOwnerCache.cache.OnEvicted = func(key lru.Key, item interface{}) { | |||
err := ctx.gc.absentOwnerCache.cache.SetEvictionFunc(func(key lru.Key, item interface{}) { |
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.
only needed for a test?
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.
yep
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.
🤷 🙃
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 still think this can be racy without a lock in SetEvictionFunc, but in this specific use, it doesn't really matter (this is helping debug an already-failed test). I do think a follow-up in utils to make SetEvictionFunc threadsafe would be good
if c.cache.OnEvicted != nil { | ||
return fmt.Errorf("lru cache eviction function is already set") | ||
} | ||
c.cache.OnEvicted = f |
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.
Does this not need a mutex lock?
The assumption seems to be that this gets called before concurrent use starts, but a one-time mutex lock would trivial and avoid that assumption.
The overall PR LGTM, so not a blocker as far as I am concerned.
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.
asked exactly the same https://github.com/kubernetes/utils/pull/318/files#r1826961649 😄
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.
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.
Agree it's not a blocker for this PR since we only use this in a single spot in an already-failed test, but a follow-up to make it threadsafe sgtm
LGTM |
f.Lock() | ||
defer f.Unlock() |
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.
this is guarding more than just the cache get/add ... also the rate limiter assignment to the record (which is not thread-safe, and ensuring we don't get concurrent accept calls to the record's rate limiter
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.
the golang rate limiter is thread safe, that is wrapped by us
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.
/lgtm
/approve
if c.cache.OnEvicted != nil { | ||
return fmt.Errorf("lru cache eviction function is already set") | ||
} | ||
c.cache.OnEvicted = f |
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.
Agree it's not a blocker for this PR since we only use this in a single spot in an already-failed test, but a follow-up to make it threadsafe sgtm
LGTM label has been added. Git tree hash: c9008c3ddd07f09e649bb3692fb8287f0482d274
|
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
af098ac
to
2b0592e
Compare
/lgtm |
LGTM label has been added. Git tree hash: 434ead3dd0fcc477db365ca7481018f91c3ac97b
|
/triage accepted |
What type of PR is this?
Drop last remaining reference to github.com/golang/groupcache/lru since we already have
k8s.io/utils/lru
for a while now.What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: