fsm

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 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 ApplyCallback added in v0.3.1

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

ApplyCallback is a callback that can be registered for everytime a log is applied to the state machine.

type Options

type Options struct {
	// ApplyTimeout is the timeout for applying a log entry.
	ApplyTimeout time.Duration
	// OnApplyLog are the callbacks for when a log entry is applied.
	OnApplyLog ApplyCallback
	// OnSnapshotRestore are the callbacks for when a snapshot is restored.
	OnSnapshotRestore SnapshotRestoreCallback
}

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(ctx context.Context, 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.

type SnapshotRestoreCallback added in v0.3.1

type SnapshotRestoreCallback func(ctx context.Context)

SnapshotRestoreCallback is a callback that can be registered for when a snapshot is restored.

Jump to

Keyboard shortcuts

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