diff --git a/src/idempotency/client/rpc_wrapper.h b/src/idempotency/client/rpc_wrapper.h index 432ab66..89c233d 100644 --- a/src/idempotency/client/rpc_wrapper.h +++ b/src/idempotency/client/rpc_wrapper.h @@ -79,8 +79,9 @@ connection_params->channel) == 0) \ { \ if ((conn_result=sf_proto_rebind_idempotency_channel( \ - conn, connection_params->channel->id, \ - connection_params->channel->key, \ + conn, (conn_manager)->module_name, \ + connection_params->channel->id, \ + connection_params->channel->key, \ client_ctx->common_cfg.network_timeout)) == 0) \ { \ continue; \ diff --git a/src/sf_configs.h b/src/sf_configs.h index a0a71ee..2fdf572 100644 --- a/src/sf_configs.h +++ b/src/sf_configs.h @@ -104,14 +104,15 @@ static inline const char *sf_get_quorum_caption( } 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) { case sf_election_quorum_any: return active_count > 0; case sf_election_quorum_auto: - if (total_count % 2 == 0) { //same as sf_election_quorum_any - return active_count > 0; + if (total_count % 2 == 0 && !vote_node_enabled) { + return active_count > 0; //same as sf_election_quorum_any } //continue case sf_election_quorum_majority: diff --git a/src/sf_connection_manager.c b/src/sf_connection_manager.c index d85577e..bb9da7e 100644 --- a/src/sf_connection_manager.c +++ b/src/sf_connection_manager.c @@ -37,7 +37,8 @@ static int get_group_servers(SFConnectionManager *cm, static ConnectionInfo *get_spec_connection(SFConnectionManager *cm, 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, @@ -419,8 +420,8 @@ static ConnectionInfo *get_leader_connection(SFConnectionManager *cm, break; } - if ((*err_no=sf_proto_get_leader(conn, cm->common_cfg-> - network_timeout, &leader)) != 0) + if ((*err_no=sf_proto_get_leader(conn, cm->module_name, cm-> + common_cfg->network_timeout, &leader)) != 0) { close_connection(cm, conn); 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-> network_timeout)) != 0) { - sf_log_network_error(&response, conn, result); + sf_log_network_error(&response, conn, cm->module_name, result); } return result; @@ -696,8 +697,8 @@ static int do_get_group_servers(SFConnectionManager *cm, sarray.alloc = MAX_GROUP_SERVER_COUNT; sarray.count = 0; sarray.servers = fixed_servers; - if ((result=sf_proto_get_group_servers(conn, cm->common_cfg-> - network_timeout, group->id, &sarray)) != 0) + if ((result=sf_proto_get_group_servers(conn, cm->module_name, cm-> + common_cfg->network_timeout, group->id, &sarray)) != 0) { return result; } diff --git a/src/sf_proto.c b/src/sf_proto.c index d4b9420..ffe049c 100644 --- a/src/sf_proto.c +++ b/src/sf_proto.c @@ -458,7 +458,8 @@ int sf_proto_deal_ack(struct fast_task_info *task, } 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) + sizeof(SFProtoRebindChannelReq)]; @@ -478,15 +479,15 @@ int sf_proto_rebind_idempotency_channel(ConnectionInfo *conn, sizeof(out_buff), &response, network_timeout, 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; } int sf_proto_get_group_servers(ConnectionInfo *conn, - const int network_timeout, const int group_id, - SFGroupServerArray *sarray) + const char *service_name, const int network_timeout, + const int group_id, SFGroupServerArray *sarray) { char out_buff[sizeof(SFCommonProtoHeader) + sizeof(SFProtoGetGroupServersReq)]; @@ -513,7 +514,7 @@ int sf_proto_get_group_servers(ConnectionInfo *conn, SF_SERVICE_PROTO_GET_GROUP_SERVERS_RESP, in_buff, sizeof(in_buff), &body_len)) != 0) { - sf_log_network_error(&response, conn, result); + sf_log_network_error(&response, conn, service_name, result); return result; } @@ -553,9 +554,8 @@ int sf_proto_get_group_servers(ConnectionInfo *conn, return 0; } -int sf_proto_get_leader(ConnectionInfo *conn, - const int network_timeout, - SFClientServerEntry *leader) +int sf_proto_get_leader(ConnectionInfo *conn, const char *service_name, + const int network_timeout, SFClientServerEntry *leader) { int result; SFCommonProtoHeader *header; @@ -571,7 +571,7 @@ int sf_proto_get_leader(ConnectionInfo *conn, SF_SERVICE_PROTO_GET_LEADER_RESP, (char *)&server_resp, sizeof(SFProtoGetServerResp))) != 0) { - sf_log_network_error(&response, conn, result); + sf_log_network_error(&response, conn, service_name, result); } else { leader->server_id = buff2int(server_resp.server_id); memcpy(leader->conn.ip_addr, server_resp.ip_addr, IP_ADDRESS_SIZE); diff --git a/src/sf_proto.h b/src/sf_proto.h index d07c030..be31a1a 100644 --- a/src/sf_proto.h +++ b/src/sf_proto.h @@ -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, - const ConnectionInfo *conn, const int result, - const int log_level, const char *file, const int line) + const ConnectionInfo *conn, const char *service_name, + const int result, const int log_level, + const char *file, const int line) { if (response->error.length > 0) { - log_it_ex(&g_log_context, log_level, - "file: %s, line: %d, " - "server %s:%u response message: %s", - file, line, conn->ip_addr, conn->port, + log_it_ex(&g_log_context, log_level, "file: %s, line: %d, " + "%s%sserver %s:%u response message: %s", file, line, + (service_name != NULL ? service_name : ""), + (service_name != NULL ? " ": ""), + conn->ip_addr, conn->port, response->error.message); } else { - log_it_ex(&g_log_context, log_level, - "file: %s, line: %d, " - "communicate with server %s:%u fail, " + log_it_ex(&g_log_context, log_level, "file: %s, line: %d, " + "communicate with %s%sserver %s:%u fail, " "errno: %d, error info: %s", file, line, + (service_name != NULL ? service_name : ""), + (service_name != NULL ? " ": ""), conn->ip_addr, conn->port, result, STRERROR(result)); } } -#define sf_log_network_error_ex(response, conn, result, log_level) \ - sf_log_network_error_ex1(response, conn, result, \ - log_level, __FILE__, __LINE__) +#define sf_log_network_error_ex(response, conn, \ + service_name, result, log_level) \ + sf_log_network_error_ex1(response, conn, service_name, \ + result, log_level, __FILE__, __LINE__) -#define sf_log_network_error(response, conn, result) \ - sf_log_network_error_ex1(response, conn, result, \ +#define sf_log_network_error(response, conn, service_name, result) \ + sf_log_network_error_ex1(response, conn, service_name, result, \ LOG_ERR, __FILE__, __LINE__) -#define sf_log_network_error_for_update(response, conn, result) \ - sf_log_network_error_ex(response, conn, result, \ +#define sf_log_network_error_for_update(response, conn, service_name, result) \ + sf_log_network_error_ex(response, conn, service_name, result, \ (result == SF_RETRIABLE_ERROR_CHANNEL_INVALID) ? \ LOG_DEBUG : LOG_ERR) -#define sf_log_network_error_for_delete(response, \ - conn, result, enoent_log_level) \ - sf_log_network_error_ex(response, conn, result, \ +#define sf_log_network_error_for_delete(response, conn, \ + service_name, result, enoent_log_level) \ + sf_log_network_error_ex(response, conn, service_name, result, \ (result == SF_RETRIABLE_ERROR_CHANNEL_INVALID) ? \ LOG_DEBUG : ((result == ENOENT || result == ENODATA) ? \ enoent_log_level : LOG_ERR)) @@ -558,15 +562,15 @@ int sf_proto_deal_ack(struct fast_task_info *task, SFRequestInfo *request, SFResponseInfo *response); 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, - const int network_timeout, const int group_id, - SFGroupServerArray *sarray); + const char *service_name, const int network_timeout, + const int group_id, SFGroupServerArray *sarray); -int sf_proto_get_leader(ConnectionInfo *conn, - const int network_timeout, - SFClientServerEntry *leader); +int sf_proto_get_leader(ConnectionInfo *conn, const char *service_name, + const int network_timeout, SFClientServerEntry *leader); static inline void sf_proto_get_server_status_pack( const SFGetServerStatusRequest *r,