Switch GC absentOwnerCache to full reference

Before deleting an object based on absent owners, GC verifies absence of those owners with a live lookup.

The coordinates used to perform that live lookup are the ones specified in the ownerReference of the child.

In order to performantly delete multiple children from the same parent (e.g. 1000 pods from a replicaset),
a 404 response to a lookup is cached in absentOwnerCache.

Previously, the cache was a simple uid set. However, since children can disagree on the coordinates
that should be used to look up a given uid, the cache should record the exact coordinates verified absent.
This is a [apiVersion, kind, namespace, name, uid] tuple.
This commit is contained in:
Jordan Liggitt
2020-06-26 20:48:21 -04:00
parent 14f7f3201f
commit 445f20dbdb
6 changed files with 61 additions and 24 deletions

View File

@@ -20,33 +20,32 @@ import (
"sync"
"github.com/golang/groupcache/lru"
"k8s.io/apimachinery/pkg/types"
)
// UIDCache is an LRU cache for uid.
type UIDCache struct {
// ReferenceCache is an LRU cache for uid.
type ReferenceCache struct {
mutex sync.Mutex
cache *lru.Cache
}
// NewUIDCache returns a UIDCache.
func NewUIDCache(maxCacheEntries int) *UIDCache {
return &UIDCache{
// NewReferenceCache returns a ReferenceCache.
func NewReferenceCache(maxCacheEntries int) *ReferenceCache {
return &ReferenceCache{
cache: lru.New(maxCacheEntries),
}
}
// Add adds a uid to the cache.
func (c *UIDCache) Add(uid types.UID) {
func (c *ReferenceCache) Add(reference objectReference) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.cache.Add(uid, nil)
c.cache.Add(reference, nil)
}
// Has returns if a uid is in the cache.
func (c *UIDCache) Has(uid types.UID) bool {
func (c *ReferenceCache) Has(reference objectReference) bool {
c.mutex.Lock()
defer c.mutex.Unlock()
_, found := c.cache.Get(uid)
_, found := c.cache.Get(reference)
return found
}