Documentation ¶
Index ¶
- Variables
- func MarshalEntry(t RaftLogEntryType, payload proto.Message) ([]byte, error)
- func RegisterRaftCommandHandler[Req, Resp proto.Message](fsm *FSM, t RaftLogEntryType, handler RaftHandler[Req, Resp])
- type FSM
- func (fsm *FSM) Apply(log *raft.Log) any
- func (fsm *FSM) Init() error
- func (fsm *FSM) Read(fn func(*bbolt.Tx)) error
- func (fsm *FSM) RegisterRestorer(r ...StateRestorer)
- func (fsm *FSM) Restore(snapshot io.ReadCloser) (err error)
- func (fsm *FSM) Shutdown()
- func (fsm *FSM) Snapshot() (raft.FSMSnapshot, error)
- type RaftHandler
- type RaftLogEntry
- type RaftLogEntryType
- type Response
- type StateRestorer
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidCommand = fmt.Errorf("invalid command format; expected at least 4 bytes")
Functions ¶
func MarshalEntry ¶
func MarshalEntry(t RaftLogEntryType, payload proto.Message) ([]byte, error)
func RegisterRaftCommandHandler ¶
func RegisterRaftCommandHandler[Req, Resp proto.Message](fsm *FSM, t RaftLogEntryType, handler RaftHandler[Req, Resp])
Types ¶
type FSM ¶
type FSM struct {
// contains filtered or unexported fields
}
FSM implements the raft.FSM interface.
func New ¶
func New(logger log.Logger, reg prometheus.Registerer, dir string) (*FSM, error)
func (*FSM) RegisterRestorer ¶
func (fsm *FSM) RegisterRestorer(r ...StateRestorer)
type RaftHandler ¶
RaftHandler is a function that processes a Raft command. The implementation MUST be idempotent.
type RaftLogEntry ¶
type RaftLogEntry struct { Type RaftLogEntryType Data []byte }
func (*RaftLogEntry) UnmarshalBinary ¶
func (c *RaftLogEntry) UnmarshalBinary(b []byte) error
type RaftLogEntryType ¶
type RaftLogEntryType uint32
type StateRestorer ¶
type StateRestorer interface { // Init is provided with a write transaction to initialize the state. // FSM guarantees that Init is called synchronously and has exclusive // access to the database. Init(*bbolt.Tx) error // Restore is provided with a read transaction to restore the state. // Restore might be called concurrently with other StateRestorer // instances. Restore(*bbolt.Tx) error }
StateRestorer is called during the FSM initialization to restore the state from a snapshot. The implementation MUST be idempotent.
Click to show internal directories.
Click to hide internal directories.