提交 6f92389a 编写于 作者: S Shengliang Guan

arg list

上级 8c7505ce
...@@ -22,6 +22,7 @@ extern "C" { ...@@ -22,6 +22,7 @@ extern "C" {
#include "tcfg.h" #include "tcfg.h"
#include "tdef.h" #include "tdef.h"
#include "tarray.h"
// cluster // cluster
extern char tsFirst[]; extern char tsFirst[];
...@@ -94,8 +95,8 @@ extern SDiskCfg tsDiskCfg[]; ...@@ -94,8 +95,8 @@ 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 *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, bool tsc); int32_t taosInitCfg(const char *cfgDir, const char *envFile, const 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);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#define _TD_CONFIG_H_ #define _TD_CONFIG_H_
#include "os.h" #include "os.h"
#include "tarray.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -32,7 +33,6 @@ typedef enum { ...@@ -32,7 +33,6 @@ typedef enum {
CFG_STYPE_ENV_VAR, CFG_STYPE_ENV_VAR,
CFG_STYPE_APOLLO_URL, CFG_STYPE_APOLLO_URL,
CFG_STYPE_ARG_LIST, CFG_STYPE_ARG_LIST,
CFG_STYPE_API_OPTION
} ECfgSrcType; } ECfgSrcType;
typedef enum { typedef enum {
...@@ -70,10 +70,16 @@ typedef struct SConfigItem { ...@@ -70,10 +70,16 @@ typedef struct SConfigItem {
}; };
} SConfigItem; } SConfigItem;
typedef struct {
char *name;
char *value;
} SConfigPair;
typedef struct SConfig SConfig; typedef struct SConfig SConfig;
SConfig *cfgInit(); SConfig *cfgInit();
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr); int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
int32_t cfgLoadArray(SConfig *pCfg, SArray *pArgs);
void cfgCleanup(SConfig *pCfg); void cfgCleanup(SConfig *pCfg);
int32_t cfgGetSize(SConfig *pCfg); int32_t cfgGetSize(SConfig *pCfg);
......
...@@ -212,12 +212,12 @@ void taos_init_imp(void) { ...@@ -212,12 +212,12 @@ void taos_init_imp(void) {
deltaToUtcInitOnce(); deltaToUtcInitOnce();
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, 1) != 0) { if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) {
tscInitRes = -1; tscInitRes = -1;
return; return;
} }
if (taosInitCfg(configDir, NULL, NULL, 1) != 0) { if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) {
tscInitRes = -1; tscInitRes = -1;
return; return;
} }
......
...@@ -414,7 +414,7 @@ static void taosSetServerCfg(SConfig *pCfg) { ...@@ -414,7 +414,7 @@ static void taosSetServerCfg(SConfig *pCfg) {
} }
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 *cfgDir, const char *envFile,
const char *apolloUrl, bool tsc) { const char *apolloUrl, SArray *pArgs, bool tsc) {
osInit(); osInit();
SConfig *pCfg = cfgInit(); SConfig *pCfg = cfgInit();
...@@ -435,13 +435,14 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi ...@@ -435,13 +435,14 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
if (tsc) { if (tsc) {
taosSetClientLogCfg(pCfg); taosSetClientLogCfg(pCfg);
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
} else { } else {
taosSetClientLogCfg(pCfg); taosSetClientLogCfg(pCfg);
taosSetServerLogCfg(pCfg); taosSetServerLogCfg(pCfg);
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
} }
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32);
if (taosInitLog(logname, logFileNum) != 0) { if (taosInitLog(logname, logFileNum) != 0) {
printf("failed to init log file since %s\n", terrstr()); printf("failed to init log file since %s\n", terrstr());
cfgCleanup(pCfg); cfgCleanup(pCfg);
...@@ -452,7 +453,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi ...@@ -452,7 +453,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, bool tsc) { int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) {
if (tsCfg != NULL) return 0; if (tsCfg != NULL) return 0;
tsCfg = cfgInit(); tsCfg = cfgInit();
......
...@@ -111,12 +111,12 @@ int main(int argc, char const *argv[]) { ...@@ -111,12 +111,12 @@ int main(int argc, char const *argv[]) {
return 0; 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"); uInfo("Failed to start TDengine since read config error");
return -1; 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"); uInfo("Failed to start TDengine since read config error");
return -1; return -1;
} }
......
...@@ -66,6 +66,14 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) { ...@@ -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) { void cfgCleanup(SConfig *pCfg) {
if (pCfg != NULL) { if (pCfg != NULL) {
if (pCfg->hash != NULL) { if (pCfg->hash != NULL) {
...@@ -441,8 +449,6 @@ const char *cfgStypeStr(ECfgSrcType type) { ...@@ -441,8 +449,6 @@ const char *cfgStypeStr(ECfgSrcType type) {
return "apollo_url"; return "apollo_url";
case CFG_STYPE_ARG_LIST: case CFG_STYPE_ARG_LIST:
return "arg_list"; return "arg_list";
case CFG_STYPE_API_OPTION:
return "api_option";
default: default:
return "invalid"; return "invalid";
} }
......
...@@ -34,7 +34,6 @@ TEST_F(CfgTest, 01_Str) { ...@@ -34,7 +34,6 @@ TEST_F(CfgTest, 01_Str) {
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var");
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(CFG_STYPE_API_OPTION), "api_option");
EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid"); EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid");
EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_NONE), "none"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_NONE), "none");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册