Package io.permazen.kv.raft.msg
Class AppendResponse
java.lang.Object
io.permazen.kv.raft.msg.Message
io.permazen.kv.raft.msg.AppendResponse
Sent from a follower to a leader in response to an
AppendRequest
.
Also contains information about the follower's log.
-
Constructor Summary
ConstructorDescriptionAppendResponse
(int clusterId, String senderId, String recipientId, long term, Timestamp leaderTimestamp, boolean success, long matchIndex, long lastLogIndex) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
calculateSize
(int version) Calculate the number of bytes required bywriteTo()
.long
Get the index of the last log entry in the follower's log.Get theleaderTimestamp
from the correspondingAppendRequest
.long
Get the index of the most recent log entry known to match leader.boolean
Determine whether the request was successful, i.e., the previous log entry term and index matched.toString()
void
visit
(MessageSwitch handler) Apply the visitor pattern based on this instance's type.void
writeTo
(ByteBuffer dest, int version) Serialize this instance into the given buffer.Methods inherited from class io.permazen.kv.raft.msg.Message
calculateSize, calculateSize, calculateSize, decode, decodeProtocolVersion, encode, getBoolean, getByteBuffer, getClusterId, getCurrentProtocolVersion, getRecipientId, getSenderId, getString, getTerm, getTimestamp, isLeaderMessage, putBoolean, putByteBuffer, putString, putTimestamp
-
Constructor Details
-
AppendResponse
public AppendResponse(int clusterId, String senderId, String recipientId, long term, Timestamp leaderTimestamp, boolean success, long matchIndex, long lastLogIndex) Constructor.- Parameters:
clusterId
- cluster IDsenderId
- identity of senderrecipientId
- identity of recipientterm
- sender's current termleaderTimestamp
- copy ofAppendRequest.getLeaderTimestamp()
success
- if request successfully matchedmatchIndex
- highest known matching log indexlastLogIndex
- index of follower's last log entry
-
-
Method Details
-
getLeaderTimestamp
Get theleaderTimestamp
from the correspondingAppendRequest
.- Returns:
- request leader timestamp
- See Also:
-
isSuccess
public boolean isSuccess()Determine whether the request was successful, i.e., the previous log entry term and index matched.- Returns:
- true if the corresponding request matched
-
getMatchIndex
public long getMatchIndex()Get the index of the most recent log entry known to match leader. In case of a successful request, this will be equal to the log entry sent (or the previous log entry in case of a probe). In case of a failed request, this will be equal to the follower's state machine last applied index.- Returns:
- highest known matching log entry index
-
getLastLogIndex
public long getLastLogIndex()Get the index of the last log entry in the follower's log.- Returns:
- last log entry index
-
visit
Description copied from class:Message
Apply the visitor pattern based on this instance's type. -
writeTo
Description copied from class:Message
Serialize this instance into the given buffer. -
calculateSize
protected int calculateSize(int version) Description copied from class:Message
Calculate the number of bytes required bywriteTo()
.- Overrides:
calculateSize
in classMessage
- Parameters:
version
- protocol encoding version- Returns:
- an upper bound on the number of encoded bytes
-
toString
-