Documentation
¶
Index ¶
Constants ¶
const (
DefaultTimeout = time.Second * 30
)
Variables ¶
This section is empty.
Functions ¶
func IsErrRetryable ¶
IsErrRetryable returns true if the given error might be transient and the interaction can be safely retried. See: https://github.com/canonical/go-dqlite/issues/220
Types ¶
type Logger ¶
type Logger interface { Errorf(string, ...interface{}) Warningf(string, ...interface{}) Debugf(string, ...interface{}) Tracef(string, ...interface{}) IsTraceEnabled() bool // Logf is used to proxy Dqlite logs via this logger. Logf(level loggo.Level, msg string, args ...interface{}) }
Logger describes methods for emitting log output.
type Option ¶
type Option func(*option)
Option defines a function for setting options on a TransactionRunner.
func WithLogger ¶
WithLogger defines a logger for the transaction.
func WithRetryStrategy ¶
func WithRetryStrategy(retryStrategy RetryStrategy) Option
WithRetryStrategy defines a retry strategy for the transaction.
func WithTimeout ¶
WithTimeout defines a timeout for the transaction. This is useful for defining a timeout for a transaction that is expected to take longer than the default timeout.
type RetryStrategy ¶
RetryStrategy defines a function for retrying a transaction.
type TransactionRunner ¶
type TransactionRunner struct {
// contains filtered or unexported fields
}
TransactionRunner defines a generic transactioner for applying transactions on a given database. It expects that no individual transaction function should take longer than the default timeout.
func NewTransactionRunner ¶
func NewTransactionRunner(opts ...Option) *TransactionRunner
NewTransactionRunner returns a new TransactionRunner.
func (*TransactionRunner) Retry ¶
func (t *TransactionRunner) Retry(ctx context.Context, fn func() error) error
Retry defines a generic retry function for applying a function that interacts with the database. It will retry in cases of transient known database errors.
func (*TransactionRunner) Txn ¶
func (t *TransactionRunner) Txn(ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error) error
Txn defines a generic txn function for applying transactions on a given database. It expects that no individual transaction function should take longer than the default timeout. There are no retry semantics for running the function.
This should not be used directly, instead the TrackedDB should be used to handle transactions.