add function write_to_binlog_index_file
parent
fc9c23fb95
commit
f9d8c3d070
|
|
@ -48,10 +48,6 @@
|
||||||
snprintf(filename, size, "%s/%s/%s_index.dat", \
|
snprintf(filename, size, "%s/%s/%s_index.dat", \
|
||||||
data_path, subdir_name, file_prefix)
|
data_path, subdir_name, file_prefix)
|
||||||
|
|
||||||
#define GET_BINLOG_INDEX_FILENAME(writer, filename, size) \
|
|
||||||
GET_BINLOG_INDEX_FILENAME_EX(writer->cfg.data_path, \
|
|
||||||
writer->cfg.subdir_name, writer->cfg.file_prefix, filename, size)
|
|
||||||
|
|
||||||
const char *sf_file_writer_get_index_filename(const char *data_path,
|
const char *sf_file_writer_get_index_filename(const char *data_path,
|
||||||
const char *subdir_name, char *filename, const int size)
|
const char *subdir_name, char *filename, const int size)
|
||||||
{
|
{
|
||||||
|
|
@ -60,23 +56,24 @@ const char *sf_file_writer_get_index_filename(const char *data_path,
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_to_binlog_index_file(SFFileWriterInfo *writer)
|
int sf_file_writer_write_to_binlog_index_file_ex(const char *data_path,
|
||||||
|
const char *subdir_name, const char *file_prefix,
|
||||||
|
const int start_index, const int last_index,
|
||||||
|
const int compress_index)
|
||||||
{
|
{
|
||||||
char filename[PATH_MAX];
|
char filename[PATH_MAX];
|
||||||
char buff[256];
|
char buff[256];
|
||||||
int result;
|
int result;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
GET_BINLOG_INDEX_FILENAME(writer, filename, sizeof(filename));
|
GET_BINLOG_INDEX_FILENAME_EX(data_path, subdir_name,
|
||||||
|
file_prefix, filename, sizeof(filename));
|
||||||
len = sprintf(buff, "%s=%d\n"
|
len = sprintf(buff, "%s=%d\n"
|
||||||
"%s=%d\n"
|
"%s=%d\n"
|
||||||
"%s=%d\n",
|
"%s=%d\n",
|
||||||
BINLOG_INDEX_ITEM_START_INDEX,
|
BINLOG_INDEX_ITEM_START_INDEX, start_index,
|
||||||
writer->binlog.start_index,
|
BINLOG_INDEX_ITEM_CURRENT_WRITE, last_index,
|
||||||
BINLOG_INDEX_ITEM_CURRENT_WRITE,
|
BINLOG_INDEX_ITEM_CURRENT_COMPRESS, compress_index);
|
||||||
writer->binlog.last_index,
|
|
||||||
BINLOG_INDEX_ITEM_CURRENT_COMPRESS,
|
|
||||||
writer->binlog.compress_index);
|
|
||||||
if ((result=safeWriteToFile(filename, buff, len)) != 0) {
|
if ((result=safeWriteToFile(filename, buff, len)) != 0) {
|
||||||
logError("file: "__FILE__", line: %d, "
|
logError("file: "__FILE__", line: %d, "
|
||||||
"write to file \"%s\" fail, errno: %d, error info: %s",
|
"write to file \"%s\" fail, errno: %d, error info: %s",
|
||||||
|
|
@ -86,6 +83,14 @@ static int write_to_binlog_index_file(SFFileWriterInfo *writer)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int write_to_binlog_index_file(SFFileWriterInfo *writer)
|
||||||
|
{
|
||||||
|
return sf_file_writer_write_to_binlog_index_file_ex(
|
||||||
|
writer->cfg.data_path, writer->cfg.subdir_name,
|
||||||
|
writer->cfg.file_prefix, writer->binlog.start_index,
|
||||||
|
writer->binlog.last_index, writer->binlog.compress_index);
|
||||||
|
}
|
||||||
|
|
||||||
static int get_binlog_info_from_file(const char *data_path,
|
static int get_binlog_info_from_file(const char *data_path,
|
||||||
const char *subdir_name, int *start_index,
|
const char *subdir_name, int *start_index,
|
||||||
int *last_index, int *compress_index)
|
int *last_index, int *compress_index)
|
||||||
|
|
|
||||||
|
|
@ -236,6 +236,16 @@ int sf_file_writer_get_last_lines(const char *data_path,
|
||||||
const char *subdir_name, const int current_write_index,
|
const char *subdir_name, const int current_write_index,
|
||||||
char *buff, const int buff_size, int *count, int *length);
|
char *buff, const int buff_size, int *count, int *length);
|
||||||
|
|
||||||
|
int sf_file_writer_write_to_binlog_index_file_ex(const char *data_path,
|
||||||
|
const char *subdir_name, const char *file_prefix,
|
||||||
|
const int start_index, const int last_index,
|
||||||
|
const int compress_index);
|
||||||
|
|
||||||
|
#define sf_file_writer_write_to_binlog_index_file(data_path, \
|
||||||
|
subdir_name, start_index, last_index) \
|
||||||
|
sf_file_writer_write_to_binlog_index_file_ex(data_path, subdir_name, \
|
||||||
|
SF_BINLOG_FILE_PREFIX, start_index, last_index, 0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue