Search in sources :

Example 1 with InFlightLogEntryReader

use of org.neo4j.causalclustering.core.state.InFlightLogEntryReader in project neo4j by neo4j.

the class RaftLogShipper method sendRange.

private void sendRange(long startIndex, long endIndex, LeaderContext leaderContext) {
    if (startIndex > endIndex) {
        return;
    }
    lastSentIndex = endIndex;
    try {
        int batchSize = (int) (endIndex - startIndex + 1);
        RaftLogEntry[] entries = new RaftLogEntry[batchSize];
        long prevLogIndex = startIndex - 1;
        long prevLogTerm = raftLog.readEntryTerm(prevLogIndex);
        if (prevLogTerm > leaderContext.term) {
            log.warn("%s aborting send. Not leader anymore? %s, prevLogTerm=%d", statusAsString(), leaderContext, prevLogTerm);
            return;
        }
        boolean entryMissing = false;
        try (InFlightLogEntryReader logEntrySupplier = new InFlightLogEntryReader(raftLog, inFlightMap, false)) {
            for (int offset = 0; offset < batchSize; offset++) {
                entries[offset] = logEntrySupplier.get(startIndex + offset);
                if (entries[offset] == null) {
                    entryMissing = true;
                    break;
                }
                if (entries[offset].term() > leaderContext.term) {
                    log.warn("%s aborting send. Not leader anymore? %s, entryTerm=%d", statusAsString(), leaderContext, entries[offset].term());
                    return;
                }
            }
        }
        if (entryMissing || doesNotExistInLog(prevLogIndex, prevLogTerm)) {
            if (raftLog.prevIndex() >= prevLogIndex) {
                sendLogCompactionInfo(leaderContext);
            } else {
                log.error("%s: Could not send compaction info and entries were missing, but log is not behind.", statusAsString());
            }
        } else {
            RaftMessages.AppendEntries.Request appendRequest = new RaftMessages.AppendEntries.Request(leader, leaderContext.term, prevLogIndex, prevLogTerm, entries, leaderContext.commitIndex);
            outbound.send(follower, appendRequest);
        }
    } catch (IOException e) {
        log.warn(statusAsString() + " exception during batch send", e);
    }
}
Also used : InFlightLogEntryReader(org.neo4j.causalclustering.core.state.InFlightLogEntryReader) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) IOException(java.io.IOException) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)

Aggregations

IOException (java.io.IOException)1 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)1 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)1 InFlightLogEntryReader (org.neo4j.causalclustering.core.state.InFlightLogEntryReader)1