Search in sources :

Example 21 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class TruncateLogCommandTest method shouldTruncateWithGaps.

@Test
public void shouldTruncateWithGaps() throws Exception {
    //given
    long fromIndex = 1L;
    TruncateLogCommand truncateLogCommand = new TruncateLogCommand(fromIndex);
    InFlightMap<RaftLogEntry> inFlightMap = new InFlightMap<>();
    inFlightMap.put(0L, new RaftLogEntry(0L, valueOf(0)));
    inFlightMap.put(2L, new RaftLogEntry(1L, valueOf(1)));
    inFlightMap.put(4L, new RaftLogEntry(2L, valueOf(2)));
    truncateLogCommand.applyTo(inFlightMap, NullLog.getInstance());
    inFlightMap.put(1L, new RaftLogEntry(3L, valueOf(1)));
    inFlightMap.put(2L, new RaftLogEntry(4L, valueOf(2)));
    assertNotNull(inFlightMap.get(0L));
    assertNotNull(inFlightMap.get(1L));
    assertNotNull(inFlightMap.get(2L));
}
Also used : InFlightMap(org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 22 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class ClusterSafetyViolationsTest method shouldRecogniseSomeMembersBeingInconsistent.

@Test
public void shouldRecogniseSomeMembersBeingInconsistent() throws Exception {
    // given
    ClusterState clusterState = new ClusterState(asSet(member(0), member(1), member(2)));
    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(2)).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(2)));
    clusterState.states.get(member(2)).entryLog.append(new RaftLogEntry(2, valueOf(2)));
    commit(clusterState, member(0), 0);
    commit(clusterState, member(1), 0);
    commit(clusterState, member(2), 0);
    // then
    assertFalse(inconsistentCommittedLogEntries(clusterState));
    // when
    commit(clusterState, member(0), 1);
    commit(clusterState, member(1), 1);
    // then
    assertFalse(inconsistentCommittedLogEntries(clusterState));
    // when
    commit(clusterState, member(2), 1);
    // then
    assertTrue(inconsistentCommittedLogEntries(clusterState));
}
Also used : RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 23 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class ClusterSafetyViolationsTest method shouldRecogniseInconsistentTerm.

@Test
public void shouldRecogniseInconsistentTerm() 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(2, valueOf(2)));
    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));
}
Also used : RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 24 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class HeartbeatTest method shouldNotResultInCommitIfHistoryMismatches.

@Test
public void shouldNotResultInCommitIfHistoryMismatches() throws Exception {
    InMemoryRaftLog raftLog = new InMemoryRaftLog();
    RaftState state = raftState().myself(myself).entryLog(raftLog).build();
    long leaderTerm = state.term() + leaderTermDifference;
    raftLog.append(new RaftLogEntry(leaderTerm, content()));
    RaftMessages.Heartbeat heartbeat = heartbeat().from(leader).commitIndex(// The leader is talking about committing stuff we don't know about
    raftLog.appendIndex()).commitIndexTerm(// And is in the same term
    leaderTerm).leaderTerm(leaderTerm).build();
    Outcome outcome = role.handler.handle(heartbeat, state, log());
    assertThat(outcome.getCommitIndex(), Matchers.equalTo(0L));
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 25 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class LeaderTest method leaderShouldDecideToAppendToItsLogAndSendAppendEntriesMessageOnReceiptOfClientProposal.

@Test
public void leaderShouldDecideToAppendToItsLogAndSendAppendEntriesMessageOnReceiptOfClientProposal() throws Exception {
    // given
    RaftState state = raftState().votingMembers(asSet(myself, member1, member2)).build();
    Leader leader = new Leader();
    RaftMessages.NewEntry.Request newEntryRequest = new RaftMessages.NewEntry.Request(member(9), CONTENT);
    // when
    Outcome outcome = leader.handle(newEntryRequest, state, log());
    //state.update( outcome );
    // then
    AppendLogEntry logCommand = (AppendLogEntry) single(outcome.getLogCommands());
    assertEquals(0, logCommand.index);
    assertEquals(0, logCommand.entry.term());
    ShipCommand.NewEntries shipCommand = (ShipCommand.NewEntries) single(outcome.getShipCommands());
    assertEquals(shipCommand, new ShipCommand.NewEntries(-1, -1, new RaftLogEntry[] { new RaftLogEntry(0, CONTENT) }));
}
Also used : ShipCommand(org.neo4j.causalclustering.core.consensus.outcome.ShipCommand) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) ReadableRaftState(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) AppendLogEntry(org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

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