raft

package
v0.4.96 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotRunning   = errors.New("raft: not running")
	ErrNodeNotFound = errors.New("raft: node not found in configuration")
)

Functions

This section is empty.

Types

type Adapter

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

func NewAdapter

func NewAdapter(cfg AdapterConfig, eventManager ports.EventManager) (*Adapter, error)

func (*Adapter) Apply

func (a *Adapter) Apply(cmd domain.Command, timeout time.Duration) (*domain.CommandResult, error)

func (*Adapter) Broadcast added in v0.4.81

func (a *Adapter) Broadcast(msg []byte)

func (*Adapter) GetClusterInfo

func (a *Adapter) GetClusterInfo() ports.ClusterInfo

func (*Adapter) GetHealth added in v0.4.78

func (a *Adapter) GetHealth() ports.HealthStatus

func (*Adapter) GetLeadershipInfo added in v0.4.78

func (a *Adapter) GetLeadershipInfo() ports.RaftLeadershipInfo

func (*Adapter) GetMetrics added in v0.4.78

func (a *Adapter) GetMetrics() ports.RaftMetrics

func (*Adapter) GetRaftStatus added in v0.4.78

func (a *Adapter) GetRaftStatus() ports.RaftStatus

func (*Adapter) IsLeader

func (a *Adapter) IsLeader() bool

func (*Adapter) LeaderAddr added in v0.4.78

func (a *Adapter) LeaderAddr() string

func (*Adapter) Node added in v0.4.78

func (a *Adapter) Node() *autoconsensus.Node

func (*Adapter) OnBroadcast added in v0.4.81

func (a *Adapter) OnBroadcast(fn func(from string, msg []byte))

func (*Adapter) RegisterService added in v0.4.81

func (a *Adapter) RegisterService(fn func(grpc.ServiceRegistrar))

func (*Adapter) SetEventManager added in v0.4.78

func (a *Adapter) SetEventManager(manager ports.EventManager)

func (*Adapter) Start

func (a *Adapter) Start(ctx context.Context) error

func (*Adapter) StateDB added in v0.4.78

func (a *Adapter) StateDB() *badger.DB

func (*Adapter) Stop

func (a *Adapter) Stop() error

func (*Adapter) Subscribe added in v0.4.78

func (a *Adapter) Subscribe() <-chan autoconsensus.StateChange

func (*Adapter) TransferLeadership added in v0.4.78

func (a *Adapter) TransferLeadership() error

func (*Adapter) TransferLeadershipTo added in v0.4.78

func (a *Adapter) TransferLeadershipTo(serverID string) error

type AdapterConfig added in v0.4.78

type AdapterConfig struct {
	NodeID        string
	GossipPort    int
	SecretKey     []byte
	AdvertiseAddr string
	Discoverer    autoconsensus.Discoverer
	DataDir       string
	InMemory      bool
	ClusterID     string
	ClusterPolicy domain.ClusterPolicy
	Logger        *slog.Logger
}

type Config

type Config struct {
	NodeID              string
	ClusterID           string
	BindAddr            string
	AdvertiseAddr       string
	DataDir             string
	ClusterPolicy       domain.ClusterPolicy
	SnapshotInterval    time.Duration
	SnapshotThreshold   uint64
	MaxSnapshots        int
	MaxJoinAttempts     int
	HeartbeatTimeout    time.Duration
	ElectionTimeout     time.Duration
	CommitTimeout       time.Duration
	MaxAppendEntries    int
	ShutdownOnRemove    bool
	TrailingLogs        uint64
	LeaderLeaseTimeout  time.Duration
	IgnoreExistingState bool
	InMemoryStorage     bool
}

Config mirrors the legacy raft adapter configuration so the manager can continue to construct nodes without large refactors while the underlying implementation is replaced by raft components.

func DefaultRaftConfig

func DefaultRaftConfig(nodeID, clusterID, bindAddr, advertiseAddr, dataDir string, clusterPolicy domain.ClusterPolicy) *Config

DefaultRaftConfig reproduces the old helper so existing callers continue to compile. Values feed into raft runtime configuration internally.

type FSM added in v0.1.11

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

FSM implements raft.FSM for the raft subsystem. It mirrors the behaviour of the legacy adapter while living entirely within the new package.

func NewFSM added in v0.1.11

func NewFSM(db *badger.DB, eventManager ports.EventManager, nodeID, clusterID string, policy domain.ClusterPolicy, logger *slog.Logger) *FSM

NewFSM constructs a new FSM instance bound to the provided Badger database.

func (*FSM) Apply added in v0.1.11

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

Apply executes a replicated command and returns a domain.CommandResult.

func (*FSM) Restore added in v0.1.11

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

Restore loads a snapshot back into memory and persistent storage.

func (*FSM) SetEventManager added in v0.3.4

func (f *FSM) SetEventManager(manager ports.EventManager)

func (*FSM) Snapshot added in v0.1.11

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

Snapshot captures the full state for Raft log compaction.

type Storage added in v0.1.11

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

Storage encapsulates the resources backing a raft node.

func NewInMemoryStorage added in v0.4.60

func NewInMemoryStorage(logger *slog.Logger) (*Storage, error)

func NewStorage added in v0.1.11

func NewStorage(cfg StorageConfig, logger *slog.Logger) (*Storage, error)

func (*Storage) Close added in v0.1.11

func (s *Storage) Close() error

Close releases all resources held by the storage instance.

func (*Storage) HasExistingState added in v0.4.16

func (s *Storage) HasExistingState() bool

HasExistingState reports whether any durable raft state has been persisted. It inspects the log and snapshot stores, tolerating empty stores when the node has never bootstrapped before.

func (*Storage) StateDB added in v0.1.11

func (s *Storage) StateDB() *badger.DB

type StorageConfig added in v0.3.4

type StorageConfig struct {
	DataDir  string
	InMemory bool
}

StorageConfig captures the directories used by the storage implementation.

type StorageFactory added in v0.4.78

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

func NewStorageFactory added in v0.4.78

func NewStorageFactory(dataDir string, inMemory bool, logger *slog.Logger) *StorageFactory

func (*StorageFactory) Close added in v0.4.78

func (f *StorageFactory) Close() error

func (*StorageFactory) Create added in v0.4.78

func (f *StorageFactory) Create() (autoconsensus.Storages, error)

func (*StorageFactory) Reset added in v0.4.78

func (f *StorageFactory) Reset() error

func (*StorageFactory) StateDB added in v0.4.78

func (f *StorageFactory) StateDB() *badger.DB

type TCPTransportProvider added in v0.3.4

type TCPTransportProvider struct {
	MaxPool int
	Timeout time.Duration
}

TCPTransportProvider builds hashicorp/raft TCP transports using the controller's bind address.

func (*TCPTransportProvider) Create added in v0.3.4

Create implements the TransportProvider interface.

Jump to

Keyboard shortcuts

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