diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 9f242f73933b2f9c30a7bf9668ca461545d36a54..d421b2e45d1ea0751aa3aaff0b42144ff293e247 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -67,11 +67,11 @@ void mndClose(SMnode *pMnode); int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); /** - * @brief Drop a mnode. + * @brief Start mnode * - * @param path Path of the mnode. + * @param pMnode The mnode object. */ -void mndDestroy(const char *path); +int32_t mndStart(SMnode *pMnode); /** * @brief Get mnode monitor info. diff --git a/source/dnode/mgmt/container/inc/dnd.h b/source/dnode/mgmt/container/inc/dnd.h index 836504e682532f2b822a055de149f8ff197b2589..29c05d6d01e05b2ce5d4d5164ed13e05ba39e773 100644 --- a/source/dnode/mgmt/container/inc/dnd.h +++ b/source/dnode/mgmt/container/inc/dnd.h @@ -69,6 +69,7 @@ typedef struct SBnodeMgmt SBnodeMgmt; typedef int32_t (*NodeMsgFp)(void *pMgmt, SNodeMsg *pMsg); typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper); typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper); +typedef int32_t (*StartNodeFp)(SMgmtWrapper *pWrapper); typedef int32_t (*CreateNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); typedef int32_t (*DropNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); typedef int32_t (*RequireNodeFp)(SMgmtWrapper *pWrapper, bool *required); @@ -95,6 +96,7 @@ typedef struct SMsgHandle { typedef struct SMgmtFp { OpenNodeFp openFp; CloseNodeFp closeFp; + StartNodeFp startFp; CreateNodeFp createMsgFp; DropNodeFp dropMsgFp; RequireNodeFp requiredFp; diff --git a/source/dnode/mgmt/container/src/dndExec.c b/source/dnode/mgmt/container/src/dndExec.c index ed789be56214d0e0c427407b0c28a13d16058aa7..d5c882398ede007bf6b047f2c4c7454b99c5ef73 100644 --- a/source/dnode/mgmt/container/src/dndExec.c +++ b/source/dnode/mgmt/container/src/dndExec.c @@ -84,14 +84,19 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { } } - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, DNODE); - int32_t code = dmStart(pWrapper->pMgmt); - if (code != 0) { - dError("failed to start dnode worker since %s", terrstr()); + dndSetStatus(pDnode, DND_STAT_RUNNING); + + for (ENodeType n = 0; n < NODE_MAX; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (pWrapper->fp.startFp == NULL) continue; + if ((*pWrapper->fp.startFp)(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } } - dndReleaseWrapper(pWrapper); - return code; + return 0; } static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) { @@ -198,6 +203,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { } } +#if 0 SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, DNODE); if (pWrapper->procType == PROC_PARENT && dmStart(pWrapper->pMgmt) != 0) { dndReleaseWrapper(pWrapper); @@ -206,6 +212,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { } dndReleaseWrapper(pWrapper); +#endif return 0; } @@ -222,7 +229,6 @@ int32_t dndRun(SDnode *pDnode) { } } - dndSetStatus(pDnode, DND_STAT_RUNNING); dndReportStartup(pDnode, "TDengine", "initialized successfully"); while (1) { diff --git a/source/dnode/mgmt/container/src/dndTransport.c b/source/dnode/mgmt/container/src/dndTransport.c index a8c816bde9f3f8762444bd79b327f07d88fbccb2..2593a762e8236cd6cda4cbcc6ada40df42f5c2f2 100644 --- a/source/dnode/mgmt/container/src/dndTransport.c +++ b/source/dnode/mgmt/container/src/dndTransport.c @@ -26,8 +26,8 @@ static void dndProcessResponse(void *parent, SRpcMsg *pRsp, SEpSet *pEpSet) { tmsg_t msgType = pRsp->msgType; if (dndGetStatus(pDnode) != DND_STAT_RUNNING) { - if (pRsp == NULL || pRsp->pCont == NULL) return; - dTrace("rsp:%s ignored since dnode exiting, handle:%p app:%p", TMSG_INFO(msgType), pRsp->handle, pRsp->ahandle); + // if (pRsp == NULL || pRsp->pCont == NULL) return; + dTrace("rsp:%s ignored since dnode not running, handle:%p app:%p", TMSG_INFO(msgType), pRsp->handle, pRsp->ahandle); rpcFreeCont(pRsp->pCont); return; } @@ -276,8 +276,13 @@ static int32_t dndSendRpcReq(STransMgmt *pMgmt, SEpSet *pEpSet, SRpcMsg *pReq) { int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, SEpSet *pEpSet, SRpcMsg *pReq) { if (pWrapper->procType == PROC_CHILD) { } else { - STransMgmt *pTrans = &pWrapper->pDnode->trans; - return dndSendRpcReq(pTrans, pEpSet, pReq); + SDnode *pDnode = pWrapper->pDnode; + if (dndGetStatus(pDnode) != DND_STAT_RUNNING) { + terrno = TSDB_CODE_DND_OFFLINE; + dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle); + return -1; + } + return dndSendRpcReq(&pDnode->trans, pEpSet, pReq); } } diff --git a/source/dnode/mgmt/dnode/inc/dm.h b/source/dnode/mgmt/dnode/inc/dm.h index 8228b2df5f86587254f8f97fa06588ace4678ae8..6c18d7969cab87627a0defd4b51e6ebf612b57d8 100644 --- a/source/dnode/mgmt/dnode/inc/dm.h +++ b/source/dnode/mgmt/dnode/inc/dm.h @@ -30,7 +30,6 @@ void dmInitMsgHandles(SMgmtWrapper *pWrapper); void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); void dmSendRedirectRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t dmStart(SDnodeMgmt *pMgmt); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/dnode/inc/dmInt.h b/source/dnode/mgmt/dnode/inc/dmInt.h index 8e67fe363931f6f8366327c99ad90d5be4de7ddd..8429694f6667f0fadabe45f4c3f594d1f8e309ed 100644 --- a/source/dnode/mgmt/dnode/inc/dmInt.h +++ b/source/dnode/mgmt/dnode/inc/dmInt.h @@ -53,6 +53,7 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); // dmWorker.c int32_t dmStartWorker(SDnodeMgmt *pMgmt); void dmStopWorker(SDnodeMgmt *pMgmt); +int32_t dmStartThread(SDnodeMgmt *pMgmt); int32_t dmProcessMgmtMsg(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); #ifdef __cplusplus diff --git a/source/dnode/mgmt/dnode/src/dmInt.c b/source/dnode/mgmt/dnode/src/dmInt.c index 4d4717f039654638d48c0a24fa7fde3328eaddc0..1746cbe6e106a26eb7f8644f399ed8ce0b1b2b65 100644 --- a/source/dnode/mgmt/dnode/src/dmInt.c +++ b/source/dnode/mgmt/dnode/src/dmInt.c @@ -73,7 +73,10 @@ void dmSendRedirectRsp(SDnodeMgmt *pMgmt, SRpcMsg *pReq) { rpcSendRedirectRsp(pReq->handle, &epSet); } -int32_t dmStart(SDnodeMgmt *pMgmt) { return dmStartWorker(pMgmt); } +static int32_t dmStart(SMgmtWrapper *pWrapper) { + dDebug("dnode mgmt start to run"); + return dmStartThread(pWrapper->pMgmt); +} int32_t dmInit(SMgmtWrapper *pWrapper) { SDnode *pDnode = pWrapper->pDnode; @@ -105,6 +108,10 @@ int32_t dmInit(SMgmtWrapper *pWrapper) { return -1; } + if (dmStartWorker(pMgmt) != 0) { + return -1; + } + pWrapper->pMgmt = pMgmt; dInfo("dnode-mgmt is initialized"); return 0; @@ -145,6 +152,7 @@ void dmGetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = dmInit; mgmtFp.closeFp = dmCleanup; + mgmtFp.startFp = dmStart; mgmtFp.requiredFp = dmRequire; dmInitMsgHandles(pWrapper); diff --git a/source/dnode/mgmt/dnode/src/dmWorker.c b/source/dnode/mgmt/dnode/src/dmWorker.c index 1e175e37ffea2b2534eea87016b831d4f6b928fe..f1b2957afb83e2aaa784257ab41e2c6efe75f182 100644 --- a/source/dnode/mgmt/dnode/src/dmWorker.c +++ b/source/dnode/mgmt/dnode/src/dmWorker.c @@ -108,6 +108,10 @@ int32_t dmStartWorker(SDnodeMgmt *pMgmt) { return -1; } + return 0; +} + +int32_t dmStartThread(SDnodeMgmt *pMgmt) { pMgmt->threadId = taosCreateThread(dmThreadRoutine, pMgmt); if (pMgmt->threadId == NULL) { dError("failed to init dnode thread"); diff --git a/source/dnode/mgmt/mnode/src/mmInt.c b/source/dnode/mgmt/mnode/src/mmInt.c index 82ddb7e953a8a2ec1e4baf13d6331182242ea57e..ad9a2dbd759eb50c34289933448b66e22ccdbc52 100644 --- a/source/dnode/mgmt/mnode/src/mmInt.c +++ b/source/dnode/mgmt/mnode/src/mmInt.c @@ -222,10 +222,17 @@ static int32_t mmOpen(SMgmtWrapper *pWrapper) { return mmOpenFromMsg(pWrapper, NULL); } +static int32_t mmStart(SMgmtWrapper *pWrapper) { + dDebug("mnode mgmt start to run"); + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + return mndStart(pMgmt->pMnode); +} + void mmGetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = mmOpen; mgmtFp.closeFp = mmClose; + mgmtFp.startFp = mmStart; mgmtFp.createMsgFp = mmProcessCreateReq; mgmtFp.dropMsgFp = mmProcessDropReq; mgmtFp.requiredFp = mmRequire; diff --git a/source/dnode/mgmt/test/sut/src/sut.cpp b/source/dnode/mgmt/test/sut/src/sut.cpp index 45075c8fe6cb510adf62d218ebaf22a19abc743e..14197153b49bb2552d29409801d35ce40d8090c6 100644 --- a/source/dnode/mgmt/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/test/sut/src/sut.cpp @@ -23,7 +23,7 @@ void Testbase::InitLog(const char* path) { jniDebugFlag = 0; tmrDebugFlag = 135; uDebugFlag = 135; - rpcDebugFlag = 135; + rpcDebugFlag = 143; qDebugFlag = 0; wDebugFlag = 0; sDebugFlag = 0; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 5a41a794a3eae25c507b56a1a260b1bde0143a89..d3b36aed31a39d592310a1d679e86b2f0f180b63 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -928,13 +928,13 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA mDebug("trans:%d, all %d actions execute successfully", pTrans->id, numOfActions); return 0; } else { - mError("trans:%d, all %d actions executed, code:0x%04x", pTrans->id, numOfActions, errCode); + mError("trans:%d, all %d actions executed, code:0x%04x", pTrans->id, numOfActions, errCode & 0XFFFF); mndTransResetActions(pMnode, pTrans, pArray); terrno = errCode; return errCode; } } else { - mDebug("trans:%d, %d of %d actions executed, code:0x%04x", pTrans->id, numOfReceived, numOfActions, errCode); + mDebug("trans:%d, %d of %d actions executed, code:0x%04x", pTrans->id, numOfReceived, numOfActions, errCode & 0XFFFF); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index beb5e024bb1d8155a08bc47a18b3d0bdcd77ce0a..39f2155109f164e3897df5ca2e425d2a2f8de1b2 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -230,7 +230,7 @@ static int32_t mndInitSteps(SMnode *pMnode) { } else { if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1; } - if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1; + // if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1; if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1; if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1; if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1; @@ -379,10 +379,8 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { return 0; } -void mndDestroy(const char *path) { - mDebug("start to destroy mnode at %s", path); - taosRemoveDir(path); - mDebug("mnode is destroyed"); +int32_t mndStart(SMnode *pMnode) { + return mndInitTimer(pMnode); } int32_t mndProcessMsg(SNodeMsg *pMsg) { diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index cea93017f4bbc1dd042d55a46a01561dfebd5881..9ddb3594bb92634895910032a7595b0866f2d427 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -204,6 +204,8 @@ TEST_F(MndTestTrans, 03_Create_Qnode2_Crash) { ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); } + taosMsleep(1000); + { // show trans test.SendShowMetaReq(TSDB_MGMT_TABLE_TRANS, ""); @@ -241,6 +243,7 @@ TEST_F(MndTestTrans, 03_Create_Qnode2_Crash) { EXPECT_EQ(test.GetShowRows(), 0); } + uInfo("======== re-create trans"); // re-create trans { SMCreateQnodeReq createReq = {0}; @@ -255,10 +258,14 @@ TEST_F(MndTestTrans, 03_Create_Qnode2_Crash) { ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); } + uInfo("======== kill and restart server") KillThenRestartServer(); + uInfo("======== server2 start") server2.DoStart(); + uInfo("======== server2 started") + { int32_t retry = 0; int32_t retryMax = 20; diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index 05f756ebb6d01b82d55692a9f9aa06585592990b..8d7dba2de2a456a21e051ffa04acecf17157af25 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -74,7 +74,7 @@ BUILD_DIR=$TAOS_DIR/$BIN_DIR SIM_DIR=$TAOS_DIR/sim NODE_DIR=$SIM_DIR/$NODE_NAME -EXE_DIR=$BUILD_DIR/source/dnode/mgmt/daemon +EXE_DIR=$BUILD_DIR/source/dnode/mgmt/main CFG_DIR=$NODE_DIR/cfg LOG_DIR=$NODE_DIR/log DATA_DIR=$NODE_DIR/data