model

package
v0.0.0-...-daf8b82 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TxnTypeSaga = "saga"
	TxnTypeTcc  = "tcc"

	BranchTypeCommit       = "commit"
	BranchTypeCompensation = "compensation"
	BranchTypeConfirm      = "confirm"
	BranchTypeCancel       = "cancel"

	TxnCallTypeSync  = "sync"
	TxnCallTypeAsync = "async"
)

Variables

View Source
var (
	ErrNotExist         = errors.New("not exist")
	ErrAlreadyExist     = errors.New("already exist")
	ErrIsNotPrepared    = errors.New("state of transaction is not prepared")
	ErrLeaseExpired     = errors.New("lease expired")
	ErrExpired          = errors.New("expired")
	ErrInvalidLessee    = errors.New("invalid lessee")
	ErrNotExpectedState = errors.New("state of transaction is not expected")
)

Functions

This section is empty.

Types

type Branch

type Branch struct {
	Id          int64
	Gtid        string
	Bid         int
	BranchType  string
	Action      string
	Payload     []byte
	Timeout     time.Duration
	Response    []byte
	Retry       RetryStrategy
	Lease       time.Time `gorm:"-"`
	TryCount    int
	State       string
	UpdatedTime time.Time
	CreatedTime time.Time
	// contains filtered or unexported fields
}

func (*Branch) BeginSave

func (s *Branch) BeginSave()

func (*Branch) CanTry

func (s *Branch) CanTry() bool

func (*Branch) EndSave

func (s *Branch) EndSave()

func (*Branch) IncrTryCount

func (s *Branch) IncrTryCount()

func (*Branch) RetryDuration

func (b *Branch) RetryDuration() time.Duration

func (*Branch) SetLease

func (s *Branch) SetLease(t time.Time)

func (*Branch) SetResponse

func (s *Branch) SetResponse(resp []byte)

func (*Branch) SetState

func (s *Branch) SetState(state string)

func (*Branch) TableName

func (*Branch) TableName() string

type ModelStorage

type ModelStorage interface {
	Timeout() time.Duration
	SetTimeout(t time.Duration)

	// query
	Exist(ctx context.Context, gtid string) error
	GetByGtid(ctx context.Context, gtid string) (*Txn, error)

	// update
	Save(ctx context.Context, t *Txn) error
	Update(ctx context.Context, t *Txn) error
	UpdateConditions(ctx context.Context, txn *Txn, cb func(oldTxn *Txn) error, returning bool) (*Txn, error)
	UpdateStateConditions(ctx context.Context, txn *Txn, cb func(oldTxn *Txn) error) (err error)
	GrantLease(ctx context.Context, txn *Txn, lease time.Duration) error
	GrantLeaseIncBranchCheckState(ctx context.Context, txn *Txn, branch *Branch,
		leaseDuration time.Duration, states []string) (err error)

	// branch
	UpdateBranch(ctx context.Context, b *Branch) error
	RegisterBranches(ctx context.Context, bs []*Branch) error

	// find expired transactions
	FindRunningLeaseExpired(ctx context.Context, txn string, limit int) ([]*Txn, error)
	FindPreparedExpired(ctx context.Context, txn string, limit int) ([]*Txn, error)
	CleanExpiredTxns(ctx context.Context, txn string, untileTime time.Time, limit int) ([]*Txn, error)
}

func NewModelStorage

func NewModelStorage(txnType string, driver string, dsn string,
	timeout time.Duration, maxConn int, MaxIdleConn int,
	lessee string) (ModelStorage, error)

func NewModelStorageMock

func NewModelStorageMock(lessee string) ModelStorage

type RetryConstant

type RetryConstant struct {
	Duration time.Duration
}

type RetryStrategy

type RetryStrategy struct {
	MaxRetry int
	Constant *RetryConstant
}

func (*RetryStrategy) Scan

func (rs *RetryStrategy) Scan(value interface{}) error

func (RetryStrategy) Value

func (rs RetryStrategy) Value() (driver.Value, error)

type Txn

type Txn struct {
	Id                int64
	Gtid              string
	Business          string
	State             string
	TxnType           string
	UpdatedTime       time.Time
	CreatedTime       time.Time
	ExpireTime        time.Time
	LeaseExpireTime   time.Time
	Lessee            string
	CallType          string
	NotifyAction      string
	NotifyTimeout     time.Duration
	NotifyRetry       time.Duration
	NotifyCount       int
	Branches          []*Branch `gorm:"-" json:"branches,omitempty"`
	ParallelExecution bool
	// contains filtered or unexported fields
}

func (*Txn) BeginSave

func (s *Txn) BeginSave()

func (*Txn) EndSave

func (s *Txn) EndSave()

func (*Txn) IncrNotify

func (s *Txn) IncrNotify()

func (*Txn) NeedNotify

func (s *Txn) NeedNotify() bool

func (*Txn) SetLeaseExpireTime

func (s *Txn) SetLeaseExpireTime(t time.Time)

func (*Txn) SetLessee

func (s *Txn) SetLessee(l string)

func (*Txn) SetState

func (s *Txn) SetState(state string)

func (*Txn) TableName

func (*Txn) TableName() string

type Txns

type Txns []*Txn

func (Txns) Len

func (ts Txns) Len() int

func (Txns) Less

func (ts Txns) Less(i, j int) bool

func (Txns) Swap

func (ts Txns) Swap(i, j int)

Jump to

Keyboard shortcuts

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