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

fix(vote): corner case of transfer leader #347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Yriuns
Copy link
Contributor

@Yriuns Yriuns commented Jan 14, 2022

transfer leader的corner case

问题场景:

  • 比如3节点abc,a是leader,a想transfer leader给 b,初始时term均为N
  • b收到timeout_now之后term变为N+1,发起选举。
  • a在handle_request_vote_request的时候需要unlock去拿last_log_id
  • 期间a还在给b发送心跳,b就会设置term为N+1
  • 心跳的response到达a,a更新term为N+1
  • a get last_log_id结束,重新拿到锁,发现term变了,拒绝给b投票。

此次transfer leader失败,需要等下次发起选举才能选出新leader,影响了集群的可用性

修改:

  • leader stepdown时记录下当前的term(disrupted_term)
  • 如果disrupted_term == previous_term,则设置disrupted标志

src/braft/node.cpp Outdated Show resolved Hide resolved
@Yriuns Yriuns changed the title fix(vote): retry when term changed fix(vote): corner case of transfer leader Jan 21, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants