delete old log files, add parameter: log_file_keep_days

pull/48/head V5.04
yuqing 2014-09-16 15:46:41 +08:00
parent 05a4947b4a
commit f19daf51ee
11 changed files with 76 additions and 8 deletions

View File

@ -1,5 +1,5 @@
Version 5.04 2014-09-13 Version 5.04 2014-09-16
* add fastdfs.spec for build RPM on Linux * add fastdfs.spec for build RPM on Linux
* depend on libfastcommon * depend on libfastcommon
* in multi tracker servers case, when receive higher status like * 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 * fdfs_monitor support delete empty group
* bug fixed: two tracker leaders occur in rare case * bug fixed: two tracker leaders occur in rare case
* add connection stats * add connection stats
* delete old log files, add parameter: log_file_keep_days
Version 5.03 2014-08-10 Version 5.03 2014-08-10
* network send and recv retry when error EINTR happen * network send and recv retry when error EINTR happen

View File

@ -248,6 +248,11 @@ rotate_access_log_size = 0
# since V4.02 # since V4.02
rotate_error_log_size = 0 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 # if skip the invalid record when sync file
# default value is false # default value is false
# since V4.02 # since V4.02

View File

@ -228,6 +228,11 @@ error_log_rotate_time=00:00
# since V4.02 # since V4.02
rotate_error_log_size = 0 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 # if use connection pool
# default value is false # default value is false
# since V4.05 # since V4.05

View File

@ -76,7 +76,7 @@ static void sigSegvHandler(int signum, siginfo_t *info, void *ptr);
static void sigDumpHandler(int sig); static void sigDumpHandler(int sig);
#endif #endif
#define SCHEDULE_ENTRIES_MAX_COUNT 7 #define SCHEDULE_ENTRIES_MAX_COUNT 9
static void usage(const char *program) static void usage(const char *program)
{ {
@ -372,12 +372,27 @@ int main(int argc, char *argv[])
scheduleEntries[scheduleArray.count].func_args = \ scheduleEntries[scheduleArray.count].func_args = \
&g_access_log_context; &g_access_log_context;
scheduleArray.count++; 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) if (g_rotate_error_log)
{ {
scheduleEntries[scheduleArray.count].id = 7; scheduleEntries[scheduleArray.count].id = 8;
scheduleEntries[scheduleArray.count].time_base = \ scheduleEntries[scheduleArray.count].time_base = \
g_error_log_rotate_time; g_error_log_rotate_time;
scheduleEntries[scheduleArray.count].interval = \ scheduleEntries[scheduleArray.count].interval = \
@ -387,6 +402,20 @@ int main(int argc, char *argv[])
scheduleEntries[scheduleArray.count].func_args = \ scheduleEntries[scheduleArray.count].func_args = \
&g_log_context; &g_log_context;
scheduleArray.count++; 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, \ if ((result=sched_start(&scheduleArray, &schedule_tid, \

View File

@ -1627,6 +1627,9 @@ int storage_func_init(const char *filename, \
} }
g_log_context.rotate_size = rotate_error_log_size; 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, \ g_file_sync_skip_invalid_record = iniGetBoolValue(NULL, \
"file_sync_skip_invalid_record", &iniContext, false); "file_sync_skip_invalid_record", &iniContext, false);
@ -1695,6 +1698,7 @@ int storage_func_init(const char *filename, \
"error_log_rotate_time=%02d:%02d, " \ "error_log_rotate_time=%02d:%02d, " \
"rotate_access_log_size=%"PRId64", " \ "rotate_access_log_size=%"PRId64", " \
"rotate_error_log_size=%"PRId64", " \ "rotate_error_log_size=%"PRId64", " \
"log_file_keep_days=%d, " \
"file_sync_skip_invalid_record=%d, " \ "file_sync_skip_invalid_record=%d, " \
"use_connection_pool=%d, " \ "use_connection_pool=%d, " \
"g_connection_pool_max_idle_time=%ds", \ "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_rotate_error_log, g_error_log_rotate_time.hour, \
g_error_log_rotate_time.minute, \ g_error_log_rotate_time.minute, \
g_access_log_context.rotate_size, \ 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_file_sync_skip_invalid_record, \
g_use_connection_pool, g_connection_pool_max_idle_time); g_use_connection_pool, g_connection_pool_max_idle_time);

View File

@ -121,6 +121,7 @@ int g_http_trunk_size = 64 * 1024;
char g_exe_name[256] = {0}; char g_exe_name[256] = {0};
#endif #endif
int g_log_file_keep_days = 0;
struct storage_nio_thread_data *g_nio_thread_data = NULL; struct storage_nio_thread_data *g_nio_thread_data = NULL;
struct storage_dio_thread_data *g_dio_thread_data = NULL; struct storage_dio_thread_data *g_dio_thread_data = NULL;

View File

@ -168,6 +168,8 @@ extern int g_http_trunk_size;
extern char g_exe_name[256]; extern char g_exe_name[256];
#endif #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_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 extern struct storage_dio_thread_data *g_dio_thread_data; //disk io thread data

View File

@ -74,7 +74,7 @@ static void sigSegvHandler(int signum, siginfo_t *info, void *ptr);
static void sigDumpHandler(int sig); static void sigDumpHandler(int sig);
#endif #endif
#define SCHEDULE_ENTRIES_COUNT 4 #define SCHEDULE_ENTRIES_COUNT 5
static void usage(const char *program) static void usage(const char *program)
{ {
@ -349,6 +349,20 @@ int main(int argc, char *argv[])
scheduleEntries[scheduleArray.count].func_args = \ scheduleEntries[scheduleArray.count].func_args = \
&g_log_context; &g_log_context;
scheduleArray.count++; 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, \ if ((result=sched_start(&scheduleArray, &schedule_tid, \

View File

@ -606,6 +606,9 @@ int tracker_load_from_conf_file(const char *filename, \
} }
g_log_context.rotate_size = rotate_error_log_size; 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, \ g_store_slave_file_use_link = iniGetBoolValue(NULL, \
"store_slave_file_use_link", &iniContext, false); "store_slave_file_use_link", &iniContext, false);
@ -692,6 +695,7 @@ int tracker_load_from_conf_file(const char *filename, \
"rotate_error_log=%d, " \ "rotate_error_log=%d, " \
"error_log_rotate_time=%02d:%02d, " \ "error_log_rotate_time=%02d:%02d, " \
"rotate_error_log_size=%"PRId64", " \ "rotate_error_log_size=%"PRId64", " \
"log_file_keep_days=%d, " \
"store_slave_file_use_link=%d, " \ "store_slave_file_use_link=%d, " \
"use_connection_pool=%d, " \ "use_connection_pool=%d, " \
"g_connection_pool_max_idle_time=%ds", \ "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, \ FDFS_ID_TYPE_SERVER_ID ? "id" : "ip", g_storage_id_count, \
g_rotate_error_log, g_error_log_rotate_time.hour, \ g_rotate_error_log, g_error_log_rotate_time.hour, \
g_error_log_rotate_time.minute, \ 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); g_use_connection_pool, g_connection_pool_max_idle_time);
#ifdef WITH_HTTPD #ifdef WITH_HTTPD

View File

@ -73,5 +73,6 @@ bool g_http_servers_dirty = false;
char g_exe_name[256] = {0}; char g_exe_name[256] = {0};
#endif #endif
int g_log_file_keep_days = 0;
FDFSConnectionStat g_connection_stat = {0, 0}; FDFSConnectionStat g_connection_stat = {0, 0};

View File

@ -97,6 +97,7 @@ extern bool g_http_servers_dirty;
extern char g_exe_name[256]; extern char g_exe_name[256];
#endif #endif
extern int g_log_file_keep_days;
extern FDFSConnectionStat g_connection_stat; extern FDFSConnectionStat g_connection_stat;
#ifdef __cplusplus #ifdef __cplusplus