java.lang.Object
org.jgroups.protocols.raft.RaftImpl
Base class for the different roles a RAFT node can have (follower, candidate, leader)
- Since:
- 0.1
- Author:
- Bela Ban
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Called before getting destroyed (on a role change)protected longgetFirstIndexOfConflictingTerm(long start_index, long conflicting_term) Finds the first index at which conflicting_term starts, going back from start_index towards the head of the log, not not going lower than commit-indexhandleAppendEntriesRequest(LogEntries entries, org.jgroups.Address leader, long prev_index, long prev_term, long entry_term, long leader_commit) Called (on a follower) when an AppendEntries request is receivedvoidhandleAppendEntriesResponse(org.jgroups.Address sender, long term, AppendResult result) voidhandleInstallSnapshotRequest(org.jgroups.Message msg, org.jgroups.Address leader, long last_included_index, long last_included_term) Called when a snapshot sent by the leader is received by a follower.voidinit()Called right after instantiationraft()
-
Field Details
-
raft
-
-
Constructor Details
-
RaftImpl
-
-
Method Details
-
raft
-
raft
-
init
public void init()Called right after instantiation -
destroy
public void destroy()Called before getting destroyed (on a role change) -
handleAppendEntriesRequest
public AppendResult handleAppendEntriesRequest(LogEntries entries, org.jgroups.Address leader, long prev_index, long prev_term, long entry_term, long leader_commit) Called (on a follower) when an AppendEntries request is received- Parameters:
entries- The data (commands to be appended to the log)leader- The leader's address (= the sender)prev_index- The index of the previous log entryprev_term- The term of the previous log entryentry_term- The term of the entryleader_commit- The leader's commit_index- Returns:
- AppendResult A result (true or false), or null if the request was ignored (e.g. due to lower term)
-
handleAppendEntriesResponse
-
handleInstallSnapshotRequest
public void handleInstallSnapshotRequest(org.jgroups.Message msg, org.jgroups.Address leader, long last_included_index, long last_included_term) Called when a snapshot sent by the leader is received by a follower. The follower needs to overwrite its snapshot file with the received bytes and reinitialize its log to last_inluded_index and create a dummy LogEntry with last_included_term at last_included_index. This is needed by the nexthandleAppendEntriesRequest(LogEntries, Address, int, int, int, int)call to compare to the previous index and term.- Parameters:
msg- The snapshot message sent by the leaderleader- The leader (= sender of the message)last_included_index- The last index that's reflected in the state (=snapshot) sent by the leader. Indices first_appended, commit_index and last_appended have to be set to last_included_indexlast_included_term- The last included term. The dummy entry needs to have this term, for comparison in the next handleAppendRequest() call.
-
getFirstIndexOfConflictingTerm
protected long getFirstIndexOfConflictingTerm(long start_index, long conflicting_term) Finds the first index at which conflicting_term starts, going back from start_index towards the head of the log, not not going lower than commit-index
-