Documentation ¶
Index ¶
- func DirSize(path string) (int64, error)
- type Command
- type CommandResponse
- type CommandType
- type Logger
- type SetPayload
- type StateMachine
- func (r *StateMachine) Apply(log *raft.Log) any
- func (r *StateMachine) Close() error
- func (r *StateMachine) GetFsmIndex() uint64
- func (r *StateMachine) ReadLocal(key []byte) *CommandResponse
- func (r *StateMachine) Restore(reader io.ReadCloser) error
- func (r *StateMachine) Snapshot() (raft.FSMSnapshot, error)
- func (r *StateMachine) Stats() (map[string]any, error)
- func (r *StateMachine) UpdateFsmIndex(index uint64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Command ¶
type Command struct { Type CommandType `json:"type"` Payload []byte `json:"payload"` }
type CommandResponse ¶
type SetPayload ¶
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) UpdateFsmIndex ¶
func (r *StateMachine) UpdateFsmIndex(index uint64)