提交 f9662420 编写于 作者: wafwerar's avatar wafwerar

feature(dnode): mul parameter start.

上级 7d8d382f
...@@ -7,7 +7,7 @@ project( ...@@ -7,7 +7,7 @@ project(
) )
if (NOT DEFINED TD_SOURCE_DIR) if (NOT DEFINED TD_SOURCE_DIR)
set( TD_SOURCE_DIR ${CMAKE_SOURCE_DIR} ) set( TD_SOURCE_DIR ${PROJECT_SOURCE_DIR} )
endif() endif()
set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake") set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake")
......
PROJECT(TDengine) PROJECT(TDengine)
IF (TD_LINUX) IF (TD_LINUX)
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc) INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
AUX_SOURCE_DIRECTORY(. SRC) AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(demo apitest.c) ADD_EXECUTABLE(demo apitest.c)
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread ) TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread )
...@@ -13,7 +13,7 @@ IF (TD_LINUX) ...@@ -13,7 +13,7 @@ IF (TD_LINUX)
TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua) TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua)
ENDIF () ENDIF ()
IF (TD_DARWIN) IF (TD_DARWIN)
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc) INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
AUX_SOURCE_DIRECTORY(. SRC) AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(demo demo.c) ADD_EXECUTABLE(demo demo.c)
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua) TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua)
......
...@@ -123,9 +123,9 @@ extern SDiskCfg tsDiskCfg[]; ...@@ -123,9 +123,9 @@ extern SDiskCfg tsDiskCfg[];
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char **envCmd, const char *cfgDir, const char *envFile,
const char *apolloUrl, SArray *pArgs, bool tsc); char *apolloUrl, SArray *pArgs, bool tsc);
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc); int32_t taosInitCfg(const char **envCmd, const char *cfgDir, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc);
void taosCleanupCfg(); void taosCleanupCfg();
void taosCfgDynamicOptions(const char *option, const char *value); void taosCfgDynamicOptions(const char *option, const char *value);
void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary); void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary);
......
...@@ -30,6 +30,7 @@ typedef enum { ...@@ -30,6 +30,7 @@ typedef enum {
CFG_STYPE_CFG_FILE, CFG_STYPE_CFG_FILE,
CFG_STYPE_ENV_FILE, CFG_STYPE_ENV_FILE,
CFG_STYPE_ENV_VAR, CFG_STYPE_ENV_VAR,
CFG_STYPE_ENV_CMD,
CFG_STYPE_APOLLO_URL, CFG_STYPE_APOLLO_URL,
CFG_STYPE_ARG_LIST, CFG_STYPE_ARG_LIST,
CFG_STYPE_TAOS_OPTIONS CFG_STYPE_TAOS_OPTIONS
...@@ -82,7 +83,7 @@ typedef struct SConfig { ...@@ -82,7 +83,7 @@ typedef struct SConfig {
} SConfig; } SConfig;
SConfig *cfgInit(); SConfig *cfgInit();
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr); int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr);
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
void cfgCleanup(SConfig *pCfg); void cfgCleanup(SConfig *pCfg);
...@@ -105,6 +106,8 @@ const char *cfgDtypeStr(ECfgDataType type); ...@@ -105,6 +106,8 @@ const char *cfgDtypeStr(ECfgDataType type);
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump); void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_ENV_H_
#define _TD_ENV_H_
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen);
int32_t taosEnvToCfg(const char *envStr, char *cfgStr);
#ifdef __cplusplus
}
#endif
#endif /*_TD_ENV_H_*/
...@@ -49,6 +49,8 @@ int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem); ...@@ -49,6 +49,8 @@ int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem); int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName); SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
int32_t tjsonGetObjectName(const SJson* pJson, char** pName);
int32_t tjsonGetObjectValueString(const SJson* pJson, char** pStringValue);
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal); int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal); int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal); int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
...@@ -81,6 +83,7 @@ char* tjsonToUnformattedString(const SJson* pJson); ...@@ -81,6 +83,7 @@ char* tjsonToUnformattedString(const SJson* pJson);
SJson* tjsonParse(const char* pStr); SJson* tjsonParse(const char* pStr);
bool tjsonValidateJson(const char* pJson); bool tjsonValidateJson(const char* pJson);
const char* tjsonGetError();
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -254,12 +254,12 @@ void taos_init_imp(void) { ...@@ -254,12 +254,12 @@ void taos_init_imp(void) {
deltaToUtcInitOnce(); deltaToUtcInitOnce();
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) { if (taosCreateLog("taoslog", 10, NULL, configDir, NULL, NULL, NULL, 1) != 0) {
tscInitRes = -1; tscInitRes = -1;
return; return;
} }
if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) { if (taosInitCfg(NULL, configDir, NULL, NULL, NULL, 1) != 0) {
tscInitRes = -1; tscInitRes = -1;
return; return;
} }
......
...@@ -220,7 +220,7 @@ struct SConfig *taosGetCfg() { ...@@ -220,7 +220,7 @@ struct SConfig *taosGetCfg() {
return tsCfg; return tsCfg;
} }
static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) { static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) {
char cfgDir[PATH_MAX] = {0}; char cfgDir[PATH_MAX] = {0};
char cfgFile[PATH_MAX + 100] = {0}; char cfgFile[PATH_MAX + 100] = {0};
...@@ -231,6 +231,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e ...@@ -231,6 +231,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
tstrncpy(cfgFile, cfgDir, sizeof(cfgDir)); tstrncpy(cfgFile, cfgDir, sizeof(cfgDir));
} }
if (apolloUrl == NULL || apolloUrl[0] == '\0') cfgGetApollUrl(envCmd, envFile, apolloUrl);
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) { if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr()); uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
return -1; return -1;
...@@ -251,6 +253,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e ...@@ -251,6 +253,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
return -1; return -1;
} }
if (cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd) != 0) {
uError("failed to load from cmd env variables since %s", terrstr());
return -1;
}
return 0; return 0;
} }
...@@ -325,8 +332,8 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) { ...@@ -325,8 +332,8 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1; if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1;
if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1; if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1; if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1; if (cfgAddInt32(pCfg, "pageSizeKB", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
if (cfgAddInt64(pCfg, "totalMemory(KB)", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1; if (cfgAddInt64(pCfg, "totalMemoryKB", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1; if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1; if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1; if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
...@@ -572,8 +579,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { ...@@ -572,8 +579,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
return 0; return 0;
} }
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char **envCmd, const char *cfgDir, const char *envFile,
const char *apolloUrl, SArray *pArgs, bool tsc) { char *apolloUrl, SArray *pArgs, bool tsc) {
osDefaultInit(); osDefaultInit();
SConfig *pCfg = cfgInit(); SConfig *pCfg = cfgInit();
...@@ -588,7 +595,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi ...@@ -588,7 +595,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
if (taosAddServerLogCfg(pCfg) != 0) return -1; if (taosAddServerLogCfg(pCfg) != 0) return -1;
} }
if (taosLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) { if (taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
uError("failed to load cfg since %s", terrstr()); uError("failed to load cfg since %s", terrstr());
cfgCleanup(pCfg); cfgCleanup(pCfg);
return -1; return -1;
...@@ -625,7 +632,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi ...@@ -625,7 +632,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
return 0; return 0;
} }
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) { int32_t taosInitCfg(const char **envCmd, const char *cfgDir, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) {
if (tsCfg != NULL) return 0; if (tsCfg != NULL) return 0;
tsCfg = cfgInit(); tsCfg = cfgInit();
...@@ -640,7 +647,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU ...@@ -640,7 +647,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
} }
taosAddSystemCfg(tsCfg); taosAddSystemCfg(tsCfg);
if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) { if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
uError("failed to load cfg since %s", terrstr()); uError("failed to load cfg since %s", terrstr());
cfgCleanup(tsCfg); cfgCleanup(tsCfg);
tsCfg = NULL; tsCfg = NULL;
......
...@@ -24,6 +24,7 @@ static struct { ...@@ -24,6 +24,7 @@ static struct {
bool printVersion; bool printVersion;
char envFile[PATH_MAX]; char envFile[PATH_MAX];
char apolloUrl[PATH_MAX]; char apolloUrl[PATH_MAX];
const char **envCmd;
SArray *pArgs; // SConfigPair SArray *pArgs; // SConfigPair
SDnode *pDnode; SDnode *pDnode;
EDndNodeType ntype; EDndNodeType ntype;
...@@ -56,6 +57,9 @@ static void dmSetSignalHandle() { ...@@ -56,6 +57,9 @@ static void dmSetSignalHandle() {
} }
static int32_t dmParseArgs(int32_t argc, char const *argv[]) { static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
int32_t cmdEnvIndex = 0;
global.envCmd = taosMemoryMalloc(argc-1);
memset(global.envCmd, 0, argc-1);
for (int32_t i = 1; i < argc; ++i) { for (int32_t i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-c") == 0) { if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
...@@ -70,7 +74,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { ...@@ -70,7 +74,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
} }
} else if (strcmp(argv[i], "-a") == 0) { } else if (strcmp(argv[i], "-a") == 0) {
tstrncpy(global.apolloUrl, argv[++i], PATH_MAX); tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
} else if (strcmp(argv[i], "-e") == 0) { } else if (strcmp(argv[i], "-E") == 0) {
tstrncpy(global.envFile, argv[++i], PATH_MAX); tstrncpy(global.envFile, argv[++i], PATH_MAX);
} else if (strcmp(argv[i], "-n") == 0) { } else if (strcmp(argv[i], "-n") == 0) {
global.ntype = atoi(argv[++i]); global.ntype = atoi(argv[++i]);
...@@ -84,6 +88,9 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { ...@@ -84,6 +88,9 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
global.dumpConfig = true; global.dumpConfig = true;
} else if (strcmp(argv[i], "-V") == 0) { } else if (strcmp(argv[i], "-V") == 0) {
global.printVersion = true; global.printVersion = true;
} else if (strcmp(argv[i], "-e") == 0) {
global.envCmd[cmdEnvIndex] = argv[++i];
cmdEnvIndex++;
} else { } else {
} }
} }
...@@ -129,7 +136,7 @@ static SDnodeOpt dmGetOpt() { ...@@ -129,7 +136,7 @@ static SDnodeOpt dmGetOpt() {
static int32_t dmInitLog() { static int32_t dmInitLog() {
char logName[12] = {0}; char logName[12] = {0};
snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype)); snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype));
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); return taosCreateLog(logName, 1, global.envCmd, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
} }
static void dmSetProcInfo(int32_t argc, char **argv) { static void dmSetProcInfo(int32_t argc, char **argv) {
...@@ -168,6 +175,10 @@ static int32_t dmRunDnode() { ...@@ -168,6 +175,10 @@ static int32_t dmRunDnode() {
return code; return code;
} }
static void taosCleanupArgs() {
if (global.envCmd != NULL) taosMemoryFree(global.envCmd);
}
int main(int argc, char const *argv[]) { int main(int argc, char const *argv[]) {
if (!taosCheckSystemIsSmallEnd()) { if (!taosCheckSystemIsSmallEnd()) {
printf("failed to start since on non-small-end machines\n"); printf("failed to start since on non-small-end machines\n");
...@@ -176,26 +187,31 @@ int main(int argc, char const *argv[]) { ...@@ -176,26 +187,31 @@ int main(int argc, char const *argv[]) {
if (dmParseArgs(argc, argv) != 0) { if (dmParseArgs(argc, argv) != 0) {
printf("failed to start since parse args error\n"); printf("failed to start since parse args error\n");
taosCleanupArgs();
return -1; return -1;
} }
if (global.generateGrant) { if (global.generateGrant) {
dmGenerateGrant(); dmGenerateGrant();
taosCleanupArgs();
return 0; return 0;
} }
if (global.printVersion) { if (global.printVersion) {
dmPrintVersion(); dmPrintVersion();
taosCleanupArgs();
return 0; return 0;
} }
if (dmInitLog() != 0) { if (dmInitLog() != 0) {
dError("failed to start since init log error"); printf("failed to start since init log error");
taosCleanupArgs();
return -1; return -1;
} }
if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) { if (taosInitCfg(global.envCmd, configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
dError("failed to start since read config error"); dError("failed to start since read config error");
taosCleanupArgs();
return -1; return -1;
} }
...@@ -203,9 +219,11 @@ int main(int argc, char const *argv[]) { ...@@ -203,9 +219,11 @@ int main(int argc, char const *argv[]) {
dmDumpCfg(); dmDumpCfg();
taosCleanupCfg(); taosCleanupCfg();
taosCloseLog(); taosCloseLog();
taosCleanupArgs();
return 0; return 0;
} }
dmSetProcInfo(argc, (char **)argv); dmSetProcInfo(argc, (char **)argv);
taosCleanupArgs();
return dmRunDnode(); return dmRunDnode();
} }
...@@ -124,7 +124,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) { ...@@ -124,7 +124,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to lock file:%s since %s", filepath, terrstr()); dError("failed to open file:%s since %s", filepath, terrstr());
return NULL; return NULL;
} }
......
...@@ -548,7 +548,7 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) { ...@@ -548,7 +548,7 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) {
static int32_t udfdInitLog() { static int32_t udfdInitLog() {
char logName[12] = {0}; char logName[12] = {0};
snprintf(logName, sizeof(logName), "%slog", "udfd"); snprintf(logName, sizeof(logName), "%slog", "udfd");
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0); return taosCreateLog(logName, 1, NULL, configDir, NULL, NULL, NULL, 0);
} }
void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) { void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
...@@ -656,7 +656,7 @@ int main(int argc, char *argv[]) { ...@@ -656,7 +656,7 @@ int main(int argc, char *argv[]) {
return -1; return -1;
} }
if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) { if (taosInitCfg(NULL, configDir, NULL, NULL, NULL, 0) != 0) {
fnError("failed to start since read config error"); fnError("failed to start since read config error");
return -1; return -1;
} }
......
...@@ -31,13 +31,13 @@ static int32_t parseArgs(int32_t argc, char *argv[]) { ...@@ -31,13 +31,13 @@ static int32_t parseArgs(int32_t argc, char *argv[]) {
static int32_t initLog() { static int32_t initLog() {
char logName[12] = {0}; char logName[12] = {0};
snprintf(logName, sizeof(logName), "%slog", "udfc"); snprintf(logName, sizeof(logName), "%slog", "udfc");
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0); return taosCreateLog(logName, 1, NULL, configDir, NULL, NULL, NULL, 0);
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
parseArgs(argc, argv); parseArgs(argc, argv);
initLog(); initLog();
if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) { if (taosInitCfg(NULL, configDir, NULL, NULL, NULL, 0) != 0) {
fnError("failed to start since read config error"); fnError("failed to start since read config error");
return -1; return -1;
} }
......
...@@ -11,7 +11,7 @@ target_link_libraries( ...@@ -11,7 +11,7 @@ target_link_libraries(
target_include_directories( target_include_directories(
sync sync
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync" PUBLIC "${TD_SOURCE_DIR}/include/libs/sync"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
) )
......
...@@ -199,197 +199,197 @@ target_sources(syncApplyMsgTest ...@@ -199,197 +199,197 @@ target_sources(syncApplyMsgTest
target_include_directories(syncTest target_include_directories(syncTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncEnvTest target_include_directories(syncEnvTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncPingTimerTest target_include_directories(syncPingTimerTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncIOTickQTest target_include_directories(syncIOTickQTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncIOTickPingTest target_include_directories(syncIOTickPingTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncIOSendMsgTest target_include_directories(syncIOSendMsgTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncIOClientTest target_include_directories(syncIOClientTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncIOServerTest target_include_directories(syncIOServerTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncRaftStoreTest target_include_directories(syncRaftStoreTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncEnqTest target_include_directories(syncEnqTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncIndexTest target_include_directories(syncIndexTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncInitTest target_include_directories(syncInitTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncUtilTest target_include_directories(syncUtilTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncVotesGrantedTest target_include_directories(syncVotesGrantedTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncVotesRespondTest target_include_directories(syncVotesRespondTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncIndexMgrTest target_include_directories(syncIndexMgrTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncLogStoreTest target_include_directories(syncLogStoreTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncEntryTest target_include_directories(syncEntryTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncRequestVoteTest target_include_directories(syncRequestVoteTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncRequestVoteReplyTest target_include_directories(syncRequestVoteReplyTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncAppendEntriesTest target_include_directories(syncAppendEntriesTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncAppendEntriesReplyTest target_include_directories(syncAppendEntriesReplyTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncClientRequestTest target_include_directories(syncClientRequestTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncTimeoutTest target_include_directories(syncTimeoutTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncPingTest target_include_directories(syncPingTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncPingReplyTest target_include_directories(syncPingReplyTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncRpcMsgTest target_include_directories(syncRpcMsgTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncPingTimerTest2 target_include_directories(syncPingTimerTest2
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncPingSelfTest target_include_directories(syncPingSelfTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncElectTest target_include_directories(syncElectTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncEncodeTest target_include_directories(syncEncodeTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncWriteTest target_include_directories(syncWriteTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncReplicateTest target_include_directories(syncReplicateTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncRefTest target_include_directories(syncRefTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncLogStoreCheck target_include_directories(syncLogStoreCheck
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncRaftCfgTest target_include_directories(syncRaftCfgTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncRespMgrTest target_include_directories(syncRespMgrTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncSnapshotTest target_include_directories(syncSnapshotTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
target_include_directories(syncApplyMsgTest target_include_directories(syncApplyMsgTest
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/libs/sync" "${TD_SOURCE_DIR}/include/libs/sync"
"${CMAKE_CURRENT_SOURCE_DIR}/../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
) )
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
#include "taoserror.h" #include "taoserror.h"
#include "tlog.h" #include "tlog.h"
#include "tutil.h" #include "tutil.h"
#include "tenv.h"
#include "cJSON.h"
#include "tjson.h"
#define CFG_NAME_PRINT_LEN 24 #define CFG_NAME_PRINT_LEN 24
#define CFG_SRC_PRINT_LEN 12 #define CFG_SRC_PRINT_LEN 12
...@@ -25,6 +28,7 @@ ...@@ -25,6 +28,7 @@
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath); int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath);
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath); int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath);
int32_t cfgLoadFromEnvVar(SConfig *pConfig); int32_t cfgLoadFromEnvVar(SConfig *pConfig);
int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd);
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url); int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype); int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype);
...@@ -45,7 +49,7 @@ SConfig *cfgInit() { ...@@ -45,7 +49,7 @@ SConfig *cfgInit() {
return pCfg; return pCfg;
} }
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr) {
switch (cfgType) { switch (cfgType) {
case CFG_STYPE_CFG_FILE: case CFG_STYPE_CFG_FILE:
return cfgLoadFromCfgFile(pCfg, sourceStr); return cfgLoadFromCfgFile(pCfg, sourceStr);
...@@ -55,6 +59,8 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { ...@@ -55,6 +59,8 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
return cfgLoadFromEnvVar(pCfg); return cfgLoadFromEnvVar(pCfg);
case CFG_STYPE_APOLLO_URL: case CFG_STYPE_APOLLO_URL:
return cfgLoadFromApollUrl(pCfg, sourceStr); return cfgLoadFromApollUrl(pCfg, sourceStr);
case CFG_STYPE_ENV_CMD:
return cfgLoadFromEnvCmd(pCfg, (const char **)sourceStr);
default: default:
return -1; return -1;
} }
...@@ -463,6 +469,8 @@ const char *cfgStypeStr(ECfgSrcType type) { ...@@ -463,6 +469,8 @@ const char *cfgStypeStr(ECfgSrcType type) {
return "arg_list"; return "arg_list";
case CFG_STYPE_TAOS_OPTIONS: case CFG_STYPE_TAOS_OPTIONS:
return "taos_options"; return "taos_options";
case CFG_STYPE_ENV_CMD:
return "env_cmd";
default: default:
return "invalid"; return "invalid";
} }
...@@ -584,12 +592,154 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { ...@@ -584,12 +592,154 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
} }
int32_t cfgLoadFromEnvVar(SConfig *pConfig) { int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
uDebug("load from env variables not implemented yet"); char *line = NULL, *name, *value, *value2, *value3;
int32_t olen, vlen, vlen2, vlen3;
ssize_t _bytes = 0;
TdCmdPtr pCmd = taosOpenCmd("set");
if (pCmd == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
while (!taosEOFCmd(pCmd)) {
name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0;
_bytes = taosGetLineCmd(pCmd, &line);
if (_bytes < 0) {
break;
}
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
taosEnvToCfg(line, line);
paGetToken(line, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) value3[vlen3] = 0;
}
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_VAR);
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_VAR);
}
}
taosCloseCmd(&pCmd);
if (line != NULL) taosMemoryFreeClear(line);
uInfo("load from env variables cfg success");
return 0; return 0;
} }
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) { int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
uDebug("load from env file not implemented yet"); char *buf, *name, *value, *value2, *value3;
int32_t olen, vlen, vlen2, vlen3;
int32_t index = 0;
if (envCmd == NULL) return 0;
while (envCmd[index]!=NULL) {
buf = taosMemoryMalloc(strlen(envCmd[index]));
taosEnvToCfg(envCmd[index], buf);
index++;
name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0;
paGetToken(buf, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) value3[vlen3] = 0;
}
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_CMD);
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_CMD);
}
taosMemoryFree(buf);
}
uInfo("load from env cmd cfg success");
return 0;
}
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
char *line = NULL, *name, *value, *value2, *value3;
int32_t olen, vlen, vlen2, vlen3;
ssize_t _bytes = 0;
const char *filepath = ".env";
if (envFile != NULL && strlen(envFile)>0) {
if (!taosCheckExistFile(envFile)) {
uError("fial to load env file: %s", envFile);
return -1;
}
filepath = envFile;
}else {
if (!taosCheckExistFile(filepath)) {
uInfo("fial to load env file: %s", filepath);
return 0;
}
}
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
while (!taosEOFFile(pFile)) {
name = value = value2 = value3 = NULL;
olen = vlen = vlen2 = vlen3 = 0;
_bytes = taosGetLineFile(pFile, &line);
if (_bytes <= 0) {
break;
}
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
taosEnvToCfg(line, line);
paGetToken(line, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) value3[vlen3] = 0;
}
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_FILE);
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_FILE);
}
}
taosCloseFile(&pFile);
if (line != NULL) taosMemoryFreeClear(line);
uInfo("load from env cfg file %s success", filepath);
return 0; return 0;
} }
...@@ -617,11 +767,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { ...@@ -617,11 +767,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
olen = vlen = vlen2 = vlen3 = 0; olen = vlen = vlen2 = vlen3 = 0;
_bytes = taosGetLineFile(pFile, &line); _bytes = taosGetLineFile(pFile, &line);
if (_bytes < 0) { if (_bytes <= 0) {
break; break;
} }
line[_bytes - 1] = 0; if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
paGetToken(line, &name, &olen); paGetToken(line, &name, &olen);
if (olen == 0) continue; if (olen == 0) continue;
...@@ -659,6 +809,193 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { ...@@ -659,6 +809,193 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
} }
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
uDebug("load from apoll url not implemented yet"); char *cfgLineBuf = NULL, *name, *value, *value2, *value3;
int32_t olen, vlen, vlen2, vlen3;
if (url == NULL || strlen(url) == 0) {
uInfo("fail to load apoll url");
return 0;
}
char *p = strchr(url, ':');
if (p == NULL) {
uError("fail to load apoll url: %s, unknown format", url);
return -1;
}
p++;
if (bcmp(url, "jsonFile", 8) == 0) {
char *filepath = p;
if (!taosCheckExistFile(filepath)) {
uError("fial to load json file: %s", filepath);
return -1;
}
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
return -1;
}
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
char *buf = taosMemoryMalloc(fileSize);
taosLSeekFile(pFile, 0, SEEK_SET);
if(taosReadFile(pFile, buf, fileSize) <= 0) {
taosCloseFile(&pFile);
uError("load json file error: %s", filepath);
return -1;
}
taosCloseFile(&pFile);
SJson* pJson = tjsonParse(buf);
if (NULL == pJson) {
const char *jsonParseError = tjsonGetError();
if (jsonParseError != NULL) {
uError("load json file parse error: %s", jsonParseError);
}
return -1;
}
taosMemoryFreeClear(buf);
int32_t jsonArraySize = tjsonGetArraySize(pJson);
for(int32_t i = 0; i < jsonArraySize; i++) {
cJSON* item = tjsonGetArrayItem(pJson, i);
if (item == NULL) break;
char *itemName = NULL, *itemValueString = NULL;
tjsonGetObjectName(item, &itemName);
tjsonGetObjectName(item, &itemName);
tjsonGetObjectValueString(item, &itemValueString);
if (itemValueString != NULL && itemName != NULL) {
size_t itemNameLen = strlen(itemName);
size_t itemValueStringLen = strlen(itemValueString);
cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2);
memcpy(cfgLineBuf, itemName, itemNameLen);
cfgLineBuf[itemNameLen] = ' ';
memcpy(&cfgLineBuf[itemNameLen+1], itemValueString, itemValueStringLen);
cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0';
paGetToken(cfgLineBuf, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) value3[vlen3] = 0;
}
printf("%s(%d) %s name=%s, value=%s\n", __FILE__, __LINE__,__func__,name, value);
cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL);
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_APOLLO_URL);
}
}
}
tjsonDelete(pJson);
// } else if (bcmp(url, "jsonUrl", 7) == 0) {
// } else if (bcmp(url, "etcdUrl", 7) == 0) {
} else {
uError("Unsupported url: %s", url);
return -1;
}
uInfo("load from apoll url not implemented yet");
return 0; return 0;
} }
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl) {
int32_t index = 0;
if (envCmd == NULL) return 0;
while (envCmd[index]!=NULL) {
if (bcmp(envCmd[index], "TAOS_APOLL_URL", 14) == 0) {
char *p = strchr(envCmd[index], '=');
if (p != NULL) {
p++;
if (*p == '\'') {
p++;
p[strlen(p)-1] = '\0';
}
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
uInfo("get apollo url from env cmd success");
return 0;
}
}
index++;
}
char *line = NULL;
ssize_t _bytes = 0;
TdCmdPtr pCmd = taosOpenCmd("set");
if (pCmd != NULL) {
while (!taosEOFCmd(pCmd)) {
_bytes = taosGetLineCmd(pCmd, &line);
if (_bytes < 0) {
break;
}
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
if (bcmp(line, "TAOS_APOLL_URL", 14) == 0) {
char *p = strchr(line, '=');
if (p != NULL) {
p++;
if (*p == '\'') {
p++;
p[strlen(p)-1] = '\0';
}
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl);
taosCloseCmd(&pCmd);
if (line != NULL) taosMemoryFreeClear(line);
return 0;
}
}
}
taosCloseCmd(&pCmd);
if (line != NULL) taosMemoryFreeClear(line);
}
const char *filepath = ".env";
if (envFile != NULL && strlen(envFile)>0) {
if (!taosCheckExistFile(envFile)) {
uError("fial to load env file: %s", envFile);
return -1;
}
filepath = envFile;
}else {
if (!taosCheckExistFile(filepath)) {
uInfo("fial to load env file: %s", filepath);
return 0;
}
}
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
if (pFile != NULL) {
while (!taosEOFFile(pFile)) {
_bytes = taosGetLineFile(pFile, &line);
if (_bytes <= 0) {
break;
}
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
if (bcmp(line, "TAOS_APOLL_URL", 14) == 0) {
char *p = strchr(line, '=');
if (p != NULL) {
p++;
if (*p == '\'') {
p++;
p[strlen(p)-1] = '\0';
}
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
taosCloseFile(&pFile);
if (line != NULL) taosMemoryFreeClear(line);
uInfo("get apollo url from env file success");
return 0;
}
}
}
taosCloseFile(&pFile);
if (line != NULL) taosMemoryFreeClear(line);
}
uInfo("fail get apollo url from cmd env file");
return -1;
}
\ No newline at end of file
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "tenv.h"
#include "tconfig.h"
static char toLowChar(char c) { return (c > 'Z' || c < 'A' ? c : (c - 'A' + 'a')); }
int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen) {
if (envNameStr == NULL || cfgNameStr == NULL) return -1;
char *p = cfgNameStr;
if (envNameStr[0] != 'T' || envNameStr[1] != 'A' || envNameStr[2] != 'O' || envNameStr[3] != 'S' ||
envNameStr[4] != '_') {
// if(p != envNameStr) strncpy(p, envNameStr, cfgNameMaxLen - 1);
// p[cfgNameMaxLen - 1] = '\0';
// return strlen(cfgNameStr);
cfgNameStr[0] = '\0';
return -1;
}
envNameStr += 5;
if (*envNameStr != '\0') {
*p = toLowChar(*envNameStr);
p++;
envNameStr++;
}
for (size_t i = 1; i < cfgNameMaxLen && *envNameStr != '\0'; i++) {
if (*envNameStr == '_') {
envNameStr++;
*p = *envNameStr;
if (*envNameStr == '\0') break;
} else {
*p = toLowChar(*envNameStr);
}
p++;
envNameStr++;
}
*p = '\0';
return strlen(cfgNameStr);
}
int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
if (envStr == NULL && cfgStr == NULL) {
return -1;
}
if (cfgStr != envStr) strcpy(cfgStr, envStr);
char *p = strchr(cfgStr, '=');
if (p != NULL) {
char buf[CFG_NAME_MAX_LEN];
if (*(p+1) == '\'') {
*(p+1)= ' ';
char *pEnd = &cfgStr[strlen(cfgStr)-1];
if (*pEnd == '\'') *pEnd = '\0';
}
*p = '\0';
int32_t cfgNameLen = taosEnvNameToCfgName(cfgStr, buf, CFG_NAME_MAX_LEN);
if (cfgNameLen > 0) {
memcpy(cfgStr, buf, cfgNameLen);
memset(&cfgStr[cfgNameLen], ' ', p - cfgStr - cfgNameLen + 1);
}
}
return strlen(cfgStr);
}
\ No newline at end of file
...@@ -144,6 +144,22 @@ char* tjsonToUnformattedString(const SJson* pJson) { return cJSON_PrintUnformatt ...@@ -144,6 +144,22 @@ char* tjsonToUnformattedString(const SJson* pJson) { return cJSON_PrintUnformatt
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) { return cJSON_GetObjectItem(pJson, pName); } SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) { return cJSON_GetObjectItem(pJson, pName); }
int32_t tjsonGetObjectName(const SJson* pJson, char** pName) {
*pName = ((cJSON*)pJson)->string;
if (NULL == *pName) {
return TSDB_CODE_FAILED;
}
return TSDB_CODE_SUCCESS;
}
int32_t tjsonGetObjectValueString(const SJson* pJson, char** pValueString) {
*pValueString = ((cJSON*)pJson)->valuestring;
if (NULL == *pValueString) {
return TSDB_CODE_FAILED;
}
return TSDB_CODE_SUCCESS;
}
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal) { int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal) {
char* p = cJSON_GetStringValue(tjsonGetObjectItem((cJSON*)pJson, pName)); char* p = cJSON_GetStringValue(tjsonGetObjectItem((cJSON*)pJson, pName));
if (NULL == p) { if (NULL == p) {
...@@ -309,4 +325,6 @@ bool tjsonValidateJson(const char *jIn) { ...@@ -309,4 +325,6 @@ bool tjsonValidateJson(const char *jIn) {
} }
} }
return true; return true;
} }
\ No newline at end of file
const char* tjsonGetError() { return cJSON_GetErrorPtr(); }
\ No newline at end of file
...@@ -31,7 +31,7 @@ ENDIF() ...@@ -31,7 +31,7 @@ ENDIF()
# TARGET_LINK_LIBRARIES(trefTest util common) # TARGET_LINK_LIBRARIES(trefTest util common)
#ENDIF () #ENDIF ()
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
# freelistTest # freelistTest
add_executable(freelistTest "") add_executable(freelistTest "")
......
...@@ -32,6 +32,7 @@ TEST_F(CfgTest, 01_Str) { ...@@ -32,6 +32,7 @@ TEST_F(CfgTest, 01_Str) {
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_CFG_FILE), "cfg_file"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_CFG_FILE), "cfg_file");
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_FILE), "env_file"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_FILE), "env_file");
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var");
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_CMD), "env_cmd");
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_APOLLO_URL), "apollo_url"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_APOLLO_URL), "apollo_url");
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ARG_LIST), "arg_list"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ARG_LIST), "arg_list");
EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid"); EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid");
......
...@@ -28,8 +28,8 @@ char simScriptDir[PATH_MAX] = {0}; ...@@ -28,8 +28,8 @@ char simScriptDir[PATH_MAX] = {0};
extern bool simExecSuccess; extern bool simExecSuccess;
int32_t simInitCfg() { int32_t simInitCfg() {
taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, 1); taosCreateLog("simlog", 1, NULL, configDir, NULL, NULL, NULL, 1);
taosInitCfg(configDir, NULL, NULL, NULL, 1); taosInitCfg(NULL, configDir, NULL, NULL, NULL, 1);
SConfig *pCfg = taosGetCfg(); SConfig *pCfg = taosGetCfg();
simDebugFlag = cfgGetItem(pCfg, "simDebugFlag")->i32; simDebugFlag = cfgGetItem(pCfg, "simDebugFlag")->i32;
......
...@@ -3,7 +3,7 @@ aux_source_directory(src SHELL_SRC) ...@@ -3,7 +3,7 @@ aux_source_directory(src SHELL_SRC)
add_executable(shell ${SHELL_SRC}) add_executable(shell ${SHELL_SRC})
target_link_libraries( target_link_libraries(
shell shell
PUBLIC taos_static PUBLIC taos
PRIVATE os common transport util PRIVATE os common transport util
) )
target_include_directories( target_include_directories(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册