From 3f77aa8f427661f5ccece06b0200cc0946b07802 Mon Sep 17 00:00:00 2001 From: yuqing Date: Tue, 12 May 2015 14:40:05 +0800 Subject: [PATCH 01/14] check item thread_stack_size in storage.conf --- HISTORY | 4 +++- fastdfs.spec | 2 +- storage/storage_func.c | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/HISTORY b/HISTORY index f837e5b..fa0cdb3 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,9 @@ -Version 5.06 2014-12-04 +Version 5.06 2015-05-12 * compile passed in mac OS Darwin * correct scripts in subdir init.d + * check item thread_stack_size in storage.conf, you must + upgrade libfastcommon to V1.14 or later Version 5.05 2014-11-22 * tracker_mem.c log more info diff --git a/fastdfs.spec b/fastdfs.spec index 0b9d047..aa61324 100644 --- a/fastdfs.spec +++ b/fastdfs.spec @@ -2,7 +2,7 @@ %define FDFSServer fastdfs-server %define FDFSClient libfdfsclient %define FDFSTool fastdfs-tool -%define FDFSVersion 5.0.5 +%define FDFSVersion 5.0.6 Name: %{FastDFS} Version: %{FDFSVersion} diff --git a/storage/storage_func.c b/storage/storage_func.c index bf03bc3..e8ddc0e 100644 --- a/storage/storage_func.c +++ b/storage/storage_func.c @@ -1530,12 +1530,12 @@ int storage_func_init(const char *filename, \ } g_thread_stack_size = (int)thread_stack_size; - if (g_thread_stack_size < 64 * 1024) + if (g_thread_stack_size < FAST_WRITE_BUFF_SIZE + 64 * 1024) { logError("file: "__FILE__", line: %d, " \ "item \"thread_stack_size\" %d is invalid, " \ "which < %d", __LINE__, g_thread_stack_size, \ - 64 * 1024); + FAST_WRITE_BUFF_SIZE + 64 * 1024); result = EINVAL; break; } @@ -2155,7 +2155,7 @@ int recv_file_serialized(int sock, const char *filename, \ const int64_t file_bytes) { int fd; - char buff[FDFS_WRITE_BUFF_SIZE]; + char buff[FAST_WRITE_BUFF_SIZE]; int64_t remain_bytes; int recv_bytes; int result; From d442cca980460b7e14ddf6bc6bf58af21e1d182d Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 22 May 2015 14:51:56 +0800 Subject: [PATCH 02/14] set require libfastcommon version in fastdfs.spec --- fastdfs.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastdfs.spec b/fastdfs.spec index aa61324..7da17d9 100644 --- a/fastdfs.spec +++ b/fastdfs.spec @@ -21,7 +21,7 @@ Requires: %__cp %__mv %__chmod %__grep %__mkdir %__install %__id This package provides tracker & storage of fastdfs %package -n %{FDFSServer} -Requires: libfastcommon +Requires: libfastcommon >= 1.0.14 Summary: fastdfs tracker & storage %package -n %{FDFSTool} From f0f2fbef904b2d12e5bd718d17eddff9589ab6ba Mon Sep 17 00:00:00 2001 From: yuqing Date: Wed, 22 Jul 2015 16:13:53 +0800 Subject: [PATCH 03/14] schedule task add the second field --- HISTORY | 4 ++++ fastdfs.spec | 2 +- make.sh | 20 +++++--------------- storage/fdfs_storaged.c | 7 +++++++ tracker/fdfs_trackerd.c | 4 ++++ tracker/tracker_global.c | 2 +- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/HISTORY b/HISTORY index fa0cdb3..24d03cc 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,8 @@ +Version 5.07 2015-07-22 + * schedule task add the "second" field + * make.sh changed, you must upgrade libfastcommon to V1.18 or later + Version 5.06 2015-05-12 * compile passed in mac OS Darwin * correct scripts in subdir init.d diff --git a/fastdfs.spec b/fastdfs.spec index 7da17d9..52ac3f2 100644 --- a/fastdfs.spec +++ b/fastdfs.spec @@ -2,7 +2,7 @@ %define FDFSServer fastdfs-server %define FDFSClient libfdfsclient %define FDFSTool fastdfs-tool -%define FDFSVersion 5.0.6 +%define FDFSVersion 5.0.7 Name: %{FastDFS} Version: %{FDFSVersion} diff --git a/make.sh b/make.sh index 503fcdd..9c75959 100755 --- a/make.sh +++ b/make.sh @@ -46,16 +46,6 @@ else OFF_BITS=32 fi -cat < common/_os_bits.h -#ifndef _OS_BITS_H -#define _OS_BITS_H - -#define OS_BITS $OS_BITS -#define OFF_BITS $OFF_BITS - -#endif -EOF - ENABLE_STATIC_LIB=0 ENABLE_SHARED_LIB=1 TARGET_PREFIX=$DESTDIR/usr @@ -82,21 +72,21 @@ fi uname=$(uname) if [ "$uname" = "Linux" ]; then - CFLAGS="$CFLAGS -DOS_LINUX -DIOEVENT_USE_EPOLL" + CFLAGS="$CFLAGS" elif [ "$uname" = "FreeBSD" ] || [ "$uname" = "Darwin" ]; then - CFLAGS="$CFLAGS -DOS_FREEBSD -DIOEVENT_USE_KQUEUE" + CFLAGS="$CFLAGS" if [ "$uname" = "Darwin" ]; then CFLAGS="$CFLAGS -DDARWIN" fi elif [ "$uname" = "SunOS" ]; then - CFLAGS="$CFLAGS -DOS_SUNOS -D_THREAD_SAFE -DIOEVENT_USE_PORT" + CFLAGS="$CFLAGS -D_THREAD_SAFE" LIBS="$LIBS -lsocket -lnsl -lresolv" export CC=gcc elif [ "$uname" = "AIX" ]; then - CFLAGS="$CFLAGS -DOS_AIX -D_THREAD_SAFE" + CFLAGS="$CFLAGS -D_THREAD_SAFE" export CC=gcc elif [ "$uname" = "HP-UX" ]; then - CFLAGS="$CFLAGS -DOS_HPUX" + CFLAGS="$CFLAGS" fi have_pthread=0 diff --git a/storage/fdfs_storaged.c b/storage/fdfs_storaged.c index 6ed81f1..7ad74df 100644 --- a/storage/fdfs_storaged.c +++ b/storage/fdfs_storaged.c @@ -317,6 +317,7 @@ int main(int argc, char *argv[]) scheduleEntries[0].id = 1; scheduleEntries[0].time_base.hour = TIME_NONE; scheduleEntries[0].time_base.minute = TIME_NONE; + scheduleEntries[0].time_base.second = TIME_NONE; scheduleEntries[0].interval = g_sync_log_buff_interval; scheduleEntries[0].task_func = log_sync_func; scheduleEntries[0].func_args = &g_log_context; @@ -324,6 +325,7 @@ int main(int argc, char *argv[]) scheduleEntries[1].id = 2; scheduleEntries[1].time_base.hour = TIME_NONE; scheduleEntries[1].time_base.minute = TIME_NONE; + scheduleEntries[1].time_base.second = TIME_NONE; scheduleEntries[1].interval = g_sync_binlog_buff_interval; scheduleEntries[1].task_func = fdfs_binlog_sync_func; scheduleEntries[1].func_args = NULL; @@ -331,6 +333,7 @@ int main(int argc, char *argv[]) scheduleEntries[2].id = 3; scheduleEntries[2].time_base.hour = TIME_NONE; scheduleEntries[2].time_base.minute = TIME_NONE; + scheduleEntries[2].time_base.second = TIME_NONE; scheduleEntries[2].interval = g_sync_stat_file_interval; scheduleEntries[2].task_func = fdfs_stat_file_sync_func; scheduleEntries[2].func_args = NULL; @@ -341,6 +344,7 @@ int main(int argc, char *argv[]) scheduleEntries[scheduleArray.count].id = 4; scheduleEntries[scheduleArray.count].time_base.hour = TIME_NONE; scheduleEntries[scheduleArray.count].time_base.minute=TIME_NONE; + scheduleEntries[scheduleArray.count].time_base.second=TIME_NONE; scheduleEntries[scheduleArray.count].interval = 1; scheduleEntries[scheduleArray.count].task_func = \ trunk_binlog_sync_func; @@ -353,6 +357,7 @@ int main(int argc, char *argv[]) scheduleEntries[scheduleArray.count].id = 5; scheduleEntries[scheduleArray.count].time_base.hour = TIME_NONE; scheduleEntries[scheduleArray.count].time_base.minute=TIME_NONE; + scheduleEntries[scheduleArray.count].time_base.second=TIME_NONE; scheduleEntries[scheduleArray.count].interval = \ g_sync_log_buff_interval; scheduleEntries[scheduleArray.count].task_func = log_sync_func; @@ -380,6 +385,7 @@ int main(int argc, char *argv[]) scheduleEntries[scheduleArray.count].id = 7; scheduleEntries[scheduleArray.count].time_base.hour = 1; scheduleEntries[scheduleArray.count].time_base.minute = 0; + scheduleEntries[scheduleArray.count].time_base.second = 0; scheduleEntries[scheduleArray.count].interval = 24 * 3600; scheduleEntries[scheduleArray.count].task_func = log_delete_old_files; @@ -409,6 +415,7 @@ int main(int argc, char *argv[]) scheduleEntries[scheduleArray.count].id = 9; scheduleEntries[scheduleArray.count].time_base.hour = 1; scheduleEntries[scheduleArray.count].time_base.minute = 0; + scheduleEntries[scheduleArray.count].time_base.second = 0; scheduleEntries[scheduleArray.count].interval = 24 * 3600; scheduleEntries[scheduleArray.count].task_func = log_delete_old_files; diff --git a/tracker/fdfs_trackerd.c b/tracker/fdfs_trackerd.c index b78574d..f2f3605 100644 --- a/tracker/fdfs_trackerd.c +++ b/tracker/fdfs_trackerd.c @@ -317,6 +317,7 @@ int main(int argc, char *argv[]) scheduleEntries[0].id = 1; scheduleEntries[0].time_base.hour = TIME_NONE; scheduleEntries[0].time_base.minute = TIME_NONE; + scheduleEntries[0].time_base.second = TIME_NONE; scheduleEntries[0].interval = g_sync_log_buff_interval; scheduleEntries[0].task_func = log_sync_func; scheduleEntries[0].func_args = &g_log_context; @@ -324,6 +325,7 @@ int main(int argc, char *argv[]) scheduleEntries[1].id = 2; scheduleEntries[1].time_base.hour = TIME_NONE; scheduleEntries[1].time_base.minute = TIME_NONE; + scheduleEntries[1].time_base.second = TIME_NONE; scheduleEntries[1].interval = g_check_active_interval; scheduleEntries[1].task_func = tracker_mem_check_alive; scheduleEntries[1].func_args = NULL; @@ -331,6 +333,7 @@ int main(int argc, char *argv[]) scheduleEntries[2].id = 3; scheduleEntries[2].time_base.hour = 0; scheduleEntries[2].time_base.minute = 0; + scheduleEntries[2].time_base.second = 0; scheduleEntries[2].interval = TRACKER_SYNC_STATUS_FILE_INTERVAL; scheduleEntries[2].task_func = tracker_write_status_to_file; scheduleEntries[2].func_args = NULL; @@ -356,6 +359,7 @@ int main(int argc, char *argv[]) scheduleEntries[scheduleArray.count].id = 5; scheduleEntries[scheduleArray.count].time_base.hour = 1; scheduleEntries[scheduleArray.count].time_base.minute = 0; + scheduleEntries[scheduleArray.count].time_base.second = 0; scheduleEntries[scheduleArray.count].interval = 24 * 3600; scheduleEntries[scheduleArray.count].task_func = log_delete_old_files; diff --git a/tracker/tracker_global.c b/tracker/tracker_global.c index ab12f08..cbff568 100644 --- a/tracker/tracker_global.c +++ b/tracker/tracker_global.c @@ -37,7 +37,7 @@ bool g_storage_ip_changed_auto_adjust = true; bool g_use_storage_id = false; //if use storage ID instead of IP address byte g_id_type_in_filename = FDFS_ID_TYPE_IP_ADDRESS; //id type of the storage server in the filename bool g_rotate_error_log = false; //if rotate the error log every day -TimeInfo g_error_log_rotate_time = {0, 0}; //rotate error log time base +TimeInfo g_error_log_rotate_time = {0, 0, 0}; //rotate error log time base int g_thread_stack_size = 64 * 1024; int g_storage_sync_file_max_delay = DEFAULT_STORAGE_SYNC_FILE_MAX_DELAY; From 70aa4378ea02e88b1053e444fc74abe74c0bfd85 Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 24 Jul 2015 16:24:08 +0800 Subject: [PATCH 04/14] Requires: libfastcommon >= 1.0.18 --- fastdfs.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastdfs.spec b/fastdfs.spec index 52ac3f2..783f3f9 100644 --- a/fastdfs.spec +++ b/fastdfs.spec @@ -21,7 +21,7 @@ Requires: %__cp %__mv %__chmod %__grep %__mkdir %__install %__id This package provides tracker & storage of fastdfs %package -n %{FDFSServer} -Requires: libfastcommon >= 1.0.14 +Requires: libfastcommon >= 1.0.18 Summary: fastdfs tracker & storage %package -n %{FDFSTool} From 10d96d407d753b7901953a4623dea5207a283216 Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 7 Aug 2015 09:19:50 +0800 Subject: [PATCH 05/14] compile library add -lm --- HISTORY | 4 ++-- common/fdfs_global.c | 2 +- make.sh | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index 24d03cc..0857961 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,7 @@ -Version 5.07 2015-07-22 +Version 5.07 2015-08-07 * schedule task add the "second" field - * make.sh changed, you must upgrade libfastcommon to V1.18 or later + * make.sh changed, you must upgrade libfastcommon to V1.20 or later Version 5.06 2015-05-12 * compile passed in mac OS Darwin diff --git a/common/fdfs_global.c b/common/fdfs_global.c index de09df6..69bcf62 100644 --- a/common/fdfs_global.c +++ b/common/fdfs_global.c @@ -23,7 +23,7 @@ int g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT; int g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT; char g_fdfs_base_path[MAX_PATH_SIZE] = {'/', 't', 'm', 'p', '\0'}; -Version g_fdfs_version = {5, 6}; +Version g_fdfs_version = {5, 7}; bool g_use_connection_pool = false; ConnectionPool g_connection_pool; int g_connection_pool_max_idle_time = 3600; diff --git a/make.sh b/make.sh index 9c75959..70649be 100755 --- a/make.sh +++ b/make.sh @@ -63,11 +63,11 @@ else CFLAGS="$CFLAGS -O3" fi -LIBS='' +LIBS='-lm' if [ $OS_BITS -eq 64 ]; then - LIBS='-L/usr/lib64' + LIBS="$LIBS -L/usr/lib64" else - LIBS='-L/usr/lib' + LIBS="$LIBS -L/usr/lib" fi uname=$(uname) From 52331c9b3b2cd7eb4393ef079a9871650f4e21f9 Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 7 Aug 2015 09:22:19 +0800 Subject: [PATCH 06/14] delete file common/_os_bits.h --- common/_os_bits.h | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 common/_os_bits.h diff --git a/common/_os_bits.h b/common/_os_bits.h deleted file mode 100644 index 81e1626..0000000 --- a/common/_os_bits.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _OS_BITS_H -#define _OS_BITS_H - -#define OS_BITS 64 -#define OFF_BITS 64 - -#endif From 7eed14951172e7d049ea923ae8c34d4e4216b684 Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 7 Aug 2015 09:56:25 +0800 Subject: [PATCH 07/14] compile library remove -lm --- make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.sh b/make.sh index 70649be..ee0493a 100755 --- a/make.sh +++ b/make.sh @@ -63,7 +63,7 @@ else CFLAGS="$CFLAGS -O3" fi -LIBS='-lm' +LIBS='' if [ $OS_BITS -eq 64 ]; then LIBS="$LIBS -L/usr/lib64" else From 41581aae6b7fd8aa29c220aa6568a98113265879 Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 14 Aug 2015 17:08:21 +0800 Subject: [PATCH 08/14] bug fixed: storage_disk_recovery.c skip the first file (binlog first line) --- HISTORY | 3 ++- fastdfs.spec | 2 +- storage/storage_disk_recovery.c | 43 ++++++++++++++++++++++++++++----- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/HISTORY b/HISTORY index 0857961..f8bf7f4 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,8 @@ -Version 5.07 2015-08-07 +Version 5.07 2015-08-14 * schedule task add the "second" field * make.sh changed, you must upgrade libfastcommon to V1.20 or later + * bug fixed: storage_disk_recovery.c skip the first file (binlog first line) Version 5.06 2015-05-12 * compile passed in mac OS Darwin diff --git a/fastdfs.spec b/fastdfs.spec index 783f3f9..fe28c5f 100644 --- a/fastdfs.spec +++ b/fastdfs.spec @@ -21,7 +21,7 @@ Requires: %__cp %__mv %__chmod %__grep %__mkdir %__install %__id This package provides tracker & storage of fastdfs %package -n %{FDFSServer} -Requires: libfastcommon >= 1.0.18 +Requires: libfastcommon >= 1.0.20 Summary: fastdfs tracker & storage %package -n %{FDFSTool} diff --git a/storage/storage_disk_recovery.c b/storage/storage_disk_recovery.c index 0d9cc79..2646891 100644 --- a/storage/storage_disk_recovery.c +++ b/storage/storage_disk_recovery.c @@ -497,6 +497,17 @@ static int recovery_reader_init(const char *pBasePath, \ return 0; } +static int recovery_reader_check_init(const char *pBasePath, \ + StorageBinLogReader *pReader) +{ + if (pReader->binlog_fd >= 0 && pReader->binlog_buff.buffer != NULL) + { + return 0; + } + + return recovery_reader_init(pBasePath, pReader); +} + static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pReader, \ ConnectionInfo *pSrcStorage) { @@ -512,6 +523,7 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead int64_t file_size; int64_t total_count; int64_t success_count; + int64_t noent_count; bool bContinueFlag; char local_filename[MAX_PATH_SIZE]; char src_filename[MAX_PATH_SIZE]; @@ -520,6 +532,7 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead count = 0; total_count = 0; success_count = 0; + noent_count = 0; result = 0; logInfo("file: "__FILE__", line: %d, " \ @@ -529,6 +542,10 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead bContinueFlag = true; while (bContinueFlag) { + if ((result=recovery_reader_check_init(pBasePath, pReader)) != 0) + { + break; + } if ((pStorageConn=tracker_connect_server(pSrcStorage, &result)) == NULL) { sleep(5); @@ -605,8 +622,13 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead success_count++; } - else if (result != ENOENT) + else if (result == ENOENT) { + result = 0; + noent_count++; + } + else + { break; } } @@ -673,6 +695,10 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead bContinueFlag = false; break; } + else + { + result = 0; + } } } else @@ -692,25 +718,30 @@ static int storage_do_recovery(const char *pBasePath, StorageBinLogReader *pRead logDebug("file: "__FILE__", line: %d, " \ "disk recovery: recover path: %s, " \ "file count: %"PRId64 \ - ", success count: %"PRId64, \ + ", success count: %"PRId64", noent_count: %"PRId64, \ __LINE__, pBasePath, total_count, \ - success_count); + success_count, noent_count); recovery_write_to_mark_file(pBasePath, pReader); count = 0; } } tracker_disconnect_server_ex(pStorageConn, result != 0); + recovery_write_to_mark_file(pBasePath, pReader); + if (bContinueFlag) + { + storage_reader_destroy(pReader); + } + if (count > 0) { - recovery_write_to_mark_file(pBasePath, pReader); count = 0; logInfo("file: "__FILE__", line: %d, " \ "disk recovery: recover path: %s, " \ "file count: %"PRId64 \ - ", success count: %"PRId64, \ - __LINE__, pBasePath, total_count, success_count); + ", success count: %"PRId64", noent_count: %"PRId64, \ + __LINE__, pBasePath, total_count, success_count, noent_count); } else { From f46f8bfb0b4ef31f42fb33b078cd113bd7f871d4 Mon Sep 17 00:00:00 2001 From: yuqing Date: Sat, 15 Aug 2015 10:32:13 +0800 Subject: [PATCH 09/14] should close connection after fetch binlog --- storage/storage_disk_recovery.c | 2 +- storage/storage_service.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/storage_disk_recovery.c b/storage/storage_disk_recovery.c index 2646891..9c5445c 100644 --- a/storage/storage_disk_recovery.c +++ b/storage/storage_disk_recovery.c @@ -1117,7 +1117,7 @@ int storage_disk_recovery_start(const int store_path_index) } result = storage_do_fetch_binlog(pStorageConn, store_path_index); - tracker_disconnect_server_ex(pStorageConn, result != 0); + tracker_disconnect_server(pStorageConn, true); if (result != 0) { return result; diff --git a/storage/storage_service.c b/storage/storage_service.c index 77bffb6..0a734eb 100644 --- a/storage/storage_service.c +++ b/storage/storage_service.c @@ -4268,6 +4268,7 @@ static int storage_server_do_fetch_one_path_binlog( \ if ((result=storage_reader_init(NULL, pReader)) != 0) { storage_reader_destroy(pReader); + free(pReader); return result; } From 2b5d703542d11e9276518399c86ab97dc00a2091 Mon Sep 17 00:00:00 2001 From: yuqing Date: Sat, 15 Aug 2015 10:43:46 +0800 Subject: [PATCH 10/14] fdfs_storaged.c: advance the position of daemon_init --- HISTORY | 4 +++- storage/fdfs_storaged.c | 5 +++-- storage/storage_disk_recovery.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/HISTORY b/HISTORY index f8bf7f4..0df7ff1 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,10 @@ -Version 5.07 2015-08-14 +Version 5.07 2015-08-15 * schedule task add the "second" field * make.sh changed, you must upgrade libfastcommon to V1.20 or later * bug fixed: storage_disk_recovery.c skip the first file (binlog first line) + * bug fixed: should close connection after fetch binlog + * fdfs_storaged.c: advance the position of daemon_init Version 5.06 2015-05-12 * compile passed in mac OS Darwin diff --git a/storage/fdfs_storaged.c b/storage/fdfs_storaged.c index 7ad74df..7cf38bd 100644 --- a/storage/fdfs_storaged.c +++ b/storage/fdfs_storaged.c @@ -144,6 +144,9 @@ int main(int argc, char *argv[]) } #endif + daemon_init(false); + umask(0); + memset(g_bind_addr, 0, sizeof(g_bind_addr)); if ((result=storage_func_init(conf_filename, \ g_bind_addr, sizeof(g_bind_addr))) != 0) @@ -168,8 +171,6 @@ int main(int argc, char *argv[]) return result; } - daemon_init(false); - umask(0); if ((result=write_to_pid_file(pidFilename)) != 0) { log_destroy(); diff --git a/storage/storage_disk_recovery.c b/storage/storage_disk_recovery.c index 9c5445c..859c34d 100644 --- a/storage/storage_disk_recovery.c +++ b/storage/storage_disk_recovery.c @@ -1117,7 +1117,7 @@ int storage_disk_recovery_start(const int store_path_index) } result = storage_do_fetch_binlog(pStorageConn, store_path_index); - tracker_disconnect_server(pStorageConn, true); + tracker_disconnect_server_ex(pStorageConn, true); if (result != 0) { return result; From c25d3a7d01cf75dec2345e2f59b43de90e27f5cc Mon Sep 17 00:00:00 2001 From: yuqing Date: Sun, 16 Aug 2015 11:20:38 +0800 Subject: [PATCH 11/14] set log rotate time format --- HISTORY | 3 ++- storage/storage_func.c | 6 +++--- tracker/fdfs_shared_func.c | 14 ++++++++++++++ tracker/fdfs_shared_func.h | 3 +++ tracker/tracker_func.c | 4 ++-- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index 0df7ff1..b0a836a 100644 --- a/HISTORY +++ b/HISTORY @@ -1,10 +1,11 @@ -Version 5.07 2015-08-15 +Version 5.07 2015-08-16 * schedule task add the "second" field * make.sh changed, you must upgrade libfastcommon to V1.20 or later * bug fixed: storage_disk_recovery.c skip the first file (binlog first line) * bug fixed: should close connection after fetch binlog * fdfs_storaged.c: advance the position of daemon_init + * set log rotate time format Version 5.06 2015-05-12 * compile passed in mac OS Darwin diff --git a/storage/storage_func.c b/storage/storage_func.c index e8ddc0e..dc893ba 100644 --- a/storage/storage_func.c +++ b/storage/storage_func.c @@ -1684,7 +1684,7 @@ int storage_func_init(const char *filename, \ break; } if (rotate_access_log_size > 0 && \ - rotate_access_log_size< FDFS_ONE_MB) + rotate_access_log_size < FDFS_ONE_MB) { logWarning("file: "__FILE__", line: %d, " \ "item \"rotate_access_log_size\": " \ @@ -1693,7 +1693,7 @@ int storage_func_init(const char *filename, \ rotate_access_log_size); rotate_access_log_size = FDFS_ONE_MB; } - g_access_log_context.rotate_size = rotate_access_log_size; + fdfs_set_log_rotate_size(&g_access_log_context, rotate_access_log_size); pRotateErrorLogSize = iniGetStrValue(NULL, \ "rotate_error_log_size", &iniContext); @@ -1716,7 +1716,7 @@ int storage_func_init(const char *filename, \ rotate_error_log_size); rotate_error_log_size = FDFS_ONE_MB; } - g_log_context.rotate_size = rotate_error_log_size; + fdfs_set_log_rotate_size(&g_log_context, rotate_error_log_size); g_log_file_keep_days = iniGetIntValue(NULL, \ "log_file_keep_days", &iniContext, 0); diff --git a/tracker/fdfs_shared_func.c b/tracker/fdfs_shared_func.c index c0f0c58..c3260f1 100644 --- a/tracker/fdfs_shared_func.c +++ b/tracker/fdfs_shared_func.c @@ -1016,3 +1016,17 @@ void fdfs_connection_pool_destroy() conn_pool_destroy(&g_connection_pool); } +void fdfs_set_log_rotate_size(LogContext *pContext, const int64_t log_rotate_size) +{ + if (log_rotate_size > 0) + { + pContext->rotate_size = log_rotate_size; + log_set_rotate_time_format(pContext, "%Y%m%d_%H%M%S"); + } + else + { + pContext->rotate_size = 0; + log_set_rotate_time_format(pContext, "%Y%m%d"); + } +} + diff --git a/tracker/fdfs_shared_func.h b/tracker/fdfs_shared_func.h index d40c5f0..899bf5d 100644 --- a/tracker/fdfs_shared_func.h +++ b/tracker/fdfs_shared_func.h @@ -13,6 +13,7 @@ #include "common_define.h" #include "ini_file_reader.h" +#include "logger.h" #include "tracker_types.h" #ifdef __cplusplus @@ -77,6 +78,8 @@ int fdfs_connection_pool_init(const char *config_filename, \ void fdfs_connection_pool_destroy(); +void fdfs_set_log_rotate_size(LogContext *pContext, const int64_t log_rotate_size); + #ifdef __cplusplus } #endif diff --git a/tracker/tracker_func.c b/tracker/tracker_func.c index 3dd814a..cefbf78 100644 --- a/tracker/tracker_func.c +++ b/tracker/tracker_func.c @@ -603,7 +603,7 @@ int tracker_load_from_conf_file(const char *filename, \ rotate_error_log_size); rotate_error_log_size = FDFS_ONE_MB; } - g_log_context.rotate_size = rotate_error_log_size; + fdfs_set_log_rotate_size(&g_log_context, rotate_error_log_size); g_log_file_keep_days = iniGetIntValue(NULL, \ "log_file_keep_days", &iniContext, 0); @@ -729,7 +729,7 @@ int tracker_load_from_conf_file(const char *filename, \ g_rotate_error_log, g_error_log_rotate_time.hour, \ g_error_log_rotate_time.minute, \ 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); #ifdef WITH_HTTPD From d1ba6c61db064a5cb56fd2931d97bc33b5688b8e Mon Sep 17 00:00:00 2001 From: yuqing Date: Mon, 17 Aug 2015 14:19:48 +0800 Subject: [PATCH 12/14] bug fixed: must check store_path_index --- HISTORY | 3 ++- storage/storage_service.c | 19 +++++++++++++++++++ storage/trunk_mgr/trunk_mem.c | 12 ++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index b0a836a..87bae49 100644 --- a/HISTORY +++ b/HISTORY @@ -1,11 +1,12 @@ -Version 5.07 2015-08-16 +Version 5.07 2015-08-17 * schedule task add the "second" field * make.sh changed, you must upgrade libfastcommon to V1.20 or later * bug fixed: storage_disk_recovery.c skip the first file (binlog first line) * bug fixed: should close connection after fetch binlog * fdfs_storaged.c: advance the position of daemon_init * set log rotate time format + * bug fixed: must check store_path_index Version 5.06 2015-05-12 * compile passed in mac OS Darwin diff --git a/storage/storage_service.c b/storage/storage_service.c index 0a734eb..fc47660 100644 --- a/storage/storage_service.c +++ b/storage/storage_service.c @@ -3758,6 +3758,15 @@ static int storage_server_trunk_alloc_space(struct fast_task_info *pTask) } trunkInfo.path.store_path_index = *(in_buff+FDFS_GROUP_NAME_MAX_LEN+4); + if (trunkInfo.path.store_path_index < 0 || + trunkInfo.path.store_path_index >= g_fdfs_store_paths.count) + { + logError("file: "__FILE__", line: %d, " \ + "client ip: %s, store_path_index: %d " \ + "is invalid", __LINE__, \ + pTask->client_ip, trunkInfo.path.store_path_index); + return EINVAL; + } if ((result=trunk_alloc_space(file_size, &trunkInfo)) != 0) { return result; @@ -3981,6 +3990,16 @@ static int storage_server_trunk_confirm_or_free(struct fast_task_info *pTask) trunkInfo.file.offset = buff2int(pTrunkBuff->offset); trunkInfo.file.size = buff2int(pTrunkBuff->size); + if (trunkInfo.path.store_path_index < 0 || + trunkInfo.path.store_path_index >= g_fdfs_store_paths.count) + { + logError("file: "__FILE__", line: %d, " \ + "client ip: %s, store_path_index: %d " \ + "is invalid", __LINE__, \ + pTask->client_ip, trunkInfo.path.store_path_index); + return EINVAL; + } + if (pHeader->cmd == STORAGE_PROTO_CMD_TRUNK_ALLOC_CONFIRM) { return trunk_alloc_confirm(&trunkInfo, pHeader->status); diff --git a/storage/trunk_mgr/trunk_mem.c b/storage/trunk_mgr/trunk_mem.c index f3f848c..4dec99f 100644 --- a/storage/trunk_mgr/trunk_mem.c +++ b/storage/trunk_mgr/trunk_mem.c @@ -750,6 +750,15 @@ static int storage_trunk_restore(const int64_t restore_offset) break; } + if (record.trunk.path.store_path_index < 0 || + record.trunk.path.store_path_index >= g_fdfs_store_paths.count) + { + logError("file: "__FILE__", line: %d, " \ + "store_path_index: %d is invalid", __LINE__, \ + record.trunk.path.store_path_index); + return EINVAL; + } + line_count++; if (record.op_type == TRUNK_OP_TYPE_ADD_SPACE) { @@ -784,8 +793,7 @@ static int storage_trunk_restore(const int64_t restore_offset) logError("file: "__FILE__", line: %d, "\ "avl_tree_insert fail, " \ "errno: %d, error info: %s", \ - __LINE__, result, \ - STRERROR(result)); + __LINE__, result, STRERROR(result)); return result; } else if (result == 0) From dc3e9b26c8da3921e3f7763ff7809c07a3de6529 Mon Sep 17 00:00:00 2001 From: yuqing Date: Sat, 5 Sep 2015 19:45:42 +0800 Subject: [PATCH 13/14] use libfastcommon v1.21 --- HISTORY | 4 ++-- conf/storage.conf | 7 +++++-- conf/tracker.conf | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index 87bae49..80c8264 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,7 @@ -Version 5.07 2015-08-17 +Version 5.07 2015-09-05 * schedule task add the "second" field - * make.sh changed, you must upgrade libfastcommon to V1.20 or later + * make.sh changed, you must upgrade libfastcommon to V1.21 or later * bug fixed: storage_disk_recovery.c skip the first file (binlog first line) * bug fixed: should close connection after fetch binlog * fdfs_storaged.c: advance the position of daemon_init diff --git a/conf/storage.conf b/conf/storage.conf index e93a071..5b98ae9 100644 --- a/conf/storage.conf +++ b/conf/storage.conf @@ -137,10 +137,13 @@ run_by_group= run_by_user= # allow_hosts can ocur more than once, host can be hostname or ip address, -# "*" means match all ip addresses, can use range like this: 10.0.1.[1-15,20] or -# host[01-08,20-25].domain.com, for example: +# "*" (only one asterisk) means match all ip addresses +# we can use CIDR ips like 192.168.5.64/26 +# and also use range like these: 10.0.1.[0-254] and host[01-08,20-25].domain.com +# for example: # allow_hosts=10.0.1.[1-15,20] # allow_hosts=host[01-08,20-25].domain.com +# allow_hosts=192.168.5.64/26 allow_hosts=* # the mode of the files distributed to the data path diff --git a/conf/tracker.conf b/conf/tracker.conf index 6427f13..9925a16 100644 --- a/conf/tracker.conf +++ b/conf/tracker.conf @@ -92,10 +92,13 @@ run_by_group= run_by_user= # allow_hosts can ocur more than once, host can be hostname or ip address, -# "*" means match all ip addresses, can use range like this: 10.0.1.[1-15,20] or -# host[01-08,20-25].domain.com, for example: +# "*" (only one asterisk) means match all ip addresses +# we can use CIDR ips like 192.168.5.64/26 +# and also use range like these: 10.0.1.[0-254] and host[01-08,20-25].domain.com +# for example: # allow_hosts=10.0.1.[1-15,20] # allow_hosts=host[01-08,20-25].domain.com +# allow_hosts=192.168.5.64/26 allow_hosts=* # sync log buff to disk every interval seconds From 7d1d0d56a3f8f5b9ab32c135acd30358d175a54c Mon Sep 17 00:00:00 2001 From: yuqing Date: Sun, 13 Sep 2015 19:27:44 +0800 Subject: [PATCH 14/14] use INIT_SCHEDULE_ENTRY --- HISTORY | 2 +- fastdfs.spec | 3 +- storage/fdfs_storaged.c | 136 ++++++++++++++-------------------------- tracker/fdfs_trackerd.c | 71 ++++++++------------- 4 files changed, 76 insertions(+), 136 deletions(-) diff --git a/HISTORY b/HISTORY index 80c8264..97af527 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 5.07 2015-09-05 +Version 5.07 2015-09-13 * schedule task add the "second" field * make.sh changed, you must upgrade libfastcommon to V1.21 or later * bug fixed: storage_disk_recovery.c skip the first file (binlog first line) diff --git a/fastdfs.spec b/fastdfs.spec index fe28c5f..f0c6e1c 100644 --- a/fastdfs.spec +++ b/fastdfs.spec @@ -16,12 +16,13 @@ Source: http://perso.orange.fr/sebastien.godard/%{name}-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Requires: %__cp %__mv %__chmod %__grep %__mkdir %__install %__id +BuildRequires: libfastcommon-devel >= 1.0.21 %description This package provides tracker & storage of fastdfs %package -n %{FDFSServer} -Requires: libfastcommon >= 1.0.20 +Requires: libfastcommon >= 1.0.21 Summary: fastdfs tracker & storage %package -n %{FDFSTool} diff --git a/storage/fdfs_storaged.c b/storage/fdfs_storaged.c index 7cf38bd..41520bf 100644 --- a/storage/fdfs_storaged.c +++ b/storage/fdfs_storaged.c @@ -313,118 +313,76 @@ int main(int argc, char *argv[]) } scheduleArray.entries = scheduleEntries; - + scheduleArray.count = 0; memset(scheduleEntries, 0, sizeof(scheduleEntries)); - scheduleEntries[0].id = 1; - scheduleEntries[0].time_base.hour = TIME_NONE; - scheduleEntries[0].time_base.minute = TIME_NONE; - scheduleEntries[0].time_base.second = TIME_NONE; - scheduleEntries[0].interval = g_sync_log_buff_interval; - scheduleEntries[0].task_func = log_sync_func; - scheduleEntries[0].func_args = &g_log_context; - scheduleEntries[1].id = 2; - scheduleEntries[1].time_base.hour = TIME_NONE; - scheduleEntries[1].time_base.minute = TIME_NONE; - scheduleEntries[1].time_base.second = TIME_NONE; - scheduleEntries[1].interval = g_sync_binlog_buff_interval; - scheduleEntries[1].task_func = fdfs_binlog_sync_func; - scheduleEntries[1].func_args = NULL; + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE, + g_sync_log_buff_interval, log_sync_func, &g_log_context); + scheduleArray.count++; - scheduleEntries[2].id = 3; - scheduleEntries[2].time_base.hour = TIME_NONE; - scheduleEntries[2].time_base.minute = TIME_NONE; - scheduleEntries[2].time_base.second = TIME_NONE; - scheduleEntries[2].interval = g_sync_stat_file_interval; - scheduleEntries[2].task_func = fdfs_stat_file_sync_func; - scheduleEntries[2].func_args = NULL; + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE, + g_sync_binlog_buff_interval, fdfs_binlog_sync_func, NULL); + scheduleArray.count++; + + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE, + g_sync_stat_file_interval, fdfs_stat_file_sync_func, NULL); + scheduleArray.count++; - scheduleArray.count = 3; if (g_if_use_trunk_file) { - scheduleEntries[scheduleArray.count].id = 4; - scheduleEntries[scheduleArray.count].time_base.hour = TIME_NONE; - scheduleEntries[scheduleArray.count].time_base.minute=TIME_NONE; - scheduleEntries[scheduleArray.count].time_base.second=TIME_NONE; - scheduleEntries[scheduleArray.count].interval = 1; - scheduleEntries[scheduleArray.count].task_func = \ - trunk_binlog_sync_func; - scheduleEntries[scheduleArray.count].func_args = NULL; + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE, + 1, trunk_binlog_sync_func, NULL); scheduleArray.count++; } if (g_use_access_log) { - scheduleEntries[scheduleArray.count].id = 5; - scheduleEntries[scheduleArray.count].time_base.hour = TIME_NONE; - scheduleEntries[scheduleArray.count].time_base.minute=TIME_NONE; - scheduleEntries[scheduleArray.count].time_base.second=TIME_NONE; - scheduleEntries[scheduleArray.count].interval = \ - g_sync_log_buff_interval; - scheduleEntries[scheduleArray.count].task_func = log_sync_func; - scheduleEntries[scheduleArray.count].func_args = \ - &g_access_log_context; + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE, + g_sync_log_buff_interval, log_sync_func, &g_access_log_context); scheduleArray.count++; if (g_rotate_access_log) { - scheduleEntries[scheduleArray.count].id = 6; - scheduleEntries[scheduleArray.count].time_base = \ - g_access_log_rotate_time; - scheduleEntries[scheduleArray.count].interval = \ - 24 * 3600; - scheduleEntries[scheduleArray.count].task_func = \ - log_notify_rotate; - scheduleEntries[scheduleArray.count].func_args = \ - &g_access_log_context; + INIT_SCHEDULE_ENTRY_EX(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, g_access_log_rotate_time, + 24 * 3600, log_notify_rotate, &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].time_base.second = 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_log_file_keep_days > 0) + { + log_set_keep_days(&g_access_log_context, + g_log_file_keep_days); + + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, 1, 0, 0, 24 * 3600, + log_delete_old_files, &g_access_log_context); + scheduleArray.count++; + } + } } if (g_rotate_error_log) { - scheduleEntries[scheduleArray.count].id = 8; - scheduleEntries[scheduleArray.count].time_base = \ - g_error_log_rotate_time; - scheduleEntries[scheduleArray.count].interval = \ - 24 * 3600; - scheduleEntries[scheduleArray.count].task_func = \ - log_notify_rotate; - scheduleEntries[scheduleArray.count].func_args = \ - &g_log_context; + INIT_SCHEDULE_ENTRY_EX(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, g_error_log_rotate_time, + 24 * 3600, log_notify_rotate, &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].time_base.second = 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 (g_log_file_keep_days > 0) + { + log_set_keep_days(&g_log_context, g_log_file_keep_days); + + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, 1, 0, 0, 24 * 3600, + log_delete_old_files, &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/tracker/fdfs_trackerd.c b/tracker/fdfs_trackerd.c index f2f3605..9ec1096 100644 --- a/tracker/fdfs_trackerd.c +++ b/tracker/fdfs_trackerd.c @@ -313,60 +313,41 @@ int main(int argc, char *argv[]) } scheduleArray.entries = scheduleEntries; + scheduleArray.count = 0; memset(scheduleEntries, 0, sizeof(scheduleEntries)); - scheduleEntries[0].id = 1; - scheduleEntries[0].time_base.hour = TIME_NONE; - scheduleEntries[0].time_base.minute = TIME_NONE; - scheduleEntries[0].time_base.second = TIME_NONE; - scheduleEntries[0].interval = g_sync_log_buff_interval; - scheduleEntries[0].task_func = log_sync_func; - scheduleEntries[0].func_args = &g_log_context; - scheduleEntries[1].id = 2; - scheduleEntries[1].time_base.hour = TIME_NONE; - scheduleEntries[1].time_base.minute = TIME_NONE; - scheduleEntries[1].time_base.second = TIME_NONE; - scheduleEntries[1].interval = g_check_active_interval; - scheduleEntries[1].task_func = tracker_mem_check_alive; - scheduleEntries[1].func_args = NULL; + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE, + g_sync_log_buff_interval, log_sync_func, &g_log_context); + scheduleArray.count++; - scheduleEntries[2].id = 3; - scheduleEntries[2].time_base.hour = 0; - scheduleEntries[2].time_base.minute = 0; - scheduleEntries[2].time_base.second = 0; - scheduleEntries[2].interval = TRACKER_SYNC_STATUS_FILE_INTERVAL; - scheduleEntries[2].task_func = tracker_write_status_to_file; - scheduleEntries[2].func_args = NULL; + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, TIME_NONE, TIME_NONE, TIME_NONE, + g_check_active_interval, tracker_mem_check_alive, NULL); + scheduleArray.count++; - scheduleArray.count = 3; + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, 0, 0, 0, + TRACKER_SYNC_STATUS_FILE_INTERVAL, + tracker_write_status_to_file, NULL); + scheduleArray.count++; if (g_rotate_error_log) { - scheduleEntries[scheduleArray.count].id = 4; - scheduleEntries[scheduleArray.count].time_base = \ - g_error_log_rotate_time; - scheduleEntries[scheduleArray.count].interval = \ - 24 * 3600; - scheduleEntries[scheduleArray.count].task_func = \ - log_notify_rotate; - scheduleEntries[scheduleArray.count].func_args = \ - &g_log_context; + INIT_SCHEDULE_ENTRY_EX(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, g_error_log_rotate_time, + 24 * 3600, log_notify_rotate, &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].time_base.second = 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 (g_log_file_keep_days > 0) + { + log_set_keep_days(&g_log_context, g_log_file_keep_days); + + INIT_SCHEDULE_ENTRY(scheduleEntries[scheduleArray.count], + scheduleArray.count + 1, 1, 0, 0, 24 * 3600, + log_delete_old_files, &g_log_context); + scheduleArray.count++; + } } if ((result=sched_start(&scheduleArray, &schedule_tid, \