diff options
author | zhenwei pi <pizhenwei@bytedance.com> | 2022-08-22 15:15:37 +0800 |
---|---|---|
committer | zhenwei pi <pizhenwei@bytedance.com> | 2022-08-22 15:15:37 +0800 |
commit | 45617385e72eb814c6548064835cf19cdf466a5b (patch) | |
tree | 26bc3790c2e8626e4c3c74a5aa3c214a389c4d92 /src/cluster.c | |
parent | eb94d6d36dec7323af5fb89a5899506d5c07adb1 (diff) | |
download | redis-45617385e72eb814c6548064835cf19cdf466a5b.tar.gz |
Use connection name of string
Suggested by Oran, use an array to store all the connection types
instead of a linked list, and use connection name of string. The index
of a connection is dynamically allocated.
Currently we support max 8 connection types, include:
- tcp
- unix socket
- tls
and RDMA is in the plan, then we have another 4 types to support, it
should be enough in a long time.
Introduce 3 functions to get connection type by a fast path:
- connectionTypeTcp()
- connectionTypeTls()
- connectionTypeUnix()
Note that connectionByType() is designed to use only in unlikely code path.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/cluster.c')
-rw-r--r-- | src/cluster.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/cluster.c b/src/cluster.c index b60b79153..7aed7b35b 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -119,12 +119,12 @@ dictType clusterNodesBlackListDictType = { NULL /* allow to expand */ }; -static int connTypeOfCluster() { +static ConnectionType *connTypeOfCluster() { if (server.tls_cluster) { - return CONN_TYPE_TLS; + return connectionTypeTls(); } - return CONN_TYPE_SOCKET; + return connectionTypeTcp(); } /* ----------------------------------------------------------------------------- @@ -5030,7 +5030,7 @@ void addNodeToNodeReply(client *c, clusterNode *node) { /* Report non-TLS ports to non-TLS client in TLS cluster if available. */ int use_pport = (server.tls_cluster && - c->conn && connGetType(c->conn) != CONN_TYPE_TLS); + c->conn && (c->conn->type != connectionTypeTls())); addReplyLongLong(c, use_pport && node->pport ? node->pport : node->port); addReplyBulkCBuffer(c, node->name, CLUSTER_NAMELEN); @@ -5335,7 +5335,7 @@ NULL /* Report plaintext ports, only if cluster is TLS but client is known to * be non-TLS). */ int use_pport = (server.tls_cluster && - c->conn && connGetType(c->conn) != CONN_TYPE_TLS); + c->conn && (c->conn->type != connectionTypeTls())); sds nodes = clusterGenNodesDescription(0, use_pport); addReplyVerbatim(c,nodes,sdslen(nodes),"txt"); sdsfree(nodes); @@ -5767,7 +5767,7 @@ NULL /* Use plaintext port if cluster is TLS but client is non-TLS. */ int use_pport = (server.tls_cluster && - c->conn && connGetType(c->conn) != CONN_TYPE_TLS); + c->conn && (c->conn->type != connectionTypeTls())); addReplyArrayLen(c,n->numslaves); for (j = 0; j < n->numslaves; j++) { sds ni = clusterGenNodeDescription(n->slaves[j], use_pport); @@ -6896,7 +6896,7 @@ void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_co /* Redirect to IP:port. Include plaintext port if cluster is TLS but * client is non-TLS. */ int use_pport = (server.tls_cluster && - c->conn && connGetType(c->conn) != CONN_TYPE_TLS); + c->conn && (c->conn->type != connectionTypeTls())); int port = use_pport && n->pport ? n->pport : n->port; addReplyErrorSds(c,sdscatprintf(sdsempty(), "-%s %d %s:%d", |