TwoPhaseCommit (two_phase_commit v0.1.0) View Source
A simple state machine representing the state of a two-phase commit, as well as providing next steps to be taken in the case of a coordinator recovery after a crash.
Link to this section Summary
Functions
Records a participant's "abort" vote and moves the transaction to the rolling_back state.
Adds a participant to the transaction while it's in the interactive phase.
Notes that a participant has committed, moves to the committed state when all have committed.
Creates a new TwoPhaseCommit state structs with the given participants
.
Indicates what actions need to be performed next in order to move the transaction forward.
Returns a list of all participants.
Moves the transaction to the voting phase.
Records a participant's "prepared" vote, moves to the committing phase when all are prepared.
Notes that a participant has rolled back, moves to the aborted state when all have rolled back.
Link to this section Types
Specs
client() :: any()
Specs
id() :: any()
Specs
next_action() :: :write_data | {:vote | :roll_back | :commit, participants()} | nil
Specs
Specs
opts() :: [opt()]
Specs
participant() :: any()
Specs
participants() :: [participant()]
Specs
state() :: :interactive | {:voting | :rolling_back | :committing, MapSet.t(participant())} | :aborted | :committed
Specs
Link to this section Functions
Specs
aborted(t(), participant()) :: t() | {:error, :unknown_participant}
Records a participant's "abort" vote and moves the transaction to the rolling_back state.
Specs
add_participant(t(), participant()) :: t()
Adds a participant to the transaction while it's in the interactive phase.
Specs
committed(t(), participant()) :: t() | {:error, :unknown_participant}
Notes that a participant has committed, moves to the committed state when all have committed.
Specs
new(participants(), opts()) :: t()
Creates a new TwoPhaseCommit state structs with the given participants
.
The following keyword parameters can be provided:
:id
- stores the transaction id (globally unique)
:client
- stores an arbitrary identifying the requesting entity (a pid, etc)
Specs
next_action(t()) :: next_action()
Indicates what actions need to be performed next in order to move the transaction forward.
This is useful for the coordinator to determine where the transaction left off after recovering from a crash.
Specs
participants(t()) :: participants()
Returns a list of all participants.
Specs
Moves the transaction to the voting phase.
Specs
prepared(t(), participant()) :: t() | {:error, :unknown_participant}
Records a participant's "prepared" vote, moves to the committing phase when all are prepared.
Specs
rolled_back(t(), participant()) :: t() | {:error, :unknown_participant}
Notes that a participant has rolled back, moves to the aborted state when all have rolled back.