-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: race condition of concurrent snapshot-install and apply.
Problem: Concurrent snapshot-install and apply mess up `last_applied`. `finalize_snapshot_installation` runs in the `RaftCore` thread. `apply_to_state_machine` runs in a separate tokio task(thread). Thus there is chance the `last_applied` being reset to a previous value: - `apply_to_state_machine` is called and finished in a thread. - `finalize_snapshot_installation` is called in `RaftCore` thread and finished with `last_applied` updated. - `RaftCore` thread finished waiting for `apply_to_state_machine`, and updated `last_applied` to a previous value. ``` RaftCore: -. install-snapshot, .-> replicate_to_sm_handle.next(), | update last_applied=5 | update last_applied=2 | | v | task: apply 2------------------------' --------------------------------------------------------------------> time ``` Solution: Rule: All changes to state machine must be serialized. A temporary simple solution for now is to call all methods that modify state machine in `RaftCore` thread. But this way it blocks `RaftCore` thread. A better way is to move all tasks that modifies state machine to a standalone thread, and send update request back to `RaftCore` to update its fields such as `last_applied`
- Loading branch information
1 parent
4d58a51
commit eed681d
Showing
9 changed files
with
94 additions
and
131 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
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
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
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.