From 06a7ba7b80734d987aba45bb027f6c82117996f7 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 22 Feb 2022 19:49:11 +0800 Subject: [PATCH] config integrate with taosd --- include/dnode/mgmt/dnode.h | 20 +- include/dnode/mnode/mnode.h | 3 +- include/libs/config/config.h | 61 +- include/util/tlog.h | 3 + source/client/src/clientEnv.c | 8 +- source/common/src/tglobal.c | 340 ------------ source/dnode/mgmt/daemon/inc/dmnInt.h | 16 +- source/dnode/mgmt/daemon/src/daemon.c | 131 ++--- source/dnode/mgmt/daemon/src/dmnCfg.c | 318 +++++------ source/dnode/mgmt/daemon/src/dmnLog.c | 67 +++ source/dnode/mgmt/daemon/src/dmnUtil.c | 35 ++ source/dnode/mnode/impl/inc/mndInt.h | 2 +- source/libs/config/CMakeLists.txt | 2 +- source/libs/config/inc/cfgInt.h | 1 + source/libs/config/src/config.c | 521 ++++++++++-------- source/libs/config/test/cfgTest.cpp | 94 +--- .../src/ttimezone.c => os/src/osTimeZone.c} | 9 +- source/util/src/tlog.c | 9 + 18 files changed, 676 insertions(+), 964 deletions(-) create mode 100644 source/dnode/mgmt/daemon/src/dmnUtil.c rename source/{common/src/ttimezone.c => os/src/osTimeZone.c} (95%) diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index e64d358de4..99fe2457a8 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -27,15 +27,16 @@ typedef struct SDnode SDnode; /* ------------------------ Environment ------------------ */ typedef struct { - int32_t sver; - int32_t numOfCores; - int16_t numOfCommitThreads; - int8_t enableTelem; - char timezone[TSDB_TIMEZONE_LEN]; - char locale[TSDB_LOCALE_LEN]; - char charset[TSDB_LOCALE_LEN]; - char buildinfo[64]; - char gitinfo[48]; + int32_t sver; + int32_t numOfCores; + uint16_t numOfCommitThreads; + bool enableTelem; + bool printAuth; + char timezone[TSDB_TIMEZONE_LEN]; + char locale[TSDB_LOCALE_LEN]; + char charset[TSDB_LOCALE_LEN]; + char buildinfo[64]; + char gitinfo[48]; } SDnodeEnvCfg; /** @@ -65,6 +66,7 @@ typedef struct { char localEp[TSDB_EP_LEN]; char localFqdn[TSDB_FQDN_LEN]; char firstEp[TSDB_EP_LEN]; + char secondEp[TSDB_EP_LEN]; } SDnodeObjCfg; /** diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index e1306800d3..01855f6d92 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -46,7 +46,8 @@ typedef struct SMnodeLoad { typedef struct SMnodeCfg { int32_t sver; - int8_t enableTelem; + bool enableTelem; + bool printAuth; int32_t statusInterval; int32_t shellActivityTimer; char *timezone; diff --git a/include/libs/config/config.h b/include/libs/config/config.h index cf8daae72b..c3e026e20b 100644 --- a/include/libs/config/config.h +++ b/include/libs/config/config.h @@ -38,8 +38,6 @@ typedef enum { typedef enum { CFG_DTYPE_NONE, CFG_DTYPE_BOOL, - CFG_DTYPE_INT8, - CFG_DTYPE_UINT16, CFG_DTYPE_INT32, CFG_DTYPE_INT64, CFG_DTYPE_FLOAT, @@ -51,37 +49,24 @@ typedef enum { CFG_DTYPE_TIMEZONE } ECfgDataType; -typedef enum { - CFG_UTYPE_NONE, - CFG_UTYPE_GB, - CFG_UTYPE_MB, - CFG_UTYPE_BYTE, - CFG_UTYPE_SECOND, - CFG_UTYPE_MS, - CFG_UTYPE_PERCENT -} ECfgUnitType; - typedef struct SConfigItem { ECfgSrcType stype; - ECfgUnitType utype; ECfgDataType dtype; char *name; union { - bool boolVal; - int8_t int8Val; - uint16_t uint16Val; - int32_t int32Val; - int64_t int64Val; - float floatVal; - char *strVal; + bool bval; + float fval; + int32_t i32; + int64_t i64; + char *str; }; union { - int64_t minIntVal; - double minFloatVal; + int64_t imin; + double fmin; }; union { - int64_t maxIntVal; - double maxFloatVal; + int64_t imax; + double fmax; }; } SConfigItem; @@ -96,27 +81,19 @@ SConfigItem *cfgIterate(SConfig *pConfig, SConfigItem *pIter); void cfgCancelIterate(SConfig *pConfig, SConfigItem *pIter); SConfigItem *cfgGetItem(SConfig *pConfig, const char *name); -int32_t cfgAddBool(SConfig *pConfig, const char *name, bool defaultVal, ECfgUnitType utype); -int32_t cfgAddInt8(SConfig *pConfig, const char *name, int8_t defaultVal, int64_t minval, int64_t maxval, - ECfgUnitType utype); -int32_t cfgAddUInt16(SConfig *pConfig, const char *name, uint16_t defaultVal, int64_t minval, int64_t maxval, - ECfgUnitType utype); -int32_t cfgAddInt32(SConfig *pConfig, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval, - ECfgUnitType utype); -int32_t cfgAddInt64(SConfig *pConfig, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval, - ECfgUnitType utype); -int32_t cfgAddFloat(SConfig *pConfig, const char *name, float defaultVal, double minval, double maxval, - ECfgUnitType utype); -int32_t cfgAddString(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype); -int32_t cfgAddIpStr(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype); -int32_t cfgAddDir(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype); -int32_t cfgAddLocale(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype); -int32_t cfgAddCharset(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype); -int32_t cfgAddTimezone(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype); +int32_t cfgAddBool(SConfig *pConfig, const char *name, bool defaultVal); +int32_t cfgAddInt32(SConfig *pConfig, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval); +int32_t cfgAddInt64(SConfig *pConfig, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval); +int32_t cfgAddFloat(SConfig *pConfig, const char *name, float defaultVal, double minval, double maxval); +int32_t cfgAddString(SConfig *pConfig, const char *name, const char *defaultVal); +int32_t cfgAddIpStr(SConfig *pConfig, const char *name, const char *defaultVa); +int32_t cfgAddDir(SConfig *pConfig, const char *name, const char *defaultVal); +int32_t cfgAddLocale(SConfig *pConfig, const char *name, const char *defaultVal); +int32_t cfgAddCharset(SConfig *pConfig, const char *name, const char *defaultVal); +int32_t cfgAddTimezone(SConfig *pConfig, const char *name, const char *defaultVal); const char *cfgStypeStr(ECfgSrcType type); const char *cfgDtypeStr(ECfgDataType type); -const char *cfgUtypeStr(ECfgUnitType type); #ifdef __cplusplus } diff --git a/include/util/tlog.h b/include/util/tlog.h index 26a5417320..d5a23f9e96 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -74,6 +74,9 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . void taosDumpData(unsigned char *msg, int32_t len); + +void taosSetDebugFlag(int32_t flag); + #ifdef __cplusplus } #endif diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 1fa6446ec7..dba4aff3a7 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -73,6 +73,7 @@ static void deregisterRequest(SRequestObj* pRequest) { } static void tscInitLogFile() { + #if 0 taosReadGlobalLogCfg(); if (mkdir(tsLogDir, 0755) != 0 && errno != EEXIST) { printf("failed to create log dir:%s\n", tsLogDir); @@ -86,6 +87,7 @@ static void tscInitLogFile() { if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) { printf("failed to open log file in directory:%s\n", tsLogDir); } + #endif } // todo close the transporter properly @@ -224,9 +226,10 @@ void taos_init_imp(void) { srand(taosGetTimestampSec()); deltaToUtcInitOnce(); +#if 0 taosInitGlobalCfg(); taosReadCfgFromFile(); - +#endif tscInitLogFile(); if (taosCheckAndPrintCfg()) { tscInitRes = -1; @@ -268,6 +271,7 @@ int taos_init() { } int taos_options_imp(TSDB_OPTION option, const char *str) { +#if 0 SGlobalCfg *cfg = NULL; switch (option) { @@ -418,7 +422,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { tscError("Invalid option %d", option); return -1; } - +#endif return 0; } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 398ded034c..35ded42991 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -340,47 +340,6 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); - // port - cfg.option = "serverPort"; - cfg.ptr = &tsServerPort; - cfg.valType = TAOS_CFG_VTYPE_UINT16; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 1; - cfg.maxValue = 65056; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "supportVnodes"; - cfg.ptr = &tsNumOfSupportVnodes; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 65536; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - // directory - cfg.option = "configDir"; - cfg.ptr = configDir; - cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = TSDB_FILENAME_LEN; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "logDir"; - cfg.ptr = tsLogDir; - cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_LOG; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = TSDB_FILENAME_LEN; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); cfg.option = "scriptDir"; cfg.ptr = tsScriptDir; @@ -402,36 +361,6 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); - // dnode configs - cfg.option = "numOfThreadsPerCore"; - cfg.ptr = &tsNumOfThreadsPerCore; - cfg.valType = TAOS_CFG_VTYPE_FLOAT; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 10; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "numOfCommitThreads"; - cfg.ptr = &tsNumOfCommitThreads; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; - cfg.minValue = 1; - cfg.maxValue = 100; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "ratioOfQueryCores"; - cfg.ptr = &tsRatioOfQueryCores; - cfg.valType = TAOS_CFG_VTYPE_FLOAT; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; - cfg.minValue = 0.0f; - cfg.maxValue = 2.0f; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); cfg.option = "maxNumOfDistinctRes"; cfg.ptr = &tsMaxNumOfDistinctResults; @@ -494,25 +423,6 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_SECOND; taosAddConfigOption(cfg); - cfg.option = "statusInterval"; - cfg.ptr = &tsStatusInterval; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 1; - cfg.maxValue = 10; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_SECOND; - taosAddConfigOption(cfg); - - cfg.option = "shellActivityTimer"; - cfg.ptr = &tsShellActivityTimer; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 1; - cfg.maxValue = 120; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_SECOND; - taosAddConfigOption(cfg); cfg.option = "minSlidingTime"; cfg.ptr = &tsMinSlidingTime; @@ -654,47 +564,6 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); - // locale & charset - cfg.option = "timezone"; - cfg.ptr = tsTimezone; - cfg.valType = TAOS_CFG_VTYPE_STRING; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = TSDB_TIMEZONE_LEN; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "locale"; - cfg.ptr = tsLocale; - cfg.valType = TAOS_CFG_VTYPE_STRING; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = TSDB_LOCALE_LEN; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "charset"; - cfg.ptr = tsCharset; - cfg.valType = TAOS_CFG_VTYPE_STRING; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = TSDB_LOCALE_LEN; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - // connect configs - cfg.option = "maxShellConns"; - cfg.ptr = &tsMaxShellConns; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; - cfg.minValue = 10; - cfg.maxValue = 50000000; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); cfg.option = "maxConnections"; cfg.ptr = &tsMaxConnections; @@ -746,176 +615,7 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); - // debug flag - cfg.option = "numOfLogLines"; - cfg.ptr = &tsNumOfLogLines; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 1000; - cfg.maxValue = 2000000000; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - cfg.option = "logKeepDays"; - cfg.ptr = &tsLogKeepDays; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = -365000; - cfg.maxValue = 365000; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "asyncLog"; - cfg.ptr = &tsAsyncLog; - cfg.valType = TAOS_CFG_VTYPE_INT8; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 1; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "debugFlag"; - cfg.ptr = &debugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "mDebugFlag"; - cfg.ptr = &mDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "dDebugFlag"; - cfg.ptr = &dDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "sDebugFlag"; - cfg.ptr = &sDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "wDebugFlag"; - cfg.ptr = &wDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "rpcDebugFlag"; - cfg.ptr = &rpcDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "tmrDebugFlag"; - cfg.ptr = &tmrDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "cDebugFlag"; - cfg.ptr = &cDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "jniDebugFlag"; - cfg.ptr = &jniDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "uDebugFlag"; - cfg.ptr = &uDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "qDebugFlag"; - cfg.ptr = &qDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "vDebugFlag"; - cfg.ptr = &vDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "tsdbDebugFlag"; - cfg.ptr = &tsdbDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "cqDebugFlag"; - cfg.ptr = &cqDebugFlag; - cfg.valType = TAOS_CFG_VTYPE_INT32; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; - cfg.minValue = 0; - cfg.maxValue = 255; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); cfg.option = "enableRecordSql"; cfg.ptr = &tsTscEnableRecordSql; @@ -937,46 +637,6 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosAddConfigOption(cfg); - // version info - cfg.option = "gitinfo"; - cfg.ptr = gitinfo; - cfg.valType = TAOS_CFG_VTYPE_STRING; - cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "gitinfoOfInternal"; - cfg.ptr = gitinfoOfInternal; - cfg.valType = TAOS_CFG_VTYPE_STRING; - cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "buildinfo"; - cfg.ptr = buildinfo; - cfg.valType = TAOS_CFG_VTYPE_STRING; - cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - - cfg.option = "version"; - cfg.ptr = version; - cfg.valType = TAOS_CFG_VTYPE_STRING; - cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; - cfg.minValue = 0; - cfg.maxValue = 0; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); cfg.option = "maxBinaryDisplayWidth"; cfg.ptr = &tsMaxBinaryDisplayWidth; diff --git a/source/dnode/mgmt/daemon/inc/dmnInt.h b/source/dnode/mgmt/daemon/inc/dmnInt.h index 3a28288bed..dd264b982d 100644 --- a/source/dnode/mgmt/daemon/inc/dmnInt.h +++ b/source/dnode/mgmt/daemon/inc/dmnInt.h @@ -20,15 +20,25 @@ #include "config.h" #include "dnode.h" #include "tglobal.h" -#include "tnote.h" #include "ulog.h" +#include "taoserror.h" #ifdef __cplusplus extern "C" { #endif -int32_t dnmInitCfg(SDnodeEnvCfg *pEnvCfg, SDnodeObjCfg *pObjCfg, const char *configFile, const char *envFile, - const char *apolloUrl); +int32_t dmnInitLogCfg(SConfig *pCfg); +int32_t dmnInitLog(const char *cfgDir, const char *envFile, const char *apolloUrl); + +int32_t dmnLoadCfg(SConfig *pConfig, const char *inputCfgDir, const char *envFile, const char *apolloUrl); +SConfig *dmnReadCfg(const char *cfgDir, const char *envFile, const char *apolloUrl); + +SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg); +SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg); + +void dmnDumpCfg(SConfig *pCfg); +void dmnPrintVersion(SConfig *pCfg); +void dmnGenerateGrant(); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/daemon/src/daemon.c b/source/dnode/mgmt/daemon/src/daemon.c index a40867d11d..a91662a316 100644 --- a/source/dnode/mgmt/daemon/src/daemon.c +++ b/source/dnode/mgmt/daemon/src/daemon.c @@ -14,7 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "dnode.h" #include "dmnInt.h" static struct { @@ -24,14 +23,16 @@ static struct { bool printAuth; bool printVersion; char configDir[PATH_MAX]; + char envFile[PATH_MAX]; + char apolloUrl[PATH_MAX]; } dmn = {0}; -void dmnSigintHandle(int signum, void *info, void *ctx) { +static void dmnSigintHandle(int signum, void *info, void *ctx) { uInfo("singal:%d is received", signum); dmn.stop = true; } -void dmnSetSignalHandle() { +static void dmnSetSignalHandle() { taosSetSignal(SIGTERM, dmnSigintHandle); taosSetSignal(SIGHUP, dmnSigintHandle); taosSetSignal(SIGINT, dmnSigintHandle); @@ -39,10 +40,17 @@ void dmnSetSignalHandle() { taosSetSignal(SIGBREAK, dmnSigintHandle); } -int dmnParseOption(int argc, char const *argv[]) { +static void dmnWaitSignal() { + dmnSetSignalHandle(); + while (!dmn.stop) { + taosMsleep(100); + } +} + +static int32_t dmnParseOption(int32_t argc, char const *argv[]) { tstrncpy(dmn.configDir, "/etc/taos", PATH_MAX); - for (int i = 1; i < argc; ++i) { + for (int32_t i = 1; i < argc; ++i) { if (strcmp(argv[i], "-c") == 0) { if (i < argc - 1) { if (strlen(argv[++i]) >= PATH_MAX) { @@ -58,8 +66,6 @@ int dmnParseOption(int argc, char const *argv[]) { dmn.dumpConfig = true; } else if (strcmp(argv[i], "-k") == 0) { dmn.generateGrant = true; - } else if (strcmp(argv[i], "-A") == 0) { - dmn.printAuth = true; } else if (strcmp(argv[i], "-V") == 0) { dmn.printVersion = true; } else { @@ -69,86 +75,17 @@ int dmnParseOption(int argc, char const *argv[]) { return 0; } -void dmnGenerateGrant() { -#if 0 - grantParseParameter(); -#endif -} - -void dmnPrintVersion() { -#ifdef TD_ENTERPRISE - char *releaseName = "enterprise"; -#else - char *releaseName = "community"; -#endif - printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); - printf("gitinfo: %s\n", gitinfo); - printf("gitinfoI: %s\n", gitinfoOfInternal); - printf("builuInfo: %s\n", buildinfo); -} - -int dmnReadConfig(const char *path) { - tstrncpy(configDir, dmn.configDir, PATH_MAX); - taosInitGlobalCfg(); - taosReadGlobalLogCfg(); - - if (taosMkDir(tsLogDir) != 0) { - printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno)); - return -1; - } - - char temp[PATH_MAX]; - snprintf(temp, PATH_MAX, "%s/taosdlog", tsLogDir); - if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) { - printf("failed to init log file\n"); - return -1; - } - - if (taosInitNotes() != 0) { - printf("failed to init log file\n"); - return -1; - } - - if (taosReadCfgFromFile() != 0) { - uError("failed to read config"); - return -1; - } - - if (taosCheckAndPrintCfg() != 0) { - uError("failed to check config"); - return -1; - } - - taosSetCoreDump(tsEnableCoreFile); - return 0; -} - -void dmnDumpConfig() { taosDumpGlobalCfg(); } - -void dmnWaitSignal() { - dmnSetSignalHandle(); - while (!dmn.stop) { - taosMsleep(100); - } -} - -int dmnRunDnode() { - SDnodeEnvCfg envCfg = {0}; - SDnodeObjCfg objCfg = {0}; - - if (dnmInitCfg(&envCfg, &objCfg, "", "", "") != 0) { - uInfo("Failed to start TDengine since load config error"); - return -1; - } - +int32_t dmnRunDnode(SConfig *pCfg) { + SDnodeEnvCfg envCfg = dmnGetEnvCfg(pCfg); if (dndInit(&envCfg) != 0) { - uInfo("Failed to start TDengine, please check the log at %s", tsLogDir); + uInfo("Failed to start TDengine, please check the log"); return -1; } + SDnodeObjCfg objCfg = dmnGetObjCfg(pCfg); SDnode *pDnode = dndCreate(&objCfg); if (pDnode == NULL) { - uInfo("Failed to start TDengine, please check the log at %s", tsLogDir); + uInfo("Failed to start TDengine, please check the log"); return -1; } @@ -168,23 +105,33 @@ int main(int argc, char const *argv[]) { } if (dmn.generateGrant) { - dmnGenerateGrant(); - return 0; + dmnGenerateGrant(); + return 0; } - if (dmn.printVersion) { - dmnPrintVersion(); - return 0; - } - - if (dmnReadConfig(dmn.configDir) != 0) { + if (dmnInitLog(dmn.configDir, dmn.envFile, dmn.apolloUrl) != 0) { return -1; } - if (dmn.dumpConfig) { - dmnDumpConfig(); + SConfig *pCfg = dmnReadCfg(dmn.configDir, dmn.envFile, dmn.apolloUrl); + if (pCfg == NULL) { + uInfo("Failed to start TDengine since read config error"); + return -1; + } + + if (dmn.printVersion) { + dmnPrintVersion(pCfg); + cfgCleanup(pCfg); return 0; } - return dmnRunDnode(); + if (dmn.dumpConfig) { + dmnDumpCfg(pCfg); + cfgCleanup(pCfg); + return 0; + } + + int32_t code = dmnRunDnode(pCfg); + cfgCleanup(pCfg); + return code; } diff --git a/source/dnode/mgmt/daemon/src/dmnCfg.c b/source/dnode/mgmt/daemon/src/dmnCfg.c index 1bd8476f94..e4414d8dad 100644 --- a/source/dnode/mgmt/daemon/src/dmnCfg.c +++ b/source/dnode/mgmt/daemon/src/dmnCfg.c @@ -16,205 +16,157 @@ #define _DEFAULT_SOURCE #include "dmnInt.h" -static void dmnInitEnvCfg(SDnodeEnvCfg *pCfg) { - pCfg->sver = 30000000; // 3.0.0.0 - pCfg->numOfCores = tsNumOfCores; - pCfg->numOfCommitThreads = tsNumOfCommitThreads; - pCfg->enableTelem = 0; - tstrncpy(pCfg->timezone, tsTimezone, TSDB_TIMEZONE_LEN); - tstrncpy(pCfg->locale, tsLocale, TSDB_LOCALE_LEN); - tstrncpy(pCfg->charset, tsCharset, TSDB_LOCALE_LEN); - tstrncpy(pCfg->buildinfo, buildinfo, 64); - tstrncpy(pCfg->gitinfo, gitinfo, 48); +static int32_t dmnInitDnodeCfg(SConfig *pConfig) { + if (cfgAddString(pConfig, "version", version) != 0) return -1; + if (cfgAddString(pConfig, "buildinfo", buildinfo) != 0) return -1; + if (cfgAddString(pConfig, "gitinfo", gitinfo) != 0) return -1; + if (cfgAddTimezone(pConfig, "timezone", "") != 0) return -1; + if (cfgAddLocale(pConfig, "locale", "") != 0) return -1; + if (cfgAddCharset(pConfig, "charset", "") != 0) return -1; + if (cfgAddInt32(pConfig, "numOfCores", 1, 1, 100000) != 0) return -1; + if (cfgAddInt32(pConfig, "numOfCommitThreads", 4, 1, 1000) != 0) return -1; + if (cfgAddBool(pConfig, "telemetryReporting", 0) != 0) return -1; + if (cfgAddBool(pConfig, "enableCoreFile", 0) != 0) return -1; + if (cfgAddInt32(pConfig, "supportVnodes", 256, 0, 65536) != 0) return -1; + if (cfgAddInt32(pConfig, "statusInterval", 1, 1, 30) != 0) return -1; + if (cfgAddFloat(pConfig, "numOfThreadsPerCore", 1, 0, 10) != 0) return -1; + if (cfgAddFloat(pConfig, "ratioOfQueryCores", 1, 0, 5) != 0) return -1; + if (cfgAddInt32(pConfig, "maxShellConns", 50000, 10, 50000000) != 0) return -1; + if (cfgAddInt32(pConfig, "shellActivityTimer", 3, 1, 120) != 0) return -1; + if (cfgAddInt32(pConfig, "serverPort", 6030, 1, 65056) != 0) return -1; + return 0; } -static void dmnInitObjCfg(SDnodeObjCfg *pCfg) { - pCfg->numOfSupportVnodes = tsNumOfSupportVnodes; - pCfg->statusInterval = tsStatusInterval; - pCfg->numOfThreadsPerCore = tsNumOfThreadsPerCore; - pCfg->ratioOfQueryCores = tsRatioOfQueryCores; - pCfg->maxShellConns = tsMaxShellConns; - pCfg->shellActivityTimer = tsShellActivityTimer; - pCfg->serverPort = tsServerPort; - tstrncpy(pCfg->dataDir, tsDataDir, TSDB_FILENAME_LEN); - tstrncpy(pCfg->localEp, tsLocalEp, TSDB_EP_LEN); - tstrncpy(pCfg->localFqdn, tsLocalFqdn, TSDB_FQDN_LEN); - tstrncpy(pCfg->firstEp, tsFirst, TSDB_EP_LEN); +int32_t dmnLoadCfg(SConfig *pConfig, const char *inputCfgDir, const char *envFile, const char *apolloUrl) { + char configDir[PATH_MAX] = {0}; + char configFile[PATH_MAX + 100] = {0}; + + taosExpandDir(inputCfgDir, configDir, PATH_MAX); + snprintf(configFile, sizeof(configFile), "%s" TD_DIRSEP "taos.cfg", configDir); + + if (cfgLoad(pConfig, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) { + uError("failed to load from apollo url:%s since %s\n", apolloUrl, terrstr()); + return -1; + } + + if (cfgLoad(pConfig, CFG_STYPE_CFG_FILE, configFile) != 0) { + if (cfgLoad(pConfig, CFG_STYPE_CFG_FILE, configDir) != 0) { + uError("failed to load from config file:%s since %s\n", configFile, terrstr()); + return -1; + } + } + + if (cfgLoad(pConfig, CFG_STYPE_ENV_FILE, envFile) != 0) { + uError("failed to load from env file:%s since %s\n", envFile, terrstr()); + return -1; + } + + if (cfgLoad(pConfig, CFG_STYPE_ENV_VAR, NULL) != 0) { + uError("failed to load from global env variables since %s\n", terrstr()); + return -1; + } + + return 0; } -#if 0 -void taosReadGlobalLogCfg() { - FILE * fp; - char * line, *option, *value; - int olen, vlen; - char fileName[PATH_MAX] = {0}; +SConfig *dmnReadCfg(const char *cfgDir, const char *envFile, const char *apolloUrl) { + SConfig *pConfig = cfgInit(); + if (pConfig == NULL) return NULL; + + if (dmnInitLogCfg(pConfig) != 0) { + uError("failed to init log cfg since %s", terrstr()); + cfgCleanup(pConfig); + return NULL; + } + + if (dmnInitDnodeCfg(pConfig) != 0) { + uError("failed to init dnode cfg since %s", terrstr()); + cfgCleanup(pConfig); + return NULL; + } + + if (dmnLoadCfg(pConfig, cfgDir, envFile, apolloUrl) != 0) { + uError("failed to load cfg since %s", terrstr()); + cfgCleanup(pConfig); + return NULL; + } + + bool enableCore = cfgGetItem(pConfig, "enableCoreFile")->bval; + taosSetCoreDump(enableCore); + + if (taosCheckAndPrintCfg() != 0) { + uError("failed to check config"); + return NULL; + } - taosExpandDir(configDir, configDir, PATH_MAX); - taosReadLogOption("logDir", tsLogDir); - sprintf(fileName, "%s/taos.cfg", configDir); - fp = fopen(fileName, "r"); - if (fp == NULL) { - printf("\nconfig file:%s not found, all variables are set to default\n", fileName); - return; - } - - ssize_t _bytes = 0; - size_t len = 1024; - line = calloc(1, len); - - while (!feof(fp)) { - memset(line, 0, len); - - option = value = NULL; - olen = vlen = 0; - - _bytes = tgetline(&line, &len, fp); - if (_bytes < 0) - { - break; - } - - line[len - 1] = 0; - - paGetToken(line, &option, &olen); - if (olen == 0) continue; - option[olen] = 0; - - paGetToken(option + olen + 1, &value, &vlen); - if (vlen == 0) continue; - value[vlen] = 0; - - taosReadLogOption(option, value); - } - - tfree(line); - fclose(fp); + return pConfig; } - -void taosPrintCfg() { - uInfo(" taos config & system info:"); - uInfo("=================================="); - - for (int i = 0; i < tsGlobalConfigNum; ++i) { - SGlobalCfg *cfg = tsGlobalConfig + i; - if (tscEmbeddedInUtil == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue; - if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue; - - int optionLen = (int)strlen(cfg->option); - int blankLen = TSDB_CFG_PRINT_LEN - optionLen; - blankLen = blankLen < 0 ? 0 : blankLen; - - char blank[TSDB_CFG_PRINT_LEN]; - memset(blank, ' ', TSDB_CFG_PRINT_LEN); - blank[blankLen] = 0; - - switch (cfg->valType) { - case TAOS_CFG_VTYPE_INT8: - uInfo(" %s:%s%d%s", cfg->option, blank, *((int8_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_INT16: - uInfo(" %s:%s%d%s", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_INT32: - uInfo(" %s:%s%d%s", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_UINT16: - uInfo(" %s:%s%d%s", cfg->option, blank, *((uint16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_FLOAT: - uInfo(" %s:%s%f%s", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_DOUBLE: - uInfo(" %s:%s%f%s", cfg->option, blank, *((double *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_STRING: - case TAOS_CFG_VTYPE_IPSTR: - case TAOS_CFG_VTYPE_DIRECTORY: - uInfo(" %s:%s%s%s", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]); - break; - default: - break; - } - } - - taosPrintOsInfo(); - uInfo("=================================="); -} - -#if 0 -static void taosDumpCfg(SGlobalCfg *cfg) { - int optionLen = (int)strlen(cfg->option); - int blankLen = TSDB_CFG_PRINT_LEN - optionLen; - blankLen = blankLen < 0 ? 0 : blankLen; - - char blank[TSDB_CFG_PRINT_LEN]; - memset(blank, ' ', TSDB_CFG_PRINT_LEN); - blank[blankLen] = 0; - - switch (cfg->valType) { - case TAOS_CFG_VTYPE_INT8: - printf(" %s:%s%d%s\n", cfg->option, blank, *((int8_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_INT16: - printf(" %s:%s%d%s\n", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_INT32: - printf(" %s:%s%d%s\n", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_UINT16: - printf(" %s:%s%d%s\n", cfg->option, blank, *((uint16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_FLOAT: - printf(" %s:%s%f%s\n", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TAOS_CFG_VTYPE_STRING: - case TAOS_CFG_VTYPE_IPSTR: - case TAOS_CFG_VTYPE_DIRECTORY: - printf(" %s:%s%s%s\n", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]); - break; - default: - break; - } -} - -void taosDumpGlobalCfg() { +void dmnDumpCfg(SConfig *pCfg) { printf("taos global config:\n"); printf("==================================\n"); - for (int i = 0; i < tsGlobalConfigNum; ++i) { - SGlobalCfg *cfg = tsGlobalConfig + i; - if (tscEmbeddedInUtil == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue; - if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue; - if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW)) continue; - taosDumpCfg(cfg); - } - - printf("\ntaos local config:\n"); - printf("==================================\n"); - - for (int i = 0; i < tsGlobalConfigNum; ++i) { - SGlobalCfg *cfg = tsGlobalConfig + i; - if (tscEmbeddedInUtil == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue; - if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue; - if (cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW) continue; - - taosDumpCfg(cfg); + SConfigItem *pItem = cfgIterate(pCfg, NULL); + while (pItem != NULL) { + switch (pItem->dtype) { + case CFG_DTYPE_BOOL: + printf("cfg:%s, value:%u src:%s\n", pItem->name, pItem->bval, cfgStypeStr(pItem->stype)); + break; + case CFG_DTYPE_INT32: + printf("cfg:%s, value:%d src:%s\n", pItem->name, pItem->i32, cfgStypeStr(pItem->stype)); + break; + case CFG_DTYPE_INT64: + printf("cfg:%s, value:%" PRId64 " src:%s\n", pItem->name, pItem->i64, cfgStypeStr(pItem->stype)); + break; + case CFG_DTYPE_FLOAT: + printf("cfg:%s, value:%f src:%s\n", pItem->name, pItem->fval, cfgStypeStr(pItem->stype)); + break; + case CFG_DTYPE_STRING: + case CFG_DTYPE_IPSTR: + case CFG_DTYPE_DIR: + case CFG_DTYPE_LOCALE: + case CFG_DTYPE_CHARSET: + case CFG_DTYPE_TIMEZONE: + printf("cfg:%s, value:%s src:%s\n", pItem->name, pItem->str, cfgStypeStr(pItem->stype)); + break; + } + pItem = cfgIterate(pCfg, pItem); } } -#endif +SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg) { + SDnodeEnvCfg envCfg = {0}; -#endif - -static int32_t dmnInitLog() { + const char *vstr = cfgGetItem(pCfg, "version")->str; + envCfg.sver = 30000000; + tstrncpy(envCfg.buildinfo, cfgGetItem(pCfg, "buildinfo")->str, sizeof(envCfg.buildinfo)); + tstrncpy(envCfg.gitinfo, cfgGetItem(pCfg, "gitinfo")->str, sizeof(envCfg.gitinfo)); + tstrncpy(envCfg.timezone, cfgGetItem(pCfg, "timezone")->str, sizeof(envCfg.timezone)); + tstrncpy(envCfg.locale, cfgGetItem(pCfg, "locale")->str, sizeof(envCfg.locale)); + tstrncpy(envCfg.charset, cfgGetItem(pCfg, "charset")->str, sizeof(envCfg.charset)); + envCfg.numOfCores = cfgGetItem(pCfg, "numOfCores")->i32; + envCfg.numOfCommitThreads = (uint16_t) cfgGetItem(pCfg, "numOfCommitThreads")->i32; + envCfg.enableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; + return envCfg; } -int32_t dnmInitCfg(SDnodeEnvCfg *pEnvCfg, SDnodeObjCfg *pObjCfg, const char *configFile, const char *envFile, - const char *apolloUrl) { - dmnInitEnvCfg(pEnvCfg); - dmnInitObjCfg(pObjCfg); - return 0; +SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg) { + SDnodeObjCfg objCfg = {0}; + + objCfg.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32; + objCfg.statusInterval = cfgGetItem(pCfg, "statusInterval")->i32; + objCfg.numOfThreadsPerCore = cfgGetItem(pCfg, "numOfThreadsPerCore")->fval; + objCfg.ratioOfQueryCores = cfgGetItem(pCfg, "ratioOfQueryCores")->fval; + objCfg.maxShellConns = cfgGetItem(pCfg, "maxShellConns")->i32; + objCfg.shellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32; + objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; + tstrncpy(objCfg.dataDir, cfgGetItem(pCfg, "dataDir")->str, sizeof(objCfg.dataDir)); + tstrncpy(objCfg.localEp, cfgGetItem(pCfg, "localEp")->str, sizeof(objCfg.localEp)); + tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "localFqdn")->str, sizeof(objCfg.localFqdn, cfgGetItem)); + tstrncpy(objCfg.firstEp, cfgGetItem(pCfg, "firstEp")->str, sizeof(objCfg.firstEp)); + tstrncpy(objCfg.secondEp, cfgGetItem(pCfg, "secondEp")->str, sizeof(objCfg.firstEp)); + + return objCfg; } \ No newline at end of file diff --git a/source/dnode/mgmt/daemon/src/dmnLog.c b/source/dnode/mgmt/daemon/src/dmnLog.c index e69de29bb2..8cce1bb01e 100644 --- a/source/dnode/mgmt/daemon/src/dmnLog.c +++ b/source/dnode/mgmt/daemon/src/dmnLog.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "dmnInt.h" + +int32_t dmnInitLogCfg(SConfig *pCfg) { + if (cfgAddDir(pCfg, "logDir", "/var/log/taos") != 0) return -1; + if (cfgAddInt32(pCfg, "numOfLogLines", 10000000, 1000, 2000000000) != 0) return -1; + if (cfgAddInt32(pCfg, "logKeepDays", 0, -365000, 365000) != 0) return -1; + if (cfgAddBool(pCfg, "asyncLog", 1) != 0) return -1; + if (cfgAddInt32(pCfg, "debugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "mDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "dDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "sDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "wDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "rpcDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "tmrDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "cDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "jniDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "uDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "qDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "vDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "tsdbDebugFlag", 0, 0, 255) != 0) return -1; + if (cfgAddInt32(pCfg, "cqDebugFlag", 0, 0, 255) != 0) return -1; + return 0; +} + +int32_t dmnInitLog(const char *cfgDir, const char *envFile, const char *apolloUrl) { + SConfig *pCfg = cfgInit(); + if (pCfg == NULL) return -1; + + if (dmnInitLogCfg(pCfg) != 0) { + uError("failed to init log cfg since %s\n", terrstr()); + cfgCleanup(pCfg); + return -1; + } + + if (dmnLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) { + uError("failed to load log cfg since %s\n", terrstr()); + cfgCleanup(pCfg); + return -1; + } + + char temp[PATH_MAX] = {0}; + snprintf(temp, PATH_MAX, "%s" TD_DIRSEP "taosdlog", cfgGetItem(pCfg, "logDir")->str); + if (taosInitLog(temp, cfgGetItem(pCfg, "numOfLogLines")->i32, 1) != 0) { + uError("failed to init log file since %s\n", terrstr()); + cfgCleanup(pCfg); + return -1; + } + + cfgCleanup(pCfg); + return 0; +} diff --git a/source/dnode/mgmt/daemon/src/dmnUtil.c b/source/dnode/mgmt/daemon/src/dmnUtil.c new file mode 100644 index 0000000000..aac27c4c33 --- /dev/null +++ b/source/dnode/mgmt/daemon/src/dmnUtil.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "dmnInt.h" + +void dmnGenerateGrant() { +#if 0 + grantParseParameter(); +#endif +} + +void dmnPrintVersion(SConfig *pCfg) { +#ifdef TD_ENTERPRISE + char *releaseName = "enterprise"; +#else + char *releaseName = "community"; +#endif + printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); + printf("gitinfo: %s\n", gitinfo); + printf("gitinfoI: %s\n", gitinfoOfInternal); + printf("builuInfo: %s\n", buildinfo); +} diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 6c7d4be581..5c32da966b 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -56,7 +56,7 @@ typedef struct { } SProfileMgmt; typedef struct { - int8_t enable; + bool enable; SRWLatch lock; char email[TSDB_FQDN_LEN]; } STelemMgmt; diff --git a/source/libs/config/CMakeLists.txt b/source/libs/config/CMakeLists.txt index 0bd467198d..596cc0b433 100644 --- a/source/libs/config/CMakeLists.txt +++ b/source/libs/config/CMakeLists.txt @@ -6,7 +6,7 @@ target_include_directories( PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) -target_link_libraries(config os util) +target_link_libraries(config os util common) if(${BUILD_TEST}) ADD_SUBDIRECTORY(test) diff --git a/source/libs/config/inc/cfgInt.h b/source/libs/config/inc/cfgInt.h index 0b62018222..6497393792 100644 --- a/source/libs/config/inc/cfgInt.h +++ b/source/libs/config/inc/cfgInt.h @@ -22,6 +22,7 @@ #include "thash.h" #include "tutil.h" #include "ulog.h" +#include "tglobal.h" #ifdef __cplusplus extern "C" { diff --git a/source/libs/config/src/config.c b/source/libs/config/src/config.c index a40783eaef..dbc4767aee 100644 --- a/source/libs/config/src/config.c +++ b/source/libs/config/src/config.c @@ -15,6 +15,10 @@ #define _DEFAULT_SOURCE #include "cfgInt.h" +#include "tmsg.h" +#include "tep.h" +#include "tlocale.h" +#include "ttimezone.h" SConfig *cfgInit() { SConfig *pConfig = calloc(1, sizeof(SConfig)); @@ -23,7 +27,7 @@ SConfig *cfgInit() { return NULL; } - pConfig->hash = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK); + pConfig->hash = taosHashInit(16, MurmurHash3_32, false, HASH_NO_LOCK); if (pConfig->hash == NULL) { free(pConfig); terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -64,6 +68,85 @@ SConfigItem *cfgIterate(SConfig *pConfig, SConfigItem *pIter) { return taosHashI void cfgCancelIterate(SConfig *pConfig, SConfigItem *pIter) { return taosHashCancelIterate(pConfig->hash, pIter); } +static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) { + tfree(pItem->str); + pItem->str = strdup(timezone); + if (pItem->str == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + +static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) { + tfree(pItem->str); + pItem->str = strdup(charset); + if (pItem->str == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + +static int32_t cfgCheckAndSetLocale(SConfigItem *pItem, const char *locale) { + tfree(pItem->str); + pItem->str = strdup(locale); + if (pItem->str == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + +static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { + char fullDir[PATH_MAX] = {0}; + if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + uError("failed to expand dir:%s since %s", inputDir, terrstr()); + return -1; + } + + if (taosRealPath(fullDir, PATH_MAX) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + uError("failed to get realpath of dir:%s since %s", inputDir, terrstr()); + return -1; + } + + if (taosMkDir(fullDir) != 0) { + uError("failed to create dir:%s realpath:%s since %s", inputDir, fullDir, terrstr()); + return -1; + } + + tfree(pItem->str); + pItem->str = strdup(fullDir); + if (pItem->str == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + +static int32_t cfgCheckAndSetIpStr(SConfigItem *pItem, const char *ip) { + uint32_t value = taosInetAddr(ip); + if (value == INADDR_NONE) { + uError("ip:%s is not a valid ip address", ip); + return -1; + } + + tfree(pItem->str); + pItem->str = strdup(ip); + if (pItem->str == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + static int32_t cfgSetBool(SConfigItem *pItem, const char *value, ECfgSrcType stype) { bool tmp = false; if (strcasecmp(value, "true") == 0) { @@ -73,83 +156,53 @@ static int32_t cfgSetBool(SConfigItem *pItem, const char *value, ECfgSrcType sty tmp = true; } - pItem->boolVal = tmp; - pItem->stype = stype; - return 0; -} - -static int32_t cfgSetInt8(SConfigItem *pItem, const char *value, ECfgSrcType stype) { - int8_t ival = (int8_t)atoi(value); - if (ival < pItem->minIntVal || ival > pItem->maxIntVal) { - uError("cfg:%s, type:%s src:%s value:%d out of range[%" PRId64 ", %" PRId64 "], use last src:%s value:%d", - pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->minIntVal, pItem->maxIntVal, - cfgStypeStr(pItem->stype), pItem->int8Val); - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; - } - - pItem->int8Val = ival; - pItem->stype = stype; - return 0; -} - -static int32_t cfgSetUInt16(SConfigItem *pItem, const char *value, ECfgSrcType stype) { - uint16_t ival = (uint16_t)atoi(value); - if (ival < pItem->minIntVal || ival > pItem->maxIntVal) { - uError("cfg:%s, type:%s src:%s value:%d out of range[%" PRId64 ", %" PRId64 "], use last src:%s value:%d", - pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->minIntVal, pItem->maxIntVal, - cfgStypeStr(pItem->stype), pItem->uint16Val); - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; - } - - pItem->uint16Val = ival; + pItem->bval = tmp; pItem->stype = stype; return 0; } static int32_t cfgSetInt32(SConfigItem *pItem, const char *value, ECfgSrcType stype) { int32_t ival = (int32_t)atoi(value); - if (ival < pItem->minIntVal || ival > pItem->maxIntVal) { + if (ival < pItem->imin || ival > pItem->imax) { uError("cfg:%s, type:%s src:%s value:%d out of range[%" PRId64 ", %" PRId64 "], use last src:%s value:%d", - pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->minIntVal, pItem->maxIntVal, - cfgStypeStr(pItem->stype), pItem->int32Val); + pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->imin, pItem->imax, + cfgStypeStr(pItem->stype), pItem->i32); terrno = TSDB_CODE_OUT_OF_RANGE; return -1; } - pItem->int32Val = ival; + pItem->i32 = ival; pItem->stype = stype; return 0; } static int32_t cfgSetInt64(SConfigItem *pItem, const char *value, ECfgSrcType stype) { int64_t ival = (int64_t)atoi(value); - if (ival < pItem->minIntVal || ival > pItem->maxIntVal) { + if (ival < pItem->imin || ival > pItem->imax) { uError("cfg:%s, type:%s src:%s value:%" PRId64 " out of range[%" PRId64 ", %" PRId64 "], use last src:%s value:%" PRId64, - pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->minIntVal, pItem->maxIntVal, - cfgStypeStr(pItem->stype), pItem->int64Val); + pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), ival, pItem->imin, pItem->imax, + cfgStypeStr(pItem->stype), pItem->i64); terrno = TSDB_CODE_OUT_OF_RANGE; return -1; } - pItem->int64Val = ival; + pItem->i64 = ival; pItem->stype = stype; return 0; } static int32_t cfgSetFloat(SConfigItem *pItem, const char *value, ECfgSrcType stype) { float fval = (float)atof(value); - if (fval < pItem->minFloatVal || fval > pItem->maxFloatVal) { + if (fval < pItem->fmin || fval > pItem->fmax) { uError("cfg:%s, type:%s src:%s value:%f out of range[%f, %f], use last src:%s value:%f", pItem->name, - cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), fval, pItem->minFloatVal, pItem->maxFloatVal, - cfgStypeStr(pItem->stype), pItem->floatVal); + cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), fval, pItem->fmin, pItem->fmax, cfgStypeStr(pItem->stype), + pItem->fval); terrno = TSDB_CODE_OUT_OF_RANGE; return -1; } - pItem->floatVal = fval; + pItem->fval = fval; pItem->stype = stype; return 0; } @@ -159,42 +212,82 @@ static int32_t cfgSetString(SConfigItem *pItem, const char *value, ECfgSrcType s if (tmp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s, use last src:%s value:%s", pItem->name, - cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->strVal); + cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->str); return -1; } - free(pItem->strVal); - pItem->strVal = tmp; + free(pItem->str); + pItem->str = tmp; pItem->stype = stype; return 0; } static int32_t cfgSetIpStr(SConfigItem *pItem, const char *value, ECfgSrcType stype) { char *tmp = strdup(value); - if (tmp == NULL) { + if (tmp == NULL || cfgCheckAndSetIpStr(pItem, value) != 0) { + free(tmp); terrno = TSDB_CODE_OUT_OF_MEMORY; uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s, use last src:%s value:%s", pItem->name, - cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->strVal); + cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->str); return -1; } - free(pItem->strVal); - pItem->strVal = tmp; pItem->stype = stype; return 0; } static int32_t cfgSetDir(SConfigItem *pItem, const char *value, ECfgSrcType stype) { char *tmp = strdup(value); - if (tmp == NULL) { + if (tmp == NULL || cfgCheckAndSetDir(pItem, value) != 0) { + free(tmp); terrno = TSDB_CODE_OUT_OF_MEMORY; uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s, use last src:%s value:%s", pItem->name, - cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->strVal); + cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->str); + return -1; + } + + pItem->stype = stype; + return 0; +} + +static int32_t cfgSetLocale(SConfigItem *pItem, const char *value, ECfgSrcType stype) { + char *tmp = strdup(value); + if (tmp == NULL || cfgCheckAndSetLocale(pItem, value) != 0) { + free(tmp); + terrno = TSDB_CODE_OUT_OF_MEMORY; + uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s, use last src:%s value:%s", pItem->name, + cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->str); + return -1; + } + + pItem->stype = stype; + return 0; +} + +static int32_t cfgSetCharset(SConfigItem *pItem, const char *value, ECfgSrcType stype) { + char *tmp = strdup(value); + if (tmp == NULL || cfgCheckAndSetCharset(pItem, value) != 0) { + free(tmp); + terrno = TSDB_CODE_OUT_OF_MEMORY; + uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s, use last src:%s value:%s", pItem->name, + cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->str); + return -1; + } + + pItem->stype = stype; + return 0; +} + +static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType stype) { + char *tmp = strdup(value); + if (tmp == NULL || cfgCheckAndSetTimezone(pItem, value) != 0) { + free(tmp); + terrno = TSDB_CODE_OUT_OF_MEMORY; + uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s, use last src:%s value:%s", pItem->name, + cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, terrstr(), cfgStypeStr(pItem->stype), pItem->str); return -1; } - free(pItem->strVal); - pItem->strVal = tmp; pItem->stype = stype; return 0; } @@ -208,10 +301,6 @@ int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSr switch (pItem->dtype) { case CFG_DTYPE_BOOL: return cfgSetBool(pItem, value, stype); - case CFG_DTYPE_INT8: - return cfgSetInt8(pItem, value, stype); - case CFG_DTYPE_UINT16: - return cfgSetUInt16(pItem, value, stype); case CFG_DTYPE_INT32: return cfgSetInt32(pItem, value, stype); case CFG_DTYPE_INT64: @@ -224,6 +313,12 @@ int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSr return cfgSetIpStr(pItem, value, stype); case CFG_DTYPE_DIR: return cfgSetDir(pItem, value, stype); + case CFG_DTYPE_TIMEZONE: + return cfgSetTimezone(pItem, value, stype); + case CFG_DTYPE_CHARSET: + return cfgSetCharset(pItem, value, stype); + case CFG_DTYPE_LOCALE: + return cfgSetLocale(pItem, value, stype); case CFG_DTYPE_NONE: default: break; @@ -246,9 +341,8 @@ SConfigItem *cfgGetItem(SConfig *pConfig, const char *name) { return pItem; } -static int32_t cfgAddItem(SConfig *pConfig, SConfigItem *pItem, const char *name, ECfgUnitType utype) { +static int32_t cfgAddItem(SConfig *pConfig, SConfigItem *pItem, const char *name) { pItem->stype = CFG_STYPE_DEFAULT; - pItem->utype = utype; pItem->name = strdup(name); if (pItem->name == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -261,7 +355,7 @@ static int32_t cfgAddItem(SConfig *pConfig, SConfigItem *pItem, const char *name if (taosHashPut(pConfig->hash, lowcaseName, strlen(lowcaseName) + 1, pItem, sizeof(SConfigItem)) != 0) { if (pItem->dtype == CFG_DTYPE_STRING) { - free(pItem->strVal); + free(pItem->str); } free(pItem->name); terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -271,202 +365,94 @@ static int32_t cfgAddItem(SConfig *pConfig, SConfigItem *pItem, const char *name return 0; } -int32_t cfgAddBool(SConfig *pConfig, const char *name, bool defaultVal, ECfgUnitType utype) { - SConfigItem item = {.dtype = CFG_DTYPE_BOOL, .boolVal = defaultVal}; - return cfgAddItem(pConfig, &item, name, utype); +int32_t cfgAddBool(SConfig *pConfig, const char *name, bool defaultVal) { + SConfigItem item = {.dtype = CFG_DTYPE_BOOL, .bval = defaultVal}; + return cfgAddItem(pConfig, &item, name); } -int32_t cfgAddInt8(SConfig *pConfig, const char *name, int8_t defaultVal, int64_t minval, int64_t maxval, - ECfgUnitType utype) { +int32_t cfgAddInt32(SConfig *pConfig, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval) { if (defaultVal < minval || defaultVal > maxval) { terrno = TSDB_CODE_OUT_OF_RANGE; return -1; } - SConfigItem item = {.dtype = CFG_DTYPE_INT8, .int8Val = defaultVal, .minIntVal = minval, .maxIntVal = maxval}; - return cfgAddItem(pConfig, &item, name, utype); + SConfigItem item = {.dtype = CFG_DTYPE_INT32, .i32 = defaultVal, .imin = minval, .imax = maxval}; + return cfgAddItem(pConfig, &item, name); } -int32_t cfgAddUInt16(SConfig *pConfig, const char *name, uint16_t defaultVal, int64_t minval, int64_t maxval, - ECfgUnitType utype) { +int32_t cfgAddInt64(SConfig *pConfig, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval) { if (defaultVal < minval || defaultVal > maxval) { terrno = TSDB_CODE_OUT_OF_RANGE; return -1; } - SConfigItem item = {.dtype = CFG_DTYPE_UINT16, .uint16Val = defaultVal, .minIntVal = minval, .maxIntVal = maxval}; - return cfgAddItem(pConfig, &item, name, utype); + SConfigItem item = {.dtype = CFG_DTYPE_INT64, .i64 = defaultVal, .imin = minval, .imax = maxval}; + return cfgAddItem(pConfig, &item, name); } -int32_t cfgAddInt32(SConfig *pConfig, const char *name, int32_t defaultVal, int64_t minval, int64_t maxval, - ECfgUnitType utype) { +int32_t cfgAddFloat(SConfig *pConfig, const char *name, float defaultVal, double minval, double maxval) { if (defaultVal < minval || defaultVal > maxval) { terrno = TSDB_CODE_OUT_OF_RANGE; return -1; } - SConfigItem item = {.dtype = CFG_DTYPE_INT32, .int32Val = defaultVal, .minIntVal = minval, .maxIntVal = maxval}; - return cfgAddItem(pConfig, &item, name, utype); + SConfigItem item = {.dtype = CFG_DTYPE_FLOAT, .fval = defaultVal, .fmin = minval, .fmax = maxval}; + return cfgAddItem(pConfig, &item, name); } -int32_t cfgAddInt64(SConfig *pConfig, const char *name, int64_t defaultVal, int64_t minval, int64_t maxval, - ECfgUnitType utype) { - if (defaultVal < minval || defaultVal > maxval) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; - } - - SConfigItem item = {.dtype = CFG_DTYPE_INT64, .int64Val = defaultVal, .minIntVal = minval, .maxIntVal = maxval}; - return cfgAddItem(pConfig, &item, name, utype); -} - -int32_t cfgAddFloat(SConfig *pConfig, const char *name, float defaultVal, double minval, double maxval, - ECfgUnitType utype) { - if (defaultVal < minval || defaultVal > maxval) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; - } - - SConfigItem item = {.dtype = CFG_DTYPE_FLOAT, .floatVal = defaultVal, .minFloatVal = minval, .maxFloatVal = maxval}; - return cfgAddItem(pConfig, &item, name, utype); -} - -int32_t cfgAddString(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype) { - if (defaultVal == NULL) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; - } - +int32_t cfgAddString(SConfig *pConfig, const char *name, const char *defaultVal) { SConfigItem item = {.dtype = CFG_DTYPE_STRING}; - item.strVal = strdup(defaultVal); - if (item.strVal == NULL) { + item.str = strdup(defaultVal); + if (item.str == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - return cfgAddItem(pConfig, &item, name, utype); + return cfgAddItem(pConfig, &item, name); } -static int32_t cfgCheckIpStr(const char *ip) { - uint32_t value = taosInetAddr(ip); - if (value == INADDR_NONE) { - uError("ip:%s is not a valid ip address", ip); - return -1; - } - - return 0; -} - -int32_t cfgAddIpStr(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype) { - if (cfgCheckIpStr(defaultVal) != 0) { - terrno = TSDB_CODE_OUT_OF_RANGE; - return -1; - } - +int32_t cfgAddIpStr(SConfig *pConfig, const char *name, const char *defaultVal) { SConfigItem item = {.dtype = CFG_DTYPE_IPSTR}; - item.strVal = strdup(defaultVal); - if (item.strVal == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + if (cfgCheckAndSetIpStr(&item, defaultVal) != 0) { return -1; } - return cfgAddItem(pConfig, &item, name, utype); + + return cfgAddItem(pConfig, &item, name); } -static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { - char fullDir[PATH_MAX] = {0}; - if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - uError("failed to expand dir:%s since %s", inputDir, terrstr()); - return -1; - } - - if (taosRealPath(fullDir, PATH_MAX) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - uError("failed to get realpath of dir:%s since %s", inputDir, terrstr()); - return -1; - } - - if (taosMkDir(fullDir) != 0) { - uError("failed to create dir:%s realpath:%s since %s", inputDir, fullDir, terrstr()); - return -1; - } - - tfree(pItem->strVal); - pItem->strVal = strdup(fullDir); - if (pItem->strVal == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -int32_t cfgAddDir(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype) { +int32_t cfgAddDir(SConfig *pConfig, const char *name, const char *defaultVal) { SConfigItem item = {.dtype = CFG_DTYPE_DIR}; if (cfgCheckAndSetDir(&item, defaultVal) != 0) { return -1; } - return cfgAddItem(pConfig, &item, name, utype); + return cfgAddItem(pConfig, &item, name); } -static int32_t cfgCheckAndSetLocale(SConfigItem *pItem, const char *locale) { - tfree(pItem->strVal); - pItem->strVal = strdup(locale); - if (pItem->strVal == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -int32_t cfgAddLocale(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype) { +int32_t cfgAddLocale(SConfig *pConfig, const char *name, const char *defaultVal) { SConfigItem item = {.dtype = CFG_DTYPE_LOCALE}; if (cfgCheckAndSetLocale(&item, defaultVal) != 0) { return -1; } - return cfgAddItem(pConfig, &item, name, utype); + return cfgAddItem(pConfig, &item, name); } -static int32_t cfgCheckAndSetCharset(SConfigItem *pItem, const char *charset) { - tfree(pItem->strVal); - pItem->strVal = strdup(charset); - if (pItem->strVal == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -int32_t cfgAddCharset(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype) { +int32_t cfgAddCharset(SConfig *pConfig, const char *name, const char *defaultVal) { SConfigItem item = {.dtype = CFG_DTYPE_CHARSET}; if (cfgCheckAndSetCharset(&item, defaultVal) != 0) { return -1; } - return cfgAddItem(pConfig, &item, name, utype); + return cfgAddItem(pConfig, &item, name); } -static int32_t cfgCheckAndSetTimezone(SConfigItem *pItem, const char *timezone) { - tfree(pItem->strVal); - pItem->strVal = strdup(timezone); - if (pItem->strVal == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -int32_t cfgAddTimezone(SConfig *pConfig, const char *name, const char *defaultVal, ECfgUnitType utype) { +int32_t cfgAddTimezone(SConfig *pConfig, const char *name, const char *defaultVal) { SConfigItem item = {.dtype = CFG_DTYPE_TIMEZONE}; if (cfgCheckAndSetTimezone(&item, defaultVal) != 0) { return -1; } - return cfgAddItem(pConfig, &item, name, utype); + return cfgAddItem(pConfig, &item, name); } const char *cfgStypeStr(ECfgSrcType type) { @@ -496,10 +482,6 @@ const char *cfgDtypeStr(ECfgDataType type) { return "none"; case CFG_DTYPE_BOOL: return "bool"; - case CFG_DTYPE_INT8: - return "int8"; - case CFG_DTYPE_UINT16: - return "uint16"; case CFG_DTYPE_INT32: return "int32"; case CFG_DTYPE_INT64: @@ -523,23 +505,120 @@ const char *cfgDtypeStr(ECfgDataType type) { } } -const char *cfgUtypeStr(ECfgUnitType type) { - switch (type) { - case CFG_UTYPE_NONE: - return ""; - case CFG_UTYPE_PERCENT: - return "(%)"; - case CFG_UTYPE_GB: - return "(GB)"; - case CFG_UTYPE_MB: - return "(Mb)"; - case CFG_UTYPE_BYTE: - return "(byte)"; - case CFG_UTYPE_SECOND: - return "(s)"; - case CFG_UTYPE_MS: - return "(ms)"; - default: - return "invalid"; +void cfgPrintCfg(SConfig *pCfg) { + uInfo("taos global config"); + uInfo("=================================="); + + SConfigItem *pItem = cfgIterate(pCfg, NULL); + while (pItem != NULL) { + switch (pItem->dtype) { + case CFG_DTYPE_BOOL: + uInfo("cfg:%s, value:%u src:%s", pItem->name, pItem->bval, cfgStypeStr(pItem->stype)); + break; + case CFG_DTYPE_INT32: + uInfo("cfg:%s, value:%d src:%s", pItem->name, pItem->i32, cfgStypeStr(pItem->stype)); + break; + case CFG_DTYPE_INT64: + uInfo("cfg:%s, value:%" PRId64 " src:%s", pItem->name, pItem->i64, cfgStypeStr(pItem->stype)); + break; + case CFG_DTYPE_FLOAT: + uInfo("cfg:%s, value:%f src:%s", pItem->name, pItem->fval, cfgStypeStr(pItem->stype)); + break; + case CFG_DTYPE_STRING: + case CFG_DTYPE_IPSTR: + case CFG_DTYPE_DIR: + case CFG_DTYPE_LOCALE: + case CFG_DTYPE_CHARSET: + case CFG_DTYPE_TIMEZONE: + uInfo("cfg:%s, value:%s src:%s", pItem->name, pItem->str, cfgStypeStr(pItem->stype)); + break; + } + pItem = cfgIterate(pCfg, pItem); } -} \ No newline at end of file +} + +int32_t cfgCheck(SConfig *pConfig) { + SConfigItem *pItem = cfgGetItem(pConfig, "debugFlag"); + if (pItem != NULL) { + taosSetDebugFlag(pItem->i32); + } + + pItem = cfgGetItem(pConfig, "localFqdn"); + if (pItem != NULL) { + tstrncpy(tsLocalFqdn, pItem->str, TSDB_FQDN_LEN); + } + + pItem = cfgGetItem(pConfig, "serverPort"); + if (pItem != NULL) { + tsServerPort = (uint16_t)pItem->i32; + } + + pItem = cfgGetItem(pConfig, "firstEp"); + if (pItem != NULL) { + tstrncpy(tsFirst, pItem->str, TSDB_EP_LEN); + } + + snprintf(tsLocalEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort); + uInfo("localEp is: %s", tsLocalEp); + + SEp ep = {0}; + if (tsFirst[0] == 0) { + strcpy(tsFirst, tsLocalEp); + } else { + taosGetFqdnPortFromEp(tsFirst, &ep); + snprintf(tsFirst, TSDB_EP_LEN, "%s:%u", ep.fqdn, ep.port); + } + + pItem = cfgGetItem(pConfig, "secondEp"); + if (pItem != NULL) { + tstrncpy(tsSecond, pItem->str, TSDB_EP_LEN); + } + + if (tsSecond[0] == 0) { + strcpy(tsSecond, tsLocalEp); + } else { + taosGetFqdnPortFromEp(tsSecond, &ep); + snprintf(tsSecond, TSDB_EP_LEN, "%s:%u", ep.fqdn, ep.port); + } + + pItem = cfgGetItem(pConfig, "dataDir"); + if (pItem != NULL) { + tstrncpy(tsDataDir, pItem->str, PATH_MAX); + } + + if (tsDiskCfgNum <= 0) { + taosAddDataDir(0, tsDataDir, 0, 1); + tsDiskCfgNum = 1; + uTrace("dataDir:%s, level:0 primary:1 is configured by default", tsDataDir); + } + + if (taosDirExist(tsTempDir) != 0) { + return -1; + } + + taosGetSystemInfo(); + + tsSetLocale(); + + // SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); + // if (cfg_timezone && cfg_timezone->cfgStatus == TAOS_CFG_CSTATUS_FILE) { + tsSetTimeZone(); + // } + + pItem = cfgGetItem(pConfig, "numOfCores"); + if (pItem != NULL) { + tsNumOfCores = pItem->i32; + } + + if (tsNumOfCores <= 0) { + tsNumOfCores = 1; + } + + if (tsQueryBufferSize >= 0) { + tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; + } + + cfgPrintCfg(pConfig); + + return 0; +} diff --git a/source/libs/config/test/cfgTest.cpp b/source/libs/config/test/cfgTest.cpp index 62ed5764ac..7c70e1a8f8 100644 --- a/source/libs/config/test/cfgTest.cpp +++ b/source/libs/config/test/cfgTest.cpp @@ -20,15 +20,14 @@ class CfgTest : public ::testing::Test { public: void SetUp() override {} void TearDown() override {} - - void InitializeConfig(SConfig *pConfig); + void InitCfg(SConfig *pConfig); static const char *pConfig; }; const char *CfgTest::pConfig; -TEST_F(CfgTest, 02_Str) { +TEST_F(CfgTest, 01_Str) { EXPECT_STREQ(cfgStypeStr(CFG_STYPE_DEFAULT), "default"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_CFG_FILE), "cfg_file"); EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_FILE), "env_file"); @@ -40,72 +39,56 @@ TEST_F(CfgTest, 02_Str) { EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_NONE), "none"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_BOOL), "bool"); - EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_INT8), "int8"); - EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_UINT16), "uint16"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_INT32), "int32"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_INT64), "int64"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_FLOAT), "float"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_STRING), "string"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_IPSTR), "ipstr"); EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_DIR), "dir"); + EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_DIR), "dir"); + EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_DIR), "dir"); + EXPECT_STREQ(cfgDtypeStr(CFG_DTYPE_DIR), "dir"); EXPECT_STREQ(cfgDtypeStr(ECfgDataType(1024)), "invalid"); - - EXPECT_STREQ(cfgUtypeStr(CFG_UTYPE_NONE), ""); - EXPECT_STREQ(cfgUtypeStr(CFG_UTYPE_GB), "(GB)"); - EXPECT_STREQ(cfgUtypeStr(CFG_UTYPE_MB), "(Mb)"); - EXPECT_STREQ(cfgUtypeStr(CFG_UTYPE_BYTE), "(byte)"); - EXPECT_STREQ(cfgUtypeStr(CFG_UTYPE_SECOND), "(s)"); - EXPECT_STREQ(cfgUtypeStr(CFG_UTYPE_MS), "(ms)"); - EXPECT_STREQ(cfgUtypeStr(CFG_UTYPE_PERCENT), "(%)"); - EXPECT_STREQ(cfgUtypeStr(ECfgUnitType(1024)), "invalid"); } TEST_F(CfgTest, 02_Basic) { SConfig *pConfig = cfgInit(); ASSERT_NE(pConfig, nullptr); - EXPECT_EQ(cfgAddBool(pConfig, "test_bool", 0, CFG_UTYPE_NONE), 0); - EXPECT_EQ(cfgAddInt8(pConfig, "test_int8", 1, 0, 16, CFG_UTYPE_GB), 0); - EXPECT_EQ(cfgAddUInt16(pConfig, "test_uint16", 2, 0, 16, CFG_UTYPE_MB), 0); - EXPECT_EQ(cfgAddInt32(pConfig, "test_int32", 3, 0, 16, CFG_UTYPE_BYTE), 0); - EXPECT_EQ(cfgAddInt64(pConfig, "test_int64", 4, 0, 16, CFG_UTYPE_SECOND), 0); - EXPECT_EQ(cfgAddFloat(pConfig, "test_float", 5, 0, 16, CFG_UTYPE_MS), 0); - EXPECT_EQ(cfgAddString(pConfig, "test_string", "6", CFG_UTYPE_NONE), 0); - EXPECT_EQ(cfgAddIpStr(pConfig, "test_ipstr", "192.168.0.1", CFG_UTYPE_NONE), 0); - EXPECT_EQ(cfgAddDir(pConfig, "test_dir", "/tmp", CFG_UTYPE_NONE), 0); + EXPECT_EQ(cfgAddBool(pConfig, "test_bool", 0), 0); + EXPECT_EQ(cfgAddInt32(pConfig, "test_int32", 1, 0, 16), 0); + EXPECT_EQ(cfgAddInt64(pConfig, "test_int64", 2, 0, 16), 0); + EXPECT_EQ(cfgAddFloat(pConfig, "test_float", 3, 0, 16), 0); + EXPECT_EQ(cfgAddString(pConfig, "test_string", "4"), 0); + EXPECT_EQ(cfgAddIpStr(pConfig, "test_ipstr", "192.168.0.1"), 0); + EXPECT_EQ(cfgAddDir(pConfig, "test_dir", "/tmp"), 0); - EXPECT_EQ(cfgGetSize(pConfig), 9); + EXPECT_EQ(cfgGetSize(pConfig), 7); int32_t size = 0; SConfigItem *pItem = cfgIterate(pConfig, NULL); while (pItem != NULL) { switch (pItem->dtype) { case CFG_DTYPE_BOOL: - printf("index:%d, cfg:%s value:%d\n", size, pItem->name, pItem->boolVal); - break; - case CFG_DTYPE_INT8: - printf("index:%d, cfg:%s value:%d\n", size, pItem->name, pItem->int8Val); - break; - case CFG_DTYPE_UINT16: - printf("index:%d, cfg:%s value:%d\n", size, pItem->name, pItem->uint16Val); + printf("index:%d, cfg:%s value:%d\n", size, pItem->name, pItem->bval); break; case CFG_DTYPE_INT32: - printf("index:%d, cfg:%s value:%d\n", size, pItem->name, pItem->int32Val); + printf("index:%d, cfg:%s value:%d\n", size, pItem->name, pItem->i32); break; case CFG_DTYPE_INT64: - printf("index:%d, cfg:%s value:%" PRId64 "\n", size, pItem->name, pItem->int64Val); + printf("index:%d, cfg:%s value:%" PRId64 "\n", size, pItem->name, pItem->i64); break; case CFG_DTYPE_FLOAT: - printf("index:%d, cfg:%s value:%f\n", size, pItem->name, pItem->floatVal); + printf("index:%d, cfg:%s value:%f\n", size, pItem->name, pItem->fval); break; case CFG_DTYPE_STRING: - printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->strVal); + printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->str); break; case CFG_DTYPE_IPSTR: - printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->strVal); + printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->str); break; case CFG_DTYPE_DIR: - printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->strVal); + printf("index:%d, cfg:%s value:%s\n", size, pItem->name, pItem->str); break; default: printf("index:%d, cfg:%s invalid cfg dtype:%d\n", size, pItem->name, pItem->dtype); @@ -116,70 +99,49 @@ TEST_F(CfgTest, 02_Basic) { } cfgCancelIterate(pConfig, pItem); - EXPECT_EQ(cfgGetSize(pConfig), 9); + EXPECT_EQ(cfgGetSize(pConfig), 7); pItem = cfgGetItem(pConfig, "test_bool"); EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_NONE); EXPECT_EQ(pItem->dtype, CFG_DTYPE_BOOL); EXPECT_STREQ(pItem->name, "test_bool"); - EXPECT_EQ(pItem->boolVal, 0); - - pItem = cfgGetItem(pConfig, "test_int8"); - EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_GB); - EXPECT_EQ(pItem->dtype, CFG_DTYPE_INT8); - EXPECT_STREQ(pItem->name, "test_int8"); - EXPECT_EQ(pItem->int8Val, 1); - - pItem = cfgGetItem(pConfig, "test_uint16"); - EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_MB); - EXPECT_EQ(pItem->dtype, CFG_DTYPE_UINT16); - EXPECT_STREQ(pItem->name, "test_uint16"); - EXPECT_EQ(pItem->uint16Val, 2); + EXPECT_EQ(pItem->bval, 0); pItem = cfgGetItem(pConfig, "test_int32"); EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_BYTE); EXPECT_EQ(pItem->dtype, CFG_DTYPE_INT32); EXPECT_STREQ(pItem->name, "test_int32"); - EXPECT_EQ(pItem->int32Val, 3); + EXPECT_EQ(pItem->i32, 1); pItem = cfgGetItem(pConfig, "test_int64"); EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_SECOND); EXPECT_EQ(pItem->dtype, CFG_DTYPE_INT64); EXPECT_STREQ(pItem->name, "test_int64"); - EXPECT_EQ(pItem->int64Val, 4); + EXPECT_EQ(pItem->i64, 2); pItem = cfgGetItem(pConfig, "test_float"); EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_MS); EXPECT_EQ(pItem->dtype, CFG_DTYPE_FLOAT); EXPECT_STREQ(pItem->name, "test_float"); - EXPECT_EQ(pItem->floatVal, 5); + EXPECT_EQ(pItem->fval, 3); pItem = cfgGetItem(pConfig, "test_string"); EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_NONE); EXPECT_EQ(pItem->dtype, CFG_DTYPE_STRING); EXPECT_STREQ(pItem->name, "test_string"); - EXPECT_STREQ(pItem->strVal, "6"); + EXPECT_STREQ(pItem->str, "4"); pItem = cfgGetItem(pConfig, "test_ipstr"); EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_NONE); EXPECT_EQ(pItem->dtype, CFG_DTYPE_IPSTR); EXPECT_STREQ(pItem->name, "test_ipstr"); - EXPECT_STREQ(pItem->strVal, "192.168.0.1"); + EXPECT_STREQ(pItem->str, "192.168.0.1"); pItem = cfgGetItem(pConfig, "test_dir"); EXPECT_EQ(pItem->stype, CFG_STYPE_DEFAULT); - EXPECT_EQ(pItem->utype, CFG_UTYPE_NONE); EXPECT_EQ(pItem->dtype, CFG_DTYPE_DIR); EXPECT_STREQ(pItem->name, "test_dir"); - EXPECT_STREQ(pItem->strVal, "/tmp"); + EXPECT_STREQ(pItem->str, "/tmp"); cfgCleanup(pConfig); } diff --git a/source/common/src/ttimezone.c b/source/os/src/osTimeZone.c similarity index 95% rename from source/common/src/ttimezone.c rename to source/os/src/osTimeZone.c index 0ee5702242..da40e14389 100644 --- a/source/common/src/ttimezone.c +++ b/source/os/src/osTimeZone.c @@ -15,12 +15,13 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "ulog.h" -#include "tglobal.h" -#include "tutil.h" +// #include "ulog.h" +// #include "tglobal.h" +// #include "tutil.h" // TODO refactor to set the tz value through parameter void tsSetTimeZone() { +#if 0 SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); if (cfg_timezone != NULL) { uInfo("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]); @@ -63,4 +64,6 @@ void tsSetTimeZone() { tsDaylight = daylight; uInfo("timezone format changed to %s", tsTimezone); + +#endif } diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 2579082022..233b000c61 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -773,3 +773,12 @@ void taosPrintOsInfo() { uInfo(" os version: %s", info.version); uInfo(" os machine: %s", info.machine); } + +void taosSetDebugFlag(int32_t flag) { + if (!(debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP)) return; + + debugFlag = flag; + mDebugFlag = flag; + dDebugFlag = flag; + cDebugFlag = flag; +} \ No newline at end of file