mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Use rwlock for caches
This commit is contained in:
parent
ce2dfac296
commit
8fcbcafc11
@ -83,7 +83,8 @@ func (e *errObjectName) Error() string {
|
|||||||
// Restore() sets the latest object pointer back to the informer object.
|
// Restore() sets the latest object pointer back to the informer object.
|
||||||
// Get/List() always returns the latest object pointer.
|
// Get/List() always returns the latest object pointer.
|
||||||
type assumeCache struct {
|
type assumeCache struct {
|
||||||
mutex sync.Mutex
|
// Synchronizes updates to store
|
||||||
|
rwMutex sync.RWMutex
|
||||||
|
|
||||||
// describes the object stored
|
// describes the object stored
|
||||||
description string
|
description string
|
||||||
@ -155,8 +156,8 @@ func (c *assumeCache) add(obj interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.mutex.Lock()
|
c.rwMutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.Unlock()
|
||||||
|
|
||||||
if objInfo, _ := c.getObjInfo(name); objInfo != nil {
|
if objInfo, _ := c.getObjInfo(name); objInfo != nil {
|
||||||
newVersion, err := c.getObjVersion(name, obj)
|
newVersion, err := c.getObjVersion(name, obj)
|
||||||
@ -199,8 +200,8 @@ func (c *assumeCache) delete(obj interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.mutex.Lock()
|
c.rwMutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.Unlock()
|
||||||
|
|
||||||
objInfo := &objInfo{name: name}
|
objInfo := &objInfo{name: name}
|
||||||
err = c.store.Delete(objInfo)
|
err = c.store.Delete(objInfo)
|
||||||
@ -239,8 +240,8 @@ func (c *assumeCache) getObjInfo(name string) (*objInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *assumeCache) Get(objName string) (interface{}, error) {
|
func (c *assumeCache) Get(objName string) (interface{}, error) {
|
||||||
c.mutex.Lock()
|
c.rwMutex.RLock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.RUnlock()
|
||||||
|
|
||||||
objInfo, err := c.getObjInfo(objName)
|
objInfo, err := c.getObjInfo(objName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -250,8 +251,8 @@ func (c *assumeCache) Get(objName string) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *assumeCache) List(indexObj interface{}) []interface{} {
|
func (c *assumeCache) List(indexObj interface{}) []interface{} {
|
||||||
c.mutex.Lock()
|
c.rwMutex.RLock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.RUnlock()
|
||||||
|
|
||||||
allObjs := []interface{}{}
|
allObjs := []interface{}{}
|
||||||
objs, err := c.store.Index(c.indexName, &objInfo{latestObj: indexObj})
|
objs, err := c.store.Index(c.indexName, &objInfo{latestObj: indexObj})
|
||||||
@ -277,8 +278,8 @@ func (c *assumeCache) Assume(obj interface{}) error {
|
|||||||
return &errObjectName{err}
|
return &errObjectName{err}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.mutex.Lock()
|
c.rwMutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.Unlock()
|
||||||
|
|
||||||
objInfo, err := c.getObjInfo(name)
|
objInfo, err := c.getObjInfo(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -306,8 +307,8 @@ func (c *assumeCache) Assume(obj interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *assumeCache) Restore(objName string) {
|
func (c *assumeCache) Restore(objName string) {
|
||||||
c.mutex.Lock()
|
c.rwMutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.Unlock()
|
||||||
|
|
||||||
objInfo, err := c.getObjInfo(objName)
|
objInfo, err := c.getObjInfo(objName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +50,8 @@ type PodBindingCache interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type podBindingCache struct {
|
type podBindingCache struct {
|
||||||
mutex sync.Mutex
|
// synchronizes bindingDecisions
|
||||||
|
rwMutex sync.RWMutex
|
||||||
|
|
||||||
// Key = pod name
|
// Key = pod name
|
||||||
// Value = nodeDecisions
|
// Value = nodeDecisions
|
||||||
@ -72,16 +73,16 @@ func NewPodBindingCache() PodBindingCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *podBindingCache) DeleteBindings(pod *v1.Pod) {
|
func (c *podBindingCache) DeleteBindings(pod *v1.Pod) {
|
||||||
c.mutex.Lock()
|
c.rwMutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.Unlock()
|
||||||
|
|
||||||
podName := getPodName(pod)
|
podName := getPodName(pod)
|
||||||
delete(c.bindingDecisions, podName)
|
delete(c.bindingDecisions, podName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *podBindingCache) UpdateBindings(pod *v1.Pod, node string, bindings []*bindingInfo) {
|
func (c *podBindingCache) UpdateBindings(pod *v1.Pod, node string, bindings []*bindingInfo) {
|
||||||
c.mutex.Lock()
|
c.rwMutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.Unlock()
|
||||||
|
|
||||||
podName := getPodName(pod)
|
podName := getPodName(pod)
|
||||||
decisions, ok := c.bindingDecisions[podName]
|
decisions, ok := c.bindingDecisions[podName]
|
||||||
@ -101,8 +102,8 @@ func (c *podBindingCache) UpdateBindings(pod *v1.Pod, node string, bindings []*b
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *podBindingCache) GetBindings(pod *v1.Pod, node string) []*bindingInfo {
|
func (c *podBindingCache) GetBindings(pod *v1.Pod, node string) []*bindingInfo {
|
||||||
c.mutex.Lock()
|
c.rwMutex.RLock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.RUnlock()
|
||||||
|
|
||||||
podName := getPodName(pod)
|
podName := getPodName(pod)
|
||||||
decisions, ok := c.bindingDecisions[podName]
|
decisions, ok := c.bindingDecisions[podName]
|
||||||
@ -117,8 +118,8 @@ func (c *podBindingCache) GetBindings(pod *v1.Pod, node string) []*bindingInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *podBindingCache) UpdateProvisionedPVCs(pod *v1.Pod, node string, pvcs []*v1.PersistentVolumeClaim) {
|
func (c *podBindingCache) UpdateProvisionedPVCs(pod *v1.Pod, node string, pvcs []*v1.PersistentVolumeClaim) {
|
||||||
c.mutex.Lock()
|
c.rwMutex.Lock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.Unlock()
|
||||||
|
|
||||||
podName := getPodName(pod)
|
podName := getPodName(pod)
|
||||||
decisions, ok := c.bindingDecisions[podName]
|
decisions, ok := c.bindingDecisions[podName]
|
||||||
@ -138,8 +139,8 @@ func (c *podBindingCache) UpdateProvisionedPVCs(pod *v1.Pod, node string, pvcs [
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *podBindingCache) GetProvisionedPVCs(pod *v1.Pod, node string) []*v1.PersistentVolumeClaim {
|
func (c *podBindingCache) GetProvisionedPVCs(pod *v1.Pod, node string) []*v1.PersistentVolumeClaim {
|
||||||
c.mutex.Lock()
|
c.rwMutex.RLock()
|
||||||
defer c.mutex.Unlock()
|
defer c.rwMutex.RUnlock()
|
||||||
|
|
||||||
podName := getPodName(pod)
|
podName := getPodName(pod)
|
||||||
decisions, ok := c.bindingDecisions[podName]
|
decisions, ok := c.bindingDecisions[podName]
|
||||||
|
Loading…
Reference in New Issue
Block a user