transaction

package
v0.0.0-...-cd0f3b4 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2016 License: GPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package transaction implements a distributed transaction handling framework

Index

Constants

View Source
const (
	//Leader is a constant string representing the leader node
	Leader = "leader"
	//All is a contant string representing all the nodes in a transaction
	All = "all"
)

Variables

This section is empty.

Functions

func CreateLockStepFunc

func CreateLockStepFunc(key string) (StepFunc, StepFunc, error)

CreateLockStepFunc returns a lock and an unlock StepFunc which lock/unlock the given key

func CreateLockSteps

func CreateLockSteps(key string) (*Step, *Step, error)

CreateLockSteps retuns a lock and an unlock Step which lock/unlock the given key

Types

type SimpleTxn

type SimpleTxn struct {
	// Ctx is the transaction context
	Ctx *context.Context
	// Nodes are the nodes where the stage and commit functions are performed
	Nodes []string
	// LockKey is the key to be locked
	LockKey string

	// Stage function verifies if the node can perform an operation.
	Stage StepFunc
	// Commit performs the operation on the a node
	Commit StepFunc
	// Store stores the results of an operation. This will only be run on the leader
	Store StepFunc
	// Rollback rollsback any changes done by Commit
	Rollback StepFunc
}

SimpleTxn is transaction with fixed stage, commit and store steps

func (*SimpleTxn) Do

func (s *SimpleTxn) Do() error

Do runs the SimpleTxn on the cluster

type Step

type Step struct {
	DoFunc   StepFunc
	UndoFunc StepFunc
	Nodes    []string
}

Step is a combination of a StepFunc and a list of nodes the step is supposed to be run on

DoFunc performs does the action UndoFunc undoes anything done by DoFunc

type StepFunc

type StepFunc func(*context.Context) error

StepFunc is the function that is supposed to be run during a transaction step

type Txn

type Txn struct {
	Ctx   *context.Context
	Steps []*Step
	Nodes []string
}

Txn is a set of steps

Nodes is a union of the all the TxnStep.Nodes

func NewSimpleTxn

func NewSimpleTxn(c *context.Context, nodes []string, lockKey string, stage, commit, store, rollback StepFunc) (*Txn, error)

NewSimpleTxn returns creates and returns a Txn using e Simple transaction template

func (*Txn) Do

func (t *Txn) Do() error

Do runs the transaction on the cluster

Jump to

Keyboard shortcuts

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