From 5b0bb82ed046b97972adcaed59bc0820483be78d Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 11 Jun 2024 17:46:53 +0800 Subject: [PATCH 1/5] fix: reserve log file name --- source/util/src/tlog.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 0c09174970..1dad1d9519 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -267,21 +267,31 @@ static void taosUnLockLogFile(TdFilePtr pFile) { } } -static void taosKeepOldLog(char *oldName) { - if (tsLogKeepDays == 0) return; - - int64_t fileSec = taosGetTimestampSec(); - char fileName[LOG_FILE_NAME_LEN + 20]; - snprintf(fileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec); - - (void)taosRenameFile(oldName, fileName); - - char compressFileName[LOG_FILE_NAME_LEN + 20]; - snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64 ".gz", tsLogObj.logName, fileSec); - if (taosCompressFile(fileName, compressFileName) == 0) { - (void)taosRemoveFile(fileName); +static void taosReserveOldLog(char *oldName, char *keepName) { + if (tsLogKeepDays == 0) { + keepName[0] = 0; + return; } + int32_t code = 0; + int64_t fileSec = taosGetTimestampSec(); + snprintf(keepName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec); + if ((code = taosRenameFile(oldName, keepName))) { + keepName[0] = 0; + uError("failed to rename file:%s to %s since %s", oldName, keepName, tstrerror(code)); + } +} + +static void taosKeepOldLog(char *oldName) { + if (oldName[0] == '\0') goto _end; + + char compressFileName[LOG_FILE_NAME_LEN + 20]; + snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.gz", oldName); + if (taosCompressFile(oldName, compressFileName) == 0) { + (void)taosRemoveFile(oldName); + } + +_end: if (tsLogKeepDays > 0) { taosRemoveOldFiles(tsLogDir, tsLogKeepDays); } @@ -316,13 +326,13 @@ static OldFileKeeper *taosOpenNewFile() { tsLogObj.logHandle->pFile = pFile; tsLogObj.lines = 0; tsLogObj.openInProgress = 0; - OldFileKeeper* oldFileKeeper = taosMemoryMalloc(sizeof(OldFileKeeper)); + OldFileKeeper *oldFileKeeper = taosMemoryMalloc(sizeof(OldFileKeeper)); if (oldFileKeeper == NULL) { uError("create old log keep info faild! mem is not enough."); return NULL; } oldFileKeeper->pOldFile = pOldFile; - memcpy(oldFileKeeper->keepName, keepName, LOG_FILE_NAME_LEN + 20); + taosReserveOldLog(keepName, oldFileKeeper->keepName); uInfo(" new log file:%d is opened", tsLogObj.flag); uInfo("=================================="); From 581f5e79d9a539d92f32a2eb5d177beb9bc14a36 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 11 Jun 2024 18:20:00 +0800 Subject: [PATCH 2/5] fix: reserve log file name --- source/util/src/tlog.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 1dad1d9519..ca809e1d5d 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -66,6 +66,7 @@ typedef struct { int32_t lines; int32_t flag; int32_t openInProgress; + int64_t lastFileSec; pid_t pid; char logName[LOG_FILE_NAME_LEN]; SLogBuff *logHandle; @@ -275,6 +276,11 @@ static void taosReserveOldLog(char *oldName, char *keepName) { int32_t code = 0; int64_t fileSec = taosGetTimestampSec(); + if (tsLogObj.lastFileSec < fileSec) { + tsLogObj.lastFileSec = fileSec; + } else { + fileSec = ++tsLogObj.lastFileSec; + } snprintf(keepName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec); if ((code = taosRenameFile(oldName, keepName))) { keepName[0] = 0; From f1fa948594b4d85fd2fd89304271961d4aa913d9 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 11 Jun 2024 18:27:46 +0800 Subject: [PATCH 3/5] fix: reserve log file name --- source/util/src/tlog.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index ca809e1d5d..e2a5d39888 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -66,7 +66,7 @@ typedef struct { int32_t lines; int32_t flag; int32_t openInProgress; - int64_t lastFileSec; + int64_t lastKeepFileSec; pid_t pid; char logName[LOG_FILE_NAME_LEN]; SLogBuff *logHandle; @@ -276,10 +276,10 @@ static void taosReserveOldLog(char *oldName, char *keepName) { int32_t code = 0; int64_t fileSec = taosGetTimestampSec(); - if (tsLogObj.lastFileSec < fileSec) { - tsLogObj.lastFileSec = fileSec; + if (tsLogObj.lastKeepFileSec < fileSec) { + tsLogObj.lastKeepFileSec = fileSec; } else { - fileSec = ++tsLogObj.lastFileSec; + fileSec = ++tsLogObj.lastKeepFileSec; } snprintf(keepName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec); if ((code = taosRenameFile(oldName, keepName))) { From db44febadf551982d6c9c54096d5150e331f94ab Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 12 Jun 2024 08:27:46 +0800 Subject: [PATCH 4/5] fix: reserve log file name --- source/util/src/tlog.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index e2a5d39888..8023541af3 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -289,15 +289,14 @@ static void taosReserveOldLog(char *oldName, char *keepName) { } static void taosKeepOldLog(char *oldName) { - if (oldName[0] == '\0') goto _end; - - char compressFileName[LOG_FILE_NAME_LEN + 20]; - snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.gz", oldName); - if (taosCompressFile(oldName, compressFileName) == 0) { - (void)taosRemoveFile(oldName); + if (oldName[0] != 0) { + char compressFileName[LOG_FILE_NAME_LEN + 20]; + snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.gz", oldName); + if (taosCompressFile(oldName, compressFileName) == 0) { + (void)taosRemoveFile(oldName); + } } -_end: if (tsLogKeepDays > 0) { taosRemoveOldFiles(tsLogDir, tsLogKeepDays); } From fa05b2c8b634c359726d6f20e7460b4cd60418df Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 12 Jun 2024 11:17:08 +0800 Subject: [PATCH 5/5] fix: reserve log file name --- source/util/src/tlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 8023541af3..b224eac8c2 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -269,7 +269,7 @@ static void taosUnLockLogFile(TdFilePtr pFile) { } static void taosReserveOldLog(char *oldName, char *keepName) { - if (tsLogKeepDays == 0) { + if (tsLogKeepDays <= 0) { keepName[0] = 0; return; }