transaction

package
v0.0.0-...-8223eb1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package transaction provides an interface for crafting transactional updates to consul.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyOperations = errors.New("consul transactions cannot have more than 64 operations")
	ErrAlreadyCommitted  = errors.New("this transaction has already been committed")
)

Functions

func Add

func Add(ctx context.Context, op api.KVTxnOp) error

func Commit

func Commit(ctx context.Context, txner Txner) (bool, *api.KVTxnResponse, error)

Commit attempts to run all of the kv operations in the context's transaction. The cancel function with which the context was created must also be passed to guarantee that the transaction won't be applied twice

func CommitWithRetries

func CommitWithRetries(ctx context.Context, txner Txner) (bool, *api.KVTxnResponse, error)

CommitWithRetries retries Commit() until the transaction is applied without an error. It will not retry the transaction if there is no error but the transaction was rolled back (and it wouldn't make sense to because it won't succeed after that point)

An exponential backoff strategy is used until the context is cancelled with a max backoff time of 10 seconds

func MustCommit

func MustCommit(ctx context.Context, txner Txner) error

MustCommit is a convenience wrapper for Commit that returns a single error if the transaction fails OR if the transaction is rolled back. If the caller wishes to take different action depending on if the transaction failed or was rolled back then Commit() should be used instead

func New

New() returns a new context derived from the one passed as an argument and its cancel function with the context containing metadata used to build a consul transaction. If the passed context already has consul operations defined, the new context will inherit those operations defined but in a separate transaction.

func TxnErrorsToString

func TxnErrorsToString(errors api.TxnErrors) string

Types

type Txner

type Txner interface {
	Txn(txn api.KVTxnOps, q *api.QueryOptions) (bool, *api.KVTxnResponse, *api.QueryMeta, error)
}

Jump to

Keyboard shortcuts

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