fsm

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCommand = fmt.Errorf("invalid command format; expected at least 4 bytes")

Functions

func MarshalEntry

func MarshalEntry(t RaftLogEntryType, payload proto.Message) ([]byte, error)

func RegisterRaftCommandHandler

func RegisterRaftCommandHandler[Req, Resp proto.Message](fsm *FSM, t RaftLogEntryType, handler RaftHandler[Req, Resp])

Types

type FSM

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

FSM implements the raft.FSM interface.

func New

func New(logger log.Logger, reg prometheus.Registerer, dir string) (*FSM, error)

func (*FSM) Apply

func (fsm *FSM) Apply(log *raft.Log) any

func (*FSM) Init

func (fsm *FSM) Init() error

Init must be called after the FSM is created and all restorers are registered.

func (*FSM) Read

func (fsm *FSM) Read(fn func(*bbolt.Tx)) error

func (*FSM) RegisterRestorer

func (fsm *FSM) RegisterRestorer(r ...StateRestorer)

func (*FSM) Restore

func (fsm *FSM) Restore(snapshot io.ReadCloser) (err error)

Restore restores the FSM state from a snapshot.

func (*FSM) Shutdown

func (fsm *FSM) Shutdown()

func (*FSM) Snapshot

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

type RaftHandler

type RaftHandler[Req, Resp proto.Message] func(*bbolt.Tx, *raft.Log, Req) (Resp, error)

RaftHandler is a function that processes a Raft command. The implementation MUST be idempotent.

type RaftLogEntry

type RaftLogEntry struct {
	Type RaftLogEntryType
	Data []byte
}

func (*RaftLogEntry) UnmarshalBinary

func (c *RaftLogEntry) UnmarshalBinary(b []byte) error

type RaftLogEntryType

type RaftLogEntryType uint32

type Response

type Response struct {
	Data proto.Message
	Err  error
}

type StateRestorer

type StateRestorer interface {
	// Init is provided with a write transaction to initialize the state.
	// FSM guarantees that Init is called synchronously and has exclusive
	// access to the database.
	Init(*bbolt.Tx) error
	// Restore is provided with a read transaction to restore the state.
	// Restore might be called concurrently with other StateRestorer
	// instances.
	Restore(*bbolt.Tx) error
}

StateRestorer is called during the FSM initialization to restore the state from a snapshot. The implementation MUST be idempotent.

Jump to

Keyboard shortcuts

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