use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class RaftMessageEncodingDecodingTest method shouldSerializeAppendRequestWithMultipleEntries.
@Test
public void shouldSerializeAppendRequestWithMultipleEntries() throws Exception {
MemberId sender = new MemberId(UUID.randomUUID());
RaftMessages.AppendEntries.Request request = new AppendEntriesRequestBuilder().from(sender).leaderCommit(2).leaderTerm(4).logEntry(new RaftLogEntry(1, ReplicatedInteger.valueOf(2))).logEntry(new RaftLogEntry(1, ReplicatedInteger.valueOf(3))).logEntry(new RaftLogEntry(1, ReplicatedInteger.valueOf(4))).build();
serializeReadBackAndVerifyMessage(request);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class RaftMembershipManager method append.
@Override
public void append(long baseIndex, RaftLogEntry... entries) throws IOException {
for (RaftLogEntry entry : entries) {
if (entry.content() instanceof RaftGroup) {
RaftGroup<MemberId> raftGroup = (RaftGroup<MemberId>) entry.content();
if (state.uncommittedMemberChangeInLog()) {
log.warn("Appending with uncommitted membership change in log");
}
if (state.append(baseIndex, new HashSet<>(raftGroup.getMembers()))) {
log.info("Appending new member set %s", state);
storage.persistStoreData(state);
updateMemberSets();
} else {
log.warn("Appending member set was ignored. Current state: %s, Appended set: %s, Log index: %d%n", state, raftGroup, baseIndex);
}
}
baseIndex++;
}
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class Appending method appendNewEntries.
static void appendNewEntries(ReadableRaftState ctx, Outcome outcome, List<ReplicatedContent> contents) throws IOException {
long prevLogIndex = ctx.entryLog().appendIndex();
long prevLogTerm = prevLogIndex == -1 ? -1 : prevLogIndex > ctx.lastLogIndexBeforeWeBecameLeader() ? ctx.term() : ctx.entryLog().readEntryTerm(prevLogIndex);
RaftLogEntry[] raftLogEntries = contents.stream().map(content -> new RaftLogEntry(ctx.term(), content)).toArray(RaftLogEntry[]::new);
outcome.addShipCommand(new ShipCommand.NewEntries(prevLogIndex, prevLogTerm, raftLogEntries));
outcome.addLogCommand(new BatchAppendLogEntries(prevLogIndex + 1, 0, raftLogEntries));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class Appending method appendNewEntry.
static void appendNewEntry(ReadableRaftState ctx, Outcome outcome, ReplicatedContent content) throws IOException {
long prevLogIndex = ctx.entryLog().appendIndex();
long prevLogTerm = prevLogIndex == -1 ? -1 : prevLogIndex > ctx.lastLogIndexBeforeWeBecameLeader() ? ctx.term() : ctx.entryLog().readEntryTerm(prevLogIndex);
RaftLogEntry newLogEntry = new RaftLogEntry(ctx.term(), content);
outcome.addShipCommand(new ShipCommand.NewEntries(prevLogIndex, prevLogTerm, new RaftLogEntry[] { newLogEntry }));
outcome.addLogCommand(new AppendLogEntry(prevLogIndex + 1, newLogEntry));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry 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);
}
}
Aggregations