backoff

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package backoff implements different backoff strategies for retrying failed operations in VTAdmin.

It is first a reimplementation of grpc-go's internal exponential backoff strategy, with one modification to prevent a jittered backoff from exceeding the MaxDelay specified in a config.

Then, for other use-cases, it implements a linear backoff strategy, as well as a "none" strategy which is primarly intended for use in tests.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultExponential = Exponential{grpcbackoff.DefaultConfig}
	DefaultLinear      = Linear{grpcbackoff.DefaultConfig}
	DefaultNone        = None{}
)

Functions

This section is empty.

Types

type Exponential

type Exponential struct {
	Config grpcbackoff.Config
}

Exponential implements an exponential backoff strategy with optional jitter.

func (Exponential) Backoff

func (e Exponential) Backoff(retries int) time.Duration

Backoff is part of the Strategy interface.

type Linear

type Linear struct {
	Config grpcbackoff.Config
}

Linear implements a linear backoff strategy with optional jitter.

func (Linear) Backoff

func (l Linear) Backoff(retries int) time.Duration

Backoff is part of the Strategy interface.

type None

type None struct{}

None implements a "backoff" strategy that can be summarized as "don't".

func (None) Backoff

func (None) Backoff(int) time.Duration

Backoff is part of the Strategy interface.

type Strategy

type Strategy interface {
	// Backoff returns the amount of time to backoff for the given retry count.
	Backoff(retries int) time.Duration
}

Strategy defines the interface for different backoff strategies.

func Get

func Get(strategy string, cfg grpcbackoff.Config) Strategy

Get returns a backoff Strategy for the specified strategy name, with the given config. Strategy lookup is case-insensitive, and the empty string defaults to an exponential strategy. It panics if an unsupported strategy name is specified.

Currently-supported strategies are "exponential", "linear", and "none".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL