Documentation ¶
Index ¶
- Constants
- func ExecuteGORMTx(db *gorm.DB, fn func(tx *gorm.DB) error) error
- func ExecuteTraceOfQuery(ctx context.Context, db *gorm.DB, q string) error
- func RetryAlways(_ error) bool
- func RetryNever(_ error) bool
- func RetryOnConnectionError(err error) bool
- type RobustDB
- func (rd *RobustDB) AvgRetries() float64
- func (rd *RobustDB) ExecuteRawQuery(fn func(*gorm.DB) error) error
- func (rd *RobustDB) ExecuteSQLTx(ctx context.Context, fn func(*sql.Tx) error) error
- func (rd *RobustDB) ExecuteTx(fn func(*gorm.DB) error) error
- func (rd *RobustDB) NumFailedTransaction() int32
- func (rd *RobustDB) NumRetries() int32
- func (rd *RobustDB) NumSuccessfulTransaction() int32
- func (rd *RobustDB) PrintStats()
- func (rd *RobustDB) RandomDB() *gorm.DB
- func (rd *RobustDB) RandomSQLDB(ctx context.Context) *sql.DB
Constants ¶
const ( // PprofPort is the listener port for pprof server PprofPort = 9999 // 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" // NumTesters is the flag for number of testers NumTesters = "num_testers" )
Variables ¶
This section is empty.
Functions ¶
func ExecuteGORMTx ¶
ExecuteGORMTx executes fn inside a GORM transaction and retries it as needed using crdb utilities.
func ExecuteTraceOfQuery ¶
ExecuteTraceOfQuery runs `SHOW TRACE FOR` on the parameter q and prints output in CSV format
func RetryOnConnectionError ¶
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 ¶
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 ¶
NewRobustSQLDB is similar to NewRobustDB except its dbs are *sql.DB instead of *gorm.DB.
func (*RobustDB) AvgRetries ¶
AvgRetries returns average number of tries per success transactions
func (*RobustDB) ExecuteRawQuery ¶
ExecuteRawQuery executes raw single query functions with retry policies without transaction
func (*RobustDB) ExecuteSQLTx ¶
ExecuteSQLTx is similar to ExecuteTx but takes a sql transaction instead of a GORM transaction.
func (*RobustDB) ExecuteTx ¶
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 ¶
NumFailedTransaction returns number of failed transactions
func (*RobustDB) NumRetries ¶
NumRetries returns the number of txn retries
func (*RobustDB) NumSuccessfulTransaction ¶
NumSuccessfulTransaction returns number of successful transactions