From 2623202c3852a46b56caba4eb0db3d1705b478c4 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 12 May 2022 09:54:13 +0800 Subject: [PATCH] refactor: node mgmt --- source/dnode/mgmt/mgmt_dnode/src/dmInt.c | 29 +++++++++++++ source/dnode/mgmt/node_util/inc/dmUtil.h | 52 ++++++++++++------------ source/dnode/mgmt/node_util/src/dmUtil.c | 1 - 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmInt.c b/source/dnode/mgmt/mgmt_dnode/src/dmInt.c index 7d927f9fab..1651552fa4 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmInt.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmInt.c @@ -39,6 +39,29 @@ static int32_t dmOpenMgmt(const SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) return -1; } + pMgmt->data.dnodeId = 0; + pMgmt->data.clusterId = 0; + pMgmt->data.dnodeVer = 0; + 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.supportVnodes = pInput->supportVnodes; + pMgmt->data.serverPort = pInput->serverPort; + 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"); @@ -83,6 +106,12 @@ static void dmCloseMgmt(SDnodeMgmt *pMgmt) { } taosWUnLockLatch(&pMgmt->data.latch); + taosMemoryFreeClear(pMgmt->data.localEp); + 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_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index 0a612c6d82..58d22976d3 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -93,6 +93,7 @@ typedef struct { int64_t clusterId; const char *localEp; const char *firstEp; + const char *secondEp; const char *localFqdn; uint16_t serverPort; int32_t supportVnodes; @@ -156,32 +157,31 @@ 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; - EDndRunStatus status; + 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; } SDnodeData; #ifdef __cplusplus diff --git a/source/dnode/mgmt/node_util/src/dmUtil.c b/source/dnode/mgmt/node_util/src/dmUtil.c index d56346ce67..e913af203b 100644 --- a/source/dnode/mgmt/node_util/src/dmUtil.c +++ b/source/dnode/mgmt/node_util/src/dmUtil.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "dmUtil.h" - const char *dmStatStr(EDndRunStatus stype) { switch (stype) { case DND_STAT_INIT: -- GitLab