Merge pull request #81332 from cwdsuzhou/Aug/rwmutex_watchbaseManager

Use RWMutex in watchBasedManager
This commit is contained in:
Kubernetes Prow Robot 2019-08-15 16:18:35 -07:00 committed by GitHub
commit 78a73e71a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)