use of org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class LeaderState method start.
void start() {
// In the beginning of the new term, replicate an empty entry in order
// to finally commit entries in the previous term.
// Also this message can help identify the last committed index when
// the leader peer is just started.
final LogEntryProto placeHolder = LogEntryProto.newBuilder().setTerm(server.getState().getCurrentTerm()).setIndex(raftLog.getNextIndex()).setNoOp(LeaderNoOp.newBuilder()).build();
CodeInjectionForTesting.execute(APPEND_PLACEHOLDER, server.getId().toString(), null);
raftLog.append(placeHolder);
processor.start();
startSenders();
}
use of org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class ServerState method updateConfiguration.
void updateConfiguration(LogEntryProto[] entries) {
if (entries != null && entries.length > 0) {
configurationManager.removeConfigurations(entries[0].getIndex());
for (LogEntryProto entry : entries) {
if (ProtoUtils.isConfigurationLogEntry(entry)) {
final RaftConfiguration conf = ServerProtoUtils.toRaftConfiguration(entry.getIndex(), entry.getConfigurationEntry());
configurationManager.addConfiguration(entry.getIndex(), conf);
server.getServerRpc().addPeers(conf.getPeers());
}
}
}
}
use of org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class LogSegment method loadCache.
/**
* Acquire LogSegment's monitor so that there is no concurrent loading.
*/
synchronized LogEntryProto loadCache(LogRecord record) throws RaftLogIOException {
LogEntryProto entry = entryCache.get(record.getTermIndex());
if (entry != null) {
return entry;
}
try {
entry = cacheLoader.load(record);
hasEntryCache = true;
return entry;
} catch (Exception e) {
throw new RaftLogIOException(e);
}
}
use of org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class LogSegment method append.
private void append(boolean keepEntryInCache, LogEntryProto... entries) {
Preconditions.assertTrue(entries != null && entries.length > 0);
final long term = entries[0].getTerm();
if (records.isEmpty()) {
Preconditions.assertTrue(entries[0].getIndex() == startIndex, "gap between start index %s and first entry to append %s", startIndex, entries[0].getIndex());
}
for (LogEntryProto entry : entries) {
// all these entries should be of the same term
Preconditions.assertTrue(entry.getTerm() == term, "expected term:%s, term of the entry:%s", term, entry.getTerm());
final LogRecord currentLast = getLastRecord();
if (currentLast != null) {
Preconditions.assertTrue(entry.getIndex() == currentLast.getTermIndex().getIndex() + 1, "gap between entries %s and %s", entry.getIndex(), currentLast.getTermIndex().getIndex());
}
final LogRecord record = new LogRecord(totalSize, entry);
records.add(record);
if (keepEntryInCache) {
entryCache.put(record.getTermIndex(), entry);
}
if (ProtoUtils.isConfigurationLogEntry(entry)) {
configEntries.add(record.getTermIndex());
}
totalSize += getEntrySize(entry);
endIndex = entry.getIndex();
}
}
use of org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class MemoryRaftLog method append.
@Override
public long append(long term, RaftConfiguration newConf) {
checkLogState();
try (AutoCloseableLock writeLock = writeLock()) {
final long nextIndex = getNextIndex();
final LogEntryProto e = ServerProtoUtils.toLogEntryProto(newConf, term, nextIndex);
entries.add(e);
return nextIndex;
}
}
Aggregations