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();
}
}
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());
}
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());
}
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();
}
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;
}
Aggregations