Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
replication: Only update commit index if last stored is high enough
Browse files Browse the repository at this point in the history
A leader might have its last_stored field lagging behind its commit_index,
after it committed an index that it did not yet persist, while enough followers
for forming a majority did.

We don't wont to update this leader's commit_index until last_stored has caught
up.

Signed-off-by: Free Ekanayaka <free@ekanayaka.io>
  • Loading branch information
freeekanayaka committed Jun 1, 2023
1 parent c553bae commit d144504
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,8 @@ static void appendFollowerCb(struct raft_io_append *req, int status)
* commitIndex, set commitIndex = min(leaderCommit, index of last new
* entry).
*/
if (args->leader_commit > r->commit_index) {
if (args->leader_commit > r->commit_index &&
r->last_stored >= r->commit_index) {
r->commit_index = min(args->leader_commit, r->last_stored);
rv = replicationApply(r);
if (rv != 0) {
Expand Down Expand Up @@ -1101,6 +1102,7 @@ int replicationAppend(struct raft *r,
*/
if (n == 0) {
if ((args->leader_commit > r->commit_index) &&
r->last_stored >= r->commit_index &&
!replicationInstallSnapshotBusy(r)) {
r->commit_index = min(args->leader_commit, r->last_stored);
rv = replicationApply(r);
Expand Down

0 comments on commit d144504

Please sign in to comment.