From 94eac805b99762db1289bcba9ec50f5d33eb747f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 23 Nov 2021 19:54:17 +0800 Subject: [PATCH] TD-10430 refact osDir.h and daemon module --- include/dnode/mgmt/dnode.h | 110 ++++++++++++++++++++---- include/os/osDir.h | 12 +-- source/common/src/tglobal.c | 2 +- source/dnode/mgmt/daemon/src/daemon.c | 12 +-- source/dnode/mgmt/impl/src/dndInt.c | 6 +- source/dnode/mnode/sdb/src/sdbFile.c | 6 +- source/dnode/vnode/tq/src/tqMetaStore.c | 2 +- source/libs/wal/src/walMgmt.c | 2 +- source/os/src/osDir.c | 18 ++-- source/util/src/tconfig.c | 2 +- src/client/src/tscSub.c | 2 +- src/tfs/src/tfs.c | 2 +- 12 files changed, 125 insertions(+), 51 deletions(-) diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index a1a94bb10b..7dd7730443 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -26,38 +26,112 @@ extern "C" { typedef struct SDnode SDnode; typedef struct { - int32_t sver; - int32_t numOfCores; - float numOfThreadsPerCore; - float ratioOfQueryCores; - int32_t maxShellConns; - int32_t shellActivityTimer; - int32_t statusInterval; + /** + * @brief software version of the program. + * + */ + int32_t sver; + + /** + * @brief num of CPU cores. + * + */ + int32_t numOfCores; + + /** + * @brief number of threads per CPU core. + * + */ + float numOfThreadsPerCore; + + /** + * @brief the proportion of total CPU cores available for query processing. + * + */ + float ratioOfQueryCores; + + /** + * @brief max number of connections allowed in dnode. + * + */ + int32_t maxShellConns; + + /** + * @brief time interval of heart beat from shell to dnode, seconds. + * + */ + int32_t shellActivityTimer; + + /** + * @brief time interval of dnode status reporting to mnode, seconds, for cluster only. + * + */ + int32_t statusInterval; + + /** + * @brief first port number for the connection (12 continuous UDP/TCP port number are used). + * + */ uint16_t serverPort; - char dataDir[PATH_MAX]; - char localEp[TSDB_EP_LEN]; - char localFqdn[TSDB_FQDN_LEN]; - char firstEp[TSDB_EP_LEN]; - char timezone[TSDB_TIMEZONE_LEN]; - char locale[TSDB_LOCALE_LEN]; - char charset[TSDB_LOCALE_LEN]; + + /** + * @brief data file's directory. + * + */ + char dataDir[PATH_MAX]; + + /** + * @brief local endpoint. + * + */ + char localEp[TSDB_EP_LEN]; + + /** + * @brieflocal fully qualified domain name (FQDN). + * + */ + char localFqdn[TSDB_FQDN_LEN]; + + /** + * @brief first fully qualified domain name (FQDN) for TDengine system. + * + */ + char firstEp[TSDB_EP_LEN]; + + /** + * @brief system time zone. + * + */ + char timezone[TSDB_TIMEZONE_LEN]; + + /** + * @brief system locale. + * + */ + char locale[TSDB_LOCALE_LEN]; + + /** + * @briefdefault system charset. + * + */ + char charset[TSDB_LOCALE_LEN]; } SDnodeOpt; /* ------------------------ SDnode ------------------------ */ /** * @brief Initialize and start the dnode. * - * @param cfgPath Config file path. + * @param pOptions Options of the dnode. * @return SDnode* The dnode object. */ SDnode *dndInit(SDnodeOpt *pOptions); /** - * @brief Stop and cleanup dnode. + * @brief Stop and cleanup the dnode. * - * @param pDnd The dnode object to close. + * @param pDnode The dnode object to close. */ -void dndCleanup(SDnode *pDnd); +void dndCleanup(SDnode *pDnode); #ifdef __cplusplus } diff --git a/include/os/osDir.h b/include/os/osDir.h index 8aefaa171a..35c294af39 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -20,12 +20,12 @@ extern "C" { #endif -void taosRemoveDir(const char *dirname); -bool taosDirExist(char *dirname); -bool taosMkDir(const char *dirname); -void taosRemoveOldFiles(char *dirname, int32_t keepDays); -bool taosExpandDir(char *dirname, char *outname, int32_t maxlen); -bool taosRealPath(char *dirname, int32_t maxlen); +void taosRemoveDir(const char *dirname); +int32_t taosDirExist(char *dirname); +int32_t taosMkDir(const char *dirname); +void taosRemoveOldFiles(char *dirname, int32_t keepDays); +int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen); +int32_t taosRealPath(char *dirname, int32_t maxlen); #ifdef __cplusplus } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index a19f6ec04b..501936d354 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1679,7 +1679,7 @@ int32_t taosCheckGlobalCfg() { taosCheckDataDirCfg(); - if (!taosDirExist(tsTempDir)) { + if (taosDirExist(tsTempDir) != 0) { return -1; } diff --git a/source/dnode/mgmt/daemon/src/daemon.c b/source/dnode/mgmt/daemon/src/daemon.c index e160de62d9..a57db1f778 100644 --- a/source/dnode/mgmt/daemon/src/daemon.c +++ b/source/dnode/mgmt/daemon/src/daemon.c @@ -40,7 +40,7 @@ void dmnSetSignalHandle() { taosSetSignal(SIGBREAK, dmnSigintHandle); } -int dmnParseOpts(int argc, char const *argv[]) { +int dmnParseOption(int argc, char const *argv[]) { tstrncpy(global.configDir, "/etc/taos", PATH_MAX); for (int i = 1; i < argc; ++i) { @@ -52,7 +52,7 @@ int dmnParseOpts(int argc, char const *argv[]) { } tstrncpy(global.configDir, argv[i], PATH_MAX); } else { - printf("'-c' requires a parameter, default:%s\n", configDir); + printf("'-c' requires a parameter, default is %s\n", configDir); return -1; } } else if (strcmp(argv[i], "-C") == 0) { @@ -78,11 +78,11 @@ void dmnGenerateGrant() { void dmnPrintVersion() { #ifdef TD_ENTERPRISE - char *versionStr = "enterprise"; + char *releaseName = "enterprise"; #else - char *versionStr = "community"; + char *releaseName = "community"; #endif - printf("%s version: %s compatible_version: %s\n", versionStr, version, compatible_version); + 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); @@ -164,7 +164,7 @@ int dmnRunDnode() { } int main(int argc, char const *argv[]) { - if (dmnParseOpts(argc, argv) != 0) { + if (dmnParseOption(argc, argv) != 0) { return -1; } diff --git a/source/dnode/mgmt/impl/src/dndInt.c b/source/dnode/mgmt/impl/src/dndInt.c index 9f575ddb4d..f4cee3f6fd 100644 --- a/source/dnode/mgmt/impl/src/dndInt.c +++ b/source/dnode/mgmt/impl/src/dndInt.c @@ -98,19 +98,19 @@ static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOptions) { return -1; } - if (!taosMkDir(pDnode->dir.dnode)) { + if (taosMkDir(pDnode->dir.dnode) != 0) { dError("failed to create dir:%s since %s", pDnode->dir.dnode, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } - if (!taosMkDir(pDnode->dir.mnode)) { + if (taosMkDir(pDnode->dir.mnode) != 0) { dError("failed to create dir:%s since %s", pDnode->dir.mnode, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } - if (!taosMkDir(pDnode->dir.vnodes)) { + if (taosMkDir(pDnode->dir.vnodes) != 0) { dError("failed to create dir:%s since %s", pDnode->dir.vnodes, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); return -1; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 169b2cf809..d77ec6ef8f 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -21,19 +21,19 @@ static int32_t sdbCreateDir() { mDebug("start to create mnode at %s", tsMnodeDir); - if (!taosMkDir(tsSdb.currDir)) { + if (taosMkDir(tsSdb.currDir) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to create dir:%s since %s", tsSdb.currDir, terrstr()); return -1; } - if (!taosMkDir(tsSdb.syncDir)) { + if (taosMkDir(tsSdb.syncDir) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to create dir:%s since %s", tsSdb.syncDir, terrstr()); return -1; } - if (!taosMkDir(tsSdb.tmpDir)) { + if (taosMkDir(tsSdb.tmpDir) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to create dir:%s since %s", tsSdb.tmpDir, terrstr()); return -1; diff --git a/source/dnode/vnode/tq/src/tqMetaStore.c b/source/dnode/vnode/tq/src/tqMetaStore.c index 71d1e8d890..81b48191bc 100644 --- a/source/dnode/vnode/tq/src/tqMetaStore.c +++ b/source/dnode/vnode/tq/src/tqMetaStore.c @@ -92,7 +92,7 @@ TqMetaStore* tqStoreOpen(const char* path, char name[pathLen+10]; strcpy(name, path); - if(!taosDirExist(name) && !taosMkDir(name)) { + if (taosDirExist(name) != 0 && taosMkDir(name) != 0) { ASSERT(false); } strcat(name, "/" TQ_IDX_NAME); diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 2bc12b374c..917723b166 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -136,7 +136,7 @@ void walClose(SWal *pWal) { } static int32_t walInitObj(SWal *pWal) { - if (!taosMkDir(pWal->path)) { + if (taosMkDir(pWal->path) != 0) { wError("vgId:%d, path:%s, failed to create directory since %s", pWal->vgId, pWal->path, strerror(errno)); return TAOS_SYSTEM_ERROR(errno); } diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index bf9446c578..cfa0028925 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -58,15 +58,15 @@ void taosRemoveDir(const char *dirname) { printf("dir:%s is removed\n", dirname); } -bool taosDirExist(char *dirname) { return access(dirname, F_OK) == 0; } +int32_t taosDirExist(char *dirname) { return access(dirname, F_OK); } -bool taosMkDir(const char *dirname) { +int32_t taosMkDir(const char *dirname) { int32_t code = mkdir(dirname, 0755); if (code < 0 && errno == EEXIST) { - return true; + return 0; } - return code == 0; + return code; } void taosRemoveOldFiles(char *dirname, int32_t keepDays) { @@ -112,12 +112,12 @@ void taosRemoveOldFiles(char *dirname, int32_t keepDays) { rmdir(dirname); } -bool taosExpandDir(char *dirname, char *outname, int32_t maxlen) { +int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen) { wordexp_t full_path; if (0 != wordexp(dirname, &full_path, 0)) { printf("failed to expand path:%s since %s", dirname, strerror(errno)); wordfree(&full_path); - return false; + return -1; } if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { @@ -126,16 +126,16 @@ bool taosExpandDir(char *dirname, char *outname, int32_t maxlen) { wordfree(&full_path); - return true; + return 0; } -bool taosRealPath(char *dirname, int32_t maxlen) { +int32_t taosRealPath(char *dirname, int32_t maxlen) { char tmp[PATH_MAX] = {0}; if (realpath(dirname, tmp) != NULL) { strncpy(dirname, tmp, maxlen); } - return true; + return 0; } #endif diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 1ca29f798a..d249297e8b 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -154,7 +154,7 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { taosExpandDir(input_value, option, cfg->ptrLength); taosRealPath(option, cfg->ptrLength); - if (!taosMkDir(option)) { + if (taosMkDir(option) != 0) { uError("config option:%s, input value:%s, directory not exist, create fail:%s", cfg->option, input_value, strerror(errno)); return false; diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index a0af98a9d2..6464224c5e 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -371,7 +371,7 @@ void tscSaveSubscriptionProgress(void* sub) { char path[256]; sprintf(path, "%s/subscribe", tsDataDir); - if (!taosMkDir(path)) { + if (taosMkDir(path) != 0) { tscError("failed to create subscribe dir: %s", path); } diff --git a/src/tfs/src/tfs.c b/src/tfs/src/tfs.c index b8e8972d93..547f862c20 100644 --- a/src/tfs/src/tfs.c +++ b/src/tfs/src/tfs.c @@ -252,7 +252,7 @@ int tfsMkdirAt(const char *rname, int level, int id) { char aname[TMPNAME_LEN]; snprintf(aname, TMPNAME_LEN, "%s/%s", DISK_DIR(pDisk), rname); - if (!taosMkDir(aname)) { + if (taosMkDir(aname) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; }