private long appendImpl(long term, RaftConfiguration newConf) { checkLogState(); try(AutoCloseableLock writeLock = writeLock()) { final long nextIndex = getNextIndex(); final LogEntryProto e = ServerProtoUtils.toLogEntryProto(newConf, term, nextIndex); appendEntry(e); return nextIndex; } }
/** * Generate a log entry for the given term and configurations, * and append the entry. Used by the leader. * @return the index of the new log entry. */ public long append(long term, RaftConfiguration newConf) { checkLogState(); try(AutoCloseableLock writeLock = writeLock()) { final long nextIndex = getNextIndex(); final LogEntryProto e = ServerProtoUtils.toLogEntryProto(newConf, term, nextIndex); appendEntry(e); return nextIndex; } }
private long appendMetadataImpl(long term, long newCommitIndex) { checkLogState(); if (!shouldAppendMetadata(newCommitIndex)) { return RaftServerConstants.INVALID_LOG_INDEX; } final LogEntryProto entry; final long nextIndex; try(AutoCloseableLock writeLock = writeLock()) { nextIndex = getNextIndex(); entry = ServerProtoUtils.toLogEntryProto(newCommitIndex, term, nextIndex); appendEntry(entry); } lastMetadataEntry = entry; return nextIndex; }
private long appendImpl(long term, TransactionContext operation) throws StateMachineException { checkLogState(); try(AutoCloseableLock writeLock = writeLock()) { final long nextIndex = getNextIndex(); // This is called here to guarantee strict serialization of callback executions in case // 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 = operation.initLogEntry(term, nextIndex); 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); return nextIndex; } }
checkLogState(); try(AutoCloseableLock writeLock = writeLock()) { final long nextIndex = getNextIndex();