log service_name field when connect or communicate error

vote_node
YuQing 2022-05-08 10:44:55 +08:00
parent 00faf7e637
commit 09839f9bf4
5 changed files with 52 additions and 45 deletions

View File

@ -79,8 +79,9 @@
connection_params->channel) == 0) \ connection_params->channel) == 0) \
{ \ { \
if ((conn_result=sf_proto_rebind_idempotency_channel( \ if ((conn_result=sf_proto_rebind_idempotency_channel( \
conn, connection_params->channel->id, \ conn, (conn_manager)->module_name, \
connection_params->channel->key, \ connection_params->channel->id, \
connection_params->channel->key, \
client_ctx->common_cfg.network_timeout)) == 0) \ client_ctx->common_cfg.network_timeout)) == 0) \
{ \ { \
continue; \ continue; \

View File

@ -104,14 +104,15 @@ static inline const char *sf_get_quorum_caption(
} }
static inline bool sf_election_quorum_check(const SFElectionQuorum quorum, static inline bool sf_election_quorum_check(const SFElectionQuorum quorum,
const int total_count, const int active_count) const bool vote_node_enabled, const int total_count,
const int active_count)
{ {
switch (quorum) { switch (quorum) {
case sf_election_quorum_any: case sf_election_quorum_any:
return active_count > 0; return active_count > 0;
case sf_election_quorum_auto: case sf_election_quorum_auto:
if (total_count % 2 == 0) { //same as sf_election_quorum_any if (total_count % 2 == 0 && !vote_node_enabled) {
return active_count > 0; return active_count > 0; //same as sf_election_quorum_any
} }
//continue //continue
case sf_election_quorum_majority: case sf_election_quorum_majority:

View File

@ -37,7 +37,8 @@ static int get_group_servers(SFConnectionManager *cm,
static ConnectionInfo *get_spec_connection(SFConnectionManager *cm, static ConnectionInfo *get_spec_connection(SFConnectionManager *cm,
const ConnectionInfo *target, int *err_no) const ConnectionInfo *target, int *err_no)
{ {
return conn_pool_get_connection(&cm->cpool, target, err_no); return conn_pool_get_connection_ex(&cm->cpool,
target, cm->module_name, err_no);
} }
static ConnectionInfo *make_connection(SFConnectionManager *cm, static ConnectionInfo *make_connection(SFConnectionManager *cm,
@ -419,8 +420,8 @@ static ConnectionInfo *get_leader_connection(SFConnectionManager *cm,
break; break;
} }
if ((*err_no=sf_proto_get_leader(conn, cm->common_cfg-> if ((*err_no=sf_proto_get_leader(conn, cm->module_name, cm->
network_timeout, &leader)) != 0) common_cfg->network_timeout, &leader)) != 0)
{ {
close_connection(cm, conn); close_connection(cm, conn);
break; break;
@ -472,7 +473,7 @@ int sf_cm_validate_connection_callback(ConnectionInfo *conn, void *args)
if ((result=sf_active_test(conn, &response, cm->common_cfg-> if ((result=sf_active_test(conn, &response, cm->common_cfg->
network_timeout)) != 0) network_timeout)) != 0)
{ {
sf_log_network_error(&response, conn, result); sf_log_network_error(&response, conn, cm->module_name, result);
} }
return result; return result;
@ -696,8 +697,8 @@ static int do_get_group_servers(SFConnectionManager *cm,
sarray.alloc = MAX_GROUP_SERVER_COUNT; sarray.alloc = MAX_GROUP_SERVER_COUNT;
sarray.count = 0; sarray.count = 0;
sarray.servers = fixed_servers; sarray.servers = fixed_servers;
if ((result=sf_proto_get_group_servers(conn, cm->common_cfg-> if ((result=sf_proto_get_group_servers(conn, cm->module_name, cm->
network_timeout, group->id, &sarray)) != 0) common_cfg->network_timeout, group->id, &sarray)) != 0)
{ {
return result; return result;
} }

View File

@ -458,7 +458,8 @@ int sf_proto_deal_ack(struct fast_task_info *task,
} }
int sf_proto_rebind_idempotency_channel(ConnectionInfo *conn, int sf_proto_rebind_idempotency_channel(ConnectionInfo *conn,
const uint32_t channel_id, const int key, const int network_timeout) const char *service_name, const uint32_t channel_id,
const int key, const int network_timeout)
{ {
char out_buff[sizeof(SFCommonProtoHeader) + char out_buff[sizeof(SFCommonProtoHeader) +
sizeof(SFProtoRebindChannelReq)]; sizeof(SFProtoRebindChannelReq)];
@ -478,15 +479,15 @@ int sf_proto_rebind_idempotency_channel(ConnectionInfo *conn,
sizeof(out_buff), &response, network_timeout, sizeof(out_buff), &response, network_timeout,
SF_SERVICE_PROTO_REBIND_CHANNEL_RESP)) != 0) SF_SERVICE_PROTO_REBIND_CHANNEL_RESP)) != 0)
{ {
sf_log_network_error(&response, conn, result); sf_log_network_error(&response, conn, service_name, result);
} }
return result; return result;
} }
int sf_proto_get_group_servers(ConnectionInfo *conn, int sf_proto_get_group_servers(ConnectionInfo *conn,
const int network_timeout, const int group_id, const char *service_name, const int network_timeout,
SFGroupServerArray *sarray) const int group_id, SFGroupServerArray *sarray)
{ {
char out_buff[sizeof(SFCommonProtoHeader) + char out_buff[sizeof(SFCommonProtoHeader) +
sizeof(SFProtoGetGroupServersReq)]; sizeof(SFProtoGetGroupServersReq)];
@ -513,7 +514,7 @@ int sf_proto_get_group_servers(ConnectionInfo *conn,
SF_SERVICE_PROTO_GET_GROUP_SERVERS_RESP, in_buff, SF_SERVICE_PROTO_GET_GROUP_SERVERS_RESP, in_buff,
sizeof(in_buff), &body_len)) != 0) sizeof(in_buff), &body_len)) != 0)
{ {
sf_log_network_error(&response, conn, result); sf_log_network_error(&response, conn, service_name, result);
return result; return result;
} }
@ -553,9 +554,8 @@ int sf_proto_get_group_servers(ConnectionInfo *conn,
return 0; return 0;
} }
int sf_proto_get_leader(ConnectionInfo *conn, int sf_proto_get_leader(ConnectionInfo *conn, const char *service_name,
const int network_timeout, const int network_timeout, SFClientServerEntry *leader)
SFClientServerEntry *leader)
{ {
int result; int result;
SFCommonProtoHeader *header; SFCommonProtoHeader *header;
@ -571,7 +571,7 @@ int sf_proto_get_leader(ConnectionInfo *conn,
SF_SERVICE_PROTO_GET_LEADER_RESP, (char *)&server_resp, SF_SERVICE_PROTO_GET_LEADER_RESP, (char *)&server_resp,
sizeof(SFProtoGetServerResp))) != 0) sizeof(SFProtoGetServerResp))) != 0)
{ {
sf_log_network_error(&response, conn, result); sf_log_network_error(&response, conn, service_name, result);
} else { } else {
leader->server_id = buff2int(server_resp.server_id); leader->server_id = buff2int(server_resp.server_id);
memcpy(leader->conn.ip_addr, server_resp.ip_addr, IP_ADDRESS_SIZE); memcpy(leader->conn.ip_addr, server_resp.ip_addr, IP_ADDRESS_SIZE);

View File

@ -297,41 +297,45 @@ static inline void sf_proto_init_task_context(struct fast_task_info *task,
} }
static inline void sf_log_network_error_ex1(SFResponseInfo *response, static inline void sf_log_network_error_ex1(SFResponseInfo *response,
const ConnectionInfo *conn, const int result, const ConnectionInfo *conn, const char *service_name,
const int log_level, const char *file, const int line) const int result, const int log_level,
const char *file, const int line)
{ {
if (response->error.length > 0) { if (response->error.length > 0) {
log_it_ex(&g_log_context, log_level, log_it_ex(&g_log_context, log_level, "file: %s, line: %d, "
"file: %s, line: %d, " "%s%sserver %s:%u response message: %s", file, line,
"server %s:%u response message: %s", (service_name != NULL ? service_name : ""),
file, line, conn->ip_addr, conn->port, (service_name != NULL ? " ": ""),
conn->ip_addr, conn->port,
response->error.message); response->error.message);
} else { } else {
log_it_ex(&g_log_context, log_level, log_it_ex(&g_log_context, log_level, "file: %s, line: %d, "
"file: %s, line: %d, " "communicate with %s%sserver %s:%u fail, "
"communicate with server %s:%u fail, "
"errno: %d, error info: %s", file, line, "errno: %d, error info: %s", file, line,
(service_name != NULL ? service_name : ""),
(service_name != NULL ? " ": ""),
conn->ip_addr, conn->port, conn->ip_addr, conn->port,
result, STRERROR(result)); result, STRERROR(result));
} }
} }
#define sf_log_network_error_ex(response, conn, result, log_level) \ #define sf_log_network_error_ex(response, conn, \
sf_log_network_error_ex1(response, conn, result, \ service_name, result, log_level) \
log_level, __FILE__, __LINE__) sf_log_network_error_ex1(response, conn, service_name, \
result, log_level, __FILE__, __LINE__)
#define sf_log_network_error(response, conn, result) \ #define sf_log_network_error(response, conn, service_name, result) \
sf_log_network_error_ex1(response, conn, result, \ sf_log_network_error_ex1(response, conn, service_name, result, \
LOG_ERR, __FILE__, __LINE__) LOG_ERR, __FILE__, __LINE__)
#define sf_log_network_error_for_update(response, conn, result) \ #define sf_log_network_error_for_update(response, conn, service_name, result) \
sf_log_network_error_ex(response, conn, result, \ sf_log_network_error_ex(response, conn, service_name, result, \
(result == SF_RETRIABLE_ERROR_CHANNEL_INVALID) ? \ (result == SF_RETRIABLE_ERROR_CHANNEL_INVALID) ? \
LOG_DEBUG : LOG_ERR) LOG_DEBUG : LOG_ERR)
#define sf_log_network_error_for_delete(response, \ #define sf_log_network_error_for_delete(response, conn, \
conn, result, enoent_log_level) \ service_name, result, enoent_log_level) \
sf_log_network_error_ex(response, conn, result, \ sf_log_network_error_ex(response, conn, service_name, result, \
(result == SF_RETRIABLE_ERROR_CHANNEL_INVALID) ? \ (result == SF_RETRIABLE_ERROR_CHANNEL_INVALID) ? \
LOG_DEBUG : ((result == ENOENT || result == ENODATA) ? \ LOG_DEBUG : ((result == ENOENT || result == ENODATA) ? \
enoent_log_level : LOG_ERR)) enoent_log_level : LOG_ERR))
@ -558,15 +562,15 @@ int sf_proto_deal_ack(struct fast_task_info *task,
SFRequestInfo *request, SFResponseInfo *response); SFRequestInfo *request, SFResponseInfo *response);
int sf_proto_rebind_idempotency_channel(ConnectionInfo *conn, int sf_proto_rebind_idempotency_channel(ConnectionInfo *conn,
const uint32_t channel_id, const int key, const int network_timeout); const char *service_name, const uint32_t channel_id,
const int key, const int network_timeout);
int sf_proto_get_group_servers(ConnectionInfo *conn, int sf_proto_get_group_servers(ConnectionInfo *conn,
const int network_timeout, const int group_id, const char *service_name, const int network_timeout,
SFGroupServerArray *sarray); const int group_id, SFGroupServerArray *sarray);
int sf_proto_get_leader(ConnectionInfo *conn, int sf_proto_get_leader(ConnectionInfo *conn, const char *service_name,
const int network_timeout, const int network_timeout, SFClientServerEntry *leader);
SFClientServerEntry *leader);
static inline void sf_proto_get_server_status_pack( static inline void sf_proto_get_server_status_pack(
const SFGetServerStatusRequest *r, const SFGetServerStatusRequest *r,