Skip to content

Raft Cluster: replace failed voters one at a time - #5762

Open
quanyeyang wants to merge 2 commits into
valkey-io:cluster-v2from
quanyeyang:raft-replace-failed-voters
Open

quanyeyang wants to merge 2 commits into
valkey-io:cluster-v2from
quanyeyang:raft-replace-failed-voters

Conversation

@quanyeyang

Copy link
Copy Markdown
Member

Fixes #5726

With five voters, a failed voter still counts toward the target. This can leave the cluster with four available voters even when a healthy learner has caught up and is ready to vote.

The leader now scans the nodes once and counts the voters without the FAIL flag. At the target, it promotes a caught-up learner first. Once that promotion is applied, the leader can demote a still-failed voter if the remaining voters have a responsive majority. If no learner is ready, the failed voter keeps its vote. If the voting set is already above the target, the leader can use the existing surplus.

Each pass makes at most one membership change. With two failed voters and two eligible learners, the voting set goes from 5 to 6, back to 5, then repeats for the second failure. A failed cluster-voter yes node can also be demoted and will be eligible for promotion again once it recovers and catches up.

The slot migration test now accepts a healthy master,learner: a node can regain its role as a shard primary while remaining a Raft learner.

Testing

The Raft cluster suite passed locally (978 tests). The regression tests check the order of changes with two failed voters, replacement after a lagging learner catches up, and re-promotion of a recovered yes voter.

Count only non-FAIL voters toward the promotion target. This lets the
leader promote a caught-up learner when a failed voter still occupies
a seat. Once the voting set exceeds the target, demote a voter that is
still marked FAIL if the remaining voters have a responsive majority.

Reevaluate membership after each applied change. A failed yes voter
can also be replaced and is eligible for promotion again after recovery.

Signed-off-by: quanyeyang <quanyemostima@gmail.com>
@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 19cd9544-4ddd-46f3-ba27-7319ab455f50

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@valkey-review-bot

valkey-review-bot Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Review state

Ready for human review.
The reconnection leak in the voter quorum test is fixed in a2c54f1. test_defer at line 181 now restores DEBUG DISABLE-CLUSTER-RECONNECTION even when an assertion fails. No open findings. src/cluster_raft.c is unchanged since the last run, and the Tcl suites were not run here.

Risk: High. The leader's automatic ADD_VOTER/DEL_VOTER decisions change the Raft voting set, so a wrong choice can cost the cluster its quorum.

Open findings: none.

Resolved (1)

  • (minor) tests/unit/cluster/cluster-raft-autopromote.tcl:180 DEBUG DISABLE-CLUSTER-RECONNECTION was restored only after assertions, so a failure leaked it into the second foreach case in the same start_cluster block. Fixed by the test_defer registered right after the toggle.

Backport: Not needed. The PR targets the cluster-v2 feature branch and RAFT_TARGET_VOTERS / cluster_raft.c do not exist on any maintained release line.

Updated for a2c54f1 at 2026-12-05 12:06 UTC. The bot rewrites this comment on every review.

Use test_defer to re-enable reconnection on R0 even if an assertion
fails, so the next voter policy test starts with reconnection enabled.

Signed-off-by: quanyeyang <quanyemostima@gmail.com>
@charsyam

charsyam commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

@quanyeyang

  1. Failed-voter replacement stops short below RAFT_TARGET_VOTERS (src/cluster_raft.c) With 3 voters (1 FAIL) and a caught-up replacement learner, the leader promotes the learner (size becomes 4), but never demotes the
    failed voter because surplus requires server.cluster->size > RAFT_TARGET_VOTERS (5). The resulting 4-voter set needs all 3 live
    voters to commit (0 fault tolerance), whereas demoting the failed voter would restore a 3-voter / 2-vote quorum.
    If retaining the failed voter below the target is intentional, please clarify design-docs/cluster-raft.md (which currently implies
    promotion below the target replaces the failed voter) and add a test for that behavior.

  2. Leader-change test can skip setting cluster-voter yes (tests/unit/cluster/cluster-raft-autopromote.tcl)
    In "Raft autopromote: leader change: yes stays a voter after auto demotes back to 5" (cluster-node-timeout 500), the new leader can
    mark srv 0 as FAIL and auto-promote $remaining before raft_add_voter runs. Because raft_add_voter only calls raft_set_voter $node yes
    when the node is still a learner, the test can pass while $remaining is still auto (or flake if srv 0 recovers before demotion and
    $remaining is chosen for surplus demotion).
    Please set cluster-voter yes explicitly on $remaining and wait for the new leader to apply NODE_INFO before checking the final voter
    set.

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.

2 participants