summaryrefslogtreecommitdiff
path: root/src/replication.c
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2022-07-27 10:46:31 +0800
committerzhenwei pi <pizhenwei@bytedance.com>2022-08-22 15:11:44 +0800
commit1234e3a5628260658adfe9065cb58ec5c1cb5ebe (patch)
tree98275a38f8d2938d7438c422371c758f28645d9a /src/replication.c
parentc4c02f80365e5f7a82efa6a4d4f247503f54a5d8 (diff)
downloadredis-1234e3a5628260658adfe9065cb58ec5c1cb5ebe.tar.gz
Fully abstract connection type
Abstract common interface of connection type, so Redis can hide the implementation and uplayer only calls connection API without macro. uplayer | connection layer / \ socket TLS Currently, for both socket and TLS, all the methods of connection type are declared as static functions. It's possible to build TLS(even socket) as a shared library, and Redis loads it dynamically in the next step. Also add helper function connTypeOfCluster() and connTypeOfReplication() to simplify the code: link->conn = server.tls_cluster ? connCreateTLS() : connCreateSocket(); -> link->conn = connCreate(connTypeOfCluster()); Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/replication.c')
-rw-r--r--src/replication.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/replication.c b/src/replication.c
index 3ae130252..8de14c9f2 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -55,6 +55,13 @@ int cancelReplicationHandshake(int reconnect);
int RDBGeneratedByReplication = 0;
/* --------------------------- Utility functions ---------------------------- */
+static int connTypeOfReplication() {
+ if (server.tls_replication) {
+ return CONN_TYPE_TLS;
+ }
+
+ return CONN_TYPE_SOCKET;
+}
/* Return the pointer to a string representing the slave ip:listening_port
* pair. Mostly useful for logging, since we want to log a slave using its
@@ -2864,7 +2871,7 @@ write_error: /* Handle sendCommand() errors. */
}
int connectWithMaster(void) {
- server.repl_transfer_s = server.tls_replication ? connCreateTLS() : connCreateSocket();
+ server.repl_transfer_s = connCreate(connTypeOfReplication());
if (connConnect(server.repl_transfer_s, server.masterhost, server.masterport,
server.bind_source_addr, syncWithMaster) == C_ERR) {
serverLog(LL_WARNING,"Unable to connect to MASTER: %s",