Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluster nodename feature 20221124 clone #88

Open
wants to merge 74 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
eaba03c
Add hostname variable
hwware Sep 27, 2021
e56dd20
Update cluster.c
hwware Sep 27, 2021
cc966d2
Update cluster.c
hwware Sep 27, 2021
03305ef
Update cluster.c
hwware Sep 27, 2021
1a05cc9
Update cluster.c
hwware Sep 28, 2021
f9fe792
Update cluster.c
hwware Sep 28, 2021
6909563
Update cluster.c
hwware Sep 28, 2021
ae5f628
Update cluster.c
hwware Sep 28, 2021
f7d6091
Check node name
hwware Sep 28, 2021
6210da7
Update cluster.c
hwware Sep 28, 2021
5e298fa
Update cluster.c
hwware Sep 28, 2021
8755fa8
Add help for nodename
hwware Sep 28, 2021
1b98683
Update cluster.c
hwware Sep 28, 2021
4778b52
Added support for hname in CLUSTER NODES
hwware Oct 5, 2021
7e79752
Add gossip and custom name support
hwware Nov 1, 2021
750365e
update codes to fix error in rebase
hwware Jan 12, 2022
da6c6bd
Added nodename support to extension (#61)
hwware Jan 19, 2022
f113b4b
Update src/cluster.c
hwware Feb 24, 2022
9a42c24
Update cluster.c
hwware Feb 24, 2022
c95884a
Add hostname variable
hwware Sep 27, 2021
02da336
Update cluster.c
hwware Sep 27, 2021
acba403
Update cluster.c
hwware Sep 27, 2021
306f548
Update cluster.c
hwware Sep 27, 2021
fb7bc2c
Update cluster.c
hwware Sep 28, 2021
fcf2ac0
Update cluster.c
hwware Sep 28, 2021
4414c6b
Check node name
hwware Sep 28, 2021
309b0b8
Update cluster.c
hwware Sep 28, 2021
21baa54
Update cluster.c
hwware Sep 28, 2021
ea70482
Add help for nodename
hwware Sep 28, 2021
1d65f2e
Update cluster.c
hwware Sep 28, 2021
7e0396a
Added support for hname in CLUSTER NODES
hwware Oct 5, 2021
54979c9
Add gossip and custom name support
hwware Nov 1, 2021
ca8d2d5
update codes to fix error in rebase
hwware Jan 12, 2022
b706820
Added nodename support to extension (#61)
hwware Jan 19, 2022
3ee0fd4
Update cluster.c
hwware Feb 24, 2022
f3d7aee
Cluster nodename feature add sds option (#67)
hwware Feb 24, 2022
ec6a43a
Cluster nodename feature rebase (#68)
hwware Feb 25, 2022
84b590c
Add hostname variable
hwware Sep 27, 2021
62e9999
Update cluster.c
hwware Sep 27, 2021
40b3748
Update cluster.c
hwware Sep 27, 2021
404021e
Update cluster.c
hwware Sep 27, 2021
2c89c98
Update cluster.c
hwware Sep 28, 2021
c129c8c
Update cluster.c
hwware Sep 28, 2021
b8f44eb
Check node name
hwware Sep 28, 2021
156de8c
Update cluster.c
hwware Sep 28, 2021
09153db
Update cluster.c
hwware Sep 28, 2021
63e3148
Add help for nodename
hwware Sep 28, 2021
7a0f2f0
Update cluster.c
hwware Sep 28, 2021
ca18558
Added support for hname in CLUSTER NODES
hwware Oct 5, 2021
3fa2f2a
Add gossip and custom name support
hwware Nov 1, 2021
96f691d
update codes to fix error in rebase
hwware Jan 12, 2022
2fb3669
Added nodename support to extension (#61)
hwware Jan 19, 2022
c314554
Update cluster.c
hwware Feb 24, 2022
34abbd4
Add hostname variable
hwware Sep 27, 2021
5eef972
Update cluster.c
hwware Sep 27, 2021
28c25a1
Update cluster.c
hwware Sep 27, 2021
5e7ab2e
Update cluster.c
hwware Sep 27, 2021
6ad79a2
Update cluster.c
hwware Sep 28, 2021
5a7c93a
Update cluster.c
hwware Sep 28, 2021
c8e32d1
Check node name
hwware Sep 28, 2021
40a3213
Update cluster.c
hwware Sep 28, 2021
e971b0a
Update cluster.c
hwware Sep 28, 2021
8664e8d
Add help for nodename
hwware Sep 28, 2021
d3b59f3
Update cluster.c
hwware Sep 28, 2021
928287a
Added support for hname in CLUSTER NODES
hwware Oct 5, 2021
ea16074
Add gossip and custom name support
hwware Nov 1, 2021
705e2bf
update codes to fix error in rebase
hwware Jan 12, 2022
10aa024
Added nodename support to extension (#61)
hwware Jan 19, 2022
6be4507
Update cluster.c
hwware Feb 24, 2022
0b755be
Cluster nodename feature add sds option (#67)
hwware Feb 24, 2022
29206e0
Cluster nodename feature rebase (#68)
hwware Feb 25, 2022
6c3bc1f
Add tests and change lof format
hwware Apr 13, 2022
6269b54
rebase on 09-14
hwware Sep 14, 2022
a696086
update some errors
hwware Sep 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions redis.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,10 @@ aof-timestamp-enabled no
#
# cluster-announce-hostname ""

# Clusters can configure their announced nodename using this config. The nodename can be a human-readable name
# which will be exposed in places like info and logging for debugging purposes.
# cluster-announce-nodename ""

# Clusters can advertise how clients should connect to them using either their IP address,
# a user defined hostname, or by declaring they have no endpoint. Which endpoint is
# shown as the preferred endpoint is set by using the cluster-preferred-endpoint-type
Expand Down
183 changes: 133 additions & 50 deletions src/cluster.c

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ typedef struct clusterNode {
long long repl_offset; /* Last known repl offset for this node. */
char ip[NET_IP_STR_LEN]; /* Latest known IP address of this node */
sds hostname; /* The known hostname for this node */
sds nodename; /* The known human readable nodename for this node */
int port; /* Latest known clients port (TLS or plain). */
int pport; /* Latest known clients plaintext port. Only used
if the main clients port is for TLS. */
Expand Down Expand Up @@ -254,6 +255,7 @@ typedef struct {
typedef enum {
CLUSTERMSG_EXT_TYPE_HOSTNAME,
CLUSTERMSG_EXT_TYPE_FORGOTTEN_NODE,
CLUSTERMSG_EXT_TYPE_NODENAME,
} clusterMsgPingtypes;

/* Helper function for making sure extensions are eight byte aligned. */
Expand All @@ -270,13 +272,18 @@ typedef struct {

static_assert(sizeof(clusterMsgPingExtForgottenNode) % 8 == 0, "");

typedef struct {
char nodename[1]; /* The announced nodename, ends with \0. */
} clusterMsgPingExtNodename;

typedef struct {
uint32_t length; /* Total length of this extension message (including this header) */
uint16_t type; /* Type of this extension message (see clusterMsgPingExtTypes) */
uint16_t unused; /* 16 bits of padding to make this structure 8 byte aligned. */
union {
clusterMsgPingExtHostname hostname;
clusterMsgPingExtForgottenNode forgotten_node;
clusterMsgPingExtNodename nodename;
} ext[]; /* Actual extension information, formatted so that the data is 8
* byte aligned, regardless of its content. */
} clusterMsgPingExt;
Expand Down Expand Up @@ -407,5 +414,6 @@ void clusterUpdateMyselfIp(void);
void slotToChannelAdd(sds channel);
void slotToChannelDel(sds channel);
void clusterUpdateMyselfHostname(void);
void clusterUpdateMyselfNodename(void);

#endif /* __CLUSTER_H */
7 changes: 7 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2603,6 +2603,12 @@ int updateClusterHostname(const char **err) {
return 1;
}

int updateClusterNodename(const char **err) {
UNUSED(err);
clusterUpdateMyselfNodename();
return 1;
}

static int applyTlsCfg(const char **err) {
UNUSED(err);

Expand Down Expand Up @@ -3028,6 +3034,7 @@ standardConfig static_configs[] = {
createStringConfig("cluster-announce-ip", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, server.cluster_announce_ip, NULL, NULL, updateClusterIp),
createStringConfig("cluster-config-file", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.cluster_configfile, "nodes.conf", NULL, NULL),
createStringConfig("cluster-announce-hostname", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, server.cluster_announce_hostname, NULL, isValidAnnouncedHostname, updateClusterHostname),
createStringConfig("cluster-announce-nodename", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, server.cluster_announce_nodename, NULL, isValidAnnouncedHostname, updateClusterNodename),
createStringConfig("syslog-ident", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.syslog_ident, "redis", NULL, NULL),
createStringConfig("dbfilename", NULL, MODIFIABLE_CONFIG | PROTECTED_CONFIG, ALLOW_EMPTY_STRING, server.rdb_filename, "dump.rdb", isValidDBfilename, NULL),
createStringConfig("appendfilename", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.aof_filename, "appendonly.aof", isValidAOFfilename, NULL),
Expand Down
3 changes: 2 additions & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,8 @@ struct redisServer {
int cluster_slave_no_failover; /* Prevent slave from starting a failover
if the master is in failure state. */
char *cluster_announce_ip; /* IP address to announce on cluster bus. */
char *cluster_announce_hostname; /* hostname to announce on cluster bus. */
char *cluster_announce_hostname; /* IP address to announce on cluster bus. */
char *cluster_announce_nodename; /* Human readable name assigned to a node. */
int cluster_preferred_endpoint_type; /* Use the announced hostname when available. */
int cluster_announce_port; /* base port to announce on cluster bus. */
int cluster_announce_tls_port; /* TLS port to announce on cluster bus. */
Expand Down
11 changes: 11 additions & 0 deletions tests/cluster/cluster.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ proc are_hostnames_propagated {match_string} {
return 1
}

# Check if cluster's view of nodename is consistent
proc are_nodenames_propagated {match_string} {
for {set j 0} {$j < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
set cfg [R $j cluster nodes]
if {! [string match $match_string $cfg]} {
return 0
}
return 1
}
}

# Returns a parsed CLUSTER LINKS output of the instance identified
# by the given `id` as a list of dictionaries, with each dictionary
# corresponds to a link.
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/cluster/hostnames.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ test "Set cluster hostnames and verify they are propagated" {
wait_for_cluster_propagation
}

test "Set cluster nodenames and verify they are propagated" {

#for {set j 0} {$j < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
# R $j config set cluster-announce-nodename "node-$j.com"
#}

#wait_for_condition 50 100 {
# [are_nodenames_propagated "*node-*.com*"] eq 1
#} else {
# fail "cluster nodenames were not propagated"
#}

# Now that everything is propagated, assert everyone agrees
#wait_for_cluster_propagation
}

test "Update hostnames and make sure they are all eventually propagated" {
for {set j 0} {$j < [llength $::servers]} {incr j} {
R $j config set cluster-announce-hostname "host-updated-$j.com"
Expand All @@ -74,6 +90,21 @@ test "Update hostnames and make sure they are all eventually propagated" {
wait_for_cluster_propagation
}

test "Update nodenames and make sure they are all eventually propagated" {
#for {set j 0} {$j < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
# R $j config set cluster-announce-nodename "node-updated-$j.com"
#}

#wait_for_condition 50 100 {
# [are_nodenames_propagated "*node-updated-*.com*"] eq 1
#} else {
# fail "cluster nodenames were not propagated"
#}

# Now that everything is propagated, assert everyone agrees
#wait_for_cluster_propagation
}

test "Remove hostnames and make sure they are all eventually propagated" {
for {set j 0} {$j < [llength $::servers]} {incr j} {
R $j config set cluster-announce-hostname ""
Expand Down Expand Up @@ -241,4 +272,11 @@ test "Test hostname validation" {
# Note this isn't a valid hostname, but it passes our internal validation
R 0 config set cluster-announce-hostname "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-."
}

test "Test nodename validation" {
#catch {R 0 config set cluster-announce-nodename [string repeat x 256]} err
#assert_match "*must be less than 256 characters*" $err
#catch {R 0 config set cluster-announce-nodename "?.com"} err
#assert_match "*may only contain alphanumeric characters, hyphens or dots*" $err
}
}