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 merge commits #83

Open
wants to merge 81 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
c48f49e
Add hostname variable
hwware Sep 27, 2021
6ac7e65
Update cluster.c
hwware Sep 27, 2021
bd01e10
Update cluster.c
hwware Sep 27, 2021
1ade627
Update cluster.c
hwware Sep 27, 2021
6946471
Update cluster.c
hwware Sep 28, 2021
3a29126
Update cluster.c
hwware Sep 28, 2021
bc6f455
Update cluster.c
hwware Sep 28, 2021
493d38c
Update cluster.c
hwware Sep 28, 2021
8e3b3c0
Check node name
hwware Sep 28, 2021
28ff415
Update cluster.c
hwware Sep 28, 2021
526196d
Update cluster.c
hwware Sep 28, 2021
67a5fea
Add help for nodename
hwware Sep 28, 2021
ae11782
Update cluster.c
hwware Sep 28, 2021
d9ef49d
Added support for hname in CLUSTER NODES
hwware Oct 5, 2021
67357a6
Add gossip and custom name support
hwware Nov 1, 2021
b1161cb
update codes to fix error in rebase
hwware Jan 12, 2022
47e07ad
Added nodename support to extension (#61)
hwware Jan 19, 2022
d40ea57
Update src/cluster.c
hwware Feb 24, 2022
3b61ebd
Update cluster.c
hwware Feb 24, 2022
799fef2
Add hostname variable
hwware Sep 27, 2021
1bb500f
Update cluster.c
hwware Sep 27, 2021
9fedeb5
Update cluster.c
hwware Sep 27, 2021
45fd965
Update cluster.c
hwware Sep 27, 2021
80ecf81
Update cluster.c
hwware Sep 28, 2021
91c27af
Update cluster.c
hwware Sep 28, 2021
f6c8be3
Update cluster.c
hwware Sep 28, 2021
6613b72
Update cluster.c
hwware Sep 28, 2021
fc90516
Check node name
hwware Sep 28, 2021
5b78f87
Update cluster.c
hwware Sep 28, 2021
9c96f69
Update cluster.c
hwware Sep 28, 2021
6568eaa
Add help for nodename
hwware Sep 28, 2021
3f99401
Update cluster.c
hwware Sep 28, 2021
a2d06c4
Added support for hname in CLUSTER NODES
hwware Oct 5, 2021
f6af3f6
Add gossip and custom name support
hwware Nov 1, 2021
1f7a365
update codes to fix error in rebase
hwware Jan 12, 2022
913c6d5
Added nodename support to extension (#61)
hwware Jan 19, 2022
bfb98c2
Update src/cluster.c
hwware Feb 24, 2022
a2d0471
Update cluster.c
hwware Feb 24, 2022
149671b
Rebase and fix conflicts
hwware Feb 24, 2022
b7837ae
Cluster nodename feature add sds option (#67)
hwware Feb 24, 2022
3c6c05e
Cluster nodename feature rebase (#68)
hwware Feb 25, 2022
a1535a9
Add hostname variable
hwware Sep 27, 2021
3105305
Update cluster.c
hwware Sep 27, 2021
7dca410
Update cluster.c
hwware Sep 27, 2021
6728cd3
Update cluster.c
hwware Sep 27, 2021
68c4e10
Update cluster.c
hwware Sep 28, 2021
f25755c
Update cluster.c
hwware Sep 28, 2021
4643299
Update cluster.c
hwware Sep 28, 2021
15d4f97
Update cluster.c
hwware Sep 28, 2021
be36fad
Check node name
hwware Sep 28, 2021
096e388
Update cluster.c
hwware Sep 28, 2021
5cb5388
Update cluster.c
hwware Sep 28, 2021
f6c1c45
Add help for nodename
hwware Sep 28, 2021
b62a01a
Update cluster.c
hwware Sep 28, 2021
5f08f5c
Added support for hname in CLUSTER NODES
hwware Oct 5, 2021
9a0ee62
Add gossip and custom name support
hwware Nov 1, 2021
413dca0
update codes to fix error in rebase
hwware Jan 12, 2022
5bd7e3e
Added nodename support to extension (#61)
hwware Jan 19, 2022
b46cacd
Update src/cluster.c
hwware Feb 24, 2022
e69266d
Update cluster.c
hwware Feb 24, 2022
f8b1acf
Add hostname variable
hwware Sep 27, 2021
6914839
Update cluster.c
hwware Sep 27, 2021
21a21c1
Update cluster.c
hwware Sep 27, 2021
4d2f3bc
Update cluster.c
hwware Sep 27, 2021
23c8f03
Update cluster.c
hwware Sep 28, 2021
34879c3
Update cluster.c
hwware Sep 28, 2021
620c7c4
Check node name
hwware Sep 28, 2021
579a90a
Update cluster.c
hwware Sep 28, 2021
9206bbb
Update cluster.c
hwware Sep 28, 2021
1284aeb
Add help for nodename
hwware Sep 28, 2021
34b7ced
Update cluster.c
hwware Sep 28, 2021
9d9b96d
Added support for hname in CLUSTER NODES
hwware Oct 5, 2021
9a67ded
Add gossip and custom name support
hwware Nov 1, 2021
b96090f
update codes to fix error in rebase
hwware Jan 12, 2022
b3a8b70
Added nodename support to extension (#61)
hwware Jan 19, 2022
85abd35
Update cluster.c
hwware Feb 24, 2022
943aaa2
Cluster nodename feature add sds option (#67)
hwware Feb 24, 2022
799846a
Cluster nodename feature rebase (#68)
hwware Feb 25, 2022
25bfa5d
Fix conflicts
hwware Mar 24, 2022
63940d0
Rebase
hwware Mar 24, 2022
239a78f
Add tests and change lof format
hwware Apr 13, 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 @@ -1684,6 +1684,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
208 changes: 144 additions & 64 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 @@ -136,6 +136,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 @@ -251,6 +252,7 @@ typedef struct {
* consistent manner. */
typedef enum {
CLUSTERMSG_EXT_TYPE_HOSTNAME,
CLUSTERMSG_EXT_TYPE_NODENAME,
} clusterMsgPingtypes;

/* Helper function for making sure extensions are eight byte aligned. */
Expand All @@ -260,12 +262,17 @@ typedef struct {
char hostname[1]; /* The announced hostname, ends with \0. */
} clusterMsgPingExtHostname;

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;
clusterMsgPingExtNodename nodename;
} ext[]; /* Actual extension information, formatted so that the data is 8
* byte aligned, regardless of its content. */
} clusterMsgPingExt;
Expand Down Expand Up @@ -396,5 +403,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 @@ -2409,6 +2409,12 @@ int updateClusterHostname(const char **err) {
return 1;
}

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

#ifdef USE_OPENSSL
static int applyTlsCfg(const char **err) {
UNUSED(err);
Expand Down Expand Up @@ -2828,6 +2834,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 @@ -1848,7 +1848,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
37 changes: 37 additions & 0 deletions tests/cluster/tests/27-endpoints.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ 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 < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
R $j config set cluster-announce-hostname "host-updated-$j.com"
Expand All @@ -55,6 +70,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 < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
R $j config set cluster-announce-hostname ""
Expand Down Expand Up @@ -216,4 +246,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
}