Documentation ¶
Index ¶
- Constants
- Variables
- type BackoffFnCfg
- type Backoffer
- func (b *Backoffer) Backoff(cfg *Config, err error) error
- func (b *Backoffer) BackoffWithCfgAndMaxSleep(cfg *Config, maxSleepMs int, err error) error
- func (b *Backoffer) BackoffWithMaxSleepTxnLockFast(maxSleepMs int, err error) error
- func (b *Backoffer) Clone() *Backoffer
- func (b *Backoffer) ErrorsNum() int
- func (b *Backoffer) Fork() (*Backoffer, context.CancelFunc)
- func (b *Backoffer) GetBackoffSleepMS() map[string]int
- func (b *Backoffer) GetBackoffTimes() map[string]int
- func (b *Backoffer) GetCtx() context.Context
- func (b *Backoffer) GetTotalBackoffTimes() int
- func (b *Backoffer) GetTotalSleep() int
- func (b *Backoffer) GetTypes() []string
- func (b *Backoffer) GetVars() *kv.Variables
- func (b *Backoffer) Reset()
- func (b *Backoffer) ResetMaxSleep(maxSleep int)
- func (b *Backoffer) SetCtx(ctx context.Context)
- func (b *Backoffer) String() string
- type Config
Constants ¶
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 ¶
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.
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 ¶
NewBackoffer (Deprecated) creates a Backoffer with maximum sleep time(in ms).
func NewBackofferWithVars ¶
NewBackofferWithVars creates a Backoffer with maximum sleep time(in ms) and kv.Variables.
func NewNoopBackoff ¶
NewNoopBackoff create a Backoffer do nothing just return error directly
func (*Backoffer) Backoff ¶
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 ¶
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 ¶
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 ¶
Clone creates a new Backoffer which keeps current Backoffer's sleep time and errors, and shares current Backoffer's context.
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 ¶
GetBackoffSleepMS returns a map contains backoff sleep time by type.
func (*Backoffer) GetBackoffTimes ¶
GetBackoffTimes returns a map contains backoff time count by type.
func (*Backoffer) GetTotalBackoffTimes ¶
GetTotalBackoffTimes returns the total backoff times of the backoffer.
func (*Backoffer) GetTotalSleep ¶
GetTotalSleep returns total sleep time.
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 ¶
ResetMaxSleep resets the sleep state and max sleep limit of the backoffer. It's used when switches to the next stage of the process.
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.