Merge pull request #26845 from taosdata/fix/TD-31105-3.0
fix: load config from apollo url
This commit is contained in:
commit
3b6ce5d7dc
|
@ -396,8 +396,9 @@ struct SConfig *taosGetCfg() { return tsCfg; }
|
|||
|
||||
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile,
|
||||
char *apolloUrl) {
|
||||
char cfgDir[PATH_MAX] = {0};
|
||||
char cfgFile[PATH_MAX + 100] = {0};
|
||||
int32_t code = 0;
|
||||
char cfgDir[PATH_MAX] = {0};
|
||||
char cfgFile[PATH_MAX + 100] = {0};
|
||||
|
||||
TAOS_CHECK_RETURN(taosExpandDir(inputCfgDir, cfgDir, PATH_MAX));
|
||||
char lastC = cfgDir[strlen(cfgDir) - 1];
|
||||
|
@ -424,32 +425,32 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *input
|
|||
}
|
||||
|
||||
if (apolloUrl != NULL && apolloUrl[0] == '\0') {
|
||||
TAOS_CHECK_RETURN(cfgGetApollUrl(envCmd, envFile, apolloUrl));
|
||||
(void)(cfgGetApollUrl(envCmd, envFile, apolloUrl));
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
||||
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
|
||||
if ((code = cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl)) != 0) {
|
||||
uError("failed to load from apollo url:%s since %s", apolloUrl, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile) != 0) {
|
||||
uError("failed to load from cfg file:%s since %s", cfgFile, terrstr());
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
|
||||
if ((code = cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile)) != 0) {
|
||||
uError("failed to load from cfg file:%s since %s", cfgFile, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile) != 0) {
|
||||
uError("failed to load from env file:%s since %s", envFile, terrstr());
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
|
||||
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_FILE, envFile)) != 0) {
|
||||
uError("failed to load from env file:%s since %s", envFile, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL) != 0) {
|
||||
uError("failed to load from global env variables since %s", terrstr());
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
|
||||
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_VAR, NULL)) != 0) {
|
||||
uError("failed to load from global env variables since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd) != 0) {
|
||||
uError("failed to load from cmd env variables since %s", terrstr());
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
|
||||
if ((code = cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd)) != 0) {
|
||||
uError("failed to load from cmd env variables since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
|
@ -1280,12 +1281,12 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
}
|
||||
|
||||
if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to load cfg since %s", tstrerror(code));
|
||||
printf("failed to load cfg since %s\n", tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if ((code = cfgLoadFromArray(pCfg, pArgs)) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to load cfg from array since %s", tstrerror(code));
|
||||
printf("failed to load cfg from array since %s\n", tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -1302,12 +1303,12 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
TAOS_CHECK_RETURN(taosSetAllDebugFlag(pCfg, pDebugItem->i32));
|
||||
|
||||
if ((code = taosMulModeMkDir(tsLogDir, 0777, true)) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create dir:%s since %s", tsLogDir, tstrerror(code));
|
||||
printf("failed to create dir:%s since %s\n", tsLogDir, tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if ((code = taosInitLog(logname, logFileNum)) != 0) {
|
||||
printf("failed to init log file since %s", terrstr());
|
||||
printf("failed to init log file since %s\n", tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -1329,12 +1330,12 @@ int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, const char *
|
|||
if (cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1;
|
||||
|
||||
if ((code = taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) {
|
||||
printf("failed to load cfg since %s", terrstr());
|
||||
printf("failed to load cfg since %s\n", tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if ((code = cfgLoadFromArray(pCfg, pArgs)) != 0) {
|
||||
printf("failed to load cfg from array since %s", terrstr());
|
||||
printf("failed to load cfg from array since %s\n", tstrerror(code));
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
|
|
@ -941,7 +941,7 @@ int32_t taosBlockSIGPIPE() {
|
|||
#endif
|
||||
}
|
||||
|
||||
int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) {
|
||||
int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) {
|
||||
#ifdef WINDOWS
|
||||
// Initialize Winsock
|
||||
WSADATA wsaData;
|
||||
|
@ -959,8 +959,8 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) {
|
|||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
struct addrinfo *result = NULL;
|
||||
bool inRetry = false;
|
||||
|
||||
bool inRetry = false;
|
||||
|
||||
while (true) {
|
||||
int32_t ret = getaddrinfo(fqdn, NULL, &hints, &result);
|
||||
if (ret) {
|
||||
|
@ -972,7 +972,7 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
terrno = TAOS_SYSTEM_ERROR(ret);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
|
@ -1011,7 +1011,7 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t* ip) {
|
|||
#else
|
||||
// printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret));
|
||||
#endif
|
||||
|
||||
|
||||
*ip = 0xFFFFFFFF;
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
#include "cJSON.h"
|
||||
#include "taoserror.h"
|
||||
#include "tenv.h"
|
||||
#include "tglobal.h"
|
||||
#include "tgrant.h"
|
||||
#include "tjson.h"
|
||||
#include "tlog.h"
|
||||
#include "tunit.h"
|
||||
#include "tutil.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
#define CFG_NAME_PRINT_LEN 24
|
||||
#define CFG_SRC_PRINT_LEN 12
|
||||
|
@ -1214,8 +1214,9 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
|||
|
||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
||||
char *cfgLineBuf = NULL, *name, *value, *value2, *value3, *value4;
|
||||
SJson *pJson = NULL;
|
||||
int32_t olen, vlen, vlen2, vlen3, vlen4;
|
||||
int32_t code = 0;
|
||||
int32_t code = 0, lino = 0;
|
||||
if (url == NULL || strlen(url) == 0) {
|
||||
uInfo("apoll url not load");
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
|
@ -1228,7 +1229,6 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
}
|
||||
p++;
|
||||
|
||||
SJson *pJson = NULL;
|
||||
if (strncmp(url, "jsonFile", 8) == 0) {
|
||||
char *filepath = p;
|
||||
if (!taosCheckExistFile(filepath)) {
|
||||
|
@ -1238,7 +1238,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
||||
TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
|
||||
char *buf = taosMemoryMalloc(fileSize + 1);
|
||||
|
@ -1264,7 +1264,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
uError("load json file parse error: %s", jsonParseError);
|
||||
}
|
||||
taosMemoryFreeClear(buf);
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT);
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT);
|
||||
}
|
||||
taosMemoryFreeClear(buf);
|
||||
|
||||
|
@ -1273,16 +1273,19 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
cJSON *item = tjsonGetArrayItem(pJson, i);
|
||||
if (item == NULL) break;
|
||||
char *itemName = NULL, *itemValueString = NULL;
|
||||
TAOS_CHECK_GOTO(tjsonGetObjectName(item, &itemName), NULL, _err_json);
|
||||
TAOS_CHECK_GOTO(tjsonGetObjectValueString(item, &itemValueString), NULL, _err_json);
|
||||
if (tjsonGetObjectName(item, &itemName) != 0) {
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT);
|
||||
}
|
||||
if (tjsonGetObjectValueString(item, &itemValueString) != 0) {
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_INVALID_DATA_FMT);
|
||||
}
|
||||
|
||||
if (itemValueString != NULL && itemName != NULL) {
|
||||
size_t itemNameLen = strlen(itemName);
|
||||
size_t itemValueStringLen = strlen(itemValueString);
|
||||
void* px = taosMemoryRealloc(cfgLineBuf, itemNameLen + itemValueStringLen + 3);
|
||||
void *px = taosMemoryRealloc(cfgLineBuf, itemNameLen + itemValueStringLen + 3);
|
||||
if (NULL == px) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err_json;
|
||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
cfgLineBuf = px;
|
||||
|
@ -1321,6 +1324,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
}
|
||||
}
|
||||
tjsonDelete(pJson);
|
||||
pJson = NULL;
|
||||
|
||||
// } else if (strncmp(url, "jsonUrl", 7) == 0) {
|
||||
// } else if (strncmp(url, "etcdUrl", 7) == 0) {
|
||||
|
@ -1333,8 +1337,12 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
uInfo("load from apoll url not implemented yet");
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
|
||||
_err_json:
|
||||
_exit:
|
||||
taosMemoryFree(cfgLineBuf);
|
||||
tjsonDelete(pJson);
|
||||
if (code != 0) {
|
||||
uError("failed to load from apollo url:%s at line %d since %s", url, lino, tstrerror(code));
|
||||
}
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
|
@ -1420,7 +1428,7 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
|
|||
}
|
||||
|
||||
uInfo("fail get apollo url from cmd env file");
|
||||
TAOS_RETURN(TSDB_CODE_INVALID_PARA);
|
||||
TAOS_RETURN(TSDB_CODE_NOT_FOUND);
|
||||
}
|
||||
|
||||
struct SConfigIter {
|
||||
|
|
Loading…
Reference in New Issue