Skip to content

Do election in order based on failed primary rank to avoid voting conflicts - #1018

Merged
enjoy-binbin merged 9 commits into
valkey-io:unstablefrom
enjoy-binbin:primary_fail_rank
Jan 11, 2025
Merged

enjoy-binbin merged 9 commits into
valkey-io:unstablefrom
enjoy-binbin:primary_fail_rank

Conversation

@enjoy-binbin

@enjoy-binbin enjoy-binbin commented Sep 11, 2024 •

Copy link
Copy Markdown
Member

When multiple primary nodes fail simultaneously, the cluster can not recover
within the default effective time (data_age limit). The main reason is that
the vote is without ranking among multiple replica nodes, which case too many
epoch conflicts.

Therefore, we introduced into ranking based on the failed primary shard-id.
Introduced a new failed_primary_rank var, this var means the rank of this
myself instance in the context of all failed primary list. This var will be
used in failover and we will do the failover election packets in order based
on the rank, this can effectively avoid the voting conflicts.

If a single primary is down, the behavior is the same as before. If multiple
primaries are down, their replica election initiation time will be delayed
by 500ms according to the ranking.

…flicts

When multiple primary nodes fail simultaneously, the cluster can not recover
within the default effective time (data_age limit). The main reason is that
the vote is without ranking among multiple replica nodes, which case too many
epoch conflicts.

Therefore, we introduced into ranking based on the failed primary node name.
Introduced a new failed_primary_rank var, this var means the rank of this
myself instance in the context of all failed primary list. This var will be
used in failover and we will do the failover election packets in order based
on the rank, this can effectively avoid the voting conflicts.

Signed-off-by: Binbin <[email protected]>
Comment thread tests/unit/cluster/failover2.tcl Resolved
@enjoy-binbin enjoy-binbin added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Sep 11, 2024
Signed-off-by: Binbin <[email protected]>
@codecov

codecov Bot commented Sep 14, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.

Project coverage is 70.85%. Comparing base (b3b4bdc) to head (6abc3c1).

Files with missing lines Patch % Lines
src/cluster_legacy.c 96.15% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1018      +/-   ##
============================================
+ Coverage     70.83%   70.85%   +0.01%     
============================================
  Files           120      120              
  Lines         64911    64937      +26     
============================================
+ Hits          45982    46012      +30     
+ Misses        18929    18925       -4     
Files with missing lines Coverage Δ
src/cluster_legacy.c 86.77% <96.15%> (-0.02%) ⬇️

... and 12 files with indirect coverage changes

@PingXie PingXie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. I like this idea. Thanks @enjoy-binbin!

Comment thread src/cluster_legacy.c Resolved
Comment thread src/cluster_legacy.c Resolved
@madolson

madolson commented Jan 3, 2025

Copy link
Copy Markdown
Member

Seems like a good idea to me as well.

Comment thread tests/unit/cluster/failover2.tcl Resolved

@madolson madolson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directionally good with this change, the remaining tests still look good.

Signed-off-by: Binbin <[email protected]>
@enjoy-binbin enjoy-binbin added the release-notes This issue should get a line item in the release notes label Jan 11, 2025
@enjoy-binbin
enjoy-binbin merged commit 211b250 into valkey-io:unstable Jan 11, 2025
@enjoy-binbin
enjoy-binbin deleted the primary_fail_rank branch January 11, 2025 02:43
proost pushed a commit to proost/valkey that referenced this pull request Jan 17, 2025
…flicts (valkey-io#1018)

When multiple primary nodes fail simultaneously, the cluster can not recover
within the default effective time (data_age limit). The main reason is that
the vote is without ranking among multiple replica nodes, which case too many
epoch conflicts.

Therefore, we introduced into ranking based on the failed primary shard-id.
Introduced a new failed_primary_rank var, this var means the rank of this
myself instance in the context of all failed primary list. This var will be
used in failover and we will do the failover election packets in order based
on the rank, this can effectively avoid the voting conflicts.

If a single primary is down, the behavior is the same as before. If multiple
primaries are down, their replica election initiation time will be delayed
by 500ms according to the ranking.

Signed-off-by: Binbin <[email protected]>
Signed-off-by: proost <[email protected]>
kronwerk pushed a commit to kronwerk/valkey that referenced this pull request Jan 27, 2025
…flicts (valkey-io#1018)

When multiple primary nodes fail simultaneously, the cluster can not recover
within the default effective time (data_age limit). The main reason is that
the vote is without ranking among multiple replica nodes, which case too many
epoch conflicts.

Therefore, we introduced into ranking based on the failed primary shard-id.
Introduced a new failed_primary_rank var, this var means the rank of this
myself instance in the context of all failed primary list. This var will be
used in failover and we will do the failover election packets in order based
on the rank, this can effectively avoid the voting conflicts.

If a single primary is down, the behavior is the same as before. If multiple
primaries are down, their replica election initiation time will be delayed
by 500ms according to the ranking.

Signed-off-by: Binbin <[email protected]>
enjoy-binbin added a commit to enjoy-binbin/valkey that referenced this pull request Jun 17, 2025
This rank was added in valkey-io#1018, we should reset it to zero when doing
the manual failover, just like we reset failover auth rank.

It affects subsequent log printing. When there is a manual failover
and there are multiple primaries failure, `Start of election` will
print a confusing log.

Signed-off-by: Binbin <[email protected]>
enjoy-binbin added a commit that referenced this pull request Jun 18, 2025
This rank was added in #1018, we should reset it to zero when doing
the manual failover, just like we reset failover auth rank.

It affects subsequent log printing. When there is a manual failover
and there are multiple primaries failure, `Start of election` will
print a confusing log.

Signed-off-by: Binbin <[email protected]>
ranshid pushed a commit to ranshid/valkey that referenced this pull request Jun 18, 2025
…ey-io#2226)

This rank was added in valkey-io#1018, we should reset it to zero when doing
the manual failover, just like we reset failover auth rank.

It affects subsequent log printing. When there is a manual failover
and there are multiple primaries failure, `Start of election` will
print a confusing log.

Signed-off-by: Binbin <[email protected]>
ranshid pushed a commit to ranshid/valkey that referenced this pull request Sep 30, 2025
…ey-io#2226)

This rank was added in valkey-io#1018, we should reset it to zero when doing
the manual failover, just like we reset failover auth rank.

It affects subsequent log printing. When there is a manual failover
and there are multiple primaries failure, `Start of election` will
print a confusing log.

Signed-off-by: Binbin <[email protected]>
zuiderkwast pushed a commit that referenced this pull request Oct 1, 2025
This rank was added in #1018, we should reset it to zero when doing
the manual failover, just like we reset failover auth rank.

It affects subsequent log printing. When there is a manual failover
and there are multiple primaries failure, `Start of election` will
print a confusing log.

Signed-off-by: Binbin <[email protected]>
sarthakaggarwal97 pushed a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 27, 2026
…flicts (valkey-io#1018)

When multiple primary nodes fail simultaneously, the cluster can not recover
within the default effective time (data_age limit). The main reason is that
the vote is without ranking among multiple replica nodes, which case too many
epoch conflicts.

Therefore, we introduced into ranking based on the failed primary shard-id.
Introduced a new failed_primary_rank var, this var means the rank of this
myself instance in the context of all failed primary list. This var will be
used in failover and we will do the failover election packets in order based
on the rank, this can effectively avoid the voting conflicts.

If a single primary is down, the behavior is the same as before. If multiple
primaries are down, their replica election initiation time will be delayed
by 500ms according to the ranking.

Signed-off-by: Binbin <[email protected]>
(cherry picked from commit 211b250)
sarthakaggarwal97 pushed a commit to sarthakaggarwal97/valkey that referenced this pull request Apr 27, 2026
…flicts (valkey-io#1018)

When multiple primary nodes fail simultaneously, the cluster can not recover
within the default effective time (data_age limit). The main reason is that
the vote is without ranking among multiple replica nodes, which case too many
epoch conflicts.

Therefore, we introduced into ranking based on the failed primary shard-id.
Introduced a new failed_primary_rank var, this var means the rank of this
myself instance in the context of all failed primary list. This var will be
used in failover and we will do the failover election packets in order based
on the rank, this can effectively avoid the voting conflicts.

If a single primary is down, the behavior is the same as before. If multiple
primaries are down, their replica election initiation time will be delayed
by 500ms according to the ranking.

Signed-off-by: Binbin <[email protected]>
(cherry picked from commit 211b250)
(cherry picked from commit bbbbead)
valkeyrie-ops Bot added a commit that referenced this pull request Dec 2, 2026
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>
valkeyrie-ops Bot added a commit that referenced this pull request Dec 3, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cluster release-notes This issue should get a line item in the release notes run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants