transaction

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Pending = fsm.State("pending") // Initial state right after creation.
	Writing = fsm.State("writing") // After a non-commit frames command has been executed.
	Written = fsm.State("written") // After a final commit frames command has been executed.
	Undone  = fsm.State("undone")  // After an undo command has been executed.
	Doomed  = fsm.State("doomed")  // The transaction has errored.
)

Possible transaction states. Most states are associated with SQLite replication hooks that are invoked upon transitioning from one lifecycle state to the next.

Variables

This section is empty.

Functions

This section is empty.

Types

type Txn

type Txn struct {
	// contains filtered or unexported fields
}

Txn captures information about an active WAL write transaction that has been started on a SQLite connection configured to be in either leader or follower replication mode.

func New

func New(conn *sqlite3.SQLiteConn, id uint64) *Txn

New creates a new Txn instance.

func (*Txn) Conn

func (t *Txn) Conn() *sqlite3.SQLiteConn

Conn returns the sqlite connection that started this write transaction.

func (*Txn) DryRun

func (t *Txn) DryRun()

DryRun makes this transaction only transition between states, without actually invoking the relevant SQLite APIs.

This is used to create a surrogate follower, and for tests.

func (*Txn) Frames

func (t *Txn) Frames(begin bool, frames *sqlite3.ReplicationFramesParams) error

Frames writes frames to the WAL.

func (*Txn) ID

func (t *Txn) ID() uint64

ID returns the ID associated with this transaction.

func (*Txn) IsLeader

func (t *Txn) IsLeader() bool

IsLeader returns true if the underlying connection is in leader replication mode.

func (*Txn) IsZombie

func (t *Txn) IsZombie() bool

IsZombie returns true if this is a zombie transaction.

func (*Txn) Leader

func (t *Txn) Leader()

Leader marks this transaction as a leader transaction.

A leader transaction is automatically set to dry-run, since the SQLite will trigger itself the relevant WAL APIs when transitioning between states.

Depending on the particular replication hook being executed SQLite might do that before or after the hook. See src/pager.c in SQLite source code for details about when WAL APis are invoked exactly with respect to the various sqlite3_replication_methods hooks.

func (*Txn) Resurrect

func (t *Txn) Resurrect(conn *sqlite3.SQLiteConn) (*Txn, error)

Resurrect a zombie transaction.

This should be called only on zombie transactions in Pending or Writing state, in case a leader that lost leadership was re-elected right away or a quorum for a lost commit frames command was reached and the new leader is replicating it on the former leader.

A new follower transaction will be created with the given connection (which is assumed to be in follower replication mode), and set to the same ID as this zombie.

All preceeding non-commit frames commands (if any) will be re-applied on the follower transaction.

If no error occurrs, the newly created follower transaction is returned.

func (*Txn) State

func (t *Txn) State() fsm.State

State returns the current state of the transaction.

func (*Txn) String

func (t *Txn) String() string

func (*Txn) Undo

func (t *Txn) Undo() error

Undo reverts all changes to the WAL since the start of the transaction.

func (*Txn) Zombie

func (t *Txn) Zombie()

Zombie marks this transaction as zombie. It must be called only for leader transactions.

A zombie transaction is one whose leader has lost leadership while applying the associated FSM command. The transaction is left in state passed as argument.

Jump to

Keyboard shortcuts

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