mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #26767 from ZTE-PaaS/249043822-patch-2
Automatic merge from submit-queue Update reason_cache.go, Get method operate lru cache not threadsafe The reason_cache wrapped lru cache , lru cache modies linked list even for a get, should use WLock for both read and write
This commit is contained in:
commit
da6d348b1c
@ -36,7 +36,7 @@ import (
|
|||||||
// TODO(random-liu): Use more reliable cache which could collect garbage of failed pod.
|
// TODO(random-liu): Use more reliable cache which could collect garbage of failed pod.
|
||||||
// TODO(random-liu): Move reason cache to somewhere better.
|
// TODO(random-liu): Move reason cache to somewhere better.
|
||||||
type ReasonCache struct {
|
type ReasonCache struct {
|
||||||
lock sync.RWMutex
|
lock sync.Mutex
|
||||||
cache *lru.Cache
|
cache *lru.Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,8 +93,8 @@ func (c *ReasonCache) Remove(uid types.UID, name string) {
|
|||||||
// whether an error reason is found in the cache. If no error reason is found, empty string will
|
// whether an error reason is found in the cache. If no error reason is found, empty string will
|
||||||
// be returned for error reason and error message.
|
// be returned for error reason and error message.
|
||||||
func (c *ReasonCache) Get(uid types.UID, name string) (error, string, bool) {
|
func (c *ReasonCache) Get(uid types.UID, name string) (error, string, bool) {
|
||||||
c.lock.RLock()
|
c.lock.Lock()
|
||||||
defer c.lock.RUnlock()
|
defer c.lock.Unlock()
|
||||||
value, ok := c.cache.Get(c.composeKey(uid, name))
|
value, ok := c.cache.Get(c.composeKey(uid, name))
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, "", ok
|
return nil, "", ok
|
||||||
|
Loading…
Reference in New Issue
Block a user