diff --git a/source/dnode/mgmt/container/inc/dndInt.h b/source/dnode/mgmt/container/inc/dndInt.h index a2cd9261591c3aa88ee93b8809df20bae41622d6..e219a82764a446f3c70ce5e635da0ebd511cd62b 100644 --- a/source/dnode/mgmt/container/inc/dndInt.h +++ b/source/dnode/mgmt/container/inc/dndInt.h @@ -56,7 +56,7 @@ extern "C" { #define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} #define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} -typedef enum { VNODES, QNODE, SNODE, MNODE, BNODE, DNODE, NODE_MAX } ENodeType; +typedef enum { DNODE, VNODES, QNODE, SNODE, MNODE, BNODE, NODE_MAX } ENodeType; typedef enum { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType; typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus; typedef enum { DND_WORKER_SINGLE, DND_WORKER_MULTI } EWorkerType; diff --git a/source/dnode/mgmt/container/src/dndNode.c b/source/dnode/mgmt/container/src/dndNode.c index a64cb4f2b8dbc0bb348545abb58c4320dc9dcdcb..8a807b538d5f7bf3da8792d00c74d52c6479352e 100644 --- a/source/dnode/mgmt/container/src/dndNode.c +++ b/source/dnode/mgmt/container/src/dndNode.c @@ -121,14 +121,6 @@ SDnode *dndCreate(SDndCfg *pCfg) { } pWrapper->procType = PROC_SINGLE; - pWrapper->required = dndRequireNode(pWrapper); - if (pWrapper->required) { - if (taosMkDir(pWrapper->path) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); - goto _OVER; - } - } } code = 0; @@ -172,8 +164,15 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { for (ENodeType n = 0; n < NODE_MAX; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + pWrapper->required = dndRequireNode(pWrapper); if (!pWrapper->required) continue; + if (taosMkDir(pWrapper->path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); + return -1; + } + dInfo("node:%s, will start in single process", pWrapper->name); pWrapper->procType = PROC_SINGLE; if (dndOpenNode(pWrapper) != 0) { @@ -182,6 +181,12 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { } } + SMgmtWrapper *pWrapper = dndGetWrapper(pDnode, DNODE); + if (dmStartWorker(pWrapper->pMgmt) != 0) { + dError("failed to start dnode worker since %s", terrstr()); + return -1; + } + return 0; } @@ -250,8 +255,15 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { for (ENodeType n = 0; n < NODE_MAX; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + pWrapper->required = dndRequireNode(pWrapper); if (!pWrapper->required) continue; + if (taosMkDir(pWrapper->path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); + return -1; + } + if (n == DNODE) { dInfo("node:%s, will start in parent process", pWrapper->name); pWrapper->procType = PROC_SINGLE; @@ -306,6 +318,12 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { } } + SMgmtWrapper *pWrapper = dndGetWrapper(pDnode, DNODE); + if (pWrapper->procType == PROC_PARENT && dmStartWorker(pWrapper->pMgmt) != 0) { + dError("failed to start dnode worker since %s", terrstr()); + return -1; + } + return 0; } @@ -322,6 +340,9 @@ int32_t dndRun(SDnode *pDnode) { } } + dndSetStatus(pDnode, DND_STAT_RUNNING); + dndReportStartup(pDnode, "TDengine", "initialized successfully"); + while (1) { if (pDnode->event == DND_EVENT_STOP) { dInfo("dnode is about to stop"); diff --git a/source/dnode/mgmt/container/src/dndWorker.c b/source/dnode/mgmt/container/src/dndWorker.c index ddef79e65909a0870aeff92a1c1e7fa377e79b05..2c89c2a20a858bba40cd132b86f99aac5350dab8 100644 --- a/source/dnode/mgmt/container/src/dndWorker.c +++ b/source/dnode/mgmt/container/src/dndWorker.c @@ -65,6 +65,8 @@ int32_t dndInitWorker(void *param, SDnodeWorker *pWorker, EWorkerType type, cons } void dndCleanupWorker(SDnodeWorker *pWorker) { + if (pWorker->queue == NULL) return; + while (!taosQueueEmpty(pWorker->queue)) { taosMsleep(10); } diff --git a/source/dnode/mgmt/dnode/inc/dmInt.h b/source/dnode/mgmt/dnode/inc/dmInt.h index 466c1248662cb304fb221f8f302411fa039c002e..78ac2786824614f41ace71441df4f5fb9834f5d2 100644 --- a/source/dnode/mgmt/dnode/inc/dmInt.h +++ b/source/dnode/mgmt/dnode/inc/dmInt.h @@ -51,6 +51,9 @@ void dmUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet); void dmGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); void dmSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg); +// dmWorker.h +int32_t dmStartWorker(SDnodeMgmt *pMgmt); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/dnode/src/dmInt.c b/source/dnode/mgmt/dnode/src/dmInt.c index 23251a2ff22d1cd8a279c9a1c5b1348b53ac14f1..4486d8a19d5fa3ac2c0c1ed35316bd300811f994 100644 --- a/source/dnode/mgmt/dnode/src/dmInt.c +++ b/source/dnode/mgmt/dnode/src/dmInt.c @@ -136,17 +136,8 @@ int32_t dmInit(SMgmtWrapper *pWrapper) { return -1; } - if (dmStartWorker(pMgmt) != 0) { - dError("failed to start dnode worker since %s", terrstr()); - return -1; - } - pWrapper->pMgmt = pMgmt; dInfo("dnode-mgmt is initialized"); - - dndSetStatus(pDnode, DND_STAT_RUNNING); - dmSendStatusReq(pMgmt); - dndReportStartup(pDnode, "TDengine", "initialized successfully"); return 0; } diff --git a/source/dnode/mgmt/mnode/src/mmInt.c b/source/dnode/mgmt/mnode/src/mmInt.c index 6cd5f2c76e53850422efa7822dac03b59d5ec242..04c91b1934de00d129597860a3025429d1040601 100644 --- a/source/dnode/mgmt/mnode/src/mmInt.c +++ b/source/dnode/mgmt/mnode/src/mmInt.c @@ -200,7 +200,7 @@ static void mmCleanup(SMgmtWrapper *pWrapper) { SMnodeMgmt *pMgmt = pWrapper->pMgmt; if (pMgmt == NULL) return; - dInfo("mnode-mgmt start to clean up"); + dInfo("mnode-mgmt start to cleanup"); if (pMgmt->pMnode) { mmStopWorker(pMgmt); mndClose(pMgmt->pMnode); @@ -217,7 +217,7 @@ static int32_t mmInit(SMgmtWrapper *pWrapper) { int32_t code = -1; SMnodeOpt option = {0}; - dInfo("mnode-mgmt is initialized"); + dInfo("mnode-mgmt start to init"); pMgmt->path = pWrapper->path; pMgmt->pDnode = pWrapper->pDnode; pMgmt->pWrapper = pWrapper;