Change Mutex to RWMutex for pod backoff
This commit is contained in:
		@@ -26,7 +26,7 @@ import (
 | 
				
			|||||||
// PodBackoffMap is a structure that stores backoff related information for pods
 | 
					// PodBackoffMap is a structure that stores backoff related information for pods
 | 
				
			||||||
type PodBackoffMap struct {
 | 
					type PodBackoffMap struct {
 | 
				
			||||||
	// lock for performing actions on this PodBackoffMap
 | 
						// lock for performing actions on this PodBackoffMap
 | 
				
			||||||
	lock sync.Mutex
 | 
						lock sync.RWMutex
 | 
				
			||||||
	// initial backoff duration
 | 
						// initial backoff duration
 | 
				
			||||||
	initialDuration time.Duration
 | 
						initialDuration time.Duration
 | 
				
			||||||
	// maximal backoff duration
 | 
						// maximal backoff duration
 | 
				
			||||||
@@ -49,8 +49,8 @@ func NewPodBackoffMap(initialDuration, maxDuration time.Duration) *PodBackoffMap
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// GetBackoffTime returns the time that nsPod completes backoff
 | 
					// GetBackoffTime returns the time that nsPod completes backoff
 | 
				
			||||||
func (pbm *PodBackoffMap) GetBackoffTime(nsPod ktypes.NamespacedName) (time.Time, bool) {
 | 
					func (pbm *PodBackoffMap) GetBackoffTime(nsPod ktypes.NamespacedName) (time.Time, bool) {
 | 
				
			||||||
	pbm.lock.Lock()
 | 
						pbm.lock.RLock()
 | 
				
			||||||
	defer pbm.lock.Unlock()
 | 
						defer pbm.lock.RUnlock()
 | 
				
			||||||
	if _, found := pbm.podAttempts[nsPod]; found == false {
 | 
						if _, found := pbm.podAttempts[nsPod]; found == false {
 | 
				
			||||||
		return time.Time{}, false
 | 
							return time.Time{}, false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -63,8 +63,8 @@ func (pbm *PodBackoffMap) GetBackoffTime(nsPod ktypes.NamespacedName) (time.Time
 | 
				
			|||||||
// TryBackoffAndWait tries to perform backoff for a non-preempting pod.
 | 
					// TryBackoffAndWait tries to perform backoff for a non-preempting pod.
 | 
				
			||||||
// it is invoked from factory.go if util.PodPriorityEnabled() returns false.
 | 
					// it is invoked from factory.go if util.PodPriorityEnabled() returns false.
 | 
				
			||||||
func (pbm *PodBackoffMap) TryBackoffAndWait(nsPod ktypes.NamespacedName, stop <-chan struct{}) bool {
 | 
					func (pbm *PodBackoffMap) TryBackoffAndWait(nsPod ktypes.NamespacedName, stop <-chan struct{}) bool {
 | 
				
			||||||
	pbm.lock.Lock()
 | 
						pbm.lock.RLock()
 | 
				
			||||||
	defer pbm.lock.Unlock()
 | 
						defer pbm.lock.RUnlock()
 | 
				
			||||||
	backoffDuration := pbm.calculateBackoffDuration(nsPod)
 | 
						backoffDuration := pbm.calculateBackoffDuration(nsPod)
 | 
				
			||||||
	select {
 | 
						select {
 | 
				
			||||||
	case <-time.After(backoffDuration):
 | 
						case <-time.After(backoffDuration):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user