Documentation ¶
Overview ¶
Package dbconn contains a series of database-related utility functions.
Index ¶
- func BeginStandardTrx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, int, error)
- func Exec(ctx context.Context, db *sql.DB, stmt string, args ...interface{}) error
- func IsMySQL84(db *sql.DB) bool
- func IsRDSHost(host string) bool
- func New(inputDSN string, config *DBConfig) (*sql.DB, error)
- func NewTLSConfig() *tls.Config
- func RetryableTransaction(ctx context.Context, db *sql.DB, ignoreDupKeyWarnings bool, config *DBConfig, ...) (int64, error)
- type DBConfig
- type MetadataLock
- type TableLock
- type TrxPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BeginStandardTrx ¶
BeginStandardTrx is like db.BeginTx but returns the connection id.
func Exec ¶
Exec is like db.Exec but only returns an error. This makes it a little bit easier to use in error handling. It accepts args which are escaped client side using the TiDB escape library. i.e. %n is an identifier, %? is automatic type conversion on a variable.
func New ¶
New is similar to sql.Open except we take the inputDSN and append additional options to it to standardize the connection. It will also ping the connection to ensure it is valid.
func NewTLSConfig ¶
func RetryableTransaction ¶
func RetryableTransaction(ctx context.Context, db *sql.DB, ignoreDupKeyWarnings bool, config *DBConfig, stmts ...string) (int64, error)
RetryableTransaction retries all statements in a transaction, retrying if a statement errors, or there is a deadlock. It will retry up to maxRetries times.
Types ¶
type DBConfig ¶
type DBConfig struct { LockWaitTimeout int InnodbLockWaitTimeout int MaxRetries int MaxOpenConnections int RangeOptimizerMaxMemSize int64 }
func NewDBConfig ¶
func NewDBConfig() *DBConfig
type MetadataLock ¶
type MetadataLock struct {
// contains filtered or unexported fields
}
func NewMetadataLock ¶
func NewMetadataLock(ctx context.Context, dsn string, lockName string, logger loggers.Advanced, optionFns ...func(*MetadataLock)) (*MetadataLock, error)
func (*MetadataLock) Close ¶
func (m *MetadataLock) Close() error
type TableLock ¶
type TableLock struct {
// contains filtered or unexported fields
}
func NewTableLock ¶
func NewTableLock(ctx context.Context, db *sql.DB, table *table.TableInfo, config *DBConfig, logger loggers.Advanced) (*TableLock, error)
NewTableLock creates a new server wide lock on a table. i.e. LOCK TABLES .. READ. It uses a short-timeout with backoff and retry, since if there is a long-running process that currently prevents the lock by being acquired, it is considered "nice" to let a few short-running processes slip in and proceed, then optimistically try and acquire the lock again.