TD-1263
This commit is contained in:
parent
37922f299f
commit
f65e360976
|
@ -1013,18 +1013,18 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.ptr = &tsNumOfLogLines;
|
cfg.ptr = &tsNumOfLogLines;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 10000;
|
cfg.minValue = 1000;
|
||||||
cfg.maxValue = 2000000000;
|
cfg.maxValue = 2000000000;
|
||||||
cfg.ptrLength = 0;
|
cfg.ptrLength = 0;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
cfg.option = "logKeepDays";
|
cfg.option = "logKeepDays";
|
||||||
cfg.ptr = &tsNumOfLogLines;
|
cfg.ptr = &tsLogKeepDays;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 3650;
|
cfg.maxValue = 36500;
|
||||||
cfg.ptrLength = 0;
|
cfg.ptrLength = 0;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
|
@ -54,9 +54,9 @@ void taosRename(char* oldName, char *newName) {
|
||||||
// if newName in not empty, rename return fail.
|
// if newName in not empty, rename return fail.
|
||||||
// the newName must be empty or does not exist
|
// the newName must be empty or does not exist
|
||||||
if (rename(oldName, newName)) {
|
if (rename(oldName, newName)) {
|
||||||
uError("%s is modify to %s fail, reason:%s", oldName, newName, strerror(errno));
|
uError("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
uInfo("%s is modify to %s success!", oldName, newName);
|
uInfo("successfully to rename file %s to %s", oldName, newName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
|
||||||
DIR *dir = opendir(rootDir);
|
DIR *dir = opendir(rootDir);
|
||||||
if (dir == NULL) return;
|
if (dir == NULL) return;
|
||||||
|
|
||||||
int64_t ms = taosGetTimestampMs();
|
int64_t sec = taosGetTimestampSec();
|
||||||
struct dirent *de = NULL;
|
struct dirent *de = NULL;
|
||||||
|
|
||||||
while ((de = readdir(dir)) != NULL) {
|
while ((de = readdir(dir)) != NULL) {
|
||||||
|
@ -80,20 +80,19 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
|
||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
int32_t len = strlen(filename);
|
int32_t len = strlen(filename);
|
||||||
int64_t fileMs = 0;
|
int64_t fileSec = 0;
|
||||||
for (int i = len - 1; i >= 0; ++i) {
|
for (int i = len - 1; i >= 0; i--) {
|
||||||
if (filename[i] == '.') {
|
if (filename[i] == '.') {
|
||||||
fileMs = atoll(filename + i + 1);
|
fileSec = atoll(filename + i + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileMs <= 0) continue;
|
if (fileSec <= 100) continue;
|
||||||
int32_t days = (fileMs - ms) / 86400 + 1;
|
int32_t days = ABS(sec - fileSec) / 86400 + 1;
|
||||||
if (days > keepDays) {
|
if (days > keepDays) {
|
||||||
(void)remove(filename);
|
(void)remove(filename);
|
||||||
uInfo("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
|
uInfo("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
uTrace("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
|
uTrace("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen
|
||||||
static SLogBuff *taosLogBuffNew(int32_t bufSize);
|
static SLogBuff *taosLogBuffNew(int32_t bufSize);
|
||||||
static void taosCloseLogByFd(int32_t oldFd);
|
static void taosCloseLogByFd(int32_t oldFd);
|
||||||
static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum);
|
static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum);
|
||||||
|
extern void taosPrintGlobalCfg();
|
||||||
|
|
||||||
static int32_t taosStartLog() {
|
static int32_t taosStartLog() {
|
||||||
pthread_attr_t threadAttr;
|
pthread_attr_t threadAttr;
|
||||||
|
@ -140,11 +141,10 @@ static void taosUnLockFile(int32_t fd) {
|
||||||
static void taosKeepOldLog(char *oldName) {
|
static void taosKeepOldLog(char *oldName) {
|
||||||
if (tsLogKeepDays <= 0) return;
|
if (tsLogKeepDays <= 0) return;
|
||||||
|
|
||||||
int64_t ms = taosGetTimestampMs();
|
int64_t fileSec = taosGetTimestampSec();
|
||||||
char fileName[LOG_FILE_NAME_LEN + 20];
|
char fileName[LOG_FILE_NAME_LEN + 20];
|
||||||
snprintf(fileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, ms);
|
snprintf(fileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec);
|
||||||
|
|
||||||
uInfo("rename log file %s to %s", oldName, fileName);
|
|
||||||
taosRename(oldName, fileName);
|
taosRename(oldName, fileName);
|
||||||
taosRemoveOldLogFiles(tsLogDir, tsLogKeepDays);
|
taosRemoveOldLogFiles(tsLogDir, tsLogKeepDays);
|
||||||
}
|
}
|
||||||
|
@ -174,8 +174,10 @@ static void *taosThreadToOpenNewFile(void *param) {
|
||||||
tsLogObj.lines = 0;
|
tsLogObj.lines = 0;
|
||||||
tsLogObj.openInProgress = 0;
|
tsLogObj.openInProgress = 0;
|
||||||
taosCloseLogByFd(oldFd);
|
taosCloseLogByFd(oldFd);
|
||||||
uInfo("new log file is opened!!!");
|
|
||||||
|
uInfo(" new log file:%d is opened", tsLogObj.flag);
|
||||||
|
uInfo("==================================");
|
||||||
|
taosPrintGlobalCfg();
|
||||||
taosKeepOldLog(keepName);
|
taosKeepOldLog(keepName);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -282,20 +284,23 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
|
||||||
strcat(name, ".0");
|
strcat(name, ".0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
|
||||||
|
strcpy(name, fn);
|
||||||
|
strcat(name, ".1");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool log0Exist = stat(name, &logstat0) >= 0;
|
||||||
|
bool log1Exist = stat(name, &logstat1) >= 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 (stat(name, &logstat0) < 0) {
|
if (!log0Exist && !log1Exist) {
|
||||||
tsLogObj.flag = 0;
|
tsLogObj.flag = 0;
|
||||||
|
} else if (!log1Exist) {
|
||||||
|
tsLogObj.flag = 0;
|
||||||
|
} else if (!log0Exist) {
|
||||||
|
tsLogObj.flag = 1;
|
||||||
} else {
|
} else {
|
||||||
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
|
tsLogObj.flag = (logstat0.st_mtime > logstat1.st_mtime) ? 0 : 1;
|
||||||
strcpy(name, fn);
|
|
||||||
strcat(name, ".1");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stat(name, &logstat1) < 0) {
|
|
||||||
tsLogObj.flag = 1;
|
|
||||||
} else {
|
|
||||||
tsLogObj.flag = (logstat0.st_mtime > logstat1.st_mtime) ? 0 : 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char fileName[LOG_FILE_NAME_LEN + 50] = "\0";
|
char fileName[LOG_FILE_NAME_LEN + 50] = "\0";
|
||||||
|
|
Loading…
Reference in New Issue