retry

package
v0.0.0-...-be15534 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Stable represents fixed time wait retry policy, every retry should wait a fixed time.
	Stable backoffStrategy = iota + 1
	// LinearIncrease represents increase time wait retry policy, every retry should wait more time depends on increasing retry times.
	LinearIncrease
)

Variables

View Source
var (
	// UnsupportedDDLMsgs list the error messages of some unsupported DDL in TiDB.
	UnsupportedDDLMsgs = []string{
		"can't drop column with index",
		"with tidb_enable_change_multi_schema is disable",
		"unsupported add column",
		"unsupported modify column",
		"unsupported modify charset",
		"unsupported modify collate",
		"unsupported drop integer primary key",
		"Unsupported collation",
		"Invalid default value for",
		"Unsupported drop primary key",
		"Error 1059",
		"Error 1117",
		"Error 1069",
	}

	// UnsupportedDMLMsgs list the error messages of some un-recoverable DML, which is used in task auto recovery.
	UnsupportedDMLMsgs = []string{
		"Error 1062",
		"Error 1406",
		"Error 1366",
		"Error 8025",
	}

	// ReplicationErrMsgs list the error message of un-recoverable replication error.
	ReplicationErrMsgs = []string{
		"Could not find first log file name in binary log index file",
		"The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires",
	}

	// ParseRelayLogErrMsgs list the error messages of some un-recoverable relay log parsing error, which is used in task auto recovery.
	ParseRelayLogErrMsgs = []string{
		"binlog checksum mismatch, data may be corrupted",
		"get event err EOF",
	}

	// UnresumableErrCodes is a set of unresumeable err codes.
	UnresumableErrCodes = map[int32]struct{}{
		int32(terror.ErrSyncUnitDDLWrongSequence.Code()):    {},
		int32(terror.ErrDumpUnitGlobalLock.Code()):          {},
		int32(terror.ErrDumpUnitRuntime.Code()):             {},
		int32(terror.ErrSyncerUnitDMLColumnNotMatch.Code()): {},
		int32(terror.ErrSyncerCancelledDDL.Code()):          {},
		int32(terror.ErrLoadLightningRuntime.Code()):        {},
		int32(terror.ErrLoadLightningHasDup.Code()):         {},
		int32(terror.ErrLoadLightningChecksum.Code()):       {},
	}

	// UnresumableRelayErrCodes is a set of unresumeable relay unit err codes.
	UnresumableRelayErrCodes = map[int32]struct{}{
		int32(terror.ErrRelayUUIDSuffixNotValid.Code()):     {},
		int32(terror.ErrRelayUUIDSuffixLessThanPrev.Code()): {},
		int32(terror.ErrRelayBinlogNameNotValid.Code()):     {},
		int32(terror.ErrRelayNoCurrentUUID.Code()):          {},
		int32(terror.ErrRelayLogDirpathEmpty.Code()):        {},
	}
)

some error reference: https://docs.pingcap.com/tidb/stable/tidb-limitations#limitations-on-a-single-table

Functions

func IsConnectionError

func IsConnectionError(err error) bool

IsConnectionError tells whether this error should reconnect to Database. Return true also means caller can retry sql safely.

func IsUnretryableConnectionError

func IsUnretryableConnectionError(err error) bool

IsUnretryableConnectionError checks whether it's an unretryable connection error or not.

Types

type FiniteRetryStrategy

type FiniteRetryStrategy struct{}

FiniteRetryStrategy will retry `RetryCount` times when failed to operate DB.

func (*FiniteRetryStrategy) Apply

func (*FiniteRetryStrategy) Apply(ctx *tcontext.Context, params Params, operateFn OperateFunc,
) (ret interface{}, i int, err error)

Apply for FiniteRetryStrategy, it waits `FirstRetryDuration` before it starts first retry, and then rest of retries wait time depends on BackoffStrategy.

type FiniteRetryer

type FiniteRetryer struct {
	FiniteRetryStrategy
	Params *Params
}

FiniteRetryer wraps params.

func (*FiniteRetryer) Apply

func (s *FiniteRetryer) Apply(ctx *tcontext.Context, operateFn OperateFunc) (ret interface{}, i int, err error)

type OperateFunc

type OperateFunc func(*tcontext.Context) (interface{}, error)

OperateFunc the function we can retry

return: (result of operation, error of operation)

type Params

type Params struct {
	RetryCount         int
	FirstRetryDuration time.Duration

	BackoffStrategy backoffStrategy

	// IsRetryableFn tells whether we should retry when operateFn failed
	// params: (number of retry, error of operation)
	// return: (bool)
	//   1. true: means operateFn can be retried
	//   2. false: means operateFn cannot retry after receive this error
	IsRetryableFn func(int, error) bool
}

Params define parameters for Apply it's a parameters union set of all implements which implement Apply.

func NewParams

func NewParams(retryCount int, firstRetryDuration time.Duration, backoffStrategy backoffStrategy,
	isRetryableFn func(int, error) bool,
) *Params

type Retryer

type Retryer interface {
	Apply(ctx *tcontext.Context, operateFn OperateFunc) (interface{}, int, error)
}

Retryer retries operateFn until success or reaches retry limit todo: merge with Strategy when refactor

type Strategy

type Strategy interface {
	// Apply define retry strategy
	// params: (retry parameters for this strategy, a normal operation)
	// return: (result of operation, number of retry, error of operation)
	Apply(ctx *tcontext.Context,
		params Params,
		operateFn OperateFunc,
	) (interface{}, int, error)
}

Strategy define different kind of retry strategy.

Jump to

Keyboard shortcuts

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