Package io.permazen.kv.raft.msg
Class CommitResponse
java.lang.Object
io.permazen.kv.raft.msg.Message
io.permazen.kv.raft.msg.CommitResponse
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 Summary
ConstructorDescriptionCommitResponse
(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).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.CommitResponse
(int clusterId, String senderId, String recipientId, long term, long txId, String errorMessage) Constructor for error case. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
calculateSize
(int version) Calculate the number of bytes required bywriteTo()
.long
Get the commit index for the transaction.Get the minimum required leader lease timeout value to commit, if any.long
Get the commit term for the transaction.Get the error message in case of failure.long
getTxId()
Get the sender's ID for the transaction.boolean
Determine whether this message is only sent by leaders.boolean
Determine whether the request was successful.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
-
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 IDsenderId
- sending node identityrecipientId
- identity of recipientterm
- current termtxId
- recipient's original transaction IDcommitTerm
- transaction commit termcommitIndex
- 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 IDsenderId
- sending node identityrecipientId
- identity of recipientterm
- current termtxId
- recipient's original transaction IDcommitTerm
- transaction commit termcommitIndex
- transaction commit indexcommitLeaderLeaseTimeout
- 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 IDsenderId
- sending node identityrecipientId
- identity of recipientterm
- current termtxId
- recipient's original transaction IDerrorMessage
- 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
Get the minimum required leader lease timeout value to commit, if any.- Returns:
- minimum leader lease timeout, or null if there is none
-
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 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
-