use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class SegmentedRaftLogPartialEntryRecoveryTest method shouldNotAppendAtTheEndOfLogFileWithIncompleteEntries.
@Test
public void shouldNotAppendAtTheEndOfLogFileWithIncompleteEntries() throws Throwable {
// Given
// we use a RaftLog to create a raft log file and then we will chop some bits off the end
SegmentedRaftLog raftLog = createRaftLog(100_000);
raftLog.start();
raftLog.append(new RaftLogEntry(4, new NewLeaderBarrier()));
raftLog.stop();
// We use a temporary RecoveryProtocol to get the file to chop
RecoveryProtocol recovery = createRecoveryProtocol();
State recoveryState = recovery.run();
String logFilename = recoveryState.segments.last().getFilename();
File logFile = new File(logDirectory, logFilename);
StoreChannel lastFile = fsRule.get().open(logFile, "rw");
long currentSize = lastFile.size();
lastFile.close();
// When
// We induce an incomplete entry at the end of the last file
lastFile = fsRule.get().open(logFile, "rw");
lastFile.truncate(currentSize - 1);
lastFile.close();
// We start the raft log again, on the previous log file with truncated last entry.
raftLog = createRaftLog(100_000);
// Recovery will run here
raftLog.start();
// Append an entry
raftLog.append(new RaftLogEntry(4, new NewLeaderBarrier()));
// The log should report as containing only the last entry we've appended
try (RaftLogCursor entryCursor = raftLog.getEntryCursor(0)) {
// There should be exactly one entry, of type NewLeaderBarrier
assertTrue(entryCursor.next());
RaftLogEntry raftLogEntry = entryCursor.get();
assertEquals(NewLeaderBarrier.class, raftLogEntry.content().getClass());
assertFalse(entryCursor.next());
}
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class RaftMembershipManagerTest method membershipManagerShouldRevertToOldMembershipSetAfterTruncationCausesLossOfAllAppendedMembershipSets.
@Test
public void membershipManagerShouldRevertToOldMembershipSetAfterTruncationCausesLossOfAllAppendedMembershipSets() throws Exception {
// given
final InMemoryRaftLog raftLog = new InMemoryRaftLog();
RaftMembershipManager membershipManager = lifeRule.add(raftMembershipManager(raftLog));
// when
List<RaftLogCommand> logCommands = asList(new AppendLogEntry(0, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 4))), new AppendLogEntry(1, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 5))), new TruncateLogCommand(1));
for (RaftLogCommand logCommand : logCommands) {
logCommand.applyTo(raftLog, log);
}
membershipManager.processLog(0, logCommands);
// then
assertEquals(new RaftTestGroup(1, 2, 3, 4).getMembers(), membershipManager.votingMembers());
assertFalse(membershipManager.uncommittedMemberChangeInLog());
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class RaftMembershipManagerTest method membershipManagerShouldRevertToEarlierAppendedMembershipSetAfterTruncationCausesLossOfLastAppened.
@Test
public void membershipManagerShouldRevertToEarlierAppendedMembershipSetAfterTruncationCausesLossOfLastAppened() throws Exception {
// given
final InMemoryRaftLog raftLog = new InMemoryRaftLog();
RaftMembershipManager membershipManager = lifeRule.add(raftMembershipManager(raftLog));
// when
List<RaftLogCommand> logCommands = asList(new AppendLogEntry(0, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 4))), new AppendLogEntry(1, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 5))), new AppendLogEntry(2, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 6))), new TruncateLogCommand(2));
for (RaftLogCommand logCommand : logCommands) {
logCommand.applyTo(raftLog, log);
}
membershipManager.processLog(0, logCommands);
// then
assertEquals(new RaftTestGroup(1, 2, 3, 5).getMembers(), membershipManager.votingMembers());
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class RaftMembershipManagerTest method membershipManagerShouldUseLatestAppendedMembershipSetEntries.
@Test
public void membershipManagerShouldUseLatestAppendedMembershipSetEntries() throws Exception {
// given
final InMemoryRaftLog log = new InMemoryRaftLog();
RaftMembershipManager membershipManager = lifeRule.add(raftMembershipManager(log));
// when
membershipManager.processLog(0, asList(new AppendLogEntry(0, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 4))), new AppendLogEntry(1, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 5)))));
// then
assertEquals(new RaftTestGroup(1, 2, 3, 5).getMembers(), membershipManager.votingMembers());
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class TruncateLogCommandTest method applyTo.
@Test
public void applyTo() throws Exception {
//Test that truncate commands correctly remove entries from the cache.
//given
AssertableLogProvider logProvider = new AssertableLogProvider();
Log log = logProvider.getLog(getClass());
long fromIndex = 2L;
TruncateLogCommand truncateLogCommand = new TruncateLogCommand(fromIndex);
InFlightMap<RaftLogEntry> inFlightMap = new InFlightMap<>();
inFlightMap.put(0L, new RaftLogEntry(0L, valueOf(0)));
inFlightMap.put(1L, new RaftLogEntry(1L, valueOf(1)));
inFlightMap.put(2L, new RaftLogEntry(2L, valueOf(2)));
inFlightMap.put(3L, new RaftLogEntry(3L, valueOf(3)));
//when
truncateLogCommand.applyTo(inFlightMap, log);
//then
assertNotNull(inFlightMap.get(0L));
assertNotNull(inFlightMap.get(1L));
assertNull(inFlightMap.get(2L));
assertNull(inFlightMap.get(3L));
logProvider.assertAtLeastOnce(inLog(getClass()).debug("Start truncating in-flight-map from index %d. Current map:%n%s", fromIndex, inFlightMap));
}
Aggregations