Search in sources :

Example 1 with StateMachineException

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;
    }
}
Also used : StateMachineException(org.apache.ratis.protocol.StateMachineException) LogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto) AutoCloseableLock(org.apache.ratis.util.AutoCloseableLock) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 StateMachineException (org.apache.ratis.protocol.StateMachineException)1 LogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto)1 AutoCloseableLock (org.apache.ratis.util.AutoCloseableLock)1