Merge pull request #26959 from taosdata/feat/TS-3718
feat:[TS-3718]save slow log file one day one file
This commit is contained in:
commit
3790a1f415
|
@ -69,7 +69,7 @@ extern int32_t tdbDebugFlag;
|
||||||
extern int32_t sndDebugFlag;
|
extern int32_t sndDebugFlag;
|
||||||
extern int32_t simDebugFlag;
|
extern int32_t simDebugFlag;
|
||||||
|
|
||||||
int32_t taosInitLog(const char *logName, int32_t maxFiles);
|
int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc);
|
||||||
void taosCloseLog();
|
void taosCloseLog();
|
||||||
void taosResetLog();
|
void taosResetLog();
|
||||||
void taosDumpData(uint8_t *msg, int32_t len);
|
void taosDumpData(uint8_t *msg, int32_t len);
|
||||||
|
|
|
@ -1615,7 +1615,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((code = taosInitLog(logname, logFileNum)) != 0) {
|
if ((code = taosInitLog(logname, logFileNum, tsc)) != 0) {
|
||||||
printf("failed to init log file since %s\n", tstrerror(code));
|
printf("failed to init log file since %s\n", tstrerror(code));
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ void Testbase::InitLog(const char* path) {
|
||||||
|
|
||||||
taosGetSystemInfo();
|
taosGetSystemInfo();
|
||||||
tsRpcQueueMemoryAllowed = tsTotalMemoryKB * 0.1;
|
tsRpcQueueMemoryAllowed = tsTotalMemoryKB * 0.1;
|
||||||
if (taosInitLog("taosdlog", 1) != 0) {
|
if (taosInitLog("taosdlog", 1, false) != 0) {
|
||||||
printf("failed to init log file\n");
|
printf("failed to init log file\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class MndTestSdb : public ::testing::Test {
|
||||||
taosRemoveDir(path);
|
taosRemoveDir(path);
|
||||||
taosMkDir(path);
|
taosMkDir(path);
|
||||||
tstrncpy(tsLogDir, path, PATH_MAX);
|
tstrncpy(tsLogDir, path, PATH_MAX);
|
||||||
if (taosInitLog("taosdlog", 1) != 0) {
|
if (taosInitLog("taosdlog", 1, false) != 0) {
|
||||||
printf("failed to init log file\n");
|
printf("failed to init log file\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class MndTestTrans2 : public ::testing::Test {
|
||||||
taosRemoveDir(logpath);
|
taosRemoveDir(logpath);
|
||||||
taosMkDir(logpath);
|
taosMkDir(logpath);
|
||||||
tstrncpy(tsLogDir, logpath, PATH_MAX);
|
tstrncpy(tsLogDir, logpath, PATH_MAX);
|
||||||
if (taosInitLog("taosdlog", 1) != 0) {
|
if (taosInitLog("taosdlog", 1, false) != 0) {
|
||||||
printf("failed to init log file\n");
|
printf("failed to init log file\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2884,7 +2884,7 @@ void jtInitLogFile() {
|
||||||
qDebugFlag = 159;
|
qDebugFlag = 159;
|
||||||
TAOS_STRCPY(tsLogDir, TD_LOG_DIR_PATH);
|
TAOS_STRCPY(tsLogDir, TD_LOG_DIR_PATH);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
JT_PRINTF("failed to open log file in directory:%s\n", tsLogDir);
|
JT_PRINTF("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ static void EnvInit() {
|
||||||
taosMkDir(path.c_str());
|
taosMkDir(path.c_str());
|
||||||
// init log file
|
// init log file
|
||||||
tstrncpy(tsLogDir, path.c_str(), PATH_MAX);
|
tstrncpy(tsLogDir, path.c_str(), PATH_MAX);
|
||||||
if (taosInitLog("tindex.idx", 1) != 0) {
|
if (taosInitLog("tindex.idx", 1, false) != 0) {
|
||||||
printf("failed to init log");
|
printf("failed to init log");
|
||||||
}
|
}
|
||||||
// init index file
|
// init index file
|
||||||
|
|
|
@ -40,7 +40,7 @@ static void initLog() {
|
||||||
taosRemoveDir(tsLogDir);
|
taosRemoveDir(tsLogDir);
|
||||||
taosMkDir(tsLogDir);
|
taosMkDir(tsLogDir);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,7 @@ static void initLog() {
|
||||||
taosRemoveDir(tsLogDir);
|
taosRemoveDir(tsLogDir);
|
||||||
taosMkDir(tsLogDir);
|
taosMkDir(tsLogDir);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ void sifInitLogFile() {
|
||||||
taosRemoveDir(tsLogDir);
|
taosRemoveDir(tsLogDir);
|
||||||
taosMkDir(tsLogDir);
|
taosMkDir(tsLogDir);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ static void initLog() {
|
||||||
taosRemoveDir(tsLogDir);
|
taosRemoveDir(tsLogDir);
|
||||||
taosMkDir(tsLogDir);
|
taosMkDir(tsLogDir);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ class ParserEnv : public testing::Environment {
|
||||||
taosRemoveDir(path);
|
taosRemoveDir(path);
|
||||||
ASSERT_EQ(TSDB_CODE_SUCCESS, taosMkDir(path));
|
ASSERT_EQ(TSDB_CODE_SUCCESS, taosMkDir(path));
|
||||||
tstrncpy(tsLogDir, path, PATH_MAX);
|
tstrncpy(tsLogDir, path, PATH_MAX);
|
||||||
if (taosInitLog("taoslog", 1) != 0) {
|
if (taosInitLog("taoslog", 1, false) != 0) {
|
||||||
std::cout << "failed to init log file" << std::endl;
|
std::cout << "failed to init log file" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ class PlannerEnv : public testing::Environment {
|
||||||
taosRemoveDir(path);
|
taosRemoveDir(path);
|
||||||
ASSERT_EQ(TSDB_CODE_SUCCESS,taosMkDir(path));
|
ASSERT_EQ(TSDB_CODE_SUCCESS,taosMkDir(path));
|
||||||
tstrncpy(tsLogDir, path, PATH_MAX);
|
tstrncpy(tsLogDir, path, PATH_MAX);
|
||||||
if (taosInitLog("taoslog", 1) != 0) {
|
if (taosInitLog("taoslog", 1, false) != 0) {
|
||||||
std::cout << "failed to init log file" << std::endl;
|
std::cout << "failed to init log file" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ void qwtInitLogFile() {
|
||||||
qDebugFlag = 159;
|
qDebugFlag = 159;
|
||||||
strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ void flttInitLogFile() {
|
||||||
qDebugFlag = 159;
|
qDebugFlag = 159;
|
||||||
(void)strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
(void)strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ void scltInitLogFile() {
|
||||||
qDebugFlag = 159;
|
qDebugFlag = 159;
|
||||||
(void)strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
(void)strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
(void)printf("failed to open log file in directory:%s\n", tsLogDir);
|
(void)printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ void schtInitLogFile() {
|
||||||
qDebugFlag = 159;
|
qDebugFlag = 159;
|
||||||
TAOS_STRCPY(tsLogDir, TD_LOG_DIR_PATH);
|
TAOS_STRCPY(tsLogDir, TD_LOG_DIR_PATH);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
(void)printf("failed to open log file in directory:%s\n", tsLogDir);
|
(void)printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ void test4() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
taosInitLog("/tmp/syncTest.log", 100);
|
taosInitLog("/tmp/syncTest.log", 100, false);
|
||||||
tsAsyncLog = 0;
|
tsAsyncLog = 0;
|
||||||
sDebugFlag = DEBUG_SCREEN + DEBUG_FILE + DEBUG_TRACE + DEBUG_INFO + DEBUG_ERROR;
|
sDebugFlag = DEBUG_SCREEN + DEBUG_FILE + DEBUG_TRACE + DEBUG_INFO + DEBUG_ERROR;
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
char logFile[256];
|
char logFile[256];
|
||||||
snprintf(logFile, sizeof(logFile), "/tmp/%s-replicaNum%d-myIndex%d.log", gDir, replicaNum, myIndex);
|
snprintf(logFile, sizeof(logFile), "/tmp/%s-replicaNum%d-myIndex%d.log", gDir, replicaNum, myIndex);
|
||||||
taosInitLog(logFile, 100);
|
taosInitLog(logFile, 100, false);
|
||||||
sTrace("logFile : %s", logFile);
|
sTrace("logFile : %s", logFile);
|
||||||
|
|
||||||
gSnapshotLastApplyIndex = lastApplyIndex;
|
gSnapshotLastApplyIndex = lastApplyIndex;
|
||||||
|
|
|
@ -43,7 +43,7 @@ void initLogEnv() {
|
||||||
taosRemoveDir(tsLogDir);
|
taosRemoveDir(tsLogDir);
|
||||||
taosMkDir(tsLogDir);
|
taosMkDir(tsLogDir);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ void initLogEnv() {
|
||||||
taosRemoveDir(tsLogDir);
|
taosRemoveDir(tsLogDir);
|
||||||
taosMkDir(tsLogDir);
|
taosMkDir(tsLogDir);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ void initLogEnv() {
|
||||||
taosRemoveDir(tsLogDir);
|
taosRemoveDir(tsLogDir);
|
||||||
taosMkDir(tsLogDir);
|
taosMkDir(tsLogDir);
|
||||||
|
|
||||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
|
||||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,7 +230,7 @@ static void initEnv() {
|
||||||
taosMkDir(path.c_str());
|
taosMkDir(path.c_str());
|
||||||
|
|
||||||
tstrncpy(tsLogDir, path.c_str(), PATH_MAX);
|
tstrncpy(tsLogDir, path.c_str(), PATH_MAX);
|
||||||
if (taosInitLog("taosdlog", 1) != 0) {
|
if (taosInitLog("taosdlog", 1, false) != 0) {
|
||||||
printf("failed to init log file\n");
|
printf("failed to init log file\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
#define LOG_MAX_LINE_DUMP_SIZE (1024 * 1024)
|
#define LOG_MAX_LINE_DUMP_SIZE (1024 * 1024)
|
||||||
#define LOG_MAX_LINE_DUMP_BUFFER_SIZE (LOG_MAX_LINE_DUMP_SIZE + 128)
|
#define LOG_MAX_LINE_DUMP_BUFFER_SIZE (LOG_MAX_LINE_DUMP_SIZE + 128)
|
||||||
|
|
||||||
#define LOG_FILE_NAME_LEN 300
|
#define LOG_FILE_DAY_LEN 64
|
||||||
|
|
||||||
#define LOG_DEFAULT_BUF_SIZE (20 * 1024 * 1024) // 20MB
|
#define LOG_DEFAULT_BUF_SIZE (20 * 1024 * 1024) // 20MB
|
||||||
#define LOG_SLOW_BUF_SIZE (10 * 1024 * 1024) // 10MB
|
#define LOG_SLOW_BUF_SIZE (10 * 1024 * 1024) // 10MB
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ typedef struct {
|
||||||
TdThreadMutex buffMutex;
|
TdThreadMutex buffMutex;
|
||||||
int32_t writeInterval;
|
int32_t writeInterval;
|
||||||
int32_t lastDuration;
|
int32_t lastDuration;
|
||||||
|
int32_t lock;
|
||||||
} SLogBuff;
|
} SLogBuff;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -68,8 +70,10 @@ typedef struct {
|
||||||
int32_t flag;
|
int32_t flag;
|
||||||
int32_t openInProgress;
|
int32_t openInProgress;
|
||||||
int64_t lastKeepFileSec;
|
int64_t lastKeepFileSec;
|
||||||
|
int64_t timestampToday;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char logName[LOG_FILE_NAME_LEN];
|
char logName[PATH_MAX];
|
||||||
|
char slowLogName[PATH_MAX];
|
||||||
SLogBuff *logHandle;
|
SLogBuff *logHandle;
|
||||||
SLogBuff *slowHandle;
|
SLogBuff *slowHandle;
|
||||||
TdThreadMutex logMutex;
|
TdThreadMutex logMutex;
|
||||||
|
@ -77,7 +81,7 @@ typedef struct {
|
||||||
|
|
||||||
extern SConfig *tsCfg;
|
extern SConfig *tsCfg;
|
||||||
static int8_t tsLogInited = 0;
|
static int8_t tsLogInited = 0;
|
||||||
static SLogObj tsLogObj = {.fileNum = 1};
|
static SLogObj tsLogObj = {.fileNum = 1, .slowHandle = NULL};
|
||||||
static int64_t tsAsyncLogLostLines = 0;
|
static int64_t tsAsyncLogLostLines = 0;
|
||||||
static int32_t tsDaylightActive; /* Currently in daylight saving time. */
|
static int32_t tsDaylightActive; /* Currently in daylight saving time. */
|
||||||
|
|
||||||
|
@ -131,17 +135,9 @@ static void *taosAsyncOutputLog(void *param);
|
||||||
static int32_t taosPushLogBuffer(SLogBuff *pLogBuf, const char *msg, int32_t msgLen);
|
static int32_t taosPushLogBuffer(SLogBuff *pLogBuf, const char *msg, int32_t msgLen);
|
||||||
static SLogBuff *taosLogBuffNew(int32_t bufSize);
|
static SLogBuff *taosLogBuffNew(int32_t bufSize);
|
||||||
static void taosCloseLogByFd(TdFilePtr pFile);
|
static void taosCloseLogByFd(TdFilePtr pFile);
|
||||||
static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum);
|
static int32_t taosInitNormalLog(const char *fn, int32_t maxFileNum);
|
||||||
|
static void taosWriteLog(SLogBuff *pLogBuf);
|
||||||
static FORCE_INLINE void taosUpdateDaylight() {
|
static void taosWriteSlowLog(SLogBuff *pLogBuf);
|
||||||
struct tm Tm, *ptm;
|
|
||||||
struct timeval timeSecs;
|
|
||||||
(void)taosGetTimeOfDay(&timeSecs);
|
|
||||||
time_t curTime = timeSecs.tv_sec;
|
|
||||||
ptm = taosLocalTime(&curTime, &Tm, NULL);
|
|
||||||
tsDaylightActive = ptm->tm_isdst;
|
|
||||||
}
|
|
||||||
static FORCE_INLINE int32_t taosGetDaylight() { return tsDaylightActive; }
|
|
||||||
|
|
||||||
static int32_t taosStartLog() {
|
static int32_t taosStartLog() {
|
||||||
TdThreadAttr threadAttr;
|
TdThreadAttr threadAttr;
|
||||||
|
@ -153,47 +149,26 @@ static int32_t taosStartLog() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosInitSlowLog() {
|
static void getDay(char* buf){
|
||||||
char fullName[PATH_MAX] = {0};
|
time_t t = taosTime(NULL);
|
||||||
char logFileName[64] = {0};
|
struct tm tmInfo;
|
||||||
#ifdef CUS_PROMPT
|
if (taosLocalTime(&t, &tmInfo, buf) != NULL) {
|
||||||
snprintf(logFileName, 64, "%sSlowLog", CUS_PROMPT);
|
(void)strftime(buf, LOG_FILE_DAY_LEN, "%Y-%m-%d", &tmInfo);
|
||||||
#else
|
|
||||||
snprintf(logFileName, 64, "taosSlowLog");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (strlen(tsLogDir) != 0) {
|
|
||||||
char lastC = tsLogDir[strlen(tsLogDir) - 1];
|
|
||||||
if (lastC == '\\' || lastC == '/') {
|
|
||||||
snprintf(fullName, PATH_MAX,
|
|
||||||
"%s"
|
|
||||||
"%s",
|
|
||||||
tsLogDir, logFileName);
|
|
||||||
} else {
|
|
||||||
snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logFileName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
snprintf(fullName, PATH_MAX, "%s", logFileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tsLogObj.slowHandle = taosLogBuffNew(LOG_SLOW_BUF_SIZE);
|
|
||||||
if (tsLogObj.slowHandle == NULL) return terrno;
|
|
||||||
|
|
||||||
(void)taosUmaskFile(0);
|
|
||||||
tsLogObj.slowHandle->pFile = taosOpenFile(fullName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
|
||||||
if (tsLogObj.slowHandle->pFile == NULL) {
|
|
||||||
printf("\nfailed to open slow log file:%s, reason:%s\n", fullName, strerror(errno));
|
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosInitLog(const char *logName, int32_t maxFiles) {
|
static int64_t getTimestampToday() {
|
||||||
if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0;
|
time_t t = taosTime(NULL);
|
||||||
osUpdate();
|
struct tm tm;
|
||||||
|
(void) taosLocalTime(&t, &tm, NULL);
|
||||||
|
tm.tm_hour = 0;
|
||||||
|
tm.tm_min = 0;
|
||||||
|
tm.tm_sec = 0;
|
||||||
|
|
||||||
char fullName[PATH_MAX] = {0};
|
return (int64_t)taosMktime(&tm);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void getFullPathName(char* fullName, const char* logName){
|
||||||
if (strlen(tsLogDir) != 0) {
|
if (strlen(tsLogDir) != 0) {
|
||||||
char lastC = tsLogDir[strlen(tsLogDir) - 1];
|
char lastC = tsLogDir[strlen(tsLogDir) - 1];
|
||||||
if (lastC == '\\' || lastC == '/') {
|
if (lastC == '\\' || lastC == '/') {
|
||||||
|
@ -207,13 +182,45 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles) {
|
||||||
} else {
|
} else {
|
||||||
snprintf(fullName, PATH_MAX, "%s", logName);
|
snprintf(fullName, PATH_MAX, "%s", logName);
|
||||||
}
|
}
|
||||||
taosUpdateDaylight();
|
}
|
||||||
|
|
||||||
tsLogObj.logHandle = taosLogBuffNew(LOG_DEFAULT_BUF_SIZE);
|
int32_t taosInitSlowLog() {
|
||||||
if (tsLogObj.logHandle == NULL) return terrno;
|
char logFileName[64] = {0};
|
||||||
TAOS_CHECK_RETURN(taosOpenLogFile(fullName, maxFiles));
|
#ifdef CUS_PROMPT
|
||||||
|
(void)snprintf(logFileName, 64, "%sSlowLog", CUS_PROMPT);
|
||||||
|
#else
|
||||||
|
(void)snprintf(logFileName, 64, "taosSlowLog");
|
||||||
|
#endif
|
||||||
|
|
||||||
TAOS_CHECK_RETURN(taosInitSlowLog());
|
getFullPathName(tsLogObj.slowLogName, logFileName);
|
||||||
|
|
||||||
|
char name[PATH_MAX + LOG_FILE_DAY_LEN] = {0};
|
||||||
|
char day[LOG_FILE_DAY_LEN] = {0};
|
||||||
|
getDay(day);
|
||||||
|
(void)snprintf(name, PATH_MAX + LOG_FILE_DAY_LEN, "%s.%s", tsLogObj.slowLogName, day);
|
||||||
|
|
||||||
|
tsLogObj.timestampToday = getTimestampToday();
|
||||||
|
tsLogObj.slowHandle = taosLogBuffNew(LOG_SLOW_BUF_SIZE);
|
||||||
|
if (tsLogObj.slowHandle == NULL) return terrno;
|
||||||
|
|
||||||
|
(void)taosUmaskFile(0);
|
||||||
|
tsLogObj.slowHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
|
if (tsLogObj.slowHandle->pFile == NULL) {
|
||||||
|
printf("\nfailed to open slow log file:%s, reason:%s\n", name, strerror(errno));
|
||||||
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) {
|
||||||
|
if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0;
|
||||||
|
osUpdate();
|
||||||
|
|
||||||
|
TAOS_CHECK_RETURN(taosInitNormalLog(logName, maxFiles));
|
||||||
|
if (tsc){
|
||||||
|
TAOS_CHECK_RETURN(taosInitSlowLog());
|
||||||
|
}
|
||||||
TAOS_CHECK_RETURN(taosStartLog());
|
TAOS_CHECK_RETURN(taosStartLog());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +295,7 @@ static void taosReserveOldLog(char *oldName, char *keepName) {
|
||||||
} else {
|
} else {
|
||||||
fileSec = ++tsLogObj.lastKeepFileSec;
|
fileSec = ++tsLogObj.lastKeepFileSec;
|
||||||
}
|
}
|
||||||
snprintf(keepName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec);
|
snprintf(keepName, PATH_MAX + 20, "%s.%" PRId64, tsLogObj.logName, fileSec);
|
||||||
if ((code = taosRenameFile(oldName, keepName))) {
|
if ((code = taosRenameFile(oldName, keepName))) {
|
||||||
keepName[0] = 0;
|
keepName[0] = 0;
|
||||||
uError("failed to rename file:%s to %s since %s", oldName, keepName, tstrerror(code));
|
uError("failed to rename file:%s to %s since %s", oldName, keepName, tstrerror(code));
|
||||||
|
@ -297,8 +304,8 @@ static void taosReserveOldLog(char *oldName, char *keepName) {
|
||||||
|
|
||||||
static void taosKeepOldLog(char *oldName) {
|
static void taosKeepOldLog(char *oldName) {
|
||||||
if (oldName[0] != 0) {
|
if (oldName[0] != 0) {
|
||||||
char compressFileName[LOG_FILE_NAME_LEN + 20];
|
char compressFileName[PATH_MAX + 20];
|
||||||
snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.gz", oldName);
|
snprintf(compressFileName, PATH_MAX + 20, "%s.gz", oldName);
|
||||||
if (taosCompressFile(oldName, compressFileName) == 0) {
|
if (taosCompressFile(oldName, compressFileName) == 0) {
|
||||||
(void)taosRemoveFile(oldName);
|
(void)taosRemoveFile(oldName);
|
||||||
}
|
}
|
||||||
|
@ -310,15 +317,15 @@ static void taosKeepOldLog(char *oldName) {
|
||||||
}
|
}
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TdFilePtr pOldFile;
|
TdFilePtr pOldFile;
|
||||||
char keepName[LOG_FILE_NAME_LEN + 20];
|
char keepName[PATH_MAX + 20];
|
||||||
} OldFileKeeper;
|
} OldFileKeeper;
|
||||||
static OldFileKeeper *taosOpenNewFile() {
|
static OldFileKeeper *taosOpenNewFile() {
|
||||||
char keepName[LOG_FILE_NAME_LEN + 20];
|
char keepName[PATH_MAX + 20];
|
||||||
sprintf(keepName, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
sprintf(keepName, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
||||||
|
|
||||||
tsLogObj.flag ^= 1;
|
tsLogObj.flag ^= 1;
|
||||||
tsLogObj.lines = 0;
|
tsLogObj.lines = 0;
|
||||||
char name[LOG_FILE_NAME_LEN + 20];
|
char name[PATH_MAX + 20];
|
||||||
sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
||||||
|
|
||||||
(void)taosUmaskFile(0);
|
(void)taosUmaskFile(0);
|
||||||
|
@ -383,6 +390,43 @@ static int32_t taosOpenNewLogFile() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void taosOpenNewSlowLogFile() {
|
||||||
|
(void)taosThreadMutexLock(&tsLogObj.logMutex);
|
||||||
|
int64_t delta = taosGetTimestampSec() - tsLogObj.timestampToday;
|
||||||
|
if (delta >= 0 && delta < 86400) {
|
||||||
|
uInfo("timestampToday is already equal to today, no need to open new slow log file");
|
||||||
|
(void)taosThreadMutexUnlock(&tsLogObj.logMutex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 1; atomic_val_compare_exchange_32(&tsLogObj.slowHandle->lock, 0, 1) == 1; ++i) {
|
||||||
|
if (i % 1000 == 0) {
|
||||||
|
(void)sched_yield();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tsLogObj.slowHandle->lastDuration = LOG_MAX_WAIT_MSEC; // force write
|
||||||
|
taosWriteLog(tsLogObj.slowHandle);
|
||||||
|
atomic_store_32(&tsLogObj.slowHandle->lock, 0);
|
||||||
|
|
||||||
|
char day[LOG_FILE_DAY_LEN] = {0};
|
||||||
|
getDay(day);
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
char name[PATH_MAX + LOG_FILE_DAY_LEN] = {0};
|
||||||
|
(void)snprintf(name, PATH_MAX + LOG_FILE_DAY_LEN, "%s.%s", tsLogObj.slowLogName, day);
|
||||||
|
pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
uError("open new log file fail! reason:%s, reuse lastlog", strerror(errno));
|
||||||
|
(void)taosThreadMutexUnlock(&tsLogObj.logMutex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TdFilePtr pOldFile = tsLogObj.slowHandle->pFile;
|
||||||
|
tsLogObj.slowHandle->pFile = pFile;
|
||||||
|
(void)taosCloseFile(&pOldFile);
|
||||||
|
tsLogObj.timestampToday = getTimestampToday();
|
||||||
|
(void)taosThreadMutexUnlock(&tsLogObj.logMutex);
|
||||||
|
}
|
||||||
|
|
||||||
void taosResetLog() {
|
void taosResetLog() {
|
||||||
// force create a new log file
|
// force create a new log file
|
||||||
tsLogObj.lines = tsNumOfLogLines + 10;
|
tsLogObj.lines = tsNumOfLogLines + 10;
|
||||||
|
@ -415,55 +459,44 @@ static bool taosCheckFileIsOpen(char *logFileName) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosGetLogFileName(char *fn) {
|
static void decideLogFileName(const char *fn, int32_t maxFileNum) {
|
||||||
|
tsLogObj.fileNum = maxFileNum;
|
||||||
if (tsLogObj.fileNum > 1) {
|
if (tsLogObj.fileNum > 1) {
|
||||||
for (int32_t i = 0; i < tsLogObj.fileNum; i++) {
|
for (int32_t i = 0; i < tsLogObj.fileNum; i++) {
|
||||||
char fileName[LOG_FILE_NAME_LEN];
|
char fileName[PATH_MAX + 10];
|
||||||
|
|
||||||
snprintf(fileName, LOG_FILE_NAME_LEN, "%s%d.0", fn, i);
|
(void)snprintf(fileName, PATH_MAX + 10, "%s%d.0", fn, i);
|
||||||
bool file1open = taosCheckFileIsOpen(fileName);
|
bool file1open = taosCheckFileIsOpen(fileName);
|
||||||
|
|
||||||
snprintf(fileName, LOG_FILE_NAME_LEN, "%s%d.1", fn, i);
|
(void)snprintf(fileName, PATH_MAX + 10, "%s%d.1", fn, i);
|
||||||
bool file2open = taosCheckFileIsOpen(fileName);
|
bool file2open = taosCheckFileIsOpen(fileName);
|
||||||
|
|
||||||
if (!file1open && !file2open) {
|
if (!file1open && !file2open) {
|
||||||
snprintf(tsLogObj.logName, LOG_FILE_NAME_LEN, "%s%d", fn, i);
|
(void)snprintf(tsLogObj.logName, PATH_MAX, "%s%d", fn, i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(fn) < LOG_FILE_NAME_LEN) {
|
if (strlen(fn) < PATH_MAX) {
|
||||||
strcpy(tsLogObj.logName, fn);
|
strcpy(tsLogObj.logName, fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) {
|
static void decideLogFileNameFlag(){
|
||||||
#ifdef WINDOWS_STASH
|
char name[PATH_MAX + 50] = "\0";
|
||||||
/*
|
int32_t logstat0_mtime = 0;
|
||||||
* always set maxFileNum to 1
|
int32_t logstat1_mtime = 0;
|
||||||
* means client log filename is unique in windows
|
bool log0Exist = false;
|
||||||
*/
|
bool log1Exist = false;
|
||||||
maxFileNum = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char name[LOG_FILE_NAME_LEN + 50] = "\0";
|
if (strlen(tsLogObj.logName) < PATH_MAX + 50 - 2) {
|
||||||
int32_t logstat0_mtime, logstat1_mtime;
|
strcpy(name, tsLogObj.logName);
|
||||||
|
|
||||||
tsLogObj.fileNum = maxFileNum;
|
|
||||||
taosGetLogFileName(fn);
|
|
||||||
|
|
||||||
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
|
|
||||||
strcpy(name, fn);
|
|
||||||
strcat(name, ".0");
|
strcat(name, ".0");
|
||||||
|
log0Exist = taosStatFile(name, NULL, &logstat0_mtime, NULL) == 0;
|
||||||
|
name[strlen(name) - 1] = '1';
|
||||||
|
log1Exist = taosStatFile(name, NULL, &logstat1_mtime, NULL) == 0;
|
||||||
}
|
}
|
||||||
bool log0Exist = taosStatFile(name, NULL, &logstat0_mtime, NULL) >= 0;
|
|
||||||
|
|
||||||
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
|
|
||||||
strcpy(name, fn);
|
|
||||||
strcat(name, ".1");
|
|
||||||
}
|
|
||||||
bool log1Exist = taosStatFile(name, NULL, &logstat1_mtime, NULL) >= 0;
|
|
||||||
|
|
||||||
// if none of the log files exist, open 0, if both exists, open the old one
|
// if none of the log files exist, open 0, if both exists, open the old one
|
||||||
if (!log0Exist && !log1Exist) {
|
if (!log0Exist && !log1Exist) {
|
||||||
|
@ -475,16 +508,37 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) {
|
||||||
} else {
|
} else {
|
||||||
tsLogObj.flag = (logstat0_mtime > logstat1_mtime) ? 0 : 1;
|
tsLogObj.flag = (logstat0_mtime > logstat1_mtime) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char fileName[LOG_FILE_NAME_LEN + 50] = "\0";
|
static void processLogFileName(const char* logName , int32_t maxFileNum){
|
||||||
sprintf(fileName, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
char fullName[PATH_MAX] = {0};
|
||||||
|
getFullPathName(fullName, logName);
|
||||||
|
decideLogFileName(fullName, maxFileNum);
|
||||||
|
decideLogFileNameFlag();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) {
|
||||||
|
#ifdef WINDOWS_STASH
|
||||||
|
/*
|
||||||
|
* always set maxFileNum to 1
|
||||||
|
* means client log filename is unique in windows
|
||||||
|
*/
|
||||||
|
maxFileNum = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
processLogFileName(logName, maxFileNum);
|
||||||
|
|
||||||
|
char name[PATH_MAX + 50] = "\0";
|
||||||
|
sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag);
|
||||||
(void)taosThreadMutexInit(&tsLogObj.logMutex, NULL);
|
(void)taosThreadMutexInit(&tsLogObj.logMutex, NULL);
|
||||||
|
|
||||||
(void)taosUmaskFile(0);
|
(void)taosUmaskFile(0);
|
||||||
tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE);
|
tsLogObj.logHandle = taosLogBuffNew(LOG_DEFAULT_BUF_SIZE);
|
||||||
|
if (tsLogObj.logHandle == NULL) return terrno;
|
||||||
|
|
||||||
|
tsLogObj.logHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||||
if (tsLogObj.logHandle->pFile == NULL) {
|
if (tsLogObj.logHandle->pFile == NULL) {
|
||||||
printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno));
|
printf("\nfailed to open log file:%s, reason:%s\n", name, strerror(errno));
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
(void)taosLockLogFile(tsLogObj.logHandle->pFile);
|
(void)taosLockLogFile(tsLogObj.logHandle->pFile);
|
||||||
|
@ -492,7 +546,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) {
|
||||||
// only an estimate for number of lines
|
// only an estimate for number of lines
|
||||||
int64_t filesize = 0;
|
int64_t filesize = 0;
|
||||||
if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) < 0) {
|
if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) < 0) {
|
||||||
printf("\nfailed to fstat log file:%s, reason:%s\n", fileName, strerror(errno));
|
printf("\nfailed to fstat log file:%s, reason:%s\n", name, strerror(errno));
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
tsLogObj.lines = (int32_t)(filesize / 60);
|
tsLogObj.lines = (int32_t)(filesize / 60);
|
||||||
|
@ -543,7 +597,7 @@ static inline int32_t taosBuildLogHead(char *buffer, const char *flags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *buffer, int32_t len) {
|
static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *buffer, int32_t len) {
|
||||||
if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->pFile != NULL && osLogSpaceAvailable()) {
|
if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->pFile != NULL && osLogSpaceSufficient()) {
|
||||||
taosUpdateLogNums(level);
|
taosUpdateLogNums(level);
|
||||||
if (tsAsyncLog) {
|
if (tsAsyncLog) {
|
||||||
(void)taosPushLogBuffer(tsLogObj.logHandle, buffer, len);
|
(void)taosPushLogBuffer(tsLogObj.logHandle, buffer, len);
|
||||||
|
@ -591,7 +645,7 @@ void taosPrintLog(const char *flags, int32_t level, int32_t dflag, const char *f
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosPrintLongString(const char *flags, int32_t level, int32_t dflag, const char *format, ...) {
|
void taosPrintLongString(const char *flags, int32_t level, int32_t dflag, const char *format, ...) {
|
||||||
if (!osLogSpaceAvailable()) return;
|
if (!osLogSpaceSufficient()) return;
|
||||||
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
|
if (!(dflag & DEBUG_FILE) && !(dflag & DEBUG_SCREEN)) return;
|
||||||
|
|
||||||
char *buffer = taosMemoryMalloc(LOG_MAX_LINE_DUMP_BUFFER_SIZE);
|
char *buffer = taosMemoryMalloc(LOG_MAX_LINE_DUMP_BUFFER_SIZE);
|
||||||
|
@ -611,7 +665,12 @@ void taosPrintLongString(const char *flags, int32_t level, int32_t dflag, const
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosPrintSlowLog(const char *format, ...) {
|
void taosPrintSlowLog(const char *format, ...) {
|
||||||
if (!osLogSpaceAvailable()) return;
|
if (!osLogSpaceSufficient()) return;
|
||||||
|
|
||||||
|
int64_t delta = taosGetTimestampSec() - tsLogObj.timestampToday;
|
||||||
|
if (delta >= 86400 || delta < 0) {
|
||||||
|
taosOpenNewSlowLogFile();
|
||||||
|
}
|
||||||
|
|
||||||
char *buffer = taosMemoryMalloc(LOG_MAX_LINE_DUMP_BUFFER_SIZE);
|
char *buffer = taosMemoryMalloc(LOG_MAX_LINE_DUMP_BUFFER_SIZE);
|
||||||
int32_t len = taosBuildLogHead(buffer, "");
|
int32_t len = taosBuildLogHead(buffer, "");
|
||||||
|
@ -683,7 +742,7 @@ static SLogBuff *taosLogBuffNew(int32_t bufSize) {
|
||||||
pLogBuf->minBuffSize = bufSize / 10;
|
pLogBuf->minBuffSize = bufSize / 10;
|
||||||
pLogBuf->stop = 0;
|
pLogBuf->stop = 0;
|
||||||
pLogBuf->writeInterval = LOG_DEFAULT_INTERVAL;
|
pLogBuf->writeInterval = LOG_DEFAULT_INTERVAL;
|
||||||
|
pLogBuf->lock = 0;
|
||||||
if (taosThreadMutexInit(&LOG_BUF_MUTEX(pLogBuf), NULL) < 0) goto _err;
|
if (taosThreadMutexInit(&LOG_BUF_MUTEX(pLogBuf), NULL) < 0) goto _err;
|
||||||
// tsem_init(&(pLogBuf->buffNotEmpty), 0, 0);
|
// tsem_init(&(pLogBuf->buffNotEmpty), 0, 0);
|
||||||
|
|
||||||
|
@ -765,6 +824,12 @@ static int32_t taosGetLogRemainSize(SLogBuff *pLogBuf, int32_t start, int32_t en
|
||||||
return rSize >= 0 ? rSize : LOG_BUF_SIZE(pLogBuf) + rSize;
|
return rSize >= 0 ? rSize : LOG_BUF_SIZE(pLogBuf) + rSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void taosWriteSlowLog(SLogBuff *pLogBuf){
|
||||||
|
int32_t lock = atomic_val_compare_exchange_32(&pLogBuf->lock, 0, 1);
|
||||||
|
if (lock == 1) return;
|
||||||
|
taosWriteLog(pLogBuf);
|
||||||
|
atomic_store_32(&pLogBuf->lock, 0);
|
||||||
|
}
|
||||||
static void taosWriteLog(SLogBuff *pLogBuf) {
|
static void taosWriteLog(SLogBuff *pLogBuf) {
|
||||||
int32_t start = LOG_BUF_START(pLogBuf);
|
int32_t start = LOG_BUF_START(pLogBuf);
|
||||||
int32_t end = LOG_BUF_END(pLogBuf);
|
int32_t end = LOG_BUF_END(pLogBuf);
|
||||||
|
@ -834,7 +899,11 @@ static void *taosAsyncOutputLog(void *param) {
|
||||||
int32_t writeInterval = 0;
|
int32_t writeInterval = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
writeInterval = TMIN(pLogBuf->writeInterval, pSlowBuf->writeInterval);
|
if (pSlowBuf) {
|
||||||
|
writeInterval = TMIN(pLogBuf->writeInterval, pSlowBuf->writeInterval);
|
||||||
|
} else {
|
||||||
|
writeInterval = pLogBuf->writeInterval;
|
||||||
|
}
|
||||||
count += writeInterval;
|
count += writeInterval;
|
||||||
updateCron++;
|
updateCron++;
|
||||||
taosMsleep(writeInterval);
|
taosMsleep(writeInterval);
|
||||||
|
@ -845,17 +914,12 @@ static void *taosAsyncOutputLog(void *param) {
|
||||||
|
|
||||||
// Polling the buffer
|
// Polling the buffer
|
||||||
taosWriteLog(pLogBuf);
|
taosWriteLog(pLogBuf);
|
||||||
taosWriteLog(pSlowBuf);
|
if (pSlowBuf) taosWriteSlowLog(pSlowBuf);
|
||||||
|
|
||||||
if (updateCron >= 3600 * 24 * 40 / 2) {
|
if (pLogBuf->stop || (pSlowBuf && pSlowBuf->stop)) {
|
||||||
taosUpdateDaylight();
|
|
||||||
updateCron = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pLogBuf->stop || pSlowBuf->stop) {
|
|
||||||
pLogBuf->lastDuration = LOG_MAX_WAIT_MSEC;
|
pLogBuf->lastDuration = LOG_MAX_WAIT_MSEC;
|
||||||
taosWriteLog(pLogBuf);
|
taosWriteLog(pLogBuf);
|
||||||
taosWriteLog(pSlowBuf);
|
if (pSlowBuf) taosWriteSlowLog(pSlowBuf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosInitLog("tref.log", 10);
|
taosInitLog("tref.log", 10, false);
|
||||||
|
|
||||||
SRefSpace *pSpaceList = (SRefSpace *)taosMemoryCalloc(sizeof(SRefSpace), threads);
|
SRefSpace *pSpaceList = (SRefSpace *)taosMemoryCalloc(sizeof(SRefSpace), threads);
|
||||||
TdThread *pThreadList = (TdThread *)taosMemoryCalloc(sizeof(TdThread), threads);
|
TdThread *pThreadList = (TdThread *)taosMemoryCalloc(sizeof(TdThread), threads);
|
||||||
|
|
Loading…
Reference in New Issue