sql

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: Apache-2.0 Imports: 35 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// SeataATMySQLDriver MySQL driver for AT mode
	SeataATMySQLDriver = "seata-at-mysql"
	// SeataXAMySQLDriver MySQL driver for XA mode
	SeataXAMySQLDriver = "seata-xa-mysql"
)

Variables

This section is empty.

Functions

func CleanTxHooks

func CleanTxHooks()

func Init added in v1.1.0

func Init()

func InitAT

func InitAT(cfg undo.Config, asyncCfg AsyncWorkerConfig)

func RegisterTxHook

func RegisterTxHook(h txHook)

Types

type ATConn

type ATConn struct {
	*Conn
}

ATConn Database connection proxy object under XA transaction model Conn is assumed to be stateful.

func (*ATConn) BeginTx

func (c *ATConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

BeginTx

func (*ATConn) ExecContext

func (c *ATConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)

ExecContext

func (*ATConn) PrepareContext

func (c *ATConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

func (*ATConn) QueryContext

func (c *ATConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

QueryContext

type ATSourceManager

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

func (*ATSourceManager) BranchCommit

func (a *ATSourceManager) BranchCommit(ctx context.Context, resource rm.BranchResource) (branch.BranchStatus, error)

BranchCommit commit the branch transaction

func (*ATSourceManager) BranchRegister

func (a *ATSourceManager) BranchRegister(ctx context.Context, req rm.BranchRegisterParam) (int64, error)

BranchRegister branch transaction register

func (*ATSourceManager) BranchReport

func (a *ATSourceManager) BranchReport(ctx context.Context, param rm.BranchReportParam) error

BranchReport Report status of transaction branch

func (*ATSourceManager) BranchRollback

func (a *ATSourceManager) BranchRollback(ctx context.Context, branchResource rm.BranchResource) (branch.BranchStatus, error)

BranchRollback rollback a branch transaction

func (*ATSourceManager) CreateTableMetaCache

func (a *ATSourceManager) CreateTableMetaCache(ctx context.Context, resID string, dbType types.DBType,
	db *sql.DB) (datasource.TableMetaCache, error)

func (*ATSourceManager) GetBranchType

func (a *ATSourceManager) GetBranchType() branch.BranchType

func (*ATSourceManager) GetCachedResources

func (a *ATSourceManager) GetCachedResources() *sync.Map

GetCachedResources get all resources managed by this manager

func (*ATSourceManager) LockQuery

func (a *ATSourceManager) LockQuery(ctx context.Context, param rm.LockQueryParam) (bool, error)

func (*ATSourceManager) RegisterResource

func (a *ATSourceManager) RegisterResource(res rm.Resource) error

RegisterResource register a Resource to be managed by Resource Manager

func (*ATSourceManager) UnregisterResource

func (a *ATSourceManager) UnregisterResource(res rm.Resource) error

UnregisterResource unregister a Resource from the Resource Manager

type ATTx

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

ATTx

func (*ATTx) Commit

func (tx *ATTx) Commit() error

Commit do commit action case 1. no open global-transaction, just do local transaction commit case 2. not need flush undolog, is XA mode, do local transaction commit case 3. need run AT transaction

func (*ATTx) Rollback

func (tx *ATTx) Rollback() error

type AsyncWorker

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

AsyncWorker executor for branch transaction commit and undo log

func NewAsyncWorker

func NewAsyncWorker(prom prometheus.Registerer, conf AsyncWorkerConfig, sourceManager datasource.DataSourceManager) *AsyncWorker

func (*AsyncWorker) BranchCommit

func (aw *AsyncWorker) BranchCommit(ctx context.Context, req rm.BranchResource) (branch.BranchStatus, error)

BranchCommit commit branch transaction

type AsyncWorkerConfig

type AsyncWorkerConfig struct {
	BufferLimit            int           `yaml:"buffer_limit" json:"buffer_limit"`
	BufferCleanInterval    time.Duration `yaml:"buffer_clean_interval" json:"buffer_clean_interval"`
	ReceiveChanSize        int           `yaml:"receive_chan_size" json:"receive_chan_size"`
	CommitWorkerCount      int           `yaml:"commit_worker_count" json:"commit_worker_count"`
	CommitWorkerBufferSize int           `yaml:"commit_worker_buffer_size" json:"commit_worker_buffer_size"`
}

func (*AsyncWorkerConfig) RegisterFlagsWithPrefix

func (cfg *AsyncWorkerConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

type Conn

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

Conn is a connection to a database. It is not used concurrently by multiple goroutines.

Conn is assumed to be stateful.

func (*Conn) Begin deprecated

func (c *Conn) Begin() (driver.Tx, error)

Begin starts and returns a new transaction.

Deprecated: Drivers should implement ConnBeginTx instead (or additionally).

func (*Conn) BeginTx

func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

BeginTx Open a transaction and judge whether the current transaction needs to open a

global transaction according to tranCtx. If so, it needs to be included in the transaction management of seata

func (*Conn) Close

func (c *Conn) Close() error

Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.

Because the sql package maintains a free pool of connections and only calls Close when there's a surplus of idle connections, it shouldn't be necessary for drivers to do their own connection caching.

Drivers must ensure all network calls made by Close do not block indefinitely (e.g. apply a timeout).

func (*Conn) Exec

func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error)

Exec warning: if you want to use global transaction, please use ExecContext function

func (*Conn) ExecContext

func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)

ExecContext

func (*Conn) GetAutoCommit added in v1.1.0

func (c *Conn) GetAutoCommit() bool

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

Prepare returns a prepared statement, bound to this connection.

func (*Conn) PrepareContext

func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

PrepareContext

func (*Conn) Query

func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error)

Query

func (*Conn) QueryContext

func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

QueryContext

func (*Conn) ResetSession

func (c *Conn) ResetSession(ctx context.Context) error

ResetSession is called prior to executing a query on the connection if the connection has been used before. If the driver returns ErrBadConn the connection is discarded.

type DBResource

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

DBResource proxy sql.DB, enchance database/sql.DB to add distribute transaction ability

func (*DBResource) ConnectionForXA added in v1.2.0

func (db *DBResource) ConnectionForXA(ctx context.Context, xaXid XAXid) (*XAConn, error)

func (*DBResource) GetBranchType

func (db *DBResource) GetBranchType() branch.BranchType

func (*DBResource) GetDB added in v1.2.0

func (db *DBResource) GetDB() *sql.DB

func (*DBResource) GetDBName added in v1.2.0

func (db *DBResource) GetDBName() string

func (*DBResource) GetDbType added in v1.2.0

func (db *DBResource) GetDbType() types.DBType

func (*DBResource) GetDbVersion added in v1.2.0

func (db *DBResource) GetDbVersion() string

func (*DBResource) GetKeeper added in v1.2.0

func (db *DBResource) GetKeeper() *sync.Map

func (*DBResource) GetResourceGroupId

func (db *DBResource) GetResourceGroupId() string

func (*DBResource) GetResourceId

func (db *DBResource) GetResourceId() string

func (*DBResource) Hold added in v1.2.0

func (db *DBResource) Hold(xaBranchID string, v interface{}) error

Hold the xa connection.

func (*DBResource) IsShouldBeHeld added in v1.2.0

func (db *DBResource) IsShouldBeHeld() bool

func (*DBResource) Lookup added in v1.2.0

func (db *DBResource) Lookup(xaBranchID string) (interface{}, bool)

func (*DBResource) Release added in v1.2.0

func (db *DBResource) Release(xaBranchID string)

func (*DBResource) SetDbType added in v1.2.0

func (db *DBResource) SetDbType(dbType types.DBType)

func (*DBResource) SetDbVersion added in v1.2.0

func (db *DBResource) SetDbVersion(v string)

type Option added in v1.2.0

type Option func(*XABranchXid)

func WithBranchId added in v1.2.0

func WithBranchId(branchId uint64) Option

func WithBranchQualifier added in v1.2.0

func WithBranchQualifier(branchQualifier []byte) Option

func WithGlobalTransactionId added in v1.2.0

func WithGlobalTransactionId(globalTransactionId []byte) Option

func WithXid added in v1.2.0

func WithXid(xid string) Option

type Stmt

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

func (*Stmt) Close

func (s *Stmt) Close() error

Close closes the statement.

As of Go 1.1, a Stmt will not be closed if it's in use by any queries.

Drivers must ensure all network calls made by Close do not block indefinitely (e.g. apply a timeout).

func (*Stmt) Exec deprecated

func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)

Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.

Deprecated: Drivers should implement StmtExecContext instead (or additionally).

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)

ExecContext executes a query that doesn't return rows, such as an INSERT or UPDATE.

ExecContext must honor the context timeout and return when it is canceled.

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

NumInput returns the number of placeholder parameters.

If NumInput returns >= 0, the sql package will sanity check argument counts from callers and return errors to the caller before the statement's Exec or Query methods are called.

NumInput may also return -1, if the driver doesn't know its number of placeholders. In that case, the sql package will not sanity check Exec or Query argument counts.

func (*Stmt) Query deprecated

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

Query executes a query that may return rows, such as a SELECT.

Deprecated: Drivers should implement StmtQueryContext instead (or additionally).

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)

QueryContext StmtQueryContext enhances the Stmt interface by providing Query with context. QueryContext executes a query that may return rows, such as a SELECT. QueryContext must honor the context timeout and return when it is canceled.

type Tx

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

Tx

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit do commit action

func (*Tx) Rollback

func (tx *Tx) Rollback() error

type XABranchXid added in v1.2.0

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

func NewXABranchXid added in v1.2.0

func NewXABranchXid(opt ...Option) *XABranchXid

func XaIdBuild added in v1.2.0

func XaIdBuild(xid string, branchId uint64) *XABranchXid

func XaIdBuildWithByte added in v1.2.0

func XaIdBuildWithByte(globalTransactionId []byte, branchQualifier []byte) *XABranchXid

func (*XABranchXid) GetBranchId added in v1.2.0

func (x *XABranchXid) GetBranchId() uint64

func (*XABranchXid) GetBranchQualifier added in v1.2.0

func (x *XABranchXid) GetBranchQualifier() []byte

func (*XABranchXid) GetGlobalTransactionId added in v1.2.0

func (x *XABranchXid) GetGlobalTransactionId() []byte

func (*XABranchXid) GetGlobalXid added in v1.2.0

func (x *XABranchXid) GetGlobalXid() string

func (*XABranchXid) String added in v1.2.0

func (x *XABranchXid) String() string

type XAConfig added in v1.2.0

type XAConfig struct {
	TwoPhaseHoldTime time.Duration `json:"two_phase_hold_time" yaml:"xa_two_phase_hold_time" koanf:"xa_two_phase_hold_time"`
	// contains filtered or unexported fields
}

func (*XAConfig) RegisterFlagsWithPrefix added in v1.2.0

func (cfg *XAConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

type XAConn

type XAConn struct {
	*Conn
	// contains filtered or unexported fields
}

XAConn Database connection proxy object under XA transaction model Conn is assumed to be stateful.

func (*XAConn) BeginTx

func (c *XAConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

BeginTx like common transaction. but it just exec XA START

func (*XAConn) Close added in v1.2.0

func (c *XAConn) Close() error

func (*XAConn) CloseForce added in v1.2.0

func (c *XAConn) CloseForce() error

func (*XAConn) Commit added in v1.2.0

func (c *XAConn) Commit(ctx context.Context) error

func (*XAConn) ExecContext

func (c *XAConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)

func (*XAConn) PrepareContext

func (c *XAConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

func (*XAConn) QueryContext

func (c *XAConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

QueryContext exec xa sql

func (*XAConn) Rollback added in v1.2.0

func (c *XAConn) Rollback(ctx context.Context) error

func (*XAConn) ShouldBeHeld added in v1.2.0

func (c *XAConn) ShouldBeHeld() bool

func (*XAConn) XaCommit added in v1.2.0

func (c *XAConn) XaCommit(ctx context.Context, xaXid XAXid) error

func (*XAConn) XaRollback added in v1.2.0

func (c *XAConn) XaRollback(ctx context.Context, xaXid XAXid) error

func (*XAConn) XaRollbackByBranchId added in v1.2.0

func (c *XAConn) XaRollbackByBranchId(ctx context.Context, xaXid XAXid) error

type XAConnConf added in v1.2.0

type XAConnConf struct {
	XaBranchExecutionTimeout time.Duration `json:"xa_branch_execution_timeout" xml:"xa_branch_execution_timeout" koanf:"xa_branch_execution_timeout"`
}

func (*XAConnConf) RegisterFlagsWithPrefix added in v1.2.0

func (cfg *XAConnConf) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

type XAResourceManager added in v1.2.0

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

func InitXA added in v1.2.0

func InitXA(config XAConfig) *XAResourceManager

func (*XAResourceManager) BranchCommit added in v1.2.0

func (xaManager *XAResourceManager) BranchCommit(ctx context.Context, branchResource rm.BranchResource) (branch.BranchStatus, error)

func (*XAResourceManager) BranchRegister added in v1.2.0

func (xaManager *XAResourceManager) BranchRegister(ctx context.Context, req rm.BranchRegisterParam) (int64, error)

func (*XAResourceManager) BranchReport added in v1.2.0

func (xaManager *XAResourceManager) BranchReport(ctx context.Context, param rm.BranchReportParam) error

func (*XAResourceManager) BranchRollback added in v1.2.0

func (xaManager *XAResourceManager) BranchRollback(ctx context.Context, branchResource rm.BranchResource) (branch.BranchStatus, error)

func (*XAResourceManager) CreateTableMetaCache added in v1.2.0

func (xaManager *XAResourceManager) CreateTableMetaCache(ctx context.Context, resID string, dbType types.DBType, db *sql.DB) (datasource.TableMetaCache, error)

func (*XAResourceManager) GetBranchType added in v1.2.0

func (xaManager *XAResourceManager) GetBranchType() branch.BranchType

func (*XAResourceManager) GetCachedResources added in v1.2.0

func (xaManager *XAResourceManager) GetCachedResources() *sync.Map

func (*XAResourceManager) LockQuery added in v1.2.0

func (xaManager *XAResourceManager) LockQuery(ctx context.Context, param rm.LockQueryParam) (bool, error)

func (*XAResourceManager) RegisterResource added in v1.2.0

func (xaManager *XAResourceManager) RegisterResource(res rm.Resource) error

func (*XAResourceManager) UnregisterResource added in v1.2.0

func (xaManager *XAResourceManager) UnregisterResource(resource rm.Resource) error

type XATx

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

func (*XATx) Commit

func (tx *XATx) Commit() error

Commit do commit action case 1. no open global-transaction, just do local transaction commit case 2. not need flush undolog, is XA mode, do local transaction commit case 3. need run AT transaction

func (*XATx) Rollback

func (tx *XATx) Rollback() error

type XAXid added in v1.2.0

type XAXid interface {
	GetGlobalXid() string
	GetBranchId() uint64
	String() string
}

Directories

Path Synopsis
at
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
Package sql provides a generic interface around SQL (or SQL-like) databases.
Package sql provides a generic interface around SQL (or SQL-like) databases.

Jump to

Keyboard shortcuts

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