From a86b9faa9f81c687ca628cc5f7518b3f2f7a1b48 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 12 Apr 2022 17:28:56 +0800 Subject: [PATCH] refact(cluster): node mgmt --- source/dnode/mgmt/CMakeLists.txt | 7 +- source/dnode/mgmt/exe/dndMain.c | 6 +- source/dnode/mgmt/implement/inc/dndNode.h | 68 +++++++++++++++++++ .../mgmt/{main => implement/src}/dndEnv.c | 2 +- .../mgmt/{main => implement/src}/dndExec.c | 2 +- .../mgmt/{main => implement/src}/dndObj.c | 2 +- .../{main => implement/src}/dndTransport.c | 2 +- source/dnode/mgmt/inc/bmInt.h | 2 +- source/dnode/mgmt/inc/dmInt.h | 2 +- source/dnode/mgmt/inc/mmInt.h | 2 +- source/dnode/mgmt/inc/qmInt.h | 2 +- source/dnode/mgmt/inc/smInt.h | 2 +- source/dnode/mgmt/inc/vmInt.h | 2 +- source/dnode/mgmt/interface/inc/dndInt.h | 9 ++- .../mgmt/{main => interface/src}/dndFile.c | 12 ++-- source/dnode/mgmt/interface/src/dndInt.c | 10 +-- 16 files changed, 100 insertions(+), 32 deletions(-) create mode 100644 source/dnode/mgmt/implement/inc/dndNode.h rename source/dnode/mgmt/{main => implement/src}/dndEnv.c (98%) rename source/dnode/mgmt/{main => implement/src}/dndExec.c (99%) rename source/dnode/mgmt/{main => implement/src}/dndObj.c (99%) rename source/dnode/mgmt/{main => implement/src}/dndTransport.c (99%) rename source/dnode/mgmt/{main => interface/src}/dndFile.c (95%) diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 40c3f5b1d3..d36a9b8de7 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -6,7 +6,7 @@ aux_source_directory(bm DNODE_SRC) aux_source_directory(sm DNODE_SRC) aux_source_directory(vm DNODE_SRC) aux_source_directory(mm DNODE_SRC) -aux_source_directory(main DNODE_SRC) +aux_source_directory(implement/src DNODE_SRC) add_library(dnode STATIC ${DNODE_SRC}) target_link_libraries( dnode dnode_interface @@ -15,14 +15,15 @@ target_include_directories( dnode PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" ) aux_source_directory(exe EXEC_SRC) add_executable(taosd ${EXEC_SRC}) target_include_directories( taosd - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" ) target_link_libraries(taosd dnode) diff --git a/source/dnode/mgmt/exe/dndMain.c b/source/dnode/mgmt/exe/dndMain.c index 3779f94620..20a73fd893 100644 --- a/source/dnode/mgmt/exe/dndMain.c +++ b/source/dnode/mgmt/exe/dndMain.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" #include "tconfig.h" static struct { @@ -129,14 +129,14 @@ static SDnodeOpt dndGetOpt() { static int32_t dndInitLog() { char logName[12] = {0}; - snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype)); + snprintf(logName, sizeof(logName), "%slog", dndLogName(global.ntype)); return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); } static void dndSetProcInfo(int32_t argc, char **argv) { taosSetProcPath(argc, argv); if (global.ntype != NODE_BEGIN && global.ntype != NODE_END) { - const char *name = dndNodeProcStr(global.ntype); + const char *name = dndProcName(global.ntype); taosSetProcName(argc, argv, name); } } diff --git a/source/dnode/mgmt/implement/inc/dndNode.h b/source/dnode/mgmt/implement/inc/dndNode.h new file mode 100644 index 0000000000..f5d93d2f61 --- /dev/null +++ b/source/dnode/mgmt/implement/inc/dndNode.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_DND_NODE_H_ +#define _TD_DND_NODE_H_ + +#include "dndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t dndOpenNode(SMgmtWrapper *pWrapper); +void dndCloseNode(SMgmtWrapper *pWrapper); + +void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); +SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType nType); +int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); +void dndReleaseWrapper(SMgmtWrapper *pWrapper); +void dndHandleEvent(SDnode *pDnode, EDndEvent event); +void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); + +// dndTransport.c +int32_t dndInitTrans(SDnode *pDnode); +void dndCleanupTrans(SDnode *pDnode); +SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); +SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); +int32_t dndInitMsgHandle(SDnode *pDnode); +void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); + +// mgmt +void dmSetMgmtFp(SMgmtWrapper *pWrapper); +void bmSetMgmtFp(SMgmtWrapper *pWrapper); +void qmSetMgmtFp(SMgmtWrapper *pMgmt); +void smSetMgmtFp(SMgmtWrapper *pWrapper); +void vmSetMgmtFp(SMgmtWrapper *pWrapper); +void mmSetMgmtFp(SMgmtWrapper *pMgmt); + +void dmGetMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); +void dmUpdateMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); +void dmSendRedirectRsp(SDnodeData *pMgmt, const SRpcMsg *pMsg); + +void dmGetMonitorSysInfo(SMonSysInfo *pInfo); +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); +void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); +void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); +void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); +void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_NODE_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/main/dndEnv.c b/source/dnode/mgmt/implement/src/dndEnv.c similarity index 98% rename from source/dnode/mgmt/main/dndEnv.c rename to source/dnode/mgmt/implement/src/dndEnv.c index 9f75594335..a7a3ee8c91 100644 --- a/source/dnode/mgmt/main/dndEnv.c +++ b/source/dnode/mgmt/implement/src/dndEnv.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" #include "wal.h" static int8_t once = DND_ENV_INIT; diff --git a/source/dnode/mgmt/main/dndExec.c b/source/dnode/mgmt/implement/src/dndExec.c similarity index 99% rename from source/dnode/mgmt/main/dndExec.c rename to source/dnode/mgmt/implement/src/dndExec.c index bdc9a2751a..7bdf0f3791 100644 --- a/source/dnode/mgmt/main/dndExec.c +++ b/source/dnode/mgmt/implement/src/dndExec.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" static bool dndRequireNode(SMgmtWrapper *pWrapper) { bool required = false; diff --git a/source/dnode/mgmt/main/dndObj.c b/source/dnode/mgmt/implement/src/dndObj.c similarity index 99% rename from source/dnode/mgmt/main/dndObj.c rename to source/dnode/mgmt/implement/src/dndObj.c index ff2be42722..4300ee0853 100644 --- a/source/dnode/mgmt/main/dndObj.c +++ b/source/dnode/mgmt/implement/src/dndObj.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->data.supportVnodes = pOption->numOfSupportVnodes; diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/implement/src/dndTransport.c similarity index 99% rename from source/dnode/mgmt/main/dndTransport.c rename to source/dnode/mgmt/implement/src/dndTransport.c index c5f195d71e..2d38d6311f 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/implement/src/dndTransport.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" #define INTERNAL_USER "_dnd" #define INTERNAL_CKEY "_key" diff --git a/source/dnode/mgmt/inc/bmInt.h b/source/dnode/mgmt/inc/bmInt.h index 3158fe7d34..627df93b01 100644 --- a/source/dnode/mgmt/inc/bmInt.h +++ b/source/dnode/mgmt/inc/bmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_BNODE_INT_H_ #define _TD_DND_BNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #include "bnode.h" diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/inc/dmInt.h index 4d6ebd63d2..5d787b36b5 100644 --- a/source/dnode/mgmt/inc/dmInt.h +++ b/source/dnode/mgmt/inc/dmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_DNODE_INT_H_ #define _TD_DND_DNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mgmt/inc/mmInt.h b/source/dnode/mgmt/inc/mmInt.h index 74b1cc44bf..4f7c1d9d8c 100644 --- a/source/dnode/mgmt/inc/mmInt.h +++ b/source/dnode/mgmt/inc/mmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_MNODE_INT_H_ #define _TD_DND_MNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #include "mnode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/inc/qmInt.h b/source/dnode/mgmt/inc/qmInt.h index 012869d637..67a00396ea 100644 --- a/source/dnode/mgmt/inc/qmInt.h +++ b/source/dnode/mgmt/inc/qmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_QNODE_INT_H_ #define _TD_DND_QNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #include "qnode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/inc/smInt.h b/source/dnode/mgmt/inc/smInt.h index 039dea2491..56cb954c22 100644 --- a/source/dnode/mgmt/inc/smInt.h +++ b/source/dnode/mgmt/inc/smInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_SNODE_INT_H_ #define _TD_DND_SNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #include "snode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/inc/vmInt.h b/source/dnode/mgmt/inc/vmInt.h index f8466fe4f2..da5ab8387e 100644 --- a/source/dnode/mgmt/inc/vmInt.h +++ b/source/dnode/mgmt/inc/vmInt.h @@ -17,7 +17,7 @@ #define _TD_DND_VNODES_INT_H_ #include "sync.h" -#include "dndInt.h" +#include "dndNode.h" #include "vnode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/interface/inc/dndInt.h b/source/dnode/mgmt/interface/inc/dndInt.h index b08f372daa..1f9d5cd8f4 100644 --- a/source/dnode/mgmt/interface/inc/dndInt.h +++ b/source/dnode/mgmt/interface/inc/dndInt.h @@ -23,11 +23,10 @@ extern "C" { #endif -// dndEnv.c -const char *dndStatStr(EDndRunStatus stat); -const char *dndNodeLogStr(EDndNodeType ntype); -const char *dndNodeProcStr(EDndNodeType ntype); -const char *dndEventStr(EDndEvent ev); +const char *dndStatName(EDndRunStatus stat); +const char *dndLogName(EDndNodeType ntype); +const char *dndProcName(EDndNodeType ntype); +const char *dndEventName(EDndEvent ev); // dndExec.c int32_t dndOpenNode(SMgmtWrapper *pWrapper); diff --git a/source/dnode/mgmt/main/dndFile.c b/source/dnode/mgmt/interface/src/dndFile.c similarity index 95% rename from source/dnode/mgmt/main/dndFile.c rename to source/dnode/mgmt/interface/src/dndFile.c index 45d80543a1..c35d7fbb4a 100644 --- a/source/dnode/mgmt/main/dndFile.c +++ b/source/dnode/mgmt/interface/src/dndFile.c @@ -23,7 +23,7 @@ int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { int64_t len = 0; char content[MAXLEN + 1] = {0}; cJSON *root = NULL; - char file[PATH_MAX]; + char file[PATH_MAX] = {0}; TdFilePtr pFile = NULL; snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); @@ -165,13 +165,13 @@ int32_t dndReadShmFile(SDnode *pDnode) { } for (EDndNodeType ntype = NODE_BEGIN + 1; ntype < NODE_END; ++ntype) { - snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype)); + snprintf(itemName, sizeof(itemName), "%s_shmid", dndProcName(ntype)); cJSON *shmid = cJSON_GetObjectItem(root, itemName); if (shmid && shmid->type == cJSON_Number) { pDnode->wrappers[ntype].procShm.id = shmid->valueint; } - snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype)); + snprintf(itemName, sizeof(itemName), "%s_shmsize", dndProcName(ntype)); cJSON *shmsize = cJSON_GetObjectItem(root, itemName); if (shmsize && shmsize->type == cJSON_Number) { pDnode->wrappers[ntype].procShm.size = shmsize->valueint; @@ -228,11 +228,11 @@ int32_t dndWriteShmFile(SDnode *pDnode) { len += snprintf(content + len, MAXLEN - len, "{\n"); for (EDndNodeType ntype = NODE_BEGIN + 1; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->procShm.id); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndProcName(ntype), pWrapper->procShm.id); if (ntype == NODE_END - 1) { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->procShm.size); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndProcName(ntype), pWrapper->procShm.size); } else { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->procShm.size); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndProcName(ntype), pWrapper->procShm.size); } } len += snprintf(content + len, MAXLEN - len, "}\n"); diff --git a/source/dnode/mgmt/interface/src/dndInt.c b/source/dnode/mgmt/interface/src/dndInt.c index 9ec37b5d04..5e4cd47824 100644 --- a/source/dnode/mgmt/interface/src/dndInt.c +++ b/source/dnode/mgmt/interface/src/dndInt.c @@ -20,12 +20,12 @@ EDndRunStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; } void dndSetStatus(SDnode *pDnode, EDndRunStatus status) { if (pDnode->status != status) { - dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status)); + dDebug("dnode status set from %s to %s", dndStatName(pDnode->status), dndStatName(status)); pDnode->status = status; } } -const char *dndStatStr(EDndRunStatus status) { +const char *dndStatName(EDndRunStatus status) { switch (status) { case DND_STAT_INIT: return "init"; @@ -38,7 +38,7 @@ const char *dndStatStr(EDndRunStatus status) { } } -const char *dndNodeLogStr(EDndNodeType ntype) { +const char *dndLogName(EDndNodeType ntype) { switch (ntype) { case VNODE: return "vnode"; @@ -55,7 +55,7 @@ const char *dndNodeLogStr(EDndNodeType ntype) { } } -const char *dndNodeProcStr(EDndNodeType ntype) { +const char *dndProcName(EDndNodeType ntype) { switch (ntype) { case VNODE: return "taosv"; @@ -72,7 +72,7 @@ const char *dndNodeProcStr(EDndNodeType ntype) { } } -const char *dndEventStr(EDndEvent ev) { +const char *dndEventName(EDndEvent ev) { switch (ev) { case DND_EVENT_START: return "start"; -- GitLab