Search in sources :

Example 36 with LogEntryProto

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);
}
Also used : LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) RaftConfiguration(org.apache.ratis.server.RaftConfiguration)

Example 37 with LogEntryProto

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

Example 38 with LogEntryProto

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);
}
Also used : LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto)

Example 39 with LogEntryProto

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());
    }
}
Also used : LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftConfiguration(org.apache.ratis.server.RaftConfiguration) RaftServer(org.apache.ratis.server.RaftServer) SimpleMessage(org.apache.ratis.RaftTestUtil.SimpleMessage) RaftClient(org.apache.ratis.client.RaftClient) RaftLog(org.apache.ratis.server.raftlog.RaftLog)

Example 40 with LogEntryProto

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;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) RaftLog(org.apache.ratis.server.raftlog.RaftLog) LogEntryBodyCase(org.apache.ratis.proto.RaftProtos.LogEntryProto.LogEntryBodyCase)

Aggregations

LogEntryProto (org.apache.ratis.proto.RaftProtos.LogEntryProto)61 Test (org.junit.Test)22 BaseTest (org.apache.ratis.BaseTest)20 SimpleOperation (org.apache.ratis.RaftTestUtil.SimpleOperation)15 CompletableFuture (java.util.concurrent.CompletableFuture)14 File (java.io.File)13 IOException (java.io.IOException)13 StateMachineLogEntryProto (org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)12 RaftLog (org.apache.ratis.server.raftlog.RaftLog)12 RaftStorage (org.apache.ratis.server.storage.RaftStorage)11 ArrayList (java.util.ArrayList)10 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)10 TermIndex (org.apache.ratis.server.protocol.TermIndex)9 LogEntryHeader (org.apache.ratis.server.raftlog.LogEntryHeader)7 RaftClient (org.apache.ratis.client.RaftClient)6 RaftProperties (org.apache.ratis.conf.RaftProperties)6 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)6 RaftGroupMemberId (org.apache.ratis.protocol.RaftGroupMemberId)6 RaftServer (org.apache.ratis.server.RaftServer)6 RandomAccessFile (java.io.RandomAccessFile)5