fsm

package
v0.0.0-...-b2d9faf Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound error = fmt.Errorf("item not found")

Functions

This section is empty.

Types

type FSM

type FSM struct {
	VMs map[string]int `json:"vms,omitempty" yaml:"vms,omitempty"`
	// contains filtered or unexported fields
}

FSM is a Raft Finite State Machine (FSM).

func New

func New() *FSM

New creates a new Finite State Machine (FSM).

func (*FSM) Apply

func (f *FSM) Apply(l *raft.Log) interface{}

Apply log is invoked once a Raft log entry is committed. It returns a value which will be made available in the ApplyFuture returned by Raft.Apply method if that method was called on the same Raft node as the FSM.

func (*FSM) Get

func (f *FSM) Get(key string) (int, error)

Get retrieves an item from the internal store, if available; it does not have to go through the Leader, since all Followers have the same data as the Leader and there is no mutation involved.

func (*FSM) Persist

func (f *FSM) Persist(sink raft.SnapshotSink) error

Persist should write all items to the given sink and then close it; it might acquire a lock to prevent concurrent updates, since it this function could be called with concurrent calls to Apply

func (*FSM) Release

func (f *FSM) Release()

Release is invoked when we are finished with the snapshot; it could be used to release a lock that might have been acquired when starting to Persist (to avoid problems with concurrent calls to Apply).

func (*FSM) Restore

func (f *FSM) Restore(reader io.ReadCloser) error

Restore is called to erase the current FSM internal status and to load it with external data as per the provided reader.

func (*FSM) Snapshot

func (f *FSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot will be called to create a snapshot of the FSM internal status; it must return an object that is capable of saving the FSM internal status while there MAY be concurrent calls to Apply; in our simplistic case, the FSM is capable of snapshotting itself.

Jump to

Keyboard shortcuts

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