Search in sources :

Example 1 with RaftLogCommand

use of org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand in project neo4j by neo4j.

the class RaftMembershipManager method processLog.

public void processLog(long commitIndex, Collection<RaftLogCommand> logCommands) throws IOException {
    for (RaftLogCommand logCommand : logCommands) {
        logCommand.dispatch(this);
    }
    if (state.commit(commitIndex)) {
        membershipChanger.onRaftGroupCommitted();
        storage.persistStoreData(state);
        updateMemberSets();
    }
}
Also used : RaftLogCommand(org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand)

Example 2 with RaftLogCommand

use of org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand in project neo4j by neo4j.

the class RaftMembershipManagerTest method membershipManagerShouldRevertToOldMembershipSetAfterTruncationCausesLossOfAllAppendedMembershipSets.

@Test
public void membershipManagerShouldRevertToOldMembershipSetAfterTruncationCausesLossOfAllAppendedMembershipSets() throws Exception {
    // given
    final InMemoryRaftLog raftLog = new InMemoryRaftLog();
    RaftMembershipManager membershipManager = lifeRule.add(raftMembershipManager(raftLog));
    // when
    List<RaftLogCommand> logCommands = asList(new AppendLogEntry(0, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 4))), new AppendLogEntry(1, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 5))), new TruncateLogCommand(1));
    for (RaftLogCommand logCommand : logCommands) {
        logCommand.applyTo(raftLog, log);
    }
    membershipManager.processLog(0, logCommands);
    // then
    assertEquals(new RaftTestGroup(1, 2, 3, 4).getMembers(), membershipManager.votingMembers());
    assertFalse(membershipManager.uncommittedMemberChangeInLog());
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) TruncateLogCommand(org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand) AppendLogEntry(org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry) RaftLogCommand(org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 3 with RaftLogCommand

use of org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand in project neo4j by neo4j.

the class RaftMembershipManagerTest method membershipManagerShouldRevertToEarlierAppendedMembershipSetAfterTruncationCausesLossOfLastAppened.

@Test
public void membershipManagerShouldRevertToEarlierAppendedMembershipSetAfterTruncationCausesLossOfLastAppened() throws Exception {
    // given
    final InMemoryRaftLog raftLog = new InMemoryRaftLog();
    RaftMembershipManager membershipManager = lifeRule.add(raftMembershipManager(raftLog));
    // when
    List<RaftLogCommand> logCommands = asList(new AppendLogEntry(0, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 4))), new AppendLogEntry(1, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 5))), new AppendLogEntry(2, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 6))), new TruncateLogCommand(2));
    for (RaftLogCommand logCommand : logCommands) {
        logCommand.applyTo(raftLog, log);
    }
    membershipManager.processLog(0, logCommands);
    // then
    assertEquals(new RaftTestGroup(1, 2, 3, 5).getMembers(), membershipManager.votingMembers());
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) TruncateLogCommand(org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand) AppendLogEntry(org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry) RaftLogCommand(org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 4 with RaftLogCommand

use of org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand in project neo4j by neo4j.

the class ComparableRaftState method update.

public void update(Outcome outcome) throws IOException {
    term = outcome.getTerm();
    votedFor = outcome.getVotedFor();
    leader = outcome.getLeader();
    votesForMe = outcome.getVotesForMe();
    lastLogIndexBeforeWeBecameLeader = outcome.getLastLogIndexBeforeWeBecameLeader();
    followerStates = outcome.getFollowerStates();
    for (RaftLogCommand logCommand : outcome.getLogCommands()) {
        logCommand.applyTo(entryLog, log);
        logCommand.applyTo(inFlightMap, log);
    }
    commitIndex = outcome.getCommitIndex();
}
Also used : RaftLogCommand(org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand)

Example 5 with RaftLogCommand

use of org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand in project neo4j by neo4j.

the class RaftStateBuilder method build.

public RaftState build() throws IOException {
    StateStorage<TermState> termStore = new InMemoryStateStorage<>(new TermState());
    StateStorage<VoteState> voteStore = new InMemoryStateStorage<>(new VoteState());
    StubMembership membership = new StubMembership(votingMembers, replicationMembers);
    RaftState state = new RaftState(myself, termStore, membership, entryLog, voteStore, new InFlightMap<>(), NullLogProvider.getInstance());
    Collection<RaftMessages.Directed> noMessages = Collections.emptyList();
    List<RaftLogCommand> noLogCommands = Collections.emptyList();
    state.update(new Outcome(null, term, leader, leaderCommit, votedFor, votesForMe, lastLogIndexBeforeWeBecameLeader, followerStates, false, noLogCommands, noMessages, emptySet(), commitIndex, emptySet()));
    return state;
}
Also used : RaftLogCommand(org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand) InMemoryStateStorage(org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage) VoteState(org.neo4j.causalclustering.core.consensus.vote.VoteState) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) TermState(org.neo4j.causalclustering.core.consensus.term.TermState)

Aggregations

RaftLogCommand (org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand)7 Test (org.junit.Test)3 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)3 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)3 AppendLogEntry (org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry)3 TruncateLogCommand (org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand)3 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)2 TermState (org.neo4j.causalclustering.core.consensus.term.TermState)2 VoteState (org.neo4j.causalclustering.core.consensus.vote.VoteState)2 LinkedList (java.util.LinkedList)1 InFlightMap (org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap)1 InMemoryStateStorage (org.neo4j.causalclustering.core.state.storage.InMemoryStateStorage)1