summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWen Hui <wen.hui.ware@gmail.com>2021-10-19 01:28:27 -0400
committerGitHub <noreply@github.com>2021-10-18 22:28:27 -0700
commit1c2b5f53188882ed78b83a5e4ec1697583530f0b (patch)
tree4ce39e107b5a767eba6c7ad079bc01848154173d
parentb7f2a1a217b5c5b7b0320bfe0511dfdf2e0eb174 (diff)
downloadredis-1c2b5f53188882ed78b83a5e4ec1697583530f0b.tar.gz
Make Cluster-bus port configurable with new cluster-port config (#9389)
Make Cluster-bus port configurable with new cluster-port config
-rw-r--r--redis.conf5
-rw-r--r--src/cluster.c9
-rw-r--r--src/cluster.h6
-rw-r--r--src/config.c1
-rw-r--r--src/server.h1
-rw-r--r--tests/unit/introspection.tcl1
6 files changed, 17 insertions, 6 deletions
diff --git a/redis.conf b/redis.conf
index e6c7039f0..2ea8190f5 100644
--- a/redis.conf
+++ b/redis.conf
@@ -1450,6 +1450,11 @@ lua-time-limit 5000
#
# cluster-node-timeout 15000
+# The cluster port is the port that the cluster bus will listen for inbound connections on. When set
+# to the default value, 0, it will be bound to the command port + 10000. Setting this value requires
+# you to specify the cluster bus port when executing cluster meet.
+# cluster-port 0
+
# A replica of a failing master will avoid to start a failover if its data
# looks too old.
#
diff --git a/src/cluster.c b/src/cluster.c
index 6527eb61f..812817aee 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -489,7 +489,8 @@ void deriveAnnouncedPorts(int *announced_port, int *announced_pport,
/* Default announced ports. */
*announced_port = port;
*announced_pport = server.tls_cluster ? server.port : 0;
- *announced_cport = port + CLUSTER_PORT_INCR;
+ *announced_cport = server.cluster_port ? server.cluster_port : port + CLUSTER_PORT_INCR;
+
/* Config overriding announced ports. */
if (server.tls_cluster && server.cluster_announce_tls_port) {
*announced_port = server.cluster_announce_tls_port;
@@ -570,7 +571,7 @@ void clusterInit(void) {
* The other handshake port check is triggered too late to stop
* us from trying to use a too-high cluster port number. */
int port = server.tls_cluster ? server.tls_port : server.port;
- if (port > (65535-CLUSTER_PORT_INCR)) {
+ if (!server.cluster_port && port > (65535-CLUSTER_PORT_INCR)) {
serverLog(LL_WARNING, "Redis port number too high. "
"Cluster communication port is 10,000 port "
"numbers higher than your Redis port. "
@@ -581,9 +582,11 @@ void clusterInit(void) {
serverLog(LL_WARNING, "No bind address is configured, but it is required for the Cluster bus.");
exit(1);
}
- if (listenToPort(port+CLUSTER_PORT_INCR, &server.cfd) == C_ERR) {
+ int cport = server.cluster_port ? server.cluster_port : port + CLUSTER_PORT_INCR;
+ if (listenToPort(cport, &server.cfd) == C_ERR ) {
exit(1);
}
+
if (createSocketAcceptHandler(&server.cfd, clusterAcceptHandler) != C_OK) {
serverPanic("Unrecoverable error creating Redis Cluster socket accept handler.");
}
diff --git a/src/cluster.h b/src/cluster.h
index 54a1ac25a..f97814775 100644
--- a/src/cluster.h
+++ b/src/cluster.h
@@ -6,9 +6,9 @@
*----------------------------------------------------------------------------*/
#define CLUSTER_SLOTS 16384
-#define CLUSTER_OK 0 /* Everything looks ok */
-#define CLUSTER_FAIL 1 /* The cluster can't work */
-#define CLUSTER_NAMELEN 40 /* sha1 hex length */
+#define CLUSTER_OK 0 /* Everything looks ok */
+#define CLUSTER_FAIL 1 /* The cluster can't work */
+#define CLUSTER_NAMELEN 40 /* sha1 hex length */
#define CLUSTER_PORT_INCR 10000 /* Cluster port = baseport + PORT_INCR */
/* The following defines are amount of time, sometimes expressed as
diff --git a/src/config.c b/src/config.c
index d8ddac124..9fb5080ad 100644
--- a/src/config.c
+++ b/src/config.c
@@ -2645,6 +2645,7 @@ standardConfig configs[] = {
createIntConfig("timeout", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.maxidletime, 0, INTEGER_CONFIG, NULL, NULL), /* Default client timeout: infinite */
createIntConfig("replica-announce-port", "slave-announce-port", MODIFIABLE_CONFIG, 0, 65535, server.slave_announce_port, 0, INTEGER_CONFIG, NULL, NULL),
createIntConfig("tcp-backlog", NULL, IMMUTABLE_CONFIG, 0, INT_MAX, server.tcp_backlog, 511, INTEGER_CONFIG, NULL, NULL), /* TCP listen backlog. */
+ createIntConfig("cluster-port", NULL, IMMUTABLE_CONFIG, 0, 65535, server.cluster_port, 0, INTEGER_CONFIG, NULL, NULL),
createIntConfig("cluster-announce-bus-port", NULL, MODIFIABLE_CONFIG, 0, 65535, server.cluster_announce_bus_port, 0, INTEGER_CONFIG, NULL, NULL), /* Default: Use +10000 offset. */
createIntConfig("cluster-announce-port", NULL, MODIFIABLE_CONFIG, 0, 65535, server.cluster_announce_port, 0, INTEGER_CONFIG, NULL, NULL), /* Use server.port */
createIntConfig("cluster-announce-tls-port", NULL, MODIFIABLE_CONFIG, 0, 65535, server.cluster_announce_tls_port, 0, INTEGER_CONFIG, NULL, NULL), /* Use server.tls_port */
diff --git a/src/server.h b/src/server.h
index 9ad4d78d0..2c9767e16 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1631,6 +1631,7 @@ struct redisServer {
xor of NOTIFY_... flags. */
/* Cluster */
int cluster_enabled; /* Is cluster enabled? */
+ int cluster_port; /* Set the cluster port for a node. */
mstime_t cluster_node_timeout; /* Cluster node timeout. */
char *cluster_configfile; /* Cluster auto-generated config file name. */
struct clusterState *cluster; /* State of the cluster */
diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl
index ba3587fe4..58e0bdcfb 100644
--- a/tests/unit/introspection.tcl
+++ b/tests/unit/introspection.tcl
@@ -158,6 +158,7 @@ start_server {tags {"introspection"}} {
bgsave_cpulist
set-proc-title
cluster-config-file
+ cluster-port
}
if {!$::tls} {