raft

package
v0.0.0-...-92cd712 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	NodeID    string
	RaftAddr  string
	RaftDir   string
	Bootstrap bool
	Peers     []string
}

Config represents the configuration for a Raft node

type FSM

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

FSM implements the raft.FSM interface for our 3D printing application

func NewFSM

func NewFSM() *FSM

NewFSM creates a new Finite State Machine for the Raft cluster

func (*FSM) Apply

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

Apply applies a Raft log entry to the FSM

func (*FSM) GetFilaments

func (f *FSM) GetFilaments() []*models.Filament

GetFilaments returns all filaments

func (*FSM) GetPrintJob

func (f *FSM) GetPrintJob(id string) (*models.PrintJob, bool)

GetPrintJob returns a print job by ID

func (*FSM) GetPrintJobs

func (f *FSM) GetPrintJobs() []*models.PrintJob

GetPrintJobs returns all print jobs

func (*FSM) GetPrintJobsByStatus

func (f *FSM) GetPrintJobsByStatus(status string) []*models.PrintJob

GetPrintJobsByStatus returns print jobs filtered by status

func (*FSM) GetPrinters

func (f *FSM) GetPrinters() []*models.Printer

GetPrinters returns all printers

func (*FSM) Restore

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

Restore restores the FSM from a snapshot

func (*FSM) Snapshot

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

Snapshot returns a snapshot of the FSM state

type Node

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

Node represents a node in the Raft cluster

func NewNode

func NewNode(config *Config) (*Node, error)

NewNode creates a new Raft node

func (*Node) Apply

func (n *Node) Apply(cmd *models.Command) error

Apply applies a command to the Raft log

func (*Node) GetFSM

func (n *Node) GetFSM() *FSM

GetFSM returns the FSM

func (*Node) Leader

func (n *Node) Leader() bool

Leader returns true if this node is the leader

func (*Node) LeaderAddress

func (n *Node) LeaderAddress() string

LeaderAddress returns the address of the current leader

func (*Node) Shutdown

func (n *Node) Shutdown() error

Shutdown stops the Raft node

func (*Node) State

func (n *Node) State() raft.RaftState

State returns the current state of the Raft node

type Store

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

Store provides an interface for storing and retrieving Raft data

func NewStore

func NewStore(path string) (*Store, error)

NewStore creates a new store

func (*Store) Backup

func (s *Store) Backup(w io.Writer) error

Backup creates a backup of the store

func (*Store) Close

func (s *Store) Close() error

Close closes the store

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes a key-value pair

func (*Store) Get

func (s *Store) Get(key string) ([]byte, error)

Get retrieves a value by key

func (*Store) Keys

func (s *Store) Keys() []string

Keys returns all keys in the store

func (*Store) LoadSnapshot

func (s *Store) LoadSnapshot() ([]byte, error)

LoadSnapshot loads the latest snapshot

func (*Store) LoadState

func (s *Store) LoadState() (raft.Configuration, error)

LoadState loads the persisted Raft server configuration

func (*Store) PersistState

func (s *Store) PersistState(state raft.Configuration) error

PersistState persists the Raft server configuration

func (*Store) Restore

func (s *Store) Restore(r io.Reader) error

Restore restores the store from a backup

func (*Store) Set

func (s *Store) Set(key string, val []byte) error

Set stores a key-value pair

func (*Store) StoreSnapshot

func (s *Store) StoreSnapshot(data []byte) error

StoreSnapshot stores a snapshot of the current state

type Transport

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

Transport provides methods for forwarding requests to the Raft leader

func NewTransport

func NewTransport(node *Node) *Transport

NewTransport creates a new Transport

func (*Transport) ForwardToLeader

func (t *Transport) ForwardToLeader(method, path string, body []byte) ([]byte, error)

ForwardToLeader forwards a request to the Raft leader

func (*Transport) JoinCluster

func (t *Transport) JoinCluster(nodeID, nodeAddr string) error

JoinCluster joins a node to the Raft cluster

func (*Transport) LeaveCluster

func (t *Transport) LeaveCluster(nodeID string) error

LeaveCluster removes a node from the Raft cluster

func (*Transport) RaftHandler

func (t *Transport) RaftHandler() http.Handler

RaftHandler returns an HTTP handler for Raft-related operations

Jump to

Keyboard shortcuts

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