From d9bc65e5be1a4d2a8c90b5038fce2cd047310990 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Feb 2022 12:03:25 +0800 Subject: [PATCH] config --- source/client/src/clientEnv.c | 5 --- source/common/src/tglobal.c | 47 +---------------------- source/dnode/mgmt/daemon/src/dmnCfg.c | 55 ++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 57 deletions(-) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 662a45a6f4..c7640e90d8 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -219,11 +219,6 @@ void taos_init_imp(void) { return; } - if (taosCheckAndPrintCfg()) { - tscInitRes = -1; - return; - } - taosInitNotes(); initMsgHandleFp(); initQueryModuleMsgHandle(); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 8fd3802441..9129ccdcae 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -274,13 +274,7 @@ void taosPrintDataDirCfg() { } #endif -static void taosCheckDataDirCfg() { - if (tsDiskCfgNum <= 0) { - taosAddDataDir(0, tsDataDir, 0, 1); - tsDiskCfgNum = 1; - uTrace("dataDir:%s, level:0 primary:1 is configured by default", tsDataDir); - } -} + static void doInitGlobalConfig(void) { osInit(); @@ -678,45 +672,6 @@ static void doInitGlobalConfig(void) { void taosInitGlobalCfg() { pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig); } -int32_t taosCheckAndPrintCfg() { -#if 0 - - SEp ep = {0}; - if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) { - taosSetAllDebugFlag(); - } - - - taosCheckDataDirCfg(); - - if (taosDirExist(tsTempDir) != 0) { - return -1; - } - - taosGetSystemInfo(); - - tsSetLocale(); - - SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); - if (cfg_timezone && cfg_timezone->cfgStatus == TAOS_CFG_CSTATUS_FILE) { - tsSetTimeZone(); - } - - if (tsNumOfCores <= 0) { - tsNumOfCores = 1; - } - - if (tsQueryBufferSize >= 0) { - tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; - } - - uInfo(" check global cfg completed"); - uInfo("=================================="); - taosPrintCfg(); -#endif - return 0; -} - /* * alter dnode 1 balance "vnode:1-dnode:2" */ diff --git a/source/dnode/mgmt/daemon/src/dmnCfg.c b/source/dnode/mgmt/daemon/src/dmnCfg.c index 5c83f9fecd..5f9a381273 100644 --- a/source/dnode/mgmt/daemon/src/dmnCfg.c +++ b/source/dnode/mgmt/daemon/src/dmnCfg.c @@ -15,6 +15,8 @@ #define _DEFAULT_SOURCE #include "dmnInt.h" +#include "tlocale.h" +#include "ttimezone.h" static int32_t dmnAddEpCfg(SConfig *pCfg) { char defaultFqdn[TSDB_FQDN_LEN] = {0}; @@ -23,7 +25,7 @@ static int32_t dmnAddEpCfg(SConfig *pCfg) { return -1; } if (cfgAddString(pCfg, "fqdn", defaultFqdn) != 0) return -1; - + int32_t defaultServerPort = 6030; if (cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056) != 0) return -1; @@ -37,15 +39,41 @@ static int32_t dmnAddEpCfg(SConfig *pCfg) { return 0; } -static int32_t dmnAddDnodeCfg(SConfig *pCfg) { - if (dmnAddEpCfg(pCfg) != 0) return -1; +static int32_t dmnAddDirCfg(SConfig *pCfg) { + if (cfgAddDir(pCfg, "dataDir", tsDataDir) != 0) return -1; + if (cfgAddDir(pCfg, "tmpDir", tsTempDir) != 0) return -1; + return 0; +} +static int32_t dmnCheckDirCfg(SConfig *pCfg) { + SConfigItem *pItem = NULL; + pItem = cfgGetItem(pCfg, "dataDir"); + if (tsDiskCfgNum <= 0) { + taosAddDataDir(0, pItem->str, 0, 1); + tsDiskCfgNum = 1; + uTrace("dataDir:%s, level:0 primary:1 is configured by default", pItem->str); + } + pItem = cfgGetItem(pCfg, "tmpDir"); + if (taosDirExist(pItem->str) != 0) { + return -1; + } + + return 0; +} + +static int32_t dmnAddVersionCfg(SConfig *pCfg) { if (cfgAddString(pCfg, "buildinfo", buildinfo) != 0) return -1; if (cfgAddString(pCfg, "gitinfo", gitinfo) != 0) return -1; if (cfgAddString(pCfg, "version", version) != 0) return -1; - - if (cfgAddDir(pCfg, "dataDir", tsDataDir) != 0) return -1; + 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; @@ -62,11 +90,26 @@ static int32_t dmnAddDnodeCfg(SConfig *pCfg) { return 0; } -int32_t dmnCheckCfg(SConfig *pCfg) { +static int32_t dmnCheckCfg(SConfig *pCfg) { bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval; taosSetCoreDump(enableCore); + if (dmnCheckDirCfg(pCfg) != 0) { + return -1; + } + taosGetSystemInfo(); + + tsSetTimeZone(); + tsSetLocale(); + + if (tsNumOfCores <= 0) { + tsNumOfCores = 1; + } + + if (tsQueryBufferSize >= 0) { + tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; + } return 0; }