From 42c100df2d668be0713be589abfb7d8ed2a48633 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Feb 2022 15:02:17 +0800 Subject: [PATCH] sim config --- include/common/tep.h | 2 +- include/common/tglobal.h | 3 - source/client/src/clientCfg.c | 14 ++--- source/client/src/clientImpl.c | 62 +++++++++---------- source/client/src/clientMain.c | 6 +- source/common/src/tep.c | 6 +- source/common/src/tglobal.c | 32 +++++----- source/dnode/mgmt/daemon/src/dmnCfg.c | 15 ++--- .../mgmt/daemon/src/{daemon.c => dmnMain.c} | 0 source/dnode/mgmt/impl/src/dndMgmt.c | 2 +- source/util/src/tlog.c | 4 ++ 11 files changed, 64 insertions(+), 82 deletions(-) rename source/dnode/mgmt/daemon/src/{daemon.c => dmnMain.c} (100%) diff --git a/include/common/tep.h b/include/common/tep.h index 584b8a5a71..6ca180667b 100644 --- a/include/common/tep.h +++ b/include/common/tep.h @@ -23,7 +23,7 @@ typedef struct SBlockOrderInfo { // bool hasNull; } SBlockOrderInfo; -int taosGetFqdnPortFromEp(const char *ep, SEp *pEp); +int taosGetFqdnPortFromEp(const char *ep, uint16_t defaultPort, SEp *pEp); void addEpIntoEpSet(SEpSet *pEpSet, const char *fqdn, uint16_t port); bool isEpsetEqual(const SEpSet *s1, const SEpSet *s2); diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 94b2471ecc..7458e5d837 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -100,13 +100,10 @@ extern uint32_t tsMaxRange; extern uint32_t tsCurRange; extern char tsCompressor[]; -extern int32_t tsDiskCfgNum; -extern SDiskCfg tsDiskCfg[]; #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) void taosInitGlobalCfg(); -int32_t taosCheckAndPrintCfg(); int32_t taosCfgDynamicOptions(char *msg); bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId); void taosAddDataDir(int index, char *v1, int level, int primary); diff --git a/source/client/src/clientCfg.c b/source/client/src/clientCfg.c index 22eea6901e..352495178b 100644 --- a/source/client/src/clientCfg.c +++ b/source/client/src/clientCfg.c @@ -21,20 +21,20 @@ SConfig *tscCfg; static int32_t tscLoadCfg(SConfig *pConfig, const char *inputCfgDir, const char *envFile, const char *apolloUrl) { - char configDir[PATH_MAX] = {0}; - char configFile[PATH_MAX + 100] = {0}; + char cfgDir[PATH_MAX] = {0}; + char cfgFile[PATH_MAX + 100] = {0}; - taosExpandDir(inputCfgDir, configDir, PATH_MAX); - snprintf(configFile, sizeof(configFile), "%s" TD_DIRSEP "taos.cfg", configDir); + taosExpandDir(inputCfgDir, cfgDir, PATH_MAX); + snprintf(cfgFile, sizeof(cfgFile), "%s" TD_DIRSEP "taos.cfg", cfgDir); 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()); + if (cfgLoad(pConfig, CFG_STYPE_CFG_FILE, cfgFile) != 0) { + if (cfgLoad(pConfig, CFG_STYPE_CFG_FILE, cfgDir) != 0) { + uError("failed to load from config file:%s since %s\n", cfgFile, terrstr()); return -1; } } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index dfbd725753..c98a3695d9 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -12,7 +12,7 @@ #include "tpagedbuf.h" #include "tref.h" -static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet); +static int32_t initEpSetFromCfg(const char* ip, uint16_t port, SCorEpSet* pEpSet); static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest); static void destroySendMsgInfo(SMsgSendInfo* pMsgBody); static void setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp); @@ -81,21 +81,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, } SCorEpSet epSet = {0}; - if (ip) { - if (initEpSetFromCfg(ip, NULL, &epSet) < 0) { - return NULL; - } - - if (port) { - epSet.epSet.eps[0].port = port; - } - } else { - SConfigItem* pFirst = cfgGetItem(tscCfg, "firstEp"); - SConfigItem* pSecond = cfgGetItem(tscCfg, "secondEp"); - if (initEpSetFromCfg(pFirst->str, pSecond->str, &epSet) < 0) { - return NULL; - } - } + initEpSetFromCfg(ip, port, &epSet); char* key = getClusterKey(user, secretEncrypt, ip, port); SAppInstInfo** pInst = NULL; @@ -284,32 +270,40 @@ _return: return pRequest; } -int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet) { - pEpSet->version = 0; +int initEpSetFromCfg(const char* ip, uint16_t port, SCorEpSet* pEpSet) { + SConfigItem* pFirst = cfgGetItem(tscCfg, "firstEp"); + SConfigItem* pSecond = cfgGetItem(tscCfg, "secondEp"); + SConfigItem* pPort = cfgGetItem(tscCfg, "serverPort"); // init mnode ip set SEpSet* mgmtEpSet = &(pEpSet->epSet); mgmtEpSet->numOfEps = 0; mgmtEpSet->inUse = 0; + pEpSet->version = 0; - if (firstEp && firstEp[0] != 0) { - if (strlen(firstEp) >= TSDB_EP_LEN) { - terrno = TSDB_CODE_TSC_INVALID_FQDN; - return -1; - } - - taosGetFqdnPortFromEp(firstEp, &mgmtEpSet->eps[0]); + if (ip != NULL) { + taosGetFqdnPortFromEp(ip, (uint16_t)pPort->i32, &mgmtEpSet->eps[0]); mgmtEpSet->numOfEps++; - } - - if (secondEp && secondEp[0] != 0) { - if (strlen(secondEp) >= TSDB_EP_LEN) { - terrno = TSDB_CODE_TSC_INVALID_FQDN; - return -1; + if (port) { + mgmtEpSet->eps[0].port = port; + } + } else { + if (pFirst->str[0] != 0) { + if (strlen(pFirst->str) >= TSDB_EP_LEN) { + terrno = TSDB_CODE_TSC_INVALID_FQDN; + return -1; + } + taosGetFqdnPortFromEp(pFirst->str, (uint16_t)pPort->i32, &mgmtEpSet->eps[0]); + mgmtEpSet->numOfEps++; + } + if (pSecond->str[0] != 0) { + if (strlen(pSecond->str) >= TSDB_EP_LEN) { + terrno = TSDB_CODE_TSC_INVALID_FQDN; + return -1; + } + taosGetFqdnPortFromEp(pSecond->str, (uint16_t)pPort->i32, &mgmtEpSet->eps[1]); + mgmtEpSet->numOfEps++; } - - taosGetFqdnPortFromEp(secondEp, &mgmtEpSet->eps[mgmtEpSet->numOfEps]); - mgmtEpSet->numOfEps++; } if (mgmtEpSet->numOfEps == 0) { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 35532f80ea..00d629ebb2 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -56,9 +56,7 @@ void taos_cleanup(void) { } TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { - int32_t p = (port != 0) ? port : cfgGetItem(tscCfg, "serverPort")->i32; - - tscDebug("try to connect to %s:%u, user:%s db:%s", ip, p, user, db); + tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db); if (user == NULL) { user = TSDB_DEFAULT_USER; } @@ -67,7 +65,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha pass = TSDB_DEFAULT_PASS; } - return taos_connect_internal(ip, user, pass, NULL, db, p); + return taos_connect_internal(ip, user, pass, NULL, db, port); } void taos_close(TAOS* taos) { diff --git a/source/common/src/tep.c b/source/common/src/tep.c index 643a313ec2..3e98cae279 100644 --- a/source/common/src/tep.c +++ b/source/common/src/tep.c @@ -4,7 +4,7 @@ #include "tglobal.h" #include "tlockfree.h" -int taosGetFqdnPortFromEp(const char *ep, SEp* pEp) { +int taosGetFqdnPortFromEp(const char *ep, uint16_t defaultPort, SEp* pEp) { pEp->port = 0; strcpy(pEp->fqdn, ep); @@ -14,12 +14,10 @@ int taosGetFqdnPortFromEp(const char *ep, SEp* pEp) { pEp->port = atoi(temp+1); } -#if 0 if (pEp->port == 0) { - pEp->port = tsServerPort; + pEp->port = defaultPort; return -1; } -#endif return 0; } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 9129ccdcae..fc25dac0df 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -125,8 +125,6 @@ int8_t tsDeadLockKillQuery = 0; // For backward compatibility bool tsdbForceKeepFile = false; -int32_t tsDiskCfgNum = 0; - #ifndef _STORAGE SDiskCfg tsDiskCfg[1]; #else @@ -257,21 +255,21 @@ void taosAddDataDir(int index, char *v1, int level, int primary) { } #ifndef _STORAGE -void taosReadDataDirCfg(char *v1, char *v2, char *v3) { - if (tsDiskCfgNum == 1) { - SDiskCfg *cfg = &tsDiskCfg[0]; - uInfo("dataDir:%s, level:%d primary:%d is replaced by %s", cfg->dir, cfg->level, cfg->primary, v1); - } - taosAddDataDir(0, v1, 0, 1); - tsDiskCfgNum = 1; -} - -void taosPrintDataDirCfg() { - for (int i = 0; i < tsDiskCfgNum; ++i) { - SDiskCfg *cfg = &tsDiskCfg[i]; - uInfo(" dataDir: %s", cfg->dir); - } -} +// void taosReadDataDirCfg(char *v1, char *v2, char *v3) { +// if (tsDiskCfgNum == 1) { +// SDiskCfg *cfg = &tsDiskCfg[0]; +// uInfo("dataDir:%s, level:%d primary:%d is replaced by %s", cfg->dir, cfg->level, cfg->primary, v1); +// } +// taosAddDataDir(0, v1, 0, 1); +// tsDiskCfgNum = 1; +// } + +// void taosPrintDataDirCfg() { +// for (int i = 0; i < tsDiskCfgNum; ++i) { +// SDiskCfg *cfg = &tsDiskCfg[i]; +// uInfo(" dataDir: %s", cfg->dir); +// } +// } #endif diff --git a/source/dnode/mgmt/daemon/src/dmnCfg.c b/source/dnode/mgmt/daemon/src/dmnCfg.c index 5f9a381273..1f68df6fe4 100644 --- a/source/dnode/mgmt/daemon/src/dmnCfg.c +++ b/source/dnode/mgmt/daemon/src/dmnCfg.c @@ -47,13 +47,6 @@ static int32_t dmnAddDirCfg(SConfig *pCfg) { 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; @@ -204,12 +197,12 @@ SDnodeObjCfg dmnGetObjCfg(SConfig *pCfg) { 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)); - + objCfg.serverPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32; + tstrncpy(objCfg.localFqdn, cfgGetItem(pCfg, "fqdn")->str, sizeof(objCfg.localFqdn, cfgGetItem)); + snprintf(objCfg.localEp, sizeof(objCfg.localEp), "%s:%u", objCfg.localFqdn, objCfg.serverPort); return objCfg; } \ No newline at end of file diff --git a/source/dnode/mgmt/daemon/src/daemon.c b/source/dnode/mgmt/daemon/src/dmnMain.c similarity index 100% rename from source/dnode/mgmt/daemon/src/daemon.c rename to source/dnode/mgmt/daemon/src/dmnMain.c diff --git a/source/dnode/mgmt/impl/src/dndMgmt.c b/source/dnode/mgmt/impl/src/dndMgmt.c index 3d149a3e60..1748c52c66 100644 --- a/source/dnode/mgmt/impl/src/dndMgmt.c +++ b/source/dnode/mgmt/impl/src/dndMgmt.c @@ -296,7 +296,7 @@ PRASE_DNODE_OVER: if (taosArrayGetSize(pMgmt->pDnodeEps) == 0) { SDnodeEp dnodeEp = {0}; dnodeEp.isMnode = 1; - taosGetFqdnPortFromEp(pDnode->cfg.firstEp, &dnodeEp.ep); + taosGetFqdnPortFromEp(pDnode->cfg.firstEp, pDnode->cfg.serverPort, &dnodeEp.ep); taosArrayPush(pMgmt->pDnodeEps, &dnodeEp); } diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index e17f221925..ecd0f0437b 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -71,6 +71,7 @@ int8_t tscEmbeddedInUtil = 0; int32_t tsLogKeepDays = 0; bool tsAsyncLog = true; +bool tsLogInited = false; float tsTotalLogDirGB = 0; float tsAvailLogDirGB = 0; float tsMinimalLogDirGB = 1.0f; @@ -120,6 +121,8 @@ static int32_t taosStartLog() { } int32_t taosInitLog(const char *logName, int maxFiles) { + if (tsLogInited) return 0; + char fullName[PATH_MAX] = {0}; snprintf(fullName, PATH_MAX, "%s" TD_DIRSEP "%s", tsLogDir, logName); @@ -127,6 +130,7 @@ int32_t taosInitLog(const char *logName, int maxFiles) { if (tsLogObj.logHandle == NULL) return -1; if (taosOpenLogFile(fullName, tsNumOfLogLines, maxFiles) < 0) return -1; if (taosStartLog() < 0) return -1; + tsLogInited = true; return 0; } -- GitLab