From f19daf51eeb021f0fcaa8770d49f76551a436cb1 Mon Sep 17 00:00:00 2001 From: yuqing Date: Tue, 16 Sep 2014 15:46:41 +0800 Subject: [PATCH] delete old log files, add parameter: log_file_keep_days --- HISTORY | 3 ++- conf/storage.conf | 5 +++++ conf/tracker.conf | 5 +++++ storage/fdfs_storaged.c | 37 +++++++++++++++++++++++++++++++++---- storage/storage_func.c | 6 +++++- storage/storage_global.c | 1 + storage/storage_global.h | 2 ++ tracker/fdfs_trackerd.c | 16 +++++++++++++++- tracker/tracker_func.c | 7 ++++++- tracker/tracker_global.c | 1 + tracker/tracker_global.h | 1 + 11 files changed, 76 insertions(+), 8 deletions(-) diff --git a/HISTORY b/HISTORY index 197c06e..569cca0 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 5.04 2014-09-13 +Version 5.04 2014-09-16 * add fastdfs.spec for build RPM on Linux * depend on libfastcommon * in multi tracker servers case, when receive higher status like @@ -9,6 +9,7 @@ Version 5.04 2014-09-13 * fdfs_monitor support delete empty group * bug fixed: two tracker leaders occur in rare case * add connection stats + * delete old log files, add parameter: log_file_keep_days Version 5.03 2014-08-10 * network send and recv retry when error EINTR happen diff --git a/conf/storage.conf b/conf/storage.conf index cd1f707..47fe053 100644 --- a/conf/storage.conf +++ b/conf/storage.conf @@ -248,6 +248,11 @@ rotate_access_log_size = 0 # since V4.02 rotate_error_log_size = 0 +# keep days of the log files +# 0 means do not delete old log files +# default value is 0 +log_file_keep_days = 0 + # if skip the invalid record when sync file # default value is false # since V4.02 diff --git a/conf/tracker.conf b/conf/tracker.conf index c7fe941..6427f13 100644 --- a/conf/tracker.conf +++ b/conf/tracker.conf @@ -228,6 +228,11 @@ error_log_rotate_time=00:00 # since V4.02 rotate_error_log_size = 0 +# keep days of the log files +# 0 means do not delete old log files +# default value is 0 +log_file_keep_days = 0 + # if use connection pool # default value is false # since V4.05 diff --git a/storage/fdfs_storaged.c b/storage/fdfs_storaged.c index 143551f..6ed81f1 100644 --- a/storage/fdfs_storaged.c +++ b/storage/fdfs_storaged.c @@ -76,7 +76,7 @@ static void sigSegvHandler(int signum, siginfo_t *info, void *ptr); static void sigDumpHandler(int sig); #endif -#define SCHEDULE_ENTRIES_MAX_COUNT 7 +#define SCHEDULE_ENTRIES_MAX_COUNT 9 static void usage(const char *program) { @@ -372,12 +372,27 @@ int main(int argc, char *argv[]) scheduleEntries[scheduleArray.count].func_args = \ &g_access_log_context; scheduleArray.count++; - } + + if (g_log_file_keep_days > 0) + { + log_set_keep_days(&g_access_log_context, + g_log_file_keep_days); + scheduleEntries[scheduleArray.count].id = 7; + scheduleEntries[scheduleArray.count].time_base.hour = 1; + scheduleEntries[scheduleArray.count].time_base.minute = 0; + scheduleEntries[scheduleArray.count].interval = 24 * 3600; + scheduleEntries[scheduleArray.count].task_func = + log_delete_old_files; + scheduleEntries[scheduleArray.count].func_args = + &g_access_log_context; + scheduleArray.count++; + } + } } if (g_rotate_error_log) { - scheduleEntries[scheduleArray.count].id = 7; + scheduleEntries[scheduleArray.count].id = 8; scheduleEntries[scheduleArray.count].time_base = \ g_error_log_rotate_time; scheduleEntries[scheduleArray.count].interval = \ @@ -387,7 +402,21 @@ int main(int argc, char *argv[]) scheduleEntries[scheduleArray.count].func_args = \ &g_log_context; scheduleArray.count++; - } + + if (g_log_file_keep_days > 0) + { + log_set_keep_days(&g_log_context, g_log_file_keep_days); + scheduleEntries[scheduleArray.count].id = 9; + scheduleEntries[scheduleArray.count].time_base.hour = 1; + scheduleEntries[scheduleArray.count].time_base.minute = 0; + scheduleEntries[scheduleArray.count].interval = 24 * 3600; + scheduleEntries[scheduleArray.count].task_func = + log_delete_old_files; + scheduleEntries[scheduleArray.count].func_args = + &g_log_context; + scheduleArray.count++; + } + } if ((result=sched_start(&scheduleArray, &schedule_tid, \ g_thread_stack_size, (bool * volatile)&g_continue_flag)) != 0) diff --git a/storage/storage_func.c b/storage/storage_func.c index 0f16112..b4d4e08 100644 --- a/storage/storage_func.c +++ b/storage/storage_func.c @@ -1627,6 +1627,9 @@ int storage_func_init(const char *filename, \ } g_log_context.rotate_size = rotate_error_log_size; + g_log_file_keep_days = iniGetIntValue(NULL, \ + "log_file_keep_days", &iniContext, 0); + g_file_sync_skip_invalid_record = iniGetBoolValue(NULL, \ "file_sync_skip_invalid_record", &iniContext, false); @@ -1695,6 +1698,7 @@ int storage_func_init(const char *filename, \ "error_log_rotate_time=%02d:%02d, " \ "rotate_access_log_size=%"PRId64", " \ "rotate_error_log_size=%"PRId64", " \ + "log_file_keep_days=%d, " \ "file_sync_skip_invalid_record=%d, " \ "use_connection_pool=%d, " \ "g_connection_pool_max_idle_time=%ds", \ @@ -1730,7 +1734,7 @@ int storage_func_init(const char *filename, \ g_rotate_error_log, g_error_log_rotate_time.hour, \ g_error_log_rotate_time.minute, \ g_access_log_context.rotate_size, \ - g_log_context.rotate_size, \ + g_log_context.rotate_size, g_log_file_keep_days, \ g_file_sync_skip_invalid_record, \ g_use_connection_pool, g_connection_pool_max_idle_time); diff --git a/storage/storage_global.c b/storage/storage_global.c index 6a5954f..53a660c 100644 --- a/storage/storage_global.c +++ b/storage/storage_global.c @@ -121,6 +121,7 @@ int g_http_trunk_size = 64 * 1024; char g_exe_name[256] = {0}; #endif +int g_log_file_keep_days = 0; struct storage_nio_thread_data *g_nio_thread_data = NULL; struct storage_dio_thread_data *g_dio_thread_data = NULL; diff --git a/storage/storage_global.h b/storage/storage_global.h index 2c180eb..de8d771 100644 --- a/storage/storage_global.h +++ b/storage/storage_global.h @@ -168,6 +168,8 @@ extern int g_http_trunk_size; extern char g_exe_name[256]; #endif +extern int g_log_file_keep_days; + extern struct storage_nio_thread_data *g_nio_thread_data; //network io thread data extern struct storage_dio_thread_data *g_dio_thread_data; //disk io thread data diff --git a/tracker/fdfs_trackerd.c b/tracker/fdfs_trackerd.c index a117fe9..b78574d 100644 --- a/tracker/fdfs_trackerd.c +++ b/tracker/fdfs_trackerd.c @@ -74,7 +74,7 @@ static void sigSegvHandler(int signum, siginfo_t *info, void *ptr); static void sigDumpHandler(int sig); #endif -#define SCHEDULE_ENTRIES_COUNT 4 +#define SCHEDULE_ENTRIES_COUNT 5 static void usage(const char *program) { @@ -349,6 +349,20 @@ int main(int argc, char *argv[]) scheduleEntries[scheduleArray.count].func_args = \ &g_log_context; scheduleArray.count++; + + if (g_log_file_keep_days > 0) + { + log_set_keep_days(&g_log_context, g_log_file_keep_days); + scheduleEntries[scheduleArray.count].id = 5; + scheduleEntries[scheduleArray.count].time_base.hour = 1; + scheduleEntries[scheduleArray.count].time_base.minute = 0; + scheduleEntries[scheduleArray.count].interval = 24 * 3600; + scheduleEntries[scheduleArray.count].task_func = + log_delete_old_files; + scheduleEntries[scheduleArray.count].func_args = + &g_log_context; + scheduleArray.count++; + } } if ((result=sched_start(&scheduleArray, &schedule_tid, \ diff --git a/tracker/tracker_func.c b/tracker/tracker_func.c index 89f919d..79f0ce7 100644 --- a/tracker/tracker_func.c +++ b/tracker/tracker_func.c @@ -606,6 +606,9 @@ int tracker_load_from_conf_file(const char *filename, \ } g_log_context.rotate_size = rotate_error_log_size; + g_log_file_keep_days = iniGetIntValue(NULL, \ + "log_file_keep_days", &iniContext, 0); + g_store_slave_file_use_link = iniGetBoolValue(NULL, \ "store_slave_file_use_link", &iniContext, false); @@ -692,6 +695,7 @@ int tracker_load_from_conf_file(const char *filename, \ "rotate_error_log=%d, " \ "error_log_rotate_time=%02d:%02d, " \ "rotate_error_log_size=%"PRId64", " \ + "log_file_keep_days=%d, " \ "store_slave_file_use_link=%d, " \ "use_connection_pool=%d, " \ "g_connection_pool_max_idle_time=%ds", \ @@ -725,7 +729,8 @@ int tracker_load_from_conf_file(const char *filename, \ FDFS_ID_TYPE_SERVER_ID ? "id" : "ip", g_storage_id_count, \ g_rotate_error_log, g_error_log_rotate_time.hour, \ g_error_log_rotate_time.minute, \ - g_log_context.rotate_size, g_store_slave_file_use_link, \ + g_log_context.rotate_size, g_log_file_keep_days, + g_store_slave_file_use_link, \ g_use_connection_pool, g_connection_pool_max_idle_time); #ifdef WITH_HTTPD diff --git a/tracker/tracker_global.c b/tracker/tracker_global.c index 624aebe..2061f46 100644 --- a/tracker/tracker_global.c +++ b/tracker/tracker_global.c @@ -73,5 +73,6 @@ bool g_http_servers_dirty = false; char g_exe_name[256] = {0}; #endif +int g_log_file_keep_days = 0; FDFSConnectionStat g_connection_stat = {0, 0}; diff --git a/tracker/tracker_global.h b/tracker/tracker_global.h index d50786c..16e37ad 100644 --- a/tracker/tracker_global.h +++ b/tracker/tracker_global.h @@ -97,6 +97,7 @@ extern bool g_http_servers_dirty; extern char g_exe_name[256]; #endif +extern int g_log_file_keep_days; extern FDFSConnectionStat g_connection_stat; #ifdef __cplusplus