diff --git a/HISTORY b/HISTORY index 7047d15..3236f5f 100644 --- a/HISTORY +++ b/HISTORY @@ -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 diff --git a/src/connection_pool.c b/src/connection_pool.c index 6d05941..fe3f37c 100644 --- a/src/connection_pool.c +++ b/src/connection_pool.c @@ -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; } diff --git a/src/connection_pool.h b/src/connection_pool.h index 1f7c0e0..72113b3 100644 --- a/src/connection_pool.h +++ b/src/connection_pool.h @@ -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 diff --git a/src/server_id_func.c b/src/server_id_func.c index 2d3766b..19790d7 100644 --- a/src/server_id_func.c +++ b/src/server_id_func.c @@ -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; groupgroup_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); } diff --git a/src/server_id_func.h b/src/server_id_func.h index 52a32bc..08dd544 100644 --- a/src/server_id_func.h +++ b/src/server_id_func.h @@ -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;