sqlapp

package
v0.0.0-...-4ed88a5 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CockroachIPAddressesCSV is the flag for cockroach node ips
	CockroachIPAddressesCSV = "cockroach_ip_addresses_csv"
	// DurationSecs is the flag for the duration a test should run
	DurationSecs = "duration_secs"
	// InstallSchema is the flag for log for whether to create db / tables
	InstallSchema = "install_schema"
	// WorkerIndex is the flag for worker id
	WorkerIndex = "worker_index"
	// CertsDir is the flag for location of cockroach certificates
	CertsDir = "certs_dir"
	// Insecure is the flag for whether cockroachDB is running in insecure mode
	Insecure = "insecure"
	// NumWorkers is the flag for number of workers
	NumWorkers = "num_workers"
)

Variables

This section is empty.

Functions

func ExecuteGORMTx

func ExecuteGORMTx(db *gorm.DB, fn func(tx *gorm.DB) error) error

ExecuteGORMTx executes fn inside a GORM transaction and retries it as needed using crdb utilities.

func ExecuteTraceOfQuery

func ExecuteTraceOfQuery(ctx context.Context, db *gorm.DB, q string) error

ExecuteTraceOfQuery runs `SHOW TRACE FOR` on the parameter q and prints output in CSV format

func RetryAlways

func RetryAlways(_ error) bool

RetryAlways always retries on any error

func RetryNever

func RetryNever(_ error) bool

RetryNever never retries on any error

func RetryOnConnectionError

func RetryOnConnectionError(err error) bool

RetryOnConnectionError returns a function that retries only on connection error

Types

type RobustDB

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

RobustDB keeps retrying transactions and queries on errors Retryable function is used to decide which error to retry on

func NewRobustDB

func NewRobustDB(dbs []*gorm.DB, fn func(error) bool, args ...interface{}) *RobustDB

NewRobustDB returns a pointer to RobustDB struct which has dbs as slice of *gorm.DB and fn as retryable function, optionally third argument Max duration for retries and fourth argument minimum sleep time between retries can be specified. Sleep time will increase exponentially between retries.

func NewRobustSQLDB

func NewRobustSQLDB(dbs []*sql.DB, fn func(error) bool, args ...interface{}) *RobustDB

NewRobustSQLDB is similar to NewRobustDB except its dbs are *sql.DB instead of *gorm.DB.

func (*RobustDB) AvgRetries

func (rd *RobustDB) AvgRetries() float64

AvgRetries returns average number of tries per success transactions

func (*RobustDB) ExecuteRawQuery

func (rd *RobustDB) ExecuteRawQuery(fn func(*gorm.DB) error) error

ExecuteRawQuery executes raw single query functions with retry policies without transaction

func (*RobustDB) ExecuteSQLTx

func (rd *RobustDB) ExecuteSQLTx(ctx context.Context, fn func(*sql.Tx) error) error

ExecuteSQLTx is similar to ExecuteTx but takes a sql transaction instead of a GORM transaction.

func (*RobustDB) ExecuteTx

func (rd *RobustDB) ExecuteTx(fn func(*gorm.DB) error) error

ExecuteTx takes a function which takes a gorm transaction and produces error, and on error keeps retrying to different DBs based on retryableError method of rd object crdb.ExecuteInTx is called internally by ExecuteGORMTx. It creates a SAVEPOINT, then it executes the user function, then calls RELEASE (equivalent of COMMIT in cockroach). If there is an error during RELEASE and it is not retryable, We get an AmbiguousCommitError. Here, we don't know weather transaction was commited or not. So, we cannot blindly retry on this error message.

func (*RobustDB) NumFailedTransaction

func (rd *RobustDB) NumFailedTransaction() int32

NumFailedTransaction returns number of failed transactions

func (*RobustDB) NumRetries

func (rd *RobustDB) NumRetries() int32

NumRetries returns the number of txn retries

func (*RobustDB) NumSuccessfulTransaction

func (rd *RobustDB) NumSuccessfulTransaction() int32

NumSuccessfulTransaction returns number of successful transactions

func (*RobustDB) PrintStats

func (rd *RobustDB) PrintStats()

PrintStats prints statistics.

func (*RobustDB) RandomDB

func (rd *RobustDB) RandomDB() *gorm.DB

RandomDB returns a randomly picked DB from DB list

func (*RobustDB) RandomSQLDB

func (rd *RobustDB) RandomSQLDB(ctx context.Context) *sql.DB

RandomSQLDB returns a randomly picked DB from DB list

Jump to

Keyboard shortcuts

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