mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Fixed incorrect parsing of hostname information from nodes.conf (#10435)
This commit is contained in:
parent
69017fa232
commit
e8771efda9
@ -219,6 +219,17 @@ int clusterLoadConfig(char *filename) {
|
||||
/* Format for the node address information:
|
||||
* ip:port[@cport][,hostname] */
|
||||
|
||||
/* Hostname is an optional argument that defines the endpoint
|
||||
* that can be reported to clients instead of IP. */
|
||||
char *hostname = strchr(argv[1], ',');
|
||||
if (hostname) {
|
||||
*hostname = '\0';
|
||||
hostname++;
|
||||
n->hostname = sdscpy(n->hostname, hostname);
|
||||
} else if (sdslen(n->hostname) != 0) {
|
||||
sdsclear(n->hostname);
|
||||
}
|
||||
|
||||
/* Address and port */
|
||||
if ((p = strrchr(argv[1],':')) == NULL) {
|
||||
sdsfreesplitres(argv,argc);
|
||||
@ -238,17 +249,6 @@ int clusterLoadConfig(char *filename) {
|
||||
* base port. */
|
||||
n->cport = busp ? atoi(busp) : n->port + CLUSTER_PORT_INCR;
|
||||
|
||||
/* Hostname is an optional argument that defines the endpoint
|
||||
* that can be reported to clients instead of IP. */
|
||||
char *hostname = strchr(p, ',');
|
||||
if (hostname) {
|
||||
*hostname = '\0';
|
||||
hostname++;
|
||||
n->hostname = sdscpy(n->hostname, hostname);
|
||||
} else if (sdslen(n->hostname) != 0) {
|
||||
sdsclear(n->hostname);
|
||||
}
|
||||
|
||||
/* The plaintext port for client in a TLS cluster (n->pport) is not
|
||||
* stored in nodes.conf. It is received later over the bus protocol. */
|
||||
|
||||
|
@ -197,6 +197,9 @@ test "Verify the nodes configured with prefer hostname only show hostname for ne
|
||||
test "Test restart will keep hostname information" {
|
||||
# Set a new hostname, reboot and make sure it sticks
|
||||
R 0 config set cluster-announce-hostname "restart-1.com"
|
||||
# Store the hostname in the config
|
||||
R 0 config rewrite
|
||||
kill_instance redis 0
|
||||
restart_instance redis 0
|
||||
set slot_result [R 0 CLUSTER SLOTS]
|
||||
assert_equal [lindex [get_slot_field $slot_result 0 2 3] 1] "restart-1.com"
|
||||
|
Loading…
Reference in New Issue
Block a user