add sf_connection_manager.[hc]

connection_manager
YuQing 2021-02-15 13:26:51 +08:00
parent 67b412fb88
commit 42715c9be0
3 changed files with 115 additions and 1 deletions

View File

@ -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 \

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#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;
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
//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