Skip to content

Commit

Permalink
Fix update commit index
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius committed Dec 2, 2023
1 parent 923f417 commit ec6622c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/raft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TVolatileState& TVolatileState::Vote(uint32_t nodeId)
TVolatileState& TVolatileState::CommitAdvance(int nservers, const TState& state)
{
auto lastIndex = state.Log.size();
std::vector<uint64_t> indices; indices.reserve(MatchIndex.size()+1+nservers);
std::vector<uint64_t> indices; indices.reserve(nservers);
for (auto [_, index] : MatchIndex) {
indices.push_back(index);
}
Expand Down Expand Up @@ -209,11 +209,11 @@ void TRaft::OnAppendEntries(TMessageHolder<TAppendEntriesResponse> message) {
if (message->Success) {
auto matchIndex = std::max(VolatileState->MatchIndex[nodeId], message->MatchIndex);
(*VolatileState)
.CommitAdvance(Nservers, *State)
.SetMatchIndex(nodeId, matchIndex)
.SetNextIndex(nodeId, message->MatchIndex+1)
.SetRpcDue(nodeId, ITimeSource::Time{})
.SetBatchSize(nodeId, 1024);
.SetBatchSize(nodeId, 1024)
.CommitAdvance(Nservers, *State);
} else {
(*VolatileState)
.SetNextIndex(nodeId, std::max((uint64_t)1, VolatileState->NextIndex[nodeId]-1))
Expand Down Expand Up @@ -384,6 +384,7 @@ void TRaft::ProcessTimeout(ITimeSource::Time now) {
nextVolatileState->NextIndex[id] = 1;
}
nextVolatileState->ElectionDue = MakeElection(now);
nextVolatileState->CommitIndex = VolatileState->CommitIndex;
VolatileState = std::move(nextVolatileState);
State->VotedFor = Id;
State->CurrentTerm ++;
Expand Down

0 comments on commit ec6622c

Please sign in to comment.