mirror of https://github.com/k3s-io/k3s
Merge pull request #73793 from tedyu/master
Reduce the duration where expirationLock is held for expiration_cachepull/564/head
commit
c615cb068c
|
@ -144,13 +144,13 @@ func (c *ExpirationCache) ListKeys() []string {
|
||||||
// Add timestamps an item and inserts it into the cache, overwriting entries
|
// Add timestamps an item and inserts it into the cache, overwriting entries
|
||||||
// that might exist under the same key.
|
// that might exist under the same key.
|
||||||
func (c *ExpirationCache) Add(obj interface{}) error {
|
func (c *ExpirationCache) Add(obj interface{}) error {
|
||||||
c.expirationLock.Lock()
|
|
||||||
defer c.expirationLock.Unlock()
|
|
||||||
|
|
||||||
key, err := c.keyFunc(obj)
|
key, err := c.keyFunc(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return KeyError{obj, err}
|
return KeyError{obj, err}
|
||||||
}
|
}
|
||||||
|
c.expirationLock.Lock()
|
||||||
|
defer c.expirationLock.Unlock()
|
||||||
|
|
||||||
c.cacheStorage.Add(key, ×tampedEntry{obj, c.clock.Now()})
|
c.cacheStorage.Add(key, ×tampedEntry{obj, c.clock.Now()})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -163,12 +163,12 @@ func (c *ExpirationCache) Update(obj interface{}) error {
|
||||||
|
|
||||||
// Delete removes an item from the cache.
|
// Delete removes an item from the cache.
|
||||||
func (c *ExpirationCache) Delete(obj interface{}) error {
|
func (c *ExpirationCache) Delete(obj interface{}) error {
|
||||||
c.expirationLock.Lock()
|
|
||||||
defer c.expirationLock.Unlock()
|
|
||||||
key, err := c.keyFunc(obj)
|
key, err := c.keyFunc(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return KeyError{obj, err}
|
return KeyError{obj, err}
|
||||||
}
|
}
|
||||||
|
c.expirationLock.Lock()
|
||||||
|
defer c.expirationLock.Unlock()
|
||||||
c.cacheStorage.Delete(key)
|
c.cacheStorage.Delete(key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -177,8 +177,6 @@ func (c *ExpirationCache) Delete(obj interface{}) error {
|
||||||
// before attempting the replace operation. The replace operation will
|
// before attempting the replace operation. The replace operation will
|
||||||
// delete the contents of the ExpirationCache `c`.
|
// delete the contents of the ExpirationCache `c`.
|
||||||
func (c *ExpirationCache) Replace(list []interface{}, resourceVersion string) error {
|
func (c *ExpirationCache) Replace(list []interface{}, resourceVersion string) error {
|
||||||
c.expirationLock.Lock()
|
|
||||||
defer c.expirationLock.Unlock()
|
|
||||||
items := make(map[string]interface{}, len(list))
|
items := make(map[string]interface{}, len(list))
|
||||||
ts := c.clock.Now()
|
ts := c.clock.Now()
|
||||||
for _, item := range list {
|
for _, item := range list {
|
||||||
|
@ -188,6 +186,8 @@ func (c *ExpirationCache) Replace(list []interface{}, resourceVersion string) er
|
||||||
}
|
}
|
||||||
items[key] = ×tampedEntry{item, ts}
|
items[key] = ×tampedEntry{item, ts}
|
||||||
}
|
}
|
||||||
|
c.expirationLock.Lock()
|
||||||
|
defer c.expirationLock.Unlock()
|
||||||
c.cacheStorage.Replace(items, resourceVersion)
|
c.cacheStorage.Replace(items, resourceVersion)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue