Merge pull request #25262 from taosdata/fix/xsren/TD-29197

fix: logFileHandle NULL
This commit is contained in:
dapan1121 2024-04-10 15:09:21 +08:00 committed by GitHub
commit b05e7fb34a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 10 deletions

View File

@ -242,6 +242,7 @@ void taosCloseLog() {
taosMemoryFreeClear(tsLogObj.logHandle->buffer);
taosThreadMutexDestroy(&tsLogObj.logMutex);
taosMemoryFreeClear(tsLogObj.logHandle);
tsLogObj.logHandle = NULL;
}
}
@ -285,8 +286,11 @@ static void taosKeepOldLog(char *oldName) {
taosRemoveOldFiles(tsLogDir, tsLogKeepDays);
}
}
static void *taosThreadToOpenNewFile(void *param) {
typedef struct {
TdFilePtr pOldFile;
char keepName[LOG_FILE_NAME_LEN + 20];
} OldFileKeeper;
static OldFileKeeper *taosOpenNewFile() {
char keepName[LOG_FILE_NAME_LEN + 20];
sprintf(keepName, "%s.%d", tsLogObj.logName, tsLogObj.flag);
@ -312,13 +316,26 @@ static void *taosThreadToOpenNewFile(void *param) {
tsLogObj.logHandle->pFile = pFile;
tsLogObj.lines = 0;
tsLogObj.openInProgress = 0;
taosSsleep(20);
taosCloseLogByFd(pOldFile);
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);
uInfo(" new log file:%d is opened", tsLogObj.flag);
uInfo("==================================");
taosKeepOldLog(keepName);
return oldFileKeeper;
}
static void *taosThreadToCloseOldFile(void* param) {
if(!param) return NULL;
OldFileKeeper* oldFileKeeper = (OldFileKeeper*)param;
taosSsleep(20);
taosCloseLogByFd(oldFileKeeper->pOldFile);
taosKeepOldLog(oldFileKeeper->keepName);
taosMemoryFree(oldFileKeeper);
return NULL;
}
@ -334,7 +351,8 @@ static int32_t taosOpenNewLogFile() {
taosThreadAttrInit(&attr);
taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED);
taosThreadCreate(&thread, &attr, taosThreadToOpenNewFile, NULL);
OldFileKeeper* oldFileKeeper = taosOpenNewFile();
taosThreadCreate(&thread, &attr, taosThreadToCloseOldFile, oldFileKeeper);
taosThreadAttrDestroy(&attr);
}
@ -347,10 +365,11 @@ void taosResetLog() {
// force create a new log file
tsLogObj.lines = tsNumOfLogLines + 10;
taosOpenNewLogFile();
uInfo("==================================");
uInfo(" reset log file ");
if (tsLogObj.logHandle) {
taosOpenNewLogFile();
uInfo("==================================");
uInfo(" reset log file ");
}
}
static bool taosCheckFileIsOpen(char *logFileName) {