diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index b975d92593..3741c75db1 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1870,7 +1870,8 @@ _exit: static int32_t taosCheckGlobalCfg() { uint32_t ipv4 = 0; - int32_t code = taosGetIpv4FromFqdn(tsLocalFqdn, &ipv4); + uInfo("start to check global tsLocalFqdn:%s, tsServerPort:%u", tsLocalFqdn, tsServerPort); + int32_t code = taosGetIpv4FromFqdn(tsLocalFqdn, &ipv4); if (code) { uError("failed to get ip from fqdn:%s since %s, dnode can not be initialized", tsLocalFqdn, tstrerror(code)); TAOS_RETURN(TSDB_CODE_RPC_FQDN_ERROR); @@ -1933,6 +1934,9 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) { if (pItem == NULL) { continue; } + if (strstr(item->name, "supportVnodes")) { + uDebug("supportVnodes:%d", pItem->valueint); + } switch (item->dtype) { { case CFG_DTYPE_NONE: @@ -1955,7 +1959,7 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) { case CFG_DTYPE_LOCALE: case CFG_DTYPE_CHARSET: case CFG_DTYPE_TIMEZONE: - tstrncpy(item->str, pItem->valuestring, strlen(pItem->valuestring)); + item->str = taosStrdup(pItem->valuestring); break; } } @@ -1969,10 +1973,10 @@ int32_t readCfgFile(const char *path, bool isGlobal) { SArray *array = NULL; if (isGlobal) { array = taosGetGlobalCfg(tsCfg); - snprintf(filename, sizeof(filename), "%s%sconfig%sglobal.json", path, TD_DIRSEP, TD_DIRSEP); + snprintf(filename, sizeof(filename), "%s%sdnode%sconfig%sglobal.json", path, TD_DIRSEP, TD_DIRSEP, TD_DIRSEP); } else { array = taosGetLocalCfg(tsCfg); - snprintf(filename, sizeof(filename), "%s%sconfig%slocal.json", path, TD_DIRSEP, TD_DIRSEP); + snprintf(filename, sizeof(filename), "%s%sdnode%sconfig%slocal.json", path, TD_DIRSEP, TD_DIRSEP, TD_DIRSEP); } uInfo("start to read config file:%s", filename); @@ -1983,6 +1987,7 @@ int32_t readCfgFile(const char *path, bool isGlobal) { code = terrno; uTrace("failed to stat file:%s , since %s", filename, tstrerror(code)); } + uInfo("config file:%s does not exist", filename); TAOS_RETURN(TSDB_CODE_SUCCESS); } TdFilePtr pFile = taosOpenFile(filename, TD_FILE_READ); @@ -2067,13 +2072,17 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile tsCfg = NULL; TAOS_RETURN(code); } - TAOS_CHECK_GOTO(tryLoadCfgFromDataDir(tsCfg), &lino, _exit); + + if (!tsc) { + TAOS_CHECK_GOTO(taosSetTfsCfg(tsCfg), &lino, _exit); + TAOS_CHECK_GOTO(taosUpdateServerCfg(tsCfg), &lino, _exit); + TAOS_CHECK_GOTO(tryLoadCfgFromDataDir(tsCfg), &lino, _exit); + } if (tsc) { TAOS_CHECK_GOTO(taosSetClientCfg(tsCfg), &lino, _exit); } else { TAOS_CHECK_GOTO(taosSetClientCfg(tsCfg), &lino, _exit); - TAOS_CHECK_GOTO(taosUpdateServerCfg(tsCfg), &lino, _exit); TAOS_CHECK_GOTO(taosSetServerCfg(tsCfg), &lino, _exit); TAOS_CHECK_GOTO(taosSetReleaseCfg(tsCfg), &lino, _exit); TAOS_CHECK_GOTO(taosSetTfsCfg(tsCfg), &lino, _exit); @@ -2716,6 +2725,8 @@ int32_t globalConfigSerialize(int32_t version, SArray *array, char **serialized) cJSON *cField = cJSON_CreateObject(); if (cField == NULL) goto _exit; + if (!cJSON_AddItemToObject(json, "configs", cField)) goto _exit; + // cjson only support int32_t or double // string are used to prohibit the loss of precision for (int i = 0; i < sz; i++) { @@ -2749,7 +2760,6 @@ int32_t globalConfigSerialize(int32_t version, SArray *array, char **serialized) } } } - if (!cJSON_AddItemToObject(json, "configs", cField)) goto _exit; char *pSerialized = cJSON_Print(json); _exit: if (terrno != TSDB_CODE_SUCCESS) { @@ -2769,6 +2779,9 @@ int32_t localConfigSerialize(SArray *array, char **serialized) { cJSON *cField = cJSON_CreateObject(); if (cField == NULL) goto _exit; + + if (!cJSON_AddItemToObject(json, "configs", cField)) goto _exit; + // cjson only support int32_t or double // string are used to prohibit the loss of precision for (int i = 0; i < sz; i++) { @@ -2802,7 +2815,6 @@ int32_t localConfigSerialize(SArray *array, char **serialized) { } } } - if (!cJSON_AddItemToObject(json, "configs", cField)) goto _exit; char *pSerialized = cJSON_Print(json); _exit: if (terrno != TSDB_CODE_SUCCESS) { diff --git a/tests/system-test/0-others/persisit_config.py b/tests/system-test/0-others/persisit_config.py new file mode 100644 index 0000000000..b7d437de3d --- /dev/null +++ b/tests/system-test/0-others/persisit_config.py @@ -0,0 +1,105 @@ +import sys +import taos +import os +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes + +class TDTestCase: + updatecfgDict = { + "supportVnodes":"1000", + "tmqMaxTopicNum":"30", + "maxShellConns":"1000", + "monitorFqdn":"localhost:9033", + "tmqRowSize":"1000", + "ttlChangeOnWrite":"1", + "compressor":"1", + "statusInterval":"4", + } + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files or "taosd.exe" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + self.index = 1 + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def cli_get_param_value(self, config_name): + tdSql.query("show dnode 1 variables;") + for row in tdSql.queryResult: + if config_name == row[1]: + tdLog.debug("Found variable '{}'".format(row[0])) + return row[2] + + def cfg(self, option, value): + cmd = "echo '%s %s' >> %s" % (option, value, self.cfgPath) + if os.system(cmd) != 0 : + tdLog.exit(cmd) + + def run(self): + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + + cfgPath = buildPath + "/../sim/dnode%d/cfg" % (self.index) + self.cfgPath = cfgPath + + dataPath = buildPath + "/../sim/dnode%d/data" % (self.index) + self.dataPath = dataPath + + logPath = buildPath + "/../sim/dnode%d/log" % (self.index) + self.logPath = logPath + + tdLog.info("start to check cfg value load from cfg file {0}".format(cfgPath)) + + for name,expValue in self.updatecfgDict.items(): + actValue = self.cli_get_param_value(name) + tdLog.debug("Get {} value: {} Expect value: {}".format(name, actValue,expValue)) + assert str(actValue) == str(expValue) + + tdLog.info("rm -rf {0}".format(cfgPath)) + os.system("rm -rf {0}/*".format(cfgPath)) + + tdLog.info("rebuilt cfg file {0}".format(cfgPath)) + cfgName = cfgPath+"/taos.cfg" + os.system("touch {0}".format(cfgName)) + os.system("echo 'fqdn localhost' >> {0}".format(cfgName)) + os.system("echo 'dataDir {0}' >> {1}".format(dataPath, cfgName)) + os.system("echo 'logDir {0}' >> {1}".format(logPath, cfgName)) + + tdDnodes.stop(1) + tdLog.info("restart taosd") + tdDnodes.start(1) + + tdLog.info("start to check cfg value load from mnd sdb") + + for name,expValue in self.updatecfgDict.items(): + actValue = self.cli_get_param_value(name) + tdLog.debug("Get {} value: {} Expect value: {}".format(name, actValue,expValue)) + assert str(actValue) == str(expValue) + + def stop(self): + tdSql.close() + # tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) +