mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #81332 from cwdsuzhou/Aug/rwmutex_watchbaseManager
Use RWMutex in watchBasedManager
This commit is contained in:
commit
78a73e71a3
@ -61,7 +61,7 @@ type objectCache struct {
|
|||||||
newObject newObjectFunc
|
newObject newObjectFunc
|
||||||
groupResource schema.GroupResource
|
groupResource schema.GroupResource
|
||||||
|
|
||||||
lock sync.Mutex
|
lock sync.RWMutex
|
||||||
items map[objectKey]*objectCacheItem
|
items map[objectKey]*objectCacheItem
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ func (c *objectCache) AddReference(namespace, name string) {
|
|||||||
key := objectKey{namespace: namespace, name: name}
|
key := objectKey{namespace: namespace, name: name}
|
||||||
|
|
||||||
// AddReference is called from RegisterPod thus it needs to be efficient.
|
// AddReference is called from RegisterPod thus it needs to be efficient.
|
||||||
// Thus, it is only increaisng refCount and in case of first registration
|
// Thus, it is only increasing refCount and in case of first registration
|
||||||
// of a given object it starts corresponding reflector.
|
// of a given object it starts corresponding reflector.
|
||||||
// It's responsibility of the first Get operation to wait until the
|
// It's responsibility of the first Get operation to wait until the
|
||||||
// reflector propagated the store.
|
// reflector propagated the store.
|
||||||
@ -158,9 +158,9 @@ func (c *objectCache) key(namespace, name string) string {
|
|||||||
func (c *objectCache) Get(namespace, name string) (runtime.Object, error) {
|
func (c *objectCache) Get(namespace, name string) (runtime.Object, error) {
|
||||||
key := objectKey{namespace: namespace, name: name}
|
key := objectKey{namespace: namespace, name: name}
|
||||||
|
|
||||||
c.lock.Lock()
|
c.lock.RLock()
|
||||||
item, exists := c.items[key]
|
item, exists := c.items[key]
|
||||||
c.lock.Unlock()
|
c.lock.RUnlock()
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, fmt.Errorf("object %q/%q not registered", namespace, name)
|
return nil, fmt.Errorf("object %q/%q not registered", namespace, name)
|
||||||
|
Loading…
Reference in New Issue
Block a user