From 42715c9be0082b6c2f0691c16d27917c13313633 Mon Sep 17 00:00:00 2001
From: YuQing <384681@qq.com>
Date: Mon, 15 Feb 2021 13:26:51 +0800
Subject: [PATCH] add sf_connection_manager.[hc]
---
src/Makefile.in | 3 +-
src/sf_connection_manager.c | 34 ++++++++++++++++
src/sf_connection_manager.h | 79 +++++++++++++++++++++++++++++++++++++
3 files changed, 115 insertions(+), 1 deletion(-)
create mode 100644 src/sf_connection_manager.c
create mode 100644 src/sf_connection_manager.h
diff --git a/src/Makefile.in b/src/Makefile.in
index 7435c2f..be876a8 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -7,7 +7,7 @@ TARGET_LIB = $(TARGET_PREFIX)/$(LIB_VERSION)
TOP_HEADERS = sf_types.h sf_global.h sf_define.h sf_nio.h sf_service.h \
sf_func.h sf_util.h sf_configs.h sf_proto.h sf_binlog_writer.h \
- sf_sharding_htable.h
+ sf_sharding_htable.h sf_connection_manager.h
IDEMP_SERVER_HEADER = idempotency/server/server_types.h \
idempotency/server/server_channel.h \
@@ -25,6 +25,7 @@ ALL_HEADERS = $(TOP_HEADERS) $(IDEMP_SERVER_HEADER) $(IDEMP_CLIENT_HEADER)
SHARED_OBJS = sf_nio.lo sf_service.lo sf_global.lo \
sf_func.lo sf_util.lo sf_configs.lo sf_proto.lo \
sf_binlog_writer.lo sf_sharding_htable.lo \
+ sf_connection_manager.lo \
idempotency/server/server_channel.lo \
idempotency/server/request_htable.lo \
idempotency/server/channel_htable.lo \
diff --git a/src/sf_connection_manager.c b/src/sf_connection_manager.c
new file mode 100644
index 0000000..7fbeafd
--- /dev/null
+++ b/src/sf_connection_manager.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 YuQing <384681@qq.com>
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "fastcommon/shared_func.h"
+#include "fastcommon/logger.h"
+#include "sf_connection_manager.h"
+
+int sf_connection_manager_init(SFConnectionManager *cm, const int group_count,
+ const int server_group_index)
+{
+ return 0;
+}
diff --git a/src/sf_connection_manager.h b/src/sf_connection_manager.h
new file mode 100644
index 0000000..de831c9
--- /dev/null
+++ b/src/sf_connection_manager.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2020 YuQing <384681@qq.com>
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+//sf_connection_manager.h
+
+#ifndef _SF_CONNECTION_MANAGER_H
+#define _SF_CONNECTION_MANAGER_H
+
+#include "fastcommon/server_id_func.h"
+#include "sf_types.h"
+#include "sf_configs.h"
+
+typedef struct sf_cm_server_entry {
+ int server_id;
+ ConnectionInfo *conn;
+ FCAddressPtrArray *addr_array;
+} SFCMServerEntry;
+
+typedef struct sf_cm_server_array {
+ SFCMServerEntry *servers;
+ int count;
+} SFCMServerArray;
+
+typedef struct sf_cm_server_ptr_array {
+ SFCMServerEntry **servers;
+ int count;
+} SFCMServerPtrArray;
+
+typedef struct sf_cm_conn_group_entry {
+ SFCMServerEntry *master;
+ SFCMServerPtrArray alives;
+ pthread_mutex_t lock;
+} SFCMConnGroupEntry;
+
+typedef struct sf_cm_conn_group_array {
+ SFCMConnGroupEntry *entries;
+ int count;
+ int base_id;
+} SFCMConnGroupArray;
+
+typedef struct sf_connection_manager {
+ int server_group_index;
+ SFDataReadRule read_rule; //the rule for read
+ SFCMConnGroupArray groups;
+} SFConnectionManager;
+
+int sf_connection_manager_init(SFConnectionManager *cm, const int group_count,
+ const int server_group_index);
+
+int sf_connection_manager_add(SFConnectionManager *cm, const int group_id,
+ FCServerInfo **servers, const int count);
+
+ConnectionInfo *sf_connection_manager_get_master(SFConnectionManager *cm,
+ const int group_index, int *err_no);
+
+ConnectionInfo *sf_connection_manager_get_readable(SFConnectionManager *cm,
+ const int group_index, int *err_no);
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif