-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: when append-entries, deleting entries after prev-log-id causes c…
…ommitted entry to be lost Problem: When append-entries, raft core removes old entries after `prev_log_id.index`, then append new logs sent from leader. Since deleting then appending entries are not atomic(two calls to `RaftStore`), deleting consistent entries may cause loss of committed entries, if server crashes after the delete. E.g., an example cluster state with logs as following and R1 now is the leader: ``` R1 1,1 1,2 1,3 R2 1,1 1,2 R3 ``` Committed entry `{1,2}` gets lost after the following steps: - R1 to R2: `append_entries(entries=[{1,2}, {1,3}], prev_log_id={1,1})` - R2 deletes 1,2 - R2 crash - R2 is elected as leader with R3, and only see 1,1; the committed entry 1,2 is lost. Solution: The safe way is to skip every entry that are consistent to the leader. And delete only the inconsistent entries. Another issue with this solution is that: Because we can not just delete `log[prev_log_id.index..]`, the commit index: - must be update only after append-entries, - and must point to a log entry that is consistent to leader. Or there could be chance applying an uncommitted entry: ``` R0 1,1 1,2 3,3 R1 1,1 1,2 2,3 R2 1,1 1,2 3,3 ``` - R0 to R1 `append_entries: entries=[{1,2}], prev_log_id = {1,1}, commit_index = 3` - R1 accepted this `append_entries` request but was not aware of that entry {2,3} is inconsistent to leader. Updating commit index to 3 allows it to apply an uncommitted entrie `{2,3}`.
- Loading branch information
1 parent
05ecf7e
commit 9540c90
Showing
3 changed files
with
217 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.