diff --git a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h index 3adcc1206bf7f8f9e5360102e49b90771344178e..dccf5790e437ba8005957275431f28caf2d71cb3 100644 --- a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h +++ b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h @@ -26,24 +26,25 @@ extern "C" { typedef struct SBnodeMgmt { SBnode *pBnode; - SDnode *pDnode; - SMgmtWrapper *pWrapper; + SMsgCb msgCb; const char *path; + const char *name; + int32_t dnodeId; SMultiWorker writeWorker; SSingleWorker monitorWorker; } SBnodeMgmt; // bmHandle.c -void bmInitMsgHandle(SMgmtWrapper *pWrapper); -int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -int32_t bmProcessGetMonBmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); +SArray *bmGetMsgHandles(); +int32_t bmProcessCreateReq(SBnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t bmProcessDropReq(SBnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t bmProcessGetMonBmInfoReq(SBnodeMgmt *pMgmt, SNodeMsg *pReq); // bmWorker.c int32_t bmStartWorker(SBnodeMgmt *pMgmt); void bmStopWorker(SBnodeMgmt *pMgmt); -int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -int32_t bmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t bmPutNodeMsgToWriteQueue(SBnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t bmPutNodeMsgToMonitorQueue(SBnodeMgmt *pMgmt, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c index e9f1617e85daf0c555b688be17351b7291b78a80..0c4b69712922ffecbddaa182cf7572313e1628d9 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c @@ -16,12 +16,12 @@ #define _DEFAULT_SOURCE #include "bmInt.h" -void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo) {} +static void bmGetMonitorInfo(SBnodeMgmt *pMgmt, SMonBmInfo *bmInfo) {} -int32_t bmProcessGetMonBmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { +int32_t bmProcessGetMonBmInfoReq(SBnodeMgmt *pMgmt, SNodeMsg *pReq) { SMonBmInfo bmInfo = {0}; - bmGetMonitorInfo(pWrapper, &bmInfo); - dmGetMonitorSysInfo(&bmInfo.sys); + bmGetMonitorInfo(pMgmt, &bmInfo); + dmGetSystemInfo(&bmInfo.sys); monGetLogs(&bmInfo.log); int32_t rspLen = tSerializeSMonBmInfo(NULL, 0, &bmInfo); @@ -43,8 +43,7 @@ int32_t bmProcessGetMonBmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { return 0; } -int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnode *pDnode = pWrapper->pDnode; +int32_t bmProcessCreateReq(SBnodeMgmt *pMgmt, SNodeMsg *pMsg) { SRpcMsg *pReq = &pMsg->rpcMsg; SDCreateBnodeReq createReq = {0}; @@ -53,14 +52,14 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (pDnode->data.dnodeId != 0 && createReq.dnodeId != pDnode->data.dnodeId) { + if (pMgmt->dnodeId != 0 && createReq.dnodeId != pMgmt->dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->data.dnodeId); + dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pMgmt->dnodeId); return -1; } bool deployed = true; - if (dmWriteFile(pWrapper, deployed) != 0) { + if (dmWriteFile(pMgmt->path, pMgmt->name, deployed) != 0) { dError("failed to write bnode file since %s", terrstr()); return -1; } @@ -68,8 +67,7 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } -int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnode *pDnode = pWrapper->pDnode; +int32_t bmProcessDropReq(SBnodeMgmt *pMgmt, SNodeMsg *pMsg) { SRpcMsg *pReq = &pMsg->rpcMsg; SDDropBnodeReq dropReq = {0}; @@ -78,14 +76,14 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->data.dnodeId) { + if (dropReq.dnodeId != pMgmt->dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop bnode since %s", terrstr()); return -1; } bool deployed = false; - if (dmWriteFile(pWrapper, deployed) != 0) { + if (dmWriteFile(pMgmt->path, pMgmt->name, deployed) != 0) { dError("failed to write bnode file since %s", terrstr()); return -1; } @@ -93,6 +91,19 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } -void bmInitMsgHandle(SMgmtWrapper *pWrapper) { - dmSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, 0); +SArray *bmGetMsgHandles() { + int32_t code = -1; + SArray *pArray = taosArrayInit(2, sizeof(SMgmtHandle)); + if (pArray == NULL) goto _OVER; + + if (dmSetMgmtHandle(pArray, TDMT_MON_BM_INFO, bmPutNodeMsgToMonitorQueue, 0) == NULL) goto _OVER; + + code = 0; +_OVER: + if (code != 0) { + taosArrayDestroy(pArray); + return NULL; + } else { + return pArray; + } } diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c index fe66e25ec9222bfd29ec2c200b1bfa2efae8d0e5..45e0c3219330458420504354c94760f506e5e991 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c @@ -16,18 +16,13 @@ #define _DEFAULT_SOURCE #include "bmInt.h" -static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } - -static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { - SMsgCb msgCb = pMgmt->pDnode->data.msgCb; - msgCb.pWrapper = pMgmt->pWrapper; - pOption->msgCb = msgCb; +static int32_t bmRequire(const SMgmtInputOpt *pInput, bool *required) { + return dmReadFile(pInput->path, pInput->name, required); } -static void bmClose(SMgmtWrapper *pWrapper) { - SBnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; +static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { pOption->msgCb = pMgmt->msgCb; } +static void bmClose(SBnodeMgmt *pMgmt) { dInfo("bnode-mgmt start to cleanup"); if (pMgmt->pBnode != NULL) { bmStopWorker(pMgmt); @@ -35,12 +30,11 @@ static void bmClose(SMgmtWrapper *pWrapper) { pMgmt->pBnode = NULL; } - pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("bnode-mgmt is cleaned up"); } -int32_t bmOpen(SMgmtWrapper *pWrapper) { +int32_t bmOpen(const SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { dInfo("bnode-mgmt start to init"); SBnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SBnodeMgmt)); if (pMgmt == NULL) { @@ -48,40 +42,42 @@ int32_t bmOpen(SMgmtWrapper *pWrapper) { return -1; } - pMgmt->path = pWrapper->path; - pMgmt->pDnode = pWrapper->pDnode; - pMgmt->pWrapper = pWrapper; - pWrapper->pMgmt = pMgmt; + pMgmt->path = pInput->path; + pMgmt->name = pInput->name; + pMgmt->dnodeId = pInput->dnodeId; + pMgmt->msgCb = pInput->msgCb; + pMgmt->msgCb.pMgmt = pMgmt; SBnodeOpt option = {0}; bmInitOption(pMgmt, &option); pMgmt->pBnode = bndOpen(pMgmt->path, &option); if (pMgmt->pBnode == NULL) { dError("failed to open bnode since %s", terrstr()); - bmClose(pWrapper); + bmClose(pMgmt); return -1; } - dmReportStartup(pWrapper->pDnode, "bnode-impl", "initialized"); + tmsgReportStartup("bnode-impl", "initialized"); if (bmStartWorker(pMgmt) != 0) { dError("failed to start bnode worker since %s", terrstr()); - bmClose(pWrapper); + bmClose(pMgmt); return -1; } - dmReportStartup(pWrapper->pDnode, "bnode-worker", "initialized"); + tmsgReportStartup("bnode-worker", "initialized"); + pOutput->pMgmt = pMgmt; + dInfo("bnode-mgmt is initialized"); return 0; } -void bmInitWrapper(SMgmtWrapper *pWrapper) { - SMgmtFp mgmtFp = {0}; - mgmtFp.openFp = bmOpen; - mgmtFp.closeFp = bmClose; - mgmtFp.createFp = bmProcessCreateReq; - mgmtFp.dropFp = bmProcessDropReq; - mgmtFp.requiredFp = bmRequire; +SMgmtFunc bmGetMgmtFunc() { + SMgmtFunc mgmtFunc = {0}; + mgmtFunc.openFp = bmOpen; + mgmtFunc.closeFp = (NodeCloseFp)bmClose; + mgmtFunc.createFp = (NodeCreateFp)bmProcessCreateReq; + mgmtFunc.dropFp = (NodeDropFp)bmProcessDropReq; + mgmtFunc.requiredFp = bmRequire; + mgmtFunc.getHandlesFp = bmGetMsgHandles; - bmInitMsgHandle(pWrapper); - pWrapper->name = "bnode"; - pWrapper->fp = mgmtFp; + return mgmtFunc; } diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c b/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c index d3204039e6769e62d28586da96aa9b1e3adf095a..2d2a89c1817fa0c8cce9df56206e26518821c74a 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c @@ -58,7 +58,7 @@ static void bmProcessMonitorQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { int32_t code = -1; if (pMsg->rpcMsg.msgType == TDMT_MON_BM_INFO) { - code = bmProcessGetMonBmInfoReq(pMgmt->pWrapper, pMsg); + code = bmProcessGetMonBmInfoReq(pMgmt, pMsg); } else { terrno = TSDB_CODE_MSG_NOT_PROCESSED; } @@ -106,8 +106,7 @@ static void bmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO taosArrayDestroy(pArray); } -int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SBnodeMgmt *pMgmt = pWrapper->pMgmt; +int32_t bmPutNodeMsgToWriteQueue(SBnodeMgmt *pMgmt, SNodeMsg *pMsg) { SMultiWorker *pWorker = &pMgmt->writeWorker; dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); @@ -115,8 +114,7 @@ int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } -int32_t bmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SBnodeMgmt *pMgmt = pWrapper->pMgmt; +int32_t bmPutNodeMsgToMonitorQueue(SBnodeMgmt *pMgmt, SNodeMsg *pMsg) { SSingleWorker *pWorker = &pMgmt->monitorWorker; dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name);