Repository navigation
Speed up split-vote elections with the new FAILOVER_AUTH_NACK message - #3833
Conversation
In the current failover protocol a replica sends AUTH_REQUEST exactly once per epoch and each voter casts at most one vote per epoch. Despite the various delay heuristics in clusterHandleReplicaFailover that try to stagger replicas, concurrent elections can still collide on the same epoch. When the votes split and nobody reaches the quorum, the losing replica has no way to learn this in time and must first wait for the election to be declared expired after auth_timeout (2*cluster-node-timeout) and then wait another auth_retry_time (2*auth_timeout) before it is even allowed to start the next election with a higher epoch. Introduce a new message type, FAILOVER_AUTH_NACK, that voters reply with from every refusal branch. The replica counts incoming NACKs; since a voter never re-answers within the same epoch, once size - nack_count drops below the quorum the election is declared unwinnable and a new one is started with a higher epoch right away, shrinking recovery from the auth_timeout + auth_retry_time window to a few cron ticks. Wire compatibility is preserved by gating NACK emission on a new CLUSTER_NODE_FAILOVER_AUTH_NACK_SUPPORTED capability flag advertised in PING/PONG flags via clusterUpdateMyselfFlags. Peers that do not advertise the capability never see the new message type and fall back to the legacy auth_timeout path. Adding a new DEBUG CLUSTER-FAILOVER-DELAY <ms> hook overrides the delay computed in clusterHandleReplicaFailover for testing. Signed-off-by: Binbin <[email protected]>
|
This is an example without the auth_time reset (just print the logs but not reset failover_auth_time): one replica The other replica: |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds explicit FAILOVER_AUTH_NACK messaging and handling: wire contracts and capability flag, send/receive helpers, denial-path NACKs, NACK counting with election fast-fail, debug-configurable failover delay, and expanded parametrized tests. ChangesCluster Failover Authorization NACK Support
Sequence Diagram(s)sequenceDiagram
participant ComponentA
participant ComponentB
ComponentA->>ComponentB: observable interaction
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
src/cluster_legacy.h (1)
147-150: ⚡ Quick winPin the new wire payload size with a static assert.
This struct is now part of the cluster wire contract. A compile-time size check here would catch accidental padding or field changes before they silently alter the on-the-wire format.
♻️ Proposed fix
typedef struct { uint8_t reason; char notused1[24]; } clusterMsgDataFailoverNack; +static_assert(sizeof(clusterMsgDataFailoverNack) == 25, "unexpected FAILOVER_AUTH_NACK payload size");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/cluster_legacy.h` around lines 147 - 150, The new cluster wire struct clusterMsgDataFailoverNack must have its on-the-wire size pinned; add a compile-time assertion (e.g., static_assert or _Static_assert depending on project C standard) that sizeof(clusterMsgDataFailoverNack) == 25 (1 byte for reason + 24 bytes for notused1) with a clear message indicating this pins the wire format, so any accidental padding/field changes will fail to compile; place the assertion next to the struct definition and use the same symbol name in the assertion.src/cluster_legacy.c (1)
70-71: ⚡ Quick winMake the new NACK helpers file-local.
clusterSendFailoverNack()andclusterProcessFailoverAuthNack()are only used inside this translation unit, so keeping them non-staticneedlessly widens the symbol surface.Proposed change
-void clusterProcessFailoverAuthNack(clusterNode *sender, clusterMsg *request); -void clusterSendFailoverNack(clusterNode *node, uint8_t reason); +static void clusterProcessFailoverAuthNack(clusterNode *sender, clusterMsg *request); +static void clusterSendFailoverNack(clusterNode *node, uint8_t reason); ... -void clusterSendFailoverNack(clusterNode *node, uint8_t reason) { +static void clusterSendFailoverNack(clusterNode *node, uint8_t reason) { ... -void clusterProcessFailoverAuthNack(clusterNode *sender, clusterMsg *request) { +static void clusterProcessFailoverAuthNack(clusterNode *sender, clusterMsg *request) {As per coding guidelines "Use static keyword for file-local functions in C code".
Also applies to: 5312-5324, 5443-5471
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/cluster_legacy.c` around lines 70 - 71, The two helper functions clusterSendFailoverNack and clusterProcessFailoverAuthNack are only used within this translation unit and should be made file-local: add the static qualifier to their forward declarations and their function definitions (and to any other internally-used helpers referenced in the same areas noted, e.g., the helpers around the 5312-5324 and 5443-5471 regions) so their symbols are not exported from the object file; ensure prototypes and definitions match (both marked static).tests/unit/cluster/failover2.tcl (1)
79-79: ⚡ Quick winConsider using the
pause_processhelper for consistency.Line 79 uses
exec kill -SIGSTOPdirectly, while the rest of the file uses thepause_processhelper (lines 15, 34, 120, 182). If atomic pausing is intentional for same-epoch testing, consider documenting the rationale; otherwise, prefer the framework helper:♻️ Align with test framework pattern
- exec kill -SIGSTOP [srv 0 pid] [srv -1 pid] [srv -2 pid] + pause_process [srv 0 pid] + pause_process [srv -1 pid] + pause_process [srv -2 pid]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/cluster/failover2.tcl` at line 79, Replace the direct call to exec kill -SIGSTOP used on the test processes with the existing pause_process helper for consistency with this test suite (the helper is used at lines where pause_process is referenced); locate the line containing exec kill -SIGSTOP [srv 0 pid] [srv -1 pid] [srv -2 pid] and change it to call pause_process for each target process (or document in a short comment why an atomic SIGSTOP across multiple pids is required if you intentionally need simultaneous pausing), ensuring you use the same helper signature and import/context as other uses in this file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/cluster_legacy.c`:
- Around line 70-71: The two helper functions clusterSendFailoverNack and
clusterProcessFailoverAuthNack are only used within this translation unit and
should be made file-local: add the static qualifier to their forward
declarations and their function definitions (and to any other internally-used
helpers referenced in the same areas noted, e.g., the helpers around the
5312-5324 and 5443-5471 regions) so their symbols are not exported from the
object file; ensure prototypes and definitions match (both marked static).
In `@src/cluster_legacy.h`:
- Around line 147-150: The new cluster wire struct clusterMsgDataFailoverNack
must have its on-the-wire size pinned; add a compile-time assertion (e.g.,
static_assert or _Static_assert depending on project C standard) that
sizeof(clusterMsgDataFailoverNack) == 25 (1 byte for reason + 24 bytes for
notused1) with a clear message indicating this pins the wire format, so any
accidental padding/field changes will fail to compile; place the assertion next
to the struct definition and use the same symbol name in the assertion.
In `@tests/unit/cluster/failover2.tcl`:
- Line 79: Replace the direct call to exec kill -SIGSTOP used on the test
processes with the existing pause_process helper for consistency with this test
suite (the helper is used at lines where pause_process is referenced); locate
the line containing exec kill -SIGSTOP [srv 0 pid] [srv -1 pid] [srv -2 pid] and
change it to call pause_process for each target process (or document in a short
comment why an atomic SIGSTOP across multiple pids is required if you
intentionally need simultaneous pausing), ensuring you use the same helper
signature and import/context as other uses in this file.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5e5ebad9-589c-475d-8218-e3d48f92cb1b
📒 Files selected for processing (6)
src/cluster_legacy.csrc/cluster_legacy.hsrc/debug.csrc/server.csrc/server.htests/unit/cluster/failover2.tcl
zuiderkwast
left a comment
There was a problem hiding this comment.
Looks good in general.
Have you consider using the light header for NACK? If we use it from the start, we don't need to support the non-light variant.
Yes, i did consider using a light header, but we do need the And another reason, i want to keep the AUTH_REQUEST / AUTH_ACK / AUTH_NACK handling logic in one place. Keeping symmetry across these three election messages. NACK is point-to-point and only emitted during a failed elections, so i think i can accept it. BUT of course, we can use light header for this type. |
Co-authored-by: Viktor Söderqvist <[email protected]> Signed-off-by: Binbin <[email protected]>
Signed-off-by: Binbin <[email protected]>
…the failover" test Signed-off-by: Binbin <[email protected]>
Signed-off-by: Binbin <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/unit/cluster/failover2.tcl (2)
78-78:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winTypo in comment.
"Killing there primary nodes" should be "Killing three primary nodes".
- # Killing there primary nodes. + # Killing three primary nodes.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/cluster/failover2.tcl` at line 78, Typo in test comment: update the comment string "Killing there primary nodes." in tests/unit/cluster/failover2.tcl to read "Killing three primary nodes." so the intent is clear; locate the commented line containing that exact phrase and replace "there" with "three".
70-70:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winGrammar issue in test name.
The test name contains "then they are elected" which should be "when they are elected" for grammatical correctness.
- test "Primaries will not time out then they are elected in the same epoch - delay $delay" { + test "Primaries will not time out when they are elected in the same epoch - delay $delay" {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/cluster/failover2.tcl` at line 70, The test name string "Primaries will not time out then they are elected in the same epoch - delay $delay" has a grammar mistake; update the test declaration to replace "then" with "when" so it reads "Primaries will not time out when they are elected in the same epoch - delay $delay" (locate the test block that begins with the same quoted title and change the text there).Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@tests/unit/cluster/failover2.tcl`:
- Line 78: Typo in test comment: update the comment string "Killing there
primary nodes." in tests/unit/cluster/failover2.tcl to read "Killing three
primary nodes." so the intent is clear; locate the commented line containing
that exact phrase and replace "there" with "three".
- Line 70: The test name string "Primaries will not time out then they are
elected in the same epoch - delay $delay" has a grammar mistake; update the test
declaration to replace "then" with "when" so it reads "Primaries will not time
out when they are elected in the same epoch - delay $delay" (locate the test
block that begins with the same quoted title and change the text there).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2f09e5f2-a421-48f6-843d-4f1f753114f9
📒 Files selected for processing (2)
src/cluster_legacy.ctests/unit/cluster/failover2.tcl
🚧 Files skipped from review as they are similar to previous changes (1)
- src/cluster_legacy.c
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #3833 +/- ##
============================================
+ Coverage 76.89% 77.02% +0.12%
============================================
Files 162 162
Lines 81843 81917 +74
============================================
+ Hits 62937 63099 +162
+ Misses 18906 18818 -88
🚀 New features to boost your workflow:
|
Signed-off-by: Binbin <[email protected]>
Let's use the normal header for NACK now. In the future, we can add light variant of all of these. |
zuiderkwast
left a comment
There was a problem hiding this comment.
LGTM. Some comments/questions. You can check if you agree or not, or just merge.
Signed-off-by: Binbin <[email protected]>
Signed-off-by: Binbin <[email protected]>
sarthakaggarwal97
left a comment
There was a problem hiding this comment.
I did try this out with valkey-fuzzer and it looks to be passing 100 fuzzer runs: https://github.com/valkey-io/valkey-fuzzer/actions/runs/27182824004
Signed-off-by: Binbin <[email protected]>
Signed-off-by: Binbin <[email protected]>
…valkey-io#3833) In the current failover protocol, a replica sends one AUTH_REQUEST per epoch and each voter casts at most one vote per epoch. Despite the various delay heuristics in `clusterHandleReplicaFailover` that try to stagger the replicas, concurrent elections can still collide on the same epoch. When the vote is split and nobody reaches the quorum, the losing replica cannot learn this in time: it must first wait for the election to be declared expired after auth_timeout (2 × cluster-node-timeout), and then wait another auth_retry_time (2 × auth_timeout) before it is allowed to start the next election with a higher epoch. This PR introduces a new message type, FAILOVER_AUTH_NACK, that a voter replies with in every rejection branch (NOT_SAFE, REQ_EPOCH_OLD, ALREADY_VOTED, REQ_IS_PRIMARY, NO_PRIMARY, PRIMARY_UP, STALE_CONFIG). The replica counts the NACKs it receives; since a voter never answers twice in the same epoch, the most votes it could still gather is bounded by the voters that have not NACKed. Once that bound drops below the quorum, the election is declared unwinnable and a new one is started immediately with a higher epoch, shrinking recovery from the auth_timeout + auth_retry_time window down to a few cron ticks. A voting primary that is itself FAIL can never reply (it neither ACKs nor NACKs) yet is still counted in cluster->size, so it is excluded from this bound: the achievable votes are `size - size_fail - nack_count`, where size_fail is the number of FAIL voting primaries maintained in clusterUpdateState(). Without this, a split vote among the replicas of several primaries that went down together could never push nack_count high enough, and the replica would fall back to the slow auth_timeout path. The quorum itself is still computed from the full size, since a failover must be authorized by a majority of the whole configuration. Wire compatibility is preserved by gating NACK sending behind a new capability flag, CLUSTER_NODE_FAILOVER_AUTH_NACK_SUPPORTED, advertised in the PING/PONG flags via `clusterUpdateMyselfFlags`. Nodes that do not advertise this capability will never see the new message type and fall back to the legacy auth_timeout path. Granted (ACK) and rejected (NACK) votes are logged symmetrically per epoch, so the vote tally of an election can be reconstructed from the logs. Two DEBUG hooks are added for testing: - DEBUG CLUSTER-FAILOVER-DELAY <ms>: override the failover delay computed in clusterHandleReplicaFailover. - DEBUG CLUSTER-FAILOVER-EPOCH <epoch>: force the next election started by this replica to run in the given epoch (consumed once, then back to currentEpoch+1), so several replicas can be made to contend in the same epoch and deterministically reproduce a split vote. Signed-off-by: Binbin <[email protected]> Signed-off-by: Viktor Söderqvist <[email protected]> Co-authored-by: Viktor Söderqvist <[email protected]>
A NACK for an old election could be counted against the current one, since the receiver only checked the sender's header epoch. Carry the rejected request's epoch in the NACK and only count exact matches. Fixes #4627. **Wire format change.** `clusterMsgDataFailoverNack` grows from 1 byte (`reason`) to 16 bytes (`epoch`, `reason`, 7 reserved). `CLUSTER_NODE_FAILOVER_AUTH_NACK_SUPPORTED` is unchanged, and `clusterIsValidPacket` requires an exact length for this type, so a node with this change and a node without it will drop each other's NACKs (one `LL_WARNING` per dropped packet) and fall back to the timeout-based election retry that predates #3833. Nothing released sets that capability bit (#3833 is only on `unstable`), so this only affects mixed `unstable` builds; it is not a rolling-upgrade concern for any released version. Signed-off-by: Dante Knowles <[email protected]>
A NACK for an old election could be counted against the current one, since the receiver only checked the sender's header epoch. Carry the rejected request's epoch in the NACK and only count exact matches. Fixes #4627. **Wire format change.** `clusterMsgDataFailoverNack` grows from 1 byte (`reason`) to 16 bytes (`epoch`, `reason`, 7 reserved). `CLUSTER_NODE_FAILOVER_AUTH_NACK_SUPPORTED` is unchanged, and `clusterIsValidPacket` requires an exact length for this type, so a node with this change and a node without it will drop each other's NACKs (one `LL_WARNING` per dropped packet) and fall back to the timeout-based election retry that predates #3833. Nothing released sets that capability bit (#3833 is only on `unstable`), so this only affects mixed `unstable` builds; it is not a rolling-upgrade concern for any released version. Signed-off-by: Dante Knowles <[email protected]> Backport-Source-PR: 4654
FAILOVER_AUTH_NACK (#3833) lets a candidate abandon an election as soon as the votes it can still collect drop below quorum, instead of waiting for auth_timeout. Every NACK is counted, but most rejection reasons (NO_PRIMARY, PRIMARY_UP, NOT_SAFE, REQ_IS_PRIMARY) describe state that a new epoch leaves unchanged: the voters answer the next request identically, so resetting only restarts the election at event-loop frequency, bumping the epoch and re-broadcasting a request that cannot win on every round. Count only the reasons that carry split-vote information, i.e. that a fresh epoch can actually change: ALREADY_VOTED (the vote is freed in the next epoch), REQ_EPOCH_OLD (the next request carries a higher epoch) and STALE_CONFIG (the voter sends an UPDATE just before the NACK). The rest are ignored, leaving those elections to expire and be rescheduled on the auth_retry_time cadence. Add a regression test where the voters CLUSTER FORGET the failed primary so that every request is answered with NO_PRIMARY: the candidate must keep one election per auth_retry_time instead of retrying once per NACK. Signed-off-by: Binbin <[email protected]>
FAILOVER_AUTH_NACK (#3833) lets a candidate abandon an election as soon as the votes it can still collect drop below quorum, instead of waiting for auth_timeout. Every NACK is counted, but most rejection reasons (NO_PRIMARY, PRIMARY_UP, NOT_SAFE, REQ_IS_PRIMARY) describe state that a new epoch leaves unchanged: the voters answer the next request identically, so resetting only restarts the election at event-loop frequency, bumping the epoch and re-broadcasting a request that cannot win on every round. Count only the reasons that carry split-vote information, i.e. that a fresh epoch can actually change: ALREADY_VOTED (the vote is freed in the next epoch), REQ_EPOCH_OLD (the next request carries a higher epoch) and STALE_CONFIG (the voter sends an UPDATE just before the NACK). The rest are ignored, leaving those elections to expire and be rescheduled on the auth_retry_time cadence. Add a regression test where the voters CLUSTER FORGET the failed primary so that every request is answered with NO_PRIMARY: the candidate must keep one election per auth_retry_time instead of retrying once per NACK. Signed-off-by: Binbin <[email protected]> Backport-Source-PR: 4700
FAILOVER_AUTH_NACK (#3833) lets a candidate abandon an election as soon as the votes it can still collect drop below quorum, instead of waiting for auth_timeout. Every NACK is counted, but most rejection reasons (NO_PRIMARY, PRIMARY_UP, NOT_SAFE, REQ_IS_PRIMARY) describe state that a new epoch leaves unchanged: the voters answer the next request identically, so resetting only restarts the election at event-loop frequency, bumping the epoch and re-broadcasting a request that cannot win on every round. Count only the reasons that carry split-vote information, i.e. that a fresh epoch can actually change: ALREADY_VOTED (the vote is freed in the next epoch), REQ_EPOCH_OLD (the next request carries a higher epoch) and STALE_CONFIG (the voter sends an UPDATE just before the NACK). The rest are ignored, leaving those elections to expire and be rescheduled on the auth_retry_time cadence. Add a regression test where the voters CLUSTER FORGET the failed primary so that every request is answered with NO_PRIMARY: the candidate must keep one election per auth_retry_time instead of retrying once per NACK. Signed-off-by: Binbin <[email protected]> Backport-Source-PR: 4700
The test pauses three primaries at once and assumes each replica ranks its failed primary correctly, but a replica ranks it only among the failed primaries it already knows about. In the job log the replica of the third primary received the FAIL for its own primary at 08:40:02.674 and the FAIL for the first primary only at 08:40:02.676. It therefore logged primary rank #0, took the best ranked replica path and started its election at once for epoch 12, the same epoch the replica of the first primary (correctly rank 0) had just started. With five voting primaries left and a quorum of 4, the votes split 2 and 3. Nobody won epoch 12, so neither replica saw a newer config epoch to reset on, and both logged Failover attempt expired from 08:40:32 (30 s auth timeout at cluster-node-timeout 15000). The retry comes after 60 s, later than the test's 50 s wait, which failed at 08:40:37. The server recovers on its own after the retry, so this is a test that depends on a FAIL propagation order that 9.1 does not guarantee, not a broken promise. On 9.1 a same-epoch split vote can only end by timeout, so the test's no-expiry assertion holds only when the replicas rank themselves from complete information. Holding the elections until all seven live nodes see all three primaries as fail gives ranks 0, 1 and 2, so the elections are staggered by the per-rank delay and run in distinct epochs. The patch uses only what this branch has: the cluster-replica-no-failover config and the existing wait_node_marked_fail polling helper, with no fixed sleeps. The default branch fixed split votes with a new product feature (FAILOVER_AUTH_NACK, f2c1c5e, #3833), which touches cluster_legacy.c, debug.c and server.c and is not suitable to port to a release branch as a CI fix. The already ported #3946 (5cf0ff9) only lengthens the per-rank delay and cannot help when the rank itself is computed as 0.
The log shows a split vote. Replica 7 won epoch 11 at 07:36:49.175. Replicas 8 and 9 then both started an election for epoch 12 within 17 ms of each other (49.274 and 49.291) and got 3 and 2 votes against a quorum of 4, so neither could win. They waited out the 30 s auth timeout (cluster-node-timeout 15000 times 2) and logged 'Failover attempt expired' at 07:37:19, and the retry only comes after 60 s, so the test's 50 s wait ended first. They collided because each replica starts its election delay when it learns that its own primary is FAIL, and those moments differed: replica 8 marked its primary failed at 47.477 and scheduled at 47.577, while replica 9 scheduled at 48.156. That 579 ms difference cancelled the 500 ms per-rank spacing, leaving the rank 2 and rank 1 replicas due at 49.572 and 49.642. When replica 7 won, both were moved 500 ms earlier, both were already overdue, and both fired on their next cron tick with the same currentEpoch. The server on 8.1 has no way to recover quickly from a split vote. It only resets an election when another node claims an equal or higher config epoch, and here nobody won epoch 12. The default branch fixed that in product code with the FAILOVER_AUTH_NACK feature (f2c1c5e, #3833), which is a new protocol message and not a backport candidate. So the fix belongs in the test. Holding the replicas with cluster-replica-no-failover until all live nodes (voters 3 to 6 and replicas 7 to 9) see all three primaries as FAIL makes the replicas compute their delays at nearly the same moment with the full failed primary rank, so the rank spacing the server relies on is intact. The test still fails over three shards at once and keeps both assertions (no epoch 0 election, no 'Failover attempt expired'), so nothing is weakened. It uses only helpers and a config this branch already has (wait_node_marked_fail, cluster-replica-no-failover).
The test pauses three primaries at once and assumes each replica ranks its failed primary correctly, but a replica ranks it only among the failed primaries it already knows about. In the job log the replica of the third primary received the FAIL for its own primary at 08:40:02.674 and the FAIL for the first primary only at 08:40:02.676. It therefore logged primary rank #0, took the best ranked replica path and started its election at once for epoch 12, the same epoch the replica of the first primary (correctly rank 0) had just started. With five voting primaries left and a quorum of 4, the votes split 2 and 3. Nobody won epoch 12, so neither replica saw a newer config epoch to reset on, and both logged Failover attempt expired from 08:40:32 (30 s auth timeout at cluster-node-timeout 15000). The retry comes after 60 s, later than the test's 50 s wait, which failed at 08:40:37. The server recovers on its own after the retry, so this is a test that depends on a FAIL propagation order that 9.1 does not guarantee, not a broken promise. On 9.1 a same-epoch split vote can only end by timeout, so the test's no-expiry assertion holds only when the replicas rank themselves from complete information. Holding the elections until all seven live nodes see all three primaries as fail gives ranks 0, 1 and 2, so the elections are staggered by the per-rank delay and run in distinct epochs. The patch uses only what this branch has: the cluster-replica-no-failover config and the existing wait_node_marked_fail polling helper, with no fixed sleeps. The default branch fixed split votes with a new product feature (FAILOVER_AUTH_NACK, f2c1c5e, #3833), which touches cluster_legacy.c, debug.c and server.c and is not suitable to port to a release branch as a CI fix. The already ported #3946 (5cf0ff9) only lengthens the per-rank delay and cannot help when the rank itself is computed as 0.
The test pauses three primaries at once and assumes each replica ranks its failed primary correctly, but a replica ranks it only among the failed primaries it already knows about. In the job log the replica of the third primary received the FAIL for its own primary at 08:40:02.674 and the FAIL for the first primary only at 08:40:02.676. It therefore logged primary rank #0, took the best ranked replica path and started its election at once for epoch 12, the same epoch the replica of the first primary (correctly rank 0) had just started. With five voting primaries left and a quorum of 4, the votes split 2 and 3. Nobody won epoch 12, so neither replica saw a newer config epoch to reset on, and both logged Failover attempt expired from 08:40:32 (30 s auth timeout at cluster-node-timeout 15000). The retry comes after 60 s, later than the test's 50 s wait, which failed at 08:40:37. The server recovers on its own after the retry, so this is a test that depends on a FAIL propagation order that 9.1 does not guarantee, not a broken promise. On 9.1 a same-epoch split vote can only end by timeout, so the test's no-expiry assertion holds only when the replicas rank themselves from complete information. Holding the elections until all seven live nodes see all three primaries as fail gives ranks 0, 1 and 2, so the elections are staggered by the per-rank delay and run in distinct epochs. The patch uses only what this branch has: the cluster-replica-no-failover config and the existing wait_node_marked_fail polling helper, with no fixed sleeps. The default branch fixed split votes with a new product feature (FAILOVER_AUTH_NACK, f2c1c5e, #3833), which touches cluster_legacy.c, debug.c and server.c and is not suitable to port to a release branch as a CI fix. The already ported #3946 (5cf0ff9) only lengthens the per-rank delay and cannot help when the rank itself is computed as 0.
The log shows a split vote. Replica 7 won epoch 11 at 07:36:49.175. Replicas 8 and 9 then both started an election for epoch 12 within 17 ms of each other (49.274 and 49.291) and got 3 and 2 votes against a quorum of 4, so neither could win. They waited out the 30 s auth timeout (cluster-node-timeout 15000 times 2) and logged 'Failover attempt expired' at 07:37:19, and the retry only comes after 60 s, so the test's 50 s wait ended first. They collided because each replica starts its election delay when it learns that its own primary is FAIL, and those moments differed: replica 8 marked its primary failed at 47.477 and scheduled at 47.577, while replica 9 scheduled at 48.156. That 579 ms difference cancelled the 500 ms per-rank spacing, leaving the rank 2 and rank 1 replicas due at 49.572 and 49.642. When replica 7 won, both were moved 500 ms earlier, both were already overdue, and both fired on their next cron tick with the same currentEpoch. The server on 8.1 has no way to recover quickly from a split vote. It only resets an election when another node claims an equal or higher config epoch, and here nobody won epoch 12. The default branch fixed that in product code with the FAILOVER_AUTH_NACK feature (f2c1c5e, #3833), which is a new protocol message and not a backport candidate. So the fix belongs in the test. Holding the replicas with cluster-replica-no-failover until all live nodes (voters 3 to 6 and replicas 7 to 9) see all three primaries as FAIL makes the replicas compute their delays at nearly the same moment with the full failed primary rank, so the rank spacing the server relies on is intact. The test still fails over three shards at once and keeps both assertions (no epoch 0 election, no 'Failover attempt expired'), so nothing is weakened. It uses only helpers and a config this branch already has (wait_node_marked_fail, cluster-replica-no-failover).
The test rejects a split vote, which this branch's server can only resolve by letting the election expire. In the log replica 9 won epoch 8 at 09:10:11.797, then replicas 7 and 8 both started an election for epoch 9 at 09:10:12.143 and 09:10:12.145. Primaries 3 and 6 and the new primary 9 voted for replica 7, primaries 4 and 5 voted for replica 8, so the votes were 3 to 2 with a needed quorum of 4 and no one won the epoch. Because no node claimed an epoch equal to or higher than 9, neither election was reset, and both replicas logged "Failover attempt expired" from 09:10:42. On 8.0 the retry comes after four times the node timeout, 60 s with cluster-node-timeout 15000, while the test waits 50 s and failed at 09:10:46. The election delay on 8.0 is a fixed 500 + random() % 500 ms with no ranking across failed shards, so the larger node timeout ported earlier does not space the shards' elections here and only makes the retry slower. A split vote in which no candidate reaches the majority, followed by a timeout and a retry, is correct server behaviour on 8.0, so the test should accept it rather than the server changing. The exception is narrow: a replica may time out only if it started an election in an epoch in which another replica also started one and which no replica won, as read from the "Starting a failover election for epoch" and "configEpoch set to N after successful failover" log lines. A replica that times out although another node won its epoch, which is what the test exists to catch, still fails. I kept the natural timing of the three elections instead of releasing the replicas one by one, because serialising them would stop the test from ever exercising same-epoch elections or the false epoch 0 case. No product change is made: upstream avoids or resolves split votes with features (failed primary ranking in #1018, the FAILOVER_AUTH_NACK message in #3833) that are not minimal backports for this branch. CI-Fix-Job: test-ubuntu-latest CI-Fix-Run: https://github.com/valkey-io/valkey/actions/runs/46245707417 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
While R 8 drops every packet with CLOSE-CLUSTER-LINK-ON-PACKET-DROP on, each dropped packet closes its link. R 8 closed all six outbound links at 09:29:53.720, and the filter was lifted at 53.868. R 8 saw R 7's claim of epoch 11 at 53.871, reset its election and started a new one for epoch 12 at 54.426. clusterNodeCronHandleReconnect only retries a node with no inbound link after node_timeout/2/10, which is 750 ms with this test's 15000 ms node timeout, and 54.426 is 706 ms after the last attempt. Primaries 3 and 4 accepted a connection only at 54.527 and logged neither a grant nor a denial for epoch 12. The vote request is broadcast once, only over links that exist, so R 8 got 3 votes (primaries 5 and 6, and R 7) of the 4 it needed. It logged 'Failover attempt expired' at 09:30:24 and the test's 50 second wait ran out. The test assumed R 8's links were back by the time its new election started, which the server does not guarantee: the new election starts 500 to 1000 ms after the reset and a reconnect can take up to 750 ms plus a cron tick. The fix holds the moving part still instead of waiting longer. It sets cluster-replica-no-failover yes on R 8 just before lifting the filter, waits until R 8 and each voter (R 3 to R 7) report each other's linkstate as connected, then sets it back to no. Both directions matter because the request goes over the candidate's outbound link and the vote comes back over the voter's outbound link. The hold does not weaken the test: the election reset happens in packet processing regardless of the config, and if it did not happen R 8 would still sit in its epoch 11 election after release and fail both the role wait and the 'Failover attempt expired' check. The same linkstate wait is what the default branch uses for the same kind of race in the config epoch test of this file (from #3833). CI-Fix-Job: test-ubuntu-tls-no-tls CI-Fix-Run: https://github.com/valkey-io/valkey/actions/runs/46616296383 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
The test rejects a split vote, which this branch's server can only resolve by letting the election expire. In the log replica 9 won epoch 8 at 09:10:11.797, then replicas 7 and 8 both started an election for epoch 9 at 09:10:12.143 and 09:10:12.145. Primaries 3 and 6 and the new primary 9 voted for replica 7, primaries 4 and 5 voted for replica 8, so the votes were 3 to 2 with a needed quorum of 4 and no one won the epoch. Because no node claimed an epoch equal to or higher than 9, neither election was reset, and both replicas logged "Failover attempt expired" from 09:10:42. On 8.0 the retry comes after four times the node timeout, 60 s with cluster-node-timeout 15000, while the test waits 50 s and failed at 09:10:46. The election delay on 8.0 is a fixed 500 + random() % 500 ms with no ranking across failed shards, so the larger node timeout ported earlier does not space the shards' elections here and only makes the retry slower. A split vote in which no candidate reaches the majority, followed by a timeout and a retry, is correct server behaviour on 8.0, so the test should accept it rather than the server changing. The exception is narrow: a replica may time out only if it started an election in an epoch in which another replica also started one and which no replica won, as read from the "Starting a failover election for epoch" and "configEpoch set to N after successful failover" log lines. A replica that times out although another node won its epoch, which is what the test exists to catch, still fails. I kept the natural timing of the three elections instead of releasing the replicas one by one, because serialising them would stop the test from ever exercising same-epoch elections or the false epoch 0 case. No product change is made: upstream avoids or resolves split votes with features (failed primary ranking in #1018, the FAILOVER_AUTH_NACK message in #3833) that are not minimal backports for this branch. CI-Fix-Job: test-ubuntu-latest CI-Fix-Run: https://github.com/valkey-io/valkey/actions/runs/46245707417 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
While R 8 drops every packet with CLOSE-CLUSTER-LINK-ON-PACKET-DROP on, each dropped packet closes its link. R 8 closed all six outbound links at 09:29:53.720, and the filter was lifted at 53.868. R 8 saw R 7's claim of epoch 11 at 53.871, reset its election and started a new one for epoch 12 at 54.426. clusterNodeCronHandleReconnect only retries a node with no inbound link after node_timeout/2/10, which is 750 ms with this test's 15000 ms node timeout, and 54.426 is 706 ms after the last attempt. Primaries 3 and 4 accepted a connection only at 54.527 and logged neither a grant nor a denial for epoch 12. The vote request is broadcast once, only over links that exist, so R 8 got 3 votes (primaries 5 and 6, and R 7) of the 4 it needed. It logged 'Failover attempt expired' at 09:30:24 and the test's 50 second wait ran out. The test assumed R 8's links were back by the time its new election started, which the server does not guarantee: the new election starts 500 to 1000 ms after the reset and a reconnect can take up to 750 ms plus a cron tick. The fix holds the moving part still instead of waiting longer. It sets cluster-replica-no-failover yes on R 8 just before lifting the filter, waits until R 8 and each voter (R 3 to R 7) report each other's linkstate as connected, then sets it back to no. Both directions matter because the request goes over the candidate's outbound link and the vote comes back over the voter's outbound link. The hold does not weaken the test: the election reset happens in packet processing regardless of the config, and if it did not happen R 8 would still sit in its epoch 11 election after release and fail both the role wait and the 'Failover attempt expired' check. The same linkstate wait is what the default branch uses for the same kind of race in the config epoch test of this file (from #3833). CI-Fix-Job: test-ubuntu-tls-no-tls CI-Fix-Run: https://github.com/valkey-io/valkey/actions/runs/46616296383 Signed-off-by: valkeyrie-ops[bot] <284117741+valkeyrie-ops[bot]@users.noreply.github.com>
In the current failover protocol, a replica sends one AUTH_REQUEST per epoch and
each voter casts at most one vote per epoch. Despite the various delay heuristics
in
clusterHandleReplicaFailoverthat try to stagger the replicas, concurrentelections can still collide on the same epoch. When the vote is split and nobody
reaches the quorum, the losing replica cannot learn this in time: it must first
wait for the election to be declared expired after auth_timeout (2 ×
cluster-node-timeout), and then wait another auth_retry_time (2 × auth_timeout)
before it is allowed to start the next election with a higher epoch.
This PR introduces a new message type, FAILOVER_AUTH_NACK, that a voter replies
with in every rejection branch (NOT_SAFE, REQ_EPOCH_OLD, ALREADY_VOTED,
REQ_IS_PRIMARY, NO_PRIMARY, PRIMARY_UP, STALE_CONFIG). The replica counts the
NACKs it receives; since a voter never answers twice in the same epoch, the most
votes it could still gather is bounded by the voters that have not NACKed. Once
that bound drops below the quorum, the election is declared unwinnable and a new
one is started immediately with a higher epoch, shrinking recovery from the
auth_timeout + auth_retry_time window down to a few cron ticks.
A voting primary that is itself FAIL can never reply (it neither ACKs nor NACKs)
yet is still counted in cluster->size, so it is excluded from this bound: the
achievable votes are
size - size_fail - nack_count, where size_fail is thenumber of FAIL voting primaries maintained in clusterUpdateState(). Without this,
a split vote among the replicas of several primaries that went down together
could never push nack_count high enough, and the replica would fall back to the
slow auth_timeout path. The quorum itself is still computed from the full size,
since a failover must be authorized by a majority of the whole configuration.
Wire compatibility is preserved by gating NACK sending behind a new capability
flag, CLUSTER_NODE_FAILOVER_AUTH_NACK_SUPPORTED, advertised in the PING/PONG
flags via
clusterUpdateMyselfFlags. Nodes that do not advertise this capabilitywill never see the new message type and fall back to the legacy auth_timeout path.
Granted (ACK) and rejected (NACK) votes are logged symmetrically per epoch, so
the vote tally of an election can be reconstructed from the logs.
Two DEBUG hooks are added for testing:
clusterHandleReplicaFailover.
replica to run in the given epoch (consumed once, then back to currentEpoch+1),
so several replicas can be made to contend in the same epoch and deterministically
reproduce a split vote.