From 3815c0b2ce5944b65d80fabfab93f8fd601af81a Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Sat, 15 Mar 2025 10:10:01 +0800 Subject: [PATCH] export function sf_file_writer_direct_write --- src/sf_file_writer.c | 8 ++++---- src/sf_file_writer.h | 10 ++++++++++ src/sf_types.h | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/sf_file_writer.c b/src/sf_file_writer.c index 975cba5..de8f8d7 100644 --- a/src/sf_file_writer.c +++ b/src/sf_file_writer.c @@ -257,7 +257,7 @@ static int do_write_to_file(SFFileWriterInfo *writer, return 0; } -static int check_write_to_file(SFFileWriterInfo *writer, +int sf_file_writer_direct_write(SFFileWriterInfo *writer, char *buff, const int len) { int result; @@ -293,7 +293,7 @@ int sf_file_writer_flush(SFFileWriterInfo *writer) return 0; } - if ((result=check_write_to_file(writer, writer-> + if ((result=sf_file_writer_direct_write(writer, writer-> binlog_buffer.buff, len)) == 0) { if (writer->flags & SF_FILE_WRITER_FLAGS_WANT_DONE_VERSION) { @@ -359,8 +359,8 @@ int sf_file_writer_deal_versioned_buffer(SFFileWriterInfo *writer, } } - if ((result=check_write_to_file(writer, buffer->buff, - buffer->length)) == 0) + if ((result=sf_file_writer_direct_write(writer, buffer-> + buff, buffer->length)) == 0) { if (writer->flags & SF_FILE_WRITER_FLAGS_WANT_DONE_VERSION) { writer->last_versions.pending = version; diff --git a/src/sf_file_writer.h b/src/sf_file_writer.h index bbb4ae4..28b70d1 100644 --- a/src/sf_file_writer.h +++ b/src/sf_file_writer.h @@ -84,6 +84,9 @@ int sf_file_writer_init(SFFileWriterInfo *writer, const char *data_path, void sf_file_writer_destroy(SFFileWriterInfo *writer); +int sf_file_writer_direct_write(SFFileWriterInfo *writer, + char *buff, const int len); + int sf_file_writer_deal_versioned_buffer(SFFileWriterInfo *writer, BufferInfo *buffer, const int64_t version); @@ -247,6 +250,13 @@ int sf_file_writer_set_binlog_start_index(SFFileWriterInfo *writer, int sf_file_writer_set_binlog_write_index(SFFileWriterInfo *writer, const int last_index); +static inline int sf_file_writer_rotate_file(SFFileWriterInfo *writer) +{ + int last_index; + last_index = sf_file_writer_get_current_write_index(writer); + return sf_file_writer_set_binlog_write_index(writer, last_index + 1); +} + int sf_file_writer_get_last_lines(const char *data_path, const char *subdir_name, const int current_write_index, char *buff, const int buff_size, int *count, int *length); diff --git a/src/sf_types.h b/src/sf_types.h index c1a5c0d..6548a35 100644 --- a/src/sf_types.h +++ b/src/sf_types.h @@ -44,6 +44,7 @@ #define SF_BINLOG_BUFFER_PRODUCER_DATA_LENGTH(bf) ((bf).data_end - (bf).buff) #define SF_BINLOG_BUFFER_PRODUCER_BUFF_REMAIN(bf) ((bf).buff_end - (bf).data_end) +#define SF_BINLOG_BUFFER_CONSUMER_DATA_LENGTH(bf) ((bf).current - (bf).buff) #define SF_BINLOG_BUFFER_CONSUMER_DATA_REMAIN(bf) ((bf).data_end - (bf).current) typedef int (*sf_accept_done_callback)(struct fast_task_info *task,