From 39b20436b3e4f02a33f2811f3d7f7ea20f25534d Mon Sep 17 00:00:00 2001 From: husharp Date: Tue, 29 Aug 2023 16:01:12 +0800 Subject: [PATCH] rename backoff Signed-off-by: husharp --- client/retry/backoff.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/client/retry/backoff.go b/client/retry/backoff.go index 6d234a8df45c..b152cb48edc5 100644 --- a/client/retry/backoff.go +++ b/client/retry/backoff.go @@ -23,9 +23,9 @@ import ( // BackOffer is a backoff policy for retrying operations. type BackOffer struct { - maxBackoff time.Duration - nextBackoff time.Duration - initialBackoff time.Duration + max time.Duration + next time.Duration + base time.Duration } // WithBackoff is a helper function to add backoff. @@ -50,11 +50,11 @@ func WithBackoff( } // InitialBackOffer make the initial state for retrying. -func InitialBackOffer(initialBackoff, maxBackoff time.Duration) BackOffer { +func InitialBackOffer(base, max time.Duration) BackOffer { return BackOffer{ - maxBackoff: maxBackoff, - initialBackoff: initialBackoff, - nextBackoff: initialBackoff, + max: max, + base: base, + next: base, } } @@ -63,19 +63,19 @@ func (rs *BackOffer) NextBackoff() time.Duration { return rs.exponentialBackoff() } -// exponentialBackoff Get the exponential backoff duration. +// exponentialBackoff returns the exponential backoff duration. func (rs *BackOffer) exponentialBackoff() time.Duration { - backoff := rs.nextBackoff - rs.nextBackoff *= 2 - if rs.nextBackoff > rs.maxBackoff { - rs.nextBackoff = rs.maxBackoff + backoffInterval := rs.next + rs.next *= 2 + if rs.next > rs.max { + rs.next = rs.max } - return backoff + return backoffInterval } -// ResetBackoff reset the backoff to initial state. +// ResetBackoff resets the backoff to initial state. func (rs *BackOffer) ResetBackoff() { - rs.nextBackoff = rs.initialBackoff + rs.next = rs.base } // Only used for test.