use of org.apache.ratis.protocol.StateMachineException in project incubator-ratis by apache.
the class RaftLog method append.
/**
* Generate a log entry for the given term and message, and append the entry.
* Used by the leader.
* @return the index of the new log entry.
*/
public long append(long term, TransactionContext operation, ClientId clientId, long callId) throws StateMachineException {
checkLogState();
try (AutoCloseableLock writeLock = writeLock()) {
final long nextIndex = getNextIndex();
// the SM wants to attach a logic depending on ordered execution in the log commit order.
try {
operation = operation.preAppendTransaction();
} catch (IOException e) {
throw new StateMachineException(selfId, e);
}
// build the log entry after calling the StateMachine
final LogEntryProto e = ProtoUtils.toLogEntryProto(operation.getSMLogEntry(), term, nextIndex, clientId, callId);
int entrySize = e.getSerializedSize();
if (entrySize > maxBufferSize) {
throw new StateMachineException(selfId, new RaftLogIOException("Log entry size " + entrySize + " exceeds the max buffer limit of " + maxBufferSize));
}
appendEntry(e);
operation.setLogEntry(e);
return nextIndex;
}
}
Aggregations