From 6e523a4706f51aaca8174fc52901cfb2d91f712c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 14 May 2022 22:08:06 +0800 Subject: [PATCH] refactor: multi-process mode --- source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 2 +- source/dnode/mgmt/node_mgmt/inc/dmMgmt.h | 2 -- source/dnode/mgmt/node_mgmt/src/dmMgmt.c | 17 ++++++++++------- source/dnode/mgmt/node_mgmt/src/dmRun.c | 5 ++--- source/dnode/mgmt/node_mgmt/src/dmTransport.c | 14 ++++++++------ 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 297a4b0629..80adacbf5a 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -86,7 +86,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; SRpcMsg rpcRsp = {0}; - dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); + dTrace("send status msg to mnode, app:%p", rpcMsg.ahandle); tmsgSendMnodeRecv(&rpcMsg, &rpcRsp); dmProcessStatusRsp(pMgmt, &rpcRsp); } diff --git a/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h b/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h index 235bb7c16c..a246d92776 100644 --- a/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h +++ b/source/dnode/mgmt/node_mgmt/inc/dmMgmt.h @@ -125,8 +125,6 @@ typedef struct SDnode { SDnodeTrans trans; SUdfdData udfdData; TdThreadMutex mutex; - SRWLatch latch; - SEpSet mnodeEps; TdFilePtr lockfile; SDnodeData data; SMgmtWrapper wrappers[NODE_END]; diff --git a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c index 094dd1efe2..b047e53260 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMgmt.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMgmt.c @@ -32,6 +32,10 @@ static bool dmRequireNode(SMgmtWrapper *pWrapper) { dDebug("node:%s, does not require startup in child process", pWrapper->name); } + if (required) { + dDebug("node:%s, required to startup", pWrapper->name); + } + return required; } @@ -71,8 +75,8 @@ static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { pData->disks = pOption->disks; pData->dataDir = strdup(pOption->dataDir); - if (pData->dataDir == NULL || pData->localEp == NULL || pData->localFqdn == NULL || - pData->firstEp == NULL || pData->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; } @@ -191,10 +195,6 @@ SDnode *dmCreate(const SDnodeOpt *pOption) { goto _OVER; } - if (dmInitClient(pDnode) != 0) { - goto _OVER; - } - if (OnlyInSingleProc(pDnode->ptype) || InParentProc(pDnode->ptype)) { pDnode->lockfile = dmCheckRunning(pOption->dataDir); if (pDnode->lockfile == NULL) { @@ -207,6 +207,10 @@ SDnode *dmCreate(const SDnodeOpt *pOption) { } } + if (dmInitClient(pDnode) != 0) { + goto _OVER; + } + dmReportStartup(pDnode, "dnode-transport", "initialized"); dInfo("dnode is created, data:%p", pDnode); code = 0; @@ -226,7 +230,6 @@ void dmClose(SDnode *pDnode) { dmCleanupClient(pDnode); dmCleanupServer(pDnode); - dmClearVars(pDnode); dInfo("dnode is closed, data:%p", pDnode); } diff --git a/source/dnode/mgmt/node_mgmt/src/dmRun.c b/source/dnode/mgmt/node_mgmt/src/dmRun.c index e4b709ba54..4fdd862652 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmRun.c +++ b/source/dnode/mgmt/node_mgmt/src/dmRun.c @@ -144,9 +144,7 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) { } int32_t dmStartNode(SMgmtWrapper *pWrapper) { - if (!pWrapper->required) return 0; if (OnlyInParentProc(pWrapper->proc.ptype)) return 0; - if (pWrapper->func.startFp != NULL && (*pWrapper->func.startFp)(pWrapper->pMgmt) != 0) { dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); return -1; @@ -201,6 +199,7 @@ static int32_t dmOpenNodes(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; if (!pWrapper->required) continue; if (dmOpenNode(pWrapper) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); return -1; } } @@ -212,7 +211,7 @@ static int32_t dmOpenNodes(SDnode *pDnode) { static int32_t dmStartNodes(SDnode *pDnode) { for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - if (ntype == DNODE && (InChildProc(pDnode->ptype) || !OnlyInTestProc(pDnode->ptype))) continue; + if (!pWrapper->required) continue; if (dmStartNode(pWrapper) != 0) { dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); return -1; diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 37ac3c89a1..e69d1d2417 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -22,21 +22,23 @@ #define INTERNAL_SECRET "_pwd" static void dmGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { - taosRLockLatch(&pDnode->latch); - *pEpSet = pDnode->mnodeEps; - taosRUnLockLatch(&pDnode->latch); + SDnodeData *pData = &pDnode->data; + taosRLockLatch(&pData->latch); + *pEpSet = pData->mnodeEps; + taosRUnLockLatch(&pData->latch); } static void dmSetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); + SDnodeData *pData = &pDnode->data; - taosWLockLatch(&pDnode->latch); - pDnode->mnodeEps = *pEpSet; + taosWLockLatch(&pData->latch); + pData->mnodeEps = *pEpSet; for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); } - taosWUnLockLatch(&pDnode->latch); + taosWUnLockLatch(&pData->latch); } static inline NodeMsgFp dmGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { -- GitLab