add function sf_file_writer_get_binlog_index
parent
a727f382bc
commit
1a03fec1f6
|
|
@ -224,6 +224,11 @@ static inline SFBinlogWriterBuffer *sf_binlog_writer_alloc_versioned_buffer_ex(
|
||||||
sf_file_writer_get_index_filename(data_path, \
|
sf_file_writer_get_index_filename(data_path, \
|
||||||
subdir_name, filename, size)
|
subdir_name, filename, size)
|
||||||
|
|
||||||
|
#define sf_binlog_writer_get_binlog_index(data_path, \
|
||||||
|
subdir_name, write_index) \
|
||||||
|
sf_file_writer_get_binlog_index(data_path, \
|
||||||
|
subdir_name, write_index)
|
||||||
|
|
||||||
#define sf_binlog_writer_set_binlog_index(writer, binlog_index) \
|
#define sf_binlog_writer_set_binlog_index(writer, binlog_index) \
|
||||||
sf_file_writer_set_binlog_index(&(writer)->fw, binlog_index)
|
sf_file_writer_set_binlog_index(&(writer)->fw, binlog_index)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,21 +82,18 @@ static int write_to_binlog_index_file(SFFileWriterInfo *writer)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_binlog_index_from_file(SFFileWriterInfo *writer)
|
static int get_binlog_info_from_file(const char *data_path,
|
||||||
|
const char *subdir_name, int *write_index,
|
||||||
|
int *compress_index)
|
||||||
{
|
{
|
||||||
char full_filename[PATH_MAX];
|
char full_filename[PATH_MAX];
|
||||||
IniContext ini_context;
|
IniContext ini_context;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
snprintf(full_filename, sizeof(full_filename), "%s/%s/%s",
|
snprintf(full_filename, sizeof(full_filename), "%s/%s/%s",
|
||||||
writer->cfg.data_path, writer->cfg.subdir_name,
|
data_path, subdir_name, BINLOG_INDEX_FILENAME);
|
||||||
BINLOG_INDEX_FILENAME);
|
|
||||||
if (access(full_filename, F_OK) != 0) {
|
if (access(full_filename, F_OK) != 0) {
|
||||||
if (errno == ENOENT) {
|
return errno != 0 ? errno : EPERM;
|
||||||
writer->binlog.index = 0;
|
|
||||||
writer->binlog.compress_index = 0;
|
|
||||||
return write_to_binlog_index_file(writer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result=iniLoadFromFile(full_filename, &ini_context)) != 0) {
|
if ((result=iniLoadFromFile(full_filename, &ini_context)) != 0) {
|
||||||
|
|
@ -106,15 +103,40 @@ static int get_binlog_index_from_file(SFFileWriterInfo *writer)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
writer->binlog.index = iniGetIntValue(NULL,
|
*write_index = iniGetIntValue(NULL,
|
||||||
BINLOG_INDEX_ITEM_CURRENT_WRITE, &ini_context, 0);
|
BINLOG_INDEX_ITEM_CURRENT_WRITE,
|
||||||
writer->binlog.compress_index = iniGetIntValue(NULL,
|
&ini_context, 0);
|
||||||
BINLOG_INDEX_ITEM_CURRENT_COMPRESS, &ini_context, 0);
|
*compress_index = iniGetIntValue(NULL,
|
||||||
|
BINLOG_INDEX_ITEM_CURRENT_COMPRESS,
|
||||||
|
&ini_context, 0);
|
||||||
|
|
||||||
iniFreeContext(&ini_context);
|
iniFreeContext(&ini_context);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sf_file_writer_get_binlog_index(const char *data_path,
|
||||||
|
const char *subdir_name, int *write_index)
|
||||||
|
{
|
||||||
|
int compress_index;
|
||||||
|
return get_binlog_info_from_file(data_path, subdir_name,
|
||||||
|
write_index, &compress_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int get_binlog_index_from_file(SFFileWriterInfo *writer)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
result = get_binlog_info_from_file(writer->cfg.data_path,
|
||||||
|
writer->cfg.subdir_name, &writer->binlog.index,
|
||||||
|
&writer->binlog.compress_index);
|
||||||
|
if (result == ENOENT) {
|
||||||
|
writer->binlog.index = 0;
|
||||||
|
writer->binlog.compress_index = 0;
|
||||||
|
return write_to_binlog_index_file(writer);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static int open_writable_binlog(SFFileWriterInfo *writer)
|
static int open_writable_binlog(SFFileWriterInfo *writer)
|
||||||
{
|
{
|
||||||
if (writer->file.fd >= 0) {
|
if (writer->file.fd >= 0) {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ typedef struct sf_file_writer_info {
|
||||||
} cfg;
|
} cfg;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int index;
|
int index; //current write index
|
||||||
int compress_index;
|
int compress_index;
|
||||||
} binlog;
|
} binlog;
|
||||||
|
|
||||||
|
|
@ -93,6 +93,9 @@ static inline int64_t sf_file_writer_get_last_version(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sf_file_writer_get_binlog_index(const char *data_path,
|
||||||
|
const char *subdir_name, int *write_index);
|
||||||
|
|
||||||
int sf_file_writer_get_current_index(SFFileWriterInfo *writer);
|
int sf_file_writer_get_current_index(SFFileWriterInfo *writer);
|
||||||
|
|
||||||
static inline void sf_file_writer_get_current_position(
|
static inline void sf_file_writer_get_current_position(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue