mirror of
https://github.com/fluencelabs/redis
synced 2025-03-27 04:41:03 +00:00
During the initial handshake with the master a slave will report to have a very high disconnection time from its master (since technically it was disconnected since forever, so the current UNIX time in seconds is reported). However when the slave is connected again the Sentinel may re-scan the INFO output again only after 10 seconds, which is a long time. During this time Sentinels will consider this instance unable to failover, so a useless delay is introduced. Actaully this hardly happened in the practice because when a slave's master is down, the INFO period for slaves changes to 1 second. However when a manual failover is attempted immediately after adding slaves (like in the case of the Sentinel unit test), this problem may happen. This commit changes the INFO period to 1 second even in the case the slave's master is not down, but the slave reported to be disconnected from the master (by publishing, last time we checked, a master disconnection time field in INFO). This change is required as a result of an unrelated change in the replication code that adds a small delay in the master-slave first synchronization.
46 lines
1.4 KiB
Tcl
46 lines
1.4 KiB
Tcl
# Test manual failover
|
|
|
|
source "../tests/includes/init-tests.tcl"
|
|
|
|
test "Manual failover works" {
|
|
set old_port [RI $master_id tcp_port]
|
|
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
|
|
assert {[lindex $addr 1] == $old_port}
|
|
catch {S 0 SENTINEL FAILOVER mymaster} reply
|
|
assert {$reply eq "OK"}
|
|
foreach_sentinel_id id {
|
|
wait_for_condition 1000 50 {
|
|
[lindex [S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] 1] != $old_port
|
|
} else {
|
|
fail "At least one Sentinel did not received failover info"
|
|
}
|
|
}
|
|
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
|
|
set master_id [get_instance_id_by_port redis [lindex $addr 1]]
|
|
}
|
|
|
|
test "New master [join $addr {:}] role matches" {
|
|
assert {[RI $master_id role] eq {master}}
|
|
}
|
|
|
|
test "All the other slaves now point to the new master" {
|
|
foreach_redis_id id {
|
|
if {$id != $master_id && $id != 0} {
|
|
wait_for_condition 1000 50 {
|
|
[RI $id master_port] == [lindex $addr 1]
|
|
} else {
|
|
fail "Redis ID $id not configured to replicate with new master"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
test "The old master eventually gets reconfigured as a slave" {
|
|
wait_for_condition 1000 50 {
|
|
[RI 0 master_port] == [lindex $addr 1]
|
|
} else {
|
|
fail "Old master not reconfigured as slave of new master"
|
|
}
|
|
}
|
|
|