retry

package
v2.5.4 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoJitter makes the backoff sequence strict exponential.
	NoJitter = 1 + iota
	// FullJitter applies random factors to strict exponential.
	FullJitter
	// EqualJitter is also randomized, but prevents very short sleeps.
	EqualJitter
	// DecorrJitter increases the maximum jitter based on the last random value.
	DecorrJitter
)

Variables

View Source
var (
	// TODO: distinguish tikv and tiflash in metrics
	BoTiKVRPC    = NewConfig("tikvRPC", &metrics.BackoffHistogramRPC, NewBackoffFnCfg(100, 2000, EqualJitter), tikverr.ErrTiKVServerTimeout)
	BoTiFlashRPC = NewConfig("tiflashRPC", &metrics.BackoffHistogramRPC, NewBackoffFnCfg(100, 2000, EqualJitter), tikverr.ErrTiFlashServerTimeout)
	BoTxnLock    = NewConfig("txnLock", &metrics.BackoffHistogramLock, NewBackoffFnCfg(200, 3000, EqualJitter), tikverr.ErrResolveLockTimeout)
	BoPDRPC      = NewConfig("pdRPC", &metrics.BackoffHistogramPD, NewBackoffFnCfg(500, 3000, EqualJitter), tikverr.NewErrPDServerTimeout(""))
	// change base time to 2ms, because it may recover soon.
	BoRegionMiss              = NewConfig("regionMiss", &metrics.BackoffHistogramRegionMiss, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrRegionUnavailable)
	BoRegionScheduling        = NewConfig("regionScheduling", &metrics.BackoffHistogramRegionScheduling, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrRegionUnavailable)
	BoTiKVServerBusy          = NewConfig("tikvServerBusy", &metrics.BackoffHistogramServerBusy, NewBackoffFnCfg(2000, 10000, EqualJitter), tikverr.ErrTiKVServerBusy)
	BoTiKVDiskFull            = NewConfig("tikvDiskFull", &metrics.BackoffHistogramTiKVDiskFull, NewBackoffFnCfg(500, 5000, NoJitter), tikverr.ErrTiKVDiskFull)
	BoTiFlashServerBusy       = NewConfig("tiflashServerBusy", &metrics.BackoffHistogramServerBusy, NewBackoffFnCfg(2000, 10000, EqualJitter), tikverr.ErrTiFlashServerBusy)
	BoTxnNotFound             = NewConfig("txnNotFound", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrResolveLockTimeout)
	BoStaleCmd                = NewConfig("staleCommand", &metrics.BackoffHistogramStaleCmd, NewBackoffFnCfg(2, 1000, NoJitter), tikverr.ErrTiKVStaleCommand)
	BoMaxTsNotSynced          = NewConfig("maxTsNotSynced", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrTiKVMaxTimestampNotSynced)
	BoMaxDataNotReady         = NewConfig("dataNotReady", &metrics.BackoffHistogramDataNotReady, NewBackoffFnCfg(100, 2000, NoJitter), tikverr.ErrRegionDataNotReady)
	BoMaxRegionNotInitialized = NewConfig("regionNotInitialized", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 1000, NoJitter), tikverr.ErrRegionNotInitialized)
	// TxnLockFast's `base` load from vars.BackoffLockFast when create BackoffFn.
	BoTxnLockFast = NewConfig(txnLockFastName, &metrics.BackoffHistogramLockFast, NewBackoffFnCfg(2, 3000, EqualJitter), tikverr.ErrResolveLockTimeout)
)

Backoff Config variables.

View Source
var TxnStartKey interface{} = txnStartCtxKeyType{}

TxnStartKey is a key for transaction start_ts info in context.Context.

Functions

This section is empty.

Types

type BackoffFnCfg

type BackoffFnCfg struct {
	// contains filtered or unexported fields
}

BackoffFnCfg is the configuration for the backoff func which implements exponential backoff with optional jitters. See http://www.awsarchitectureblog.com/2015/03/backoff.html

func NewBackoffFnCfg

func NewBackoffFnCfg(base, cap, jitter int) *BackoffFnCfg

NewBackoffFnCfg creates the config for BackoffFn.

type Backoffer

type Backoffer struct {
	// contains filtered or unexported fields
}

Backoffer is a utility for retrying queries.

func NewBackoffer

func NewBackoffer(ctx context.Context, maxSleep int) *Backoffer

NewBackoffer (Deprecated) creates a Backoffer with maximum sleep time(in ms).

func NewBackofferWithVars

func NewBackofferWithVars(ctx context.Context, maxSleep int, vars *kv.Variables) *Backoffer

NewBackofferWithVars creates a Backoffer with maximum sleep time(in ms) and kv.Variables.

func NewNoopBackoff

func NewNoopBackoff(ctx context.Context) *Backoffer

NewNoopBackoff create a Backoffer do nothing just return error directly

func (*Backoffer) Backoff

func (b *Backoffer) Backoff(cfg *Config, err error) error

Backoff sleeps a while base on the Config and records the error message. It returns a retryable error if total sleep time exceeds maxSleep.

func (*Backoffer) BackoffWithCfgAndMaxSleep

func (b *Backoffer) BackoffWithCfgAndMaxSleep(cfg *Config, maxSleepMs int, err error) error

BackoffWithCfgAndMaxSleep sleeps a while base on the Config and records the error message and never sleep more than maxSleepMs for each sleep.

func (*Backoffer) BackoffWithMaxSleepTxnLockFast

func (b *Backoffer) BackoffWithMaxSleepTxnLockFast(maxSleepMs int, err error) error

BackoffWithMaxSleepTxnLockFast sleeps a while base on the MaxSleepTxnLock and records the error message and never sleep more than maxSleepMs for each sleep.

func (*Backoffer) Clone

func (b *Backoffer) Clone() *Backoffer

Clone creates a new Backoffer which keeps current Backoffer's sleep time and errors, and shares current Backoffer's context.

func (*Backoffer) ErrorsNum

func (b *Backoffer) ErrorsNum() int

ErrorsNum returns the number of errors.

func (*Backoffer) Fork

func (b *Backoffer) Fork() (*Backoffer, context.CancelFunc)

Fork creates a new Backoffer which keeps current Backoffer's sleep time and errors, and holds a child context of current Backoffer's context.

func (*Backoffer) GetBackoffSleepMS

func (b *Backoffer) GetBackoffSleepMS() map[string]int

GetBackoffSleepMS returns a map contains backoff sleep time by type.

func (*Backoffer) GetBackoffTimes

func (b *Backoffer) GetBackoffTimes() map[string]int

GetBackoffTimes returns a map contains backoff time count by type.

func (*Backoffer) GetCtx

func (b *Backoffer) GetCtx() context.Context

GetCtx returns the binded context.

func (*Backoffer) GetTotalBackoffTimes

func (b *Backoffer) GetTotalBackoffTimes() int

GetTotalBackoffTimes returns the total backoff times of the backoffer.

func (*Backoffer) GetTotalSleep

func (b *Backoffer) GetTotalSleep() int

GetTotalSleep returns total sleep time.

func (*Backoffer) GetTypes

func (b *Backoffer) GetTypes() []string

GetTypes returns type list of this backoff and all its ancestors.

func (*Backoffer) GetVars

func (b *Backoffer) GetVars() *kv.Variables

GetVars returns the binded vars.

func (*Backoffer) Reset

func (b *Backoffer) Reset()

Reset resets the sleep state of the backoffer, so that following backoff can sleep shorter. The reason why we don't create a new backoffer is that backoffer is similar to context and it records some metrics that we want to record for an entire process which is composed of serveral stages.

func (*Backoffer) ResetMaxSleep

func (b *Backoffer) ResetMaxSleep(maxSleep int)

ResetMaxSleep resets the sleep state and max sleep limit of the backoffer. It's used when switches to the next stage of the process.

func (*Backoffer) SetCtx

func (b *Backoffer) SetCtx(ctx context.Context)

SetCtx sets the binded context to ctx.

func (*Backoffer) String

func (b *Backoffer) String() string

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config is the configuration of the Backoff function.

func NewConfig

func NewConfig(name string, metric *prometheus.Observer, backoffFnCfg *BackoffFnCfg, err error) *Config

NewConfig creates a new Config for the Backoff operation.

func (*Config) SetErrors

func (c *Config) SetErrors(err error)

SetErrors sets a more detailed error instead of the default bo config.

func (*Config) String

func (c *Config) String() string

Jump to

Keyboard shortcuts

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