Search in sources :

Example 16 with LogEntryProto

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

Example 17 with LogEntryProto

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

Example 18 with LogEntryProto

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

Example 19 with LogEntryProto

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

Example 20 with LogEntryProto

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

Aggregations

LogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto)36 SimpleOperation (org.apache.ratis.RaftTestUtil.SimpleOperation)16 Test (org.junit.Test)16 BaseTest (org.apache.ratis.BaseTest)14 File (java.io.File)12 ArrayList (java.util.ArrayList)8 SMLogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto)8 IOException (java.io.IOException)7 CompletableFuture (java.util.concurrent.CompletableFuture)6 RandomAccessFile (java.io.RandomAccessFile)5 RaftServerImpl (org.apache.ratis.server.impl.RaftServerImpl)5 List (java.util.List)4 RaftProperties (org.apache.ratis.conf.RaftProperties)4 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)4 TermIndex (org.apache.ratis.server.protocol.TermIndex)4 AutoCloseableLock (org.apache.ratis.util.AutoCloseableLock)4 Level (org.apache.log4j.Level)3 RaftServerConfigKeys (org.apache.ratis.server.RaftServerConfigKeys)3 RetryCache (org.apache.ratis.server.impl.RetryCache)3 RetryCacheTestUtil (org.apache.ratis.server.impl.RetryCacheTestUtil)3