use of org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand in project neo4j by neo4j.
the class RaftStateTest method shouldUpdateCacheState.
@Test
public void shouldUpdateCacheState() throws Exception {
//Test that updates applied to the raft state will be refelcted in the entry cache.
//given
InFlightMap<RaftLogEntry> cache = new InFlightMap<>();
RaftState raftState = new RaftState(member(0), new InMemoryStateStorage<>(new TermState()), new FakeMembership(), new InMemoryRaftLog(), new InMemoryStateStorage<>(new VoteState()), cache, NullLogProvider.getInstance());
List<RaftLogCommand> logCommands = new LinkedList<RaftLogCommand>() {
{
add(new AppendLogEntry(1, new RaftLogEntry(0L, valueOf(0))));
add(new AppendLogEntry(2, new RaftLogEntry(0L, valueOf(1))));
add(new AppendLogEntry(3, new RaftLogEntry(0L, valueOf(2))));
add(new AppendLogEntry(4, new RaftLogEntry(0L, valueOf(4))));
add(new TruncateLogCommand(3));
add(new AppendLogEntry(3, new RaftLogEntry(0L, valueOf(5))));
}
};
Outcome raftTestMemberOutcome = new Outcome(CANDIDATE, 0, null, -1, null, emptySet(), -1, initialFollowerStates(), true, logCommands, emptyOutgoingMessages(), emptySet(), -1, emptySet());
//when
raftState.update(raftTestMemberOutcome);
//then
assertNotNull(cache.get(1L));
assertNotNull(cache.get(2L));
assertNotNull(cache.get(3L));
assertEquals(valueOf(5), cache.get(3L).content());
assertNull(cache.get(4L));
}
use of org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand in project neo4j by neo4j.
the class RaftState method update.
public void update(Outcome outcome) throws IOException {
if (termState().update(outcome.getTerm())) {
termStorage.persistStoreData(termState());
}
if (voteState().update(outcome.getVotedFor(), outcome.getTerm())) {
voteStorage.persistStoreData(voteState());
}
logIfLeaderChanged(outcome.getLeader());
leader = outcome.getLeader();
leaderCommit = outcome.getLeaderCommit();
votesForMe = outcome.getVotesForMe();
heartbeatResponses = outcome.getHeartbeatResponses();
lastLogIndexBeforeWeBecameLeader = outcome.getLastLogIndexBeforeWeBecameLeader();
followerStates = outcome.getFollowerStates();
for (RaftLogCommand logCommand : outcome.getLogCommands()) {
logCommand.applyTo(entryLog, log);
logCommand.applyTo(inFlightMap, log);
}
commitIndex = outcome.getCommitIndex();
}
Aggregations