sf_set_read_event just skipped when use_io_uring is true
parent
263171c4fe
commit
cf0950ea62
|
|
@ -174,7 +174,6 @@ static struct fast_task_info *alloc_channel_task(IdempotencyClientChannel
|
||||||
*channel, const uint32_t hash_code, const FCCommunicationType comm_type,
|
*channel, const uint32_t hash_code, const FCCommunicationType comm_type,
|
||||||
const char *server_ip, const uint16_t port, int *err_no)
|
const char *server_ip, const uint16_t port, int *err_no)
|
||||||
{
|
{
|
||||||
int len;
|
|
||||||
struct fast_task_info *task;
|
struct fast_task_info *task;
|
||||||
SFAddressFamilyHandler *fh;
|
SFAddressFamilyHandler *fh;
|
||||||
SFNetworkHandler *handler;
|
SFNetworkHandler *handler;
|
||||||
|
|
@ -195,12 +194,7 @@ static struct fast_task_info *alloc_channel_task(IdempotencyClientChannel
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(server_ip);
|
fc_safe_strcpy(task->server_ip, server_ip);
|
||||||
if (len >= sizeof(task->server_ip)) {
|
|
||||||
len = sizeof(task->server_ip) - 1;
|
|
||||||
}
|
|
||||||
memcpy(task->server_ip, server_ip, len);
|
|
||||||
*(task->server_ip + len) = '\0';
|
|
||||||
task->port = port;
|
task->port = port;
|
||||||
task->arg = channel;
|
task->arg = channel;
|
||||||
task->thread_data = g_sf_context.thread_data +
|
task->thread_data = g_sf_context.thread_data +
|
||||||
|
|
@ -209,7 +203,8 @@ static struct fast_task_info *alloc_channel_task(IdempotencyClientChannel
|
||||||
channel->last_connect_time = g_current_time;
|
channel->last_connect_time = g_current_time;
|
||||||
if ((*err_no=sf_nio_notify(task, SF_NIO_STAGE_CONNECT)) != 0) {
|
if ((*err_no=sf_nio_notify(task, SF_NIO_STAGE_CONNECT)) != 0) {
|
||||||
channel->in_ioevent = 0; //rollback
|
channel->in_ioevent = 0; //rollback
|
||||||
sf_release_task(task);
|
__sync_sub_and_fetch(&task->reffer_count, 1);
|
||||||
|
free_queue_push(task);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return task;
|
return task;
|
||||||
|
|
@ -221,6 +216,12 @@ int idempotency_client_channel_check_reconnect(
|
||||||
int result;
|
int result;
|
||||||
char formatted_ip[FORMATTED_IP_SIZE];
|
char formatted_ip[FORMATTED_IP_SIZE];
|
||||||
|
|
||||||
|
#if IOEVENT_USE_URING
|
||||||
|
if (FC_ATOMIC_GET(channel->task->reffer_count) > 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
@ -237,6 +238,9 @@ int idempotency_client_channel_check_reconnect(
|
||||||
formatted_ip, channel->task->port);
|
formatted_ip, channel->task->port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (channel->task->event.fd >= 0) {
|
||||||
|
channel->task->handler->close_connection(channel->task);
|
||||||
|
}
|
||||||
__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) {
|
||||||
channel->last_connect_time = g_current_time;
|
channel->last_connect_time = g_current_time;
|
||||||
|
|
@ -348,8 +352,8 @@ int idempotency_client_channel_push(struct idempotency_client_channel *channel,
|
||||||
receipt->req_id = req_id;
|
receipt->req_id = req_id;
|
||||||
fc_queue_push_ex(&channel->queue, receipt, ¬ify);
|
fc_queue_push_ex(&channel->queue, receipt, ¬ify);
|
||||||
if (notify) {
|
if (notify) {
|
||||||
if (__sync_add_and_fetch(&channel->in_ioevent, 0)) {
|
if (FC_ATOMIC_GET(channel->in_ioevent)) {
|
||||||
if (__sync_add_and_fetch(&channel->established, 0)) {
|
if (FC_ATOMIC_GET(channel->established)) {
|
||||||
sf_nio_notify(channel->task, SF_NIO_STAGE_CONTINUE);
|
sf_nio_notify(channel->task, SF_NIO_STAGE_CONTINUE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,13 @@ static inline void idempotency_client_channel_set_id_key(
|
||||||
static inline int idempotency_client_channel_check_wait_ex(
|
static inline int idempotency_client_channel_check_wait_ex(
|
||||||
struct idempotency_client_channel *channel, const int timeout)
|
struct idempotency_client_channel *channel, const int timeout)
|
||||||
{
|
{
|
||||||
if (__sync_add_and_fetch(&channel->established, 0)) {
|
if (FC_ATOMIC_GET(channel->established)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
idempotency_client_channel_check_reconnect(channel);
|
idempotency_client_channel_check_reconnect(channel);
|
||||||
lcp_timedwait_sec(&channel->lcp, timeout);
|
lcp_timedwait_sec(&channel->lcp, timeout);
|
||||||
if (__sync_add_and_fetch(&channel->established, 0)) {
|
if (FC_ATOMIC_GET(channel->established)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,10 @@ static IdempotencyReceiptGlobalVars receipt_global_vars;
|
||||||
|
|
||||||
static int receipt_init_task(struct fast_task_info *task, void *arg)
|
static int receipt_init_task(struct fast_task_info *task, void *arg)
|
||||||
{
|
{
|
||||||
|
#if IOEVENT_USE_URING
|
||||||
|
FC_URING_IS_CLIENT(task) = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (RDMA_INIT_CONNECTION != NULL) {
|
if (RDMA_INIT_CONNECTION != NULL) {
|
||||||
return RDMA_INIT_CONNECTION(task, arg);
|
return RDMA_INIT_CONNECTION(task, arg);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -92,7 +96,6 @@ static void receipt_task_finish_cleanup(struct fast_task_info *task)
|
||||||
|
|
||||||
if (task->event.fd >= 0) {
|
if (task->event.fd >= 0) {
|
||||||
sf_task_detach_thread(task);
|
sf_task_detach_thread(task);
|
||||||
task->handler->close_connection(task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sf_nio_reset_task_length(task);
|
sf_nio_reset_task_length(task);
|
||||||
|
|
@ -282,7 +285,7 @@ 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 (FC_ATOMIC_GET(channel->established)) {
|
||||||
format_ip_address(task->server_ip, formatted_ip);
|
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: "
|
||||||
|
|
|
||||||
40
src/sf_nio.c
40
src/sf_nio.c
|
|
@ -269,6 +269,12 @@ static inline int set_read_event(struct fast_task_info *task)
|
||||||
|
|
||||||
int sf_set_read_event(struct fast_task_info *task)
|
int sf_set_read_event(struct fast_task_info *task)
|
||||||
{
|
{
|
||||||
|
#if IOEVENT_USE_URING
|
||||||
|
if (task->handler->use_io_uring) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
task->recv.ptr->offset = 0;
|
task->recv.ptr->offset = 0;
|
||||||
task->recv.ptr->length = 0;
|
task->recv.ptr->length = 0;
|
||||||
task->nio_stages.current = SF_NIO_STAGE_RECV;
|
task->nio_stages.current = SF_NIO_STAGE_RECV;
|
||||||
|
|
@ -561,7 +567,7 @@ int sf_nio_notify(struct fast_task_info *task, const int stage)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : EIO;
|
result = errno != 0 ? errno : EIO;
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"write eventfd %d fail, errno: %d, error info: %s",
|
"write to fd %d fail, errno: %d, error info: %s",
|
||||||
__LINE__, FC_NOTIFY_WRITE_FD(task->thread_data),
|
__LINE__, FC_NOTIFY_WRITE_FD(task->thread_data),
|
||||||
result, STRERROR(result));
|
result, STRERROR(result));
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -589,26 +595,32 @@ static inline void deal_notified_task(struct fast_task_info *task,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sf_recv_notify_read(int sock, short event, void *arg)
|
void sf_recv_notify_read(int fd, short event, void *arg)
|
||||||
{
|
{
|
||||||
int64_t n;
|
int64_t n;
|
||||||
int stage;
|
int stage;
|
||||||
struct nio_thread_data *thread_data;
|
struct ioevent_notify_entry *notify_entry;
|
||||||
struct fast_task_info *task;
|
struct fast_task_info *task;
|
||||||
struct fast_task_info *current;
|
struct fast_task_info *current;
|
||||||
|
|
||||||
thread_data = ((struct ioevent_notify_entry *)arg)->thread_data;
|
notify_entry = (struct ioevent_notify_entry *)arg;
|
||||||
if (read(sock, &n, sizeof(n)) < 0) {
|
if (read(fd, &n, sizeof(n)) < 0) {
|
||||||
|
#if IOEVENT_USE_URING
|
||||||
|
if (errno == EAGAIN) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"read from eventfd %d fail, errno: %d, error info: %s",
|
"read from fd %d fail, errno: %d, error info: %s",
|
||||||
__LINE__, sock, errno, STRERROR(errno));
|
__LINE__, fd, errno, STRERROR(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
PTHREAD_MUTEX_LOCK(&thread_data->waiting_queue.lock);
|
PTHREAD_MUTEX_LOCK(¬ify_entry->thread_data->waiting_queue.lock);
|
||||||
current = thread_data->waiting_queue.head;
|
current = notify_entry->thread_data->waiting_queue.head;
|
||||||
thread_data->waiting_queue.head = NULL;
|
notify_entry->thread_data->waiting_queue.head = NULL;
|
||||||
thread_data->waiting_queue.tail = NULL;
|
notify_entry->thread_data->waiting_queue.tail = NULL;
|
||||||
PTHREAD_MUTEX_UNLOCK(&thread_data->waiting_queue.lock);
|
PTHREAD_MUTEX_UNLOCK(¬ify_entry->thread_data->waiting_queue.lock);
|
||||||
|
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
task = current;
|
task = current;
|
||||||
|
|
@ -772,9 +784,9 @@ ssize_t sf_socket_send_data(struct fast_task_info *task,
|
||||||
}
|
}
|
||||||
} else if (bytes == 0) {
|
} else if (bytes == 0) {
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"client ip: %s, sock: %d, task length: %d, offset: %d, "
|
"client ip: %s, task length: %d, offset: %d, "
|
||||||
"send failed, connection disconnected", __LINE__,
|
"send failed, connection disconnected", __LINE__,
|
||||||
task->client_ip, task->event.fd, task->send.ptr->length,
|
task->client_ip, task->send.ptr->length,
|
||||||
task->send.ptr->offset);
|
task->send.ptr->offset);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -490,7 +490,9 @@ struct fast_task_info *sf_socket_accept_connection(SFListener *listener)
|
||||||
}
|
}
|
||||||
FC_SET_CLOEXEC(incomesock);
|
FC_SET_CLOEXEC(incomesock);
|
||||||
|
|
||||||
if ((task=sf_alloc_init_task(listener->handler, incomesock)) == NULL) {
|
if ((task=sf_alloc_init_server_task(listener->handler,
|
||||||
|
incomesock)) == NULL)
|
||||||
|
{
|
||||||
close(incomesock);
|
close(incomesock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -169,12 +169,42 @@ static inline struct fast_task_info *sf_alloc_init_task_ex(
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define sf_hold_task_ex(task, inc_count) \
|
#define sf_hold_task_ex(task, inc_count) fc_hold_task_ex(task, inc_count)
|
||||||
fc_hold_task_ex(task, inc_count)
|
|
||||||
#define sf_hold_task(task) fc_hold_task(task)
|
#define sf_hold_task(task) fc_hold_task(task)
|
||||||
|
|
||||||
#define sf_alloc_init_task(handler, fd) sf_alloc_init_task_ex(handler, fd, 1)
|
#define sf_alloc_init_task(handler, fd) sf_alloc_init_task_ex(handler, fd, 1)
|
||||||
|
|
||||||
|
static inline struct fast_task_info *sf_alloc_init_server_task(
|
||||||
|
SFNetworkHandler *handler, const int fd)
|
||||||
|
{
|
||||||
|
const int reffer_count = 1;
|
||||||
|
struct fast_task_info *task;
|
||||||
|
|
||||||
|
if ((task=sf_alloc_init_task_ex(handler, fd, reffer_count)) != NULL) {
|
||||||
|
#if IOEVENT_USE_URING
|
||||||
|
FC_URING_IS_CLIENT(task) = false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct fast_task_info *sf_alloc_init_client_task(
|
||||||
|
SFNetworkHandler *handler)
|
||||||
|
{
|
||||||
|
const int fd = -1;
|
||||||
|
const int reffer_count = 1;
|
||||||
|
struct fast_task_info *task;
|
||||||
|
|
||||||
|
if ((task=sf_alloc_init_task_ex(handler, fd, reffer_count)) != NULL) {
|
||||||
|
#if IOEVENT_USE_URING
|
||||||
|
FC_URING_IS_CLIENT(task) = true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void sf_release_task(struct fast_task_info *task)
|
static inline void sf_release_task(struct fast_task_info *task)
|
||||||
{
|
{
|
||||||
if (__sync_sub_and_fetch(&task->reffer_count, 1) == 0) {
|
if (__sync_sub_and_fetch(&task->reffer_count, 1) == 0) {
|
||||||
|
|
@ -194,6 +224,7 @@ static inline void sf_release_task(struct fast_task_info *task)
|
||||||
connection_stat.current_count, 1);
|
connection_stat.current_count, 1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
free_queue_push(task);
|
free_queue_push(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -269,6 +300,19 @@ static inline SFNetworkHandler *sf_get_rdma_network_handler3(
|
||||||
return sf_get_rdma_network_handler(sf_context3);
|
return sf_get_rdma_network_handler(sf_context3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool sf_get_double_buffers_flag(FCServerGroupInfo *server_group)
|
||||||
|
{
|
||||||
|
if (server_group->comm_type == fc_comm_type_sock) {
|
||||||
|
#if IOEVENT_USE_URING
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
} else { //RDMA
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue