sf_nio_notify more graceful
parent
cce11f56cb
commit
4a92e31272
|
|
@ -144,9 +144,9 @@ static int open_next_binlog(SFBinlogWriterInfo *writer)
|
||||||
char bak_filename[PATH_MAX];
|
char bak_filename[PATH_MAX];
|
||||||
char date_str[32];
|
char date_str[32];
|
||||||
|
|
||||||
sprintf(bak_filename, "%s.%s", writer->file.name,
|
snprintf(bak_filename, sizeof(bak_filename), "%s.%s",
|
||||||
formatDatetime(g_current_time, "%Y%m%d%H%M%S",
|
writer->file.name, formatDatetime(g_current_time,
|
||||||
date_str, sizeof(date_str)));
|
"%Y%m%d%H%M%S", date_str, sizeof(date_str)));
|
||||||
if (rename(writer->file.name, bak_filename) == 0) {
|
if (rename(writer->file.name, bak_filename) == 0) {
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"binlog file %s exist, rename to %s",
|
"binlog file %s exist, rename to %s",
|
||||||
|
|
|
||||||
11
src/sf_nio.c
11
src/sf_nio.c
|
|
@ -304,6 +304,7 @@ int sf_nio_notify(struct fast_task_info *task, const int stage)
|
||||||
{
|
{
|
||||||
int64_t n;
|
int64_t n;
|
||||||
int result;
|
int result;
|
||||||
|
int old_stage;
|
||||||
bool notify;
|
bool notify;
|
||||||
|
|
||||||
if (__sync_add_and_fetch(&task->canceled, 0)) {
|
if (__sync_add_and_fetch(&task->canceled, 0)) {
|
||||||
|
|
@ -321,19 +322,19 @@ int sf_nio_notify(struct fast_task_info *task, const int stage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__sync_bool_compare_and_swap(&task->nio_stages.notify,
|
while (!__sync_bool_compare_and_swap(&task->nio_stages.notify,
|
||||||
SF_NIO_STAGE_NONE, stage))
|
SF_NIO_STAGE_NONE, stage))
|
||||||
{
|
{
|
||||||
if (__sync_fetch_and_add(&task->nio_stages.notify, 0) == stage) {
|
old_stage = __sync_fetch_and_add(&task->nio_stages.notify, 0);
|
||||||
|
if (old_stage == stage) {
|
||||||
logDebug("file: "__FILE__", line: %d, "
|
logDebug("file: "__FILE__", line: %d, "
|
||||||
"current stage: %d equals to the target, skip set",
|
"current stage: %d equals to the target, skip set",
|
||||||
__LINE__, stage);
|
__LINE__, stage);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else if (old_stage != SF_NIO_STAGE_NONE) {
|
||||||
logWarning("file: "__FILE__", line: %d, "
|
logWarning("file: "__FILE__", line: %d, "
|
||||||
"current stage: %d != %d, skip set stage to %d",
|
"current stage: %d != %d, skip set stage to %d",
|
||||||
__LINE__, __sync_fetch_and_add(&task->nio_stages.notify, 0),
|
__LINE__, old_stage, SF_NIO_STAGE_NONE, stage);
|
||||||
SF_NIO_STAGE_NONE, stage);
|
|
||||||
return EAGAIN;
|
return EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ int sf_proto_set_body_length(struct fast_task_info *task)
|
||||||
header = (SFCommonProtoHeader *)task->data;
|
header = (SFCommonProtoHeader *)task->data;
|
||||||
if (!SF_PROTO_CHECK_MAGIC(header->magic)) {
|
if (!SF_PROTO_CHECK_MAGIC(header->magic)) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"client ip: %s, magic "SF_PROTO_MAGIC_FORMAT
|
"peer %s:%u, magic "SF_PROTO_MAGIC_FORMAT
|
||||||
" is invalid, expect: "SF_PROTO_MAGIC_FORMAT,
|
" is invalid, expect: "SF_PROTO_MAGIC_FORMAT,
|
||||||
__LINE__, task->client_ip,
|
__LINE__, task->client_ip, task->port,
|
||||||
SF_PROTO_MAGIC_PARAMS(header->magic),
|
SF_PROTO_MAGIC_PARAMS(header->magic),
|
||||||
SF_PROTO_MAGIC_EXPECT_PARAMS);
|
SF_PROTO_MAGIC_EXPECT_PARAMS);
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue