Documentation ¶
Index ¶
- Constants
- type Txn
- func (t *Txn) Conn() *sqlite3.SQLiteConn
- func (t *Txn) DryRun()
- func (t *Txn) Frames(begin bool, frames *sqlite3.ReplicationFramesParams) error
- func (t *Txn) ID() uint64
- func (t *Txn) IsLeader() bool
- func (t *Txn) IsZombie() bool
- func (t *Txn) Leader()
- func (t *Txn) Resurrect(conn *sqlite3.SQLiteConn) (*Txn, error)
- func (t *Txn) State() fsm.State
- func (t *Txn) String() string
- func (t *Txn) Undo() error
- func (t *Txn) Zombie()
Constants ¶
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 (*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) IsLeader ¶
IsLeader returns true if the underlying connection is in leader replication mode.
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 ¶
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.