diff options
author | Wen Hui <wen.hui.ware@gmail.com> | 2021-10-19 01:28:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-18 22:28:27 -0700 |
commit | 1c2b5f53188882ed78b83a5e4ec1697583530f0b (patch) | |
tree | 4ce39e107b5a767eba6c7ad079bc01848154173d /src | |
parent | b7f2a1a217b5c5b7b0320bfe0511dfdf2e0eb174 (diff) | |
download | redis-1c2b5f53188882ed78b83a5e4ec1697583530f0b.tar.gz |
Make Cluster-bus port configurable with new cluster-port config (#9389)
Make Cluster-bus port configurable with new cluster-port config
Diffstat (limited to 'src')
-rw-r--r-- | src/cluster.c | 9 | ||||
-rw-r--r-- | src/cluster.h | 6 | ||||
-rw-r--r-- | src/config.c | 1 | ||||
-rw-r--r-- | src/server.h | 1 |
4 files changed, 11 insertions, 6 deletions
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 */ |