fsm

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package fsm implements the Raft FSM.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalLogEntry

func MarshalLogEntry(logEntry *v1.RaftLogEntry) ([]byte, error)

MarshalLogEntry marshals a RaftLogEntry.

func UnmarshalLogEntry

func UnmarshalLogEntry(data []byte) (*v1.RaftLogEntry, error)

UnmarshalLogEntry unmarshals a RaftLogEntry.

Types

type ApplyLogCallback

type ApplyLogCallback func(ctx context.Context, term, index uint64, log *v1.RaftLogEntry)

ApplyLogCallback is the callback for when a log entry is applied.

type OnSnapshotRestoreCallback

type OnSnapshotRestoreCallback func(ctx context.Context, meta *raft.SnapshotMeta, data io.ReadCloser)

OnSnapshotRestoreCallback is the callback for when a snapshot is restored. TODO: This is not used yet.

type Options

type Options struct {
	// ApplyTimeout is the timeout for applying a log entry.
	ApplyTimeout time.Duration
	// OnApplyLog is the callback for when a log entry is applied.
	OnApplyLog ApplyLogCallback
	// OnSnapshotRestore is the callback for when a snapshot is restored.
	OnSnapshotRestore OnSnapshotRestoreCallback
}

Options are options for the FSM.

type RaftFSM

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

RaftFSM is the Raft FSM.

func New

func New(st storage.MeshStorage, opts Options) *RaftFSM

New returns a new RaftFSM. The storage interface must be a direct connection to the underlying database.

func (*RaftFSM) Apply

func (r *RaftFSM) Apply(l *raft.Log) any

Apply applies a Raft log entry to the store.

func (*RaftFSM) ApplyBatch

func (r *RaftFSM) ApplyBatch(logs []*raft.Log) []any

ApplyBatch implements the raft.BatchingFSM interface.

func (*RaftFSM) CurrentTerm

func (r *RaftFSM) CurrentTerm() uint64

CurrentTerm returns the current term.

func (*RaftFSM) LastAppliedIndex

func (r *RaftFSM) LastAppliedIndex() uint64

LastAppliedIndex returns the last applied index.

func (*RaftFSM) Restore

func (r *RaftFSM) Restore(rdr io.ReadCloser) error

Restore restores a Raft snapshot.

func (*RaftFSM) Snapshot

func (r *RaftFSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot returns a Raft snapshot.

Jump to

Keyboard shortcuts

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