diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 1358bba2e2..b54058d489 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -99,6 +99,8 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU void taosCleanupCfg(); void taosCfgDynamicOptions(const char *option, const char *value); +struct SConfig *taosGetCfg(); + #ifdef __cplusplus } #endif diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index c64397dd51..1c5d92eeb6 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -32,8 +32,6 @@ typedef struct { uint16_t numOfCommitThreads; bool enableTelem; bool printAuth; - int32_t rpcTimer; - int32_t rpcMaxTime; } SDnodeEnvCfg; /** diff --git a/include/util/tconfig.h b/include/util/tconfig.h index fe7002c8c0..2eb98a3ba8 100644 --- a/include/util/tconfig.h +++ b/include/util/tconfig.h @@ -95,7 +95,7 @@ int32_t cfgAddTimezone(SConfig *pCfg, const char *name, const char *defaultVal); const char *cfgStypeStr(ECfgSrcType type); const char *cfgDtypeStr(ECfgDataType type); -void cfgDumpCfg(SConfig *pCfg, bool tsc); +void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump); #ifdef __cplusplus } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 5200474cbd..6a63c735e5 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -170,6 +170,10 @@ static void taosPrintDataDirCfg() { } } +struct SConfig *taosGetCfg() { + return tsCfg; +} + static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) { char cfgDir[PATH_MAX] = {0}; char cfgFile[PATH_MAX + 100] = {0}; @@ -332,6 +336,11 @@ static void taosSetClientCfg(SConfig *pCfg) { tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort); + SConfigItem *pItem = cfgGetItem(pCfg, "timezone"); + osSetTimezone(pItem->str); + uDebug("timezone format changed from %s to %s", pItem->str, osTimezone()); + cfgSetItem(pCfg, "timezone", osTimezone(), pItem->stype); + taosGetSystemInfo(); if (tsNumOfCores <= 0) { tsNumOfCores = 1; @@ -408,7 +417,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU taosSetServerCfg(tsCfg); } - cfgDumpCfg(tsCfg, tsc); + cfgDumpCfg(tsCfg, tsc, false); return 0; } @@ -429,4 +438,4 @@ void taosCfgDynamicOptions(const char *option, const char *value) { taosResetLog(); // taosPrintCfg(); } -} +} \ No newline at end of file diff --git a/source/dnode/mgmt/daemon/inc/dmnInt.h b/source/dnode/mgmt/daemon/inc/dmnInt.h index 5e680aa77a..fc1c3b4f2c 100644 --- a/source/dnode/mgmt/daemon/inc/dmnInt.h +++ b/source/dnode/mgmt/daemon/inc/dmnInt.h @@ -28,15 +28,10 @@ extern "C" { #endif -int32_t dmnAddLogCfg(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); +SDnodeEnvCfg dmnGetEnvCfg(); +SDnodeObjCfg dmnGetObjCfg(); -SConfig *dmnReadCfg(const char *cfgDir, const char *envFile, const char *apolloUrl); -SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg); -SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg); - -void dmnDumpCfg(SConfig *pCfg); +void dmnDumpCfg(); void dmnPrintVersion(); void dmnGenerateGrant(); diff --git a/source/dnode/mgmt/daemon/src/dmnCfg.c b/source/dnode/mgmt/daemon/src/dmnCfg.c index cfff49c890..9f8a44ab89 100644 --- a/source/dnode/mgmt/daemon/src/dmnCfg.c +++ b/source/dnode/mgmt/daemon/src/dmnCfg.c @@ -15,131 +15,10 @@ #define _DEFAULT_SOURCE #include "dmnInt.h" +#include "tconfig.h" -static int32_t dmnCheckDirCfg(SConfig *pCfg) { - - return 0; -} - -static int32_t dmnAddDnodeCfg(SConfig *pCfg) { - if (dmnAddEpCfg(pCfg) != 0) return -1; - if (dmnAddDirCfg(pCfg) != 0) return -1; - if (dmnAddVersionCfg(pCfg) != 0) return -1; - - if (cfgAddTimezone(pCfg, "timezone", "") != 0) return -1; - if (cfgAddLocale(pCfg, "locale", "") != 0) return -1; - if (cfgAddCharset(pCfg, "charset", "") != 0) return -1; - if (cfgAddInt32(pCfg, "numOfCores", 2, 1, 100000) != 0) return -1; - if (cfgAddInt32(pCfg, "numOfCommitThreads", 4, 1, 1000) != 0) return -1; - if (cfgAddBool(pCfg, "telemetryReporting", 0) != 0) return -1; - if (cfgAddBool(pCfg, "enableCoreFile", 0) != 0) return -1; - if (cfgAddInt32(pCfg, "supportVnodes", 256, 0, 65536) != 0) return -1; - if (cfgAddInt32(pCfg, "statusInterval", 1, 1, 30) != 0) return -1; - if (cfgAddFloat(pCfg, "numOfThreadsPerCore", 1, 0, 10) != 0) return -1; - if (cfgAddFloat(pCfg, "ratioOfQueryCores", 1, 0, 5) != 0) return -1; - if (cfgAddInt32(pCfg, "maxShellConns", 50000, 10, 50000000) != 0) return -1; - if (cfgAddInt32(pCfg, "shellActivityTimer", 3, 1, 120) != 0) return -1; - if (cfgAddInt32(pCfg, "rpcTimer", 300, 100, 3000) != 0) return -1; - if (cfgAddInt32(pCfg, "rpcMaxTime", 600, 100, 7200) != 0) return -1; - - return 0; -} - -static void dmnSetDnodeCfg(SConfig *pCfg) { - SConfigItem *pItem = cfgGetItem(pCfg, "timezone"); - osSetTimezone(pItem->str); - uDebug("timezone format changed from %s to %s", pItem->str, osTimezone()); - cfgSetItem(pCfg, "timezone", osTimezone(), pItem->stype); -} - -static int32_t dmnCheckCfg(SConfig *pCfg) { - bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval; - taosSetCoreDump(enableCore); - - dmnSetDnodeCfg(pCfg); - - if (dmnCheckDirCfg(pCfg) != 0) { - return -1; - } - - taosGetSystemInfo(); - - - if (tsNumOfCores <= 0) { - tsNumOfCores = 1; - } - - if (tsQueryBufferSize >= 0) { - tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; - } - - return 0; -} - -SConfig *dmnReadCfg(const char *cfgDir, const char *envFile, const char *apolloUrl) { - SConfig *pCfg = cfgInit(); - if (pCfg == NULL) return NULL; - - if (dmnAddLogCfg(pCfg) != 0) { - uError("failed to add log cfg since %s", terrstr()); - cfgCleanup(pCfg); - return NULL; - } - - if (dmnAddDnodeCfg(pCfg) != 0) { - uError("failed to init dnode cfg since %s", terrstr()); - cfgCleanup(pCfg); - return NULL; - } - - if (dmnLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) { - uError("failed to load cfg since %s", terrstr()); - cfgCleanup(pCfg); - return NULL; - } - - if (dmnCheckCfg(pCfg) != 0) { - uError("failed to check cfg since %s", terrstr()); - cfgCleanup(pCfg); - return NULL; - } - - cfgDumpCfg(pCfg); - return pCfg; -} - -void dmnDumpCfg(SConfig *pCfg) { - printf("taos global config:\n"); - printf("==================================\n"); - - 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_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); - } -} - -SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg) { +SDnodeEnvCfg dmnGetEnvCfg() { + SConfig *pCfg = taosGetCfg(); SDnodeEnvCfg envCfg = {0}; const char *vstr = cfgGetItem(pCfg, "version")->str; @@ -147,27 +26,24 @@ SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg) { envCfg.numOfCores = cfgGetItem(pCfg, "numOfCores")->i32; envCfg.numOfCommitThreads = (uint16_t)cfgGetItem(pCfg, "numOfCommitThreads")->i32; envCfg.enableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; - envCfg.rpcMaxTime = cfgGetItem(pCfg, "rpcMaxTime")->i32; - envCfg.rpcTimer = cfgGetItem(pCfg, "rpcTimer")->i32; - return envCfg; } -SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg) { +SDnodeObjCfg dmnGetObjCfg() { + SConfig *pCfg = taosGetCfg(); 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; tstrncpy(objCfg.dataDir, cfgGetItem(pCfg, "dataDir")->str, sizeof(objCfg.dataDir)); - tstrncpy(objCfg.firstEp, cfgGetItem(pCfg, "firstEp")->str, sizeof(objCfg.firstEp)); tstrncpy(objCfg.secondEp, cfgGetItem(pCfg, "secondEp")->str, sizeof(objCfg.firstEp)); objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn)); snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort); return objCfg; +} + +void dmnDumpCfg() { + SConfig *pCfg = taosGetCfg(); + cfgDumpCfg(pCfg, 0, 1); } \ No newline at end of file diff --git a/source/dnode/mgmt/daemon/src/dmnMain.c b/source/dnode/mgmt/daemon/src/dmnMain.c index 62f0db5fc5..94b480c23d 100644 --- a/source/dnode/mgmt/daemon/src/dmnMain.c +++ b/source/dnode/mgmt/daemon/src/dmnMain.c @@ -72,14 +72,14 @@ static int32_t dmnParseOption(int32_t argc, char const *argv[]) { return 0; } -int32_t dmnRunDnode(SConfig *pCfg) { - SDnodeEnvCfg envCfg = dmnGetEnvCfg(pCfg); +int32_t dmnRunDnode() { + SDnodeEnvCfg envCfg = dmnGetEnvCfg(); if (dndInit(&envCfg) != 0) { uInfo("Failed to start TDengine, please check the log"); return -1; } - SDnodeObjCfg objCfg = dmnGetObjCfg(pCfg); + SDnodeObjCfg objCfg = dmnGetObjCfg(); SDnode *pDnode = dndCreate(&objCfg); if (pDnode == NULL) { uInfo("Failed to start TDengine, please check the log"); @@ -113,23 +113,23 @@ int main(int argc, char const *argv[]) { return 0; } - if (dmnInitLog(configDir, dmn.envFile, dmn.apolloUrl) != 0) { + if (taosCreateLog("taosdlog", 1, configDir, dmn.envFile, dmn.apolloUrl, 1) != 0) { + uInfo("Failed to start TDengine since read config error"); return -1; } - SConfig *pCfg = dmnReadCfg(configDir, dmn.envFile, dmn.apolloUrl); - if (pCfg == NULL) { + if (taosInitCfg(configDir, dmn.envFile, dmn.apolloUrl, 1) != 0) { uInfo("Failed to start TDengine since read config error"); return -1; } if (dmn.dumpConfig) { - dmnDumpCfg(pCfg); - cfgCleanup(pCfg); + dmnDumpCfg(); + taosCleanupCfg(); return 0; } - int32_t code = dmnRunDnode(pCfg); - cfgCleanup(pCfg); + int32_t code = dmnRunDnode(); + taosCleanupCfg(); return code; } diff --git a/source/dnode/mgmt/impl/test/sut/src/sut.cpp b/source/dnode/mgmt/impl/test/sut/src/sut.cpp index 5d2abd86c3..56fd1c91c8 100644 --- a/source/dnode/mgmt/impl/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/sut.cpp @@ -43,8 +43,6 @@ void Testbase::Init(const char* path, int16_t port) { SDnodeEnvCfg cfg = {0}; cfg.numOfCommitThreads = 1; cfg.numOfCores = 1; - cfg.rpcMaxTime = 600; - cfg.rpcTimer = 300; dndInit(&cfg); char fqdn[] = "localhost"; diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 4ced62ec37..839ced7f50 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -475,9 +475,16 @@ const char *cfgDtypeStr(ECfgDataType type) { } } -void cfgDumpCfg(SConfig *pCfg, bool tsc) { - uInfo(" global config"); - uInfo("================================================================="); +void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { + if (dump) { + printf(" global config"); + printf("\n"); + printf("================================================================="); + printf("\n"); + } else { + uInfo(" global config"); + uInfo("================================================================="); + } char src[CFG_SRC_PRINT_LEN + 1] = {0}; char name[CFG_NAME_PRINT_LEN + 1] = {0}; @@ -497,111 +504,62 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc) { switch (pItem->dtype) { case CFG_DTYPE_BOOL: - uInfo("%s %s %u", src, name, pItem->bval); + if (dump) { + printf("%s %s %u", src, name, pItem->bval); + printf("\n"); + } else { + uInfo("%s %s %u", src, name, pItem->bval); + } + break; case CFG_DTYPE_INT32: - uInfo("%s %s %d", src, name, pItem->i32); + if (dump) { + printf("%s %s %d", src, name, pItem->i32); + printf("\n"); + } else { + uInfo("%s %s %d", src, name, pItem->i32); + } break; case CFG_DTYPE_INT64: - uInfo("%s %s %" PRId64, src, name, pItem->i64); + if (dump) { + printf("%s %s %" PRId64, src, name, pItem->i64); + printf("\n"); + } else { + uInfo("%s %s %" PRId64, src, name, pItem->i64); + } break; case CFG_DTYPE_FLOAT: - uInfo("%s %s %f", src, name, pItem->fval); + if (dump) { + printf("%s %s %f", src, name, pItem->fval); + printf("\n"); + } else { + uInfo("%s %s %f", src, name, pItem->fval); + } break; case CFG_DTYPE_STRING: case CFG_DTYPE_DIR: case CFG_DTYPE_LOCALE: case CFG_DTYPE_CHARSET: case CFG_DTYPE_TIMEZONE: - uInfo("%s %s %s", src, name, pItem->str); + if (dump) { + printf("%s %s %s", src, name, pItem->str); + printf("\n"); + } else { + uInfo("%s %s %s", src, name, pItem->str); + } break; } pItem = cfgIterate(pCfg, pItem); } - uInfo("================================================================="); + if (dump) { + printf("================================================================="); + printf("\n"); + } else { + uInfo("================================================================="); + } } -#if 0 -// int32_t cfgCheck(SConfig *pCfg) { -// SConfigItem *pItem = NULL; - -// pItem = cfgGetItem(pCfg, "serverPort"); -// if (pItem != NULL) { -// tsServerPort = (uint16_t)pItem->i32; -// } - -// pItem = cfgGetItem(pCfg, "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(pCfg, "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(pCfg, "dataDir"); -// if (pItem != NULL) { -// tstrncpy(osDataDir(), pItem->str, PATH_MAX); -// } - -// if (tsDiskCfgNum <= 0) { -// taosAddDataDir(0, osDataDir(), 0, 1); -// tsDiskCfgNum = 1; -// uTrace("dataDir:%s, level:0 primary:1 is configured by default", osDataDir()); -// } - -// if (taosDirExist(osTempDir()) != 0) { -// return -1; -// } - -// taosGetSystemInfo(); - -// tsSetLocale(); - -// // SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); -// // if (cfg_timezone && cfg_timezone->cfgStatus == TAOS_CFG_CSTATUS_FILE) { -// tsSetTimeZone(); -// // } - -// pItem = cfgGetItem(pCfg, "numOfCores"); -// if (pItem != NULL) { -// tsNumOfCores = pItem->i32; -// } - -// if (tsNumOfCores <= 0) { -// tsNumOfCores = 1; -// } - -// if (tsQueryBufferSize >= 0) { -// tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; -// } - -// cfgPrintCfg(pCfg); - -// return 0; -// } -#endif - int32_t cfgLoadFromEnvVar(SConfig *pConfig) { uInfo("load from global env variables"); return 0;