fsm

package
v0.0.0-...-1747526 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirSize

func DirSize(path string) (int64, error)

dirSize returns the total size of all files in the given directory

Types

type Command

type Command struct {
	Type    CommandType `json:"type"`
	Payload []byte      `json:"payload"`
}

type CommandResponse

type CommandResponse struct {
	Val   []byte `json:"val"`
	Error error  `json:"error"`
}

type CommandType

type CommandType int
const (
	Query  CommandType = 0
	Insert CommandType = 1
)

type Logger

type Logger struct {
}

func (*Logger) Fatalf

func (log *Logger) Fatalf(format string, args ...interface{})

func (*Logger) Infof

func (log *Logger) Infof(format string, args ...interface{})

type SetPayload

type SetPayload struct {
	Key   []byte `json:"key"`
	Value []byte `json:"val"`
}

type StateMachine

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

func NewStateMachine

func NewStateMachine(raftAddr string, nodeId string, dir string) (*StateMachine, error)

func (*StateMachine) Apply

func (r *StateMachine) Apply(log *raft.Log) any

Apply is called once a log entry is committed by a majority of the cluster.

Apply should apply the log to the FSM. Apply must be deterministic and produce the same result on all peers in the cluster.

The returned value is returned to the client as the ApplyFuture.Response.

func (*StateMachine) Close

func (r *StateMachine) Close() error

func (*StateMachine) GetFsmIndex

func (r *StateMachine) GetFsmIndex() uint64

func (*StateMachine) ReadLocal

func (r *StateMachine) ReadLocal(key []byte) *CommandResponse

func (*StateMachine) Restore

func (r *StateMachine) Restore(reader io.ReadCloser) error

Restore is used to restore an FSM from a snapshot. It is not called concurrently with any other command. The FSM must discard all previous state before restoring the snapshot.

func (*StateMachine) Snapshot

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

Snapshot returns an FSMSnapshot used to: support log compaction, to restore the FSM to a previous state, or to bring out-of-date followers up to a recent log index.

The Snapshot implementation should return quickly, because Apply can not be called while Snapshot is running. Generally this means Snapshot should only capture a pointer to the state, and any expensive IO should happen as part of FSMSnapshot.Persist.

Apply and Snapshot are always called from the same thread, but Apply will be called concurrently with FSMSnapshot.Persist. This means the FSM should be implemented to allow for concurrent updates while a snapshot is happening.

func (*StateMachine) Stats

func (r *StateMachine) Stats() (map[string]any, error)

func (*StateMachine) UpdateFsmIndex

func (r *StateMachine) UpdateFsmIndex(index uint64)

Jump to

Keyboard shortcuts

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