
The 'sentinel replicas <master>' command will ignore replicas with `replica-announced` set to no. The goal of disabling the config setting replica-announced is to allow ghost replicas. The replica is in the cluster, synchronize with its master, can be promoted to master and is not exposed to sentinel clients. This way, it is acting as a live backup or living ghost. In addition, to prevent the replica to be promoted as master, set replica-priority to 0.
74 lines
2.7 KiB
Tcl
74 lines
2.7 KiB
Tcl
source "../tests/includes/init-tests.tcl"
|
|
|
|
test "Check acceptable replica-priority values" {
|
|
foreach_redis_id id {
|
|
if {$id == $master_id} continue
|
|
|
|
# ensure replica-announced accepts yes and no
|
|
catch {R $id CONFIG SET replica-announced no} e
|
|
if {$e ne "OK"} {
|
|
fail "Unable to set replica-announced to no"
|
|
}
|
|
catch {R $id CONFIG SET replica-announced yes} e
|
|
if {$e ne "OK"} {
|
|
fail "Unable to set replica-announced to yes"
|
|
}
|
|
|
|
# ensure a random value throw error
|
|
catch {R $id CONFIG SET replica-announced 321} e
|
|
if {$e eq "OK"} {
|
|
fail "Able to set replica-announced with something else than yes or no (321) whereas it should not be possible"
|
|
}
|
|
catch {R $id CONFIG SET replica-announced a3b2c1} e
|
|
if {$e eq "OK"} {
|
|
fail "Able to set replica-announced with something else than yes or no (a3b2c1) whereas it should not be possible"
|
|
}
|
|
|
|
# test only the first redis replica, no need to double test
|
|
break
|
|
}
|
|
}
|
|
|
|
proc 10_test_number_of_replicas {n_replicas_expected} {
|
|
test "Check sentinel replies with $n_replicas_expected replicas" {
|
|
# ensure sentinels replies with the right number of replicas
|
|
foreach_sentinel_id id {
|
|
# retries 40 x 500ms = 20s as SENTINEL_INFO_PERIOD = 10s
|
|
set len [llength [S $id SENTINEL REPLICAS mymaster]]
|
|
wait_for_condition 40 500 {
|
|
[llength [S $id SENTINEL REPLICAS mymaster]] == $n_replicas_expected
|
|
} else {
|
|
fail "Sentinel replies with a wrong number of replicas with replica-announced=yes (expected $n_replicas_expected but got $len) on sentinel $id"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
proc 10_set_replica_announced {master_id announced n_replicas} {
|
|
test "Set replica-announced=$announced on $n_replicas replicas" {
|
|
set i 0
|
|
foreach_redis_id id {
|
|
if {$id == $master_id} continue
|
|
#puts "set replica-announce=$announced on redis #$id"
|
|
R $id CONFIG SET replica-announced "$announced"
|
|
incr i
|
|
if { $n_replicas!="all" && $i >= $n_replicas } { break }
|
|
}
|
|
}
|
|
}
|
|
|
|
# ensure all replicas are announced
|
|
10_set_replica_announced $master_id "yes" "all"
|
|
# ensure all replicas are announced by sentinels
|
|
10_test_number_of_replicas 4
|
|
|
|
# ensure the first 2 replicas are not announced
|
|
10_set_replica_announced $master_id "no" 2
|
|
# ensure sentinels are not announcing the first 2 replicas that have been set unannounced
|
|
10_test_number_of_replicas 2
|
|
|
|
# ensure all replicas are announced
|
|
10_set_replica_announced $master_id "yes" "all"
|
|
# ensure all replicas are not announced by sentinels
|
|
10_test_number_of_replicas 4
|