trunk_binlog_truncate delete trunk data file

pull/484/head
YuQing 2019-12-20 09:07:09 +08:00
parent 4a6f89c692
commit 13ba0963a3
6 changed files with 56 additions and 77 deletions

View File

@ -1,5 +1,5 @@
Version 6.05 2019-12-19
Version 6.05 2019-12-20
* fdfs_trackerd and fdfs_storaged print the server version in usage.
you can execute fdfs_trackerd or fdfs_storaged without parameters
to show the server version

View File

@ -4059,12 +4059,12 @@ static int storage_server_trunk_delete_binlog_marks(struct fast_task_info *pTask
}
result = storage_delete_trunk_data_file();
if (!(result == 0 || result == ENOENT))
if (result != 0)
{
return result;
}
return trunk_unlink_all_mark_files(false);
return trunk_unlink_all_mark_files();
}
/**

View File

@ -591,7 +591,7 @@ int storage_trunk_binlog_compress_check_recovery()
}
case STORAGE_TRUNK_COMPRESS_STAGE_COMPRESS_SUCCESS:
/* unlink all mark files because the binlog file be compressed */
result = trunk_unlink_all_mark_files(true);
result = trunk_unlink_all_mark_files();
if (result == 0)
{
g_trunk_binlog_compress_stage =
@ -693,7 +693,7 @@ static int storage_trunk_compress()
last_write_version = current_write_version;
/* unlink all mark files because the binlog file be compressed */
result = trunk_unlink_all_mark_files(true);
result = trunk_unlink_all_mark_files();
} while (0);
__sync_sub_and_fetch(&trunk_binlog_compress_in_progress, 1);
@ -1164,30 +1164,6 @@ static int storage_trunk_restore(const int64_t restore_offset)
return result;
}
int storage_delete_trunk_data_file()
{
char trunk_data_filename[MAX_PATH_SIZE];
int result;
storage_trunk_get_data_filename(trunk_data_filename);
if (unlink(trunk_data_filename) == 0)
{
return 0;
}
result = errno != 0 ? errno : ENOENT;
if (result != ENOENT)
{
logError("file: "__FILE__", line: %d, "
"unlink trunk data file: %s fail, "
"errno: %d, error info: %s",
__LINE__, trunk_data_filename,
result, STRERROR(result));
}
return result;
}
static int storage_trunk_load()
{
#define TRUNK_DATA_NEW_FIELD_COUNT 8 // >= v5.01

View File

@ -107,8 +107,6 @@ int trunk_binlog_compress_func(void *args);
int storage_trunk_binlog_compress_check_recovery();
int storage_delete_trunk_data_file();
char *storage_trunk_get_data_filename(char *full_filename);
#define storage_check_reserved_space(pGroup) \

View File

@ -387,7 +387,7 @@ int trunk_sync_notify_thread_reset_offset()
}
}
logError("file: "__FILE__", line: %d, "
logWarning("file: "__FILE__", line: %d, "
"%d trunk sync threads reset binlog offset timeout.",
__LINE__, count);
return EBUSY;
@ -516,13 +516,12 @@ static int trunk_binlog_delete_overflow_backups()
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;
over_count = (file_array.count - g_trunk_binlog_max_backups) + 1;
if (result != 0 || over_count <= 0)
{
if (file_array.files != NULL)
@ -539,7 +538,6 @@ static int trunk_binlog_delete_overflow_backups()
{
sprintf(full_filename, "%s/%s", file_path,
file_array.files[i].filename);
logInfo("unlink old file: %s", full_filename);
unlink(full_filename);
}
@ -592,6 +590,34 @@ static int trunk_binlog_backup_and_truncate()
return (result == 0) ? open_res : result;
}
int storage_delete_trunk_data_file()
{
char trunk_data_filename[MAX_PATH_SIZE];
int result;
storage_trunk_get_data_filename(trunk_data_filename);
if (unlink(trunk_data_filename) == 0)
{
return 0;
}
result = errno != 0 ? errno : ENOENT;
if (result == ENOENT)
{
result = 0;
}
else
{
logError("file: "__FILE__", line: %d, "
"unlink trunk data file: %s fail, "
"errno: %d, error info: %s",
__LINE__, trunk_data_filename,
result, STRERROR(result));
}
return result;
}
int trunk_binlog_truncate()
{
int result;
@ -626,6 +652,11 @@ int trunk_binlog_truncate()
} while (0);
pthread_mutex_unlock(&trunk_sync_thread_lock);
if (result == 0)
{
result = storage_delete_trunk_data_file();
}
return result;
}
@ -2453,11 +2484,10 @@ void trunk_waiting_sync_thread_exit()
}
}
int trunk_unlink_all_mark_files(const bool force_delete)
int trunk_unlink_all_mark_files()
{
char file_path[MAX_PATH_SIZE];
char old_filename[MAX_PATH_SIZE];
char new_filename[MAX_PATH_SIZE];
char full_filename[MAX_PATH_SIZE];
DIR *dir;
struct dirent *ent;
int result;
@ -2496,11 +2526,9 @@ int trunk_unlink_all_mark_files(const bool force_delete)
continue;
}
snprintf(old_filename, sizeof(old_filename), "%s/%s",
snprintf(full_filename, sizeof(full_filename), "%s/%s",
file_path, ent->d_name);
if (force_delete)
{
if (unlink(old_filename) != 0)
if (unlink(full_filename) != 0)
{
result = errno != 0 ? errno : EPERM;
if (result == ENOENT)
@ -2511,37 +2539,12 @@ int trunk_unlink_all_mark_files(const bool force_delete)
{
logError("file: "__FILE__", line: %d, "
"unlink %s fail, errno: %d, error info: %s",
__LINE__, old_filename,
__LINE__, full_filename,
result, STRERROR(result));
break;
}
}
}
else
{
snprintf(new_filename, sizeof(new_filename),
"%s.%04d%02d%02d%02d%02d%02d", old_filename,
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
if (rename(old_filename, new_filename) != 0)
{
result = errno != 0 ? errno : EPERM;
if (result == ENOENT)
{
result = 0;
}
else
{
logError("file: "__FILE__", line: %d, "
"rename file %s to %s fail, "
"errno: %d, error info: %s",
__LINE__, old_filename, new_filename,
result, STRERROR(result));
break;
}
}
}
}
closedir(dir);
return result;

View File

@ -65,7 +65,7 @@ void trunk_waiting_sync_thread_exit();
char *get_trunk_binlog_filename(char *full_filename);
char *trunk_mark_filename_by_reader(const void *pArg, char *full_filename);
int trunk_unlink_all_mark_files(const bool force_delete);
int trunk_unlink_all_mark_files();
int trunk_unlink_mark_file(const char *storage_id);
int trunk_rename_mark_file(const char *old_ip_addr, const int old_port, \
const char *new_ip_addr, const int new_port);
@ -88,6 +88,8 @@ int trunk_binlog_compress_rollback();
int trunk_sync_notify_thread_reset_offset();
int trunk_binlog_get_write_version();
int storage_delete_trunk_data_file();
char *get_trunk_binlog_tmp_filename_ex(const char *binlog_filename,
char *tmp_filename);