Skip to content

Commit

Permalink
Avoid transfer of snapshot log entry for the minority of the cluster …
Browse files Browse the repository at this point in the history
…(see #232)
  • Loading branch information
sakno committed May 2, 2024
1 parent 3fc2809 commit 368a7ff
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,28 @@ private async Task DoHeartbeats(TimeSpan period, IAuditTrail<IRaftLogEntry> audi
{
RenewLease(startTime.Elapsed);
UpdateLeaderStickiness();
await configurationStorage.ApplyAsync(Token).ConfigureAwait(false);
}

if (result.Value && ++commitQuorum == majority)
{
// majority of nodes accept entries with at least one entry from the current term
var count = await auditTrail.CommitAsync(currentIndex, Token).ConfigureAwait(false); // commit all entries starting from the first uncommitted index to the end
Logger.CommitSuccessful(currentIndex, count);
}
commitQuorum += Unsafe.BitCast<bool, byte>(result.Value);
}
}

if (commitQuorum < majority)
if (commitQuorum >= majority)
{
// majority of nodes accept entries with at least one entry from the current term
var count = await auditTrail.CommitAsync(currentIndex, Token).ConfigureAwait(false); // commit all entries starting from the first uncommitted index to the end
Logger.CommitSuccessful(currentIndex, count);
}
else
{
Logger.CommitFailed(quorum, commitIndex);
}

if (quorum < majority)
if (quorum >= majority)
{
await configurationStorage.ApplyAsync(Token).ConfigureAwait(false);
}
else
{
MoveToFollowerState(randomizeTimeout: false);
return;
Expand Down

0 comments on commit 368a7ff

Please sign in to comment.