-
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.
The leader records the most recent time point when an RPC is initiated towards a target node. The highest timestamp associated with RPCs made to a quorum serves as the starting time point for a leader lease. Improve: use tokio::Instant to replace TimeState Use `Instant` for timekeeping instead of a custom `TimeState` struct. Because multiple components need to generate timestamp, not only the `RaftCore`, e.g., the `ReplicationCore`. And generating a timestamp is not in the hot path, therefore caching it introduces unnecessary complexity.
- Loading branch information
1 parent
2cabdae
commit e9eed21
Showing
24 changed files
with
293 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Leader lease | ||
|
||
Leader lease is a mechanism to prevent split-brain scenarios in which multiple leaders are elected in a cluster. | ||
|
||
It is implemented by the leader sending heartbeats(append-entries and install-snapshot request | ||
can be considered as heartbeat too) to the followers. | ||
If the followers do not receive any heartbeats within a certain time period `lease`, | ||
they will start an election to elect a new leader. | ||
|
||
## The lease for leader and follower | ||
|
||
The `lease` stored on the leader is smaller than the `lease` stored on a follower. | ||
The leader must not believe it is still valid while the follower has already started an election. | ||
|
||
## Extend the lease | ||
|
||
- A follower will extend the lease to `now + lease + timeout` when it receives a valid heartbeat from the leader, i.e., `leader.vote >= local.vote` . | ||
|
||
- A leader will extend the lease to `t + lease` when a quorum grants the leader at time `t`. | ||
|
||
When a heartbeat RPC call succeeds, | ||
it means the target node acknowledged the leader's clock time when the RPC was sent. | ||
|
||
If a time point `t` is acknowledged by a quorum, the leader can be sure that no | ||
other leader existed during the period `[t, t + lease]`. The leader can then extend its | ||
local lease to `t + lease`. | ||
|
||
The above `timeout` is the maximum time that can be taken by an operation that relies on the lease on the leader. | ||
|
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.