log square quoted IPv6 address
parent
1c796ab819
commit
231e2610e5
|
|
@ -213,6 +213,7 @@ int idempotency_client_channel_check_reconnect(
|
||||||
IdempotencyClientChannel *channel)
|
IdempotencyClientChannel *channel)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
if (!__sync_bool_compare_and_swap(&channel->in_ioevent, 0, 1)) {
|
if (!__sync_bool_compare_and_swap(&channel->in_ioevent, 0, 1)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -223,10 +224,12 @@ int idempotency_client_channel_check_reconnect(
|
||||||
channel->last_connect_time = g_current_time;
|
channel->last_connect_time = g_current_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||||
|
format_ip_address(channel->task->server_ip, formatted_ip);
|
||||||
logDebug("file: "__FILE__", line: %d, "
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"trigger connect to server %s:%u",
|
"trigger connect to server %s:%u", __LINE__,
|
||||||
__LINE__, channel->task->server_ip,
|
formatted_ip, channel->task->port);
|
||||||
channel->task->port);
|
}
|
||||||
|
|
||||||
__sync_bool_compare_and_swap(&channel->task->canceled, 1, 0);
|
__sync_bool_compare_and_swap(&channel->task->canceled, 1, 0);
|
||||||
if ((result=sf_nio_notify(channel->task, SF_NIO_STAGE_CONNECT)) == 0) {
|
if ((result=sf_nio_notify(channel->task, SF_NIO_STAGE_CONNECT)) == 0) {
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,12 @@ static inline int idempotency_client_channel_check_wait_ex(
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
format_ip_address(channel->task->server_ip, formatted_ip);
|
||||||
logInfo("file: "__FILE__", line: %d, "
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"channel_check fail, server %s:%u, in_ioevent: %d, "
|
"channel_check fail, server %s:%u, in_ioevent: %d, "
|
||||||
"canceled: %d, req count: %"PRId64, __LINE__,
|
"canceled: %d, req count: %"PRId64, __LINE__,
|
||||||
channel->task->server_ip, channel->task->port,
|
formatted_ip, channel->task->port,
|
||||||
__sync_add_and_fetch(&channel->in_ioevent, 0),
|
__sync_add_and_fetch(&channel->in_ioevent, 0),
|
||||||
__sync_add_and_fetch(&channel->task->canceled, 0),
|
__sync_add_and_fetch(&channel->task->canceled, 0),
|
||||||
channel->task->req_count);
|
channel->task->req_count);
|
||||||
|
|
|
||||||
|
|
@ -60,11 +60,13 @@ static int receipt_init_task(struct fast_task_info *task)
|
||||||
static int receipt_recv_timeout_callback(struct fast_task_info *task)
|
static int receipt_recv_timeout_callback(struct fast_task_info *task)
|
||||||
{
|
{
|
||||||
IdempotencyClientChannel *channel;
|
IdempotencyClientChannel *channel;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
if (SF_NIO_TASK_STAGE_FETCH(task) == SF_NIO_STAGE_CONNECT) {
|
if (SF_NIO_TASK_STAGE_FETCH(task) == SF_NIO_STAGE_CONNECT) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connect to server %s:%u timeout",
|
"connect to server %s:%u timeout",
|
||||||
__LINE__, task->server_ip, task->port);
|
__LINE__, formatted_ip, task->port);
|
||||||
return ETIMEDOUT;
|
return ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,12 +74,12 @@ static int receipt_recv_timeout_callback(struct fast_task_info *task)
|
||||||
if (channel->waiting_resp_qinfo.head != NULL) {
|
if (channel->waiting_resp_qinfo.head != NULL) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"waiting receipt response from server %s:%u timeout",
|
"waiting receipt response from server %s:%u timeout",
|
||||||
__LINE__, task->server_ip, task->port);
|
__LINE__, formatted_ip, task->port);
|
||||||
} else {
|
} else {
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"%s server %s:%u timeout, channel established: %d",
|
"%s server %s:%u timeout, channel established: %d",
|
||||||
__LINE__, task->nio_stages.current == SF_NIO_STAGE_SEND ?
|
__LINE__, task->nio_stages.current == SF_NIO_STAGE_SEND ?
|
||||||
"send to" : "recv from", task->server_ip, task->port,
|
"send to" : "recv from", formatted_ip, task->port,
|
||||||
FC_ATOMIC_GET(channel->established));
|
FC_ATOMIC_GET(channel->established));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,6 +89,7 @@ static int receipt_recv_timeout_callback(struct fast_task_info *task)
|
||||||
static void receipt_task_finish_cleanup(struct fast_task_info *task)
|
static void receipt_task_finish_cleanup(struct fast_task_info *task)
|
||||||
{
|
{
|
||||||
IdempotencyClientChannel *channel;
|
IdempotencyClientChannel *channel;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
if (task->event.fd >= 0) {
|
if (task->event.fd >= 0) {
|
||||||
sf_task_detach_thread(task);
|
sf_task_detach_thread(task);
|
||||||
|
|
@ -102,9 +105,12 @@ static void receipt_task_finish_cleanup(struct fast_task_info *task)
|
||||||
__sync_bool_compare_and_swap(&channel->established, 1, 0);
|
__sync_bool_compare_and_swap(&channel->established, 1, 0);
|
||||||
__sync_bool_compare_and_swap(&channel->in_ioevent, 1, 0);
|
__sync_bool_compare_and_swap(&channel->in_ioevent, 1, 0);
|
||||||
|
|
||||||
|
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logDebug("file: "__FILE__", line: %d, "
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"receipt task for server %s:%u exit",
|
"receipt task for server %s:%u exit",
|
||||||
__LINE__, task->server_ip, task->port);
|
__LINE__, formatted_ip, task->port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_channel_request(struct fast_task_info *task)
|
static void setup_channel_request(struct fast_task_info *task)
|
||||||
|
|
@ -245,11 +251,14 @@ static inline int receipt_expect_body_length(struct fast_task_info *task,
|
||||||
const int expect_body_len)
|
const int expect_body_len)
|
||||||
{
|
{
|
||||||
int body_len;
|
int body_len;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
body_len = task->recv.ptr->length - sizeof(SFCommonProtoHeader);
|
body_len = task->recv.ptr->length - sizeof(SFCommonProtoHeader);
|
||||||
if (body_len != expect_body_len) {
|
if (body_len != expect_body_len) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"server %s:%u, response body length: %d != %d", __LINE__,
|
"server %s:%u, response body length: %d != %d", __LINE__,
|
||||||
task->server_ip, task->port, body_len, expect_body_len);
|
formatted_ip, task->port, body_len, expect_body_len);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,6 +271,7 @@ static int deal_setup_channel_response(struct fast_task_info *task)
|
||||||
IdempotencyReceiptThreadContext *thread_ctx;
|
IdempotencyReceiptThreadContext *thread_ctx;
|
||||||
SFProtoSetupChannelResp *resp;
|
SFProtoSetupChannelResp *resp;
|
||||||
IdempotencyClientChannel *channel;
|
IdempotencyClientChannel *channel;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
int channel_id;
|
int channel_id;
|
||||||
int channel_key;
|
int channel_key;
|
||||||
int buffer_size;
|
int buffer_size;
|
||||||
|
|
@ -274,10 +284,11 @@ static int deal_setup_channel_response(struct fast_task_info *task)
|
||||||
|
|
||||||
channel = (IdempotencyClientChannel *)task->arg;
|
channel = (IdempotencyClientChannel *)task->arg;
|
||||||
if (__sync_add_and_fetch(&channel->established, 0)) {
|
if (__sync_add_and_fetch(&channel->established, 0)) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"response from server %s:%u, unexpected cmd: "
|
"response from server %s:%u, unexpected cmd: "
|
||||||
"SETUP_CHANNEL_RESP, ignore it!",
|
"SETUP_CHANNEL_RESP, ignore it!",
|
||||||
__LINE__, task->server_ip, task->port);
|
__LINE__, formatted_ip, task->port);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,6 +325,7 @@ static inline int deal_report_req_receipt_response(struct fast_task_info *task)
|
||||||
IdempotencyClientChannel *channel;
|
IdempotencyClientChannel *channel;
|
||||||
IdempotencyClientReceipt *current;
|
IdempotencyClientReceipt *current;
|
||||||
IdempotencyClientReceipt *deleted;
|
IdempotencyClientReceipt *deleted;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
if ((result=receipt_expect_body_length(task, 0)) != 0) {
|
if ((result=receipt_expect_body_length(task, 0)) != 0) {
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -321,10 +333,11 @@ static inline int deal_report_req_receipt_response(struct fast_task_info *task)
|
||||||
|
|
||||||
channel = (IdempotencyClientChannel *)task->arg;
|
channel = (IdempotencyClientChannel *)task->arg;
|
||||||
if (channel->waiting_resp_qinfo.head == NULL) {
|
if (channel->waiting_resp_qinfo.head == NULL) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"response from server %s:%u, unexpect cmd: "
|
"response from server %s:%u, unexpect cmd: "
|
||||||
"REPORT_REQ_RECEIPT_RESP", __LINE__,
|
"REPORT_REQ_RECEIPT_RESP", __LINE__,
|
||||||
task->server_ip, task->port);
|
formatted_ip, task->port);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -346,6 +359,7 @@ static int receipt_deal_task(struct fast_task_info *task, const int stage)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
SFCommonProtoHeader *header;
|
SFCommonProtoHeader *header;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (stage == SF_NIO_STAGE_HANDSHAKE) {
|
if (stage == SF_NIO_STAGE_HANDSHAKE) {
|
||||||
|
|
@ -373,10 +387,11 @@ static int receipt_deal_task(struct fast_task_info *task, const int stage)
|
||||||
|
|
||||||
msg_len = SF_RECV_BODY_LENGTH(task);
|
msg_len = SF_RECV_BODY_LENGTH(task);
|
||||||
message = SF_PROTO_RECV_BODY(task);
|
message = SF_PROTO_RECV_BODY(task);
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"response from server %s:%u, cmd: %d (%s), "
|
"response from server %s:%u, cmd: %d (%s), "
|
||||||
"status: %d, error info: %.*s", __LINE__,
|
"status: %d, error info: %.*s", __LINE__,
|
||||||
task->server_ip, task->port, header->cmd,
|
formatted_ip, task->port, header->cmd,
|
||||||
sf_get_cmd_caption(header->cmd),
|
sf_get_cmd_caption(header->cmd),
|
||||||
result, msg_len, message);
|
result, msg_len, message);
|
||||||
break;
|
break;
|
||||||
|
|
@ -395,14 +410,18 @@ static int receipt_deal_task(struct fast_task_info *task, const int stage)
|
||||||
break;
|
break;
|
||||||
case SF_SERVICE_PROTO_CLOSE_CHANNEL_RESP:
|
case SF_SERVICE_PROTO_CLOSE_CHANNEL_RESP:
|
||||||
result = ECONNRESET; //force to close socket
|
result = ECONNRESET; //force to close socket
|
||||||
|
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logDebug("file: "__FILE__", line: %d, "
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"close channel to server %s:%u !!!",
|
"close channel to server %s:%u !!!",
|
||||||
__LINE__, task->server_ip, task->port);
|
__LINE__, formatted_ip, task->port);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"response from server %s:%u, unexpect cmd: %d (%s)",
|
"response from server %s:%u, unexpect cmd: %d (%s)",
|
||||||
__LINE__, task->server_ip, task->port, header->cmd,
|
__LINE__, formatted_ip, task->port, header->cmd,
|
||||||
sf_get_cmd_caption(header->cmd));
|
sf_get_cmd_caption(header->cmd));
|
||||||
result = EINVAL;
|
result = EINVAL;
|
||||||
break;
|
break;
|
||||||
|
|
@ -447,6 +466,7 @@ static void receipt_thread_close_idle_channel(
|
||||||
{
|
{
|
||||||
IdempotencyClientChannel *channel;
|
IdempotencyClientChannel *channel;
|
||||||
IdempotencyClientChannel *tmp;
|
IdempotencyClientChannel *tmp;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
fc_list_for_each_entry_safe(channel, tmp, &thread_ctx->head, dlink) {
|
fc_list_for_each_entry_safe(channel, tmp, &thread_ctx->head, dlink) {
|
||||||
if (channel->task->pending_send_count > 0) {
|
if (channel->task->pending_send_count > 0) {
|
||||||
|
|
@ -456,9 +476,12 @@ static void receipt_thread_close_idle_channel(
|
||||||
if (g_current_time - channel->last_report_time >
|
if (g_current_time - channel->last_report_time >
|
||||||
g_idempotency_client_cfg.channel_max_idle_time)
|
g_idempotency_client_cfg.channel_max_idle_time)
|
||||||
{
|
{
|
||||||
|
if (FC_LOG_BY_LEVEL(LOG_DEBUG)) {
|
||||||
|
format_ip_address(channel->task->server_ip, formatted_ip);
|
||||||
logDebug("file: "__FILE__", line: %d, "
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"close channel to server %s:%u because idle too long",
|
"close channel to server %s:%u because idle too long",
|
||||||
__LINE__, channel->task->server_ip, channel->task->port);
|
__LINE__, formatted_ip, channel->task->port);
|
||||||
|
}
|
||||||
close_channel_request(channel->task);
|
close_channel_request(channel->task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -405,6 +405,7 @@ static ConnectionInfo *get_leader_connection(SFConnectionManager *cm,
|
||||||
ConnectionInfo *conn;
|
ConnectionInfo *conn;
|
||||||
SFClientServerEntry leader;
|
SFClientServerEntry leader;
|
||||||
SFNetRetryIntervalContext net_retry_ctx;
|
SFNetRetryIntervalContext net_retry_ctx;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
int i;
|
int i;
|
||||||
int connect_fails;
|
int connect_fails;
|
||||||
|
|
||||||
|
|
@ -467,10 +468,11 @@ static ConnectionInfo *get_leader_connection(SFConnectionManager *cm,
|
||||||
connect.times, ++i, *err_no);
|
connect.times, ++i, *err_no);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
format_ip_address(server->group_addrs[cm->server_group_index].
|
||||||
|
address_array.addrs[0]->conn.ip_addr, formatted_ip);
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"%s get_leader_connection fail, server id: %d, %s:%u, errno: %d",
|
"%s get_leader_connection fail, server id: %d, %s:%u, errno: %d",
|
||||||
__LINE__, cm->module_name, server->id, server->group_addrs
|
__LINE__, cm->module_name, server->id, formatted_ip,
|
||||||
[cm->server_group_index]. address_array.addrs[0]->conn.ip_addr,
|
|
||||||
server->group_addrs[cm->server_group_index].address_array.
|
server->group_addrs[cm->server_group_index].address_array.
|
||||||
addrs[0]->conn.port, *err_no);
|
addrs[0]->conn.port, *err_no);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ extern SFContext g_sf_context;
|
||||||
#define SF_G_CONTINUE_FLAG g_sf_global_vars.continue_flag
|
#define SF_G_CONTINUE_FLAG g_sf_global_vars.continue_flag
|
||||||
#define SF_G_CONNECT_TIMEOUT g_sf_global_vars.net_buffer_cfg.connect_timeout
|
#define SF_G_CONNECT_TIMEOUT g_sf_global_vars.net_buffer_cfg.connect_timeout
|
||||||
#define SF_G_NETWORK_TIMEOUT g_sf_global_vars.net_buffer_cfg.network_timeout
|
#define SF_G_NETWORK_TIMEOUT g_sf_global_vars.net_buffer_cfg.network_timeout
|
||||||
#define SF_G_MAX_CONNECTIONS g_sf_global_vars.max_connections
|
#define SF_G_MAX_CONNECTIONS g_sf_global_vars.net_buffer_cfg.max_connections
|
||||||
#define SF_G_THREAD_STACK_SIZE g_sf_global_vars.thread_stack_size
|
#define SF_G_THREAD_STACK_SIZE g_sf_global_vars.thread_stack_size
|
||||||
#define SF_G_UP_TIME g_sf_global_vars.up_time
|
#define SF_G_UP_TIME g_sf_global_vars.up_time
|
||||||
|
|
||||||
|
|
|
||||||
22
src/sf_nio.c
22
src/sf_nio.c
|
|
@ -216,6 +216,7 @@ static int sf_client_connect_done(int sock, short event, void *arg)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
struct fast_task_info *task;
|
struct fast_task_info *task;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
task = (struct fast_task_info *)arg;
|
task = (struct fast_task_info *)arg;
|
||||||
if (task->canceled) {
|
if (task->canceled) {
|
||||||
|
|
@ -237,9 +238,10 @@ static int sf_client_connect_done(int sock, short event, void *arg)
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
if (SF_CTX->connect_need_log) {
|
if (SF_CTX->connect_need_log) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connect to server %s:%u fail, errno: %d, "
|
"connect to server %s:%u fail, errno: %d, "
|
||||||
"error info: %s", __LINE__, task->server_ip,
|
"error info: %s", __LINE__, formatted_ip,
|
||||||
task->port, result, STRERROR(result));
|
task->port, result, STRERROR(result));
|
||||||
}
|
}
|
||||||
ioevent_add_to_deleted_list(task);
|
ioevent_add_to_deleted_list(task);
|
||||||
|
|
@ -247,9 +249,10 @@ static int sf_client_connect_done(int sock, short event, void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SF_CTX->connect_need_log) {
|
if (SF_CTX->connect_need_log) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logInfo("file: "__FILE__", line: %d, "
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"connect to server %s:%u successfully",
|
"connect to server %s:%u successfully",
|
||||||
__LINE__, task->server_ip, task->port);
|
__LINE__, formatted_ip, task->port);
|
||||||
}
|
}
|
||||||
return SF_CTX->callbacks.deal_task(task, SF_NIO_STAGE_HANDSHAKE);
|
return SF_CTX->callbacks.deal_task(task, SF_NIO_STAGE_HANDSHAKE);
|
||||||
}
|
}
|
||||||
|
|
@ -270,6 +273,7 @@ int sf_socket_async_connect_server(struct fast_task_info *task)
|
||||||
static int sf_async_connect_server(struct fast_task_info *task)
|
static int sf_async_connect_server(struct fast_task_info *task)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
if ((result=task->handler->async_connect_server(task)) == EINPROGRESS) {
|
if ((result=task->handler->async_connect_server(task)) == EINPROGRESS) {
|
||||||
result = ioevent_set(task, task->thread_data, task->event.fd,
|
result = ioevent_set(task, task->thread_data, task->event.fd,
|
||||||
|
|
@ -291,17 +295,19 @@ static int sf_async_connect_server(struct fast_task_info *task)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SF_CTX->connect_need_log) {
|
if (SF_CTX->connect_need_log) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logInfo("file: "__FILE__", line: %d, "
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"connect to server %s:%u successfully",
|
"connect to server %s:%u successfully",
|
||||||
__LINE__, task->server_ip, task->port);
|
__LINE__, formatted_ip, task->port);
|
||||||
}
|
}
|
||||||
return SF_CTX->callbacks.deal_task(task, SF_NIO_STAGE_HANDSHAKE);
|
return SF_CTX->callbacks.deal_task(task, SF_NIO_STAGE_HANDSHAKE);
|
||||||
} else {
|
} else {
|
||||||
task->handler->close_connection(task);
|
task->handler->close_connection(task);
|
||||||
if (SF_CTX->connect_need_log) {
|
if (SF_CTX->connect_need_log) {
|
||||||
|
format_ip_address(task->server_ip, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"connect to server %s:%u fail, errno: %d, "
|
"connect to server %s:%u fail, errno: %d, "
|
||||||
"error info: %s", __LINE__, task->server_ip,
|
"error info: %s", __LINE__, formatted_ip,
|
||||||
task->port, result, STRERROR(result));
|
task->port, result, STRERROR(result));
|
||||||
}
|
}
|
||||||
return result > 0 ? -1 * result : result;
|
return result > 0 ? -1 * result : result;
|
||||||
|
|
@ -767,6 +773,7 @@ ssize_t sf_socket_recv_data(struct fast_task_info *task,
|
||||||
|
|
||||||
static int calc_iops_and_trigger_polling(struct fast_task_info *task)
|
static int calc_iops_and_trigger_polling(struct fast_task_info *task)
|
||||||
{
|
{
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
int time_distance;
|
int time_distance;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
|
@ -793,9 +800,10 @@ static int calc_iops_and_trigger_polling(struct fast_task_info *task)
|
||||||
fc_list_add_tail(&task->polling.dlink,
|
fc_list_add_tail(&task->polling.dlink,
|
||||||
&task->thread_data->polling_queue);
|
&task->thread_data->polling_queue);
|
||||||
|
|
||||||
|
format_ip_address(task->client_ip, formatted_ip);
|
||||||
logInfo("file: "__FILE__", line: %d, client: %s:%u, "
|
logInfo("file: "__FILE__", line: %d, client: %s:%u, "
|
||||||
"trigger polling iops: %"PRId64, __LINE__,
|
"trigger polling iops: %"PRId64, __LINE__,
|
||||||
task->client_ip, task->port, (task->req_count -
|
formatted_ip, task->port, (task->req_count -
|
||||||
task->polling.last_req_count) / time_distance);
|
task->polling.last_req_count) / time_distance);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -813,6 +821,7 @@ static int calc_iops_and_trigger_polling(struct fast_task_info *task)
|
||||||
|
|
||||||
static int calc_iops_and_remove_polling(struct fast_task_info *task)
|
static int calc_iops_and_remove_polling(struct fast_task_info *task)
|
||||||
{
|
{
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
int time_distance;
|
int time_distance;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
|
@ -835,9 +844,10 @@ static int calc_iops_and_remove_polling(struct fast_task_info *task)
|
||||||
result = sf_ioevent_add(task, (IOEventCallback)
|
result = sf_ioevent_add(task, (IOEventCallback)
|
||||||
sf_client_sock_read, SF_CTX->net_buffer_cfg.network_timeout);
|
sf_client_sock_read, SF_CTX->net_buffer_cfg.network_timeout);
|
||||||
|
|
||||||
|
format_ip_address(task->client_ip, formatted_ip);
|
||||||
logInfo("file: "__FILE__", line: %d, client: %s:%u, "
|
logInfo("file: "__FILE__", line: %d, client: %s:%u, "
|
||||||
"remove polling iops: %"PRId64, __LINE__,
|
"remove polling iops: %"PRId64, __LINE__,
|
||||||
task->client_ip, task->port, (task->req_count -
|
formatted_ip, task->port, (task->req_count -
|
||||||
task->polling.last_req_count) / time_distance);
|
task->polling.last_req_count) / time_distance);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include "fastcommon/shared_func.h"
|
|
||||||
#include "sf_util.h"
|
#include "sf_util.h"
|
||||||
#include "sf_nio.h"
|
#include "sf_nio.h"
|
||||||
#include "sf_proto.h"
|
#include "sf_proto.h"
|
||||||
|
|
@ -29,14 +27,16 @@ static int64_t log_slower_than_us = 0;
|
||||||
int sf_proto_set_body_length(struct fast_task_info *task)
|
int sf_proto_set_body_length(struct fast_task_info *task)
|
||||||
{
|
{
|
||||||
SFCommonProtoHeader *header;
|
SFCommonProtoHeader *header;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
header = (SFCommonProtoHeader *)task->recv.ptr->data;
|
header = (SFCommonProtoHeader *)task->recv.ptr->data;
|
||||||
if (!SF_PROTO_CHECK_MAGIC(header->magic)) {
|
if (!SF_PROTO_CHECK_MAGIC(header->magic)) {
|
||||||
|
format_ip_address(task->client_ip, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"%s peer %s:%u, magic "SF_PROTO_MAGIC_FORMAT" is invalid, "
|
"%s peer %s:%u, magic "SF_PROTO_MAGIC_FORMAT" is invalid, "
|
||||||
"expect: "SF_PROTO_MAGIC_FORMAT", cmd: %d, body length: %d",
|
"expect: "SF_PROTO_MAGIC_FORMAT", cmd: %d, body length: %d",
|
||||||
__LINE__, (task->handler != NULL ? task->handler->fh->ctx->
|
__LINE__, (task->handler != NULL ? task->handler->fh->ctx->
|
||||||
name : ""), task->client_ip, task->port,
|
name : ""), formatted_ip, task->port,
|
||||||
SF_PROTO_MAGIC_PARAMS(header->magic),
|
SF_PROTO_MAGIC_PARAMS(header->magic),
|
||||||
SF_PROTO_MAGIC_EXPECT_PARAMS, header->cmd,
|
SF_PROTO_MAGIC_EXPECT_PARAMS, header->cmd,
|
||||||
buff2int(header->body_len));
|
buff2int(header->body_len));
|
||||||
|
|
@ -456,14 +456,17 @@ const char *sf_get_cmd_caption(const int cmd)
|
||||||
int sf_proto_deal_ack(struct fast_task_info *task,
|
int sf_proto_deal_ack(struct fast_task_info *task,
|
||||||
SFRequestInfo *request, SFResponseInfo *response)
|
SFRequestInfo *request, SFResponseInfo *response)
|
||||||
{
|
{
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
if (request->header.status != 0) {
|
if (request->header.status != 0) {
|
||||||
if (request->header.body_len > 0) {
|
if (request->header.body_len > 0) {
|
||||||
int remain_size;
|
int remain_size;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
format_ip_address(task->client_ip, formatted_ip);
|
||||||
response->error.length = sprintf(response->error.message,
|
response->error.length = sprintf(response->error.message,
|
||||||
"message from peer %s:%u => ",
|
"message from peer %s:%u => ",
|
||||||
task->client_ip, task->port);
|
formatted_ip, task->port);
|
||||||
remain_size = sizeof(response->error.message) -
|
remain_size = sizeof(response->error.message) -
|
||||||
response->error.length;
|
response->error.length;
|
||||||
if (request->header.body_len >= remain_size) {
|
if (request->header.body_len >= remain_size) {
|
||||||
|
|
@ -525,6 +528,7 @@ int sf_proto_get_group_servers(ConnectionInfo *conn,
|
||||||
char out_buff[sizeof(SFCommonProtoHeader) +
|
char out_buff[sizeof(SFCommonProtoHeader) +
|
||||||
sizeof(SFProtoGetGroupServersReq)];
|
sizeof(SFProtoGetGroupServersReq)];
|
||||||
char in_buff[1024];
|
char in_buff[1024];
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
SFCommonProtoHeader *header;
|
SFCommonProtoHeader *header;
|
||||||
SFProtoGetGroupServersReq *req;
|
SFProtoGetGroupServersReq *req;
|
||||||
SFProtoGetGroupServersRespBodyHeader *body_header;
|
SFProtoGetGroupServersRespBodyHeader *body_header;
|
||||||
|
|
@ -552,9 +556,10 @@ int sf_proto_get_group_servers(ConnectionInfo *conn,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body_len < sizeof(SFProtoGetGroupServersRespBodyHeader)) {
|
if (body_len < sizeof(SFProtoGetGroupServersRespBodyHeader)) {
|
||||||
|
format_ip_address(conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"server %s:%d response body length: %d < %d",
|
"server %s:%u response body length: %d < %d",
|
||||||
__LINE__, conn->ip_addr, conn->port, body_len,
|
__LINE__, formatted_ip, conn->port, body_len,
|
||||||
(int)sizeof(SFProtoGetGroupServersRespBodyHeader));
|
(int)sizeof(SFProtoGetGroupServersRespBodyHeader));
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
@ -562,15 +567,17 @@ int sf_proto_get_group_servers(ConnectionInfo *conn,
|
||||||
body_header = (SFProtoGetGroupServersRespBodyHeader *)in_buff;
|
body_header = (SFProtoGetGroupServersRespBodyHeader *)in_buff;
|
||||||
count = buff2int(body_header->count);
|
count = buff2int(body_header->count);
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
|
format_ip_address(conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"server %s:%d response server count: %d <= 0",
|
"server %s:%u response server count: %d <= 0",
|
||||||
__LINE__, conn->ip_addr, conn->port, count);
|
__LINE__, formatted_ip, conn->port, count);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
if (count > sarray->alloc) {
|
if (count > sarray->alloc) {
|
||||||
|
format_ip_address(conn->ip_addr, formatted_ip);
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"server %s:%d response server count: %d is too large, "
|
"server %s:%u response server count: %d is too large, "
|
||||||
"exceeds %d", __LINE__, conn->ip_addr, conn->port,
|
"exceeds %d", __LINE__, formatted_ip, conn->port,
|
||||||
count, sarray->alloc);
|
count, sarray->alloc);
|
||||||
return EOVERFLOW;
|
return EOVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
@ -630,6 +637,7 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
|
||||||
int r;
|
int r;
|
||||||
int64_t time_used;
|
int64_t time_used;
|
||||||
int log_level;
|
int log_level;
|
||||||
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
char time_buff[32];
|
char time_buff[32];
|
||||||
|
|
||||||
if (ctx->log_level != LOG_NOTHING && ctx->response.error.length > 0) {
|
if (ctx->log_level != LOG_NOTHING && ctx->response.error.length > 0) {
|
||||||
|
|
@ -637,7 +645,8 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
|
||||||
"file: "__FILE__", line: %d, %s "
|
"file: "__FILE__", line: %d, %s "
|
||||||
"peer %s:%u, cmd: %d (%s), req body length: %d, "
|
"peer %s:%u, cmd: %d (%s), req body length: %d, "
|
||||||
"resp status: %d, %s", __LINE__, service_name,
|
"resp status: %d, %s", __LINE__, service_name,
|
||||||
task->client_ip, task->port, ctx->request.header.cmd,
|
format_ip_address(task->client_ip, formatted_ip),
|
||||||
|
task->port, ctx->request.header.cmd,
|
||||||
GET_CMD_CAPTION(ctx->request.header.cmd),
|
GET_CMD_CAPTION(ctx->request.header.cmd),
|
||||||
ctx->request.header.body_len, ctx->response.header.status,
|
ctx->request.header.body_len, ctx->response.header.status,
|
||||||
ctx->response.error.message);
|
ctx->response.error.message);
|
||||||
|
|
@ -650,7 +659,8 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
|
||||||
log_it_ex(&g_log_context, log_level, "file: "__FILE__", line: %d, "
|
log_it_ex(&g_log_context, log_level, "file: "__FILE__", line: %d, "
|
||||||
"%s client %s:%u, req cmd: %d (%s), req body_len: %d, "
|
"%s client %s:%u, req cmd: %d (%s), req body_len: %d, "
|
||||||
"resp status: %d, time used: %s us", __LINE__, service_name,
|
"resp status: %d, time used: %s us", __LINE__, service_name,
|
||||||
task->client_ip, task->port, ctx->request.header.cmd,
|
format_ip_address(task->client_ip, formatted_ip),
|
||||||
|
task->port, ctx->request.header.cmd,
|
||||||
GET_CMD_CAPTION(ctx->request.header.cmd),
|
GET_CMD_CAPTION(ctx->request.header.cmd),
|
||||||
ctx->request.header.body_len, ctx->response.header.status,
|
ctx->request.header.body_len, ctx->response.header.status,
|
||||||
long_to_comma_str(time_used, time_buff));
|
long_to_comma_str(time_used, time_buff));
|
||||||
|
|
@ -691,8 +701,9 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
|
||||||
blen = sprintf(buff, "timed used: %s us, %s client %s:%u, "
|
blen = sprintf(buff, "timed used: %s us, %s client %s:%u, "
|
||||||
"req cmd: %d (%s), req body len: %d, resp cmd: %d (%s), "
|
"req cmd: %d (%s), req body len: %d, resp cmd: %d (%s), "
|
||||||
"status: %d, resp body len: %d", long_to_comma_str(time_used,
|
"status: %d, resp body len: %d", long_to_comma_str(time_used,
|
||||||
time_buff), service_name, task->client_ip, task->port, ctx->
|
time_buff), service_name, format_ip_address(task->
|
||||||
request.header.cmd, GET_CMD_CAPTION(ctx->request.header.cmd),
|
client_ip, formatted_ip), task->port, ctx->request.
|
||||||
|
header.cmd, GET_CMD_CAPTION(ctx->request.header.cmd),
|
||||||
ctx->request.header.body_len, ctx->response.header.cmd,
|
ctx->request.header.body_len, ctx->response.header.cmd,
|
||||||
GET_CMD_CAPTION(ctx->response.header.cmd),
|
GET_CMD_CAPTION(ctx->response.header.cmd),
|
||||||
ctx->response.header.status, ctx->response.header.body_len);
|
ctx->response.header.status, ctx->response.header.body_len);
|
||||||
|
|
@ -705,7 +716,8 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
|
||||||
"%s client %s:%u, req cmd: %d (%s), req body_len: %d, "
|
"%s client %s:%u, req cmd: %d (%s), req body_len: %d, "
|
||||||
"resp cmd: %d (%s), status: %d, resp body_len: %d, "
|
"resp cmd: %d (%s), status: %d, resp body_len: %d, "
|
||||||
"time used: %s us", __LINE__, service_name,
|
"time used: %s us", __LINE__, service_name,
|
||||||
task->client_ip, task->port, ctx->request.header.cmd,
|
format_ip_address(task->client_ip, formatted_ip),
|
||||||
|
task->port, ctx->request.header.cmd,
|
||||||
GET_CMD_CAPTION(ctx->request.header.cmd),
|
GET_CMD_CAPTION(ctx->request.header.cmd),
|
||||||
ctx->request.header.body_len, ctx->response.header.cmd,
|
ctx->request.header.body_len, ctx->response.header.cmd,
|
||||||
GET_CMD_CAPTION(ctx->response.header.cmd),
|
GET_CMD_CAPTION(ctx->response.header.cmd),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue