From 842611494efa5e780420d80d5f803b220f60b7b8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 14 May 2022 18:59:46 +0800 Subject: [PATCH] refactor: multi process mode --- source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 10 --- source/dnode/mgmt/mgmt_dnode/src/dmInt.c | 31 +------- source/dnode/mgmt/node_mgmt/src/dmMgmt.c | 78 +++++++++++++++------ source/dnode/mgmt/node_util/inc/dmUtil.h | 3 - 4 files changed, 56 insertions(+), 66 deletions(-) diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index ea5587879c..297a4b0629 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -74,19 +74,9 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { SMonVloadInfo vinfo = {0}; dmGetVnodeLoads(pMgmt, &vinfo); req.pVloads = vinfo.pVloads; - pMgmt->pData->unsyncedVgId = 0; - pMgmt->pData->vndState = TAOS_SYNC_STATE_LEADER; - for (int32_t i = 0; i < taosArrayGetSize(req.pVloads); ++i) { - SVnodeLoad *pLoad = taosArrayGet(req.pVloads, i); - if (pLoad->syncState != TAOS_SYNC_STATE_LEADER && pLoad->syncState != TAOS_SYNC_STATE_FOLLOWER) { - pMgmt->pData->unsyncedVgId = pLoad->vgId; - pMgmt->pData->vndState = pLoad->syncState; - } - } SMonMloadInfo minfo = {0}; dmGetMnodeLoads(pMgmt, &minfo); - pMgmt->pData->mndState = minfo.load.syncState; int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); void *pHead = rpcMallocCont(contLen); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmInt.c b/source/dnode/mgmt/mgmt_dnode/src/dmInt.c index 4c1ed1e9ad..1a4a85f76a 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmInt.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmInt.c @@ -41,30 +41,13 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { } pMgmt->pDnode = pInput->pDnode; + pMgmt->pData = pInput->pData; pMgmt->msgCb = pInput->msgCb; pMgmt->path = pInput->path; pMgmt->name = pInput->name; pMgmt->processCreateNodeFp = pInput->processCreateNodeFp; pMgmt->processDropNodeFp = pInput->processDropNodeFp; pMgmt->isNodeRequiredFp = pInput->isNodeRequiredFp; - taosInitRWLatch(&pMgmt->pData->latch); - - pMgmt->pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - if (pMgmt->pData->dnodeHash == NULL) { - dError("failed to init dnode hash"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - if (dmReadEps(pMgmt->pData) != 0) { - dError("failed to read file since %s", terrstr()); - return -1; - } - - if (pMgmt->pData->dropped) { - dError("dnode will not start since its already dropped"); - return -1; - } if (dmStartWorker(pMgmt) != 0) { return -1; @@ -82,19 +65,7 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { static void dmCloseMgmt(SDnodeMgmt *pMgmt) { dInfo("dnode-mgmt start to clean up"); dmStopWorker(pMgmt); - - taosWLockLatch(&pMgmt->pData->latch); - if (pMgmt->pData->dnodeEps != NULL) { - taosArrayDestroy(pMgmt->pData->dnodeEps); - pMgmt->pData->dnodeEps = NULL; - } - if (pMgmt->pData->dnodeHash != NULL) { - taosHashCleanup(pMgmt->pData->dnodeHash); - pMgmt->pData->dnodeHash = NULL; - } - taosWUnLockLatch(&pMgmt->pData->latch); taosMemoryFree(pMgmt); - dInfo("dnode-mgmt is cleaned up"); } diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index cc45173324..094dd1efe2 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -53,28 +53,48 @@ static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { dInfo("dnode will run in child-process mode, node:%s", pWrapper->name); } - pDnode->data.dnodeId = 0; - pDnode->data.clusterId = 0; - pDnode->data.dnodeVer = 0; - pDnode->data.updateTime = 0; - pDnode->data.rebootTime = taosGetTimestampMs(); - pDnode->data.dropped = 0; - pDnode->data.localEp = strdup(pOption->localEp); - pDnode->data.localFqdn = strdup(pOption->localFqdn); - pDnode->data.firstEp = strdup(pOption->firstEp); - pDnode->data.secondEp = strdup(pOption->secondEp); - pDnode->data.serverPort = pOption->serverPort; - pDnode->data.supportVnodes = pOption->numOfSupportVnodes; - pDnode->data.numOfDisks = pOption->numOfDisks; - pDnode->data.disks = pOption->disks; - pDnode->data.dataDir = strdup(pOption->dataDir); + SDnodeData *pData = &pDnode->data; + pData->dnodeId = 0; + pData->clusterId = 0; + pData->dnodeVer = 0; + pData->updateTime = 0; + pData->rebootTime = taosGetTimestampMs(); + pData->dropped = 0; + pData->stopped = 0; + pData->localEp = strdup(pOption->localEp); + pData->localFqdn = strdup(pOption->localFqdn); + pData->firstEp = strdup(pOption->firstEp); + pData->secondEp = strdup(pOption->secondEp); + pData->supportVnodes = pOption->numOfSupportVnodes; + pData->serverPort = pOption->serverPort; + pData->numOfDisks = pOption->numOfDisks; + pData->disks = pOption->disks; + pData->dataDir = strdup(pOption->dataDir); - if (pDnode->data.dataDir == NULL || pDnode->data.localEp == NULL || pDnode->data.localFqdn == NULL || - pDnode->data.firstEp == NULL || pDnode->data.secondEp == NULL) { + if (pData->dataDir == NULL || pData->localEp == NULL || pData->localFqdn == NULL || + pData->firstEp == NULL || pData->secondEp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + if (pData->dnodeHash == NULL) { + dError("failed to init dnode hash"); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (dmReadEps(pData) != 0) { + dError("failed to read file since %s", terrstr()); + return -1; + } + + if (pData->dropped) { + dError("dnode will not start since its already dropped"); + return -1; + } + + taosInitRWLatch(&pData->latch); taosThreadMutexInit(&pDnode->mutex, NULL); return 0; } @@ -90,11 +110,23 @@ static void dmClearVars(SDnode *pDnode) { pDnode->lockfile = NULL; } - taosMemoryFreeClear(pDnode->data.localEp); - taosMemoryFreeClear(pDnode->data.localFqdn); - taosMemoryFreeClear(pDnode->data.firstEp); - taosMemoryFreeClear(pDnode->data.secondEp); - taosMemoryFreeClear(pDnode->data.dataDir); + SDnodeData *pData = &pDnode->data; + taosWLockLatch(&pData->latch); + if (pData->dnodeEps != NULL) { + taosArrayDestroy(pData->dnodeEps); + pData->dnodeEps = NULL; + } + if (pData->dnodeHash != NULL) { + taosHashCleanup(pData->dnodeHash); + pData->dnodeHash = NULL; + } + taosWUnLockLatch(&pData->latch); + + taosMemoryFreeClear(pData->localEp); + taosMemoryFreeClear(pData->localFqdn); + taosMemoryFreeClear(pData->firstEp); + taosMemoryFreeClear(pData->secondEp); + taosMemoryFreeClear(pData->dataDir); taosThreadMutexDestroy(&pDnode->mutex); memset(&pDnode->mutex, 0, sizeof(pDnode->mutex)); @@ -163,7 +195,7 @@ SDnode *dmCreate(const SDnodeOpt *pOption) { goto _OVER; } - if (OnlyInSingleProc(pDnode->ptype) && InParentProc(pDnode->ptype)) { + if (OnlyInSingleProc(pDnode->ptype) || InParentProc(pDnode->ptype)) { pDnode->lockfile = dmCheckRunning(pOption->dataDir); if (pDnode->lockfile == NULL) { goto _OVER; diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index 2d997b3ad7..3fbc6ad287 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -90,9 +90,6 @@ typedef struct { int64_t dnodeVer; int64_t updateTime; int64_t rebootTime; - int32_t unsyncedVgId; - ESyncState vndState; - ESyncState mndState; bool dropped; bool stopped; SEpSet mnodeEps;