From 9f4d41fe14e459317e4901014f27f3c7e95ca9f2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 12 May 2022 16:15:16 +0800 Subject: [PATCH] refactor: node mgmt --- source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 1 - source/dnode/mgmt/mgmt_dnode/src/dmInt.c | 23 +++++------ source/dnode/mgmt/node_mgmt/src/dmExec.c | 4 +- source/dnode/mgmt/node_util/inc/dmUtil.h | 45 +++++++++------------ 4 files changed, 32 insertions(+), 41 deletions(-) diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index ca905d41ea..ea89b672a8 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -88,7 +88,6 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { SMonMloadInfo minfo = {0}; dmGetMnodeLoads(pMgmt, &minfo); - pMgmt->data.isMnode = minfo.isMnode; pMgmt->data.mndState = minfo.load.syncState; int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmInt.c b/source/dnode/mgmt/mgmt_dnode/src/dmInt.c index 1651552fa4..ccb0c5fe8d 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmInt.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmInt.c @@ -45,23 +45,18 @@ static int32_t dmOpenMgmt(const SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) pMgmt->data.updateTime = 0; pMgmt->data.rebootTime = taosGetTimestampMs(); pMgmt->data.dropped = 0; - pMgmt->data.localEp = strdup(pInput->localEp); - pMgmt->data.localFqdn = strdup(pInput->localFqdn); - pMgmt->data.firstEp = strdup(pInput->firstEp); - pMgmt->data.secondEp = strdup(pInput->secondEp); - pMgmt->data.dataDir = strdup(pInput->dataDir); - pMgmt->data.disks = pInput->disks; - pMgmt->data.numOfDisks = pInput->numOfDisks; + pMgmt->data.localEp = pInput->localEp; + pMgmt->data.localFqdn = pInput->localFqdn; + pMgmt->data.firstEp = pInput->firstEp; + pMgmt->data.secondEp = pInput->secondEp; pMgmt->data.supportVnodes = pInput->supportVnodes; pMgmt->data.serverPort = pInput->serverPort; + pMgmt->pDnode = pInput->pDnode; + pMgmt->processCreateNodeFp = pInput->processCreateNodeFp; + pMgmt->processDropNodeFp = pInput->processDropNodeFp; + pMgmt->isNodeDeployedFp = pInput->isNodeDeployedFp; taosInitRWLatch(&pMgmt->data.latch); - if (pMgmt->data.dataDir == NULL || pMgmt->data.localEp == NULL || pMgmt->data.localFqdn == NULL || - pMgmt->data.firstEp == NULL || pMgmt->data.secondEp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - pMgmt->data.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); if (pMgmt->data.dnodeHash == NULL) { dError("failed to init dnode hash"); @@ -87,6 +82,7 @@ static int32_t dmOpenMgmt(const SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) dError("failed to start udfd"); } + pOutput->pMgmt = pMgmt; dInfo("dnode-mgmt is initialized"); return 0; } @@ -110,7 +106,6 @@ static void dmCloseMgmt(SDnodeMgmt *pMgmt) { taosMemoryFreeClear(pMgmt->data.localFqdn); taosMemoryFreeClear(pMgmt->data.firstEp); taosMemoryFreeClear(pMgmt->data.secondEp); - taosMemoryFreeClear(pMgmt->data.dataDir); dInfo("dnode-mgmt is cleaned up"); } diff --git a/source/dnode/mgmt/node_mgmt/src/dmExec.c b/source/dnode/mgmt/node_mgmt/src/dmExec.c index 8837853e12..50d1c8ab46 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmExec.c +++ b/source/dnode/mgmt/node_mgmt/src/dmExec.c @@ -228,7 +228,9 @@ static int32_t dmOpenNodes(SDnode *pDnode) { } else { pWrapper->procType = pDnode->ptype; } - return dmOpenNode(pWrapper); + if (dmOpenNode(pWrapper) != 0) { + return -1; + } } } diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index aaeba61081..fa15d1e898 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -158,31 +158,26 @@ int32_t dmWriteShmFile(const char *path, const char *name, const SShm *pShm); // common define typedef struct { - int32_t dnodeId; - int64_t clusterId; - int64_t dnodeVer; - int64_t updateTime; - int64_t rebootTime; - int32_t unsyncedVgId; - ESyncState vndState; - ESyncState mndState; - bool isMnode; - bool dropped; - SEpSet mnodeEps; - SArray *dnodeEps; - SHashObj *dnodeHash; - SRWLatch latch; - SMsgCb msgCb; - TdFilePtr lockfile; - char *localEp; - char *localFqdn; - char *firstEp; - char *secondEp; - char *dataDir; - SDiskCfg *disks; - int32_t numOfDisks; - int32_t supportVnodes; - uint16_t serverPort; + int32_t dnodeId; + int64_t clusterId; + int64_t dnodeVer; + int64_t updateTime; + int64_t rebootTime; + int32_t unsyncedVgId; + ESyncState vndState; + ESyncState mndState; + bool dropped; + SEpSet mnodeEps; + SArray *dnodeEps; + SHashObj *dnodeHash; + SRWLatch latch; + SMsgCb msgCb; + const char *localEp; + const char *localFqdn; + const char *firstEp; + const char *secondEp; + int32_t supportVnodes; + uint16_t serverPort; } SDnodeData; #ifdef __cplusplus -- GitLab