sf_binlog_writer_rotate_file can skip empty file

use_iouring
YuQing 2025-02-10 18:34:04 +08:00
parent e9e33883bf
commit 14a783fd6f
2 changed files with 21 additions and 8 deletions

View File

@ -168,6 +168,7 @@ static int deal_binlog_records(SFBinlogWriterThread *thread,
SFBinlogWriterBuffer *wb_head, uint32_t *last_timestamp) SFBinlogWriterBuffer *wb_head, uint32_t *last_timestamp)
{ {
int result; int result;
bool skip_empty_file;
SFBinlogWriterBuffer *wbuffer; SFBinlogWriterBuffer *wbuffer;
SFBinlogWriterBuffer *current; SFBinlogWriterBuffer *current;
@ -196,12 +197,15 @@ static int deal_binlog_records(SFBinlogWriterThread *thread,
thread->mblock, current); thread->mblock, current);
break; break;
case SF_BINLOG_BUFFER_TYPE_ROTATE_FILE: case SF_BINLOG_BUFFER_TYPE_ROTATE_FILE:
skip_empty_file = current->version.first;
if (!(skip_empty_file && current->writer->fw.file.size == 0)) {
if ((result=sf_file_writer_set_binlog_write_index(&current-> if ((result=sf_file_writer_set_binlog_write_index(&current->
writer->fw, current->writer->fw.binlog. writer->fw, current->writer->fw.binlog.
last_index + 1)) != 0) last_index + 1)) != 0)
{ {
return result; return result;
} }
}
fast_mblock_free_object(&current->writer-> fast_mblock_free_object(&current->writer->
thread->mblock, current); thread->mblock, current);
break; break;
@ -623,10 +627,12 @@ int sf_binlog_writer_change_write_index(SFBinlogWriterInfo *writer,
SF_BINLOG_BUFFER_TYPE_SET_WRITE_INDEX, write_index); SF_BINLOG_BUFFER_TYPE_SET_WRITE_INDEX, write_index);
} }
int sf_binlog_writer_rotate_file(SFBinlogWriterInfo *writer) int sf_binlog_writer_rotate_file_ex(SFBinlogWriterInfo *writer,
const bool skip_empty_file)
{ {
return sf_binlog_writer_push_directive(writer, return sf_binlog_writer_push_directive(writer,
SF_BINLOG_BUFFER_TYPE_ROTATE_FILE, 0); SF_BINLOG_BUFFER_TYPE_ROTATE_FILE,
skip_empty_file ? 1 : 0);
} }
int sf_binlog_writer_flush_file(SFBinlogWriterInfo *writer) int sf_binlog_writer_flush_file(SFBinlogWriterInfo *writer)

View File

@ -235,7 +235,14 @@ static inline int sf_binlog_writer_get_thread_waiting_count(
return waiting_count; return waiting_count;
} }
int sf_binlog_writer_rotate_file(SFBinlogWriterInfo *writer); int sf_binlog_writer_rotate_file_ex(SFBinlogWriterInfo *writer,
const bool skip_empty_file);
static inline int sf_binlog_writer_rotate_file(SFBinlogWriterInfo *writer)
{
const bool skip_empty_file = false;
return sf_binlog_writer_rotate_file_ex(writer, skip_empty_file);
}
int sf_binlog_writer_flush_file(SFBinlogWriterInfo *writer); int sf_binlog_writer_flush_file(SFBinlogWriterInfo *writer);