Skip to content

Commit

Permalink
Fix the election was reset wrongly before failover epoch was obtained
Browse files Browse the repository at this point in the history
After #1009, we will reset the election when we received
a claim with an equal or higher epoch since a node can win
an election in the past.

But we need to consider the time before the node actually
obtains the failover_auth_epoch. The failover_auth_epoch
default is 0, so before the node actually get the failover
epoch, we might wrongly reset the election.

This is probably harmless, but will produce misleading log
output and may delay election by a cron cycle or beforesleep.
Now we will only reset the election when a node is actually
obtains the failover epoch.

Signed-off-by: Binbin <binloveplay1314@qq.com>
  • Loading branch information
enjoy-binbin committed Nov 22, 2024
1 parent 50aae13 commit c2d5d61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,8 @@ int clusterProcessPacket(clusterLink *link) {
sender->configEpoch = sender_claimed_config_epoch;
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG | CLUSTER_TODO_FSYNC_CONFIG);

if (server.cluster->failover_auth_time && sender->configEpoch >= server.cluster->failover_auth_epoch) {
if (server.cluster->failover_auth_time && server.cluster->failover_auth_sent &&
sender->configEpoch >= server.cluster->failover_auth_epoch) {
/* Another node has claimed an epoch greater than or equal to ours.
* If we have an ongoing election, reset it because we cannot win
* with an epoch smaller than or equal to the incoming claim. This
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/cluster/failover2.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ start_cluster 7 3 {tags {external:skip cluster} overrides {cluster-ping-interval
fail "No failover detected"
}

# Make sure there is no false epoch 0.
verify_no_log_message -7 "*Failover election in progress for epoch 0*" 0
verify_no_log_message -8 "*Failover election in progress for epoch 0*" 0
verify_no_log_message -9 "*Failover election in progress for epoch 0*" 0

# Make sure there is no failover timeout.
verify_no_log_message -7 "*Failover attempt expired*" 0
verify_no_log_message -8 "*Failover attempt expired*" 0
Expand Down

0 comments on commit c2d5d61

Please sign in to comment.