From aa3df5f7fac7976f1adf267977bce3d8062944d9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 8 Dec 2020 10:28:13 +0800 Subject: [PATCH] TD-2371 --- src/util/src/tlog.c | 1 - src/util/src/tnote.c | 37 +++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index ad3a922304..0ba5e49c6e 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -287,7 +287,6 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { tsLogObj.fileNum = maxFileNum; taosGetLogFileName(fn); - if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) { strcpy(name, fn); strcat(name, ".0"); diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 04dd58afce..3338d8f301 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -53,7 +53,7 @@ void taosInitNotes() { taosInitNote(tsNumOfLogLines, 1, &tsHttpNote, name); } - if (tscEmbedded == 0) { + if (tscEmbedded == 1) { snprintf(name, TSDB_FILENAME_LEN * 2, "%s/note", tsLogDir); taosInitNote(tsNumOfLogLines, 1, &tsErrorNote, name); } @@ -170,36 +170,37 @@ void taosGetNoteName(char *fn, SNoteObj *pNote) { } int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum, SNoteObj *pNote) { - char name[NOTE_FILE_NAME_LEN * 2] = "\0"; + char name[NOTE_FILE_NAME_LEN * 2] = {0}; int32_t size; - struct stat notestat0, notestat1; + struct stat logstat0, logstat1; pNote->maxLines = maxLines; pNote->fileNum = maxNoteNum; taosGetNoteName(fn, pNote); - if (strlen(fn) > NOTE_FILE_NAME_LEN * 2 - 2) { - fprintf(stderr, "the len of file name overflow:%s\n", fn); - return -1; + if (strlen(fn) < NOTE_FILE_NAME_LEN + 50 - 2) { + strcpy(name, fn); + strcat(name, ".0"); } + bool log0Exist = stat(name, &logstat0) >= 0; - strcpy(name, fn); - strcat(name, ".0"); + if (strlen(fn) < NOTE_FILE_NAME_LEN + 50 - 2) { + strcpy(name, fn); + strcat(name, ".1"); + } + bool log1Exist = stat(name, &logstat1) >= 0; - // if none of the note files exist, open 0, if both exists, open the old one - if (stat(name, ¬estat0) < 0) { + if (!log0Exist && !log1Exist) { pNote->flag = 0; + } else if (!log1Exist) { + pNote->flag = 0; + } else if (!log0Exist) { + pNote->flag = 1; } else { - strcpy(name, fn); - strcat(name, ".1"); - if (stat(name, ¬estat1) < 0) { - pNote->flag = 1; - } else { - pNote->flag = (notestat0.st_mtime > notestat1.st_mtime) ? 0 : 1; - } + pNote->flag = (logstat0.st_mtime > logstat1.st_mtime) ? 0 : 1; } - char noteName[NOTE_FILE_NAME_LEN * 2] = "\0"; + char noteName[NOTE_FILE_NAME_LEN * 2] = {0}; sprintf(noteName, "%s.%d", pNote->name, pNote->flag); pthread_mutex_init(&pNote->mutex, NULL); -- GitLab