enh: solve conflict during process log file

This commit is contained in:
kailixu 2025-02-08 14:14:58 +08:00
parent db807020a0
commit 74f8a252c6
2 changed files with 17 additions and 9 deletions

View File

@ -205,7 +205,7 @@ typedef struct {
typedef struct {
int64_t id;
char name[TSDB_CLUSTER_ID_LEN];
char nameX[TSDB_CLUSTER_ID_LEN];
int64_t createdTime;
int64_t updateTime;
int32_t upTime;

View File

@ -385,13 +385,21 @@ static void taosReserveOldLog(char *oldName, char *keepName) {
static void taosKeepOldLog(char *oldName) {
if (oldName[0] != 0) {
char compressFileName[PATH_MAX + 20];
snprintf(compressFileName, PATH_MAX + 20, "%s.gz", oldName);
if (taosCompressFile(oldName, compressFileName) == 0) {
int32_t code = taosRemoveFile(oldName);
if (code != 0) {
TAOS_UNUSED(printf("failed to remove file:%s, reason:%s\n", oldName, tstrerror(code)));
}
int32_t code = 0, lino = 0;
TdFilePtr oldFile = NULL;
if ((oldFile = taosOpenFile(oldName, TD_FILE_READ))) {
TAOS_CHECK_GOTO(taosLockFile(oldFile), &lino, _exit2);
char compressFileName[PATH_MAX + 20];
snprintf(compressFileName, PATH_MAX + 20, "%s.gz", oldName);
TAOS_CHECK_GOTO(taosCompressFile(oldName, compressFileName), &lino, _exit1);
TAOS_CHECK_GOTO(taosRemoveFile(oldName), &lino, _exit1);
}
_exit1:
TAOS_UNUSED(taosUnLockFile(oldFile));
_exit2:
TAOS_UNUSED(taosCloseFile(&oldFile));
if (code != 0) {
uWarn("failed at line %d to keep old log file:%s, reason:%s\n", oldName, lino, tstrerror(code));
}
}
}
@ -1041,7 +1049,7 @@ static void taosWriteLog(SLogBuff *pLogBuf) {
}
#define LOG_ROTATE_INTERVAL 3600
#if !defined(TD_ENTERPRISE) || defined(ASSERT_NOT_CORE)
#if !defined(TD_ENTERPRISE) || defined(ASSERT_NOT_CORE) || defined(GRANTS_CFG)
#define LOG_INACTIVE_TIME 7200
#define LOG_ROTATE_BOOT 900
#else