use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class SegmentedRaftLogCursorIT method shouldReturnTrueOnEntryThatExists.
@Test
public void shouldReturnTrueOnEntryThatExists() 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)) {
next = entryCursor.next();
}
//then
assertTrue(next);
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class RaftMachineTest method shouldPersistAtSpecifiedLogIndex.
@Test
public void shouldPersistAtSpecifiedLogIndex() throws Exception {
// given
FakeClock fakeClock = Clocks.fakeClock();
ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).clock(fakeClock).raftLog(raftLog).build();
raftLog.append(new RaftLogEntry(0, new MemberIdSet(asSet(myself, member1, member2))));
// when
raft.handle(appendEntriesRequest().from(member1).prevLogIndex(0).prevLogTerm(0).leaderTerm(0).logEntry(new RaftLogEntry(0, data1)).build());
// then
assertEquals(1, raftLog.appendIndex());
assertEquals(data1, readLogEntry(raftLog, 1).content());
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class RaftTestFixture method bootstrap.
public void bootstrap(MemberId[] members) throws RaftMachine.BootstrapException, IOException {
for (MemberFixture member : members()) {
member.raftLog().append(new RaftLogEntry(0, new MemberIdSet(asSet(members))));
member.raftInstance().installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(members))));
member.raftInstance().startTimers();
}
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class Fixture method boot.
void boot() throws BootstrapException, TimeoutException, InterruptedException, IOException {
for (RaftFixture raft : rafts) {
raft.raftLog().append(new RaftLogEntry(0, new MemberIdSet(asSet(members))));
raft.raftMachine().installCoreState(new RaftCoreState(new MembershipEntry(0, members)));
raft.raftMachine.startTimers();
}
net.start();
awaitBootstrapped();
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class ClusterSafetyViolations method inconsistentCommittedLogEntries.
public static boolean inconsistentCommittedLogEntries(ClusterState state) throws IOException {
int index = 0;
boolean moreLog = true;
while (moreLog) {
moreLog = false;
RaftLogEntry clusterLogEntry = null;
for (ComparableRaftState memberState : state.states.values()) {
if (index <= memberState.commitIndex()) {
RaftLogEntry memberLogEntry = readLogEntry(memberState.entryLog(), index);
if (clusterLogEntry == null) {
clusterLogEntry = memberLogEntry;
} else {
if (!clusterLogEntry.equals(memberLogEntry)) {
return true;
}
}
}
if (index < memberState.commitIndex()) {
moreLog = true;
}
}
index++;
}
return false;
}
Aggregations