server_id_func.[hc]: support communication type

support_rdma
YuQing 2023-09-06 17:24:44 +08:00
parent 4a86162913
commit 44f827f291
5 changed files with 69 additions and 10 deletions

View File

@ -1,7 +1,8 @@
Version 1.70 2023-09-05
Version 1.70 2023-09-06
* get full mac address of infiniband NIC under Linux
* struct fast_task_info add field conn for RDMA connection
* server_id_func.[hc]: support communication type
Version 1.69 2023-08-05
* bugfixed: array_allocator_alloc MUST init the array

View File

@ -513,6 +513,7 @@ int conn_pool_parse_server_info(const char *pServerStr,
pServerInfo->socket_domain = AF_INET;
pServerInfo->sock = -1;
pServerInfo->comm_type = fc_comm_type_sock;
return 0;
}

View File

@ -41,15 +41,15 @@ extern "C" {
(conn1).port == (conn2).port)
typedef enum {
fc_network_type_sock = 0,
fc_network_type_rdma
} FCNetworkType;
fc_comm_type_sock = 0,
fc_comm_type_rdma
} FCCommunicationType;
typedef struct {
int sock;
uint16_t port;
short socket_domain; //socket domain, AF_INET, AF_INET6 or AF_UNSPEC for auto dedect
FCNetworkType network_type;
FCCommunicationType comm_type;
bool validate_flag; //for connection pool
char ip_addr[INET6_ADDRSTRLEN];
char args[0]; //for extra data
@ -352,6 +352,18 @@ static inline int conn_pool_compare_ip_and_port(const char *ip1,
return port1 - port2;
}
static inline const char *fc_comm_type_str(const FCCommunicationType type)
{
switch (type) {
case fc_comm_type_sock:
return "socket";
case fc_comm_type_rdma:
return "rdma";
default:
return "unkown";
}
}
#ifdef __cplusplus
}
#endif

View File

@ -314,15 +314,39 @@ static inline void fc_server_set_ip_prefix(FCServerGroupInfo *ginfo,
}
}
static inline int fc_server_set_comm_type(FCServerGroupInfo *ginfo,
const char *config_filename, const char *section_name,
const char *comm_type)
{
if (comm_type == NULL) {
ginfo->comm_type = fc_comm_type_sock;
return 0;
} else if (strcasecmp(comm_type, "socket") == 0) {
ginfo->comm_type = fc_comm_type_sock;
return 0;
} else if (strcasecmp(comm_type, "rdma") == 0) {
ginfo->comm_type = fc_comm_type_rdma;
return 0;
} else {
logError("file: "__FILE__", line: %d, "
"config filename: %s, section: %s, "
"invalid communication: %s!", __LINE__,
config_filename, section_name, comm_type);
return EINVAL;
}
}
static int fc_server_load_one_group(FCServerConfig *ctx,
const char *config_filename, IniContext *ini_context,
const int group_count, const char *section_name)
{
int result;
FCServerGroupInfo *group;
char new_name[FAST_INI_ITEM_NAME_SIZE];
char *port_str;
char *net_type;
char *ip_prefix;
char *comm_type;
strcpy(new_name, section_name);
group = ctx->group_array.groups + ctx->group_array.count;
@ -370,6 +394,16 @@ static int fc_server_load_one_group(FCServerConfig *ctx,
ip_prefix = iniGetStrValue(section_name, "ip_prefix", ini_context);
fc_server_set_ip_prefix(group, ip_prefix);
comm_type = iniGetStrValue(section_name, "communication", ini_context);
if (comm_type == NULL) {
comm_type = iniGetStrValue(section_name, "comm_type", ini_context);
}
if ((result=fc_server_set_comm_type(group, config_filename,
section_name, comm_type)) != 0)
{
return result;
}
ctx->group_array.count++;
return 0;
}
@ -794,6 +828,7 @@ static int fc_server_load_group_server(FCServerConfig *ctx,
return result;
}
address.conn.comm_type = group->comm_type;
if ((result=fc_server_set_group_server_address(server,
group_addr, &address)) != 0)
{
@ -835,9 +870,16 @@ static int fc_server_set_host(FCServerConfig *ctx, FCServerInfo *server,
if (addr->conn.port == 0) {
addr_holder = *addr;
addr_holder.conn.port = FC_SERVER_GROUP_PORT(group);
addr_holder.conn.comm_type = group->comm_type;
new_addr = &addr_holder;
} else {
new_addr = addr;
if (addr->conn.comm_type == group->comm_type) {
new_addr = addr;
} else {
addr_holder = *addr;
addr_holder.conn.comm_type = group->comm_type;
new_addr = &addr_holder;
}
}
if ((result=fc_server_set_group_server_address(server,
@ -1341,12 +1383,13 @@ static int fc_groups_to_string(FCServerConfig *ctx, FastBuffer *buffer)
fast_buffer_append(buffer,
"[%s%.*s]\n"
"port = %d\n"
"communication = %s\n"
"net_type = %s\n"
"ip_prefix = %.*s\n\n",
GROUP_SECTION_PREFIX_STR,
group->group_name.len, group->group_name.str,
group->port, net_type_caption,
group->filter.ip_prefix.len,
group->port, fc_comm_type_str(group->comm_type),
net_type_caption, group->filter.ip_prefix.len,
group->filter.ip_prefix.str);
}
return 0;
@ -1438,8 +1481,9 @@ static void fc_server_log_groups(FCServerConfig *ctx)
end = ctx->group_array.groups + ctx->group_array.count;
for (group=ctx->group_array.groups; group<end; group++) {
logInfo("group_name: %.*s, port: %d, net_type: %s, ip_prefix: %.*s",
group->group_name.len, group->group_name.str, group->port,
logInfo("group_name: %.*s, port: %d, communication: %s, net_type: %s, "
"ip_prefix: %.*s", group->group_name.len, group->group_name.str,
group->port, fc_comm_type_str(group->comm_type),
get_net_type_caption(group->filter.net_type),
group->filter.ip_prefix.len, group->filter.ip_prefix.str);
}

View File

@ -57,6 +57,7 @@ typedef struct
string_t group_name;
int port; //default port
int server_port; //port in server section
FCCommunicationType comm_type;
struct {
int net_type;
string_t ip_prefix;