Class CommitResponse

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

public class CommitResponse extends Message
Response to a CommitRequest.

If the request was successful, the leader returns the term and index of the log entry that, when committed (in the Raft sense), allows the transaction to be committed. This suffices for read-write transactions, because the log entry corresponds directly to the transaction's mutations.

In order to support linearizable semantics for read-only transactions, which do not create new log entries, in addition a minimum leader lease timeout value is included; the transaction can then be committed after receiving an AppendRequest whose leader lease timeout is at least this high. In most cases, such an AppendRequest will have already been received, so the transaction can be committed with a single round trip.

  • Constructor Details

    • CommitResponse

      public CommitResponse(int clusterId, String senderId, String recipientId, long term, long txId, long commitTerm, long commitIndex)
      Constructor for success case, when there is no minimum leader lease timeout required for commit (read-write transaction, or read-only transaction occurring within the current leader lease timeout).
      Parameters:
      clusterId - cluster ID
      senderId - sending node identity
      recipientId - identity of recipient
      term - current term
      txId - recipient's original transaction ID
      commitTerm - transaction commit term
      commitIndex - transaction commit index
    • CommitResponse

      public CommitResponse(int clusterId, String senderId, String recipientId, long term, long txId, long commitTerm, long commitIndex, Timestamp commitLeaderLeaseTimeout)
      Constructor for success case when a minimum leader lease timeout is required for commit (read-only transaction when leader has not heard from a majority of followers in at least a minimum election timeout.
      Parameters:
      clusterId - cluster ID
      senderId - sending node identity
      recipientId - identity of recipient
      term - current term
      txId - recipient's original transaction ID
      commitTerm - transaction commit term
      commitIndex - transaction commit index
      commitLeaderLeaseTimeout - minimum leader lease time required for commit, or null for none
    • CommitResponse

      public CommitResponse(int clusterId, String senderId, String recipientId, long term, long txId, String errorMessage)
      Constructor for error case.
      Parameters:
      clusterId - cluster ID
      senderId - sending node identity
      recipientId - identity of recipient
      term - current term
      txId - recipient's original transaction ID
      errorMessage - failure error message
  • Method Details

    • getTxId

      public long getTxId()
      Get the sender's ID for the transaction.
      Returns:
      transaction ID
    • isSuccess

      public boolean isSuccess()
      Determine whether the request was successful.
      Returns:
      true for success, false for error
    • getCommitTerm

      public long getCommitTerm()
      Get the commit term for the transaction. This is always the same as the term of the sender.
      Returns:
      transaction commit term
    • getCommitIndex

      public long getCommitIndex()
      Get the commit index for the transaction.
      Returns:
      transaction commit index, or zero if there was an error
    • getCommitLeaderLeaseTimeout

      public Timestamp getCommitLeaderLeaseTimeout()
      Get the minimum required leader lease timeout value to commit, if any.
      Returns:
      minimum leader lease timeout, or null if there is none
    • getErrorMessage

      public String getErrorMessage()
      Get the error message in case of failure.
      Returns:
      failure message, or null if there was no error
    • 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 an upper bound on 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