Documentation
¶
Overview ¶
Package retryutils defines common retry and jitter logic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PermanentRetryError ¶
PermanentRetryError returns a new instance of a permanent retry error.
Types ¶
type Jitter ¶
Jitter is a function which applies random jitter to a duration. Used to randomize backoff values. Must be safe for concurrent usage.
func NewFullJitter ¶
func NewFullJitter() Jitter
NewFullJitter builds a new jitter on the range [0,d). Most use-cases are better served by a jitter with a meaningful minimum value, but if the *only* purpose of the jitter is to spread out retries to the greatest extent possible (e.g. when retrying a CompareAndSwap operation), a full jitter may be appropriate.
func NewHalfJitter ¶
func NewHalfJitter() Jitter
NewHalfJitter returns a new jitter on the range [d/2,d). This is a large range and most suitable for jittering things like backoff operations where breaking cycles quickly is a priority.
func NewJitter ¶
func NewJitter() Jitter
NewJitter builds a new default jitter (currently jitters on the range [d/2,d), but this is subject to change).
func NewSeventhJitter ¶
func NewSeventhJitter() Jitter
NewSeventhJitter builds a new jitter on the range [6d/7,d). Prefer smaller jitters such as this when jittering periodic operations (e.g. cert rotation checks) since large jitters result in significantly increased load.
func NewShardedFullJitter ¶
func NewShardedFullJitter() Jitter
NewShardedFullJitter is equivalent to NewFullJitter except that it performs better under high concurrency at the cost of having a larger footprint in memory.
func NewShardedHalfJitter ¶
func NewShardedHalfJitter() Jitter
NewShardedHalfJitter is equivalent to NewHalfJitter except that it performs better under high concurrency at the cost of having a larger footprint in memory.
func NewShardedSeventhJitter ¶
func NewShardedSeventhJitter() Jitter
NewShardedSeventhJitter is equivalent to NewSeventhJitter except that it performs better under high concurrency at the cost of having a larger footprint in memory.
type Linear ¶
type Linear struct { // LinearConfig is a linear retry config LinearConfig // contains filtered or unexported fields }
Linear is used to calculate retry period that follows the following logic: On the first error there is no delay on the next error, delay is FastLinear on all other errors, delay is SlowLinear
func NewConstant ¶
NewConstant returns a new linear retry with constant interval.
func NewLinear ¶
func NewLinear(cfg LinearConfig) (*Linear, error)
NewLinear returns a new instance of linear retry
func (*Linear) After ¶
After returns channel that fires with timeout defined in Duration method, as a special case if Duration is 0 returns a closed channel
func (*Linear) ResetToDelay ¶
func (r *Linear) ResetToDelay()
ResetToDelay resets retry period and increments the number of attempts.
type LinearConfig ¶
type LinearConfig struct { // First is a first element of the progression, // could be 0 First time.Duration // Step is a step of the progression, can't be 0 Step time.Duration // Max is a maximum value of the progression, // can't be 0 Max time.Duration // Jitter is an optional jitter function to be applied // to the delay. Note that supplying a jitter means that // successive calls to Duration may return different results. Jitter Jitter `json:"-"` // AutoReset, if greater than zero, causes the linear retry to automatically // reset after Max * AutoReset has elapsed since the last call to Incr. AutoReset int64 // Clock to override clock in tests Clock clockwork.Clock }
LinearConfig sets up retry configuration using arithmetic progression
func (*LinearConfig) CheckAndSetDefaults ¶
func (c *LinearConfig) CheckAndSetDefaults() error
CheckAndSetDefaults checks and sets defaults
type Retry ¶
type Retry interface { // Reset resets retry state Reset() // Inc increments retry attempt Inc() // Duration returns retry duration, // could be 0 Duration() time.Duration // After returns time.Time channel // that fires after Duration delay, // could fire right away if Duration is 0 After() <-chan time.Time // Clone creates a copy of this retry in a // reset state. Clone() Retry }
Retry is an interface that provides retry logic