Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type StateManager ¶
type StateManager struct {
// contains filtered or unexported fields
}
StateManager handles the aspects of the Raft protocol that require timing
func NewStateManager ¶
func NewStateManager( resetFlag chan bool, electionTimeout time.Duration, electionJob func() bool, graceWindow time.Duration, graceEndJob func(), appendInterval time.Duration, appendJob func()) *StateManager
NewStateManager creates a StateManager with state initialized to Follower followFlag is a channel that indicates the node should reset the election timer, including becoming a Follower if the current state is Leader
electionTimeout is the duration a node should wait before starting an election. Events that delay an election should call `ResetTimer`. If the timer expires, the electionJob function is called
electionJob is a function that is called when the election timer expires, which should return a boolean designating whether the node should become a Leader (on true), or remain a Follower (on false)
appendInterval is the period between append requests when a node is a Leader
The ticker ticks on this period, and calls appendJob ¶
appendJob is the task that a Leader should perform after each appendInterval
func (*StateManager) BecomeFollower ¶
func (s *StateManager) BecomeFollower()
BecomeFollower explicitly changes the state to Follower
func (*StateManager) ResetTimer ¶
func (s *StateManager) ResetTimer()
ResetTimer restarts the countdown on the election timer if the current state is Follower (does nothing if the current state is Leader)