Unverified Commit db1ab237 authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #76252 from goodluckbot/pod-backoff-rwmutex

Change Mutex to RWMutex for pod backoff
parents fbc28fd1 b92b0eb7
......@@ -26,7 +26,7 @@ import (
// PodBackoffMap is a structure that stores backoff related information for pods
type PodBackoffMap struct {
// lock for performing actions on this PodBackoffMap
lock sync.Mutex
lock sync.RWMutex
// initial backoff duration
initialDuration time.Duration
// maximal backoff duration
......@@ -49,8 +49,8 @@ func NewPodBackoffMap(initialDuration, maxDuration time.Duration) *PodBackoffMap
// GetBackoffTime returns the time that nsPod completes backoff
func (pbm *PodBackoffMap) GetBackoffTime(nsPod ktypes.NamespacedName) (time.Time, bool) {
pbm.lock.Lock()
defer pbm.lock.Unlock()
pbm.lock.RLock()
defer pbm.lock.RUnlock()
if _, found := pbm.podAttempts[nsPod]; found == 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.
// it is invoked from factory.go if util.PodPriorityEnabled() returns false.
func (pbm *PodBackoffMap) TryBackoffAndWait(nsPod ktypes.NamespacedName, stop <-chan struct{}) bool {
pbm.lock.Lock()
defer pbm.lock.Unlock()
pbm.lock.RLock()
defer pbm.lock.RUnlock()
backoffDuration := pbm.calculateBackoffDuration(nsPod)
select {
case <-time.After(backoffDuration):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment