tx

package
v0.0.0-...-28b0f05 Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReadyTx

type ReadyTx interface {
	Start() error
	ExecSubTx(subTxID string, args ...interface{}) error
	ExecSubTxAndGetResult(subTxID string, args ...interface{}) ([]reflect.Value, error)
	End() error
	SetLogger(l trace.Logger)
	SetContext(ctx context.Context)
	RollbackWithInfiniteTries()
	Rollback(tryCount int) error
	IsTxIDAlreadyInUse() (bool, error)
}

ReadyTx is the Ready-Transaction that exposes the executable actions for the Saga Transaction

func New

func New(ctx context.Context, sg Saga, st Storage, txID string) ReadyTx

New returns an instance of type ReadyTx

func NewWithLogger

func NewWithLogger(ctx context.Context, sg Saga, st Storage, txID string, logger trace.Logger) ReadyTx

NewWithLogger returns an instance of type ReadyTx with given logger

type Saga

type Saga interface {
	GetSubTxDef(subTxID string) (subtx.Definition, error)
	MarshallArgs(args []interface{}) ([]log.ArgData, error)
	UnmarshallArgs(argData []log.ArgData) ([]reflect.Value, error)
}

Saga is the dependency for Transaction that keeps Sub-Transaction definitions.

type Storage

type Storage interface {
	TxIDAlreadyExists(string) (bool, error)
	AppendLog(string, string) error
	GetTxLogs(id string) ([]string, error)
}

Storage is the dependency for Transaction that provides persistence to Saga

type Tx

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

Tx is the Transaction object to perfrom sub-transactions in the Saga

func (*Tx) CompensateSubTx

func (tx *Tx) CompensateSubTx(logData log.Log) error

func (*Tx) End

func (tx *Tx) End() error

End ends the Transaction

func (*Tx) ExecSubTx

func (tx *Tx) ExecSubTx(subTxID string, args ...interface{}) error

ExecSubTx executes the sub-transaction that's already defined in saga and identified by the identifier

func (*Tx) ExecSubTxAndGetResult

func (tx *Tx) ExecSubTxAndGetResult(subTxID string, args ...interface{}) ([]reflect.Value, error)

ExecSubTxAndGetResult executes and returns the results of the sub-transaction that's already defined in saga and identified by the identifier

func (*Tx) IsTxIDAlreadyInUse

func (tx *Tx) IsTxIDAlreadyInUse() (bool, error)

IsTxIDAlreadyInUse checks if TxID is already in use i.e. another Tx was already initiated.

func (*Tx) Rollback

func (tx *Tx) Rollback(tryCount int) error

Rollback tries rolling back the transaction. If rollback is failing it'll try rolling back only tryCount times.

func (*Tx) RollbackWithInfiniteTries

func (tx *Tx) RollbackWithInfiniteTries()

RollbackWithInfiniteTries tries rolling back the transaction. It'll keep retrying the rollback until it's successful.

func (*Tx) SetContext

func (tx *Tx) SetContext(ctx context.Context)

SetContext to change the Transaction context.

func (*Tx) SetLogger

func (tx *Tx) SetLogger(l trace.Logger)

SetLogger to change the Transaction logger.

func (*Tx) Start

func (tx *Tx) Start() error

Start starts the transaction If it returns any error like "could not rollback TxID", you can retry start, because the start tries rollback just once.

Jump to

Keyboard shortcuts

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