dtmcli

package module
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2021 License: BSD-3-Clause Imports: 5 Imported by: 2

README

a client for distributed transaction manager dtm

dtmcli 是分布式事务管理器dtm的客户端sdk

dtmcli

这个库的代码与dtm下的dtmcli代码保持完全同步,如果您需要线上使用,那么当前的dtmcli相关的依赖非常少,对于最终打包的镜像也会很少

具体文档和使用方式,请参考dtm

完整示例

dtmcli-go-sample

Documentation

Index

Constants

View Source
const (
	// StatusPrepared status for global/branch trans status.
	StatusPrepared = "prepared"
	// StatusSubmitted status for global trans status.
	StatusSubmitted = "submitted"
	// StatusSucceed status for global/branch trans status.
	StatusSucceed = "succeed"
	// StatusFailed status for global/branch trans status.
	StatusFailed = "failed"
	// StatusAborting status for global trans status.
	StatusAborting = "aborting"

	// BranchTry branch type for TCC
	BranchTry = "try"
	// BranchConfirm branch type for TCC
	BranchConfirm = "confirm"
	// BranchCancel branch type for TCC
	BranchCancel = "cancel"
	// BranchAction branch type for message, SAGA, XA
	BranchAction = "action"
	// BranchCompensate branch type for SAGA
	BranchCompensate = "compensate"
	// BranchCommit branch type for XA
	BranchCommit = "commit"
	// BranchRollback branch type for XA
	BranchRollback = "rollback"

	// ResultSuccess for result of a trans/trans branch
	ResultSuccess = dtmimp.ResultSuccess
	// ResultFailure for result of a trans/trans branch
	ResultFailure = dtmimp.ResultFailure
	// ResultOngoing for result of a trans/trans branch
	ResultOngoing = dtmimp.ResultOngoing

	// DBTypeMysql const for driver mysql
	DBTypeMysql = dtmimp.DBTypeMysql
	// DBTypePostgres const for driver postgres
	DBTypePostgres = dtmimp.DBTypePostgres
)

Variables

View Source
var ErrFailure = dtmimp.ErrFailure

ErrFailure error for returned failure

View Source
var ErrOngoing = dtmimp.ErrOngoing

ErrOngoing error for returned ongoing

View Source
var MapFailure = dtmimp.MapFailure

MapFailure HTTP result of FAILURE

View Source
var MapSuccess = dtmimp.MapSuccess

MapSuccess HTTP result of SUCCESS

Functions

func GetCurrentDBType

func GetCurrentDBType() string

GetCurrentDBType get currentDBType

func GetXaSqlTimeoutMs

func GetXaSqlTimeoutMs() int

GetXaSqlTimeoutMs get XaSqlTimeoutMs

func MustGenGid

func MustGenGid(server string) string

MustGenGid generate a new gid

func SetCurrentDBType

func SetCurrentDBType(dbType string)

SetCurrentDBType set currentDBType

func SetXaSqlTimeoutMs

func SetXaSqlTimeoutMs(ms int)

SetXaSqlTimeoutMs set XaSqlTimeoutMs

func TccGlobalTransaction

func TccGlobalTransaction(dtm string, gid string, tccFunc TccGlobalFunc) (rerr error)

TccGlobalTransaction begin a tcc global transaction dtm dtm服务器地址 gid 全局事务id tccFunc tcc事务函数,里面会定义全局事务的分支

Types

type BarrierBusiFunc

type BarrierBusiFunc func(tx *sql.Tx) error

BarrierBusiFunc type for busi func

type BranchBarrier

type BranchBarrier struct {
	TransType string
	Gid       string
	BranchID  string
	Op        string
	BarrierID int
}

BranchBarrier every branch info

func BarrierFrom

func BarrierFrom(transType, gid, branchID, op string) (*BranchBarrier, error)

BarrierFrom construct transaction info from request

func BarrierFromQuery

func BarrierFromQuery(qs url.Values) (*BranchBarrier, error)

BarrierFromQuery construct transaction info from request

func (*BranchBarrier) Call

func (bb *BranchBarrier) Call(tx *sql.Tx, busiCall BarrierBusiFunc) (rerr error)

Call 子事务屏障,详细介绍见 https://zhuanlan.zhihu.com/p/388444465 tx: 本地数据库的事务对象,允许子事务屏障进行事务操作 busiCall: 业务函数,仅在必要时被调用

func (*BranchBarrier) CallWithDB

func (bb *BranchBarrier) CallWithDB(db *sql.DB, busiCall BarrierBusiFunc) error

CallWithDB the same as Call, but with *sql.DB

func (*BranchBarrier) String

func (bb *BranchBarrier) String() string

type DB

type DB = dtmimp.DB

DB interface

type Msg

type Msg struct {
	dtmimp.TransBase
}

Msg reliable msg type

func NewMsg

func NewMsg(server string, gid string) *Msg

NewMsg create new msg

func (*Msg) Add

func (s *Msg) Add(action string, postData interface{}) *Msg

Add add a new step

func (*Msg) Prepare

func (s *Msg) Prepare(queryPrepared string) error

Prepare prepare the msg, msg will later be submitted

func (*Msg) Submit

func (s *Msg) Submit() error

Submit submit the msg

type Saga

type Saga struct {
	dtmimp.TransBase
	// contains filtered or unexported fields
}

Saga struct of saga

func NewSaga

func NewSaga(server string, gid string) *Saga

NewSaga create a saga

func (*Saga) Add

func (s *Saga) Add(action string, compensate string, postData interface{}) *Saga

Add add a saga step

func (*Saga) AddBranchOrder

func (s *Saga) AddBranchOrder(branch int, preBranches []int) *Saga

AddBranchOrder specify that branch should be after preBranches. branch should is larger than all the element in preBranches

func (*Saga) EnableConcurrent

func (s *Saga) EnableConcurrent() *Saga

EnableConcurrent enable the concurrent exec of sub trans

func (*Saga) Submit

func (s *Saga) Submit() error

Submit submit the saga trans

type Tcc

type Tcc struct {
	dtmimp.TransBase
}

Tcc struct of tcc

func TccFromQuery

func TccFromQuery(qs url.Values) (*Tcc, error)

TccFromQuery tcc from request info

func (*Tcc) CallBranch

func (t *Tcc) CallBranch(body interface{}, tryURL string, confirmURL string, cancelURL string) (*resty.Response, error)

CallBranch call a tcc branch

type TccGlobalFunc

type TccGlobalFunc func(tcc *Tcc) (*resty.Response, error)

TccGlobalFunc type of global tcc call

type TransOptions

type TransOptions = dtmimp.TransOptions

TransOptions transaction option

type Xa

type Xa struct {
	dtmimp.TransBase
}

Xa xa transaction

func XaFromQuery

func XaFromQuery(qs url.Values) (*Xa, error)

XaFromQuery construct xa info from request

func (*Xa) CallBranch

func (x *Xa) CallBranch(body interface{}, url string) (*resty.Response, error)

CallBranch call a xa branch

type XaClient

type XaClient struct {
	dtmimp.XaClientBase
}

XaClient xa client

func NewXaClient

func NewXaClient(server string, mysqlConf map[string]string, notifyURL string, register XaRegisterCallback) (*XaClient, error)

NewXaClient construct a xa client

func (*XaClient) HandleCallback

func (xc *XaClient) HandleCallback(gid string, branchID string, action string) (interface{}, error)

HandleCallback 处理commit/rollback的回调

func (*XaClient) XaGlobalTransaction

func (xc *XaClient) XaGlobalTransaction(gid string, xaFunc XaGlobalFunc) (rerr error)

XaGlobalTransaction start a xa global transaction

func (*XaClient) XaLocalTransaction

func (xc *XaClient) XaLocalTransaction(qs url.Values, xaFunc XaLocalFunc) error

XaLocalTransaction start a xa local transaction

type XaGlobalFunc

type XaGlobalFunc func(xa *Xa) (*resty.Response, error)

XaGlobalFunc type of xa global function

type XaLocalFunc

type XaLocalFunc func(db *sql.DB, xa *Xa) error

XaLocalFunc type of xa local function

type XaRegisterCallback

type XaRegisterCallback func(path string, xa *XaClient)

XaRegisterCallback type of xa register callback handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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