sql

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2023 License: Apache-2.0 Imports: 28 Imported by: 3

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"
)
View Source
const REPORT_RETRY_COUNT = 5

Variables

This section is empty.

Functions

func CleanTxHooks

func CleanTxHooks()

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

func (*ATSourceManager) BranchRegister

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

BranchRegister

func (*ATSourceManager) BranchReport

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

BranchReport

func (*ATSourceManager) BranchRollback

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

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)

CreateTableMetaCache

func (*ATSourceManager) GetBranchType

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

func (*ATSourceManager) GetCachedResources

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

Get all resources managed by this manager

func (*ATSourceManager) LockQuery

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

LockQuery

func (*ATSourceManager) RegisterResource

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

Register a Resource to be managed by Resource Manager

func (*ATSourceManager) UnregisterResource

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

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) 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) GetBranchType

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

func (*DBResource) GetResourceGroupId

func (db *DBResource) GetResourceGroupId() string

func (*DBResource) GetResourceId

func (db *DBResource) GetResourceId() string

type SqlDBProxy

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

func (*SqlDBProxy) GetDB

func (s *SqlDBProxy) GetDB() *sql.DB

func (*SqlDBProxy) GetDBName

func (s *SqlDBProxy) GetDBName() string

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 XAConn

type XAConn struct {
	*Conn
}

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

func (*XAConn) ExecContext

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

ExecContext

func (*XAConn) PrepareContext

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

PrepareContext

func (*XAConn) QueryContext

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

QueryContext

type XATx

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

XATx

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

Directories

Path Synopsis
at
xa
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