From ffc7eca16aa1118014f9f9dbc04887ef969cc744 Mon Sep 17 00:00:00 2001 From: Alexey Ozeritskiy Date: Tue, 24 Dec 2024 01:55:34 +0300 Subject: [PATCH] Apply log entries on rsm for followers --- src/raft.cpp | 3 +++ src/server.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/raft.cpp b/src/raft.cpp index ae65506..98813c3 100644 --- a/src/raft.cpp +++ b/src/raft.cpp @@ -235,6 +235,7 @@ void TRaft::OnAppendEntries(ITimeSource::Time now, TMessageHolderDst]->Send(std::move(reply)); } @@ -407,6 +408,8 @@ void TRaft::FollowerTimeout(ITimeSource::Time now) { if (VolatileState->ElectionDue <= now) { Become(EState::CANDIDATE); } + + ProcessCommitted(); } void TRaft::CandidateTimeout(ITimeSource::Time now) { diff --git a/src/server.cpp b/src/server.cpp index eb6a389..8bfc5dc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -164,7 +164,8 @@ void TRaftServer::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) << " "; @@ -183,12 +184,14 @@ void TRaftServer::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"; } }