raftstore: optimize hibernate condition#19082
Conversation
|
Hi @jiadebin. Thanks for your PR. I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Welcome @jiadebin! |
ddd61bc to
080e0b2
Compare
f0cc9af to
2e8188b
Compare
f0511ba to
4f9b1af
Compare
| pub fn maybe_hibernate(&mut self) -> bool { | ||
| self.hibernate_state | ||
| .maybe_hibernate(self.peer.peer_id(), self.peer.region()) | ||
| pub fn maybe_hibernate(&mut self, down_peer_ids: &Vec<u64>) -> (bool, Vec<u64>) { |
There was a problem hiding this comment.
Please add some comments about when it should hibernate.
| // broadcasting hibernate request. Because non hibernate vote peers may | ||
| // be down, and they have not been detected as down peers. Down peers | ||
| // are expected to encounter heartbeat timeout and be in probe state. | ||
| let heartbeat_timeout_duration = self.ctx.cfg.raft_heartbeat_interval() * 3; |
There was a problem hiding this comment.
Code comment added: Using 3 times of raft_heartbeat_interval as heartbeat_timeout_duration to determine whether a peer is unreachable.
| cluster.must_put(b"k2", b"v2"); | ||
| } | ||
|
|
||
| /// Tests whether leader can hibernate when some voter is down. |
There was a problem hiding this comment.
| /// Tests whether leader can hibernate when some voter is down. | |
| /// Tests whether leader can hibernate when some voters are down. |
| thread::sleep(cluster.cfg.raft_store.raft_heartbeat_interval() * 2); | ||
| // Leader can go to sleep as voters can reach majority. | ||
| assert!(!awakened.load(Ordering::SeqCst)); | ||
|
|
There was a problem hiding this comment.
Before starting the down voter, write some data and then make sure alive peers can hibernate.
| } | ||
| } | ||
| if !self.raft_group.raft.prs().has_quorum(&matched_peer_ids) { | ||
| res.reason = "not enough matched peers"; |
There was a problem hiding this comment.
Not yet before, I've add a new integration test function test_hibernate_not_enough_matched_peers() to test it.
Signed-off-by: Debin <debin.jia@pingcap.com>
|
|
||
| fn all_agree_to_hibernate(&mut self) -> bool { | ||
| if self.fsm.maybe_hibernate() { | ||
| fn agree_to_hibernate(&mut self, down_peer_ids: &[u64]) -> bool { |
There was a problem hiding this comment.
nit: quorum_agree_to_hibernate might be a better name?
| where | ||
| F: Fn(&HashSet<u64>) -> bool, | ||
| { | ||
| let mut hibernate_vote_peer_ids = HashSet::default(); |
There was a problem hiding this comment.
Do learners participate in the hibernation "vote" as well? The term vote can be a bit confusing, since Raft learners are not voters. I know the existing code uses this terminology, just calling out the potential ambiguity.
There was a problem hiding this comment.
Yes, learners also participate. So I use hibernate_vote_xxx to distinguish it from "election vote".
| /// Check if all non hibernate vote peers are unreachable. | ||
| /// If one peer is unreachable, it must be in probe state and encounter | ||
| /// heartbeat timeout. | ||
| pub fn all_non_hibernate_vote_peers_unreachable( |
There was a problem hiding this comment.
naming suggestion: all_nonvote_peers_unreachable
I feel like it's not obvious what "non" refers to in the original name.
There was a problem hiding this comment.
Here I also want to use hibernate_vote_xxx to distinguish it from "election vote".
There was a problem hiding this comment.
ok, if we keep the function name maybe we can improve the comment to "Checks if all peers that have not sent a hibernate vote are unreachable."
| { | ||
| return false; | ||
| } | ||
| // If non hibernate vote peers are all unreachable, leader can skip |
There was a problem hiding this comment.
Just trying to learn: what happens if the leader has already hibernated and an unreachable follower later comes back online? Will that follower resume ticking and potentially trigger an election?
There was a problem hiding this comment.
Good point, I've read the relevant code, and here's my understanding:
- If an unreachable follower recovers from hibernated state, the missing_ticks mechanism can prevent it from blindly initiating an election. Instead, the leader will be woken up by this follower and resume broadcasting heartbeats, eventually bringing the entire cluster back to the hibernated idle state.
- If an unreachable follower restarts and recovers, and the leader has not been woken up before the follower reaches its election timeout, the follower will attempt to start an election. However, during the pre-vote phase, it can wake up the leader, discover that a valid leader still exists, and consequently abort the election.
- read_index() request on follower can also wake up leader.
|
/ok-to-test |
Signed-off-by: Debin <debin.jia@pingcap.com>
|
/ok-to-test |
Signed-off-by: Debin <debin.jia@pingcap.com>
|
/ok-to-test |
1 similar comment
|
/ok-to-test |
|
/retest-required |
Signed-off-by: Debin <debin.jia@pingcap.com>
|
/ok-to-test |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Connor1996, overvenus The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
/cherrypick release-8.5 |
close tikv#19070 Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
|
@jiadebin: new pull request created to branch DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
close #19070 1. Hibernate condition optimization: leader no need wait for all peers' hibernate votes if any non-voter peer is down and votes reach majority. 2. If non hibernate vote peers are all unreachable, leader can skip broadcasting hibernate request. This can reduce the number of messages before down peer is detected (10min by default). Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io> Signed-off-by: Debin <debin.jia@pingcap.com> Co-authored-by: Debin <debin.jia@pingcap.com>
What is changed and how it works?
Issue Number: Close #19070
What's Changed:
As noted in #19070, when a TiKV peer becomes unavailable, region leaders on other nodes are prevented from entering hibernation due to the current condition logic—which requires the leader to receive votes from all peers before hibernating. This requirement is overly strict. In practice, the leader only needs to confirm that it has received votes from all alive peers(referencing the down_peers field) and that a majority has been reached for raft voters.
Before Modification

After Modification

Related changes
pingcap/docs/pingcap/docs-cn:Check List
Tests
Side effects
Release note