txn

package module
v0.0.0-...-1bc7d3e Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2014 License: LGPL-3.0 Imports: 4 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(params RunnerParams) Runner

NewRunner returns a Runner which runs transactions for the database specified in params. Collection names used to manage the transactions and change log may also be specified in params, but if not, default values will be used.

type RunnerParams

type RunnerParams struct {
	// Database is the mgo database for which the transaction runner will be used.
	Database *mgo.Database

	// TransactionCollectionName is the name of the collection
	// used to initialise the underlying mgo transaction runner,
	// defaults to "txns" if unspecified.
	TransactionCollectionName string

	// ChangeLogName is the mgo transaction runner change log,
	// defaults to "txns.log" if unspecified.
	ChangeLogName string
}

RunnerParams are used to construct a new transaction runner. Only the Database value is mandatory, defaults will be used for the other attributes if not specified.

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