mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-28 07:57:20 +00:00
Utilize RWMutex for efficient backoff operations
Kubernetes-commit: 9e73e69f4947c88e0d9b6e35ea115086d917a2a2
This commit is contained in:
parent
c597d11714
commit
e12fc43899
@ -30,7 +30,7 @@ type backoffEntry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Backoff struct {
|
type Backoff struct {
|
||||||
sync.Mutex
|
sync.RWMutex
|
||||||
Clock clock.Clock
|
Clock clock.Clock
|
||||||
defaultDuration time.Duration
|
defaultDuration time.Duration
|
||||||
maxDuration time.Duration
|
maxDuration time.Duration
|
||||||
@ -57,8 +57,8 @@ func NewBackOff(initial, max time.Duration) *Backoff {
|
|||||||
|
|
||||||
// Get the current backoff Duration
|
// Get the current backoff Duration
|
||||||
func (p *Backoff) Get(id string) time.Duration {
|
func (p *Backoff) Get(id string) time.Duration {
|
||||||
p.Lock()
|
p.RLock()
|
||||||
defer p.Unlock()
|
defer p.RUnlock()
|
||||||
var delay time.Duration
|
var delay time.Duration
|
||||||
entry, ok := p.perItemBackoff[id]
|
entry, ok := p.perItemBackoff[id]
|
||||||
if ok {
|
if ok {
|
||||||
@ -90,8 +90,8 @@ func (p *Backoff) Reset(id string) {
|
|||||||
|
|
||||||
// Returns True if the elapsed time since eventTime is smaller than the current backoff window
|
// Returns True if the elapsed time since eventTime is smaller than the current backoff window
|
||||||
func (p *Backoff) IsInBackOffSince(id string, eventTime time.Time) bool {
|
func (p *Backoff) IsInBackOffSince(id string, eventTime time.Time) bool {
|
||||||
p.Lock()
|
p.RLock()
|
||||||
defer p.Unlock()
|
defer p.RUnlock()
|
||||||
entry, ok := p.perItemBackoff[id]
|
entry, ok := p.perItemBackoff[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
@ -104,8 +104,8 @@ func (p *Backoff) IsInBackOffSince(id string, eventTime time.Time) bool {
|
|||||||
|
|
||||||
// Returns True if time since lastupdate is less than the current backoff window.
|
// Returns True if time since lastupdate is less than the current backoff window.
|
||||||
func (p *Backoff) IsInBackOffSinceUpdate(id string, eventTime time.Time) bool {
|
func (p *Backoff) IsInBackOffSinceUpdate(id string, eventTime time.Time) bool {
|
||||||
p.Lock()
|
p.RLock()
|
||||||
defer p.Unlock()
|
defer p.RUnlock()
|
||||||
entry, ok := p.perItemBackoff[id]
|
entry, ok := p.perItemBackoff[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user