Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support consistent read with leader lease #804

Open
Tracked by #806
drmingdrmer opened this issue Apr 28, 2023 · 1 comment
Open
Tracked by #806

Support consistent read with leader lease #804

drmingdrmer opened this issue Apr 28, 2023 · 1 comment

Comments

@drmingdrmer
Copy link
Member

drmingdrmer commented Apr 28, 2023

Openraft has a mechanism called leader lease. This mechanism ensures that a follower does not elect itself as a leader before a certain period of time, which is determined by adding the timer_config.leader_lease + timer_config.election_timeout. The follower refreshes the lease by updating the last-updated-time of the vote. However, the current issue is that the leader does not update the lease yet.

To support reading consistent state, openraft needs to :

  • The leader should extend its lease when a log is accepted by a quorum.
  • and add a public API such as Raft::read(sm: &mut impl RaftStateMachine) that atomically checks leader lease and reads some data from the state machine.

let current_vote = self.engine.state.vote_ref();
let utime = self.engine.state.vote_last_modified();
let timer_config = &self.engine.config.timer_config;
let mut election_timeout = if current_vote.is_committed() {
timer_config.leader_lease + timer_config.election_timeout
} else {
timer_config.election_timeout
};
if self.engine.is_there_greater_log() {
election_timeout += timer_config.smaller_log_timeout;
}

self.state.vote.update(*self.timer.now(), *vote);

Originally posted by @drmingdrmer in #262 (comment)

@github-actions
Copy link

👋 Thanks for opening this issue!

Get help or engage by:

  • /help : to print help messages.
  • /assignme : to assign this issue to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant