public interface StateMachine
| 限定符和类型 | 方法和说明 |
|---|---|
void |
onApply(Iterator iter)
Update the StateMachine with a batch a tasks that can be accessed
through |iterator|.
|
void |
onConfigurationCommitted(Configuration conf)
Invoked when a configuration has been committed to the group.
|
void |
onError(RaftException e)
This method is called when a critical error was encountered, after this
point, no any further modification is allowed to applied to this node
until the error is fixed and this node restarts.
|
void |
onLeaderStart(long term)
Invoked when the belonging node becomes the leader of the group at |term|
Default: Do nothing
|
void |
onLeaderStop(Status status)
Invoked when this node steps down from the leader of the replication
group and |status| describes detailed information
|
void |
onShutdown()
Invoked once when the raft node was shut down.
|
boolean |
onSnapshotLoad(SnapshotReader reader)
User defined snapshot load function
get and load snapshot
Default: Load nothing and returns error.
|
void |
onSnapshotSave(SnapshotWriter writer,
Closure done)
User defined snapshot generate function, this method will block StateMachine#onApply(Iterator).
|
void |
onStartFollowing(LeaderChangeContext ctx)
This method is called when a follower or candidate starts following a leader and its leaderId
(should be NULL before the method is called) is set to the leader's id,
situations including:
1. a candidate receives appendEntries request from a leader
2. a follower(without leader) receives appendEntries from a leader
the parameter ctx gives the information(leaderId, term and status) about
the very leader whom the follower starts to follow.
|
void |
onStopFollowing(LeaderChangeContext ctx)
This method is called when a follower stops following a leader and its leaderId becomes null,
situations including:
1. handle election timeout and start preVote
2. receive requests with higher term such as VoteRequest from a candidate
or appendEntries request from a new leader
3. receive timeoutNow request from current leader and start request vote.
|
void onApply(Iterator iter)
iter - iterator of statesvoid onShutdown()
void onSnapshotSave(SnapshotWriter writer, Closure done)
writer - snapshot writerdone - callbackboolean onSnapshotLoad(SnapshotReader reader)
reader - snapshot readervoid onLeaderStart(long term)
term - new term numvoid onLeaderStop(Status status)
status - status infovoid onError(RaftException e)
e - raft error messagevoid onConfigurationCommitted(Configuration conf)
conf - committed configurationvoid onStopFollowing(LeaderChangeContext ctx)
ctx - context of leader changevoid onStartFollowing(LeaderChangeContext ctx)
ctx - context of leader changeCopyright © 2021. All rights reserved.