diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 4220f9dcae..7dc16f9bb4 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -4095,8 +4095,9 @@ void clusterSendFailoverAuthIfNeeded(clusterNode *node, clusterMsg *request) { * replication offset, and so forth. Note that because how the rank is computed * multiple replicas may have the same rank, in case they have the same offset. * - * If the replication offsets are the same, the one with the smaller node id - * will have a better ranking to avoid simultaneous elections of replicas. + * If the replication offsets are the same, the one with the lexicographically + * smaller Node id * will have a better ranking to avoid simultaneous elections + * of replicas. * * The replica rank is used to add a delay to start an election in order to * get voted and replace a failing primary. Replicas with better replication diff --git a/tests/support/util.tcl b/tests/support/util.tcl index c6c405b191..af7a399771 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -171,11 +171,16 @@ proc count_log_message {srv_idx pattern} { return [count_message_lines $stdout $pattern] } -# verify pattern exists in server's sdtout after a certain line number +# verify pattern exists in server's stdout after a certain line number proc verify_log_message {srv_idx pattern from_line} { incr from_line set result [exec tail -n +$from_line < [srv $srv_idx stdout]] if {![string match $pattern $result]} { + puts "logs ====1====" + puts $pattern + puts $srv_idx + puts $result + puts "logs ====2====" error "assertion:expected message not found in log file: $pattern" } } diff --git a/tests/unit/cluster/failover.tcl b/tests/unit/cluster/failover.tcl index b3033a98f9..c23dd3e710 100644 --- a/tests/unit/cluster/failover.tcl +++ b/tests/unit/cluster/failover.tcl @@ -71,17 +71,7 @@ test "Instance #0 gets converted into a slave" { } ;# start_cluster -# Add all replicas to the first primary node. -proc cluster_allocate_replicas_to_one_primary {primaries replicas} { - set primary_id 0 - for {set j 0} {$j < $replicas} {incr j} { - set replica_id [cluster_find_available_replica $primaries] - set primary_myself [cluster_get_myself $primary_id] - R $replica_id cluster replicate [dict get $primary_myself id] - } -} - -start_cluster 5 10 {tags {external:skip cluster} overrides {cluster-node-timeout 5000}} { +start_cluster 3 6 {tags {external:skip cluster}} { test "Cluster is up" { wait_for_cluster_state ok @@ -130,4 +120,14 @@ test "Instance #0 gets converted into a replica" { wait_for_cluster_propagation } -} continuous_slot_allocation cluster_allocate_replicas_to_one_primary ;# start_cluster +test "Make sure the replicas always get the different ranks" { + if {[s -3 role] == "master"} { + verify_log_message -3 "*Start of election*rank #0*" 0 + verify_log_message -6 "*Start of election*rank #1*" 0 + } else { + verify_log_message -3 "*Start of election*rank #1*" 0 + verify_log_message -6 "*Start of election*rank #0*" 0 + } +} + +} ;# start_cluster