Merge pull request #27533 from taosdata/fix/TD-31696

fix:[TD-31696]print error log to screen if parsing config file error …
This commit is contained in:
Pan Wei 2024-08-30 17:37:03 +08:00 committed by GitHub
commit c959a13c25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 41 deletions

View File

@ -933,7 +933,7 @@ void taos_init_imp(void) {
appInfo.pInstMapByClusterId = appInfo.pInstMapByClusterId =
taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK); taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
if (NULL == appInfo.pInstMap || NULL == appInfo.pInstMapByClusterId) { if (NULL == appInfo.pInstMap || NULL == appInfo.pInstMapByClusterId) {
tscError("failed to allocate memory when init appInfo"); (void)printf("failed to allocate memory when init appInfo\n");
tscInitRes = TSDB_CODE_OUT_OF_MEMORY; tscInitRes = TSDB_CODE_OUT_OF_MEMORY;
return; return;
} }
@ -961,7 +961,7 @@ void taos_init_imp(void) {
if (InitRegexCache() != 0) { if (InitRegexCache() != 0) {
tscInitRes = -1; tscInitRes = -1;
tscError("failed to init regex cache"); (void)printf("failed to init regex cache\n");
return; return;
} }

View File

@ -485,27 +485,27 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *input
} }
if ((code = cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl)) != 0) { if ((code = cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl)) != 0) {
uError("failed to load from apollo url:%s since %s", apolloUrl, tstrerror(code)); (void)printf("failed to load from apollo url:%s since %s\n", apolloUrl, tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
if ((code = cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile)) != 0) { if ((code = cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile)) != 0) {
uError("failed to load from cfg file:%s since %s", cfgFile, tstrerror(code)); (void)printf("failed to load from cfg file:%s since %s\n", cfgFile, tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile)) != 0) { if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile)) != 0) {
uError("failed to load from env file:%s since %s", envFile, tstrerror(code)); (void)printf("failed to load from env file:%s since %s\n", envFile, tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL)) != 0) { if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL)) != 0) {
uError("failed to load from global env variables since %s", tstrerror(code)); (void)printf("failed to load from global env variables since %s\n", tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd)) != 0) { if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd)) != 0) {
uError("failed to load from cmd env variables since %s", tstrerror(code)); (void)printf("failed to load from cmd env variables since %s\n", tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -1648,12 +1648,12 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
} }
if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != TSDB_CODE_SUCCESS) { if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != TSDB_CODE_SUCCESS) {
printf("failed to load cfg since %s\n", tstrerror(code)); (void)printf("failed to load cfg since %s\n", tstrerror(code));
goto _exit; goto _exit;
} }
if ((code = cfgLoadFromArray(pCfg, pArgs)) != TSDB_CODE_SUCCESS) { if ((code = cfgLoadFromArray(pCfg, pArgs)) != TSDB_CODE_SUCCESS) {
printf("failed to load cfg from array since %s\n", tstrerror(code)); (void)printf("failed to load cfg from array since %s\n", tstrerror(code));
goto _exit; goto _exit;
} }
@ -1669,18 +1669,18 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
TAOS_CHECK_GOTO(taosSetAllDebugFlag(pCfg, pDebugItem->i32), &lino, _exit); TAOS_CHECK_GOTO(taosSetAllDebugFlag(pCfg, pDebugItem->i32), &lino, _exit);
if ((code = taosMulModeMkDir(tsLogDir, 0777, true)) != TSDB_CODE_SUCCESS) { if ((code = taosMulModeMkDir(tsLogDir, 0777, true)) != TSDB_CODE_SUCCESS) {
printf("failed to create dir:%s since %s\n", tsLogDir, tstrerror(code)); (void)printf("failed to create dir:%s since %s\n", tsLogDir, tstrerror(code));
goto _exit; goto _exit;
} }
if ((code = taosInitLog(logname, logFileNum, tsc)) != 0) { if ((code = taosInitLog(logname, logFileNum, tsc)) != 0) {
printf("failed to init log file since %s\n", tstrerror(code)); (void)printf("failed to init log file since %s\n", tstrerror(code));
goto _exit; goto _exit;
} }
_exit: _exit:
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
printf("failed to create log at %d since %s:", lino, tstrerror(code)); (void)printf("failed to create log at %d since %s\n", lino, tstrerror(code));
} }
cfgCleanup(pCfg); cfgCleanup(pCfg);
@ -1700,12 +1700,12 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *
TAOS_CHECK_GOTO(cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) ,NULL, _exit); TAOS_CHECK_GOTO(cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) ,NULL, _exit);
if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) { if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) {
printf("failed to load cfg since %s\n", tstrerror(code)); (void)printf("failed to load cfg since %s\n", tstrerror(code));
goto _exit; goto _exit;
} }
if ((code = cfgLoadFromArray(pCfg, pArgs)) != 0) { if ((code = cfgLoadFromArray(pCfg, pArgs)) != 0) {
printf("failed to load cfg from array since %s\n", tstrerror(code)); (void)printf("failed to load cfg from array since %s\n", tstrerror(code));
goto _exit; goto _exit;
} }
@ -1769,14 +1769,14 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile
TAOS_CHECK_GOTO(taosAddSystemCfg(tsCfg), &lino, _exit); TAOS_CHECK_GOTO(taosAddSystemCfg(tsCfg), &lino, _exit);
if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) { if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) {
uError("failed to load cfg since %s", tstrerror(code)); (void)printf("failed to load cfg since %s\n", tstrerror(code));
cfgCleanup(tsCfg); cfgCleanup(tsCfg);
tsCfg = NULL; tsCfg = NULL;
TAOS_RETURN(code); TAOS_RETURN(code);
} }
if ((code = cfgLoadFromArray(tsCfg, pArgs)) != 0) { if ((code = cfgLoadFromArray(tsCfg, pArgs)) != 0) {
uError("failed to load cfg from array since %s", tstrerror(code)); (void)printf("failed to load cfg from array since %s\n", tstrerror(code));
cfgCleanup(tsCfg); cfgCleanup(tsCfg);
tsCfg = NULL; tsCfg = NULL;
TAOS_RETURN(code); TAOS_RETURN(code);
@ -1798,7 +1798,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile
SConfigItem *pItem = cfgGetItem(tsCfg, "debugFlag"); SConfigItem *pItem = cfgGetItem(tsCfg, "debugFlag");
if (NULL == pItem) { if (NULL == pItem) {
uError("debugFlag not found in cfg"); (void)printf("debugFlag not found in cfg\n");
TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND);
} }
TAOS_CHECK_GOTO(taosSetAllDebugFlag(tsCfg, pItem->i32), &lino, _exit); TAOS_CHECK_GOTO(taosSetAllDebugFlag(tsCfg, pItem->i32), &lino, _exit);
@ -1811,7 +1811,7 @@ _exit:
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
cfgCleanup(tsCfg); cfgCleanup(tsCfg);
tsCfg = NULL; tsCfg = NULL;
uError("failed to init cfg at %d since %s", lino, tstrerror(code)); (void)printf("failed to init cfg at %d since %s\n", lino, tstrerror(code));
} }
TAOS_RETURN(code); TAOS_RETURN(code);

View File

@ -385,10 +385,6 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
(void)taosThreadMutexUnlock(&pCfg->lock); (void)taosThreadMutexUnlock(&pCfg->lock);
} }
if (code != 0){
uError("cfg:%s, type:%s src:%s value:%s failed since %s", pItem->name, cfgDtypeStr(pItem->dtype),
cfgStypeStr(stype), value, tstrerror(code));
}
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -1000,7 +996,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
const char *filepath = ".env"; const char *filepath = ".env";
if (envFile != NULL && strlen(envFile) > 0) { if (envFile != NULL && strlen(envFile) > 0) {
if (!taosCheckExistFile(envFile)) { if (!taosCheckExistFile(envFile)) {
uError("failed to load env file:%s", envFile); (void)printf("failed to load env file:%s\n", envFile);
TAOS_RETURN(TSDB_CODE_NOT_FOUND); TAOS_RETURN(TSDB_CODE_NOT_FOUND);
} }
filepath = envFile; filepath = envFile;
@ -1075,7 +1071,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code)); uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code));
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} else { } else {
uError("failed to load from cfg file %s since %s", filepath, tstrerror(code)); (void)printf("failed to load from cfg file %s since %s\n", filepath, tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
} }
@ -1117,7 +1113,10 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
} }
code = cfgSetItem(pConfig, name, newValue, CFG_STYPE_CFG_FILE, true); code = cfgSetItem(pConfig, name, newValue, CFG_STYPE_CFG_FILE, true);
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break; if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) {
(void)printf("cfg:%s, value:%s failed since %s\n", name,newValue, tstrerror(code));
break;
}
} else { } else {
(void)paGetToken(value + vlen + 1, &value2, &vlen2); (void)paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) { if (vlen2 != 0) {
@ -1131,7 +1130,10 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
} }
code = cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE, true); code = cfgSetItem(pConfig, name, value, CFG_STYPE_CFG_FILE, true);
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break; if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) {
(void)printf("cfg:%s, value:%s failed since %s\n", name, value, tstrerror(code));
break;
}
} }
if (strcasecmp(name, "dataDir") == 0) { if (strcasecmp(name, "dataDir") == 0) {
@ -1154,7 +1156,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
uInfo("load from cfg file %s success", filepath); uInfo("load from cfg file %s success", filepath);
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} else { } else {
uError("failed to load from cfg file %s since %s", filepath, tstrerror(code)); (void)printf("failed to load from cfg file %s since %s\n", filepath, tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
} }
@ -1236,7 +1238,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
char *p = strchr(url, ':'); char *p = strchr(url, ':');
if (p == NULL) { if (p == NULL) {
uError("fail to load apoll url: %s, unknown format", url); (void)printf("fail to load apoll url: %s, unknown format\n", url);
TAOS_RETURN(TSDB_CODE_INVALID_PARA); TAOS_RETURN(TSDB_CODE_INVALID_PARA);
} }
p++; p++;
@ -1244,7 +1246,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
if (strncmp(url, "jsonFile", 8) == 0) { if (strncmp(url, "jsonFile", 8) == 0) {
char *filepath = p; char *filepath = p;
if (!taosCheckExistFile(filepath)) { if (!taosCheckExistFile(filepath)) {
uError("failed to load json file:%s", filepath); (void)printf("failed to load json file:%s\n", filepath);
TAOS_RETURN(TSDB_CODE_NOT_FOUND); TAOS_RETURN(TSDB_CODE_NOT_FOUND);
} }
@ -1256,7 +1258,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
char *buf = taosMemoryMalloc(fileSize + 1); char *buf = taosMemoryMalloc(fileSize + 1);
if (!buf) { if (!buf) {
(void)taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
uError("load json file error: %s, failed to alloc memory", filepath); (void)printf("load json file error: %s, failed to alloc memory\n", filepath);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
} }
@ -1264,7 +1266,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
(void)taosLSeekFile(pFile, 0, SEEK_SET); (void)taosLSeekFile(pFile, 0, SEEK_SET);
if (taosReadFile(pFile, buf, fileSize) <= 0) { if (taosReadFile(pFile, buf, fileSize) <= 0) {
(void)taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
uError("load json file error: %s", filepath); (void)printf("load json file error: %s\n", filepath);
taosMemoryFreeClear(buf); taosMemoryFreeClear(buf);
TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT); TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT);
} }
@ -1273,7 +1275,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
if (NULL == pJson) { if (NULL == pJson) {
const char *jsonParseError = tjsonGetError(); const char *jsonParseError = tjsonGetError();
if (jsonParseError != NULL) { if (jsonParseError != NULL) {
uError("load json file parse error: %s", jsonParseError); (void)printf("load json file parse error: %s\n", jsonParseError);
} }
taosMemoryFreeClear(buf); taosMemoryFreeClear(buf);
TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT); TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT);
@ -1341,7 +1343,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
// } else if (strncmp(url, "jsonUrl", 7) == 0) { // } else if (strncmp(url, "jsonUrl", 7) == 0) {
// } else if (strncmp(url, "etcdUrl", 7) == 0) { // } else if (strncmp(url, "etcdUrl", 7) == 0) {
} else { } else {
uError("Unsupported url: %s", url); (void)printf("Unsupported url: %s\n", url);
TAOS_RETURN(TSDB_CODE_INVALID_PARA); TAOS_RETURN(TSDB_CODE_INVALID_PARA);
} }
@ -1353,7 +1355,7 @@ _exit:
taosMemoryFree(cfgLineBuf); taosMemoryFree(cfgLineBuf);
tjsonDelete(pJson); tjsonDelete(pJson);
if (code != 0) { if (code != 0) {
uError("failed to load from apollo url:%s at line %d since %s", url, lino, tstrerror(code)); (void)printf("failed to load from apollo url:%s at line %d since %s\n", url, lino, tstrerror(code));
} }
TAOS_RETURN(code); TAOS_RETURN(code);
} }

View File

@ -206,7 +206,7 @@ int32_t taosInitSlowLog() {
(void)taosUmaskFile(0); (void)taosUmaskFile(0);
tsLogObj.slowHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); tsLogObj.slowHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (tsLogObj.slowHandle->pFile == NULL) { if (tsLogObj.slowHandle->pFile == NULL) {
printf("\nfailed to open slow log file:%s, reason:%s\n", name, strerror(errno)); (void)printf("\nfailed to open slow log file:%s, reason:%s\n", name, strerror(errno));
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} }
@ -529,7 +529,7 @@ static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) {
processLogFileName(logName, maxFileNum); processLogFileName(logName, maxFileNum);
char name[PATH_MAX + 50] = "\0"; char name[PATH_MAX + 50] = "\0";
sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag); (void)sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag);
(void)taosThreadMutexInit(&tsLogObj.logMutex, NULL); (void)taosThreadMutexInit(&tsLogObj.logMutex, NULL);
(void)taosUmaskFile(0); (void)taosUmaskFile(0);
@ -538,7 +538,7 @@ static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) {
tsLogObj.logHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE); 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", name, strerror(errno)); (void)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);
@ -546,18 +546,18 @@ static int32_t taosInitNormalLog(const char *logName, 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", name, strerror(errno)); (void)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);
(void)taosLSeekFile(tsLogObj.logHandle->pFile, 0, SEEK_END); (void)taosLSeekFile(tsLogObj.logHandle->pFile, 0, SEEK_END);
sprintf(name, "==================================================\n"); (void)sprintf(name, "==================================================\n");
(void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); (void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name));
sprintf(name, " new log file \n"); (void)sprintf(name, " new log file \n");
(void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); (void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name));
sprintf(name, "==================================================\n"); (void)sprintf(name, "==================================================\n");
(void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name)); (void)taosWriteFile(tsLogObj.logHandle->pFile, name, (uint32_t)strlen(name));
return 0; return 0;