Package io.permazen.kv.raft.msg
Class AppendRequest
java.lang.Object
io.permazen.kv.raft.msg.Message
io.permazen.kv.raft.msg.AppendRequest
Sent from leaders to followers to probe the follower's log state and/or append an entry to their log.
Instances also provide the leader's lease timeout value (if any),
which is used to commit read-only transactions, as well as a leader timestamp
which should be reflected back in the corresponding AppendResponse
.
-
Constructor Summary
ConstructorDescriptionAppendRequest
(int clusterId, String senderId, String recipientId, long term, Timestamp leaderTimestamp, Timestamp leaderLeaseTimeout, long leaderCommit, long prevLogTerm, long prevLogIndex) Constructor for a "probe" that does not contain a log entry.AppendRequest
(int clusterId, String senderId, String recipientId, long term, Timestamp leaderTimestamp, Timestamp leaderLeaseTimeout, long leaderCommit, long prevLogTerm, long prevLogIndex, long logEntryTerm, ByteBuffer mutationData) Constructor for a request that contains an actual log entry. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
calculateSize
(int version) Calculate the number of bytes required bywriteTo()
.long
Get leader's commit index.long
Get the serialized data for the log entry, if any.long
long
boolean
Determine whether this message is only sent by leaders.boolean
isProbe()
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, putBoolean, putByteBuffer, putString, putTimestamp
-
Constructor Details
-
AppendRequest
public AppendRequest(int clusterId, String senderId, String recipientId, long term, Timestamp leaderTimestamp, Timestamp leaderLeaseTimeout, long leaderCommit, long prevLogTerm, long prevLogIndex) Constructor for a "probe" that does not contain a log entry.Note that
leaderCommit
is limited toprevLogIndex
by this constructor, because we can't guarantee that the omitted log entry atprevLogIndex + 1
matches whatever the follower has in its log.- Parameters:
clusterId
- cluster IDsenderId
- identity of senderrecipientId
- identity of recipientterm
- sender's current termleaderTimestamp
- leader's timestamp for this requestleaderLeaseTimeout
- earliest leader timestamp at which leader could be deposed (or null)leaderCommit
- current commit index for senderprevLogTerm
- term of the log entry just prior to this oneprevLogIndex
- index of the log entry just prior to this one
-
AppendRequest
public AppendRequest(int clusterId, String senderId, String recipientId, long term, Timestamp leaderTimestamp, Timestamp leaderLeaseTimeout, long leaderCommit, long prevLogTerm, long prevLogIndex, long logEntryTerm, ByteBuffer mutationData) Constructor for a request that contains an actual log entry.- Parameters:
clusterId
- cluster IDsenderId
- identity of senderrecipientId
- identity of recipientterm
- sender's current termleaderTimestamp
- leader's timestamp for this requestleaderLeaseTimeout
- earliest leader timestamp at which leader could be deposed (or null)leaderCommit
- current commit index for senderprevLogTerm
- term of the log entry just prior to this oneprevLogIndex
- index of the log entry just prior to this onelogEntryTerm
- term of this log entrymutationData
- log entry serialized mutations, or null if follower should have the data already
-
-
Method Details
-
getLeaderTimestamp
-
getLeaderLeaseTimeout
-
getLeaderCommit
public long getLeaderCommit()Get leader's commit index.For probe requests, this value is limited to the value returned by
getPrevLogIndex()
.- Returns:
- leader's commit index
-
getPrevLogTerm
public long getPrevLogTerm() -
getPrevLogIndex
public long getPrevLogIndex() -
isProbe
public boolean isProbe() -
getLogEntryTerm
public long getLogEntryTerm() -
getMutationData
Get the serialized data for the log entry, if any. Returns null if this is a probe or follower is expected to already have the data from a transaction.This method may only be invoked once.
- Returns:
- log entry serialized mutations, or null if this message does not contain data
- Throws:
IllegalStateException
- if this method has already been invoked
-
isLeaderMessage
public boolean isLeaderMessage()Description copied from class:Message
Determine whether this message is only sent by leaders.- Overrides:
isLeaderMessage
in classMessage
- Returns:
- true if receipt of this message implies sender is a leader
-
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
-