From 92851d213ab0e665c09b152dd37dc86c80e08ae7 Mon Sep 17 00:00:00 2001 From: caiweidong Date: Tue, 13 Aug 2019 13:09:21 +0800 Subject: [PATCH] Use RWMutex in watchBasedManager --- pkg/kubelet/util/manager/watch_based_manager.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/util/manager/watch_based_manager.go b/pkg/kubelet/util/manager/watch_based_manager.go index 39768371b92..952326348f0 100644 --- a/pkg/kubelet/util/manager/watch_based_manager.go +++ b/pkg/kubelet/util/manager/watch_based_manager.go @@ -61,7 +61,7 @@ type objectCache struct { newObject newObjectFunc groupResource schema.GroupResource - lock sync.Mutex + lock sync.RWMutex items map[objectKey]*objectCacheItem } @@ -117,7 +117,7 @@ func (c *objectCache) AddReference(namespace, name string) { key := objectKey{namespace: namespace, name: name} // 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. // It's responsibility of the first Get operation to wait until the // 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) { key := objectKey{namespace: namespace, name: name} - c.lock.Lock() + c.lock.RLock() item, exists := c.items[key] - c.lock.Unlock() + c.lock.RUnlock() if !exists { return nil, fmt.Errorf("object %q/%q not registered", namespace, name)