use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class SegmentedRaftLogRotationTruncationPruneTest method shouldPruneAwaySingleEntriesIfRotationHappenedEveryEntry.
@Test
public void shouldPruneAwaySingleEntriesIfRotationHappenedEveryEntry() throws Exception {
/**
* If you have a raft log which rotates after every append, therefore having a single entry in every segment,
* we assert that every sequential prune attempt will result in the prevIndex incrementing by one.
*/
// given
RaftLog log = createRaftLog();
long term = 0;
for (int i = 0; i < 10; i++) {
log.append(new RaftLogEntry(term, valueOf(i)));
}
assertEquals(-1, log.prevIndex());
for (int i = 0; i < 9; i++) {
log.prune(i);
assertEquals(i, log.prevIndex());
}
log.prune(9);
assertEquals(8, log.prevIndex());
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class SegmentedRaftLogRotationTruncationPruneTest method shouldPruneAwaySingleEntriesAfterTruncationIfRotationHappenedEveryEntry.
@Test
public void shouldPruneAwaySingleEntriesAfterTruncationIfRotationHappenedEveryEntry() throws Exception {
/**
* Given a log with many single-entry segments, a series of truncations at decending values followed by
* pruning at more previous segments will maintain the correct prevIndex for the log.
*
* Initial Scenario: [0][1][2][3][4][5][6][7][8][9] prevIndex = 0
* Truncate segment 9 : [0][1][2][3][4][5][6][7][8] (9) prevIndex = 0
* Truncate segment 8 : [0][1][2][3][4][5][6][7] (8)(9) prevIndex = 0
* Truncate segment 7 : [0][1][2][3][4][5][6] (7)(8)(9) prevIndex = 0
* Prune segment 0 : [1][2][3][4][5][6] (7)(8)(9) prevIndex = 1
* Prune segment 1 : [2][3][4][5][6] (7)(8)(9) prevIndex = 2
* Prune segment 2 : [3][4][5][6] (7)(8)(9) prevIndex = 3
* Prune segment 3 : [4][5][6] (7)(8)(9) prevIndex = 4
* Prune segment 4 : [5][6] (7)(8)(9) prevIndex = 5
* Prune segment 5 : [5][6] (7)(8)(9) prevIndex = 5
* Prune segment 6 : [5][6] (7)(8)(9) prevIndex = 5
* Etc...
*
* The prevIndex should not become corrupt and become greater than 5 in this example.
*/
// given
RaftLog log = createRaftLog();
long term = 0;
for (int i = 0; i < 10; i++) {
log.append(new RaftLogEntry(term, valueOf(i)));
}
log.truncate(9);
log.truncate(8);
log.truncate(7);
assertEquals(-1, log.prevIndex());
for (int i = 0; i <= 5; i++) {
log.prune(i);
assertEquals(i, log.prevIndex());
}
for (int i = 5; i < 10; i++) {
log.prune(i);
assertEquals(5, log.prevIndex());
}
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class MembershipWaiterTest method shouldWaitUntilLeaderCommitIsAvailable.
@Test
public void shouldWaitUntilLeaderCommitIsAvailable() 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();
future.get(1, TimeUnit.SECONDS);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class SegmentedRaftLogCursorIT method shouldReturnFalseOnCursorForEntryThatWasPruned.
@Test
public void shouldReturnFalseOnCursorForEntryThatWasPruned() throws Exception {
//given
SegmentedRaftLog segmentedRaftLog = createRaftLog(1, "keep_none");
long firstIndex = segmentedRaftLog.append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));
segmentedRaftLog.append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
long lastIndex = segmentedRaftLog.append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));
//when
segmentedRaftLog.prune(firstIndex);
RaftLogCursor entryCursor = segmentedRaftLog.getEntryCursor(firstIndex);
boolean next = entryCursor.next();
//then
assertFalse(next);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class SegmentedRaftLogCursorIT method shouldReturnFalseOnCursorForEntryThatDoesntExist.
@Test
public void shouldReturnFalseOnCursorForEntryThatDoesntExist() throws Exception {
//given
SegmentedRaftLog segmentedRaftLog = createRaftLog(1);
segmentedRaftLog.append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));
segmentedRaftLog.append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
long lastIndex = segmentedRaftLog.append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));
//when
boolean next;
try (RaftLogCursor entryCursor = segmentedRaftLog.getEntryCursor(lastIndex + 1)) {
next = entryCursor.next();
}
//then
assertFalse(next);
}
Aggregations