Class AppendRequest

java.lang.Object
io.permazen.kv.raft.msg.Message
io.permazen.kv.raft.msg.AppendRequest

public class AppendRequest extends Message
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 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 to prevLogIndex by this constructor, because we can't guarantee that the omitted log entry at prevLogIndex + 1 matches whatever the follower has in its log.

      Parameters:
      clusterId - cluster ID
      senderId - identity of sender
      recipientId - identity of recipient
      term - sender's current term
      leaderTimestamp - leader's timestamp for this request
      leaderLeaseTimeout - earliest leader timestamp at which leader could be deposed (or null)
      leaderCommit - current commit index for sender
      prevLogTerm - term of the log entry just prior to this one
      prevLogIndex - 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 ID
      senderId - identity of sender
      recipientId - identity of recipient
      term - sender's current term
      leaderTimestamp - leader's timestamp for this request
      leaderLeaseTimeout - earliest leader timestamp at which leader could be deposed (or null)
      leaderCommit - current commit index for sender
      prevLogTerm - term of the log entry just prior to this one
      prevLogIndex - index of the log entry just prior to this one
      logEntryTerm - term of this log entry
      mutationData - log entry serialized mutations, or null if follower should have the data already
  • Method Details

    • getLeaderTimestamp

      public Timestamp getLeaderTimestamp()
    • getLeaderLeaseTimeout

      public Timestamp 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

      public ByteBuffer 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 class Message
      Returns:
      true if receipt of this message implies sender is a leader
    • visit

      public void visit(MessageSwitch handler)
      Description copied from class: Message
      Apply the visitor pattern based on this instance's type.
      Specified by:
      visit in class Message
      Parameters:
      handler - target for visit
    • writeTo

      public void writeTo(ByteBuffer dest, int version)
      Description copied from class: Message
      Serialize this instance into the given buffer.
      Overrides:
      writeTo in class Message
      Parameters:
      dest - destination for encoded data
      version - protocol encoding version number
    • calculateSize

      protected int calculateSize(int version)
      Description copied from class: Message
      Calculate the number of bytes required by writeTo().
      Overrides:
      calculateSize in class Message
      Parameters:
      version - protocol encoding version
      Returns:
      an upper bound on the number of encoded bytes
    • toString

      public String toString()
      Specified by:
      toString in class Message