fix: create log file thread
This commit is contained in:
parent
ad1c474dc6
commit
a969142c37
|
@ -286,8 +286,11 @@ static void taosKeepOldLog(char *oldName) {
|
||||||
taosRemoveOldFiles(tsLogDir, tsLogKeepDays);
|
taosRemoveOldFiles(tsLogDir, tsLogKeepDays);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
typedef struct {
|
||||||
static void *taosThreadToOpenNewFile(void *param) {
|
TdFilePtr pOldFile;
|
||||||
|
char keepName[LOG_FILE_NAME_LEN + 20];
|
||||||
|
} OldFileKeeper;
|
||||||
|
static OldFileKeeper *taosOpenNewFile() {
|
||||||
char keepName[LOG_FILE_NAME_LEN + 20];
|
char keepName[LOG_FILE_NAME_LEN + 20];
|
||||||
sprintf(keepName, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
sprintf(keepName, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
||||||
|
|
||||||
|
@ -313,13 +316,26 @@ static void *taosThreadToOpenNewFile(void *param) {
|
||||||
tsLogObj.logHandle->pFile = pFile;
|
tsLogObj.logHandle->pFile = pFile;
|
||||||
tsLogObj.lines = 0;
|
tsLogObj.lines = 0;
|
||||||
tsLogObj.openInProgress = 0;
|
tsLogObj.openInProgress = 0;
|
||||||
taosSsleep(20);
|
OldFileKeeper* oldFileKeeper = taosMemoryMalloc(sizeof(OldFileKeeper));
|
||||||
taosCloseLogByFd(pOldFile);
|
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(" new log file:%d is opened", tsLogObj.flag);
|
||||||
uInfo("==================================");
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +351,8 @@ static int32_t taosOpenNewLogFile() {
|
||||||
taosThreadAttrInit(&attr);
|
taosThreadAttrInit(&attr);
|
||||||
taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED);
|
taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED);
|
||||||
|
|
||||||
taosThreadCreate(&thread, &attr, taosThreadToOpenNewFile, NULL);
|
OldFileKeeper* oldFileKeeper = taosOpenNewFile();
|
||||||
|
taosThreadCreate(&thread, &attr, taosThreadToCloseOldFile, oldFileKeeper);
|
||||||
taosThreadAttrDestroy(&attr);
|
taosThreadAttrDestroy(&attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue