dtmimp

package
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: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ResultFailure for result of a trans/trans branch
	ResultFailure = "FAILURE"
	// ResultSuccess for result of a trans/trans branch
	ResultSuccess = "SUCCESS"
	// ResultOngoing for result of a trans/trans branch
	ResultOngoing = "ONGOING"
	// DBTypeMysql const for driver mysql
	DBTypeMysql = "mysql"
	// DBTypePostgres const for driver postgres
	DBTypePostgres = "postgres"
)

Variables

View Source
var ErrFailure = errors.New("FAILURE")

ErrFailure error of FAILURE

View Source
var ErrOngoing = errors.New("ONGOING")

ErrOngoing error of ONGOING

View Source
var FatalExitFunc = func() { os.Exit(1) }

FatalExitFunc Fatal退出函数,测试时被替换

View Source
var MapFailure = map[string]interface{}{"dtm_result": ResultFailure}

MapFailure HTTP result of FAILURE

View Source
var MapSuccess = map[string]interface{}{"dtm_result": ResultSuccess}

MapSuccess HTTP result of SUCCESS

View Source
var RestyClient = resty.New()

RestyClient the resty object

View Source
var XaSqlTimeoutMs = 15000

XaSqlTimeoutMs milliseconds for Xa sql to timeout

Functions

func AsError

func AsError(x interface{}) error

AsError wrap a panic value as an error

func CatchP

func CatchP(f func()) (rerr error)

CatchP catch panic to error

func CheckResponse

func CheckResponse(resp *resty.Response, err error) error

CheckResponse 检查Response,返回错误

func CheckResult

func CheckResult(res interface{}, err error) error

CheckResult 检查Result,返回错误

func DBExec

func DBExec(db DB, sql string, values ...interface{}) (affected int64, rerr error)

DBExec use raw db to exec

func E2P

func E2P(err error)

E2P error to panic

func FatalIfError

func FatalIfError(err error)

FatalIfError 采用红色打印错误类信息, 并退出

func GetCurrentDBType

func GetCurrentDBType() string

GetCurrentDBType get currentDBType

func GetDsn

func GetDsn(conf map[string]string) string

GetDsn get dsn from map config

func GetFuncName

func GetFuncName() string

GetFuncName get current call func name

func If

func If(condition bool, trueObj interface{}, falseObj interface{}) interface{}

If ternary operator

func InitLog

func InitLog()

func LogFatalf

func LogFatalf(fmt string, args ...interface{})

LogFatalf 采用红色打印错误类信息, 并退出

func LogIfFatalf

func LogIfFatalf(condition bool, fmt string, args ...interface{})

LogIfFatalf 采用红色打印错误类信息, 并退出

func LogRedf

func LogRedf(fmt string, args ...interface{})

LogRedf 采用红色打印错误类信息

func Logf

func Logf(fmt string, args ...interface{})

Logf 输出日志

func MayReplaceLocalhost

func MayReplaceLocalhost(host string) string

MayReplaceLocalhost when run in docker compose, change localhost to host.docker.internal for accessing host network

func MustAtoi

func MustAtoi(s string) int

MustAtoi 走must逻辑

func MustMarshal

func MustMarshal(v interface{}) []byte

MustMarshal checked version for marshal

func MustMarshalString

func MustMarshalString(v interface{}) string

MustMarshalString string version of MustMarshal

func MustRemarshal

func MustRemarshal(from interface{}, to interface{})

MustRemarshal marshal and unmarshal, and check error

func MustUnmarshal

func MustUnmarshal(b []byte, obj interface{})

MustUnmarshal checked version for unmarshal

func MustUnmarshalString

func MustUnmarshalString(s string, obj interface{})

MustUnmarshalString string version of MustUnmarshal

func OrString

func OrString(ss ...string) string

OrString return the first not empty string

func P2E

func P2E(perr *error)

P2E panic to error

func PanicIf

func PanicIf(cond bool, err error)

PanicIf name is clear

func PooledDB

func PooledDB(conf map[string]string) (*sql.DB, error)

PooledDB get pooled sql.DB

func SetCurrentDBType

func SetCurrentDBType(dbType string)

SetCurrentDBType set currentDBType

func StandaloneDB

func StandaloneDB(conf map[string]string) (*sql.DB, error)

StandaloneDB get a standalone db instance

func TransCallDtm

func TransCallDtm(tb *TransBase, body interface{}, operation string) error

TransCallDtm TransBase call dtm

func TransRegisterBranch

func TransRegisterBranch(tb *TransBase, added map[string]string, operation string) error

TransRegisterBranch TransBase register a branch to dtm

func TransRequestBranch

func TransRequestBranch(t *TransBase, body interface{}, branchID string, op string, url string) (*resty.Response, error)

TransRequestBranch TransBAse request branch result

Types

type BranchIDGen

type BranchIDGen struct {
	BranchID string
	// contains filtered or unexported fields
}

BranchIDGen used to generate a sub branch id

func (*BranchIDGen) CurrentSubBranchID

func (g *BranchIDGen) CurrentSubBranchID() string

CurrentSubBranchID return current branchID

func (*BranchIDGen) NewSubBranchID

func (g *BranchIDGen) NewSubBranchID() string

NewSubBranchID generate a sub branch id

type DB

type DB interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

DB inteface of dtmcli db

type DBSpecial

type DBSpecial interface {
	TimestampAdd(second int) string
	GetPlaceHoldSQL(sql string) string
	GetInsertIgnoreTemplate(tableAndValues string, pgConstraint string) string
	GetXaSQL(command string, xid string) string
}

DBSpecial db specific operations

func GetDBSpecial

func GetDBSpecial() DBSpecial

GetDBSpecial get DBSpecial for currentDBType

type TransBase

type TransBase struct {
	Gid        string `json:"gid"`
	TransType  string `json:"trans_type"`
	Dtm        string `json:"-"`
	CustomData string `json:"custom_data,omitempty"`
	TransOptions

	Steps       []map[string]string `json:"steps,omitempty"`    // use in MSG/SAGA
	Payloads    []string            `json:"payloads,omitempty"` // used in MSG/SAGA
	BinPayloads [][]byte            `json:"-"`
	BranchIDGen `json:"-"`          // used in XA/TCC
	Op          string              `json:"-"` // used in XA/TCC

	QueryPrepared string `json:"query_prepared,omitempty"` // used in MSG
}

TransBase base for all trans

func NewTransBase

func NewTransBase(gid string, transType string, dtm string, branchID string) *TransBase

NewTransBase new a TransBase

func TransBaseFromQuery

func TransBaseFromQuery(qs url.Values) *TransBase

TransBaseFromQuery construct transaction info from request

func (*TransBase) SetOptions

func (tb *TransBase) SetOptions(options *TransOptions)

SetOptions set options

type TransOptions

type TransOptions struct {
	WaitResult    bool  `json:"wait_result,omitempty" gorm:"-"`
	TimeoutToFail int64 `json:"timeout_to_fail,omitempty" gorm:"-"` // for trans type: xa, tcc
	RetryInterval int64 `json:"retry_interval,omitempty" gorm:"-"`  // for trans type: msg saga xa tcc
}

TransOptions transaction options

type XaClientBase

type XaClientBase struct {
	Server    string
	Conf      map[string]string
	NotifyURL string
}

XaClientBase XaClient/XaGrpcClient base

func (*XaClientBase) HandleCallback

func (xc *XaClientBase) HandleCallback(gid string, branchID string, action string) error

HandleCallback 处理commit/rollback的回调

func (*XaClientBase) HandleGlobalTrans

func (xc *XaClientBase) HandleGlobalTrans(xa *TransBase, callDtm func(string) error, callBusi func() error) (rerr error)

HandleGlobalTrans http/grpc GlobalTransaction的公共方法

func (*XaClientBase) HandleLocalTrans

func (xc *XaClientBase) HandleLocalTrans(xa *TransBase, cb func(*sql.DB) error) (rerr error)

HandleLocalTrans http/grpc 处理LocalTransaction的公共方法

Jump to

Keyboard shortcuts

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