use of org.apache.ratis.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class LeaderProtoUtils method toInstallSnapshotRequestProtoBuilder.
private static InstallSnapshotRequestProto.Builder toInstallSnapshotRequestProtoBuilder(RaftServer.Division server, RaftPeerId replyId) {
// term is not going to used by installSnapshot to update the RaftConfiguration
final RaftConfiguration conf = server.getRaftConf();
final LogEntryProto confLogEntryProto = LogProtoUtils.toLogEntryProto(conf, null, conf.getLogEntryIndex());
return InstallSnapshotRequestProto.newBuilder().setServerRequest(ClientProtoUtils.toRaftRpcRequestProtoBuilder(server.getMemberId(), replyId)).setLeaderTerm(server.getInfo().getCurrentTerm()).setLastRaftConfigurationLogEntryProto(confLogEntryProto);
}
use of org.apache.ratis.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class RaftLogBase method appendMetadataImpl.
private long appendMetadataImpl(long term, long newCommitIndex) {
checkLogState();
if (!shouldAppendMetadata(newCommitIndex)) {
return INVALID_LOG_INDEX;
}
final LogEntryProto entry;
final long nextIndex;
try (AutoCloseableLock writeLock = writeLock()) {
nextIndex = getNextIndex();
entry = LogProtoUtils.toLogEntryProto(newCommitIndex, term, nextIndex);
appendEntry(entry);
}
lastMetadataEntry = entry;
return nextIndex;
}
use of org.apache.ratis.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class LogSegment method putEntryCache.
void putEntryCache(TermIndex key, LogEntryProto value, Op op) {
final LogEntryProto previous = entryCache.put(key, value);
long previousSize = 0;
if (previous != null) {
// Different threads maybe load LogSegment file into cache at the same time, so duplicate maybe happen
previousSize = getEntrySize(value, Op.REMOVE_CACHE);
}
totalCacheSize.getAndAdd(getEntrySize(value, op) - previousSize);
}
use of org.apache.ratis.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class RaftReconfigurationBaseTest method runTestNoChangeRequest.
void runTestNoChangeRequest(CLUSTER cluster) throws Exception {
final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster);
try (final RaftClient client = cluster.createClient(leader.getId())) {
client.io().send(new SimpleMessage("m"));
final RaftLog leaderLog = leader.getRaftLog();
final long committedIndex = leaderLog.getLastCommittedIndex();
final RaftConfiguration confBefore = cluster.getLeader().getRaftConf();
// no real configuration change in the request
final RaftClientReply reply = client.admin().setConfiguration(cluster.getPeers().toArray(RaftPeer.emptyArray()));
Assert.assertTrue(reply.isSuccess());
final long newCommittedIndex = leaderLog.getLastCommittedIndex();
for (long i = committedIndex + 1; i <= newCommittedIndex; i++) {
final LogEntryProto e = leaderLog.get(i);
Assert.assertTrue(e.hasMetadataEntry());
}
Assert.assertSame(confBefore, cluster.getLeader().getRaftConf());
}
}
use of org.apache.ratis.proto.RaftProtos.LogEntryProto in project incubator-ratis by apache.
the class OutputStreamBaseTest method assertRaftLog.
private RaftLog assertRaftLog(int expectedEntries, RaftServer.Division server) throws Exception {
final RaftLog raftLog = server.getRaftLog();
final EnumMap<LogEntryBodyCase, AtomicLong> counts = RaftTestUtil.countEntries(raftLog);
Assert.assertEquals(expectedEntries, counts.get(LogEntryBodyCase.STATEMACHINELOGENTRY).get());
final LogEntryProto last = RaftTestUtil.getLastEntry(LogEntryBodyCase.STATEMACHINELOGENTRY, raftLog);
Assert.assertNotNull(last);
Assert.assertTrue(raftLog.getLastCommittedIndex() >= last.getIndex());
Assert.assertTrue(server.getInfo().getLastAppliedIndex() >= last.getIndex());
return raftLog;
}
Aggregations