Documentation
¶
Index ¶
- Variables
- type Adapter
- func (a *Adapter) Apply(cmd domain.Command, timeout time.Duration) (*domain.CommandResult, error)
- func (a *Adapter) Broadcast(msg []byte)
- func (a *Adapter) GetClusterInfo() ports.ClusterInfo
- func (a *Adapter) GetHealth() ports.HealthStatus
- func (a *Adapter) GetLeadershipInfo() ports.RaftLeadershipInfo
- func (a *Adapter) GetMetrics() ports.RaftMetrics
- func (a *Adapter) GetRaftStatus() ports.RaftStatus
- func (a *Adapter) IsLeader() bool
- func (a *Adapter) LeaderAddr() string
- func (a *Adapter) Node() *autoconsensus.Node
- func (a *Adapter) OnBroadcast(fn func(from string, msg []byte))
- func (a *Adapter) RegisterService(fn func(grpc.ServiceRegistrar))
- func (a *Adapter) SetEventManager(manager ports.EventManager)
- func (a *Adapter) Start(ctx context.Context) error
- func (a *Adapter) StateDB() *badger.DB
- func (a *Adapter) Stop() error
- func (a *Adapter) Subscribe() <-chan autoconsensus.StateChange
- func (a *Adapter) TransferLeadership() error
- func (a *Adapter) TransferLeadershipTo(serverID string) error
- type AdapterConfig
- type Config
- type FSM
- type Storage
- type StorageConfig
- type StorageFactory
- type TCPTransportProvider
Constants ¶
This section is empty.
Variables ¶
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) 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) LeaderAddr ¶ added in v0.4.78
func (*Adapter) Node ¶ added in v0.4.78
func (a *Adapter) Node() *autoconsensus.Node
func (*Adapter) OnBroadcast ¶ added in v0.4.81
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) Subscribe ¶ added in v0.4.78
func (a *Adapter) Subscribe() <-chan autoconsensus.StateChange
func (*Adapter) TransferLeadership ¶ added in v0.4.78
func (*Adapter) TransferLeadershipTo ¶ added in v0.4.78
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
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)
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 NewStorage ¶ added in v0.1.11
func NewStorage(cfg StorageConfig, logger *slog.Logger) (*Storage, error)
func (*Storage) HasExistingState ¶ added in v0.4.16
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.
type StorageConfig ¶ added in v0.3.4
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
TCPTransportProvider builds hashicorp/raft TCP transports using the controller's bind address.
func (*TCPTransportProvider) Create ¶ added in v0.3.4
func (p *TCPTransportProvider) Create(_ context.Context, opts domain.RaftControllerOptions) (raft.Transport, raft.ServerAddress, error)
Create implements the TransportProvider interface.