Search in sources :

Example 46 with RaftLogEntry

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);
}
Also used : RaftLogCursor(org.neo4j.causalclustering.core.consensus.log.RaftLogCursor) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 47 with RaftLogEntry

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());
}
Also used : FakeClock(org.neo4j.time.FakeClock) MemberIdSet(org.neo4j.causalclustering.core.consensus.membership.MemberIdSet) ControlledRenewableTimeoutService(org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 48 with RaftLogEntry

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();
    }
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) MemberIdSet(org.neo4j.causalclustering.core.consensus.membership.MemberIdSet) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)

Example 49 with RaftLogEntry

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();
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) MemberIdSet(org.neo4j.causalclustering.core.consensus.membership.MemberIdSet) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)

Example 50 with RaftLogEntry

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;
}
Also used : RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)

Aggregations

RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)87 Test (org.junit.Test)69 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)27 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)25 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)20 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)12 RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)10 ReadableRaftState (org.neo4j.causalclustering.core.consensus.state.ReadableRaftState)10 AppendLogEntry (org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry)8 NewLeaderBarrier (org.neo4j.causalclustering.core.consensus.NewLeaderBarrier)7 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)7 MemberId (org.neo4j.causalclustering.identity.MemberId)7 InOrder (org.mockito.InOrder)6 RaftLogCursor (org.neo4j.causalclustering.core.consensus.log.RaftLogCursor)6 ReadableRaftLog (org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog)5 RaftTestGroup (org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup)5 BatchAppendLogEntries (org.neo4j.causalclustering.core.consensus.outcome.BatchAppendLogEntries)5 ShipCommand (org.neo4j.causalclustering.core.consensus.outcome.ShipCommand)5 TruncateLogCommand (org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand)5 File (java.io.File)4