use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class ClusterSafetyViolationsTest method shouldRecogniseInconsistentCommittedContent.
@Test
public void shouldRecogniseInconsistentCommittedContent() throws Exception {
// given
ClusterState clusterState = new ClusterState(asSet(member(0), member(1)));
clusterState.states.get(member(0)).entryLog.append(new RaftLogEntry(1, valueOf(1)));
clusterState.states.get(member(1)).entryLog.append(new RaftLogEntry(1, valueOf(1)));
clusterState.states.get(member(0)).entryLog.append(new RaftLogEntry(1, valueOf(2)));
clusterState.states.get(member(1)).entryLog.append(new RaftLogEntry(1, valueOf(3)));
commit(clusterState, member(0), 0);
commit(clusterState, member(1), 0);
// then
assertFalse(inconsistentCommittedLogEntries(clusterState));
// when
commit(clusterState, member(0), 1);
commit(clusterState, member(1), 1);
// then
assertTrue(inconsistentCommittedLogEntries(clusterState));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class SegmentedRaftLogPartialEntryRecoveryTest method incompleteHeaderOfLastOfMoreThanOneLogFilesShouldNotCauseFailure.
@Test
public void incompleteHeaderOfLastOfMoreThanOneLogFilesShouldNotCauseFailure() throws Throwable {
// Given
// we use a RaftLog to create two log files, in order to chop the header of the second
SegmentedRaftLog raftLog = createRaftLog(1);
raftLog.start();
// will cause rotation
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);
// When
// We remove any number of bytes from the end of the second file and try to recover
// Then
// No exceptions should be thrown
truncateAndRecover(logFile, 0);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class SegmentedRaftLogRotationTest method shouldBeAbleToRecoverToLatestStateAfterRotation.
@Test
public void shouldBeAbleToRecoverToLatestStateAfterRotation() throws Throwable {
// Given
int term = 0;
long indexToRestoreTo;
try (Lifespan lifespan = new Lifespan()) {
SegmentedRaftLog log = lifespan.add(createRaftLog(ROTATE_AT_SIZE_IN_BYTES));
log.append(new RaftLogEntry(term, replicatedStringOfBytes(ROTATE_AT_SIZE_IN_BYTES - 40)));
indexToRestoreTo = log.append(new RaftLogEntry(term, ReplicatedInteger.valueOf(1)));
}
// When
SegmentedRaftLog log = life.add(createRaftLog(ROTATE_AT_SIZE_IN_BYTES));
// Then
assertEquals(indexToRestoreTo, log.appendIndex());
assertEquals(term, log.readEntryTerm(indexToRestoreTo));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class MembershipWaiterTest method shouldReturnImmediatelyIfMemberAndCaughtUp.
@Test
public void shouldReturnImmediatelyIfMemberAndCaughtUp() throws Exception {
OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 500, NullLogProvider.getInstance());
InMemoryRaftLog raftLog = new InMemoryRaftLog();
raftLog.append(new RaftLogEntry(0, valueOf(0)));
ExposedRaftState raftState = RaftStateBuilder.raftState().votingMembers(member(0)).leaderCommit(0).entryLog(raftLog).commitIndex(0L).build().copy();
RaftMachine raft = mock(RaftMachine.class);
when(raft.state()).thenReturn(raftState);
CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
jobScheduler.runJob();
jobScheduler.runJob();
future.get(0, NANOSECONDS);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class InFlightLogEntryReaderTest method shouldNeverUseMapAgainAfterHavingFeltBackToTheRaftLog.
@Test
public void shouldNeverUseMapAgainAfterHavingFeltBackToTheRaftLog() throws Exception {
// given
InFlightLogEntryReader reader = new InFlightLogEntryReader(raftLog, inFlightMap, clearCache);
startingFromIndexReturnEntries(inFlightMap, logIndex, entry, null, mock(RaftLogEntry.class));
RaftLogEntry[] entries = { entry, mock(RaftLogEntry.class), mock(RaftLogEntry.class) };
startingFromIndexReturnEntries(raftLog, logIndex + 1, entries[1], entries[2]);
for (int offset = 0; offset < 3; offset++) {
// when
RaftLogEntry raftLogEntry = reader.get(offset + logIndex);
// then
assertEquals(entries[offset], raftLogEntry);
if (offset <= 1) {
verify(inFlightMap).get(offset + logIndex);
}
if (offset == 1) {
verify(raftLog).getEntryCursor(offset + logIndex);
}
assertCacheIsUpdated(inFlightMap, offset + logIndex);
}
verifyNoMoreInteractions(inFlightMap);
verifyNoMoreInteractions(raftLog);
}
Aggregations