support backup binlog file when truncate trunk binlog
parent
2c5955c1fe
commit
4a6f89c692
6
HISTORY
6
HISTORY
|
|
@ -1,12 +1,14 @@
|
||||||
|
|
||||||
Version 6.05 2019-12-18
|
Version 6.05 2019-12-19
|
||||||
* fdfs_trackerd and fdfs_storaged print the server version in usage.
|
* fdfs_trackerd and fdfs_storaged print the server version in usage.
|
||||||
you can execute fdfs_trackerd or fdfs_storaged without parameters
|
you can execute fdfs_trackerd or fdfs_storaged without parameters
|
||||||
to show the server version
|
to show the server version
|
||||||
* trunk server support compress the trunk binlog periodically,
|
* trunk server support compress the trunk binlog periodically,
|
||||||
config items in tracker.conf: trunk_compress_binlog_interval
|
the config items in tracker.conf: trunk_compress_binlog_interval
|
||||||
and trunk_compress_binlog_time_base
|
and trunk_compress_binlog_time_base
|
||||||
* trunk binlog compression support transaction
|
* trunk binlog compression support transaction
|
||||||
|
* support backup binlog file when truncate trunk binlog,
|
||||||
|
the config item in tracker.conf: trunk_binlog_max_backups
|
||||||
|
|
||||||
Version 6.04 2019-12-05
|
Version 6.04 2019-12-05
|
||||||
* storage_report_ip_changed ignore result EEXIST
|
* storage_report_ip_changed ignore result EEXIST
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,11 @@ trunk_compress_binlog_interval = 86400
|
||||||
# since V6.05
|
# since V6.05
|
||||||
trunk_compress_binlog_time_base = 03:00
|
trunk_compress_binlog_time_base = 03:00
|
||||||
|
|
||||||
|
# max backups for the trunk binlog file
|
||||||
|
# default value is 0 (never backup)
|
||||||
|
# since V6.05
|
||||||
|
trunk_binlog_max_backups = 7
|
||||||
|
|
||||||
# if use storage server ID instead of IP address
|
# if use storage server ID instead of IP address
|
||||||
# if you want to use dual IPs for storage server, you MUST set
|
# if you want to use dual IPs for storage server, you MUST set
|
||||||
# this parameter to true, and configure the dual IPs in the file
|
# this parameter to true, and configure the dual IPs in the file
|
||||||
|
|
|
||||||
|
|
@ -74,30 +74,30 @@ int storage_get_params_from_tracker()
|
||||||
char reserved_space_str[32];
|
char reserved_space_str[32];
|
||||||
char *pIdType;
|
char *pIdType;
|
||||||
|
|
||||||
if ((result=fdfs_get_ini_context_from_tracker(&g_tracker_group, \
|
if ((result=fdfs_get_ini_context_from_tracker(&g_tracker_group,
|
||||||
&iniContext, (bool * volatile)&g_continue_flag, \
|
&iniContext, (bool * volatile)&g_continue_flag,
|
||||||
g_client_bind_addr, g_bind_addr)) != 0)
|
g_client_bind_addr, g_bind_addr)) != 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_storage_ip_changed_auto_adjust = iniGetBoolValue(NULL, \
|
g_storage_ip_changed_auto_adjust = iniGetBoolValue(NULL,
|
||||||
"storage_ip_changed_auto_adjust", \
|
"storage_ip_changed_auto_adjust",
|
||||||
&iniContext, false);
|
&iniContext, false);
|
||||||
|
|
||||||
g_store_path_mode = iniGetIntValue(NULL, "store_path", &iniContext, \
|
g_store_path_mode = iniGetIntValue(NULL, "store_path", &iniContext,
|
||||||
FDFS_STORE_PATH_ROUND_ROBIN);
|
FDFS_STORE_PATH_ROUND_ROBIN);
|
||||||
|
|
||||||
if ((result=fdfs_parse_storage_reserved_space(&iniContext, \
|
if ((result=fdfs_parse_storage_reserved_space(&iniContext,
|
||||||
&g_storage_reserved_space)) != 0)
|
&g_storage_reserved_space)) != 0)
|
||||||
{
|
{
|
||||||
iniFreeContext(&iniContext);
|
iniFreeContext(&iniContext);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (g_storage_reserved_space.flag == \
|
if (g_storage_reserved_space.flag ==
|
||||||
TRACKER_STORAGE_RESERVED_SPACE_FLAG_MB)
|
TRACKER_STORAGE_RESERVED_SPACE_FLAG_MB)
|
||||||
{
|
{
|
||||||
g_avg_storage_reserved_mb = g_storage_reserved_space.rs.mb \
|
g_avg_storage_reserved_mb = g_storage_reserved_space.rs.mb
|
||||||
/ g_fdfs_store_paths.count;
|
/ g_fdfs_store_paths.count;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -105,31 +105,31 @@ int storage_get_params_from_tracker()
|
||||||
g_avg_storage_reserved_mb = 0;
|
g_avg_storage_reserved_mb = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_use_storage_id = iniGetBoolValue(NULL, "use_storage_id", \
|
g_use_storage_id = iniGetBoolValue(NULL, "use_storage_id",
|
||||||
&iniContext, false);
|
&iniContext, false);
|
||||||
use_trunk_file = iniGetBoolValue(NULL, "use_trunk_file", \
|
use_trunk_file = iniGetBoolValue(NULL, "use_trunk_file",
|
||||||
&iniContext, false);
|
&iniContext, false);
|
||||||
g_slot_min_size = iniGetIntValue(NULL, "slot_min_size", \
|
g_slot_min_size = iniGetIntValue(NULL, "slot_min_size",
|
||||||
&iniContext, 256);
|
&iniContext, 256);
|
||||||
g_trunk_file_size = iniGetIntValue(NULL, "trunk_file_size", \
|
g_trunk_file_size = iniGetIntValue(NULL, "trunk_file_size",
|
||||||
&iniContext, 64 * 1024 * 1024);
|
&iniContext, 64 * 1024 * 1024);
|
||||||
g_slot_max_size = iniGetIntValue(NULL, "slot_max_size", \
|
g_slot_max_size = iniGetIntValue(NULL, "slot_max_size",
|
||||||
&iniContext, g_trunk_file_size / 2);
|
&iniContext, g_trunk_file_size / 2);
|
||||||
|
|
||||||
g_trunk_create_file_advance = iniGetBoolValue(NULL, \
|
g_trunk_create_file_advance = iniGetBoolValue(NULL,
|
||||||
"trunk_create_file_advance", &iniContext, false);
|
"trunk_create_file_advance", &iniContext, false);
|
||||||
if ((result=get_time_item_from_conf(&iniContext, \
|
if ((result=get_time_item_from_conf(&iniContext,
|
||||||
"trunk_create_file_time_base", \
|
"trunk_create_file_time_base",
|
||||||
&g_trunk_create_file_time_base, 2, 0)) != 0)
|
&g_trunk_create_file_time_base, 2, 0)) != 0)
|
||||||
{
|
{
|
||||||
iniFreeContext(&iniContext);
|
iniFreeContext(&iniContext);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
g_trunk_create_file_interval = iniGetIntValue(NULL, \
|
g_trunk_create_file_interval = iniGetIntValue(NULL,
|
||||||
"trunk_create_file_interval", &iniContext, \
|
"trunk_create_file_interval", &iniContext,
|
||||||
86400);
|
86400);
|
||||||
g_trunk_create_file_space_threshold = iniGetInt64Value(NULL, \
|
g_trunk_create_file_space_threshold = iniGetInt64Value(NULL,
|
||||||
"trunk_create_file_space_threshold", \
|
"trunk_create_file_space_threshold",
|
||||||
&iniContext, 0);
|
&iniContext, 0);
|
||||||
|
|
||||||
g_trunk_init_check_occupying = iniGetBoolValue(NULL,
|
g_trunk_init_check_occupying = iniGetBoolValue(NULL,
|
||||||
|
|
@ -147,7 +147,9 @@ int storage_get_params_from_tracker()
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_store_slave_file_use_link = iniGetBoolValue(NULL, \
|
g_trunk_binlog_max_backups = iniGetIntValue(NULL,
|
||||||
|
"trunk_binlog_max_backups", &iniContext, 0);
|
||||||
|
g_store_slave_file_use_link = iniGetBoolValue(NULL,
|
||||||
"store_slave_file_use_link", &iniContext, false);
|
"store_slave_file_use_link", &iniContext, false);
|
||||||
|
|
||||||
pIdType = iniGetStrValue(NULL, "id_type_in_filename", &iniContext);
|
pIdType = iniGetStrValue(NULL, "id_type_in_filename", &iniContext);
|
||||||
|
|
@ -178,48 +180,50 @@ int storage_get_params_from_tracker()
|
||||||
}
|
}
|
||||||
g_if_use_trunk_file = use_trunk_file;
|
g_if_use_trunk_file = use_trunk_file;
|
||||||
|
|
||||||
logInfo("file: "__FILE__", line: %d, " \
|
logInfo("file: "__FILE__", line: %d, "
|
||||||
"use_storage_id=%d, " \
|
"use_storage_id=%d, "
|
||||||
"id_type_in_filename=%s, " \
|
"id_type_in_filename=%s, "
|
||||||
"storage_ip_changed_auto_adjust=%d, " \
|
"storage_ip_changed_auto_adjust=%d, "
|
||||||
"store_path=%d, " \
|
"store_path=%d, "
|
||||||
"reserved_storage_space=%s, " \
|
"reserved_storage_space=%s, "
|
||||||
"use_trunk_file=%d, " \
|
"use_trunk_file=%d, "
|
||||||
"slot_min_size=%d, " \
|
"slot_min_size=%d, "
|
||||||
"slot_max_size=%d MB, " \
|
"slot_max_size=%d MB, "
|
||||||
"trunk_file_size=%d MB, " \
|
"trunk_file_size=%d MB, "
|
||||||
"trunk_create_file_advance=%d, " \
|
"trunk_create_file_advance=%d, "
|
||||||
"trunk_create_file_time_base=%02d:%02d, " \
|
"trunk_create_file_time_base=%02d:%02d, "
|
||||||
"trunk_create_file_interval=%d, " \
|
"trunk_create_file_interval=%d, "
|
||||||
"trunk_create_file_space_threshold=%d GB, " \
|
"trunk_create_file_space_threshold=%d GB, "
|
||||||
"trunk_init_check_occupying=%d, " \
|
"trunk_init_check_occupying=%d, "
|
||||||
"trunk_init_reload_from_binlog=%d, " \
|
"trunk_init_reload_from_binlog=%d, "
|
||||||
"trunk_compress_binlog_min_interval=%d, " \
|
"trunk_compress_binlog_min_interval=%d, "
|
||||||
"trunk_compress_binlog_interval=%d, " \
|
"trunk_compress_binlog_interval=%d, "
|
||||||
"trunk_compress_binlog_time_base=%02d:%02d, " \
|
"trunk_compress_binlog_time_base=%02d:%02d, "
|
||||||
"store_slave_file_use_link=%d", \
|
"trunk_binlog_max_backups=%d, "
|
||||||
__LINE__, g_use_storage_id, \
|
"store_slave_file_use_link=%d",
|
||||||
g_id_type_in_filename == FDFS_ID_TYPE_SERVER_ID ? "id" : "ip", \
|
__LINE__, g_use_storage_id,
|
||||||
g_storage_ip_changed_auto_adjust, \
|
g_id_type_in_filename == FDFS_ID_TYPE_SERVER_ID ? "id" : "ip",
|
||||||
g_store_path_mode, fdfs_storage_reserved_space_to_string( \
|
g_storage_ip_changed_auto_adjust,
|
||||||
&g_storage_reserved_space, reserved_space_str), \
|
g_store_path_mode, fdfs_storage_reserved_space_to_string(
|
||||||
g_if_use_trunk_file, g_slot_min_size, \
|
&g_storage_reserved_space, reserved_space_str),
|
||||||
g_slot_max_size / FDFS_ONE_MB, \
|
g_if_use_trunk_file, g_slot_min_size,
|
||||||
g_trunk_file_size / FDFS_ONE_MB, \
|
g_slot_max_size / FDFS_ONE_MB,
|
||||||
g_trunk_create_file_advance, \
|
g_trunk_file_size / FDFS_ONE_MB,
|
||||||
g_trunk_create_file_time_base.hour, \
|
g_trunk_create_file_advance,
|
||||||
g_trunk_create_file_time_base.minute, \
|
g_trunk_create_file_time_base.hour,
|
||||||
g_trunk_create_file_interval, \
|
g_trunk_create_file_time_base.minute,
|
||||||
(int)(g_trunk_create_file_space_threshold / \
|
g_trunk_create_file_interval,
|
||||||
(FDFS_ONE_MB * 1024)), g_trunk_init_check_occupying, \
|
(int)(g_trunk_create_file_space_threshold /
|
||||||
g_trunk_init_reload_from_binlog, \
|
(FDFS_ONE_MB * 1024)), g_trunk_init_check_occupying,
|
||||||
g_trunk_compress_binlog_min_interval, \
|
g_trunk_init_reload_from_binlog,
|
||||||
g_trunk_compress_binlog_interval, \
|
g_trunk_compress_binlog_min_interval,
|
||||||
g_trunk_compress_binlog_time_base.hour, \
|
g_trunk_compress_binlog_interval,
|
||||||
g_trunk_compress_binlog_time_base.minute, \
|
g_trunk_compress_binlog_time_base.hour,
|
||||||
|
g_trunk_compress_binlog_time_base.minute,
|
||||||
|
g_trunk_binlog_max_backups,
|
||||||
g_store_slave_file_use_link);
|
g_store_slave_file_use_link);
|
||||||
|
|
||||||
if (g_use_storage_id && *g_sync_src_id != '\0' && \
|
if (g_use_storage_id && *g_sync_src_id != '\0' &&
|
||||||
!fdfs_is_server_id_valid(g_sync_src_id))
|
!fdfs_is_server_id_valid(g_sync_src_id))
|
||||||
{
|
{
|
||||||
if ((result=storage_convert_src_server_id()) == 0)
|
if ((result=storage_convert_src_server_id()) == 0)
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ TimeInfo g_trunk_compress_binlog_time_base = {0, 0};
|
||||||
int g_trunk_create_file_interval = 86400;
|
int g_trunk_create_file_interval = 86400;
|
||||||
int g_trunk_compress_binlog_min_interval = 0;
|
int g_trunk_compress_binlog_min_interval = 0;
|
||||||
int g_trunk_compress_binlog_interval = 0;
|
int g_trunk_compress_binlog_interval = 0;
|
||||||
|
int g_trunk_binlog_max_backups = 0;
|
||||||
TrackerServerInfo g_trunk_server = {0, 0};
|
TrackerServerInfo g_trunk_server = {0, 0};
|
||||||
bool g_if_use_trunk_file = false;
|
bool g_if_use_trunk_file = false;
|
||||||
bool g_if_trunker_self = false;
|
bool g_if_trunker_self = false;
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ extern TimeInfo g_trunk_compress_binlog_time_base;
|
||||||
extern int g_trunk_create_file_interval;
|
extern int g_trunk_create_file_interval;
|
||||||
extern int g_trunk_compress_binlog_min_interval;
|
extern int g_trunk_compress_binlog_min_interval;
|
||||||
extern int g_trunk_compress_binlog_interval;
|
extern int g_trunk_compress_binlog_interval;
|
||||||
|
extern int g_trunk_binlog_max_backups;
|
||||||
extern TrackerServerInfo g_trunk_server; //the trunk server
|
extern TrackerServerInfo g_trunk_server; //the trunk server
|
||||||
extern bool g_if_use_trunk_file; //if use trunk file
|
extern bool g_if_use_trunk_file; //if use trunk file
|
||||||
extern bool g_trunk_create_file_advance;
|
extern bool g_trunk_create_file_advance;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@
|
||||||
#include "storage_sync_func.h"
|
#include "storage_sync_func.h"
|
||||||
#include "trunk_sync.h"
|
#include "trunk_sync.h"
|
||||||
|
|
||||||
#define TRUNK_SYNC_BINLOG_FILENAME "binlog"
|
#define TRUNK_SYNC_BINLOG_FILENAME_STR "binlog"
|
||||||
|
#define TRUNK_SYNC_BINLOG_FILENAME_LEN (sizeof(TRUNK_SYNC_BINLOG_FILENAME_STR) - 1)
|
||||||
#define TRUNK_SYNC_BINLOG_ROLLBACK_EXT ".rollback"
|
#define TRUNK_SYNC_BINLOG_ROLLBACK_EXT ".rollback"
|
||||||
#define TRUNK_SYNC_MARK_FILE_EXT_STR ".mark"
|
#define TRUNK_SYNC_MARK_FILE_EXT_STR ".mark"
|
||||||
#define TRUNK_SYNC_MARK_FILE_EXT_LEN (sizeof(TRUNK_SYNC_MARK_FILE_EXT_STR) - 1)
|
#define TRUNK_SYNC_MARK_FILE_EXT_LEN (sizeof(TRUNK_SYNC_MARK_FILE_EXT_STR) - 1)
|
||||||
|
|
@ -82,7 +83,7 @@ static int trunk_binlog_preread(TrunkBinLogReader *pReader);
|
||||||
char *get_trunk_binlog_filename(char *full_filename)
|
char *get_trunk_binlog_filename(char *full_filename)
|
||||||
{
|
{
|
||||||
snprintf(full_filename, MAX_PATH_SIZE, \
|
snprintf(full_filename, MAX_PATH_SIZE, \
|
||||||
"%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME, \
|
"%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME_STR, \
|
||||||
g_fdfs_base_path);
|
g_fdfs_base_path);
|
||||||
return full_filename;
|
return full_filename;
|
||||||
}
|
}
|
||||||
|
|
@ -405,29 +406,227 @@ int trunk_binlog_sync_func(void *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BACKUP_FILENAME_LEN (TRUNK_SYNC_BINLOG_FILENAME_LEN + 15)
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char filename[BACKUP_FILENAME_LEN + 1];
|
||||||
|
} TrunkBinlogBackupFileInfo;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
TrunkBinlogBackupFileInfo *files;
|
||||||
|
int count;
|
||||||
|
int alloc;
|
||||||
|
} TrunkBinlogBackupFileArray;
|
||||||
|
|
||||||
|
static int trunk_binlog_check_alloc_filename_array(
|
||||||
|
TrunkBinlogBackupFileArray *file_array)
|
||||||
|
{
|
||||||
|
int bytes;
|
||||||
|
TrunkBinlogBackupFileInfo *files;
|
||||||
|
int alloc;
|
||||||
|
|
||||||
|
if (file_array->count < file_array->alloc)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_array->alloc == 0)
|
||||||
|
{
|
||||||
|
alloc = g_trunk_binlog_max_backups + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alloc = file_array->alloc * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes = sizeof(TrunkBinlogBackupFileInfo) * alloc;
|
||||||
|
files = (TrunkBinlogBackupFileInfo *)malloc(bytes);
|
||||||
|
if (files == NULL)
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"malloc %d bytes fail", __LINE__, bytes);
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_array->count > 0)
|
||||||
|
{
|
||||||
|
memcpy(files, file_array->files, sizeof(TrunkBinlogBackupFileInfo) *
|
||||||
|
file_array->count);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_array->files != NULL)
|
||||||
|
{
|
||||||
|
free(file_array->files);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_array->files = files;
|
||||||
|
file_array->alloc = alloc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int trunk_binlog_compare_filename(const void *p1, const void *p2)
|
||||||
|
{
|
||||||
|
return strcmp(((TrunkBinlogBackupFileInfo *)p1)->filename,
|
||||||
|
((TrunkBinlogBackupFileInfo *)p2)->filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int trunk_binlog_delete_overflow_backups()
|
||||||
|
{
|
||||||
|
#define BACKUP_FILENAME_PREFIX_STR TRUNK_SYNC_BINLOG_FILENAME_STR"."
|
||||||
|
#define BACKUP_FILENAME_PREFIX_LEN (sizeof(BACKUP_FILENAME_PREFIX_STR) - 1)
|
||||||
|
|
||||||
|
int result;
|
||||||
|
int i;
|
||||||
|
int over_count;
|
||||||
|
char file_path[MAX_PATH_SIZE];
|
||||||
|
char full_filename[MAX_PATH_SIZE];
|
||||||
|
DIR *dir;
|
||||||
|
struct dirent *ent;
|
||||||
|
TrunkBinlogBackupFileArray file_array;
|
||||||
|
|
||||||
|
snprintf(file_path, sizeof(file_path),
|
||||||
|
"%s/data/%s", g_fdfs_base_path, TRUNK_DIR_NAME);
|
||||||
|
if ((dir=opendir(file_path)) == NULL)
|
||||||
|
{
|
||||||
|
result = errno != 0 ? errno : EPERM;
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"call opendir %s fail, errno: %d, error info: %s",
|
||||||
|
__LINE__, file_path, result, STRERROR(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = 0;
|
||||||
|
file_array.files = NULL;
|
||||||
|
file_array.count = 0;
|
||||||
|
file_array.alloc = 0;
|
||||||
|
while ((ent=readdir(dir)) != NULL)
|
||||||
|
{
|
||||||
|
if (strlen(ent->d_name) == BACKUP_FILENAME_LEN &&
|
||||||
|
memcmp(ent->d_name, BACKUP_FILENAME_PREFIX_STR,
|
||||||
|
BACKUP_FILENAME_PREFIX_LEN) == 0)
|
||||||
|
{
|
||||||
|
if ((result=trunk_binlog_check_alloc_filename_array(
|
||||||
|
&file_array)) != 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(file_array.files[file_array.count].
|
||||||
|
filename, ent->d_name);
|
||||||
|
file_array.count++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
|
over_count = file_array.count - g_trunk_binlog_max_backups;
|
||||||
|
if (result != 0 || over_count <= 0)
|
||||||
|
{
|
||||||
|
if (file_array.files != NULL)
|
||||||
|
{
|
||||||
|
free(file_array.files);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
qsort(file_array.files, file_array.count,
|
||||||
|
sizeof(TrunkBinlogBackupFileInfo),
|
||||||
|
trunk_binlog_compare_filename);
|
||||||
|
for (i=0; i<over_count; i++)
|
||||||
|
{
|
||||||
|
sprintf(full_filename, "%s/%s", file_path,
|
||||||
|
file_array.files[i].filename);
|
||||||
|
logInfo("unlink old file: %s", full_filename);
|
||||||
|
unlink(full_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(file_array.files);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int trunk_binlog_backup_and_truncate()
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
int open_res;
|
||||||
|
char binlog_filename[MAX_PATH_SIZE];
|
||||||
|
char backup_filename[MAX_PATH_SIZE];
|
||||||
|
time_t t;
|
||||||
|
struct tm tm;
|
||||||
|
|
||||||
|
if ((result=trunk_binlog_delete_overflow_backups()) != 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((result=trunk_binlog_close_writer(false)) != 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
t = g_current_time;
|
||||||
|
localtime_r(&t, &tm);
|
||||||
|
|
||||||
|
get_trunk_binlog_filename(binlog_filename);
|
||||||
|
snprintf(backup_filename, sizeof(backup_filename),
|
||||||
|
"%s.%04d%02d%02d%02d%02d%02d", binlog_filename,
|
||||||
|
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
|
||||||
|
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||||
|
if (rename(binlog_filename, backup_filename) != 0)
|
||||||
|
{
|
||||||
|
result = errno != 0 ? errno : EACCES;
|
||||||
|
logError("file: "__FILE__", line: %d, "
|
||||||
|
"rename file %s to %s fail, "
|
||||||
|
"errno: %d, error info: %s", __LINE__,
|
||||||
|
binlog_filename, backup_filename,
|
||||||
|
result, STRERROR(result));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
open_res = trunk_binlog_open_writer(binlog_filename);
|
||||||
|
return (result == 0) ? open_res : result;
|
||||||
|
}
|
||||||
|
|
||||||
int trunk_binlog_truncate()
|
int trunk_binlog_truncate()
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
|
result = 0;
|
||||||
|
pthread_mutex_lock(&trunk_sync_thread_lock);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (g_trunk_binlog_max_backups > 0)
|
||||||
|
{
|
||||||
|
result = trunk_binlog_backup_and_truncate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (trunk_binlog_write_cache_len > 0)
|
if (trunk_binlog_write_cache_len > 0)
|
||||||
{
|
{
|
||||||
if ((result=trunk_binlog_fsync(true)) != 0)
|
if ((result=trunk_binlog_fsync(false)) != 0)
|
||||||
{
|
{
|
||||||
return result;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ftruncate(trunk_binlog_fd, 0) != 0)
|
if (ftruncate(trunk_binlog_fd, 0) != 0)
|
||||||
{
|
{
|
||||||
result = errno != 0 ? errno : EIO;
|
result = errno != 0 ? errno : EIO;
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, "
|
||||||
"call ftruncate fail, " \
|
"call ftruncate fail, "
|
||||||
"errno: %d, error info: %s", \
|
"errno: %d, error info: %s",
|
||||||
__LINE__, result, STRERROR(result));
|
__LINE__, result, STRERROR(result));
|
||||||
return result;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
|
||||||
return 0;
|
pthread_mutex_unlock(&trunk_sync_thread_lock);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int trunk_binlog_delete_rollback_file(const char *filename,
|
static int trunk_binlog_delete_rollback_file(const char *filename,
|
||||||
|
|
@ -1206,7 +1405,7 @@ int trunk_binlog_write_buffer(const char *buff, const int length)
|
||||||
return write_ret;
|
return write_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *get_binlog_readable_filename(const void *pArg, \
|
static char *get_binlog_readable_filename(const void *pArg,
|
||||||
char *full_filename)
|
char *full_filename)
|
||||||
{
|
{
|
||||||
static char buff[MAX_PATH_SIZE];
|
static char buff[MAX_PATH_SIZE];
|
||||||
|
|
@ -1217,7 +1416,7 @@ static char *get_binlog_readable_filename(const void *pArg, \
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(full_filename, MAX_PATH_SIZE,
|
snprintf(full_filename, MAX_PATH_SIZE,
|
||||||
"%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME, \
|
"%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME_STR,
|
||||||
g_fdfs_base_path);
|
g_fdfs_base_path);
|
||||||
return full_filename;
|
return full_filename;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -576,6 +576,9 @@ int tracker_load_from_conf_file(const char *filename, \
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_trunk_binlog_max_backups = iniGetIntValue(NULL,
|
||||||
|
"trunk_binlog_max_backups", &iniContext, 0);
|
||||||
|
|
||||||
g_trunk_init_check_occupying = iniGetBoolValue(NULL, \
|
g_trunk_init_check_occupying = iniGetBoolValue(NULL, \
|
||||||
"trunk_init_check_occupying", &iniContext, false);
|
"trunk_init_check_occupying", &iniContext, false);
|
||||||
|
|
||||||
|
|
@ -728,89 +731,91 @@ int tracker_load_from_conf_file(const char *filename, \
|
||||||
int_to_comma_str(g_min_buff_size, sz_min_buff_size);
|
int_to_comma_str(g_min_buff_size, sz_min_buff_size);
|
||||||
int_to_comma_str(g_max_buff_size, sz_max_buff_size);
|
int_to_comma_str(g_max_buff_size, sz_max_buff_size);
|
||||||
|
|
||||||
logInfo("FastDFS v%d.%02d, base_path=%s, " \
|
logInfo("FastDFS v%d.%02d, base_path=%s, "
|
||||||
"run_by_group=%s, run_by_user=%s, " \
|
"run_by_group=%s, run_by_user=%s, "
|
||||||
"connect_timeout=%ds, " \
|
"connect_timeout=%ds, "
|
||||||
"network_timeout=%ds, " \
|
"network_timeout=%ds, "
|
||||||
"port=%d, bind_addr=%s, " \
|
"port=%d, bind_addr=%s, "
|
||||||
"max_connections=%d, " \
|
"max_connections=%d, "
|
||||||
"accept_threads=%d, " \
|
"accept_threads=%d, "
|
||||||
"work_threads=%d, " \
|
"work_threads=%d, "
|
||||||
"min_buff_size=%s, " \
|
"min_buff_size=%s, "
|
||||||
"max_buff_size=%s, " \
|
"max_buff_size=%s, "
|
||||||
"store_lookup=%d, store_group=%s, " \
|
"store_lookup=%d, store_group=%s, "
|
||||||
"store_server=%d, store_path=%d, " \
|
"store_server=%d, store_path=%d, "
|
||||||
"reserved_storage_space=%s, " \
|
"reserved_storage_space=%s, "
|
||||||
"download_server=%d, " \
|
"download_server=%d, "
|
||||||
"allow_ip_count=%d, sync_log_buff_interval=%ds, " \
|
"allow_ip_count=%d, sync_log_buff_interval=%ds, "
|
||||||
"check_active_interval=%ds, " \
|
"check_active_interval=%ds, "
|
||||||
"thread_stack_size=%d KB, " \
|
"thread_stack_size=%d KB, "
|
||||||
"storage_ip_changed_auto_adjust=%d, " \
|
"storage_ip_changed_auto_adjust=%d, "
|
||||||
"storage_sync_file_max_delay=%ds, " \
|
"storage_sync_file_max_delay=%ds, "
|
||||||
"storage_sync_file_max_time=%ds, " \
|
"storage_sync_file_max_time=%ds, "
|
||||||
"use_trunk_file=%d, " \
|
"use_trunk_file=%d, "
|
||||||
"slot_min_size=%d, " \
|
"slot_min_size=%d, "
|
||||||
"slot_max_size=%d MB, " \
|
"slot_max_size=%d MB, "
|
||||||
"trunk_file_size=%d MB, " \
|
"trunk_file_size=%d MB, "
|
||||||
"trunk_create_file_advance=%d, " \
|
"trunk_create_file_advance=%d, "
|
||||||
"trunk_create_file_time_base=%02d:%02d, " \
|
"trunk_create_file_time_base=%02d:%02d, "
|
||||||
"trunk_create_file_interval=%d, " \
|
"trunk_create_file_interval=%d, "
|
||||||
"trunk_create_file_space_threshold=%d GB, " \
|
"trunk_create_file_space_threshold=%d GB, "
|
||||||
"trunk_init_check_occupying=%d, " \
|
"trunk_init_check_occupying=%d, "
|
||||||
"trunk_init_reload_from_binlog=%d, " \
|
"trunk_init_reload_from_binlog=%d, "
|
||||||
"trunk_compress_binlog_min_interval=%d, " \
|
"trunk_compress_binlog_min_interval=%d, "
|
||||||
"trunk_compress_binlog_interval=%d, " \
|
"trunk_compress_binlog_interval=%d, "
|
||||||
"trunk_compress_binlog_time_base=%02d:%02d, " \
|
"trunk_compress_binlog_time_base=%02d:%02d, "
|
||||||
"use_storage_id=%d, " \
|
"trunk_binlog_max_backups=%d, "
|
||||||
"id_type_in_filename=%s, " \
|
"use_storage_id=%d, "
|
||||||
"storage_id/ip_count=%d / %d, " \
|
"id_type_in_filename=%s, "
|
||||||
"rotate_error_log=%d, " \
|
"storage_id/ip_count=%d / %d, "
|
||||||
"error_log_rotate_time=%02d:%02d, " \
|
"rotate_error_log=%d, "
|
||||||
"compress_old_error_log=%d, " \
|
"error_log_rotate_time=%02d:%02d, "
|
||||||
"compress_error_log_days_before=%d, " \
|
"compress_old_error_log=%d, "
|
||||||
"rotate_error_log_size=%"PRId64", " \
|
"compress_error_log_days_before=%d, "
|
||||||
"log_file_keep_days=%d, " \
|
"rotate_error_log_size=%"PRId64", "
|
||||||
"store_slave_file_use_link=%d, " \
|
"log_file_keep_days=%d, "
|
||||||
"use_connection_pool=%d, " \
|
"store_slave_file_use_link=%d, "
|
||||||
"g_connection_pool_max_idle_time=%ds", \
|
"use_connection_pool=%d, "
|
||||||
g_fdfs_version.major, g_fdfs_version.minor, \
|
"g_connection_pool_max_idle_time=%ds",
|
||||||
g_fdfs_base_path, g_run_by_group, g_run_by_user, \
|
g_fdfs_version.major, g_fdfs_version.minor,
|
||||||
g_fdfs_connect_timeout, \
|
g_fdfs_base_path, g_run_by_group, g_run_by_user,
|
||||||
g_fdfs_network_timeout, g_server_port, bind_addr, \
|
g_fdfs_connect_timeout,
|
||||||
g_max_connections, g_accept_threads, g_work_threads, \
|
g_fdfs_network_timeout, g_server_port, bind_addr,
|
||||||
sz_min_buff_size, sz_max_buff_size, \
|
g_max_connections, g_accept_threads, g_work_threads,
|
||||||
g_groups.store_lookup, g_groups.store_group, \
|
sz_min_buff_size, sz_max_buff_size,
|
||||||
g_groups.store_server, g_groups.store_path, \
|
g_groups.store_lookup, g_groups.store_group,
|
||||||
fdfs_storage_reserved_space_to_string( \
|
g_groups.store_server, g_groups.store_path,
|
||||||
&g_storage_reserved_space, reserved_space_str), \
|
fdfs_storage_reserved_space_to_string(
|
||||||
g_groups.download_server, \
|
&g_storage_reserved_space, reserved_space_str),
|
||||||
g_allow_ip_count, g_sync_log_buff_interval, \
|
g_groups.download_server,
|
||||||
g_check_active_interval, g_thread_stack_size / 1024, \
|
g_allow_ip_count, g_sync_log_buff_interval,
|
||||||
g_storage_ip_changed_auto_adjust, \
|
g_check_active_interval, g_thread_stack_size / 1024,
|
||||||
g_storage_sync_file_max_delay, \
|
g_storage_ip_changed_auto_adjust,
|
||||||
g_storage_sync_file_max_time, \
|
g_storage_sync_file_max_delay,
|
||||||
g_if_use_trunk_file, g_slot_min_size, \
|
g_storage_sync_file_max_time,
|
||||||
g_slot_max_size / FDFS_ONE_MB, \
|
g_if_use_trunk_file, g_slot_min_size,
|
||||||
g_trunk_file_size / FDFS_ONE_MB, \
|
g_slot_max_size / FDFS_ONE_MB,
|
||||||
g_trunk_create_file_advance, \
|
g_trunk_file_size / FDFS_ONE_MB,
|
||||||
g_trunk_create_file_time_base.hour, \
|
g_trunk_create_file_advance,
|
||||||
g_trunk_create_file_time_base.minute, \
|
g_trunk_create_file_time_base.hour,
|
||||||
g_trunk_create_file_interval, \
|
g_trunk_create_file_time_base.minute,
|
||||||
(int)(g_trunk_create_file_space_threshold / \
|
g_trunk_create_file_interval,
|
||||||
(FDFS_ONE_MB * 1024)), g_trunk_init_check_occupying, \
|
(int)(g_trunk_create_file_space_threshold /
|
||||||
g_trunk_init_reload_from_binlog, \
|
(FDFS_ONE_MB * 1024)), g_trunk_init_check_occupying,
|
||||||
g_trunk_compress_binlog_min_interval, \
|
g_trunk_init_reload_from_binlog,
|
||||||
g_trunk_compress_binlog_interval, \
|
g_trunk_compress_binlog_min_interval,
|
||||||
g_trunk_compress_binlog_time_base.hour, \
|
g_trunk_compress_binlog_interval,
|
||||||
g_trunk_compress_binlog_time_base.minute, \
|
g_trunk_compress_binlog_time_base.hour,
|
||||||
g_use_storage_id, g_id_type_in_filename == \
|
g_trunk_compress_binlog_time_base.minute,
|
||||||
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip", \
|
g_trunk_binlog_max_backups,
|
||||||
g_storage_ids_by_id.count, g_storage_ids_by_ip.count, \
|
g_use_storage_id, g_id_type_in_filename ==
|
||||||
g_rotate_error_log, g_error_log_rotate_time.hour, \
|
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip",
|
||||||
g_error_log_rotate_time.minute, g_compress_old_error_log, \
|
g_storage_ids_by_id.count, g_storage_ids_by_ip.count,
|
||||||
g_compress_error_log_days_before, \
|
g_rotate_error_log, g_error_log_rotate_time.hour,
|
||||||
|
g_error_log_rotate_time.minute, g_compress_old_error_log,
|
||||||
|
g_compress_error_log_days_before,
|
||||||
g_log_context.rotate_size, g_log_file_keep_days,
|
g_log_context.rotate_size, g_log_file_keep_days,
|
||||||
g_store_slave_file_use_link, \
|
g_store_slave_file_use_link,
|
||||||
g_use_connection_pool, g_connection_pool_max_idle_time);
|
g_use_connection_pool, g_connection_pool_max_idle_time);
|
||||||
|
|
||||||
#ifdef WITH_HTTPD
|
#ifdef WITH_HTTPD
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ TimeInfo g_trunk_compress_binlog_time_base = {0, 0};
|
||||||
int g_trunk_create_file_interval = 86400;
|
int g_trunk_create_file_interval = 86400;
|
||||||
int g_trunk_compress_binlog_interval = 0;
|
int g_trunk_compress_binlog_interval = 0;
|
||||||
int g_trunk_compress_binlog_min_interval = 0;
|
int g_trunk_compress_binlog_min_interval = 0;
|
||||||
|
int g_trunk_binlog_max_backups = 0;
|
||||||
int64_t g_trunk_create_file_space_threshold = 0;
|
int64_t g_trunk_create_file_space_threshold = 0;
|
||||||
|
|
||||||
time_t g_up_time = 0;
|
time_t g_up_time = 0;
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ extern TimeInfo g_trunk_compress_binlog_time_base;
|
||||||
extern int g_trunk_create_file_interval;
|
extern int g_trunk_create_file_interval;
|
||||||
extern int g_trunk_compress_binlog_interval;
|
extern int g_trunk_compress_binlog_interval;
|
||||||
extern int g_trunk_compress_binlog_min_interval;
|
extern int g_trunk_compress_binlog_min_interval;
|
||||||
|
extern int g_trunk_binlog_max_backups;
|
||||||
extern int64_t g_trunk_create_file_space_threshold;
|
extern int64_t g_trunk_create_file_space_threshold;
|
||||||
|
|
||||||
extern time_t g_up_time;
|
extern time_t g_up_time;
|
||||||
|
|
|
||||||
|
|
@ -661,6 +661,7 @@ static int tracker_deal_get_trunk_fid(struct fast_task_info *pTask)
|
||||||
static int tracker_deal_parameter_req(struct fast_task_info *pTask)
|
static int tracker_deal_parameter_req(struct fast_task_info *pTask)
|
||||||
{
|
{
|
||||||
char reserved_space_str[32];
|
char reserved_space_str[32];
|
||||||
|
int body_len;
|
||||||
|
|
||||||
if (pTask->length - sizeof(TrackerHeader) != 0)
|
if (pTask->length - sizeof(TrackerHeader) != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -676,49 +677,51 @@ static int tracker_deal_parameter_req(struct fast_task_info *pTask)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTask->length = sizeof(TrackerHeader) + \
|
body_len = sprintf(pTask->data + sizeof(TrackerHeader),
|
||||||
sprintf(pTask->data + sizeof(TrackerHeader), \
|
"use_storage_id=%d\n"
|
||||||
"use_storage_id=%d\n" \
|
"id_type_in_filename=%s\n"
|
||||||
"id_type_in_filename=%s\n" \
|
"storage_ip_changed_auto_adjust=%d\n"
|
||||||
"storage_ip_changed_auto_adjust=%d\n" \
|
"storage_sync_file_max_delay=%d\n"
|
||||||
"storage_sync_file_max_delay=%d\n" \
|
"store_path=%d\n"
|
||||||
"store_path=%d\n" \
|
"reserved_storage_space=%s\n"
|
||||||
"reserved_storage_space=%s\n" \
|
"use_trunk_file=%d\n"
|
||||||
"use_trunk_file=%d\n" \
|
"slot_min_size=%d\n"
|
||||||
"slot_min_size=%d\n" \
|
"slot_max_size=%d\n"
|
||||||
"slot_max_size=%d\n" \
|
"trunk_file_size=%d\n"
|
||||||
"trunk_file_size=%d\n" \
|
"trunk_create_file_advance=%d\n"
|
||||||
"trunk_create_file_advance=%d\n" \
|
"trunk_create_file_time_base=%02d:%02d\n"
|
||||||
"trunk_create_file_time_base=%02d:%02d\n" \
|
"trunk_create_file_interval=%d\n"
|
||||||
"trunk_create_file_interval=%d\n" \
|
"trunk_create_file_space_threshold=%"PRId64"\n"
|
||||||
"trunk_create_file_space_threshold=%"PRId64"\n" \
|
"trunk_init_check_occupying=%d\n"
|
||||||
"trunk_init_check_occupying=%d\n" \
|
"trunk_init_reload_from_binlog=%d\n"
|
||||||
"trunk_init_reload_from_binlog=%d\n" \
|
"trunk_compress_binlog_min_interval=%d\n"
|
||||||
"trunk_compress_binlog_min_interval=%d\n" \
|
"trunk_compress_binlog_interval=%d\n"
|
||||||
"trunk_compress_binlog_interval=%d\n" \
|
"trunk_compress_binlog_time_base=%02d:%02d\n"
|
||||||
"trunk_compress_binlog_time_base=%02d:%02d\n" \
|
"trunk_binlog_max_backups=%d\n"
|
||||||
"store_slave_file_use_link=%d\n", \
|
"store_slave_file_use_link=%d\n",
|
||||||
g_use_storage_id, g_id_type_in_filename == \
|
g_use_storage_id, g_id_type_in_filename ==
|
||||||
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip", \
|
FDFS_ID_TYPE_SERVER_ID ? "id" : "ip",
|
||||||
g_storage_ip_changed_auto_adjust, \
|
g_storage_ip_changed_auto_adjust,
|
||||||
g_storage_sync_file_max_delay, g_groups.store_path, \
|
g_storage_sync_file_max_delay, g_groups.store_path,
|
||||||
fdfs_storage_reserved_space_to_string( \
|
fdfs_storage_reserved_space_to_string(
|
||||||
&g_storage_reserved_space, reserved_space_str), \
|
&g_storage_reserved_space, reserved_space_str),
|
||||||
g_if_use_trunk_file, \
|
g_if_use_trunk_file,
|
||||||
g_slot_min_size, g_slot_max_size, \
|
g_slot_min_size, g_slot_max_size,
|
||||||
g_trunk_file_size, g_trunk_create_file_advance, \
|
g_trunk_file_size, g_trunk_create_file_advance,
|
||||||
g_trunk_create_file_time_base.hour, \
|
g_trunk_create_file_time_base.hour,
|
||||||
g_trunk_create_file_time_base.minute, \
|
g_trunk_create_file_time_base.minute,
|
||||||
g_trunk_create_file_interval, \
|
g_trunk_create_file_interval,
|
||||||
g_trunk_create_file_space_threshold, \
|
g_trunk_create_file_space_threshold,
|
||||||
g_trunk_init_check_occupying, \
|
g_trunk_init_check_occupying,
|
||||||
g_trunk_init_reload_from_binlog, \
|
g_trunk_init_reload_from_binlog,
|
||||||
g_trunk_compress_binlog_min_interval, \
|
g_trunk_compress_binlog_min_interval,
|
||||||
g_trunk_compress_binlog_interval, \
|
g_trunk_compress_binlog_interval,
|
||||||
g_trunk_compress_binlog_time_base.hour, \
|
g_trunk_compress_binlog_time_base.hour,
|
||||||
g_trunk_compress_binlog_time_base.minute, \
|
g_trunk_compress_binlog_time_base.minute,
|
||||||
|
g_trunk_binlog_max_backups,
|
||||||
g_store_slave_file_use_link);
|
g_store_slave_file_use_link);
|
||||||
|
|
||||||
|
pTask->length = sizeof(TrackerHeader) + body_len;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue