public interface TransactionContext
TransactionContext can be created from
either the StateMachine or the state machine updater.
In the first case, the StateMachine is a leader. When it receives
a StateMachine.startTransaction(RaftClientRequest) request, it returns
a TransactionContext with the changes from the StateMachine.
The same context will be passed back to the StateMachine
via the StateMachine.applyTransaction(TransactionContext) call.
In the second case, the StateMachine is a follower.
The TransactionContext will be a committed entry coming from
the RAFT log from the leader.| 限定符和类型 | 接口和说明 |
|---|---|
static class |
TransactionContext.Builder |
| 限定符和类型 | 方法和说明 |
|---|---|
TransactionContext |
cancelTransaction()
Called to notify the state machine that the Transaction passed cannot be appended (or synced).
|
RaftClientRequest |
getClientRequest()
Returns the original request from the
RaftClientRequest |
Exception |
getException()
Returns the exception from the
StateMachine or the log |
org.apache.ratis.proto.RaftProtos.LogEntryProto |
getLogEntry()
Returns the committed log entry
|
org.apache.ratis.proto.RaftProtos.RaftPeerRole |
getServerRole() |
Object |
getStateMachineContext()
Returns the
StateMachine the current TransactionContext specific to |
org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto |
getStateMachineLogEntry()
Returns the data from the
StateMachine |
org.apache.ratis.proto.RaftProtos.LogEntryProto |
initLogEntry(long term,
long index)
Initialize
RaftProtos.LogEntryProto using the internal RaftProtos.StateMachineLogEntryProto. |
static TransactionContext.Builder |
newBuilder() |
TransactionContext |
preAppendTransaction()
This is called before the transaction passed from the StateMachine is appended to the raft log.
|
TransactionContext |
setException(Exception exception)
Set exception in case of failure.
|
TransactionContext |
setShouldCommit(boolean shouldCommit)
Sets whether to commit the transaction to the RAFT log or not
|
TransactionContext |
setStateMachineContext(Object stateMachineContext)
Sets the
StateMachine the TransactionContext is specific to, the method would
not create a new transaction context, it updates the StateMachine it associates with |
boolean |
shouldCommit()
It indicates if the transaction should be committed to the RAFT log
|
org.apache.ratis.proto.RaftProtos.RaftPeerRole getServerRole()
RaftClientRequest getClientRequest()
RaftClientRequestRaftClientRequestorg.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto getStateMachineLogEntry()
StateMachineStateMachineTransactionContext setException(Exception exception)
Exception getException()
StateMachine or the logStateMachine or the logTransactionContext setStateMachineContext(Object stateMachineContext)
StateMachine the TransactionContext is specific to, the method would
not create a new transaction context, it updates the StateMachine it associates withstateMachineContext - state machine contextStateMachineObject getStateMachineContext()
StateMachine the current TransactionContext specific toStateMachine the current TransactionContext specific toorg.apache.ratis.proto.RaftProtos.LogEntryProto initLogEntry(long term, long index)
RaftProtos.LogEntryProto using the internal RaftProtos.StateMachineLogEntryProto.term - The current term.index - The index of the log entry.RaftProtos.LogEntryProtoorg.apache.ratis.proto.RaftProtos.LogEntryProto getLogEntry()
TransactionContext setShouldCommit(boolean shouldCommit)
shouldCommit - true if the transaction is supposed to be committed to the RAFT logTransactionContext itselfboolean shouldCommit()
TransactionContext preAppendTransaction() throws IOException
IOExceptionTransactionContext cancelTransaction() throws IOException
IOExceptionstatic TransactionContext.Builder newBuilder()
Copyright © 2017–2025 The Apache Software Foundation. All rights reserved.