diff --git a/src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/LeaderState.cs b/src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/LeaderState.cs index bb5e33bb0..81abd5c43 100644 --- a/src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/LeaderState.cs +++ b/src/cluster/DotNext.Net.Cluster/Net/Cluster/Consensus/Raft/LeaderState.cs @@ -169,24 +169,28 @@ private async Task DoHeartbeats(TimeSpan period, IAuditTrail 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(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;