Raft Cluster: Automatic learner promotion (#4392) - #4456
Conversation
Signed-off-by: quanyeyang <quanyemostima@gmail.com>
Signed-off-by: quanyeyang <quanyemostima@gmail.com>
The auto-promoter may promote a learner between the check and the ADDVOTER call, causing the command to fail with "already a voter". Treat either state as success so the helper tolerates the race. Signed-off-by: quanyeyang <quanyemostima@gmail.com>
Signed-off-by: quanyeyang <quanyemostima@gmail.com>
Signed-off-by: quanyeyang <quanyemostima@gmail.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Signed-off-by: quanyeyang <quanyemostima@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## cluster-v2 #4456 +/- ##
==============================================
+ Coverage 76.49% 76.55% +0.05%
==============================================
Files 166 166
Lines 83713 83789 +76
==============================================
+ Hits 64037 64142 +105
+ Misses 19676 19647 -29
🚀 New features to boost your workflow:
|
- NODE_FORGET could drop a five-voter cluster to four, bypassing the replacement-first rule that DEL_VOTER enforces. Reject forgetting a voter when it would bring the voting set below RAFT_TARGET_VOTERS. - On leader change, a pending proposal whose transition was already in the log (RAFT_QC_SAME) was re-appended, duplicating the entry. The second copy became a no-op at apply. Keep the pending proposal attached to the existing entry instead of re-appending. Signed-off-by: quanyeyang <quanyemostima@gmail.com>
Closes #4392.
Follow-up to #4094, which introduced non-voting Raft members (learners).
This PR adds automatic promotion of caught-up learners and, as part of that
work, serializes quorum-changing membership transitions so that Cluster V2
has at most one distinct voting-membership change in flight at a time.
Motivation
After #4094, newly joined nodes enter the cluster as non-voting learners and
must be promoted manually with
CLUSTER ADDVOTER.For the common bootstrap case, this requires the administrator to manage the
voter set explicitly even when no special voter placement policy is needed.
This PR makes the default behavior self-managing:
ADD_VOTERRaft entry and apply path.No new node flag or membership entry type is introduced.
Automatic learner promotion
The leader runs a one-way reconciliation controller:
The initial target is hard-coded to:
The controller is intentionally one-way:
size >= RAFT_TARGET_VOTERS, the controller is a no-op;automatically replaced.
A learner is eligible for automatic promotion only when it:
NODE_JOINand is no longer a MEET node;(
match_index >= raftLogLastIndex()).The actual membership mutation still goes through the existing
ADD_VOTERapply path.Serialized quorum membership changes
Automatic promotion also exposes a broader issue with overlapping membership
changes in the current config-on-apply model.
server.cluster->sizechanges only when a membership entry is applied.Without serialization, multiple membership changes could be proposed while
all of them still observe the same applied voter set.
For example:
To prevent this, Cluster V2 now allows at most one distinct
quorum-changing membership transition to remain unapplied at a time.
The following entries are considered quorum-changing:
ADD_VOTERDEL_VOTERNODE_JOIN ... voterNODE_FORGETof a voterLearner admission itself (
NODE_JOIN ... learner) does not modify the votingquorum and is therefore not serialized by this rule.
A membership transition is identified by:
The leader examines the unapplied log suffix:
and classifies a candidate transition as:
NONE— no quorum-changing transition is currently in flight;SAME— the same transition is already present in the log;CONFLICT— a different quorum-changing transition is still unapplied.A
CONFLICTtransition is rejected.For a retried pending proposal,
SAMEmeans the pending proposal remainsassociated with the already existing log entry instead of appending another
copy.
This is particularly important across leader changes: peer
match_indexvalues are reset when a new leader is elected, so re-running learner readiness
validation for an already logged
ADD_VOTERcould incorrectly reject atransition that is already being replicated.
This serialization rule applies to both automatic and manual membership
operations, not only to the auto-promoter.
Replacement-first voter changes
Because the automatic target is currently fixed at 5, manually reducing the
voter set below that target would conflict with the controller's policy.
CLUSTER DELVOTERtherefore rejects a demotion that would reduce the votercount below
RAFT_TARGET_VOTERS.Forgetting a voting node is subject to the same rule.
To replace a voter, the administrator uses a replacement-first workflow:
A manual
ADDVOTERmay temporarily increase the voter count above the target.The controller does not automatically demote the excess voter.
A future configurable voter target can provide the mechanism for explicitly
shrinking the voting set.
Relationship to future Cluster V2 work
Separating node admission from voting membership also helps future workflows
such as non-singleton cluster merging (#3868).
Joining nodes can first be admitted as learners without changing the voting
quorum, then promoted one at a time until the voter target is reached.
Candidate selection is intentionally simple in this PR. More advanced
placement policies, such as availability-zone-aware voter selection, belong
to #4393.
Safety scope
This PR serializes distinct quorum-changing membership transitions, but it
does not replace Cluster V2's existing config-on-apply membership model.
In particular, it does not implement Ongaro-style config-on-append or joint
consensus, and it does not eliminate the existing config-on-apply quorum-view
limitation documented in
design-docs/cluster-raft.md.The serialization rule follows the same engineering principle as Raft's
single-server membership changes while retaining Cluster V2's current
config-on-apply semantics.
Non-goals
Deferred to follow-up work:
Test cleanup
The test-only
raft_promote_start_cluster_votersbridge and most explicitraft_add_votercalls are no longer needed because ordinary Raft clusterstartup now converges automatically.
The PR also consolidates Raft test helpers so wire-protocol tests and
higher-level cluster tests reuse the same support code.
Tests
tests/unit/cluster/cluster-raft-autopromote.tclcovers:ADDVOTERabove the target without automatic demotion;DELVOTER;DELVOTERoperations not reducing the voter set below target.Existing Raft suites and generic cluster tests under
--cluster-raftwerealso updated to rely on automatic voter promotion instead of test-only manual
promotion.