coord

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package coord is a two-phase-commit coordinator for two participants. It asks for votes, retries once on timeout, and commits only when both participants voted yes. New can also build it with one of two known bugs, for the acceptance tests.

Index

Constants

View Source
const Participants = 2

Participants is the number of votes a commit needs.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actions

type Actions uint64

Actions is the set of things the holder must do after a transition, one bit each. The holder performs them in declaration order. The zero value is the empty set.

const (
	ActPrepare Actions = 1 << iota
	ActCommit
	ActAbort
	ActStartTimer
	ActCancelTimer
	ActModeChanged
)

Actions values.

type Bug

type Bug uint8

Bug selects a seeded defect. NoBug is the correct coordinator.

const (
	NoBug           Bug
	CommitOnTimeout // commits on a timeout after one yes vote
	SkipRecovery    // returns from Retrying straight to Collecting
)

Bug values.

type Event

type Event uint8

Event is an input to Fire.

const (
	EvStart Event
	EvYes
	EvNo
	EvTimeout
	EvResume
)

Event values.

type Machine

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

Machine is one coordinator. Build it with New and change it only with Fire.

func New

func New(b Bug) Machine

New returns a coordinator in Init. Pass NoBug for the correct one, or a seeded bug for the acceptance tests.

func (Machine) Fire

func (m Machine) Fire(e Event) (Machine, Actions, fsm.Outcome)

Fire applies e and returns the next machine, its actions and what happened.

func (Machine) Mode

func (m Machine) Mode() Mode

Mode derives the mode from the state.

func (Machine) State

func (m Machine) State() State

State returns the control state.

func (Machine) Yes

func (m Machine) Yes() int64

Yes returns the yes votes counted in this round.

type Mode

type Mode uint8

Mode is derived from State.

const (
	Normal Mode
	Degraded
	Recovery
	Closed
)

Mode values.

func (Mode) String

func (m Mode) String() string

type State

type State uint8

State is the coordinator's control state.

const (
	Init State
	Collecting
	Retrying
	Recovering
	Committed
	Aborted
)

State values.

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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