txn

package module
v0.0.0-...-5694f17 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2014 License: LGPL-3.0 Imports: 3 Imported by: 0

README

juju/txn

This package wraps labix.org/v2/mgo/txn, providing convenience functions and interfaces for common transaction execution patterns, and also providing test hook points.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExcessiveContention is used to signal that even after retrying, the transaction operations
	// could not be successfully applied due to database contention.
	ErrExcessiveContention = stderrors.New("state changing too quickly; try again soon")

	// ErrNoOperations is returned by TransactionSource implementations to signal that
	// no transaction operations are available to run.
	ErrNoOperations = stderrors.New("no transaction operations are available")

	// ErrNoOperations is returned by TransactionSource implementations to signal that
	// the transaction list could not be built but the caller should retry.
	ErrTransientFailure = stderrors.New("transient failure")
)

Functions

func TestHooks

func TestHooks(runner Runner) chan ([]TestHook)

TestHooks returns the test hooks for a transaction runner. Exported only for testing.

Types

type Runner

type Runner interface {
	// RunTransaction applies the specified transaction operations to a database.
	RunTransaction(ops []txn.Op) error

	// Run calls the nominated function to get the transaction operations to apply to a database.
	// If there is a failure due to a txn.ErrAborted error, the attempt is retried up to nrRetries times.
	Run(transactions TransactionSource) error

	// ResumeTransactions resumes all pending transactions.
	ResumeTransactions() error
}

Runner instances applies operations to collections in a database.

func NewRunner

func NewRunner(runner *txn.Runner) Runner

NewRunner returns a Runner which delegates to the specified txn.Runner.

type TestHook

type TestHook struct {
	Before func()
	After  func()
}

TestHook holds a pair of functions to be called before and after a mgo/txn transaction is run. Exported only for testing.

type TransactionSource

type TransactionSource func(attempt int) ([]txn.Op, error)

TransactionSource defines a function that can return transaction operations to run.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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