Documentation
¶
Index ¶
- type Observer
- type Options
- type OptionsFn
- type RaftNode
- func (r *RaftNode) CopyPeers() map[uint]string
- func (r *RaftNode) GetCurrentTerm() uint64
- func (r *RaftNode) GetID() int32
- func (r *RaftNode) GetLastApplied() uint64
- func (r *RaftNode) GetLeaderID() int32
- func (r *RaftNode) GetLog() []log.LogEntry
- func (r *RaftNode) GetLogByIndex(index uint64) log.LogEntry
- func (r *RaftNode) GetPeers() map[uint]string
- func (r *RaftNode) GetState() (uint64, bool)
- func (r *RaftNode) GetVotedFor() int32
- func (r *RaftNode) IsLeader() bool
- func (r *RaftNode) IsStopped() bool
- func (r *RaftNode) Run(ctx context.Context, secure bool) error
- func (r *RaftNode) SetCurrentTerm(term uint64)
- func (r *RaftNode) SetLastApplied(index uint64)
- func (r *RaftNode) SetLog(log []log.LogEntry)
- func (r *RaftNode) SetVotedFor(id int32)
- func (r *RaftNode) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Observer ¶
type Observer interface { // Notify is called when the fsm observes a change in leadership. Notify(state bool) }
Observer is an interface that is notified when the RaftNode observes a change in leadership. It is used to notify the leader health service.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options holds the configurable options for a RaftNode.
type OptionsFn ¶
type OptionsFn func(opt Options)
OptionsFn is a function that sets an option.
func WithBufferSize ¶
WithBufferSize sets the size of the commit channel.
func WithElectionTimeout ¶
WithElectionTimeout sets the election timeout for the RaftNode.
func WithHeartbeatTimeout ¶
WithHeartbeatTimeout sets the heartbeat timeout for the RaftNode.
func WithTimeout ¶
WithTimeout sets the timeout for the RaftNode.
type RaftNode ¶
type RaftNode struct { // RPCServer is the server used to communicate with other peers. RPCServer server.Server // commitChan is a channel that receives committed entries from the RaftNode to be applied to the state machine. // It is buffered to allow the RaftNode to continue committing entries while the state machine is busy. CommitChan chan log.LogEntry Options // contains filtered or unexported fields }
RaftNode is a member of the Raft cluster
func New ¶
func New(peers map[uint]string, id int32, port uint16, storage storage.Store, logger *slog.Logger, opts ...OptionsFn) (*RaftNode, error)
New creates a new RaftNode.
func (*RaftNode) GetCurrentTerm ¶
func (*RaftNode) GetLastApplied ¶
func (*RaftNode) GetLeaderID ¶
func (*RaftNode) GetState ¶
GetState returns the currentTerm and whether this server believes it is the leader.
func (*RaftNode) GetVotedFor ¶
func (*RaftNode) SetCurrentTerm ¶
func (*RaftNode) SetLastApplied ¶
func (*RaftNode) SetVotedFor ¶
Click to show internal directories.
Click to hide internal directories.