2014-02-20 16:57:51 +01:00
|
|
|
# Initialization tests -- most units will start including this.
|
|
|
|
|
Add hostname support in Sentinel. (#8282)
This is both a bugfix and an enhancement.
Internally, Sentinel relies entirely on IP addresses to identify
instances. When configured with a new master, it also requires users to
specify and IP and not hostname.
However, replicas may use the replica-announce-ip configuration to
announce a hostname. When that happens, Sentinel fails to match the
announced hostname with the expected IP and considers that a different
instance, triggering reconfiguration, etc.
Another use case is where TLS is used and clients are expected to match
the hostname to connect to with the certificate's SAN attribute. To
properly implement this configuration, it is necessary for Sentinel to
redirect clients to a hostname rather than an IP address.
The new 'resolve-hostnames' configuration parameter determines if
Sentinel is willing to accept hostnames. It is set by default to no,
which maintains backwards compatibility and avoids unexpected DNS
resolution delays on systems with DNS configuration issues.
Internally, Sentinel continues to identify instances by their resolved
IP address and will also report the IP by default. The new
'announce-hostnames' parameter determines if Sentinel should prefer to
announce a hostname, when available, rather than an IP address. This
applies to addresses returned to clients, as well as their
representation in the configuration file, REPLICAOF configuration
commands, etc.
This commit also introduces SENTINEL CONFIG GET and SENTINEL CONFIG SET
which can be used to introspect or configure global Sentinel
configuration that was previously was only possible by directly
accessing the configuration file and possibly restarting the instance.
Co-authored-by: myl1024 <myl92916@qq.com>
Co-authored-by: sundb <sundbcn@gmail.com>
2021-01-28 12:09:11 +02:00
|
|
|
proc restart_killed_instances {} {
|
2014-02-25 08:48:46 +01:00
|
|
|
foreach type {redis sentinel} {
|
|
|
|
foreach_${type}_id id {
|
|
|
|
if {[get_instance_attrib $type $id pid] == -1} {
|
|
|
|
puts -nonewline "$type/$id "
|
|
|
|
flush stdout
|
|
|
|
restart_instance $type $id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add hostname support in Sentinel. (#8282)
This is both a bugfix and an enhancement.
Internally, Sentinel relies entirely on IP addresses to identify
instances. When configured with a new master, it also requires users to
specify and IP and not hostname.
However, replicas may use the replica-announce-ip configuration to
announce a hostname. When that happens, Sentinel fails to match the
announced hostname with the expected IP and considers that a different
instance, triggering reconfiguration, etc.
Another use case is where TLS is used and clients are expected to match
the hostname to connect to with the certificate's SAN attribute. To
properly implement this configuration, it is necessary for Sentinel to
redirect clients to a hostname rather than an IP address.
The new 'resolve-hostnames' configuration parameter determines if
Sentinel is willing to accept hostnames. It is set by default to no,
which maintains backwards compatibility and avoids unexpected DNS
resolution delays on systems with DNS configuration issues.
Internally, Sentinel continues to identify instances by their resolved
IP address and will also report the IP by default. The new
'announce-hostnames' parameter determines if Sentinel should prefer to
announce a hostname, when available, rather than an IP address. This
applies to addresses returned to clients, as well as their
representation in the configuration file, REPLICAOF configuration
commands, etc.
This commit also introduces SENTINEL CONFIG GET and SENTINEL CONFIG SET
which can be used to introspect or configure global Sentinel
configuration that was previously was only possible by directly
accessing the configuration file and possibly restarting the instance.
Co-authored-by: myl1024 <myl92916@qq.com>
Co-authored-by: sundb <sundbcn@gmail.com>
2021-01-28 12:09:11 +02:00
|
|
|
test "(init) Restart killed instances" {
|
|
|
|
restart_killed_instances
|
|
|
|
}
|
|
|
|
|
2014-06-23 14:04:09 +02:00
|
|
|
test "(init) Remove old master entry from sentinels" {
|
|
|
|
foreach_sentinel_id id {
|
|
|
|
catch {S $id SENTINEL REMOVE mymaster}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-13 18:39:59 +03:00
|
|
|
set redis_slaves [expr $::instances_count - 1]
|
2014-02-24 17:21:50 +01:00
|
|
|
test "(init) Create a master-slaves cluster of [expr $redis_slaves+1] instances" {
|
2014-02-20 16:57:51 +01:00
|
|
|
create_redis_master_slave_cluster [expr {$redis_slaves+1}]
|
|
|
|
}
|
|
|
|
set master_id 0
|
|
|
|
|
2014-02-24 17:21:50 +01:00
|
|
|
test "(init) Sentinels can start monitoring a master" {
|
2014-02-20 16:57:51 +01:00
|
|
|
set sentinels [llength $::sentinel_instances]
|
|
|
|
set quorum [expr {$sentinels/2+1}]
|
|
|
|
foreach_sentinel_id id {
|
|
|
|
S $id SENTINEL MONITOR mymaster \
|
|
|
|
[get_instance_attrib redis $master_id host] \
|
|
|
|
[get_instance_attrib redis $master_id port] $quorum
|
|
|
|
}
|
|
|
|
foreach_sentinel_id id {
|
|
|
|
assert {[S $id sentinel master mymaster] ne {}}
|
2014-02-22 17:26:30 +01:00
|
|
|
S $id SENTINEL SET mymaster down-after-milliseconds 2000
|
2014-03-04 17:10:29 +01:00
|
|
|
S $id SENTINEL SET mymaster failover-timeout 20000
|
|
|
|
S $id SENTINEL SET mymaster parallel-syncs 10
|
2021-02-11 15:25:01 +02:00
|
|
|
if {$::leaked_fds_file != "" && [exec uname] == "Linux"} {
|
2021-02-08 17:02:46 +02:00
|
|
|
S $id SENTINEL SET mymaster notification-script ../../tests/helpers/check_leaked_fds.tcl
|
|
|
|
S $id SENTINEL SET mymaster client-reconfig-script ../../tests/helpers/check_leaked_fds.tcl
|
|
|
|
}
|
2014-02-20 16:57:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-24 17:21:50 +01:00
|
|
|
test "(init) Sentinels can talk with the master" {
|
2014-02-22 17:26:30 +01:00
|
|
|
foreach_sentinel_id id {
|
2014-06-19 15:58:45 +02:00
|
|
|
wait_for_condition 1000 50 {
|
2014-02-22 17:26:30 +01:00
|
|
|
[catch {S $id SENTINEL GET-MASTER-ADDR-BY-NAME mymaster}] == 0
|
|
|
|
} else {
|
|
|
|
fail "Sentinel $id can't talk with the master."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-24 17:21:50 +01:00
|
|
|
|
|
|
|
test "(init) Sentinels are able to auto-discover other sentinels" {
|
|
|
|
set sentinels [llength $::sentinel_instances]
|
|
|
|
foreach_sentinel_id id {
|
2014-06-19 15:58:45 +02:00
|
|
|
wait_for_condition 1000 50 {
|
2014-02-24 17:21:50 +01:00
|
|
|
[dict get [S $id SENTINEL MASTER mymaster] num-other-sentinels] == ($sentinels-1)
|
|
|
|
} else {
|
|
|
|
fail "At least some sentinel can't detect some other sentinel"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test "(init) Sentinels are able to auto-discover slaves" {
|
|
|
|
foreach_sentinel_id id {
|
2014-06-19 15:58:45 +02:00
|
|
|
wait_for_condition 1000 50 {
|
2014-02-24 17:21:50 +01:00
|
|
|
[dict get [S $id SENTINEL MASTER mymaster] num-slaves] == $redis_slaves
|
|
|
|
} else {
|
|
|
|
fail "At least some sentinel can't detect some slave"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|