From 6f92389ad0dc6eb22e1fce3d8a0d6f6278ef9d0f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 25 Feb 2022 10:40:53 +0800 Subject: [PATCH] arg list --- include/common/tglobal.h | 5 +++-- include/util/tconfig.h | 8 +++++++- source/client/src/clientEnv.c | 4 ++-- source/common/src/tglobal.c | 9 +++++---- source/dnode/mgmt/daemon/src/dmnMain.c | 4 ++-- source/util/src/tconfig.c | 10 ++++++++-- source/util/test/cfgTest.cpp | 1 - 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index b54058d489..a6cd04e006 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -22,6 +22,7 @@ extern "C" { #include "tcfg.h" #include "tdef.h" +#include "tarray.h" // cluster extern char tsFirst[]; @@ -94,8 +95,8 @@ extern SDiskCfg tsDiskCfg[]; #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, - const char *apolloUrl, bool tsc); -int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, bool tsc); + const char *apolloUrl, SArray *pArgs, bool tsc); +int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc); void taosCleanupCfg(); void taosCfgDynamicOptions(const char *option, const char *value); diff --git a/include/util/tconfig.h b/include/util/tconfig.h index 2eb98a3ba8..d116f6e6ea 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -18,6 +18,7 @@ #define _TD_CONFIG_H_ #include "os.h" +#include "tarray.h" #ifdef __cplusplus extern "C" { @@ -32,7 +33,6 @@ typedef enum { CFG_STYPE_ENV_VAR, CFG_STYPE_APOLLO_URL, CFG_STYPE_ARG_LIST, - CFG_STYPE_API_OPTION } ECfgSrcType; typedef enum { @@ -70,10 +70,16 @@ typedef struct SConfigItem { }; } SConfigItem; +typedef struct { + char *name; + char *value; +} SConfigPair; + typedef struct SConfig SConfig; SConfig *cfgInit(); int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr); +int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs); void cfgCleanup(SConfig *pCfg); int32_t cfgGetSize(SConfig *pCfg); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 7ffb5dcd44..08285c9d26 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -212,12 +212,12 @@ void taos_init_imp(void) { deltaToUtcInitOnce(); - if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, 1) != 0) { + if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) { tscInitRes = -1; return; } - if (taosInitCfg(configDir, NULL, NULL, 1) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) { tscInitRes = -1; return; } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index f76e8380e4..26d5322ac7 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -414,7 +414,7 @@ static void taosSetServerCfg(SConfig *pCfg) { } int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile, - const char *apolloUrl, bool tsc) { + const char *apolloUrl, SArray *pArgs, bool tsc) { osInit(); SConfig *pCfg = cfgInit(); @@ -435,13 +435,14 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi if (tsc) { taosSetClientLogCfg(pCfg); - taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32); } else { taosSetClientLogCfg(pCfg); taosSetServerLogCfg(pCfg); - taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32); } + taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32); + + if (taosInitLog(logname, logFileNum) != 0) { printf("failed to init log file since %s\n", terrstr()); cfgCleanup(pCfg); @@ -452,7 +453,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi return 0; } -int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, bool tsc) { +int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) { if (tsCfg != NULL) return 0; tsCfg = cfgInit(); diff --git a/source/dnode/mgmt/daemon/src/dmnMain.c b/source/dnode/mgmt/daemon/src/dmnMain.c index 9ce09c0a5d..df705898ca 100644 --- a/source/dnode/mgmt/daemon/src/dmnMain.c +++ b/source/dnode/mgmt/daemon/src/dmnMain.c @@ -111,12 +111,12 @@ int main(int argc, char const *argv[]) { return 0; } - if (taosCreateLog("taosdlog", 1, configDir, dmn.envFile, dmn.apolloUrl, 0) != 0) { + if (taosCreateLog("taosdlog", 1, configDir, dmn.envFile, dmn.apolloUrl, NULL, 0) != 0) { uInfo("Failed to start TDengine since read config error"); return -1; } - if (taosInitCfg(configDir, dmn.envFile, dmn.apolloUrl, 0) != 0) { + if (taosInitCfg(configDir, dmn.envFile, dmn.apolloUrl, NULL, 0) != 0) { uInfo("Failed to start TDengine since read config error"); return -1; } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 7ad08e44d5..c95adae3b4 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -66,6 +66,14 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { } } +int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs) { + int32_t size = taosArrayGetSize(pArgs); + for (int32_t i = 0; i < size; ++i) { + SConfigPair *pPair = taosArrayGet(pArgs, i); + cfgSetItem(pCfg, pPair->name, pPair->value, CFG_STYPE_ARG_LIST); + } +} + void cfgCleanup(SConfig *pCfg) { if (pCfg != NULL) { if (pCfg->hash != NULL) { @@ -441,8 +449,6 @@ const char *cfgStypeStr(ECfgSrcType type) { return "apollo_url"; case CFG_STYPE_ARG_LIST: return "arg_list"; - case CFG_STYPE_API_OPTION: - return "api_option"; default: return "invalid"; } diff --git a/source/util/test/cfgTest.cpp b/source/util/test/cfgTest.cpp index c352a4c21b..800e261dcb 100644 --- a/source/util/test/cfgTest.cpp +++ b/source/util/test/cfgTest.cpp @@ -34,7 +34,6 @@ TEST_F(CfgTest, 01_Str) { EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_APOLLO_URL), "apollo_url"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ARG_LIST), "arg_list"); - EXPECT_STREQ(cfgStypeStr(CFG_STYPE_API_OPTION), "api_option"); EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_NONE), "none"); -- GitLab