txn

package
v0.0.0-...-439fd0a Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = time.Second * 30
)

Variables

This section is empty.

Functions

func IsErrRetryable

func IsErrRetryable(err error) bool

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

func WithLogger(logger Logger) Option

WithLogger defines a logger for the transaction.

func WithRetryStrategy

func WithRetryStrategy(retryStrategy RetryStrategy) Option

WithRetryStrategy defines a retry strategy for the transaction.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

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

type RetryStrategy func(context.Context, func() error) error

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.

Jump to

Keyboard shortcuts

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