Skip to content

Commit

Permalink
Apply log entries on rsm for followers
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Dec 23, 2024
1 parent 3bb7b4d commit ffc7eca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void TRaft::OnAppendEntries(ITimeSource::Time now, TMessageHolder<TAppendEntries
(*VolatileState)
.SetCommitIndex(commitIndex)
.SetElectionDue(MakeElection(now));

Become(EState::FOLLOWER);
Nodes[reply->Dst]->Send(std::move(reply));
}
Expand Down Expand Up @@ -407,6 +408,8 @@ void TRaft::FollowerTimeout(ITimeSource::Time now) {
if (VolatileState->ElectionDue <= now) {
Become(EState::CANDIDATE);
}

ProcessCommitted();
}

void TRaft::CandidateTimeout(ITimeSource::Time now) {
Expand Down
5 changes: 4 additions & 1 deletion src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ void TRaftServer<TSocket>::DebugPrint() {
std::cout << "Leader, "
<< "Term: " << state->CurrentTerm << ", "
<< "Index: " << state->Log.size() << ", "
<< "CommitIndex: " << volatileState->CommitIndex << ", ";
<< "CommitIndex: " << volatileState->CommitIndex << ", "
<< "LastApplied: " << volatileState->LastApplied << ", ";
std::cout << "Delay: ";
for (auto [id, index] : volatileState->MatchIndex) {
std::cout << id << ":" << (state->Log.size() - index) << " ";
Expand All @@ -183,12 +184,14 @@ void TRaftServer<TSocket>::DebugPrint() {
<< "Term: " << state->CurrentTerm << ", "
<< "Index: " << state->Log.size() << ", "
<< "CommitIndex: " << volatileState->CommitIndex << ", "
<< "LastApplied: " << volatileState->LastApplied << ", "
<< "\n";
} else if (Raft->CurrentStateName() == EState::FOLLOWER) {
std::cout << "Follower, "
<< "Term: " << state->CurrentTerm << ", "
<< "Index: " << state->Log.size() << ", "
<< "CommitIndex: " << volatileState->CommitIndex << ", "
<< "LastApplied: " << volatileState->LastApplied << ", "
<< "\n";
}
}
Expand Down

0 comments on commit ffc7eca

Please sign in to comment.