From 139a4c7fb1e8f403f6e40df0f4e2bdab757c9346 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 29 Oct 2021 17:11:15 +0800 Subject: [PATCH 01/17] adjust tqueue codes --- include/util/tqueue.h | 21 +-- include/util/tworker.h | 54 +++---- source/server/mnode/src/mnodeWorker.c | 116 +++++++++------- source/server/vnode/inc/vnodeWrite.h | 7 +- source/server/vnode/src/vnodeInt.c | 20 +-- source/server/vnode/src/vnodeMgmt.c | 24 ++-- source/server/vnode/src/vnodeRead.c | 42 +++--- source/server/vnode/src/vnodeWrite.c | 193 ++++++++++++-------------- source/util/src/tqueue.c | 168 +++++++++++----------- source/util/src/tworker.c | 64 ++++----- 10 files changed, 339 insertions(+), 370 deletions(-) diff --git a/include/util/tqueue.h b/include/util/tqueue.h index cd897435fa..dc16222c2b 100644 --- a/include/util/tqueue.h +++ b/include/util/tqueue.h @@ -37,21 +37,24 @@ shall be used to set up the protection. */ -typedef void* taos_queue; -typedef void* taos_qset; -typedef void* taos_qall; +typedef void *taos_queue; +typedef void *taos_qset; +typedef void *taos_qall; +typedef void *(*FProcessOneItem)(void *pItem, void *ahandle); +typedef void *(*FProcessAllItem)(taos_qall qall, int numOfItems, void *ahandle); taos_queue taosOpenQueue(); void taosCloseQueue(taos_queue); +void taosSetQueueFp(taos_queue, FProcessOneItem, FProcessAllItem fp); void *taosAllocateQitem(int size); -void taosFreeQitem(void *item); -int taosWriteQitem(taos_queue, int type, void *item); -int taosReadQitem(taos_queue, int *type, void **pitem); +void taosFreeQitem(void *pItem); +int taosWriteQitem(taos_queue, void *pItem); +int taosReadQitem(taos_queue, void **pItem); taos_qall taosAllocateQall(); void taosFreeQall(taos_qall); int taosReadAllQitems(taos_queue, taos_qall); -int taosGetQitem(taos_qall, int *type, void **pitem); +int taosGetQitem(taos_qall, void **pItem); void taosResetQitems(taos_qall); taos_qset taosOpenQset(); @@ -61,8 +64,8 @@ int taosAddIntoQset(taos_qset, taos_queue, void *ahandle); void taosRemoveFromQset(taos_qset, taos_queue); int taosGetQueueNumber(taos_qset); -int taosReadQitemFromQset(taos_qset, int *type, void **pitem, void **handle); -int taosReadAllQitemsFromQset(taos_qset, taos_qall, void **handle); +int taosReadQitemFromQset(taos_qset, void **pItem, void **ahandle, FProcessOneItem *); +int taosReadAllQitemsFromQset(taos_qset, taos_qall, void **ahandle, FProcessAllItem *); int taosGetQueueItemsNumber(taos_queue param); int taosGetQsetItemsNumber(taos_qset param); diff --git a/include/util/tworker.h b/include/util/tworker.h index 47ad0bd9e7..591ebf8967 100644 --- a/include/util/tworker.h +++ b/include/util/tworker.h @@ -22,13 +22,6 @@ extern "C" { #endif -typedef int32_t (*ProcessStartFp)(void *ahandle, void *pMsg, int32_t qtype); -typedef void (*ProcessEndFp)(void *ahandle, void *pMsg, int32_t qtype, int32_t code); - -typedef bool (*ProcessWriteStartFp)(void *ahandle, void *pMsg, int32_t qtype); -typedef void (*ProcessWriteSyncFp)(void *ahandle, int32_t code); -typedef void (*ProcessWriteEndFp)(void *ahandle, void *pMsg, int32_t qtype); - typedef struct SWorker { int32_t id; // worker ID pthread_t thread; // thread @@ -40,41 +33,36 @@ typedef struct SWorkerPool { int32_t min; // min number of workers int32_t num; // current number of workers taos_qset qset; - const char * name; - ProcessStartFp startFp; - ProcessEndFp endFp; - SWorker * workers; + const char *name; + SWorker *workers; pthread_mutex_t mutex; } SWorkerPool; -typedef struct SWriteWorker { - int32_t id; // worker id - pthread_t thread; // thread - taos_qall qall; - taos_qset qset; // queue set - struct SWriteWorkerPool *pool; -} SWriteWorker; +typedef struct SMWorker { + int32_t id; // worker id + pthread_t thread; // thread + taos_qall qall; + taos_qset qset; // queue set + struct SMWorkerPool *pool; +} SMWorker; -typedef struct SWriteWorkerPool { - int32_t max; // max number of workers - int32_t nextId; // from 0 to max-1, cyclic - const char * name; - ProcessWriteStartFp startFp; - ProcessWriteSyncFp syncFp; - ProcessWriteEndFp endFp; - SWriteWorker * workers; - pthread_mutex_t mutex; -} SWriteWorkerPool; +typedef struct SMWorkerPool { + int32_t max; // max number of workers + int32_t nextId; // from 0 to max-1, cyclic + const char *name; + SMWorker *workers; + pthread_mutex_t mutex; +} SMWorkerPool; int32_t tWorkerInit(SWorkerPool *pool); void tWorkerCleanup(SWorkerPool *pool); -taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle); +taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessOneItem fp); void tWorkerFreeQueue(SWorkerPool *pool, taos_queue queue); -int32_t tWriteWorkerInit(SWriteWorkerPool *pool); -void tWriteWorkerCleanup(SWriteWorkerPool *pool); -taos_queue tWriteWorkerAllocQueue(SWriteWorkerPool *pool, void *ahandle); -void tWriteWorkerFreeQueue(SWriteWorkerPool *pool, taos_queue queue); +int32_t tMWorkerInit(SMWorkerPool *pool); +void tMWorkerCleanup(SMWorkerPool *pool); +taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessAllItem fp); +void tMWorkerFreeQueue(SMWorkerPool *pool, taos_queue queue); #ifdef __cplusplus } diff --git a/source/server/mnode/src/mnodeWorker.c b/source/server/mnode/src/mnodeWorker.c index 84beddb2da..fc370538aa 100644 --- a/source/server/mnode/src/mnodeWorker.c +++ b/source/server/mnode/src/mnodeWorker.c @@ -28,10 +28,10 @@ static struct { SWorkerPool write; SWorkerPool peerReq; SWorkerPool peerRsp; - taos_queue readQ; - taos_queue writeQ; - taos_queue peerReqQ; - taos_queue peerRspQ; + taos_queue readQ; + taos_queue writeQ; + taos_queue peerReqQ; + taos_queue peerRspQ; int32_t (*writeMsgFp[TSDB_MSG_TYPE_MAX])(SMnMsg *); int32_t (*readMsgFp[TSDB_MSG_TYPE_MAX])(SMnMsg *); int32_t (*peerReqFp[TSDB_MSG_TYPE_MAX])(SMnMsg *); @@ -81,7 +81,7 @@ static void mnodeDispatchToWriteQueue(SRpcMsg *pRpcMsg) { rpcSendResponse(&rpcRsp); } else { mTrace("msg:%p, app:%p type:%s is put into wqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - taosWriteQitem(tsMworker.writeQ, TAOS_QTYPE_RPC, pMsg); + taosWriteQitem(tsMworker.writeQ, pMsg); } } @@ -93,7 +93,7 @@ void mnodeReDispatchToWriteQueue(SMnMsg *pMsg) { mnodeSendRedirectMsg(&pMsg->rpcMsg, true); mnodeCleanupMsg(pMsg); } else { - taosWriteQitem(tsMworker.writeQ, TAOS_QTYPE_RPC, pMsg); + taosWriteQitem(tsMworker.writeQ, pMsg); } } @@ -107,7 +107,7 @@ static void mnodeDispatchToReadQueue(SRpcMsg *pRpcMsg) { rpcSendResponse(&rpcRsp); } else { mTrace("msg:%p, app:%p type:%s is put into rqueue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - taosWriteQitem(tsMworker.readQ, TAOS_QTYPE_RPC, pMsg); + taosWriteQitem(tsMworker.readQ, pMsg); } } @@ -125,7 +125,7 @@ static void mnodeDispatchToPeerQueue(SRpcMsg *pRpcMsg) { } else { mTrace("msg:%p, app:%p type:%s is put into peer req queue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - taosWriteQitem(tsMworker.peerReqQ, TAOS_QTYPE_RPC, pMsg); + taosWriteQitem(tsMworker.peerReqQ, pMsg); } } @@ -140,13 +140,13 @@ void mnodeDispatchToPeerRspQueue(SRpcMsg *pRpcMsg) { } else { mTrace("msg:%p, app:%p type:%s is put into peer rsp queue", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType]); - taosWriteQitem(tsMworker.peerRspQ, TAOS_QTYPE_RPC, pMsg); + taosWriteQitem(tsMworker.peerRspQ, pMsg); } // rpcFreeCont(pRpcMsg->pCont); } -static void mnodeSendRpcRsp(void *ahandle, SMnMsg *pMsg, int32_t qtype, int32_t code) { +void mnodeSendRsp(SMnMsg *pMsg, int32_t code) { if (pMsg == NULL) return; if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return; if (code == TSDB_CODE_MND_ACTION_NEED_REPROCESSED) { @@ -155,22 +155,16 @@ static void mnodeSendRpcRsp(void *ahandle, SMnMsg *pMsg, int32_t qtype, int32_t } SRpcMsg rpcRsp = { - .handle = pMsg->rpcMsg.handle, - .pCont = pMsg->rpcRsp.rsp, - .contLen = pMsg->rpcRsp.len, - .code = code, + .handle = pMsg->rpcMsg.handle, + .pCont = pMsg->rpcRsp.rsp, + .contLen = pMsg->rpcRsp.len, + .code = code, }; rpcSendResponse(&rpcRsp); mnodeCleanupMsg(pMsg); } -void mnodeSendRsp(SMnMsg *pMsg, int32_t code) { mnodeSendRpcRsp(NULL, pMsg, 0, code); } - -static void mnodeProcessPeerRspEnd(void *ahandle, SMnMsg *pMsg, int32_t qtype, int32_t code) { - mnodeCleanupMsg(pMsg); -} - static void mnodeInitMsgFp() { // // peer req // tsMworker.msgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE] = mnodeDispatchToPeerQueue; @@ -290,13 +284,15 @@ static void mnodeInitMsgFp() { // tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = mnodeProcessKillConnectionMsg; } -static int32_t mnodeProcessWriteReq(void *unused, SMnMsg *pMsg, int32_t qtype) { +static void mnodeProcessWriteReq(SMnMsg *pMsg, void *unused) { int32_t msgType = pMsg->rpcMsg.msgType; - void *ahandle = pMsg->rpcMsg.ahandle; + void *ahandle = pMsg->rpcMsg.ahandle; + int32_t code = 0; if (pMsg->rpcMsg.pCont == NULL) { mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]); - return TSDB_CODE_MND_INVALID_MSG_LEN; + code = TSDB_CODE_MND_INVALID_MSG_LEN; + goto PROCESS_WRITE_REQ_END; } if (!mnodeIsMaster()) { @@ -309,31 +305,39 @@ static int32_t mnodeProcessWriteReq(void *unused, SMnMsg *pMsg, int32_t qtype) { mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType], epSet->numOfEps, epSet->inUse); - return TSDB_CODE_RPC_REDIRECT; + code = TSDB_CODE_RPC_REDIRECT; + goto PROCESS_WRITE_REQ_END; } if (tsMworker.writeMsgFp[msgType] == NULL) { mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]); - return TSDB_CODE_MND_MSG_NOT_PROCESSED; + code = TSDB_CODE_MND_MSG_NOT_PROCESSED; + goto PROCESS_WRITE_REQ_END; } - return (*tsMworker.writeMsgFp[msgType])(pMsg); + code = (*tsMworker.writeMsgFp[msgType])(pMsg); + +PROCESS_WRITE_REQ_END: + mnodeSendRsp(pMsg, code); } -static int32_t mnodeProcessReadReq(void* unused, SMnMsg *pMsg, int32_t qtype) { +static void mnodeProcessReadReq(SMnMsg *pMsg, void *unused) { int32_t msgType = pMsg->rpcMsg.msgType; - void *ahandle = pMsg->rpcMsg.ahandle; + void *ahandle = pMsg->rpcMsg.ahandle; + int32_t code = 0; if (pMsg->rpcMsg.pCont == NULL) { mError("msg:%p, app:%p type:%s in mread queue, content is null", pMsg, ahandle, taosMsg[msgType]); - return TSDB_CODE_MND_INVALID_MSG_LEN; + code = TSDB_CODE_MND_INVALID_MSG_LEN; + goto PROCESS_READ_REQ_END; } if (!mnodeIsMaster()) { SMnRsp *rpcRsp = &pMsg->rpcRsp; SRpcEpSet *epSet = rpcMallocCont(sizeof(SRpcEpSet)); if (!epSet) { - return TSDB_CODE_MND_OUT_OF_MEMORY; + code = TSDB_CODE_MND_OUT_OF_MEMORY; + goto PROCESS_READ_REQ_END; } mnodeGetMnodeEpSetForShell(epSet, true); rpcRsp->rsp = epSet; @@ -341,25 +345,32 @@ static int32_t mnodeProcessReadReq(void* unused, SMnMsg *pMsg, int32_t qtype) { mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType], epSet->numOfEps, epSet->inUse); - return TSDB_CODE_RPC_REDIRECT; + code = TSDB_CODE_RPC_REDIRECT; + goto PROCESS_READ_REQ_END; } if (tsMworker.readMsgFp[msgType] == NULL) { mError("msg:%p, app:%p type:%s in mread queue, not processed", pMsg, ahandle, taosMsg[msgType]); - return TSDB_CODE_MND_MSG_NOT_PROCESSED; + code = TSDB_CODE_MND_MSG_NOT_PROCESSED; + goto PROCESS_READ_REQ_END; } mTrace("msg:%p, app:%p type:%s will be processed in mread queue", pMsg, ahandle, taosMsg[msgType]); - return (*tsMworker.readMsgFp[msgType])(pMsg); + code = (*tsMworker.readMsgFp[msgType])(pMsg); + +PROCESS_READ_REQ_END: + mnodeSendRsp(pMsg, code); } -static int32_t mnodeProcessPeerReq(void *unused, SMnMsg *pMsg, int32_t qtype) { +static void mnodeProcessPeerReq(SMnMsg *pMsg, void *unused) { int32_t msgType = pMsg->rpcMsg.msgType; - void * ahandle = pMsg->rpcMsg.ahandle; + void *ahandle = pMsg->rpcMsg.ahandle; + int32_t code = 0; if (pMsg->rpcMsg.pCont == NULL) { mError("msg:%p, ahandle:%p type:%s in mpeer queue, content is null", pMsg, ahandle, taosMsg[msgType]); - return TSDB_CODE_MND_INVALID_MSG_LEN; + code = TSDB_CODE_MND_INVALID_MSG_LEN; + goto PROCESS_PEER_REQ_END; } if (!mnodeIsMaster()) { @@ -372,24 +383,29 @@ static int32_t mnodeProcessPeerReq(void *unused, SMnMsg *pMsg, int32_t qtype) { mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType], epSet->numOfEps, epSet->inUse); - return TSDB_CODE_RPC_REDIRECT; + code = TSDB_CODE_RPC_REDIRECT; + goto PROCESS_PEER_REQ_END; } if (tsMworker.peerReqFp[msgType] == NULL) { mError("msg:%p, ahandle:%p type:%s in mpeer queue, not processed", pMsg, ahandle, taosMsg[msgType]); - return TSDB_CODE_MND_MSG_NOT_PROCESSED; + code = TSDB_CODE_MND_MSG_NOT_PROCESSED; + goto PROCESS_PEER_REQ_END; } - return (*tsMworker.peerReqFp[msgType])(pMsg); + code = (*tsMworker.peerReqFp[msgType])(pMsg); + +PROCESS_PEER_REQ_END: + mnodeSendRsp(pMsg, code); } -static int32_t mnodeProcessPeerRsp(void *ahandle, SMnMsg *pMsg, int32_t qtype) { +static void mnodeProcessPeerRsp(SMnMsg *pMsg, void *unused) { int32_t msgType = pMsg->rpcMsg.msgType; SRpcMsg *pRpcMsg = &pMsg->rpcMsg; if (!mnodeIsMaster()) { mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]); - return 0; + mnodeCleanupMsg(pMsg); } if (tsMworker.peerRspFp[msgType]) { @@ -398,7 +414,7 @@ static int32_t mnodeProcessPeerRsp(void *ahandle, SMnMsg *pMsg, int32_t qtype) { mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]); } - return 0; + mnodeCleanupMsg(pMsg); } int32_t mnodeInitWorker() { @@ -406,20 +422,16 @@ int32_t mnodeInitWorker() { SWorkerPool *pPool = &tsMworker.write; pPool->name = "mnode-write"; - pPool->startFp = (ProcessStartFp)mnodeProcessWriteReq; - pPool->endFp = (ProcessEndFp)mnodeSendRpcRsp; pPool->min = 1; pPool->max = 1; if (tWorkerInit(pPool) != 0) { return TSDB_CODE_MND_OUT_OF_MEMORY; } else { - tsMworker.writeQ = tWorkerAllocQueue(pPool, NULL); + tsMworker.writeQ = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)mnodeProcessWriteReq); } pPool = &tsMworker.read; pPool->name = "mnode-read"; - pPool->startFp = (ProcessStartFp)mnodeProcessReadReq; - pPool->endFp = (ProcessEndFp)mnodeSendRpcRsp; pPool->min = 2; pPool->max = (int32_t)(tsNumOfCores * tsNumOfThreadsPerCore / 2); pPool->max = MAX(2, pPool->max); @@ -427,31 +439,27 @@ int32_t mnodeInitWorker() { if (tWorkerInit(pPool) != 0) { return TSDB_CODE_MND_OUT_OF_MEMORY; } else { - tsMworker.readQ = tWorkerAllocQueue(pPool, NULL); + tsMworker.readQ = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)mnodeProcessReadReq); } pPool = &tsMworker.peerReq; pPool->name = "mnode-peer-req"; - pPool->startFp = (ProcessStartFp)mnodeProcessPeerReq; - pPool->endFp = (ProcessEndFp)mnodeSendRpcRsp; pPool->min = 1; pPool->max = 1; if (tWorkerInit(pPool) != 0) { return TSDB_CODE_MND_OUT_OF_MEMORY; } else { - tsMworker.peerReqQ = tWorkerAllocQueue(pPool, NULL); + tsMworker.peerReqQ = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)mnodeProcessPeerReq); } pPool = &tsMworker.peerRsp; pPool->name = "mnode-peer-rsp"; - pPool->startFp = (ProcessStartFp)mnodeProcessPeerRsp; - pPool->endFp = (ProcessEndFp)mnodeProcessPeerRspEnd; pPool->min = 1; pPool->max = 1; if (tWorkerInit(pPool) != 0) { return TSDB_CODE_MND_OUT_OF_MEMORY; } else { - tsMworker.peerRspQ = tWorkerAllocQueue(pPool, NULL); + tsMworker.peerRspQ = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)mnodeProcessPeerRsp); } mInfo("mnode worker is initialized"); diff --git a/source/server/vnode/inc/vnodeWrite.h b/source/server/vnode/inc/vnodeWrite.h index 0bb670de5b..8500607694 100644 --- a/source/server/vnode/inc/vnodeWrite.h +++ b/source/server/vnode/inc/vnodeWrite.h @@ -23,11 +23,12 @@ extern "C" { int32_t vnodeInitWrite(); void vnodeCleanupWrite(); + taos_queue vnodeAllocWriteQueue(SVnode *pVnode); void vnodeFreeWriteQueue(taos_queue pQueue); - -void vnodeProcessWriteMsg(SRpcMsg *pRpcMsg); -int32_t vnodeProcessWalMsg(SVnode *pVnode, SWalHead *pHead); +taos_queue vnodeAllocApplyQueue(SVnode *pVnode); +void vnodeFreeApplyQueue(taos_queue pQueue); +void vnodeProcessWriteReq(SRpcMsg *pRpcMsg); void vnodeStartWrite(SVnode *pVnode); void vnodeStopWrite(SVnode *pVnode); diff --git a/source/server/vnode/src/vnodeInt.c b/source/server/vnode/src/vnodeInt.c index 9e1739a68e..4061c04d94 100644 --- a/source/server/vnode/src/vnodeInt.c +++ b/source/server/vnode/src/vnodeInt.c @@ -54,17 +54,17 @@ static void vnodeInitMsgFp() { tsVint.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMgmtMsg; tsVint.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMgmtMsg; tsVint.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMgmtMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE] = vnodeProcessWriteMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_DROP_TABLE] = vnodeProcessWriteMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE] = vnodeProcessWriteMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = vnodeProcessWriteMsg; - tsVint.msgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessWriteMsg; - tsVint.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessWriteMsg; + tsVint.msgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE] = vnodeProcessWriteReq; + tsVint.msgFp[TSDB_MSG_TYPE_MD_DROP_TABLE] = vnodeProcessWriteReq; + tsVint.msgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE] = vnodeProcessWriteReq; + tsVint.msgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = vnodeProcessWriteReq; + tsVint.msgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessWriteReq; + tsVint.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessWriteReq; // mq related - tsVint.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessWriteMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessWriteMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessWriteMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessWriteMsg; + tsVint.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessWriteReq; + tsVint.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessWriteReq; + tsVint.msgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessWriteReq; + tsVint.msgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessWriteReq; tsVint.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessReadMsg; tsVint.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessReadMsg; // mq related end diff --git a/source/server/vnode/src/vnodeMgmt.c b/source/server/vnode/src/vnodeMgmt.c index e0e76d5b56..dfb3c95b8d 100644 --- a/source/server/vnode/src/vnodeMgmt.c +++ b/source/server/vnode/src/vnodeMgmt.c @@ -194,22 +194,18 @@ static int32_t vnodeProcessAlterStreamReq(SRpcMsg *pMsg) { return TSDB_CODE_VND_MSG_NOT_PROCESSED; } -static int32_t vnodeProcessMgmtStart(void *unused, SVnMgmtMsg *pMgmt, int32_t qtype) { +static void vnodeProcessMgmtReq(SVnMgmtMsg *pMgmt, void *unused) { SRpcMsg *pMsg = &pMgmt->rpcMsg; int32_t msgType = pMsg->msgType; + int32_t code = 0; if (tsVmgmt.msgFp[msgType]) { vTrace("msg:%p, ahandle:%p type:%s will be processed", pMgmt, pMsg->ahandle, taosMsg[msgType]); - return (*tsVmgmt.msgFp[msgType])(pMsg); + code = (*tsVmgmt.msgFp[msgType])(pMsg); } else { vError("msg:%p, ahandle:%p type:%s not processed since no handle", pMgmt, pMsg->ahandle, taosMsg[msgType]); - return TSDB_CODE_DND_MSG_NOT_PROCESSED; + code = TSDB_CODE_DND_MSG_NOT_PROCESSED; } -} - -static void vnodeProcessMgmtEnd(void *unused, SVnMgmtMsg *pMgmt, int32_t qtype, int32_t code) { - SRpcMsg *pMsg = &pMgmt->rpcMsg; - vTrace("msg:%p, is processed, result:%s", pMgmt, tstrerror(code)); SRpcMsg rsp = {.code = code, .handle = pMsg->handle}; rpcSendResponse(&rsp); @@ -235,9 +231,9 @@ static int32_t vnodeWriteToMgmtQueue(SRpcMsg *pMsg) { memcpy(pMgmt->pCont, pMsg->pCont, pMsg->contLen); if (pMsg->msgType == TSDB_MSG_TYPE_MD_CREATE_VNODE) { - return taosWriteQitem(tsVmgmt.createQueue, TAOS_QTYPE_RPC, pMgmt); + return taosWriteQitem(tsVmgmt.createQueue, pMgmt); } else { - return taosWriteQitem(tsVmgmt.workerQueue, TAOS_QTYPE_RPC, pMgmt); + return taosWriteQitem(tsVmgmt.workerQueue, pMgmt); } } @@ -257,27 +253,23 @@ int32_t vnodeInitMgmt() { SWorkerPool *pPool = &tsVmgmt.createPool; pPool->name = "vnode-mgmt-create"; - pPool->startFp = (ProcessStartFp)vnodeProcessMgmtStart; - pPool->endFp = (ProcessEndFp)vnodeProcessMgmtEnd; pPool->min = 1; pPool->max = 1; if (tWorkerInit(pPool) != 0) { return TSDB_CODE_VND_OUT_OF_MEMORY; } - tsVmgmt.createQueue = tWorkerAllocQueue(pPool, NULL); + tsVmgmt.createQueue = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)vnodeProcessMgmtReq); pPool = &tsVmgmt.workerPool; pPool->name = "vnode-mgmt-worker"; - pPool->startFp = (ProcessStartFp)vnodeProcessMgmtStart; - pPool->endFp = (ProcessEndFp)vnodeProcessMgmtEnd; pPool->min = 1; pPool->max = 1; if (tWorkerInit(pPool) != 0) { return TSDB_CODE_VND_OUT_OF_MEMORY; } - tsVmgmt.workerQueue = tWorkerAllocQueue(pPool, NULL); + tsVmgmt.workerQueue = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)vnodeProcessMgmtReq); vInfo("vmgmt is initialized"); return TSDB_CODE_SUCCESS; diff --git a/source/server/vnode/src/vnodeRead.c b/source/server/vnode/src/vnodeRead.c index 2ca2a81739..ce6348c992 100644 --- a/source/server/vnode/src/vnodeRead.c +++ b/source/server/vnode/src/vnodeRead.c @@ -71,9 +71,9 @@ static int32_t vnodeWriteToRQueue(SVnode *pVnode, void *pCont, int32_t contLen, atomic_add_fetch_32(&pVnode->queuedRMsg, 1); if (pRead->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRead->msgType == TSDB_MSG_TYPE_FETCH) { - return taosWriteQitem(pVnode->pFetchQ, qtype, pRead); + return taosWriteQitem(pVnode->pFetchQ, pRead); } else { - return taosWriteQitem(pVnode->pQueryQ, qtype, pRead); + return taosWriteQitem(pVnode->pQueryQ, pRead); } } @@ -136,18 +136,6 @@ static void vnodeInitReadMsgFp() { tsVread.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessConsumeMsg; } -static int32_t vnodeProcessReadStart(SVnode *pVnode, SReadMsg *pRead, int32_t qtype) { - int32_t msgType = pRead->msgType; - if (tsVread.msgFp[msgType] == NULL) { - vDebug("vgId:%d, msgType:%s not processed, no handle", pVnode->vgId, taosMsg[msgType]); - return TSDB_CODE_VND_MSG_NOT_PROCESSED; - } else { - vTrace("msg:%p, app:%p type:%s will be processed", pRead, pRead->rpcAhandle, taosMsg[msgType]); - } - - return (*tsVread.msgFp[msgType])(pVnode, pRead); -} - static void vnodeSendReadRsp(SReadMsg *pRead, int32_t code) { SRpcMsg rpcRsp = { .handle = pRead->rpcHandle, @@ -159,8 +147,18 @@ static void vnodeSendReadRsp(SReadMsg *pRead, int32_t code) { rpcSendResponse(&rpcRsp); } -static void vnodeProcessReadEnd(SVnode *pVnode, SReadMsg *pRead, int32_t qtype, int32_t code) { - if (qtype == TAOS_QTYPE_RPC && code != TSDB_CODE_QRY_NOT_READY) { +static void vnodeProcessReadReq(SReadMsg *pRead, SVnode *pVnode) { + int32_t msgType = pRead->msgType; + int32_t code = 0; + if (tsVread.msgFp[msgType] == NULL) { + vDebug("vgId:%d, msgType:%s not processed, no handle", pVnode->vgId, taosMsg[msgType]); + code = TSDB_CODE_VND_MSG_NOT_PROCESSED; + } else { + vTrace("msg:%p, app:%p type:%s will be processed", pRead, pRead->rpcAhandle, taosMsg[msgType]); + code = (*tsVread.msgFp[msgType])(pVnode, pRead); + } + + if (/*qtype == TAOS_QTYPE_RPC && */ code != TSDB_CODE_QRY_NOT_READY) { vnodeSendReadRsp(pRead, code); } else { if (code == TSDB_CODE_QRY_HAS_RSP) { @@ -181,16 +179,12 @@ int32_t vnodeInitRead() { SWorkerPool *pPool = &tsVread.query; pPool->name = "vquery"; - pPool->startFp = (ProcessStartFp)vnodeProcessReadStart; - pPool->endFp = (ProcessEndFp)vnodeProcessReadEnd; pPool->min = (int32_t)threadsForQuery; pPool->max = pPool->min; if (tWorkerInit(pPool) != 0) return -1; pPool = &tsVread.fetch; pPool->name = "vfetch"; - pPool->startFp = (ProcessStartFp)vnodeProcessReadStart; - pPool->endFp = (ProcessEndFp)vnodeProcessReadEnd; pPool->min = MIN(maxFetchThreads, tsNumOfCores); pPool->max = pPool->min; if (tWorkerInit(pPool) != 0) return -1; @@ -205,9 +199,13 @@ void vnodeCleanupRead() { vInfo("vread is closed"); } -taos_queue vnodeAllocQueryQueue(SVnode *pVnode) { return tWorkerAllocQueue(&tsVread.query, pVnode); } +taos_queue vnodeAllocQueryQueue(SVnode *pVnode) { + return tWorkerAllocQueue(&tsVread.query, pVnode, (FProcessOneItem)vnodeProcessReadReq); +} -taos_queue vnodeAllocFetchQueue(SVnode *pVnode) { return tWorkerAllocQueue(&tsVread.fetch, pVnode); } +taos_queue vnodeAllocFetchQueue(SVnode *pVnode) { + return tWorkerAllocQueue(&tsVread.fetch, pVnode, (FProcessOneItem)vnodeProcessReadReq); +} void vnodeFreeQueryQueue(taos_queue pQueue) { tWorkerFreeQueue(&tsVread.query, pQueue); } diff --git a/source/server/vnode/src/vnodeWrite.c b/source/server/vnode/src/vnodeWrite.c index f3258af0bf..119cd29537 100644 --- a/source/server/vnode/src/vnodeWrite.c +++ b/source/server/vnode/src/vnodeWrite.c @@ -32,15 +32,13 @@ typedef struct { } SVnWriteMsg; static struct { - SWriteWorkerPool pool; - int64_t queuedBytes; - int32_t queuedMsgs; + SMWorkerPool pool; + int64_t queuedBytes; + int32_t queuedMsgs; } tsVwrite = {0}; void vnodeStartWrite(SVnode *pVnode) {} -void vnodeStoprite(SVnode *pVnode) {} - -void vnodeWaitWriteCompleted(SVnode *pVnode) { +void vnodeStopWrite(SVnode *pVnode) { while (pVnode->queuedWMsg > 0) { vTrace("vgId:%d, queued wmsg num:%d", pVnode->vgId, pVnode->queuedWMsg); taosMsleep(10); @@ -86,7 +84,7 @@ static int32_t vnodeWriteToWQueue(SVnode *pVnode, SWalHead *pHead, int32_t qtype atomic_add_fetch_32(&tsVwrite.queuedMsgs, 1); atomic_add_fetch_32(&pVnode->refCount, 1); atomic_add_fetch_32(&pVnode->queuedWMsg, 1); - taosWriteQitem(pVnode->pWriteQ, pWrite->qtype, pWrite); + taosWriteQitem(pVnode->pWriteQ, pWrite); return TSDB_CODE_SUCCESS; } @@ -101,11 +99,7 @@ static void vnodeFreeFromWQueue(SVnode *pVnode, SVnWriteMsg *pWrite) { vnodeRelease(pVnode); } -int32_t vnodeProcessWalMsg(SVnode *pVnode, SWalHead *pHead) { - return vnodeWriteToWQueue(pVnode, pHead, TAOS_QTYPE_WAL, NULL); -} - -void vnodeProcessWriteMsg(SRpcMsg *pRpcMsg) { +void vnodeProcessWriteReq(SRpcMsg *pRpcMsg) { int32_t code; SMsgHead *pMsg = pRpcMsg->pCont; @@ -132,109 +126,104 @@ void vnodeProcessWriteMsg(SRpcMsg *pRpcMsg) { rpcFreeCont(pRpcMsg->pCont); } -static bool vnodeProcessWriteStart(SVnode *pVnode, SVnWriteMsg *pWrite, int32_t qtype) { - SWalHead *pHead = &pWrite->walHead; - SVnRsp * pRet = &pWrite->rspRet; - int32_t msgType = pHead->msgType; - - vTrace("vgId:%d, msg:%s will be processed, hver:%" PRIu64, pVnode->vgId, taosMsg[pHead->msgType], pHead->version); - - // write into WAL -#if 0 - pWrite->code = walWrite(pVnode->wal, pHead); - if (pWrite->code < 0) return false; - - - pVnode->version = pHead->version; -#endif - // write data locally - switch (msgType) { - case TSDB_MSG_TYPE_SUBMIT: - pRet->len = sizeof(SSubmitRsp); - pRet->rsp = rpcMallocCont(pRet->len); - pWrite->code = vnodeProcessSubmitReq(pVnode, (void*)pHead->cont, pRet->rsp); - break; - case TSDB_MSG_TYPE_MD_CREATE_TABLE: - pWrite->code = vnodeProcessCreateTableReq(pVnode, (void*)pHead->cont, NULL); - break; - case TSDB_MSG_TYPE_MD_DROP_TABLE: - pWrite->code = vnodeProcessDropTableReq(pVnode, (void*)pHead->cont, NULL); - break; - case TSDB_MSG_TYPE_MD_ALTER_TABLE: - pWrite->code = vnodeProcessAlterTableReq(pVnode, (void*)pHead->cont, NULL); - break; - case TSDB_MSG_TYPE_MD_DROP_STABLE: - pWrite->code = vnodeProcessDropStableReq(pVnode, (void*)pHead->cont, NULL); - break; - case TSDB_MSG_TYPE_UPDATE_TAG_VAL: - pWrite->code = vnodeProcessUpdateTagValReq(pVnode, (void*)pHead->cont, NULL); - break; - //mq related - case TSDB_MSG_TYPE_MQ_CONNECT: - pWrite->code = vnodeProcessMqConnectReq(pVnode, (void*)pHead->cont, NULL); - break; - case TSDB_MSG_TYPE_MQ_DISCONNECT: - pWrite->code = vnodeProcessMqDisconnectReq(pVnode, (void*)pHead->cont, NULL); - break; - case TSDB_MSG_TYPE_MQ_ACK: - pWrite->code = vnodeProcessMqAckReq(pVnode, (void*)pHead->cont, NULL); - break; - case TSDB_MSG_TYPE_MQ_RESET: - pWrite->code = vnodeProcessMqResetReq(pVnode, (void*)pHead->cont, NULL); - break; - //mq related end - default: - pWrite->code = TSDB_CODE_VND_MSG_NOT_PROCESSED; - break; - } - - if (pWrite->code < 0) return false; - - // update fsync - return (pWrite->code == 0 && msgType != TSDB_MSG_TYPE_SUBMIT); +static void vnodeProcessWrite(SVnWriteMsg *pWrite, SVnode *pVnode) { } + // SWalHead *pHead = &pWrite->walHead; + // SVnRsp * pRet = &pWrite->rspRet; + // int32_t msgType = pHead->msgType; -static void vnodeFsync(SVnode *pVnode, bool fsync) { -#if 0 - walFsync(pVnode->wal, fsync); -#endif -} + // vTrace("vgId:%d, msg:%s will be processed, hver:%" PRIu64, pVnode->vgId, taosMsg[pHead->msgType], pHead->version); -static void vnodeProcessWriteEnd(SVnode *pVnode, SVnWriteMsg *pWrite, int32_t qtype, int32_t code) { - if (qtype == TAOS_QTYPE_RPC) { - SRpcMsg rpcRsp = { - .handle = pWrite->rpcMsg.handle, - .pCont = pWrite->rspRet.rsp, - .contLen = pWrite->rspRet.len, - .code = pWrite->code, - }; - rpcSendResponse(&rpcRsp); - } else { - if (pWrite->rspRet.rsp) { - rpcFreeCont(pWrite->rspRet.rsp); - } - } - vnodeFreeFromWQueue(pVnode, pWrite); -} + // // write data locally + // switch (msgType) { + // case TSDB_MSG_TYPE_SUBMIT: + // pRet->len = sizeof(SSubmitRsp); + // pRet->rsp = rpcMallocCont(pRet->len); + // pWrite->code = vnodeProcessSubmitReq(pVnode, (void*)pHead->cont, pRet->rsp); + // break; + // case TSDB_MSG_TYPE_MD_CREATE_TABLE: + // pWrite->code = vnodeProcessCreateTableReq(pVnode, (void*)pHead->cont, NULL); + // break; + // case TSDB_MSG_TYPE_MD_DROP_TABLE: + // pWrite->code = vnodeProcessDropTableReq(pVnode, (void*)pHead->cont, NULL); + // break; + // case TSDB_MSG_TYPE_MD_ALTER_TABLE: + // pWrite->code = vnodeProcessAlterTableReq(pVnode, (void*)pHead->cont, NULL); + // break; + // case TSDB_MSG_TYPE_MD_DROP_STABLE: + // pWrite->code = vnodeProcessDropStableReq(pVnode, (void*)pHead->cont, NULL); + // break; + // case TSDB_MSG_TYPE_UPDATE_TAG_VAL: + // pWrite->code = vnodeProcessUpdateTagValReq(pVnode, (void*)pHead->cont, NULL); + // break; + // //mq related + // case TSDB_MSG_TYPE_MQ_CONNECT: + // pWrite->code = vnodeProcessMqConnectReq(pVnode, (void*)pHead->cont, NULL); + // break; + // case TSDB_MSG_TYPE_MQ_DISCONNECT: + // pWrite->code = vnodeProcessMqDisconnectReq(pVnode, (void*)pHead->cont, NULL); + // break; + // case TSDB_MSG_TYPE_MQ_ACK: + // pWrite->code = vnodeProcessMqAckReq(pVnode, (void*)pHead->cont, NULL); + // break; + // case TSDB_MSG_TYPE_MQ_RESET: + // pWrite->code = vnodeProcessMqResetReq(pVnode, (void*)pHead->cont, NULL); + // break; + // //mq related end + // default: + // pWrite->code = TSDB_CODE_VND_MSG_NOT_PROCESSED; + // break; + // } + + // if (pWrite->code < 0) return false; + + // // update fsync + // return (pWrite->code == 0 && msgType != TSDB_MSG_TYPE_SUBMIT); + + + // // walFsync(pVnode->wal, fsync); + + +// static void vnodeProcessWriteEnd(SVnWriteMsg *pWrite, SVnode *pVnode) { +// if (qtype == TAOS_QTYPE_RPC) { +// SRpcMsg rpcRsp = { +// .handle = pWrite->rpcMsg.handle, +// .pCont = pWrite->rspRet.rsp, +// .contLen = pWrite->rspRet.len, +// .code = pWrite->code, +// }; +// rpcSendResponse(&rpcRsp); +// } else { +// if (pWrite->rspRet.rsp) { +// rpcFreeCont(pWrite->rspRet.rsp); +// } +// } +// vnodeFreeFromWQueue(pVnode, pWrite); +// } int32_t vnodeInitWrite() { - SWriteWorkerPool *pPool = &tsVwrite.pool; - pPool->name = "vwrite"; + SMWorkerPool *pPool = &tsVwrite.pool; + pPool->name = "vnode-write"; pPool->max = tsNumOfCores; - pPool->startFp = (ProcessWriteStartFp)vnodeProcessWriteStart; - pPool->syncFp = (ProcessWriteSyncFp)vnodeFsync; - pPool->endFp = (ProcessWriteEndFp)vnodeProcessWriteEnd; - if (tWriteWorkerInit(pPool) != 0) return -1; + if (tMWorkerInit(pPool) != 0) return -1; vInfo("vwrite is initialized, max worker %d", pPool->max); return TSDB_CODE_SUCCESS; } void vnodeCleanupWrite() { - tWriteWorkerCleanup(&tsVwrite.pool); + tMWorkerCleanup(&tsVwrite.pool); vInfo("vwrite is closed"); } -taos_queue vnodeAllocWriteQueue(SVnode *pVnode) { return tWriteWorkerAllocQueue(&tsVwrite.pool, pVnode); } +taos_queue vnodeAllocWriteQueue(SVnode *pVnode) { + return tMWorkerAllocQueue(&tsVwrite.pool, pVnode, NULL); +} -void vnodeFreeWriteQueue(taos_queue pQueue) { tWriteWorkerFreeQueue(&tsVwrite.pool, pQueue); } +void vnodeFreeWriteQueue(taos_queue pQueue) { tMWorkerFreeQueue(&tsVwrite.pool, pQueue); } + +taos_queue vnodeAllocApplyQueue(SVnode *pVnode) { + return tMWorkerAllocQueue(&tsVwrite.pool, pVnode, NULL); +} + +void vnodeFreeApplyQueue(taos_queue pQueue) { tMWorkerFreeQueue(&tsVwrite.pool, pQueue); } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index da1fb1837f..bb0303c04a 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -19,41 +19,41 @@ #include "tqueue.h" typedef struct STaosQnode { - int type; - struct STaosQnode *next; - char item[]; + struct STaosQnode *next; + char item[]; } STaosQnode; typedef struct STaosQueue { - int32_t itemSize; - int32_t numOfItems; - struct STaosQnode *head; - struct STaosQnode *tail; - struct STaosQueue *next; // for queue set - struct STaosQset *qset; // for queue set - void *ahandle; // for queue set - pthread_mutex_t mutex; + int32_t itemSize; + int32_t numOfItems; + struct STaosQnode *head; + struct STaosQnode *tail; + struct STaosQueue *next; // for queue set + struct STaosQset *qset; // for queue set + void *ahandle; // for queue set + FProcessOneItem fpOneItem; + FProcessAllItem fpAllItem; + pthread_mutex_t mutex; } STaosQueue; typedef struct STaosQset { - STaosQueue *head; - STaosQueue *current; - pthread_mutex_t mutex; - int32_t numOfQueues; - int32_t numOfItems; - tsem_t sem; + STaosQueue *head; + STaosQueue *current; + pthread_mutex_t mutex; + int32_t numOfQueues; + int32_t numOfItems; + tsem_t sem; } STaosQset; typedef struct STaosQall { - STaosQnode *current; - STaosQnode *start; - int32_t itemSize; - int32_t numOfItems; -} STaosQall; - + STaosQnode *current; + STaosQnode *start; + int32_t itemSize; + int32_t numOfItems; +} STaosQall; + taos_queue taosOpenQueue() { - - STaosQueue *queue = (STaosQueue *) calloc(sizeof(STaosQueue), 1); + STaosQueue *queue = (STaosQueue *)calloc(sizeof(STaosQueue), 1); if (queue == NULL) { terrno = TSDB_CODE_COM_OUT_OF_MEMORY; return NULL; @@ -65,6 +65,13 @@ taos_queue taosOpenQueue() { return queue; } +void taosSetQueueFp(taos_queue param, FProcessOneItem fpOneItem, FProcessAllItem fpAllItem) { + if (param == NULL) return; + STaosQueue *queue = (STaosQueue *)param; + queue->fpOneItem = fpOneItem; + queue->fpAllItem = fpAllItem; +} + void taosCloseQueue(taos_queue param) { if (param == NULL) return; STaosQueue *queue = (STaosQueue *)param; @@ -72,17 +79,17 @@ void taosCloseQueue(taos_queue param) { STaosQset *qset; pthread_mutex_lock(&queue->mutex); - STaosQnode *pNode = queue->head; + STaosQnode *pNode = queue->head; queue->head = NULL; qset = queue->qset; pthread_mutex_unlock(&queue->mutex); - if (queue->qset) taosRemoveFromQset(qset, queue); + if (queue->qset) taosRemoveFromQset(qset, queue); while (pNode) { pTemp = pNode; pNode = pNode->next; - free (pTemp); + free(pTemp); } pthread_mutex_destroy(&queue->mutex); @@ -93,7 +100,7 @@ void taosCloseQueue(taos_queue param) { void *taosAllocateQitem(int size) { STaosQnode *pNode = (STaosQnode *)calloc(sizeof(STaosQnode) + size, 1); - + if (pNode == NULL) return NULL; uTrace("item:%p, node:%p is allocated", pNode->item, pNode); return (void *)pNode->item; @@ -108,10 +115,9 @@ void taosFreeQitem(void *param) { free(temp); } -int taosWriteQitem(taos_queue param, int type, void *item) { +int taosWriteQitem(taos_queue param, void *item) { STaosQueue *queue = (STaosQueue *)param; STaosQnode *pNode = (STaosQnode *)(((char *)item) - sizeof(STaosQnode)); - pNode->type = type; pNode->next = NULL; pthread_mutex_lock(&queue->mutex); @@ -121,12 +127,12 @@ int taosWriteQitem(taos_queue param, int type, void *item) { queue->tail = pNode; } else { queue->head = pNode; - queue->tail = pNode; + queue->tail = pNode; } queue->numOfItems++; if (queue->qset) atomic_add_fetch_32(&queue->qset->numOfItems, 1); - uTrace("item:%p is put into queue:%p, type:%d items:%d", item, queue, type, queue->numOfItems); + uTrace("item:%p is put into queue:%p, items:%d", item, queue, queue->numOfItems); pthread_mutex_unlock(&queue->mutex); @@ -135,7 +141,7 @@ int taosWriteQitem(taos_queue param, int type, void *item) { return 0; } -int taosReadQitem(taos_queue param, int *type, void **pitem) { +int taosReadQitem(taos_queue param, void **pitem) { STaosQueue *queue = (STaosQueue *)param; STaosQnode *pNode = NULL; int code = 0; @@ -143,17 +149,15 @@ int taosReadQitem(taos_queue param, int *type, void **pitem) { pthread_mutex_lock(&queue->mutex); if (queue->head) { - pNode = queue->head; - *pitem = pNode->item; - *type = pNode->type; - queue->head = pNode->next; - if (queue->head == NULL) - queue->tail = NULL; - queue->numOfItems--; - if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, 1); - code = 1; - uDebug("item:%p is read out from queue:%p, type:%d items:%d", *pitem, queue, *type, queue->numOfItems); - } + pNode = queue->head; + *pitem = pNode->item; + queue->head = pNode->next; + if (queue->head == NULL) queue->tail = NULL; + queue->numOfItems--; + if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, 1); + code = 1; + uDebug("item:%p is read out from queue:%p, items:%d", *pitem, queue, queue->numOfItems); + } pthread_mutex_unlock(&queue->mutex); @@ -165,9 +169,7 @@ void *taosAllocateQall() { return p; } -void taosFreeQall(void *param) { - free(param); -} +void taosFreeQall(void *param) { free(param); } int taosReadAllQitems(taos_queue param, taos_qall p2) { STaosQueue *queue = (STaosQueue *)param; @@ -203,33 +205,30 @@ int taosReadAllQitems(taos_queue param, taos_qall p2) { return code; } -int taosGetQitem(taos_qall param, int *type, void **pitem) { +int taosGetQitem(taos_qall param, void **pitem) { STaosQall *qall = (STaosQall *)param; STaosQnode *pNode; int num = 0; pNode = qall->current; - if (pNode) - qall->current = pNode->next; - + if (pNode) qall->current = pNode->next; + if (pNode) { *pitem = pNode->item; - *type = pNode->type; num = 1; - uTrace("item:%p is fetched, type:%d", *pitem, *type); + uTrace("item:%p is fetched", *pitem); } return num; } void taosResetQitems(taos_qall param) { - STaosQall *qall = (STaosQall *)param; + STaosQall *qall = (STaosQall *)param; qall->current = qall->start; } taos_qset taosOpenQset() { - - STaosQset *qset = (STaosQset *) calloc(sizeof(STaosQset), 1); + STaosQset *qset = (STaosQset *)calloc(sizeof(STaosQset), 1); if (qset == NULL) { terrno = TSDB_CODE_COM_OUT_OF_MEMORY; return NULL; @@ -276,7 +275,7 @@ int taosAddIntoQset(taos_qset p1, taos_queue p2, void *ahandle) { STaosQueue *queue = (STaosQueue *)p2; STaosQset *qset = (STaosQset *)p1; - if (queue->qset) return -1; + if (queue->qset) return -1; pthread_mutex_lock(&qset->mutex); @@ -299,7 +298,7 @@ int taosAddIntoQset(taos_qset p1, taos_queue p2, void *ahandle) { void taosRemoveFromQset(taos_qset p1, taos_queue p2) { STaosQueue *queue = (STaosQueue *)p2; STaosQset *qset = (STaosQset *)p1; - + STaosQueue *tqueue = NULL; pthread_mutex_lock(&qset->mutex); @@ -313,7 +312,7 @@ void taosRemoveFromQset(taos_qset p1, taos_queue p2) { tqueue = qset->head->next; while (tqueue) { assert(tqueue->qset); - if (tqueue== queue) { + if (tqueue == queue) { prev->next = tqueue->next; break; } else { @@ -333,29 +332,26 @@ void taosRemoveFromQset(taos_qset p1, taos_queue p2) { queue->next = NULL; pthread_mutex_unlock(&queue->mutex); } - } - + } + pthread_mutex_unlock(&qset->mutex); uTrace("queue:%p is removed from qset:%p", queue, qset); } -int taosGetQueueNumber(taos_qset param) { - return ((STaosQset *)param)->numOfQueues; -} +int taosGetQueueNumber(taos_qset param) { return ((STaosQset *)param)->numOfQueues; } -int taosReadQitemFromQset(taos_qset param, int *type, void **pitem, void **phandle) { +int taosReadQitemFromQset(taos_qset param, void **pitem, void **ahandle, FProcessOneItem *fpOneItem) { STaosQset *qset = (STaosQset *)param; STaosQnode *pNode = NULL; int code = 0; - + tsem_wait(&qset->sem); pthread_mutex_lock(&qset->mutex); - for(int i=0; inumOfQueues; ++i) { - if (qset->current == NULL) - qset->current = qset->head; + for (int i = 0; i < qset->numOfQueues; ++i) { + if (qset->current == NULL) qset->current = qset->head; STaosQueue *queue = qset->current; if (queue) qset->current = queue->next; if (queue == NULL) break; @@ -364,18 +360,17 @@ int taosReadQitemFromQset(taos_qset param, int *type, void **pitem, void **phand pthread_mutex_lock(&queue->mutex); if (queue->head) { - pNode = queue->head; - *pitem = pNode->item; - if (type) *type = pNode->type; - if (phandle) *phandle = queue->ahandle; - queue->head = pNode->next; - if (queue->head == NULL) - queue->tail = NULL; - queue->numOfItems--; - atomic_sub_fetch_32(&qset->numOfItems, 1); - code = 1; - uTrace("item:%p is read out from queue:%p, type:%d items:%d", *pitem, queue, pNode->type, queue->numOfItems); - } + pNode = queue->head; + *pitem = pNode->item; + if (ahandle) *ahandle = queue->ahandle; + if (fpOneItem) *fpOneItem = queue->fpOneItem; + queue->head = pNode->next; + if (queue->head == NULL) queue->tail = NULL; + queue->numOfItems--; + atomic_sub_fetch_32(&qset->numOfItems, 1); + code = 1; + uTrace("item:%p is read out from queue:%p, items:%d", *pitem, queue, queue->numOfItems); + } pthread_mutex_unlock(&queue->mutex); if (pNode) break; @@ -383,10 +378,10 @@ int taosReadQitemFromQset(taos_qset param, int *type, void **pitem, void **phand pthread_mutex_unlock(&qset->mutex); - return code; + return code; } -int taosReadAllQitemsFromQset(taos_qset param, taos_qall p2, void **phandle) { +int taosReadAllQitemsFromQset(taos_qset param, taos_qall p2, void **ahandle, FProcessAllItem *fpAllItem) { STaosQset *qset = (STaosQset *)param; STaosQueue *queue; STaosQall *qall = (STaosQall *)p2; @@ -411,8 +406,9 @@ int taosReadAllQitemsFromQset(taos_qset param, taos_qall p2, void **phandle) { qall->numOfItems = queue->numOfItems; qall->itemSize = queue->itemSize; code = qall->numOfItems; - *phandle = queue->ahandle; - + if (ahandle) *ahandle = queue->ahandle; + if (fpAllItem) *fpAllItem = queue->fpAllItem; + queue->head = NULL; queue->tail = NULL; queue->numOfItems = 0; diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index abed265e0b..12f1aac9f9 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -58,11 +58,11 @@ void tWorkerCleanup(SWorkerPool *pool) { } static void *tWorkerThreadFp(SWorker *worker) { - SWorkerPool *pool = worker->pool; + SWorkerPool *pool = worker->pool; + FProcessOneItem fp = NULL; - void * msg = NULL; - void * ahandle = NULL; - int32_t qtype = 0; + void *msg = NULL; + void *ahandle = NULL; int32_t code = 0; taosBlockSIGPIPE(); @@ -70,19 +70,20 @@ static void *tWorkerThreadFp(SWorker *worker) { uDebug("worker:%s:%d is running", pool->name, worker->id); while (1) { - if (taosReadQitemFromQset(pool->qset, &qtype, (void **)&msg, &ahandle) == 0) { + if (taosReadQitemFromQset(pool->qset, (void **)&msg, &ahandle, &fp) == 0) { uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, pool->qset); break; } - code = (*pool->startFp)(ahandle, msg, qtype); - if (pool->endFp) (*pool->endFp)(ahandle, msg, qtype, code); + if (fp) { + (*fp)(msg, ahandle); + } } return NULL; } -taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle) { +taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessOneItem fp) { pthread_mutex_lock(&pool->mutex); taos_queue queue = taosOpenQueue(); if (queue == NULL) { @@ -90,6 +91,7 @@ taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle) { return NULL; } + taosSetQueueFp(queue, fp, NULL); taosAddIntoQset(pool->qset, queue, ahandle); // spawn a thread to process queue @@ -122,14 +124,14 @@ void tWorkerFreeQueue(SWorkerPool *pool, void *queue) { uDebug("worker:%s, queue:%p is freed", pool->name, queue); } -int32_t tWriteWorkerInit(SWriteWorkerPool *pool) { +int32_t tMWorkerInit(SMWorkerPool *pool) { pool->nextId = 0; - pool->workers = calloc(sizeof(SWriteWorker), pool->max); + pool->workers = calloc(sizeof(SMWorker), pool->max); if (pool->workers == NULL) return -1; pthread_mutex_init(&pool->mutex, NULL); for (int32_t i = 0; i < pool->max; ++i) { - SWriteWorker *worker = pool->workers + i; + SMWorker *worker = pool->workers + i; worker->id = i; worker->qall = NULL; worker->qset = NULL; @@ -140,16 +142,16 @@ int32_t tWriteWorkerInit(SWriteWorkerPool *pool) { return 0; } -void tWriteWorkerCleanup(SWriteWorkerPool *pool) { +void tMWorkerCleanup(SMWorkerPool *pool) { for (int32_t i = 0; i < pool->max; ++i) { - SWriteWorker *worker = pool->workers + i; + SMWorker *worker = pool->workers + i; if (taosCheckPthreadValid(worker->thread)) { if (worker->qset) taosQsetThreadResume(worker->qset); } } for (int32_t i = 0; i < pool->max; ++i) { - SWriteWorker *worker = pool->workers + i; + SMWorker *worker = pool->workers + i; if (taosCheckPthreadValid(worker->thread)) { pthread_join(worker->thread, NULL); taosFreeQall(worker->qall); @@ -163,11 +165,12 @@ void tWriteWorkerCleanup(SWriteWorkerPool *pool) { uInfo("worker:%s is closed", pool->name); } -static void *tWriteWorkerThreadFp(SWriteWorker *worker) { - SWriteWorkerPool *pool = worker->pool; +static void *tWriteWorkerThreadFp(SMWorker *worker) { + SMWorkerPool *pool = worker->pool; + FProcessAllItem fp = NULL; - void * msg = NULL; - void * ahandle = NULL; + void *msg = NULL; + void *ahandle = NULL; int32_t numOfMsgs = 0; int32_t qtype = 0; @@ -176,34 +179,23 @@ static void *tWriteWorkerThreadFp(SWriteWorker *worker) { uDebug("worker:%s:%d is running", pool->name, worker->id); while (1) { - numOfMsgs = taosReadAllQitemsFromQset(worker->qset, worker->qall, &ahandle); + numOfMsgs = taosReadAllQitemsFromQset(worker->qset, worker->qall, &ahandle, &fp); if (numOfMsgs == 0) { uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, worker->qset); break; } - bool fsync = false; - for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(worker->qall, &qtype, (void **)&msg); - fsync = fsync | (*pool->startFp)(ahandle, msg, qtype); - } - - (*pool->syncFp)(ahandle, fsync); - - // browse all items, and process them one by one - taosResetQitems(worker->qall); - for (int32_t i = 0; i < numOfMsgs; ++i) { - taosGetQitem(worker->qall, &qtype, (void **)&msg); - (*pool->endFp)(ahandle, msg, qtype); + if (fp) { + (*fp)(worker->qall, numOfMsgs, ahandle); } } return NULL; } -taos_queue tWriteWorkerAllocQueue(SWriteWorkerPool *pool, void *ahandle) { +taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessAllItem fp) { pthread_mutex_lock(&pool->mutex); - SWriteWorker *worker = pool->workers + pool->nextId; + SMWorker *worker = pool->workers + pool->nextId; taos_queue *queue = taosOpenQueue(); if (queue == NULL) { @@ -211,6 +203,8 @@ taos_queue tWriteWorkerAllocQueue(SWriteWorkerPool *pool, void *ahandle) { return NULL; } + taosSetQueueFp(queue, NULL, fp); + if (worker->qset == NULL) { worker->qset = taosOpenQset(); if (worker->qset == NULL) { @@ -254,7 +248,7 @@ taos_queue tWriteWorkerAllocQueue(SWriteWorkerPool *pool, void *ahandle) { return queue; } -void tWriteWorkerFreeQueue(SWriteWorkerPool *pool, taos_queue queue) { +void tMWorkerFreeQueue(SMWorkerPool *pool, taos_queue queue) { taosCloseQueue(queue); uDebug("worker:%s, queue:%p is freed", pool->name, queue); } From 3521ec34d2a390af1f02f0a5f88b36fcd4d87961 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 31 Oct 2021 13:17:19 +0800 Subject: [PATCH 02/17] add user manual of SMA --- .../Small_Materialized_Aggrates.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 docs/user_manual/Small_Materialized_Aggrates.md diff --git a/docs/user_manual/Small_Materialized_Aggrates.md b/docs/user_manual/Small_Materialized_Aggrates.md new file mode 100644 index 0000000000..59a5ed7b45 --- /dev/null +++ b/docs/user_manual/Small_Materialized_Aggrates.md @@ -0,0 +1,43 @@ +# Small Materialized Aggragates + +**SMA** (**S**mall **M**aterialized **A**ggrates) is used to speed up the query process on materialized data cube in TDengine. TDengine 3.0 gives more flexibility on the SMA configurations. + +There are two kinds of SMA in TDengine: +1. Block-wise SMA +2. Time-range-wise SMA + + +![SMA in TDengine 3.0](http://www.plantuml.com/plantuml/png/Km02X-AInAAItCoybDp40WKG7Gzan9Ua5fTmWUIr589z7I4iBGMddFpaR6I1aCpSLDsWnBpqLBYeGsfU2jGu0000) + +## Block-wise SMA +Block-wise SMA is created by default when the data are committed. Since time-series data are saved as block data in files, a corresponding SMA is create when the data block is written. The default block-wise SMA includes: +1. sum(*) +2. max(*) +3. min(*) + +By default, the system will create SMA for each column except those columns with type *binary* and *nchar*. However, users can change the behavior by the keyword **NOSMA** to disable the SMA for a certain column like below: +```SQL +# create a super table with the SMA on column b disabled +create table st (ts timestamp, a int, b int NOSMA, c double) tags (tg1 binary(10), tg2 int); +``` + +## Time-range-wise SMA +In addition to the default block-wise SMA, users can create their own SMAs ondemand. Below is an example to create a SMA. +```SQL +# create a SMA every 10 minutes with SMA of sum, max and min +create sma_indx sma_5min on st (sum(*), max(*), min(*), twa(*)) interval(10m); +``` +Users can also drop a time-range-wise SMA like below: +```SQL +# drop the sma index +drop sma_index sma_5min on st; +``` +**NOTE: Creating a SMA index is a heavy operation which may take a long time and block the write operation. So create the time-range-wise SMA when creating the table or when there are not too much data.** \ No newline at end of file From 78628286831a51e34a04b914aad10c193b2fad4a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 31 Oct 2021 13:25:09 +0800 Subject: [PATCH 03/17] change more --- docs/user_manual/Small_Materialized_Aggrates.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/user_manual/Small_Materialized_Aggrates.md b/docs/user_manual/Small_Materialized_Aggrates.md index 59a5ed7b45..81a067139d 100644 --- a/docs/user_manual/Small_Materialized_Aggrates.md +++ b/docs/user_manual/Small_Materialized_Aggrates.md @@ -10,13 +10,12 @@ There are two kinds of SMA in TDengine: ```plantuml @startmindmap mind_map_test * SMA - ** Block SMA - ** Time-Range SMA + ** Block-wise SMA + ** Time-range-wise SMA @endmindmap -``` ---> -![SMA in TDengine 3.0](http://www.plantuml.com/plantuml/png/Km02X-AInAAItCoybDp40WKG7Gzan9Ua5fTmWUIr589z7I4iBGMddFpaR6I1aCpSLDsWnBpqLBYeGsfU2jGu0000) +``` --> +![SMA in TDengine 3.0](http://www.plantuml.com/plantuml/png/Kr1GK70eBaaiAidDp4l9JInG0D7nG4PyIMfn2HTGMa5B8TZN4SBIKd3AoK_ErYtFB4v55Wt9p4tLBKhCIqz5bN981HeACHW0) ## Block-wise SMA Block-wise SMA is created by default when the data are committed. Since time-series data are saved as block data in files, a corresponding SMA is create when the data block is written. The default block-wise SMA includes: 1. sum(*) From 96bb823464769f13cd3f2c638edcc8e21b55bfcf Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 31 Oct 2021 13:26:15 +0800 Subject: [PATCH 04/17] change --- docs/user_manual/Small_Materialized_Aggrates.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user_manual/Small_Materialized_Aggrates.md b/docs/user_manual/Small_Materialized_Aggrates.md index 81a067139d..dc2d9e41ed 100644 --- a/docs/user_manual/Small_Materialized_Aggrates.md +++ b/docs/user_manual/Small_Materialized_Aggrates.md @@ -32,7 +32,7 @@ create table st (ts timestamp, a int, b int NOSMA, c double) tags (tg1 binary(10 In addition to the default block-wise SMA, users can create their own SMAs ondemand. Below is an example to create a SMA. ```SQL # create a SMA every 10 minutes with SMA of sum, max and min -create sma_indx sma_5min on st (sum(*), max(*), min(*), twa(*)) interval(10m); +create sma_indx sma_10min on st (sum(*), max(*), min(*), twa(*)) interval(10m); ``` Users can also drop a time-range-wise SMA like below: ```SQL From f84b1eb2dfff0642ff1cdd8203d693259b50da58 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 31 Oct 2021 13:29:09 +0800 Subject: [PATCH 05/17] change --- docs/user_manual/Small_Materialized_Aggrates.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user_manual/Small_Materialized_Aggrates.md b/docs/user_manual/Small_Materialized_Aggrates.md index dc2d9e41ed..e13a623afb 100644 --- a/docs/user_manual/Small_Materialized_Aggrates.md +++ b/docs/user_manual/Small_Materialized_Aggrates.md @@ -39,4 +39,4 @@ Users can also drop a time-range-wise SMA like below: # drop the sma index drop sma_index sma_5min on st; ``` -**NOTE: Creating a SMA index is a heavy operation which may take a long time and block the write operation. So create the time-range-wise SMA when creating the table or when there are not too much data.** \ No newline at end of file +**NOTE: Creating an SMA index is a heavy operation which may take a long time and block the write operation. So create the time-range-wise SMA when creating the table or when there are not too much data.** \ No newline at end of file From 5deae213dca60ff5cce2ff0284821bb14ee9aead Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Mon, 1 Nov 2021 10:06:05 +0800 Subject: [PATCH 06/17] refine tq meta data structure --- source/server/vnode/tq/inc/tqMetaStore.h | 40 +++++----- source/server/vnode/tq/src/tqMetaStore.c | 98 ++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 21 deletions(-) diff --git a/source/server/vnode/tq/inc/tqMetaStore.h b/source/server/vnode/tq/inc/tqMetaStore.h index 6319b32a10..066e76028d 100644 --- a/source/server/vnode/tq/inc/tqMetaStore.h +++ b/source/server/vnode/tq/inc/tqMetaStore.h @@ -43,35 +43,33 @@ typedef struct TqMetaList { typedef struct TqMetaStore { TqMetaList* inUse[TQ_INUSE_SIZE]; + //a table head, key is empty TqMetaList* unpersistHead; - //deserializer - //serializer - //deleter + int fileFd; //TODO:temporaral use + int idxFd; //TODO:temporaral use + void* (*serializer)(void*); + void* (*deserializer)(void*); + void (*deleter)(void*); } TqMetaStore; -typedef struct TqMetaPageBuf { - int16_t offset; - char buffer[TQ_PAGE_SIZE]; -} TqMetaPageBuf; +TqMetaStore* tqStoreOpen(const char* path, void* serializer(void* ), void* deserializer(void*), void deleter(void*)); +int32_t tqStoreClose(TqMetaStore*); +int32_t tqStoreDelete(TqMetaStore*); +//int32_t TqStoreCommitAll(TqMetaStore*); +int32_t tqStorePersist(TqMetaStore*); -TqMetaStore* TqStoreOpen(const char* path, void* serializer(void* ), void* deserializer(void*)); -int32_t TqStoreClose(TqMetaStore*); -int32_t TqStoreDelete(TqMetaStore*); -int32_t TqStoreCommitAll(TqMetaStore*); -int32_t TqStorePersist(TqMetaStore*); - -TqMetaHandle* TqHandleGetInUse(TqMetaStore*, int64_t key); -int32_t TqHandlePutInUse(TqMetaStore*, TqMetaHandle* handle); -TqMetaHandle* TqHandleGetInTxn(TqMetaStore*, int64_t key); -int32_t TqHandlePutInTxn(TqMetaStore*, TqMetaHandle* handle); +TqMetaHandle* tqHandleGetInUse(TqMetaStore*, int64_t key); +int32_t tqHandlePutInUse(TqMetaStore*, TqMetaHandle* handle); +TqMetaHandle* tqHandleGetInTxn(TqMetaStore*, int64_t key); +int32_t tqHandlePutInTxn(TqMetaStore*, TqMetaHandle* handle); //delete in-use-handle, make in-txn-handle in use -int32_t TqHandleCommit(TqMetaStore*, int64_t key); +int32_t tqHandleCommit(TqMetaStore*, int64_t key); //delete in-txn-handle -int32_t TqHandleAbort(TqMetaStore*, int64_t key); +int32_t tqHandleAbort(TqMetaStore*, int64_t key); //delete in-use-handle -int32_t TqHandleDel(TqMetaStore*, int64_t key); +int32_t tqHandleDel(TqMetaStore*, int64_t key); //delete in-use-handle and in-txn-handle -int32_t TqHandleClear(TqMetaStore*, int64_t key); +int32_t tqHandleClear(TqMetaStore*, int64_t key); #ifdef __cplusplus } diff --git a/source/server/vnode/tq/src/tqMetaStore.c b/source/server/vnode/tq/src/tqMetaStore.c index f2f48bbc8a..d652058c74 100644 --- a/source/server/vnode/tq/src/tqMetaStore.c +++ b/source/server/vnode/tq/src/tqMetaStore.c @@ -12,3 +12,101 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +#include "tqMetaStore.h" +//TODO:replace by a abstract file layer +#include +#include + +typedef struct TqMetaPageBuf { + int16_t offset; + char buffer[TQ_PAGE_SIZE]; +} TqMetaPageBuf; + +TqMetaStore* tqStoreOpen(const char* path, void* serializer(void*), + void* deserializer(void*), void deleter(void*)) { + //concat data file name and index file name + int fileFd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0755); + if(fileFd < 0) return NULL; + TqMetaStore* pMeta = malloc(sizeof(TqMetaStore)); + if(pMeta == NULL) { + //close + return NULL; + } + memset(pMeta, 0, sizeof(TqMetaStore)); + pMeta->fileFd = fileFd; + + int idxFd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0755); + if(idxFd < 0) { + //close file + //free memory + return NULL; + } + pMeta->idxFd = idxFd; + pMeta->unpersistHead = malloc(sizeof(TqMetaList)); + if(pMeta->unpersistHead == NULL) { + //close file + //free memory + return NULL; + } + pMeta->serializer = serializer; + pMeta->deserializer = deserializer; + pMeta->deleter = deleter; + return pMeta; +} + +int32_t tqStoreClose(TqMetaStore* pMeta) { + //commit data and idx + //close file + //free memory + return 0; +} + +int32_t tqStoreDelete(TqMetaStore* pMeta) { + //close file + //delete file + //free memory + return 0; +} + +int32_t tqStorePersist(TqMetaStore* pMeta) { + TqMetaList *node = pMeta->unpersistHead; + while(node->unpersistNext) { + //serialize + //append data + //write offset and idx + //remove from unpersist list + } + return 0; +} + +int32_t tqHandlePutInUse(TqMetaStore* pMeta, TqMetaHandle* handle) { + return 0; +} + +TqMetaHandle* tqHandleGetInUse(TqMetaStore* pMeta, int64_t key) { + return NULL; +} + +int32_t tqHandlePutInTxn(TqMetaStore* pMeta, TqMetaHandle* handle) { + return 0; +} + +TqMetaHandle* tqHandleGetInTxn(TqMetaStore* pMeta, int64_t key) { + return NULL; +} + +int32_t tqHandleCommit(TqMetaStore* pMeta, int64_t key) { + return 0; +} + +int32_t tqHandleAbort(TqMetaStore* pMeta, int64_t key) { + return 0; +} + +int32_t tqHandleDel(TqMetaStore* pMeta, int64_t key) { + return 0; +} + +int32_t tqHandleClear(TqMetaStore* pMeta, int64_t key) { + return 0; +} From bc6bee69b1f86ccac7931012bb00de3e2edf6d23 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 1 Nov 2021 16:04:58 +0800 Subject: [PATCH 07/17] refact --- source/server/vnode/CMakeLists.txt | 24 +------------------ source/server/vnode/impl/CMakeLists.txt | 22 +++++++++++++++++ .../server/vnode/{ => impl}/inc/vnodeCommit.h | 0 .../server/vnode/{ => impl}/inc/vnodeFile.h | 0 source/server/vnode/{ => impl}/inc/vnodeInt.h | 0 .../server/vnode/{ => impl}/inc/vnodeMain.h | 0 .../vnode/{ => impl}/inc/vnodeMemAllocator.h | 0 .../server/vnode/{ => impl}/inc/vnodeMgmt.h | 0 .../server/vnode/{ => impl}/inc/vnodeRead.h | 0 .../vnode/{ => impl}/inc/vnodeReadMsg.h | 0 .../server/vnode/{ => impl}/inc/vnodeWrite.h | 0 .../vnode/{ => impl}/inc/vnodeWriteMsg.h | 0 .../server/vnode/{ => impl}/src/vnodeCommit.c | 0 .../server/vnode/{ => impl}/src/vnodeFile.c | 0 source/server/vnode/{ => impl}/src/vnodeInt.c | 0 .../server/vnode/{ => impl}/src/vnodeMain.c | 0 .../vnode/{ => impl}/src/vnodeMemAllocator.c | 0 .../server/vnode/{ => impl}/src/vnodeMgmt.c | 0 .../server/vnode/{ => impl}/src/vnodeRead.c | 0 .../vnode/{ => impl}/src/vnodeReadMsg.c | 0 .../server/vnode/{ => impl}/src/vnodeWrite.c | 0 .../vnode/{ => impl}/src/vnodeWriteMsg.c | 0 .../vnode/{ => impl}/test/CMakeLists.txt | 0 .../{ => impl}/test/vnodeMemAllocatorTest.cpp | 0 .../vnode/{ => impl}/test/vnodeTests.cpp | 0 25 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 source/server/vnode/impl/CMakeLists.txt rename source/server/vnode/{ => impl}/inc/vnodeCommit.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeFile.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeInt.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeMain.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeMemAllocator.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeMgmt.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeRead.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeReadMsg.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeWrite.h (100%) rename source/server/vnode/{ => impl}/inc/vnodeWriteMsg.h (100%) rename source/server/vnode/{ => impl}/src/vnodeCommit.c (100%) rename source/server/vnode/{ => impl}/src/vnodeFile.c (100%) rename source/server/vnode/{ => impl}/src/vnodeInt.c (100%) rename source/server/vnode/{ => impl}/src/vnodeMain.c (100%) rename source/server/vnode/{ => impl}/src/vnodeMemAllocator.c (100%) rename source/server/vnode/{ => impl}/src/vnodeMgmt.c (100%) rename source/server/vnode/{ => impl}/src/vnodeRead.c (100%) rename source/server/vnode/{ => impl}/src/vnodeReadMsg.c (100%) rename source/server/vnode/{ => impl}/src/vnodeWrite.c (100%) rename source/server/vnode/{ => impl}/src/vnodeWriteMsg.c (100%) rename source/server/vnode/{ => impl}/test/CMakeLists.txt (100%) rename source/server/vnode/{ => impl}/test/vnodeMemAllocatorTest.cpp (100%) rename source/server/vnode/{ => impl}/test/vnodeTests.cpp (100%) diff --git a/source/server/vnode/CMakeLists.txt b/source/server/vnode/CMakeLists.txt index 573cea79b5..a4a9cff002 100644 --- a/source/server/vnode/CMakeLists.txt +++ b/source/server/vnode/CMakeLists.txt @@ -1,26 +1,4 @@ add_subdirectory(meta) add_subdirectory(tq) add_subdirectory(tsdb) - -aux_source_directory(src VNODE_SRC) -add_library(vnode STATIC ${VNODE_SRC}) -target_include_directories( - vnode - PUBLIC "${CMAKE_SOURCE_DIR}/include/server/vnode" - private "${CMAKE_CURRENT_SOURCE_DIR}/inc" -) -target_link_libraries( - vnode - PUBLIC transport - PUBLIC meta - PUBLIC tq - PUBLIC tsdb - PUBLIC wal - PUBLIC sync - PUBLIC cjson -) - -# test -if(${BUILD_TEST}) - add_subdirectory(test) -endif(${BUILD_TEST}) \ No newline at end of file +add_subdirectory(impl) \ No newline at end of file diff --git a/source/server/vnode/impl/CMakeLists.txt b/source/server/vnode/impl/CMakeLists.txt new file mode 100644 index 0000000000..81744df79c --- /dev/null +++ b/source/server/vnode/impl/CMakeLists.txt @@ -0,0 +1,22 @@ +aux_source_directory(src VNODE_SRC) +add_library(vnode STATIC ${VNODE_SRC}) +target_include_directories( + vnode + PUBLIC "${CMAKE_SOURCE_DIR}/include/server/vnode" + private "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + vnode + PUBLIC transport + PUBLIC meta + PUBLIC tq + PUBLIC tsdb + PUBLIC wal + PUBLIC sync + PUBLIC cjson +) + +# test +if(${BUILD_TEST}) + add_subdirectory(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/server/vnode/inc/vnodeCommit.h b/source/server/vnode/impl/inc/vnodeCommit.h similarity index 100% rename from source/server/vnode/inc/vnodeCommit.h rename to source/server/vnode/impl/inc/vnodeCommit.h diff --git a/source/server/vnode/inc/vnodeFile.h b/source/server/vnode/impl/inc/vnodeFile.h similarity index 100% rename from source/server/vnode/inc/vnodeFile.h rename to source/server/vnode/impl/inc/vnodeFile.h diff --git a/source/server/vnode/inc/vnodeInt.h b/source/server/vnode/impl/inc/vnodeInt.h similarity index 100% rename from source/server/vnode/inc/vnodeInt.h rename to source/server/vnode/impl/inc/vnodeInt.h diff --git a/source/server/vnode/inc/vnodeMain.h b/source/server/vnode/impl/inc/vnodeMain.h similarity index 100% rename from source/server/vnode/inc/vnodeMain.h rename to source/server/vnode/impl/inc/vnodeMain.h diff --git a/source/server/vnode/inc/vnodeMemAllocator.h b/source/server/vnode/impl/inc/vnodeMemAllocator.h similarity index 100% rename from source/server/vnode/inc/vnodeMemAllocator.h rename to source/server/vnode/impl/inc/vnodeMemAllocator.h diff --git a/source/server/vnode/inc/vnodeMgmt.h b/source/server/vnode/impl/inc/vnodeMgmt.h similarity index 100% rename from source/server/vnode/inc/vnodeMgmt.h rename to source/server/vnode/impl/inc/vnodeMgmt.h diff --git a/source/server/vnode/inc/vnodeRead.h b/source/server/vnode/impl/inc/vnodeRead.h similarity index 100% rename from source/server/vnode/inc/vnodeRead.h rename to source/server/vnode/impl/inc/vnodeRead.h diff --git a/source/server/vnode/inc/vnodeReadMsg.h b/source/server/vnode/impl/inc/vnodeReadMsg.h similarity index 100% rename from source/server/vnode/inc/vnodeReadMsg.h rename to source/server/vnode/impl/inc/vnodeReadMsg.h diff --git a/source/server/vnode/inc/vnodeWrite.h b/source/server/vnode/impl/inc/vnodeWrite.h similarity index 100% rename from source/server/vnode/inc/vnodeWrite.h rename to source/server/vnode/impl/inc/vnodeWrite.h diff --git a/source/server/vnode/inc/vnodeWriteMsg.h b/source/server/vnode/impl/inc/vnodeWriteMsg.h similarity index 100% rename from source/server/vnode/inc/vnodeWriteMsg.h rename to source/server/vnode/impl/inc/vnodeWriteMsg.h diff --git a/source/server/vnode/src/vnodeCommit.c b/source/server/vnode/impl/src/vnodeCommit.c similarity index 100% rename from source/server/vnode/src/vnodeCommit.c rename to source/server/vnode/impl/src/vnodeCommit.c diff --git a/source/server/vnode/src/vnodeFile.c b/source/server/vnode/impl/src/vnodeFile.c similarity index 100% rename from source/server/vnode/src/vnodeFile.c rename to source/server/vnode/impl/src/vnodeFile.c diff --git a/source/server/vnode/src/vnodeInt.c b/source/server/vnode/impl/src/vnodeInt.c similarity index 100% rename from source/server/vnode/src/vnodeInt.c rename to source/server/vnode/impl/src/vnodeInt.c diff --git a/source/server/vnode/src/vnodeMain.c b/source/server/vnode/impl/src/vnodeMain.c similarity index 100% rename from source/server/vnode/src/vnodeMain.c rename to source/server/vnode/impl/src/vnodeMain.c diff --git a/source/server/vnode/src/vnodeMemAllocator.c b/source/server/vnode/impl/src/vnodeMemAllocator.c similarity index 100% rename from source/server/vnode/src/vnodeMemAllocator.c rename to source/server/vnode/impl/src/vnodeMemAllocator.c diff --git a/source/server/vnode/src/vnodeMgmt.c b/source/server/vnode/impl/src/vnodeMgmt.c similarity index 100% rename from source/server/vnode/src/vnodeMgmt.c rename to source/server/vnode/impl/src/vnodeMgmt.c diff --git a/source/server/vnode/src/vnodeRead.c b/source/server/vnode/impl/src/vnodeRead.c similarity index 100% rename from source/server/vnode/src/vnodeRead.c rename to source/server/vnode/impl/src/vnodeRead.c diff --git a/source/server/vnode/src/vnodeReadMsg.c b/source/server/vnode/impl/src/vnodeReadMsg.c similarity index 100% rename from source/server/vnode/src/vnodeReadMsg.c rename to source/server/vnode/impl/src/vnodeReadMsg.c diff --git a/source/server/vnode/src/vnodeWrite.c b/source/server/vnode/impl/src/vnodeWrite.c similarity index 100% rename from source/server/vnode/src/vnodeWrite.c rename to source/server/vnode/impl/src/vnodeWrite.c diff --git a/source/server/vnode/src/vnodeWriteMsg.c b/source/server/vnode/impl/src/vnodeWriteMsg.c similarity index 100% rename from source/server/vnode/src/vnodeWriteMsg.c rename to source/server/vnode/impl/src/vnodeWriteMsg.c diff --git a/source/server/vnode/test/CMakeLists.txt b/source/server/vnode/impl/test/CMakeLists.txt similarity index 100% rename from source/server/vnode/test/CMakeLists.txt rename to source/server/vnode/impl/test/CMakeLists.txt diff --git a/source/server/vnode/test/vnodeMemAllocatorTest.cpp b/source/server/vnode/impl/test/vnodeMemAllocatorTest.cpp similarity index 100% rename from source/server/vnode/test/vnodeMemAllocatorTest.cpp rename to source/server/vnode/impl/test/vnodeMemAllocatorTest.cpp diff --git a/source/server/vnode/test/vnodeTests.cpp b/source/server/vnode/impl/test/vnodeTests.cpp similarity index 100% rename from source/server/vnode/test/vnodeTests.cpp rename to source/server/vnode/impl/test/vnodeTests.cpp From 2f36662750f163e7f9514d5c9e67c62007e3b11b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 19:49:44 +0800 Subject: [PATCH 08/17] remove mgmt from vnode --- include/common/taosmsg.h | 153 ++-- include/server/vnode/vnode.h | 118 +-- include/util/tqueue.h | 10 +- include/util/tworker.h | 4 +- source/libs/parser/src/parserUtil.c | 2 +- source/libs/transport/src/rpcMain.c | 8 +- source/server/dnode/src/dnodeInt.c | 16 +- source/server/dnode/src/dnodeMsg.c | 8 +- source/server/dnode/src/dnodeTrans.c | 211 +++--- source/server/mnode/src/mnodeWorker.c | 148 ++-- source/server/vnode/impl/inc/vnodeCommit.h | 2 + source/server/vnode/impl/inc/vnodeFile.h | 33 - source/server/vnode/impl/inc/vnodeInt.h | 80 +- source/server/vnode/impl/inc/vnodeMain.h | 42 -- .../server/vnode/impl/inc/vnodeMemAllocator.h | 2 +- source/server/vnode/impl/inc/vnodeMgmt.h | 40 - source/server/vnode/impl/inc/vnodeRead.h | 14 +- source/server/vnode/impl/inc/vnodeReadMsg.h | 46 -- source/server/vnode/impl/inc/vnodeWrite.h | 13 +- source/server/vnode/impl/inc/vnodeWriteMsg.h | 41 - source/server/vnode/impl/src/vnodeFile.c | 372 --------- source/server/vnode/impl/src/vnodeInt.c | 84 +-- source/server/vnode/impl/src/vnodeMain.c | 712 ------------------ source/server/vnode/impl/src/vnodeMgmt.c | 287 ------- source/server/vnode/impl/src/vnodeRead.c | 195 ----- source/server/vnode/impl/src/vnodeReadMsg.c | 342 --------- source/server/vnode/impl/src/vnodeWrite.c | 212 ------ source/server/vnode/impl/src/vnodeWriteMsg.c | 94 --- source/server/vnode/impl/test/CMakeLists.txt | 2 +- source/util/src/tqueue.c | 18 +- source/util/src/tworker.c | 12 +- src/client/src/tscServer.c | 60 +- src/client/src/tscUtil.c | 2 +- 33 files changed, 425 insertions(+), 2958 deletions(-) delete mode 100644 source/server/vnode/impl/inc/vnodeFile.h delete mode 100644 source/server/vnode/impl/inc/vnodeMain.h delete mode 100644 source/server/vnode/impl/inc/vnodeMgmt.h delete mode 100644 source/server/vnode/impl/inc/vnodeReadMsg.h delete mode 100644 source/server/vnode/impl/inc/vnodeWriteMsg.h delete mode 100644 source/server/vnode/impl/src/vnodeFile.c delete mode 100644 source/server/vnode/impl/src/vnodeMain.c delete mode 100644 source/server/vnode/impl/src/vnodeMgmt.c delete mode 100644 source/server/vnode/impl/src/vnodeReadMsg.c delete mode 100644 source/server/vnode/impl/src/vnodeWriteMsg.c diff --git a/include/common/taosmsg.h b/include/common/taosmsg.h index d571153c1a..dde737162b 100644 --- a/include/common/taosmsg.h +++ b/include/common/taosmsg.h @@ -40,87 +40,112 @@ enum { TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SUBMIT, "submit" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_QUERY, "query" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_FETCH, "fetch" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_TABLE, "create-table" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TABLE, "drop-table" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_TABLE, "alter-table" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_UPDATE_TAG_VAL, "update-tag-val" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONNECT, "mq-connect" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TABLE_META, "table-meta" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_TABLES_META, "tables-meta" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_STABLE_VGROUP, "stable-vgroup" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONSUME, "mq-consume" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_QUERY, "mq-query" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONNECT, "mq-connect" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_ACK, "mq-ack" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_RESET, "mq-reset" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY0, "dummy0" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY1, "dummy1" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY2, "dummy2" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY3, "dummy3" ) - -// message from mnode to dnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_CREATE_TABLE, "create-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_TABLE, "drop-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_TABLE, "alter-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_CREATE_VNODE, "create-vnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_VNODE, "drop-vnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_DROP_STABLE, "drop-stable" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_STREAM, "alter-stream" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_CONFIG_DNODE, "config-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_ALTER_VNODE, "alter-vnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_SYNC_VNODE, "sync-vnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_CREATE_MNODE, "create-mnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MD_COMPACT_VNODE, "compact-vnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY4, "dummy4" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY5, "dummy5" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY6, "dummy6" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY7, "dummy7" ) - - -// message from client to mnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CONNECT, "connect" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_ACCT, "create-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_ALTER_ACCT, "alter-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_ACCT, "drop-acct" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_USER, "create-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_ALTER_USER, "alter-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_USER, "drop-user" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_DNODE, "create-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_DNODE, "drop-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_DB, "create-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_FUNCTION, "create-function" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_DB, "drop-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_FUNCTION, "drop-function" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_USE_DB, "use-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_ALTER_DB, "alter-db" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_SYNC_DB, "sync-db-replica" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_TABLE, "create-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_TABLE, "drop-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_ALTER_TABLE, "alter-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_TABLE_META, "table-meta" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_STABLE_VGROUP, "stable-vgroup" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_COMPACT_VNODE, "compact-vnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_TABLES_META, "multiTable-meta" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_ALTER_STREAM, "alter-stream" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_SHOW, "show" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_RETRIEVE, "retrieve" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_KILL_QUERY, "kill-query" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_KILL_STREAM, "kill-stream" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_KILL_CONN, "kill-conn" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CONFIG_DNODE, "cm-config-dnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_HEARTBEAT, "heartbeat" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_RETRIEVE_FUNC, "retrieve-func" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY8, "dummy8" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY9, "dummy9" ) + +// message from mnode to dnode +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STABLE_IN, "create-stable" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STABLE_IN, "alter-stable" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STABLE_IN, "drop-stable" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_VNODE_IN, "create-vnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_VNODE_IN, "alter-vnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_VNODE_IN, "drop-vnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_VNODE_IN, "sync-vnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_VNODE_IN, "compact-vnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE_IN, "create-mnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_MNODE_IN, "drop-mnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE_IN, "config-dnode" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY10, "dummy10" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY11, "dummy11" ) - -// message from dnode to mnode -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DM_CONFIG_TABLE, "config-table" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DM_CONFIG_VNODE, "config-vnode" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DM_STATUS, "status" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DM_GRANT, "grant" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DM_AUTH, "auth" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY12, "dummy12" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY13, "dummy13" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY14, "dummy14" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY15, "dummy15" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY16, "dummy16" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY17, "dummy17" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY18, "dummy18" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY19, "dummy19" ) -// message for topic -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_CREATE_TP, "create-tp" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_DROP_TP, "drop-tp" ) -//TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_USE_TP, "use-tp" ) -TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CM_ALTER_TP, "alter-tp" ) + +// message from client to mnode +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONNECT, "connect" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_ACCT, "create-acct" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_ACCT, "alter-acct" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_ACCT, "drop-acct" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_USER, "create-user" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_USER, "alter-user" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_USER, "drop-user" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DNODE, "create-dnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE, "config-dnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DNODE, "drop-dnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_DB, "create-db" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_DB, "drop-db" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_USE_DB, "use-db" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_DB, "alter-db" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_DB, "sync-db" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_TOPIC, "create-topic" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_TOPIC, "drop-topic" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_TOPIC, "alter-topic" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_FUNCTION, "create-function" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_FUNCTION, "alter-function" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_FUNCTION, "drop-function" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STABLE, "create-stable" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STABLE, "drop-stable" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STABLE, "alter-stable" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_HEARTBEAT, "heartbeat" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW, "show" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW_RETRIEVE, "retrieve" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW_RETRIEVE_FUNC, "retrieve-func" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_VNODE, "compact-vnode" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY20, "dummy20" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY21, "dummy21" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY22, "dummy22" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY23, "dummy23" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY24, "dummy24" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY25, "dummy25" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY26, "dummy26" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY27, "dummy27" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY28, "dummy28" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY29, "dummy29" ) + +// message from dnode to mnode +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DM_STATUS, "status" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DM_GRANT, "grant" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DM_AUTH, "auth" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY30, "dummy30" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY31, "dummy31" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY32, "dummy32" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY33, "dummy33" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY34, "dummy34" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY35, "dummy35" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY36, "dummy36" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY37, "dummy37" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY38, "dummy38" ) +TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DUMMY39, "dummy39" ) #ifndef TAOS_MESSAGE_C TSDB_MSG_TYPE_MAX // 147 diff --git a/include/server/vnode/vnode.h b/include/server/vnode/vnode.h index ecb1412b06..36112a2cf8 100644 --- a/include/server/vnode/vnode.h +++ b/include/server/vnode/vnode.h @@ -16,93 +16,111 @@ #ifndef _TD_VNODE_H_ #define _TD_VNODE_H_ +#include "os.h" +#include "taosmsg.h" +#include "trpc.h" + #ifdef __cplusplus extern "C" { #endif -typedef struct { - /** - * Send messages to other dnodes, such as create vnode message. - * - * @param epSet, the endpoint list of dnodes. - * @param rpcMsg, message to be sent. - */ - void (*SendMsgToDnode)(struct SRpcEpSet *epSet, struct SRpcMsg *rpcMsg); - - /** - * Send messages to mnode, such as config message. - * - * @param rpcMsg, message to be sent. - */ - void (*SendMsgToMnode)(struct SRpcMsg *rpcMsg); - - /** - * Get the corresponding endpoint information from dnodeId. - * - * @param dnodeId, the id ot dnode. - * @param ep, the endpoint of dnode. - * @param fqdn, the fqdn of dnode. - * @param port, the port of dnode. - */ - void (*GetDnodeEp)(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port); - - /** - * Report the startup progress. - */ - void (*ReportStartup)(char *name, char *desc); - -} SVnodeFp; +typedef struct SVnode SVnode; typedef struct { - SVnodeFp fp; -} SVnodePara; + char dbName[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; + int32_t cacheBlockSize; // MB + int32_t totalBlocks; + int32_t daysPerFile; + int32_t daysToKeep0; + int32_t daysToKeep1; + int32_t daysToKeep2; + int32_t minRowsPerFileBlock; + int32_t maxRowsPerFileBlock; + int8_t precision; // time resolution + int8_t compression; + int8_t cacheLastRow; + int8_t update; + int8_t quorum; + int8_t replica; + int8_t walLevel; + int32_t fsyncPeriod; // millisecond + SVnodeDesc replicas[TSDB_MAX_REPLICA]; +} SVnodeCfg; + +typedef struct { + int64_t totalStorage; + int64_t compStorage; + int64_t pointsWritten; + int64_t tablesNum; +} SVnodeStatisic; + +typedef struct { + int8_t syncRole; +} SVnodeStatus; + +typedef struct { + int32_t accessState; +} SVnodeAccess; + +typedef struct SVnodeMsg { + int32_t msgType; + int32_t code; + SRpcMsg rpcMsg; // original message from rpc + int32_t contLen; + char pCont[]; +} SVnodeMsg; /** * Start initialize vnode module. * - * @param para, initialization parameters. * @return Error code. */ -int32_t vnodeInit(SVnodePara para); +int32_t vnodeInit(); /** * Cleanup vnode module. */ void vnodeCleanup(); -typedef struct { - int32_t unused; -} SVnodeStat; - /** * Get the statistical information of vnode. * - * @param stat, statistical information. + * @param pVnode, + * @param pStat, statistical information. * @return Error Code. */ -int32_t vnodeGetStatistics(SVnodeStat *stat); +int32_t vnodeGetStatistics(SVnode *pVnode, SVnodeStatisic *pStat); /** * Get the status of all vnodes. * - * @param status, status msg. + * @param pVnode, + * @param status, status information. + * @return Error Code. */ -void vnodeGetStatus(struct SStatusMsg *status); +int32_t vnodeGetStatus(SVnode *pVnode, SVnodeStatus *pStatus); /** - * Set access permissions for all vnodes. + * Operation functions of vnode * - * @param access, access permissions of vnodes. - * @param numOfVnodes, the size of vnodes. + * @return Error Code. */ -void vnodeSetAccess(struct SVgroupAccess *access, int32_t numOfVnodes); +SVnode *vnodeOpen(int32_t vgId, const char *path); +void vnodeClose(SVnode *pVnode); +int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg); +SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg); +int32_t vnodeDrop(SVnode *pVnode); +int32_t vnodeCompact(SVnode *pVnode); +int32_t vnodeSync(SVnode *pVnode); /** * Interface for processing messages. * - * @param msg, message to be processed. + * @param pVnode, + * @param pMsg, message to be processed. + * */ -void vnodeProcessMsg(SRpcMsg *msg); +int32_t vnodeProcessMsg(SVnode *pVnode, SVnodeMsg *pMsg); #ifdef __cplusplus } diff --git a/include/util/tqueue.h b/include/util/tqueue.h index dc16222c2b..faac1afe70 100644 --- a/include/util/tqueue.h +++ b/include/util/tqueue.h @@ -40,12 +40,12 @@ shall be used to set up the protection. typedef void *taos_queue; typedef void *taos_qset; typedef void *taos_qall; -typedef void *(*FProcessOneItem)(void *pItem, void *ahandle); -typedef void *(*FProcessAllItem)(taos_qall qall, int numOfItems, void *ahandle); +typedef void *(*FProcessItem)(void *pItem, void *ahandle); +typedef void *(*FProcessItems)(taos_qall qall, int numOfItems, void *ahandle); taos_queue taosOpenQueue(); void taosCloseQueue(taos_queue); -void taosSetQueueFp(taos_queue, FProcessOneItem, FProcessAllItem fp); +void taosSetQueueFp(taos_queue, FProcessItem, FProcessItems); void *taosAllocateQitem(int size); void taosFreeQitem(void *pItem); int taosWriteQitem(taos_queue, void *pItem); @@ -64,8 +64,8 @@ int taosAddIntoQset(taos_qset, taos_queue, void *ahandle); void taosRemoveFromQset(taos_qset, taos_queue); int taosGetQueueNumber(taos_qset); -int taosReadQitemFromQset(taos_qset, void **pItem, void **ahandle, FProcessOneItem *); -int taosReadAllQitemsFromQset(taos_qset, taos_qall, void **ahandle, FProcessAllItem *); +int taosReadQitemFromQset(taos_qset, void **pItem, void **ahandle, FProcessItem *); +int taosReadAllQitemsFromQset(taos_qset, taos_qall, void **ahandle, FProcessItems *); int taosGetQueueItemsNumber(taos_queue param); int taosGetQsetItemsNumber(taos_qset param); diff --git a/include/util/tworker.h b/include/util/tworker.h index 591ebf8967..9b0fe4f3a5 100644 --- a/include/util/tworker.h +++ b/include/util/tworker.h @@ -56,12 +56,12 @@ typedef struct SMWorkerPool { int32_t tWorkerInit(SWorkerPool *pool); void tWorkerCleanup(SWorkerPool *pool); -taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessOneItem fp); +taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessItem fp); void tWorkerFreeQueue(SWorkerPool *pool, taos_queue queue); int32_t tMWorkerInit(SMWorkerPool *pool); void tMWorkerCleanup(SMWorkerPool *pool); -taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessAllItem fp); +taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessItems fp); void tMWorkerFreeQueue(SMWorkerPool *pool, taos_queue queue); #ifdef __cplusplus diff --git a/source/libs/parser/src/parserUtil.c b/source/libs/parser/src/parserUtil.c index c970283ca7..0bef796026 100644 --- a/source/libs/parser/src/parserUtil.c +++ b/source/libs/parser/src/parserUtil.c @@ -1841,7 +1841,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt SSqlCmd *pCmd = &pSql->cmd; pCmd->command = TSDB_SQL_MULTI_META; - pCmd->msgType = TSDB_MSG_TYPE_CM_TABLES_META; + pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; char *str = (char *)pNameList; diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index fb555ea33f..eecde288b1 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -403,10 +403,10 @@ void rpcSendRequest(void *shandle, const SRpcEpSet *pEpSet, SRpcMsg *pMsg, int64 // connection type is application specific. // for TDengine, all the query, show commands shall have TCP connection char type = pMsg->msgType; - if (type == TSDB_MSG_TYPE_QUERY || type == TSDB_MSG_TYPE_CM_RETRIEVE - || type == TSDB_MSG_TYPE_FETCH || type == TSDB_MSG_TYPE_CM_STABLE_VGROUP - || type == TSDB_MSG_TYPE_CM_TABLES_META || type == TSDB_MSG_TYPE_CM_TABLE_META - || type == TSDB_MSG_TYPE_CM_SHOW || type == TSDB_MSG_TYPE_DM_STATUS || type == TSDB_MSG_TYPE_CM_ALTER_TABLE) + if (type == TSDB_MSG_TYPE_QUERY || type == TSDB_MSG_TYPE_SHOW_RETRIEVE + || type == TSDB_MSG_TYPE_FETCH || type == TSDB_MSG_TYPE_STABLE_VGROUP + || type == TSDB_MSG_TYPE_TABLES_META || type == TSDB_MSG_TYPE_TABLE_META + || type == TSDB_MSG_TYPE_SHOW || type == TSDB_MSG_TYPE_DM_STATUS || type == TSDB_MSG_TYPE_ALTER_TABLE) pContext->connType = RPC_CONN_TCPC; pContext->rid = taosAddRef(tsRpcRefId, pContext); diff --git a/source/server/dnode/src/dnodeInt.c b/source/server/dnode/src/dnodeInt.c index 7b0b87368e..1166a06d38 100644 --- a/source/server/dnode/src/dnodeInt.c +++ b/source/server/dnode/src/dnodeInt.c @@ -54,13 +54,7 @@ static void dnodeReportStartupFinished(char *name, char *desc) { void dnodeGetStartup(SStartupStep *pStep) { memcpy(pStep, &tsDnode.startup, sizeof(SStartupStep)); } static int32_t dnodeInitVnode() { - SVnodePara para; - para.fp.GetDnodeEp = dnodeGetEp; - para.fp.SendMsgToDnode = dnodeSendMsgToDnode; - para.fp.SendMsgToMnode = dnodeSendMsgToMnode; - para.fp.ReportStartup = dnodeReportStartup; - - return vnodeInit(para); + return vnodeInit(); } static int32_t dnodeInitMnode() { @@ -200,3 +194,11 @@ void dnodeCleanup() { tsDnode.steps = NULL; } } + +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMgmtMsg; + \ No newline at end of file diff --git a/source/server/dnode/src/dnodeMsg.c b/source/server/dnode/src/dnodeMsg.c index 6df01a5b7f..a5c3db5e14 100644 --- a/source/server/dnode/src/dnodeMsg.c +++ b/source/server/dnode/src/dnodeMsg.c @@ -52,9 +52,9 @@ static void dnodeSendStatusMsg() { tstrncpy(pStatus->clusterCfg.locale, tsLocale, TSDB_LOCALE_LEN); tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN); - vnodeGetStatus(pStatus); - contLen = sizeof(SStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad); - pStatus->openVnodes = htons(pStatus->openVnodes); + // vnodeGetStatus(NULL, pStatus); + // contLen = sizeof(SStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad); + // pStatus->openVnodes = htons(pStatus->openVnodes); SRpcMsg rpcMsg = {.ahandle = NULL, .pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_DM_STATUS}; @@ -79,7 +79,7 @@ void dnodeProcessStatusRsp(SRpcMsg *pMsg) { return; } - vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes); + // vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes); SDnodeEps *eps = (SDnodeEps *)((char *)pStatusRsp->vgAccess + pCfg->numOfVnodes * sizeof(SVgroupAccess)); eps->dnodeNum = htonl(eps->dnodeNum); diff --git a/source/server/dnode/src/dnodeTrans.c b/source/server/dnode/src/dnodeTrans.c index 4eba31ab68..3e32510df9 100644 --- a/source/server/dnode/src/dnodeTrans.c +++ b/source/server/dnode/src/dnodeTrans.c @@ -26,18 +26,101 @@ #include "mnode.h" #include "vnode.h" -typedef void (*RpcMsgFp)(SRpcMsg *pMsg); +typedef void (*MsgFp)(SRpcMsg *pMsg); static struct { - void *serverRpc; - void *clientRpc; - void *shellRpc; - int32_t queryReqNum; - int32_t submitReqNum; - RpcMsgFp peerMsgFp[TSDB_MSG_TYPE_MAX]; - RpcMsgFp shellMsgFp[TSDB_MSG_TYPE_MAX]; + void *serverRpc; + void *clientRpc; + void *shellRpc; + MsgFp msgFp[TSDB_MSG_TYPE_MAX]; } tsTrans; +static void dnodeInitMsgFp() { + // msg from client to dnode + tsTrans.msgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_TABLE] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_TABLE_META] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_TABLES_META] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeProcessStartupReq; + + // msg from client to mnode + tsTrans.msgFp[TSDB_MSG_TYPE_CONNECT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_ACCT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_USER] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_USER] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_USER] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_DNODE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_USE_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_TOPIC] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_TOPIC] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_TOPIC] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_FUNCTION] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_KILL_QUERY] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_KILL_CONN] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_HEARTBEAT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SHOW] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE_FUNC] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = mnodeProcessMsg; + + // message from mnode to dnode + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN] = dnodeProcessCreateMnodeReq; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN] = NULL; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN] = NULL; + tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = mnodeProcessMsg; + + // message from dnode to mnode + tsTrans.msgFp[TSDB_MSG_TYPE_DM_AUTH] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_AUTH_RSP] = NULL; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_GRANT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_GRANT_RSP] = NULL; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_STATUS] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_STATUS_RSP] = dnodeProcessStatusRsp; +} + static void dnodeProcessPeerReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0}; int32_t msgType = pMsg->msgType; @@ -61,7 +144,7 @@ static void dnodeProcessPeerReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { return; } - RpcMsgFp fp = tsTrans.peerMsgFp[msgType]; + MsgFp fp = tsTrans.msgFp[msgType]; if (fp != NULL) { dTrace("RPC %p, peer req:%s will be processed", pMsg->handle, taosMsg[msgType]); (*fp)(pMsg); @@ -74,35 +157,6 @@ static void dnodeProcessPeerReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { } static int32_t dnodeInitServer() { - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_TABLE] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = vnodeProcessMsg; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMsg; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMsg; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE] = dnodeProcessConfigDnodeReq; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_MNODE] = dnodeProcessCreateMnodeReq; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_AUTH] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_GRANT] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_STATUS] = mnodeProcessMsg; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessMsg; - SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.localPort = tsDnodeDnodePort; @@ -145,7 +199,7 @@ static void dnodeProcessPeerRsp(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { dnodeUpdateMnodeEps(pEpSet); } - RpcMsgFp fp = tsTrans.peerMsgFp[msgType]; + MsgFp fp = tsTrans.msgFp[msgType]; if (fp != NULL) { dTrace("RPC %p, peer rsp:%s will be processed", pMsg->handle, taosMsg[msgType]); (*fp)(pMsg); @@ -157,28 +211,6 @@ static void dnodeProcessPeerRsp(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { } static int32_t dnodeInitClient() { - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_TABLE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_STABLE_RSP] = mnodeProcessMsg; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_DROP_VNODE_RSP] = mnodeProcessMsg; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM_RSP] = mnodeProcessMsg; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CONFIG_DNODE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_MD_CREATE_MNODE_RSP] = mnodeProcessMsg; - - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_TABLE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_CONFIG_VNODE_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_AUTH_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_GRANT_RSP] = mnodeProcessMsg; - tsTrans.peerMsgFp[TSDB_MSG_TYPE_DM_STATUS_RSP] = dnodeProcessStatusRsp; - char secret[TSDB_KEY_LEN] = "secret"; SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); @@ -234,14 +266,7 @@ static void dnodeProcessShellReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { return; } - if (msgType == TSDB_MSG_TYPE_QUERY) { - atomic_fetch_add_32(&tsTrans.queryReqNum, 1); - } else if (msgType == TSDB_MSG_TYPE_SUBMIT) { - atomic_fetch_add_32(&tsTrans.submitReqNum, 1); - } else { - } - - RpcMsgFp fp = tsTrans.shellMsgFp[msgType]; + MsgFp fp = tsTrans.msgFp[msgType]; if (fp != NULL) { dTrace("RPC %p, shell req:%s will be processed", pMsg->handle, taosMsg[msgType]); (*fp)(pMsg); @@ -299,54 +324,6 @@ static int32_t dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, c } static int32_t dnodeInitShell() { - tsTrans.shellMsgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessMsg; - - // the following message shall be treated as mnode write - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_ACCT] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_ACCT] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_ACCT] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_USER] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_USER] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_USER] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_DNODE] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_DNODE] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_DB] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_TP] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_FUNCTION] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_DB] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_SYNC_DB] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_TP] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_FUNCTION] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_DB] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_TP] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CREATE_TABLE] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_DROP_TABLE] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_TABLE] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_ALTER_STREAM] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_QUERY] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_STREAM] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CONFIG_DNODE] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_COMPACT_VNODE] = mnodeProcessMsg; - - // the following message shall be treated as mnode query - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_HEARTBEAT] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_CONNECT] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_USE_DB] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_TABLE_META] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_STABLE_VGROUP] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_TABLES_META] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_SHOW] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE] = mnodeProcessMsg; - tsTrans.shellMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE_FUNC] = mnodeProcessMsg; - - tsTrans.shellMsgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeProcessStartupReq; - int32_t numOfThreads = (int32_t)((tsNumOfCores * tsNumOfThreadsPerCore) / 2.0); if (numOfThreads < 1) { numOfThreads = 1; diff --git a/source/server/mnode/src/mnodeWorker.c b/source/server/mnode/src/mnodeWorker.c index fc370538aa..a477a11f7c 100644 --- a/source/server/mnode/src/mnodeWorker.c +++ b/source/server/mnode/src/mnodeWorker.c @@ -201,87 +201,87 @@ static void mnodeInitMsgFp() { // tsMworker.peerRspFp[TSDB_MSG_TYPE_MD_DROP_VNODE_RSP] = mnodeProcessDropVnodeRsp; // // read msg -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_HEARTBEAT] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_HEARTBEAT] = mnodeProcessHeartBeatMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CONNECT] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_CONNECT] = mnodeProcessConnectMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_USE_DB] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_USE_DB] = mnodeProcessUseMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_HEARTBEAT] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_HEARTBEAT] = mnodeProcessHeartBeatMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_CONNECT] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_CONNECT] = mnodeProcessConnectMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_USE_DB] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_USE_DB] = mnodeProcessUseMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_TABLE_META] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_TABLE_META] = mnodeProcessTableMetaMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_TABLES_META] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_TABLES_META] = mnodeProcessMultiTableMetaMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_STABLE_VGROUP] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_STABLE_VGROUP] = mnodeProcessSuperTableVgroupMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_TABLE_META] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_TABLE_META] = mnodeProcessTableMetaMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_TABLES_META] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_TABLES_META] = mnodeProcessMultiTableMetaMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = mnodeProcessSuperTableVgroupMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_SHOW] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_SHOW] = mnodeProcessShowMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_RETRIEVE] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE] = mnodeProcessRetrieveMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_RETRIEVE_FUNC] = mnodeDispatchToReadQueue; -// tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_RETRIEVE_FUNC] = mnodeProcessRetrieveFuncReq; +// tsMworker.msgFp[TSDB_MSG_TYPE_SHOW] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_SHOW] = mnodeProcessShowMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = mnodeProcessRetrieveMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_RETRIEVE_FUNC] = mnodeDispatchToReadQueue; +// tsMworker.readMsgFp[TSDB_MSG_TYPE_RETRIEVE_FUNC] = mnodeProcessRetrieveFuncReq; -// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_ACCT] = mnodeDispatchToWriteQueue; -// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_CREATE_ACCT] = acctProcessCreateAcctMsg; -// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_ACCT] = mnodeDispatchToWriteQueue; -// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_ALTER_ACCT] = acctProcessDropAcctMsg; -// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_ACCT] = mnodeDispatchToWriteQueue; -// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_DROP_ACCT] = acctProcessAlterAcctMsg; +// // tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = mnodeDispatchToWriteQueue; +// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CREATE_ACCT] = acctProcessCreateAcctMsg; +// // tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = mnodeDispatchToWriteQueue; +// // tsMworker.readMsgFp[TSDB_MSG_TYPE_ALTER_ACCT] = acctProcessDropAcctMsg; +// // tsMworker.msgFp[TSDB_MSG_TYPE_DROP_ACCT] = mnodeDispatchToWriteQueue; +// // tsMworker.readMsgFp[TSDB_MSG_TYPE_DROP_ACCT] = acctProcessAlterAcctMsg; // // write msg -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_USER] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_USER] = mnodeProcessCreateUserMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_USER] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_ALTER_USER] = mnodeProcessAlterUserMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_USER] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_USER] = mnodeProcessDropUserMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_USER] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_USER] = mnodeProcessCreateUserMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_USER] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_ALTER_USER] = mnodeProcessAlterUserMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_USER] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_USER] = mnodeProcessDropUserMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_DNODE] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_DNODE] = mnodeProcessCreateDnodeMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_DNODE] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_DNODE] = mnodeProcessDropDnodeMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CONFIG_DNODE] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CONFIG_DNODE] = mnodeProcessCfgDnodeMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_DNODE] = mnodeProcessCreateDnodeMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_DNODE] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_DNODE] = mnodeProcessDropDnodeMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = mnodeProcessCfgDnodeMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_DB] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_DB] = mnodeProcessCreateDbMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_DB] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_ALTER_DB] = mnodeProcessAlterDbMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_DB] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_DB] = mnodeProcessDropDbMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_SYNC_DB] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_SYNC_DB] = mnodeProcessSyncDbMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_COMPACT_VNODE] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_COMPACT_VNODE] = mnodeProcessCompactMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_DB] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_DB] = mnodeProcessCreateDbMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_DB] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_ALTER_DB] = mnodeProcessAlterDbMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_DB] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_DB] = mnodeProcessDropDbMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_SYNC_DB] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_SYNC_DB] = mnodeProcessSyncDbMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = mnodeProcessCompactMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_FUNCTION] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_FUNCTION] = mnodeProcessCreateFuncMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_FUNCTION] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_FUNCTION] = mnodeProcessDropFuncMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = mnodeProcessCreateFuncMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = mnodeProcessDropFuncMsg; -// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_TP] = mnodeDispatchToWriteQueue; -// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_CREATE_TP] = tpProcessCreateTpMsg; -// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_TP] = mnodeDispatchToWriteQueue; -// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_DROP_TP] = tpProcessAlterTpMsg; -// // tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_TP] = mnodeDispatchToWriteQueue; -// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CM_ALTER_TP] = tpProcessDropTpMsg; +// // tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_TP] = mnodeDispatchToWriteQueue; +// // tsMworker.readMsgFp[TSDB_MSG_TYPE_CREATE_TP] = tpProcessCreateTpMsg; +// // tsMworker.msgFp[TSDB_MSG_TYPE_DROP_TP] = mnodeDispatchToWriteQueue; +// // tsMworker.readMsgFp[TSDB_MSG_TYPE_DROP_TP] = tpProcessAlterTpMsg; +// // tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_TP] = mnodeDispatchToWriteQueue; +// // tsMworker.readMsgFp[TSDB_MSG_TYPE_ALTER_TP] = tpProcessDropTpMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_CREATE_TABLE] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_CREATE_TABLE] = mnodeProcessCreateTableMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_DROP_TABLE] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_DROP_TABLE] = mnodeProcessDropTableMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_TABLE] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_ALTER_TABLE] = mnodeProcessAlterTableMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CREATE_TABLE] = mnodeProcessCreateTableMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_DROP_TABLE] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_DROP_TABLE] = mnodeProcessDropTableMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_ALTER_TABLE] = mnodeProcessAlterTableMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_ALTER_STREAM] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_ALTER_STREAM] = NULL; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_KILL_QUERY] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_KILL_QUERY] = mnodeProcessKillQueryMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_KILL_STREAM] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_KILL_STREAM] = mnodeProcessKillStreamMsg; -// tsMworker.msgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = mnodeDispatchToWriteQueue; -// tsMworker.writeMsgFp[TSDB_MSG_TYPE_CM_KILL_CONN] = mnodeProcessKillConnectionMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_ALTER_STREAM] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_ALTER_STREAM] = NULL; +// tsMworker.msgFp[TSDB_MSG_TYPE_KILL_QUERY] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_KILL_QUERY] = mnodeProcessKillQueryMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_KILL_STREAM] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_KILL_STREAM] = mnodeProcessKillStreamMsg; +// tsMworker.msgFp[TSDB_MSG_TYPE_KILL_CONN] = mnodeDispatchToWriteQueue; +// tsMworker.writeMsgFp[TSDB_MSG_TYPE_KILL_CONN] = mnodeProcessKillConnectionMsg; } static void mnodeProcessWriteReq(SMnMsg *pMsg, void *unused) { @@ -427,7 +427,7 @@ int32_t mnodeInitWorker() { if (tWorkerInit(pPool) != 0) { return TSDB_CODE_MND_OUT_OF_MEMORY; } else { - tsMworker.writeQ = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)mnodeProcessWriteReq); + tsMworker.writeQ = tWorkerAllocQueue(pPool, NULL, (FProcessItem)mnodeProcessWriteReq); } pPool = &tsMworker.read; @@ -439,7 +439,7 @@ int32_t mnodeInitWorker() { if (tWorkerInit(pPool) != 0) { return TSDB_CODE_MND_OUT_OF_MEMORY; } else { - tsMworker.readQ = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)mnodeProcessReadReq); + tsMworker.readQ = tWorkerAllocQueue(pPool, NULL, (FProcessItem)mnodeProcessReadReq); } pPool = &tsMworker.peerReq; @@ -449,7 +449,7 @@ int32_t mnodeInitWorker() { if (tWorkerInit(pPool) != 0) { return TSDB_CODE_MND_OUT_OF_MEMORY; } else { - tsMworker.peerReqQ = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)mnodeProcessPeerReq); + tsMworker.peerReqQ = tWorkerAllocQueue(pPool, NULL, (FProcessItem)mnodeProcessPeerReq); } pPool = &tsMworker.peerRsp; @@ -459,7 +459,7 @@ int32_t mnodeInitWorker() { if (tWorkerInit(pPool) != 0) { return TSDB_CODE_MND_OUT_OF_MEMORY; } else { - tsMworker.peerRspQ = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)mnodeProcessPeerRsp); + tsMworker.peerRspQ = tWorkerAllocQueue(pPool, NULL, (FProcessItem)mnodeProcessPeerRsp); } mInfo("mnode worker is initialized"); diff --git a/source/server/vnode/impl/inc/vnodeCommit.h b/source/server/vnode/impl/inc/vnodeCommit.h index d37c61008c..544a42f0e8 100644 --- a/source/server/vnode/impl/inc/vnodeCommit.h +++ b/source/server/vnode/impl/inc/vnodeCommit.h @@ -16,6 +16,8 @@ #ifndef _TD_VNODE_COMMIT_H_ #define _TD_VNODE_COMMIT_H_ +#include "vnodeInt.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/source/server/vnode/impl/inc/vnodeFile.h b/source/server/vnode/impl/inc/vnodeFile.h deleted file mode 100644 index bea28324ee..0000000000 --- a/source/server/vnode/impl/inc/vnodeFile.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_CFG_H_ -#define _TD_VNODE_CFG_H_ - -#ifdef __cplusplus -extern "C" { -#endif -#include "vnodeInt.h" - -int32_t vnodeReadCfg(int32_t vgId, SVnodeCfg *pCfg); -int32_t vnodeWriteCfg(int32_t vgId, SVnodeCfg *pCfg); -int32_t vnodeReadState(int32_t vgId, SSyncServerState *pState); -int32_t vnodeSaveState(int32_t vgid, SSyncServerState *pState); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_CFG_H_*/ diff --git a/source/server/vnode/impl/inc/vnodeInt.h b/source/server/vnode/impl/inc/vnodeInt.h index 90d9e7105e..d7b84be83d 100644 --- a/source/server/vnode/impl/inc/vnodeInt.h +++ b/source/server/vnode/impl/inc/vnodeInt.h @@ -16,19 +16,14 @@ #ifndef _TD_VNODE_INT_H_ #define _TD_VNODE_INT_H_ -#include "os.h" +#include "vnode.h" + #include "amalloc.h" #include "meta.h" #include "sync.h" -#include "taosmsg.h" -#include "tglobal.h" #include "tlog.h" #include "tq.h" -#include "tqueue.h" -#include "trpc.h" #include "tsdb.h" -#include "tworker.h" -#include "vnode.h" #include "wal.h" #ifdef __cplusplus @@ -44,71 +39,16 @@ extern int32_t vDebugFlag; #define vDebug(...) { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }} #define vTrace(...) { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", vDebugFlag, __VA_ARGS__); }} -typedef struct STsdbCfg { - int32_t cacheBlockSize; // MB - int32_t totalBlocks; - int32_t daysPerFile; - int32_t daysToKeep0; - int32_t daysToKeep1; - int32_t daysToKeep2; - int32_t minRowsPerFileBlock; - int32_t maxRowsPerFileBlock; - uint8_t precision; // time resolution - int8_t compression; - int8_t cacheLastRow; - int8_t update; -} STsdbCfg; - -typedef struct SMetaCfg { -} SMetaCfg; - -typedef struct SVnodeCfg { - char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; - int8_t dropped; - int8_t quorum; - SWalCfg wal; - STsdbCfg tsdb; - SMetaCfg meta; - SSyncCluster sync; -} SVnodeCfg; - -typedef struct { - int32_t vgId; // global vnode group ID - int32_t refCount; // reference count - SMemAllocator *allocator; - SMeta *pMeta; - STsdb *pTsdb; - STQ *pTQ; - SWal *pWal; - void *pQuery; - SSyncNode *pSync; - taos_queue pWriteQ; // write queue - taos_queue pQueryQ; // read query queue - taos_queue pFetchQ; // read fetch/cancel queue - SVnodeCfg cfg; - SSyncServerState term; - int64_t queuedWMsgSize; - int32_t queuedWMsg; - int32_t queuedRMsg; - int32_t numOfQHandle; // current initialized and existed query handle in current dnode - int8_t role; - int8_t accessState; - int8_t dropped; - int8_t status; - pthread_mutex_t statusMutex; +typedef struct SVnode { + int32_t vgId; + SVnodeCfg cfg; + SMeta *pMeta; + STsdb *pTsdb; + STQ *pTQ; + SWal *pWal; + SSyncNode *pSync; } SVnode; -typedef struct { - int32_t len; - void *rsp; - void *qhandle; // used by query and retrieve msg -} SVnRsp; - -void vnodeSendMsgToDnode(struct SRpcEpSet *epSet, struct SRpcMsg *rpcMsg); -void vnodeSendMsgToMnode(struct SRpcMsg *rpcMsg); -void vnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port); -void vnodeReportStartup(char *name, char *desc); - #ifdef __cplusplus } #endif diff --git a/source/server/vnode/impl/inc/vnodeMain.h b/source/server/vnode/impl/inc/vnodeMain.h deleted file mode 100644 index d0d84792e8..0000000000 --- a/source/server/vnode/impl/inc/vnodeMain.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_MAIN_H_ -#define _TD_VNODE_MAIN_H_ - -#include "vnodeInt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t vnodeInitMain(); -void vnodeCleanupMain(); - -SVnode *vnodeAcquireInAllState(int32_t vgId); -SVnode *vnodeAcquire(int32_t vgId); -void vnodeRelease(SVnode *pVnode); - -int32_t vnodeCreateVnode(int32_t vgId, SVnodeCfg *pCfg); -int32_t vnodeAlterVnode(SVnode *pVnode, SVnodeCfg *pCfg); -int32_t vnodeDropVnode(SVnode *pVnode); -int32_t vnodeSyncVnode(SVnode *pVnode); -int32_t vnodeCompactVnode(SVnode *pVnode); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_MAIN_H_*/ diff --git a/source/server/vnode/impl/inc/vnodeMemAllocator.h b/source/server/vnode/impl/inc/vnodeMemAllocator.h index ca00abc70a..76aa2c6714 100644 --- a/source/server/vnode/impl/inc/vnodeMemAllocator.h +++ b/source/server/vnode/impl/inc/vnodeMemAllocator.h @@ -16,7 +16,7 @@ #ifndef _TD_VNODE_MEM_ALLOCATOR_H_ #define _TD_VNODE_MEM_ALLOCATOR_H_ -#include "os.h" +#include "vnodeInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/server/vnode/impl/inc/vnodeMgmt.h b/source/server/vnode/impl/inc/vnodeMgmt.h deleted file mode 100644 index ccd1b28b61..0000000000 --- a/source/server/vnode/impl/inc/vnodeMgmt.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_MGMT_H_ -#define _TD_VNODE_MGMT_H_ - -#ifdef __cplusplus -extern "C" { -#endif -#include "vnodeInt.h" - - -typedef struct { - SVnode *pVnode; - SRpcMsg rpcMsg; - char pCont[]; -} SVnMgmtMsg; - - -int32_t vnodeInitMgmt(); -void vnodeCleanupMgmt(); -void vnodeProcessMgmtMsg(SRpcMsg *pMsg); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_MGMT_H_*/ diff --git a/source/server/vnode/impl/inc/vnodeRead.h b/source/server/vnode/impl/inc/vnodeRead.h index e5efae3d93..5ce84b2ebf 100644 --- a/source/server/vnode/impl/inc/vnodeRead.h +++ b/source/server/vnode/impl/inc/vnodeRead.h @@ -21,19 +21,7 @@ extern "C" { #endif #include "vnodeInt.h" -int32_t vnodeInitRead(); -void vnodeCleanupRead(); -taos_queue vnodeAllocQueryQueue(SVnode *pVnode); -taos_queue vnodeAllocFetchQueue(SVnode *pVnode); -void vnodeFreeQueryQueue(taos_queue pQueue); -void vnodeFreeFetchQueue(taos_queue pQueue); - -void vnodeProcessReadMsg(SRpcMsg *pRpcMsg); -int32_t vnodeReputPutToRQueue(SVnode *pVnode, void **qhandle, void *ahandle); - -void vnodeStartRead(SVnode *pVnode); -void vnodeStopRead(SVnode *pVnode); -void vnodeWaitReadCompleted(SVnode *pVnode); +void vnodeProcessReadMsg(SVnode *pVnode, SVnodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/server/vnode/impl/inc/vnodeReadMsg.h b/source/server/vnode/impl/inc/vnodeReadMsg.h deleted file mode 100644 index 1efc74d1af..0000000000 --- a/source/server/vnode/impl/inc/vnodeReadMsg.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_READ_MSG_H_ -#define _TD_VNODE_READ_MSG_H_ - -#ifdef __cplusplus -extern "C" { -#endif -#include "vnodeInt.h" - -typedef struct SReadMsg { - int32_t code; - int32_t contLen; - int8_t qtype; - int8_t msgType; - SVnode *pVnode; - SVnRsp rspRet; - void * rpcHandle; - void * rpcAhandle; - void * qhandle; - char pCont[]; -} SReadMsg; - -int32_t vnodeProcessQueryMsg(SVnode *pVnode, SReadMsg *pRead); -int32_t vnodeProcessFetchMsg(SVnode *pVnode, SReadMsg *pRead); -int32_t vnodeProcessConsumeMsg(SVnode *pVnode, SReadMsg *pRead); -int32_t vnodeProcessTqQueryMsg(SVnode *pVnode, SReadMsg *pRead); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_READ_MSG_H_*/ diff --git a/source/server/vnode/impl/inc/vnodeWrite.h b/source/server/vnode/impl/inc/vnodeWrite.h index 8500607694..11fe9836f6 100644 --- a/source/server/vnode/impl/inc/vnodeWrite.h +++ b/source/server/vnode/impl/inc/vnodeWrite.h @@ -21,18 +21,7 @@ extern "C" { #endif #include "vnodeInt.h" -int32_t vnodeInitWrite(); -void vnodeCleanupWrite(); - -taos_queue vnodeAllocWriteQueue(SVnode *pVnode); -void vnodeFreeWriteQueue(taos_queue pQueue); -taos_queue vnodeAllocApplyQueue(SVnode *pVnode); -void vnodeFreeApplyQueue(taos_queue pQueue); -void vnodeProcessWriteReq(SRpcMsg *pRpcMsg); - -void vnodeStartWrite(SVnode *pVnode); -void vnodeStopWrite(SVnode *pVnode); -void vnodeWaitWriteCompleted(SVnode *pVnode); +void vnodeProcessWriteMsg(SVnode* pVnode, SVnodeMsg* pMsg); #ifdef __cplusplus } diff --git a/source/server/vnode/impl/inc/vnodeWriteMsg.h b/source/server/vnode/impl/inc/vnodeWriteMsg.h deleted file mode 100644 index 9dbc4fe490..0000000000 --- a/source/server/vnode/impl/inc/vnodeWriteMsg.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_WRITE_MSG_H_ -#define _TD_VNODE_WRITE_MSG_H_ - -#ifdef __cplusplus -extern "C" { -#endif -#include "vnodeInt.h" - -int32_t vnodeProcessSubmitReq(SVnode *pVnode, SSubmitReq *pReq, SSubmitRsp *pRsp); -int32_t vnodeProcessCreateTableReq(SVnode *pVnode, SCreateTableReq *pReq, SCreateTableRsp *pRsp); -int32_t vnodeProcessDropTableReq(SVnode *pVnode, SDropTableReq *pReq, SDropTableRsp *pRsp); -int32_t vnodeProcessAlterTableReq(SVnode *pVnode, SAlterTableReq *pReq, SAlterTableRsp *pRsp); -int32_t vnodeProcessDropStableReq(SVnode *pVnode, SDropStableReq *pReq, SDropStableRsp *pRsp); -int32_t vnodeProcessUpdateTagValReq(SVnode *pVnode, SUpdateTagValReq *pReq, SUpdateTagValRsp *pRsp); -//mq related -int32_t vnodeProcessMqConnectReq(SVnode* pVnode, SMqConnectReq *pReq, SMqConnectRsp *pRsp); -int32_t vnodeProcessMqDisconnectReq(SVnode* pVnode, SMqConnectReq *pReq, SMqConnectRsp *pRsp); -int32_t vnodeProcessMqAckReq(SVnode* pVnode, SMqAckReq *pReq, SMqAckRsp *pRsp); -int32_t vnodeProcessMqResetReq(SVnode* pVnode, SMqResetReq *pReq, SMqResetRsp *pRsp); -//mq related end - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_WRITE_MSG_H_*/ diff --git a/source/server/vnode/impl/src/vnodeFile.c b/source/server/vnode/impl/src/vnodeFile.c deleted file mode 100644 index ddcbd2689d..0000000000 --- a/source/server/vnode/impl/src/vnodeFile.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "cJSON.h" -#include "vnodeFile.h" - -int32_t vnodeReadCfg(int32_t vgId, SVnodeCfg *pCfg) { - int32_t ret = TSDB_CODE_VND_APP_ERROR; - int32_t len = 0; - int maxLen = 1000; - char *content = calloc(1, maxLen + 1); - cJSON *root = NULL; - FILE *fp = NULL; - - char file[PATH_MAX + 30] = {0}; - sprintf(file, "%s/vnode%d/config.json", tsVnodeDir, vgId); - - fp = fopen(file, "r"); - if (!fp) { - vError("vgId:%d, failed to open vnode cfg file:%s to read since %s", vgId, file, strerror(errno)); - ret = TAOS_SYSTEM_ERROR(errno); - goto PARSE_VCFG_ERROR; - } - - len = (int32_t)fread(content, 1, maxLen, fp); - if (len <= 0) { - vError("vgId:%d, failed to read %s since content is null", vgId, file); - goto PARSE_VCFG_ERROR; - } - - content[len] = 0; - root = cJSON_Parse(content); - if (root == NULL) { - vError("vgId:%d, failed to read %s since invalid json format", vgId, file); - goto PARSE_VCFG_ERROR; - } - - cJSON *db = cJSON_GetObjectItem(root, "db"); - if (!db || db->type != cJSON_String || db->valuestring == NULL) { - vError("vgId:%d, failed to read %s since db not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - tstrncpy(pCfg->db, db->valuestring, sizeof(pCfg->db)); - - cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); - if (!dropped || dropped->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since dropped not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->dropped = (int32_t)dropped->valueint; - - cJSON *quorum = cJSON_GetObjectItem(root, "quorum"); - if (!quorum || quorum->type != cJSON_Number) { - vError("vgId: %d, failed to read %s, quorum not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->quorum = (int8_t)quorum->valueint; - - cJSON *cacheBlockSize = cJSON_GetObjectItem(root, "cacheBlockSize"); - if (!cacheBlockSize || cacheBlockSize->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since cacheBlockSize not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.cacheBlockSize = (int32_t)cacheBlockSize->valueint; - - cJSON *totalBlocks = cJSON_GetObjectItem(root, "totalBlocks"); - if (!totalBlocks || totalBlocks->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since totalBlocks not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.totalBlocks = (int32_t)totalBlocks->valueint; - - cJSON *daysPerFile = cJSON_GetObjectItem(root, "daysPerFile"); - if (!daysPerFile || daysPerFile->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since daysPerFile not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.daysPerFile = (int32_t)daysPerFile->valueint; - - cJSON *daysToKeep0 = cJSON_GetObjectItem(root, "daysToKeep0"); - if (!daysToKeep0 || daysToKeep0->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since daysToKeep0 not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.daysToKeep0 = (int32_t)daysToKeep0->valueint; - - cJSON *daysToKeep1 = cJSON_GetObjectItem(root, "daysToKeep1"); - if (!daysToKeep1 || daysToKeep1->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since daysToKeep1 not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.daysToKeep1 = (int32_t)daysToKeep1->valueint; - - cJSON *daysToKeep2 = cJSON_GetObjectItem(root, "daysToKeep2"); - if (!daysToKeep2 || daysToKeep2->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since daysToKeep2 not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.daysToKeep2 = (int32_t)daysToKeep2->valueint; - - cJSON *minRowsPerFileBlock = cJSON_GetObjectItem(root, "minRowsPerFileBlock"); - if (!minRowsPerFileBlock || minRowsPerFileBlock->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since minRowsPerFileBlock not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.minRowsPerFileBlock = (int32_t)minRowsPerFileBlock->valueint; - - cJSON *maxRowsPerFileBlock = cJSON_GetObjectItem(root, "maxRowsPerFileBlock"); - if (!maxRowsPerFileBlock || maxRowsPerFileBlock->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since maxRowsPerFileBlock not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.maxRowsPerFileBlock = (int32_t)maxRowsPerFileBlock->valueint; - - cJSON *precision = cJSON_GetObjectItem(root, "precision"); - if (!precision || precision->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since precision not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.precision = (int8_t)precision->valueint; - - cJSON *compression = cJSON_GetObjectItem(root, "compression"); - if (!compression || compression->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since compression not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.compression = (int8_t)compression->valueint; - - cJSON *update = cJSON_GetObjectItem(root, "update"); - if (!update || update->type != cJSON_Number) { - vError("vgId: %d, failed to read %s since update not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.update = (int8_t)update->valueint; - - cJSON *cacheLastRow = cJSON_GetObjectItem(root, "cacheLastRow"); - if (!cacheLastRow || cacheLastRow->type != cJSON_Number) { - vError("vgId: %d, failed to read %s since cacheLastRow not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->tsdb.cacheLastRow = (int8_t)cacheLastRow->valueint; - - cJSON *walLevel = cJSON_GetObjectItem(root, "walLevel"); - if (!walLevel || walLevel->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since walLevel not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->wal.walLevel = (int8_t)walLevel->valueint; - - cJSON *fsyncPeriod = cJSON_GetObjectItem(root, "fsyncPeriod"); - if (!walLevel || walLevel->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since fsyncPeriod not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->wal.fsyncPeriod = (int32_t)fsyncPeriod->valueint; - - cJSON *selfIndex = cJSON_GetObjectItem(root, "selfIndex"); - if (!selfIndex || selfIndex->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since selfIndex not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->sync.selfIndex = selfIndex->valueint; - - cJSON *replica = cJSON_GetObjectItem(root, "replica"); - if (!replica || replica->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since replica not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - pCfg->sync.replica = replica->valueint; - - cJSON *nodes = cJSON_GetObjectItem(root, "nodes"); - if (!nodes || nodes->type != cJSON_Array) { - vError("vgId:%d, failed to read %s, nodes not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - - int size = cJSON_GetArraySize(nodes); - if (size != pCfg->sync.replica) { - vError("vgId:%d, failed to read %s since nodes size not matched", vgId, file); - goto PARSE_VCFG_ERROR; - } - - for (int i = 0; i < size; ++i) { - cJSON *nodeInfo = cJSON_GetArrayItem(nodes, i); - if (nodeInfo == NULL) continue; - SNodeInfo *node = &pCfg->sync.nodeInfo[i]; - - cJSON *nodeId = cJSON_GetObjectItem(nodeInfo, "id"); - if (!nodeId || nodeId->type != cJSON_Number) { - vError("vgId:%d, failed to read %s since nodeId not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - node->nodeId = nodeId->valueint; - - cJSON *nodePort = cJSON_GetObjectItem(nodeInfo, "port"); - if (!nodePort || nodePort->type != cJSON_Number) { - vError("vgId:%d, failed to read %s sincenodePort not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - node->nodePort = (uint16_t)nodePort->valueint; - - cJSON *nodeFqdn = cJSON_GetObjectItem(nodeInfo, "fqdn"); - if (!nodeFqdn || nodeFqdn->type != cJSON_String || nodeFqdn->valuestring == NULL) { - vError("vgId:%d, failed to read %s since nodeFqdn not found", vgId, file); - goto PARSE_VCFG_ERROR; - } - tstrncpy(node->nodeFqdn, nodeFqdn->valuestring, TSDB_FQDN_LEN); - } - - ret = TSDB_CODE_SUCCESS; - -PARSE_VCFG_ERROR: - if (content != NULL) free(content); - if (root != NULL) cJSON_Delete(root); - if (fp != NULL) fclose(fp); - - terrno = 0; - return ret; -} - -int32_t vnodeWriteCfg(int32_t vgId, SVnodeCfg *pCfg) { - int32_t code = 0; - char file[PATH_MAX + 30] = {0}; - sprintf(file, "%s/vnode%d/config.json", tsVnodeDir, vgId); - - FILE *fp = fopen(file, "w"); - if (!fp) { - vError("vgId:%d, failed to write %s error:%s", vgId, file, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - return terrno; - } - - int32_t len = 0; - int32_t maxLen = 1000; - char *content = calloc(1, maxLen + 1); - - len += snprintf(content + len, maxLen - len, "{\n"); - // vnode - len += snprintf(content + len, maxLen - len, " \"vgId\": %d,\n", vgId); - len += snprintf(content + len, maxLen - len, " \"db\": \"%s\",\n", pCfg->db); - len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pCfg->dropped); - len += snprintf(content + len, maxLen - len, " \"quorum\": %d,\n", pCfg->quorum); - // tsdb - len += snprintf(content + len, maxLen - len, " \"cacheBlockSize\": %d,\n", pCfg->tsdb.cacheBlockSize); - len += snprintf(content + len, maxLen - len, " \"totalBlocks\": %d,\n", pCfg->tsdb.totalBlocks); - len += snprintf(content + len, maxLen - len, " \"daysPerFile\": %d,\n", pCfg->tsdb.daysPerFile); - len += snprintf(content + len, maxLen - len, " \"daysToKeep0\": %d,\n", pCfg->tsdb.daysToKeep0); - len += snprintf(content + len, maxLen - len, " \"daysToKeep1\": %d,\n", pCfg->tsdb.daysToKeep1); - len += snprintf(content + len, maxLen - len, " \"daysToKeep2\": %d,\n", pCfg->tsdb.daysToKeep2); - len += snprintf(content + len, maxLen - len, " \"minRowsPerFileBlock\": %d,\n", pCfg->tsdb.minRowsPerFileBlock); - len += snprintf(content + len, maxLen - len, " \"maxRowsPerFileBlock\": %d,\n", pCfg->tsdb.maxRowsPerFileBlock); - len += snprintf(content + len, maxLen - len, " \"precision\": %d,\n", pCfg->tsdb.precision); - len += snprintf(content + len, maxLen - len, " \"compression\": %d,\n", pCfg->tsdb.compression); - len += snprintf(content + len, maxLen - len, " \"cacheLastRow\": %d,\n", pCfg->tsdb.cacheLastRow); - len += snprintf(content + len, maxLen - len, " \"update\": %d,\n", pCfg->tsdb.update); - // wal - len += snprintf(content + len, maxLen - len, " \"walLevel\": %d,\n", pCfg->wal.walLevel); - len += snprintf(content + len, maxLen - len, " \"fsyncPeriod\": %d,\n", pCfg->wal.fsyncPeriod); - // sync - len += snprintf(content + len, maxLen - len, " \"replica\": %d,\n", pCfg->sync.replica); - len += snprintf(content + len, maxLen - len, " \"selfIndex\": %d,\n", pCfg->sync.selfIndex); - len += snprintf(content + len, maxLen - len, " \"nodes\": [{\n"); - for (int32_t i = 0; i < pCfg->sync.replica; i++) { - SNodeInfo *node = &pCfg->sync.nodeInfo[i]; - len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", node->nodeId); - len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", node->nodePort); - len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\"\n", node->nodeFqdn); - if (i < pCfg->sync.replica - 1) { - len += snprintf(content + len, maxLen - len, " },{\n"); - } else { - len += snprintf(content + len, maxLen - len, " }]\n"); - } - } - len += snprintf(content + len, maxLen - len, "}\n"); - - fwrite(content, 1, len, fp); - taosFsyncFile(fileno(fp)); - fclose(fp); - free(content); - terrno = 0; - - vInfo("vgId:%d, successed to write %s", vgId, file); - return TSDB_CODE_SUCCESS; -} - -int32_t vnodeReadState(int32_t vgId, SSyncServerState *pState) { - int32_t ret = TSDB_CODE_VND_APP_ERROR; - int32_t len = 0; - int32_t maxLen = 100; - char *content = calloc(1, maxLen + 1); - cJSON *root = NULL; - FILE *fp = NULL; - - char file[PATH_MAX + 30] = {0}; - sprintf(file, "%s/vnode%d/state.json", tsVnodeDir, vgId); - - len = (int32_t)fread(content, 1, maxLen, fp); - if (len <= 0) { - vError("vgId:%d, failed to read %s since content is null", vgId, file); - goto PARSE_TERM_ERROR; - } - - root = cJSON_Parse(content); - if (root == NULL) { - vError("vgId:%d, failed to read %s since invalid json format", vgId, file); - goto PARSE_TERM_ERROR; - } - - cJSON *term = cJSON_GetObjectItem(root, "term"); - if (!term || term->type != cJSON_String) { - vError("vgId:%d, failed to read %s since term not found", vgId, file); - goto PARSE_TERM_ERROR; - } - pState->term = atoll(term->valuestring); - - cJSON *voteFor = cJSON_GetObjectItem(root, "voteFor"); - if (!voteFor || voteFor->type != cJSON_String) { - vError("vgId:%d, failed to read %s since voteFor not found", vgId, file); - goto PARSE_TERM_ERROR; - } - pState->voteFor = atoi(voteFor->valuestring); - - vInfo("vgId:%d, read %s success, voteFor:%d, term:%" PRIu64, vgId, file, pState->voteFor, pState->term); - -PARSE_TERM_ERROR: - if (content != NULL) free(content); - if (root != NULL) cJSON_Delete(root); - if (fp != NULL) fclose(fp); - - return ret; -} - -int32_t vnodeSaveState(int32_t vgId, SSyncServerState *pState) { - char file[PATH_MAX + 30] = {0}; - sprintf(file, "%s/vnode%d/state.json", tsVnodeDir, vgId); - - FILE *fp = fopen(file, "w"); - if (!fp) { - vError("vgId:%d, failed to write %s since %s", vgId, file, strerror(errno)); - return -1; - } - - int32_t len = 0; - int32_t maxLen = 100; - char *content = calloc(1, maxLen + 1); - - len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"term\": \"%" PRIu64 "\",\n", pState->term); - len += snprintf(content + len, maxLen - len, " \"voteFor\": \"%d\"\n", pState->voteFor); - len += snprintf(content + len, maxLen - len, "}\n"); - - fwrite(content, 1, len, fp); - taosFsyncFile(fileno(fp)); - fclose(fp); - free(content); - - vInfo("vgId:%d, write %s success, voteFor:%d, term:%" PRIu64, vgId, file, pState->voteFor, pState->term); - return TSDB_CODE_SUCCESS; -} \ No newline at end of file diff --git a/source/server/vnode/impl/src/vnodeInt.c b/source/server/vnode/impl/src/vnodeInt.c index 4061c04d94..7a395706e9 100644 --- a/source/server/vnode/impl/src/vnodeInt.c +++ b/source/server/vnode/impl/src/vnodeInt.c @@ -14,78 +14,20 @@ */ #define _DEFAULT_SOURCE -#include "os.h" -#include "tstep.h" -#include "vnodeMain.h" -#include "vnodeMgmt.h" -#include "vnodeRead.h" -#include "vnodeWrite.h" +#include "vnodeInt.h" -static struct { - SSteps *steps; - SVnodeFp fp; - void (*msgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *); -} tsVint; +int32_t vnodeInit() { return 0; } +void vnodeCleanup() {} -void vnodeGetDnodeEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port) { - return (*tsVint.fp.GetDnodeEp)(dnodeId, ep, fqdn, port); -} +int32_t vnodeGetStatistics(SVnode *pVnode, SVnodeStatisic *pStat) { return 0; } +int32_t vnodeGetStatus(SVnode *pVnode, SVnodeStatus *pStatus) { return 0; } -void vnodeSendMsgToDnode(struct SRpcEpSet *epSet, struct SRpcMsg *rpcMsg) { - (*tsVint.fp.SendMsgToDnode)(epSet, rpcMsg); -} +SVnode *vnodeOpen(int32_t vgId, const char *path) { return NULL; } +void vnodeClose(SVnode *pVnode) {} +int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; } +SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg) { return NULL; } +int32_t vnodeDrop(SVnode *pVnode) { return 0; } +int32_t vnodeCompact(SVnode *pVnode) { return 0; } +int32_t vnodeSync(SVnode *pVnode) { return 0; } -void vnodeSendMsgToMnode(struct SRpcMsg *rpcMsg) { return (*tsVint.fp.SendMsgToMnode)(rpcMsg); } - -void vnodeReportStartup(char *name, char *desc) { (*tsVint.fp.ReportStartup)(name, desc); } - -void vnodeProcessMsg(SRpcMsg *pMsg) { - if (tsVint.msgFp[pMsg->msgType]) { - (*tsVint.msgFp[pMsg->msgType])(pMsg); - } else { - assert(0); - } -} - -static void vnodeInitMsgFp() { - tsVint.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMgmtMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMgmtMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMgmtMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMgmtMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMgmtMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMgmtMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MD_CREATE_TABLE] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_MD_DROP_TABLE] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_MD_ALTER_TABLE] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_MD_DROP_STABLE] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessWriteReq; - // mq related - tsVint.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessWriteReq; - tsVint.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessReadMsg; - tsVint.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessReadMsg; - // mq related end - tsVint.msgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessReadMsg; - tsVint.msgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessReadMsg; -} - -int32_t vnodeInit(SVnodePara para) { - vnodeInitMsgFp(); - tsVint.fp = para.fp; - - struct SSteps *steps = taosStepInit(8, NULL); - if (steps == NULL) return -1; - - taosStepAdd(steps, "vnode-main", vnodeInitMain, vnodeCleanupMain); - taosStepAdd(steps, "vnode-read", vnodeInitRead, vnodeCleanupRead); - taosStepAdd(steps, "vnode-mgmt", vnodeInitMgmt, vnodeCleanupMgmt); - taosStepAdd(steps, "vnode-write", vnodeInitWrite, vnodeCleanupWrite); - - tsVint.steps = steps; - return taosStepExec(tsVint.steps); -} - -void vnodeCleanup() { taosStepCleanup(tsVint.steps); } +int32_t vnodeProcessMsg(SVnode *pVnode, SVnodeMsg *pMsg) { return 0; } diff --git a/source/server/vnode/impl/src/vnodeMain.c b/source/server/vnode/impl/src/vnodeMain.c deleted file mode 100644 index ced93ea6a7..0000000000 --- a/source/server/vnode/impl/src/vnodeMain.c +++ /dev/null @@ -1,712 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "thash.h" -#include "tthread.h" -#include "vnodeFile.h" -#include "vnodeMain.h" -#include "vnodeMgmt.h" -#include "vnodeRead.h" -#include "vnodeWrite.h" - -typedef enum _VN_STATUS { - TAOS_VN_STATUS_INIT = 0, - TAOS_VN_STATUS_READY = 1, - TAOS_VN_STATUS_CLOSING = 2, - TAOS_VN_STATUS_UPDATING = 3 -} EVnodeStatus; - -char *vnodeStatus[] = {"init", "ready", "closing", "updating"}; - -typedef struct { - pthread_t *threadId; - int32_t threadIndex; - int32_t failed; - int32_t opened; - int32_t vnodeNum; - int32_t *vnodeList; -} SOpenVnodeThread; - -static struct { - SHashObj *hash; - int32_t openVnodes; - int32_t totalVnodes; -} tsVnode; - -static bool vnodeSetInitStatus(SVnode *pVnode) { - pthread_mutex_lock(&pVnode->statusMutex); - pVnode->status = TAOS_VN_STATUS_INIT; - pthread_mutex_unlock(&pVnode->statusMutex); - return true; -} - -static bool vnodeSetReadyStatus(SVnode *pVnode) { - bool set = false; - pthread_mutex_lock(&pVnode->statusMutex); - - if (pVnode->status == TAOS_VN_STATUS_INIT || pVnode->status == TAOS_VN_STATUS_UPDATING) { - pVnode->status = TAOS_VN_STATUS_READY; - set = true; - } - - pthread_mutex_unlock(&pVnode->statusMutex); - return set; -} - -static bool vnodeSetUpdatingStatus(SVnode *pVnode) { - bool set = false; - pthread_mutex_lock(&pVnode->statusMutex); - - if (pVnode->status == TAOS_VN_STATUS_READY) { - pVnode->status = TAOS_VN_STATUS_UPDATING; - set = true; - } - - pthread_mutex_unlock(&pVnode->statusMutex); - return set; -} - -static bool vnodeSetClosingStatus(SVnode *pVnode) { - bool set = false; - pthread_mutex_lock(&pVnode->statusMutex); - - if (pVnode->status == TAOS_VN_STATUS_INIT || pVnode->status == TAOS_VN_STATUS_READY) { - pVnode->status = TAOS_VN_STATUS_CLOSING; - set = true; - } - - pthread_mutex_unlock(&pVnode->statusMutex); - return set; -} - -static bool vnodeInStatus(SVnode *pVnode, EVnodeStatus status) { - bool in = false; - pthread_mutex_lock(&pVnode->statusMutex); - - if (pVnode->status == status) { - in = true; - } - - pthread_mutex_unlock(&pVnode->statusMutex); - return in; -} - -static void vnodeDestroyVnode(SVnode *pVnode) { - int32_t code = 0; - int32_t vgId = pVnode->vgId; - - if (pVnode->pSync != NULL) { - syncStop(pVnode->pSync); - pVnode->pSync = NULL; - } - - if (pVnode->pQuery) { - // todo - } - - if (pVnode->pMeta) { - // todo - } - - if (pVnode->pTsdb) { - // todo - } - - if (pVnode->pTQ) { - // todo - } - - if (pVnode->pWal) { - walClose(pVnode->pWal); - pVnode->pWal = NULL; - } - - if (pVnode->allocator) { - // todo - } - - if (pVnode->pWriteQ) { - vnodeFreeWriteQueue(pVnode->pWriteQ); - pVnode->pWriteQ = NULL; - } - - if (pVnode->pQueryQ) { - vnodeFreeQueryQueue(pVnode->pQueryQ); - pVnode->pQueryQ = NULL; - } - - if (pVnode->pFetchQ) { - vnodeFreeFetchQueue(pVnode->pFetchQ); - pVnode->pFetchQ = NULL; - } - - if (pVnode->dropped) { - // todo - } - - pthread_mutex_destroy(&pVnode->statusMutex); - free(pVnode); -} - -static void vnodeCleanupVnode(SVnode *pVnode) { - vnodeSetClosingStatus(pVnode); - taosHashRemove(tsVnode.hash, &pVnode->vgId, sizeof(int32_t)); - vnodeRelease(pVnode); -} - -static inline int32_t vnodeLogWrite(struct SSyncLogStore *logStore, SyncIndex index, SSyncBuffer *pBuf) { - SVnode *pVnode = logStore->pData; // vnode status can be checked here - return walWrite(pVnode->pWal, index, pBuf->data, (int32_t)pBuf->len); -} - -static inline int32_t vnodeLogCommit(struct SSyncLogStore *logStore, SyncIndex index) { - SVnode *pVnode = logStore->pData; // vnode status can be checked here - return walCommit(pVnode->pWal, index); -} - -static inline int32_t vnodeLogPrune(struct SSyncLogStore *logStore, SyncIndex index) { - SVnode *pVnode = logStore->pData; // vnode status can be checked here - return walPrune(pVnode->pWal, index); -} - -static inline int32_t vnodeLogRollback(struct SSyncLogStore *logStore, SyncIndex index) { - SVnode *pVnode = logStore->pData; // vnode status can be checked here - return walRollback(pVnode->pWal, index); -} - -static inline int32_t vnodeSaveServerState(struct SStateManager *stateMng, SSyncServerState *pState) { - SVnode *pVnode = stateMng->pData; - return vnodeSaveState(pVnode->vgId, pState); -} - -static inline int32_t vnodeReadServerState(struct SStateManager *stateMng, SSyncServerState *pState) { - SVnode *pVnode = stateMng->pData; - return vnodeSaveState(pVnode->vgId, pState); -} - -static inline int32_t vnodeApplyLog(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) { - return 0; -} - -static inline int32_t vnodeOnClusterChanged(struct SSyncFSM *fsm, const SSyncCluster *cluster, void *pData) { return 0; } - -static inline int32_t vnodeGetSnapshot(struct SSyncFSM *fsm, SSyncBuffer **ppBuf, int32_t *objId, bool *isLast) { - return 0; -} - -static inline int32_t vnodeApplySnapshot(struct SSyncFSM *fsm, SSyncBuffer *pBuf, int32_t objId, bool isLast) { - return 0; -} - -static inline int32_t vnodeOnRestoreDone(struct SSyncFSM *fsm) { return 0; } - -static inline void vnodeOnRollback(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf) {} - -static inline void vnodeOnRoleChanged(struct SSyncFSM *fsm, const SNodesRole *pRole) {} - -static int32_t vnodeOpenVnode(int32_t vgId) { - int32_t code = 0; - - SVnode *pVnode = calloc(sizeof(SVnode), 1); - if (pVnode == NULL) { - vError("vgId:%d, failed to open vnode since no enough memory", vgId); - return TAOS_SYSTEM_ERROR(errno); - } - - pVnode->vgId = vgId; - pVnode->accessState = TAOS_VN_STATUS_INIT; - pVnode->status = TSDB_VN_ALL_ACCCESS; - pVnode->refCount = 1; - pVnode->role = TAOS_SYNC_ROLE_CANDIDATE; - pthread_mutex_init(&pVnode->statusMutex, NULL); - - vDebug("vgId:%d, vnode is opened", pVnode->vgId); - taosHashPut(tsVnode.hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnode *)); - - code = vnodeReadCfg(vgId, &pVnode->cfg); - if (code != TSDB_CODE_SUCCESS) { - vError("vgId:%d, failed to read config file, set cfgVersion to 0", pVnode->vgId); - pVnode->cfg.dropped = 1; - vnodeCleanupVnode(pVnode); - return 0; - } - - code = vnodeSaveState(vgId, &pVnode->term); - if (code != TSDB_CODE_SUCCESS) { - vError("vgId:%d, failed to read term file since %s", pVnode->vgId, tstrerror(code)); - pVnode->cfg.dropped = 1; - vnodeCleanupVnode(pVnode); - return code; - } - - pVnode->pWriteQ = vnodeAllocWriteQueue(pVnode); - pVnode->pQueryQ = vnodeAllocQueryQueue(pVnode); - pVnode->pFetchQ = vnodeAllocFetchQueue(pVnode); - if (pVnode->pWriteQ == NULL || pVnode->pQueryQ == NULL || pVnode->pFetchQ == NULL) { - vnodeCleanupVnode(pVnode); - return terrno; - } - - char path[PATH_MAX + 20]; - snprintf(path, sizeof(path), "%s/vnode%d/wal", tsVnodeDir, vgId); - pVnode->pWal = walOpen(path, &pVnode->cfg.wal); - if (pVnode->pWal == NULL) { - vnodeCleanupVnode(pVnode); - return terrno; - } - - // create sync node - SSyncInfo syncInfo = {0}; - syncInfo.vgId = vgId; - syncInfo.snapshotIndex = 0; // todo, from tsdb - memcpy(&syncInfo.syncCfg, &pVnode->cfg.sync, sizeof(SSyncCluster)); - syncInfo.fsm.pData = pVnode; - syncInfo.fsm.applyLog = vnodeApplyLog; - syncInfo.fsm.onClusterChanged = vnodeOnClusterChanged; - syncInfo.fsm.getSnapshot = vnodeGetSnapshot; - syncInfo.fsm.applySnapshot = vnodeApplySnapshot; - syncInfo.fsm.onRestoreDone = vnodeOnRestoreDone; - syncInfo.fsm.onRollback = vnodeOnRollback; - syncInfo.fsm.onRoleChanged = vnodeOnRoleChanged; - syncInfo.logStore.pData = pVnode; - syncInfo.logStore.logWrite = vnodeLogWrite; - syncInfo.logStore.logCommit = vnodeLogCommit; - syncInfo.logStore.logPrune = vnodeLogPrune; - syncInfo.logStore.logRollback = vnodeLogRollback; - syncInfo.stateManager.pData = pVnode; - syncInfo.stateManager.saveServerState = vnodeSaveServerState; - syncInfo.stateManager.readServerState = vnodeReadServerState; - - pVnode->pSync = syncStart(&syncInfo); - if (pVnode->pSync == NULL) { - vnodeCleanupVnode(pVnode); - return terrno; - } - - vnodeSetReadyStatus(pVnode); - return TSDB_CODE_SUCCESS; -} - -int32_t vnodeCreateVnode(int32_t vgId, SVnodeCfg *pCfg) { - int32_t code = 0; - char path[PATH_MAX + 20] = {0}; - - snprintf(path, sizeof(path), "%s/vnode%d", tsVnodeDir, vgId); - if (taosMkDir(path) < 0) { - code = TAOS_SYSTEM_ERROR(errno); - vError("vgId:%d, failed to create since %s", vgId, tstrerror(code)); - return code; - } - - snprintf(path, sizeof(path), "%s/vnode%d/cfg", tsVnodeDir, vgId); - if (taosMkDir(path) < 0) { - code = TAOS_SYSTEM_ERROR(errno); - vError("vgId:%d, failed to create since %s", vgId, tstrerror(code)); - return code; - } - - snprintf(path, sizeof(path), "%s/vnode%d/wal", tsVnodeDir, vgId); - if (taosMkDir(path) < 0) { - code = TAOS_SYSTEM_ERROR(errno); - vError("vgId:%d, failed to create since %s", vgId, tstrerror(code)); - return code; - } - - snprintf(path, sizeof(path), "%s/vnode%d/tq", tsVnodeDir, vgId); - if (taosMkDir(path) < 0) { - code = TAOS_SYSTEM_ERROR(errno); - vError("vgId:%d, failed to create since %s", vgId, tstrerror(code)); - return code; - } - - snprintf(path, sizeof(path), "%s/vnode%d/tsdb", tsVnodeDir, vgId); - if (taosMkDir(path) < 0) { - code = TAOS_SYSTEM_ERROR(errno); - vError("vgId:%d, failed to create since %s", vgId, tstrerror(code)); - return code; - } - - snprintf(path, sizeof(path), "%s/vnode%d/meta", tsVnodeDir, vgId); - if (taosMkDir(path) < 0) { - code = TAOS_SYSTEM_ERROR(errno); - vError("vgId:%d, failed to create since %s", vgId, tstrerror(code)); - return code; - } - - code = vnodeWriteCfg(vgId, pCfg); - if (code != 0) { - vError("vgId:%d, failed to save vnode cfg since %s", vgId, tstrerror(code)); - return code; - } - - return vnodeOpenVnode(vgId); -} - -int32_t vnodeAlterVnode(SVnode * pVnode, SVnodeCfg *pCfg) { - int32_t code = 0; - int32_t vgId = pVnode->vgId; - - bool walChanged = (memcmp(&pCfg->wal, &pVnode->cfg.wal, sizeof(SWalCfg)) != 0); - bool tsdbChanged = (memcmp(&pCfg->tsdb, &pVnode->cfg.tsdb, sizeof(STsdbCfg)) != 0); - bool metaChanged = (memcmp(&pCfg->meta, &pVnode->cfg.meta, sizeof(SMetaCfg)) != 0); - bool syncChanged = (memcmp(&pCfg->sync, &pVnode->cfg.sync, sizeof(SSyncCluster)) != 0); - - if (!walChanged && !tsdbChanged && !metaChanged && !syncChanged) { - vDebug("vgId:%d, nothing changed", vgId); - vnodeRelease(pVnode); - return code; - } - - code = vnodeWriteCfg(pVnode->vgId, pCfg); - if (code != 0) { - vError("vgId:%d, failed to write alter msg to file since %s", vgId, tstrerror(code)); - vnodeRelease(pVnode); - return code; - } - - pVnode->cfg = *pCfg; - - if (walChanged) { - code = walAlter(pVnode->pWal, &pVnode->cfg.wal); - if (code != 0) { - vDebug("vgId:%d, failed to alter wal since %s", vgId, tstrerror(code)); - vnodeRelease(pVnode); - return code; - } - } - - if (tsdbChanged) { - // todo - } - - if (metaChanged) { - // todo - } - - if (syncChanged) { - syncReconfig(pVnode->pSync, &pVnode->cfg.sync); - } - - vnodeRelease(pVnode); - return code; -} - -int32_t vnodeDropVnode(SVnode *pVnode) { - if (pVnode->cfg.dropped) { - vInfo("vgId:%d, already set drop flag, ref:%d", pVnode->vgId, pVnode->refCount); - vnodeRelease(pVnode); - return TSDB_CODE_SUCCESS; - } - - pVnode->cfg.dropped = 1; - int32_t code = vnodeWriteCfg(pVnode->vgId, &pVnode->cfg); - if (code == 0) { - vInfo("vgId:%d, set drop flag, ref:%d", pVnode->vgId, pVnode->refCount); - vnodeCleanupVnode(pVnode); - } else { - vError("vgId:%d, failed to set drop flag since %s", pVnode->vgId, tstrerror(code)); - pVnode->cfg.dropped = 0; - } - - vnodeRelease(pVnode); - return code; -} - -int32_t vnodeSyncVnode(SVnode *pVnode) { - return TSDB_CODE_SUCCESS; -} - -int32_t vnodeCompactVnode(SVnode *pVnode) { - return TSDB_CODE_SUCCESS; -} - -static void *vnodeOpenVnodeFunc(void *param) { - SOpenVnodeThread *pThread = param; - - vDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum); - setThreadName("vnodeOpenVnode"); - - for (int32_t v = 0; v < pThread->vnodeNum; ++v) { - int32_t vgId = pThread->vnodeList[v]; - - char stepDesc[TSDB_STEP_DESC_LEN] = {0}; - snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", vgId, - tsVnode.openVnodes, tsVnode.totalVnodes); - // (*vnodeInst()->fp.ReportStartup)("open-vnodes", stepDesc); - - if (vnodeOpenVnode(vgId) < 0) { - vError("vgId:%d, failed to open vnode by thread:%d", vgId, pThread->threadIndex); - pThread->failed++; - } else { - vDebug("vgId:%d, is opened by thread:%d", vgId, pThread->threadIndex); - pThread->opened++; - } - - atomic_add_fetch_32(&tsVnode.openVnodes, 1); - } - - vDebug("thread:%d, total vnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened, - pThread->failed); - return NULL; -} - -static int32_t vnodeGetVnodeListFromDisk(int32_t vnodeList[], int32_t *numOfVnodes) { -#if 0 - DIR *dir = opendir(tsVnodeDir); - if (dir == NULL) return TSDB_CODE_DND_NO_WRITE_ACCESS; - - *numOfVnodes = 0; - struct dirent *de = NULL; - while ((de = readdir(dir)) != NULL) { - if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; - if (de->d_type & DT_DIR) { - if (strncmp("vnode", de->d_name, 5) != 0) continue; - int32_t vnode = atoi(de->d_name + 5); - if (vnode == 0) continue; - - (*numOfVnodes)++; - - if (*numOfVnodes >= TSDB_MAX_VNODES) { - vError("vgId:%d, too many vnode directory in disk, exist:%d max:%d", vnode, *numOfVnodes, TSDB_MAX_VNODES); - closedir(dir); - return TSDB_CODE_DND_TOO_MANY_VNODES; - } else { - vnodeList[*numOfVnodes - 1] = vnode; - } - } - } - closedir(dir); -#endif - return TSDB_CODE_SUCCESS; -} - -static int32_t vnodeOpenVnodes() { - int32_t vnodeList[TSDB_MAX_VNODES] = {0}; - int32_t numOfVnodes = 0; - int32_t status = vnodeGetVnodeListFromDisk(vnodeList, &numOfVnodes); - - if (status != TSDB_CODE_SUCCESS) { - vInfo("failed to get vnode list from disk since code:%d", status); - return status; - } - - tsVnode.totalVnodes = numOfVnodes; - - int32_t threadNum = tsNumOfCores; - int32_t vnodesPerThread = numOfVnodes / threadNum + 1; - - SOpenVnodeThread *threads = calloc(threadNum, sizeof(SOpenVnodeThread)); - for (int32_t t = 0; t < threadNum; ++t) { - threads[t].threadIndex = t; - threads[t].vnodeList = calloc(vnodesPerThread, sizeof(int32_t)); - } - - for (int32_t v = 0; v < numOfVnodes; ++v) { - int32_t t = v % threadNum; - SOpenVnodeThread *pThread = &threads[t]; - pThread->vnodeList[pThread->vnodeNum++] = vnodeList[v]; - } - - vInfo("start %d threads to open %d vnodes", threadNum, numOfVnodes); - - for (int32_t t = 0; t < threadNum; ++t) { - SOpenVnodeThread *pThread = &threads[t]; - if (pThread->vnodeNum == 0) continue; - - pThread->threadId = taosCreateThread(vnodeOpenVnodeFunc, pThread); - if (pThread->threadId == NULL) { - vError("thread:%d, failed to create thread to open vnode, reason:%s", pThread->threadIndex, strerror(errno)); - } - } - - int32_t openVnodes = 0; - int32_t failedVnodes = 0; - for (int32_t t = 0; t < threadNum; ++t) { - SOpenVnodeThread *pThread = &threads[t]; - taosDestoryThread(pThread->threadId); - pThread->threadId = NULL; - - openVnodes += pThread->opened; - failedVnodes += pThread->failed; - free(pThread->vnodeList); - } - - free(threads); - vInfo("there are total vnodes:%d, opened:%d", numOfVnodes, openVnodes); - - if (failedVnodes != 0) { - vError("there are total vnodes:%d, failed:%d", numOfVnodes, failedVnodes); - return -1; - } - - return TSDB_CODE_SUCCESS; -} - -static int32_t vnodeGetVnodeList(SVnode *vnodeList[], int32_t *numOfVnodes) { - void *pIter = taosHashIterate(tsVnode.hash, NULL); - while (pIter) { - SVnode **pVnode = pIter; - if (*pVnode) { - (*numOfVnodes)++; - if (*numOfVnodes >= TSDB_MAX_VNODES) { - vError("vgId:%d, too many open vnodes, exist:%d max:%d", (*pVnode)->vgId, *numOfVnodes, TSDB_MAX_VNODES); - continue; - } else { - vnodeList[*numOfVnodes - 1] = (*pVnode); - } - } - - pIter = taosHashIterate(tsVnode.hash, pIter); - } - - return TSDB_CODE_SUCCESS; -} - -static void vnodeCleanupVnodes() { - SVnode* vnodeList[TSDB_MAX_VNODES] = {0}; - int32_t numOfVnodes = 0; - - int32_t code = vnodeGetVnodeList(vnodeList, &numOfVnodes); - - if (code != TSDB_CODE_SUCCESS) { - vInfo("failed to get dnode list since code %d", code); - return; - } - - for (int32_t i = 0; i < numOfVnodes; ++i) { - vnodeCleanupVnode(vnodeList[i]); - } - - vInfo("total vnodes:%d are all closed", numOfVnodes); -} - -static void vnodeIncRef(void *ptNode) { - assert(ptNode != NULL); - - SVnode **ppVnode = (SVnode **)ptNode; - assert(ppVnode); - assert(*ppVnode); - - SVnode *pVnode = *ppVnode; - atomic_add_fetch_32(&pVnode->refCount, 1); - vTrace("vgId:%d, get vnode, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode); -} - -SVnode *vnodeAcquireInAllState(int32_t vgId) { - SVnode *pVnode = NULL; - - // taosHashGetClone(tsVnode.hash, &vgId, sizeof(int32_t), vnodeIncRef, (void*)&pVnode); - if (pVnode == NULL) { - vDebug("vgId:%d, can't accquire since not exist", vgId); - terrno = TSDB_CODE_VND_INVALID_VGROUP_ID; - return NULL; - } - - return pVnode; -} - -SVnode *vnodeAcquire(int32_t vgId) { - SVnode *pVnode = vnodeAcquireInAllState(vgId); - if (pVnode == NULL) return NULL; - - if (vnodeInStatus(pVnode, TAOS_VN_STATUS_READY)) { - return pVnode; - } else { - vDebug("vgId:%d, can't accquire since not in ready status", vgId); - vnodeRelease(pVnode); - terrno = TSDB_CODE_VND_INVALID_TSDB_STATE; - return NULL; - } -} - -void vnodeRelease(SVnode *pVnode) { - if (pVnode == NULL) return; - - int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1); - int32_t vgId = pVnode->vgId; - - vTrace("vgId:%d, release vnode, refCount:%d pVnode:%p", vgId, refCount, pVnode); - assert(refCount >= 0); - - if (refCount <= 0) { - vDebug("vgId:%d, vnode will be destroyed, refCount:%d pVnode:%p", vgId, refCount, pVnode); - vnodeDestroyVnode(pVnode); - int32_t count = taosHashGetSize(tsVnode.hash); - vDebug("vgId:%d, vnode is destroyed, vnodes:%d", vgId, count); - } -} - -int32_t vnodeInitMain() { - tsVnode.hash = taosHashInit(TSDB_MIN_VNODES, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); - if (tsVnode.hash == NULL) { - vError("failed to init vnode mgmt"); - return -1; - } - - vInfo("vnode main is initialized"); - return vnodeOpenVnodes(); -} - -void vnodeCleanupMain() { - vnodeCleanupVnodes(); - taosHashCleanup(tsVnode.hash); - tsVnode.hash = NULL; -} - -static void vnodeBuildVloadMsg(SVnode *pVnode, SStatusMsg *pStatus) { - int64_t totalStorage = 0; - int64_t compStorage = 0; - int64_t pointsWritten = 0; - - if (pStatus->openVnodes >= TSDB_MAX_VNODES) return; - - // if (pVnode->tsdb) { - // tsdbReportStat(pVnode->tsdb, &pointsWritten, &totalStorage, &compStorage); - // } - - SVnodeLoad *pLoad = &pStatus->load[pStatus->openVnodes++]; - pLoad->vgId = htonl(pVnode->vgId); - pLoad->totalStorage = htobe64(totalStorage); - pLoad->compStorage = htobe64(compStorage); - pLoad->pointsWritten = htobe64(pointsWritten); - pLoad->status = pVnode->status; - pLoad->role = pVnode->role; -} - -void vnodeGetStatus(SStatusMsg *pStatus) { - void *pIter = taosHashIterate(tsVnode.hash, NULL); - while (pIter) { - SVnode **pVnode = pIter; - if (*pVnode) { - vnodeBuildVloadMsg(*pVnode, pStatus); - } - pIter = taosHashIterate(tsVnode.hash, pIter); - } -} - -void vnodeSetAccess(SVgroupAccess *pAccess, int32_t numOfVnodes) { - for (int32_t i = 0; i < numOfVnodes; ++i) { - pAccess[i].vgId = htonl(pAccess[i].vgId); - SVnode *pVnode = vnodeAcquire(pAccess[i].vgId); - if (pVnode != NULL) { - pVnode->accessState = pAccess[i].accessState; - if (pVnode->accessState != TSDB_VN_ALL_ACCCESS) { - vDebug("vgId:%d, access state is set to %d", pAccess[i].vgId, pVnode->accessState); - } - vnodeRelease(pVnode); - } - } -} diff --git a/source/server/vnode/impl/src/vnodeMgmt.c b/source/server/vnode/impl/src/vnodeMgmt.c deleted file mode 100644 index dfb3c95b8d..0000000000 --- a/source/server/vnode/impl/src/vnodeMgmt.c +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "vnodeMain.h" -#include "vnodeMgmt.h" - -static struct { - SWorkerPool createPool; - taos_queue createQueue; - SWorkerPool workerPool; - taos_queue workerQueue; - int32_t (*msgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *); -} tsVmgmt = {0}; - -static int32_t vnodeParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg *pCfg) { - SCreateVnodeMsg *pCreate = rpcMsg->pCont; - *vgId = htonl(pCreate->vgId); - - pCfg->dropped = 0; - pCfg->quorum = pCreate->quorum; - tstrncpy(pCfg->db, pCreate->db, sizeof(pCfg->db)); - - pCfg->tsdb.cacheBlockSize = htonl(pCreate->cacheBlockSize); - pCfg->tsdb.totalBlocks = htonl(pCreate->totalBlocks); - pCfg->tsdb.daysPerFile = htonl(pCreate->daysPerFile); - pCfg->tsdb.daysToKeep1 = htonl(pCreate->daysToKeep1); - pCfg->tsdb.daysToKeep2 = htonl(pCreate->daysToKeep2); - pCfg->tsdb.daysToKeep0 = htonl(pCreate->daysToKeep0); - pCfg->tsdb.minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock); - pCfg->tsdb.maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock); - pCfg->tsdb.precision = pCreate->precision; - pCfg->tsdb.compression = pCreate->compression; - pCfg->tsdb.cacheLastRow = pCreate->cacheLastRow; - pCfg->tsdb.update = pCreate->update; - - pCfg->wal.fsyncPeriod = htonl(pCreate->fsyncPeriod); - pCfg->wal.walLevel = pCreate->walLevel; - - pCfg->sync.replica = pCreate->replica; - pCfg->sync.selfIndex = pCreate->selfIndex; - - for (int32_t j = 0; j < pCreate->replica; ++j) { - pCfg->sync.nodeInfo[j].nodePort = htons(pCreate->nodes[j].port); - tstrncpy(pCfg->sync.nodeInfo[j].nodeFqdn, pCreate->nodes[j].fqdn, TSDB_FQDN_LEN); - } - - return 0; -} - -static int32_t vnodeProcessCreateVnodeReq(SRpcMsg *rpcMsg) { - SVnodeCfg vnodeCfg = {0}; - int32_t vgId = 0; - - int32_t code = vnodeParseCreateVnodeReq(rpcMsg, &vgId, &vnodeCfg); - if (code != 0) { - vError("failed to parse create vnode msg since %s", tstrerror(code)); - } - - vDebug("vgId:%d, create vnode req is received", vgId); - - SVnode *pVnode = vnodeAcquireInAllState(vgId); - if (pVnode != NULL) { - vDebug("vgId:%d, already exist, return success", vgId); - vnodeRelease(pVnode); - return code; - } - - code = vnodeCreateVnode(vgId, &vnodeCfg); - if (code != 0) { - vError("vgId:%d, failed to create vnode since %s", vgId, tstrerror(code)); - } - - return code; -} - -static int32_t vnodeProcessAlterVnodeReq(SRpcMsg *rpcMsg) { - SVnodeCfg vnodeCfg = {0}; - int32_t vgId = 0; - - int32_t code = vnodeParseCreateVnodeReq(rpcMsg, &vgId, &vnodeCfg); - if (code != 0) { - vError("failed to parse create vnode msg since %s", tstrerror(code)); - } - - vDebug("vgId:%d, alter vnode req is received", vgId); - - SVnode *pVnode = vnodeAcquire(vgId); - if (pVnode == NULL) { - code = terrno; - vDebug("vgId:%d, failed to alter vnode since %s", vgId, tstrerror(code)); - return code; - } - - code = vnodeAlterVnode(pVnode, &vnodeCfg); - if (code != 0) { - vError("vgId:%d, failed to alter vnode since %s", vgId, tstrerror(code)); - } - - vnodeRelease(pVnode); - return code; -} - -static SDropVnodeMsg *vnodeParseDropVnodeReq(SRpcMsg *rpcMsg) { - SDropVnodeMsg *pDrop = rpcMsg->pCont; - pDrop->vgId = htonl(pDrop->vgId); - return pDrop; -} - -static int32_t vnodeProcessSyncVnodeReq(SRpcMsg *rpcMsg) { - SSyncVnodeMsg *pSync = (SSyncVnodeMsg *)vnodeParseDropVnodeReq(rpcMsg); - - int32_t code = 0; - int32_t vgId = pSync->vgId; - vDebug("vgId:%d, sync vnode req is received", vgId); - - SVnode *pVnode = vnodeAcquire(vgId); - if (pVnode == NULL) { - code = terrno; - vDebug("vgId:%d, failed to sync since %s", vgId, tstrerror(code)); - return code; - } - - code = vnodeSyncVnode(pVnode); - if (code != 0) { - vError("vgId:%d, failed to compact vnode since %s", vgId, tstrerror(code)); - } - - vnodeRelease(pVnode); - return code; -} - -static int32_t vnodeProcessCompactVnodeReq(SRpcMsg *rpcMsg) { - SCompactVnodeMsg *pCompact = (SCompactVnodeMsg *)vnodeParseDropVnodeReq(rpcMsg); - - int32_t code = 0; - int32_t vgId = pCompact->vgId; - vDebug("vgId:%d, compact vnode req is received", vgId); - - SVnode *pVnode = vnodeAcquire(vgId); - if (pVnode == NULL) { - code = terrno; - vDebug("vgId:%d, failed to compact since %s", vgId, tstrerror(code)); - return code; - } - - code = vnodeCompactVnode(pVnode); - if (code != 0) { - vError("vgId:%d, failed to compact vnode since %s", vgId, tstrerror(code)); - } - - vnodeRelease(pVnode); - return code; -} - -static int32_t vnodeProcessDropVnodeReq(SRpcMsg *rpcMsg) { - SDropVnodeMsg *pDrop = vnodeParseDropVnodeReq(rpcMsg); - - int32_t code = 0; - int32_t vgId = pDrop->vgId; - vDebug("vgId:%d, drop vnode req is received", vgId); - - SVnode *pVnode = vnodeAcquire(vgId); - if (pVnode == NULL) { - code = terrno; - vDebug("vgId:%d, failed to drop since %s", vgId, tstrerror(code)); - return code; - } - - code = vnodeDropVnode(pVnode); - if (code != 0) { - vError("vgId:%d, failed to drop vnode since %s", vgId, tstrerror(code)); - } - - vnodeRelease(pVnode); - return code; -} - -static int32_t vnodeProcessAlterStreamReq(SRpcMsg *pMsg) { - vError("alter stream msg not processed"); - return TSDB_CODE_VND_MSG_NOT_PROCESSED; -} - -static void vnodeProcessMgmtReq(SVnMgmtMsg *pMgmt, void *unused) { - SRpcMsg *pMsg = &pMgmt->rpcMsg; - int32_t msgType = pMsg->msgType; - int32_t code = 0; - - if (tsVmgmt.msgFp[msgType]) { - vTrace("msg:%p, ahandle:%p type:%s will be processed", pMgmt, pMsg->ahandle, taosMsg[msgType]); - code = (*tsVmgmt.msgFp[msgType])(pMsg); - } else { - vError("msg:%p, ahandle:%p type:%s not processed since no handle", pMgmt, pMsg->ahandle, taosMsg[msgType]); - code = TSDB_CODE_DND_MSG_NOT_PROCESSED; - } - - SRpcMsg rsp = {.code = code, .handle = pMsg->handle}; - rpcSendResponse(&rsp); - taosFreeQitem(pMgmt); -} - -static void vnodeInitMgmtReqFp() { - tsVmgmt.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessCreateVnodeReq; - tsVmgmt.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessAlterVnodeReq; - tsVmgmt.msgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessSyncVnodeReq; - tsVmgmt.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessCompactVnodeReq; - tsVmgmt.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessDropVnodeReq; - tsVmgmt.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessAlterStreamReq; -} - -static int32_t vnodeWriteToMgmtQueue(SRpcMsg *pMsg) { - int32_t size = sizeof(SVnMgmtMsg) + pMsg->contLen; - SVnMgmtMsg *pMgmt = taosAllocateQitem(size); - if (pMgmt == NULL) return TSDB_CODE_DND_OUT_OF_MEMORY; - - pMgmt->rpcMsg = *pMsg; - pMgmt->rpcMsg.pCont = pMgmt->pCont; - memcpy(pMgmt->pCont, pMsg->pCont, pMsg->contLen); - - if (pMsg->msgType == TSDB_MSG_TYPE_MD_CREATE_VNODE) { - return taosWriteQitem(tsVmgmt.createQueue, pMgmt); - } else { - return taosWriteQitem(tsVmgmt.workerQueue, pMgmt); - } -} - -void vnodeProcessMgmtMsg(SRpcMsg *pMsg) { - int32_t code = vnodeWriteToMgmtQueue(pMsg); - if (code != TSDB_CODE_SUCCESS) { - vError("msg, ahandle:%p type:%s not processed since %s", pMsg->ahandle, taosMsg[pMsg->msgType], tstrerror(code)); - SRpcMsg rsp = {.handle = pMsg->handle, .code = code}; - rpcSendResponse(&rsp); - } - - rpcFreeCont(pMsg->pCont); -} - -int32_t vnodeInitMgmt() { - vnodeInitMgmtReqFp(); - - SWorkerPool *pPool = &tsVmgmt.createPool; - pPool->name = "vnode-mgmt-create"; - pPool->min = 1; - pPool->max = 1; - if (tWorkerInit(pPool) != 0) { - return TSDB_CODE_VND_OUT_OF_MEMORY; - } - - tsVmgmt.createQueue = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)vnodeProcessMgmtReq); - - pPool = &tsVmgmt.workerPool; - pPool->name = "vnode-mgmt-worker"; - pPool->min = 1; - pPool->max = 1; - if (tWorkerInit(pPool) != 0) { - return TSDB_CODE_VND_OUT_OF_MEMORY; - } - - tsVmgmt.workerQueue = tWorkerAllocQueue(pPool, NULL, (FProcessOneItem)vnodeProcessMgmtReq); - - vInfo("vmgmt is initialized"); - return TSDB_CODE_SUCCESS; -} - -void vnodeCleanupMgmt() { - tWorkerFreeQueue(&tsVmgmt.createPool, tsVmgmt.createQueue); - tWorkerCleanup(&tsVmgmt.createPool); - tsVmgmt.createQueue = NULL; - - tWorkerFreeQueue(&tsVmgmt.workerPool, tsVmgmt.workerQueue); - tWorkerCleanup(&tsVmgmt.workerPool); - tsVmgmt.createQueue = NULL; - vInfo("vmgmt is closed"); -} diff --git a/source/server/vnode/impl/src/vnodeRead.c b/source/server/vnode/impl/src/vnodeRead.c index ce6348c992..8964402f6c 100644 --- a/source/server/vnode/impl/src/vnodeRead.c +++ b/source/server/vnode/impl/src/vnodeRead.c @@ -14,199 +14,4 @@ */ #define _DEFAULT_SOURCE -#include "vnodeMain.h" #include "vnodeRead.h" -#include "vnodeReadMsg.h" - -static struct { - SWorkerPool query; - SWorkerPool fetch; - int32_t (*msgFp[TSDB_MSG_TYPE_MAX])(SVnode *, struct SReadMsg *); -} tsVread = {0}; - -void vnodeStartRead(SVnode *pVnode) {} -void vnodeStopRead(SVnode *pVnode) {} - -void vnodeWaitReadCompleted(SVnode *pVnode) { - while (pVnode->queuedRMsg > 0) { - vTrace("vgId:%d, queued rmsg num:%d", pVnode->vgId, pVnode->queuedRMsg); - taosMsleep(10); - } -} - -static int32_t vnodeWriteToRQueue(SVnode *pVnode, void *pCont, int32_t contLen, int8_t qtype, SRpcMsg *pRpcMsg) { - if (pVnode->dropped) { - return TSDB_CODE_APP_NOT_READY; - } - -#if 0 - if (!((pVnode->role == TAOS_SYNC_ROLE_MASTER) || (tsEnableSlaveQuery && pVnode->role == TAOS_SYNC_ROLE_SLAVE))) { - return TSDB_CODE_APP_NOT_READY; - } -#endif - - int32_t size = sizeof(SReadMsg) + contLen; - SReadMsg *pRead = taosAllocateQitem(size); - if (pRead == NULL) { - return TSDB_CODE_VND_OUT_OF_MEMORY; - } - - if (pRpcMsg != NULL) { - pRead->rpcHandle = pRpcMsg->handle; - pRead->rpcAhandle = pRpcMsg->ahandle; - pRead->msgType = pRpcMsg->msgType; - pRead->code = pRpcMsg->code; - } - - if (contLen != 0) { - pRead->contLen = contLen; - memcpy(pRead->pCont, pCont, contLen); - } else { - pRead->qhandle = pCont; - } - - pRead->qtype = qtype; - - atomic_add_fetch_32(&pVnode->refCount, 1); - atomic_add_fetch_32(&pVnode->queuedRMsg, 1); - - if (pRead->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRead->msgType == TSDB_MSG_TYPE_FETCH) { - return taosWriteQitem(pVnode->pFetchQ, pRead); - } else { - return taosWriteQitem(pVnode->pQueryQ, pRead); - } -} - -static void vnodeFreeFromRQueue(SVnode *pVnode, SReadMsg *pRead) { - atomic_sub_fetch_32(&pVnode->queuedRMsg, 1); - - taosFreeQitem(pRead); - vnodeRelease(pVnode); -} - -int32_t vnodeReputPutToRQueue(SVnode *pVnode, void **qhandle, void *ahandle) { - SRpcMsg rpcMsg = {0}; - rpcMsg.msgType = TSDB_MSG_TYPE_QUERY; - rpcMsg.ahandle = ahandle; - - int32_t code = vnodeWriteToRQueue(pVnode, qhandle, 0, TAOS_QTYPE_QUERY, &rpcMsg); - if (code == TSDB_CODE_SUCCESS) { - vTrace("QInfo:%p add to vread queue for exec query", *qhandle); - } - - return code; -} - -void vnodeProcessReadMsg(SRpcMsg *pMsg) { - int32_t queuedMsgNum = 0; - int32_t leftLen = pMsg->contLen; - int32_t code = TSDB_CODE_VND_INVALID_VGROUP_ID; - char * pCont = pMsg->pCont; - - while (leftLen > 0) { - SMsgHead *pHead = (SMsgHead *)pCont; - pHead->vgId = htonl(pHead->vgId); - pHead->contLen = htonl(pHead->contLen); - - assert(pHead->contLen > 0); - SVnode *pVnode = vnodeAcquire(pHead->vgId); - if (pVnode != NULL) { - code = vnodeWriteToRQueue(pVnode, pCont, pHead->contLen, TAOS_QTYPE_RPC, pMsg); - if (code == TSDB_CODE_SUCCESS) queuedMsgNum++; - vnodeRelease(pVnode); - } - - leftLen -= pHead->contLen; - pCont -= pHead->contLen; - } - - if (queuedMsgNum == 0) { - SRpcMsg rpcRsp = {.handle = pMsg->handle, .code = code}; - rpcSendResponse(&rpcRsp); - } - - rpcFreeCont(pMsg->pCont); -} - -static void vnodeInitReadMsgFp() { - tsVread.msgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessQueryMsg; - tsVread.msgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessFetchMsg; - - tsVread.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessTqQueryMsg; - tsVread.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessConsumeMsg; -} - -static void vnodeSendReadRsp(SReadMsg *pRead, int32_t code) { - SRpcMsg rpcRsp = { - .handle = pRead->rpcHandle, - .pCont = pRead->rspRet.rsp, - .contLen = pRead->rspRet.len, - .code = code, - }; - - rpcSendResponse(&rpcRsp); -} - -static void vnodeProcessReadReq(SReadMsg *pRead, SVnode *pVnode) { - int32_t msgType = pRead->msgType; - int32_t code = 0; - if (tsVread.msgFp[msgType] == NULL) { - vDebug("vgId:%d, msgType:%s not processed, no handle", pVnode->vgId, taosMsg[msgType]); - code = TSDB_CODE_VND_MSG_NOT_PROCESSED; - } else { - vTrace("msg:%p, app:%p type:%s will be processed", pRead, pRead->rpcAhandle, taosMsg[msgType]); - code = (*tsVread.msgFp[msgType])(pVnode, pRead); - } - - if (/*qtype == TAOS_QTYPE_RPC && */ code != TSDB_CODE_QRY_NOT_READY) { - vnodeSendReadRsp(pRead, code); - } else { - if (code == TSDB_CODE_QRY_HAS_RSP) { - vnodeSendReadRsp(pRead, pRead->code); - } else { // code == TSDB_CODE_QRY_NOT_READY, do not return msg to client - assert(pRead->rpcHandle == NULL || (pRead->rpcHandle != NULL && pRead->msgType == 5)); - } - } - - vnodeFreeFromRQueue(pVnode, pRead); -} - -int32_t vnodeInitRead() { - vnodeInitReadMsgFp(); - - int32_t maxFetchThreads = 4; - float threadsForQuery = MAX(tsNumOfCores * tsRatioOfQueryCores, 1); - - SWorkerPool *pPool = &tsVread.query; - pPool->name = "vquery"; - pPool->min = (int32_t)threadsForQuery; - pPool->max = pPool->min; - if (tWorkerInit(pPool) != 0) return -1; - - pPool = &tsVread.fetch; - pPool->name = "vfetch"; - pPool->min = MIN(maxFetchThreads, tsNumOfCores); - pPool->max = pPool->min; - if (tWorkerInit(pPool) != 0) return -1; - - vInfo("vread is initialized, max worker %d", pPool->max); - return 0; -} - -void vnodeCleanupRead() { - tWorkerCleanup(&tsVread.fetch); - tWorkerCleanup(&tsVread.query); - vInfo("vread is closed"); -} - -taos_queue vnodeAllocQueryQueue(SVnode *pVnode) { - return tWorkerAllocQueue(&tsVread.query, pVnode, (FProcessOneItem)vnodeProcessReadReq); -} - -taos_queue vnodeAllocFetchQueue(SVnode *pVnode) { - return tWorkerAllocQueue(&tsVread.fetch, pVnode, (FProcessOneItem)vnodeProcessReadReq); -} - -void vnodeFreeQueryQueue(taos_queue pQueue) { tWorkerFreeQueue(&tsVread.query, pQueue); } - -void vnodeFreeFetchQueue(taos_queue pQueue) { tWorkerFreeQueue(&tsVread.fetch, pQueue); } diff --git a/source/server/vnode/impl/src/vnodeReadMsg.c b/source/server/vnode/impl/src/vnodeReadMsg.c deleted file mode 100644 index 58dfe4116a..0000000000 --- a/source/server/vnode/impl/src/vnodeReadMsg.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "vnodeMain.h" -#include "vnodeRead.h" -#include "vnodeReadMsg.h" - -#if 0 -// notify connection(handle) that current qhandle is created, if current connection from -// client is broken, the query needs to be killed immediately. -static int32_t vnodeNotifyCurrentQhandle(void *handle, uint64_t qId, void *qhandle, int32_t vgId) { - SRetrieveTableMsg *pMsg = rpcMallocCont(sizeof(SRetrieveTableMsg)); - pMsg->qId = htobe64(qId); - pMsg->header.vgId = htonl(vgId); - pMsg->header.contLen = htonl(sizeof(SRetrieveTableMsg)); - - vTrace("QInfo:0x%" PRIx64 "-%p register qhandle to connect:%p", qId, qhandle, handle); - return rpcReportProgress(handle, (char *)pMsg, sizeof(SRetrieveTableMsg)); -} - -/** - * @param pRet response message object - * @param pVnode the vnode object - * @param handle qhandle for executing query - * @param freeHandle free qhandle or not - * @param ahandle sqlObj address at client side - * @return - */ -static int32_t vnodeDumpQueryResult(SVnRsp *pRet, void *pVnode, uint64_t qId, void **handle, bool *freeHandle, - void *ahandle) { - bool continueExec = false; - - int32_t code = TSDB_CODE_SUCCESS; - if ((code = qDumpRetrieveResult(*handle, (SRetrieveTableRsp **)&pRet->rsp, &pRet->len, &continueExec)) == - TSDB_CODE_SUCCESS) { - if (continueExec) { - *freeHandle = false; - code = vnodeReputPutToRQueue(pVnode, handle, ahandle); - if (code != TSDB_CODE_SUCCESS) { - *freeHandle = true; - return code; - } else { - pRet->qhandle = *handle; - } - } else { - *freeHandle = true; - vTrace("QInfo:0x%" PRIx64 "-%p exec completed, free handle:%d", qId, *handle, *freeHandle); - } - } else { - SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp)); - memset(pRsp, 0, sizeof(SRetrieveTableRsp)); - pRsp->completed = true; - - pRet->rsp = pRsp; - pRet->len = sizeof(SRetrieveTableRsp); - *freeHandle = true; - } - - return code; -} - -static void vnodeBuildNoResultQueryRsp(SVnRsp *pRet) { - pRet->rsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp)); - pRet->len = sizeof(SRetrieveTableRsp); - - memset(pRet->rsp, 0, sizeof(SRetrieveTableRsp)); - SRetrieveTableRsp *pRsp = pRet->rsp; - - pRsp->completed = true; -} -#endif - -int32_t vnodeProcessQueryMsg(SVnode *pVnode, SReadMsg *pRead) { -#if 0 - void * pCont = pRead->pCont; - int32_t contLen = pRead->contLen; - SVnRsp *pRet = &pRead->rspRet; - - SQueryTableMsg *pQueryTableMsg = (SQueryTableMsg *)pCont; - memset(pRet, 0, sizeof(SVnRsp)); - - // qHandle needs to be freed correctly - if (pRead->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { - vError("error rpc msg in query, %s", tstrerror(pRead->code)); - } - - int32_t code = TSDB_CODE_SUCCESS; - void ** handle = NULL; - - if (contLen != 0) { - qinfo_t pQInfo = NULL; - uint64_t qId = genQueryId(); - code = qCreateQueryInfo(pVnode->tsdb, pVnode->vgId, pQueryTableMsg, &pQInfo, qId); - - SQueryTableRsp *pRsp = (SQueryTableRsp *)rpcMallocCont(sizeof(SQueryTableRsp)); - pRsp->code = code; - pRsp->qId = 0; - - pRet->len = sizeof(SQueryTableRsp); - pRet->rsp = pRsp; - int32_t vgId = pVnode->vgId; - - // current connect is broken - if (code == TSDB_CODE_SUCCESS) { - handle = qRegisterQInfo(pVnode->qMgmt, qId, pQInfo); - if (handle == NULL) { // failed to register qhandle - pRsp->code = terrno; - terrno = 0; - - vError("vgId:%d, QInfo:0x%" PRIx64 "-%p register qhandle failed, return to app, code:%s,", pVnode->vgId, qId, - (void *)pQInfo, tstrerror(pRsp->code)); - qDestroyQueryInfo(pQInfo); // destroy it directly - return pRsp->code; - } else { - assert(*handle == pQInfo); - pRsp->qId = htobe64(qId); - } - - if (handle != NULL && - vnodeNotifyCurrentQhandle(pRead->rpcHandle, qId, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) { - vError("vgId:%d, QInfo:0x%" PRIx64 "-%p, query discarded since link is broken, %p", pVnode->vgId, qId, *handle, - pRead->rpcHandle); - - pRsp->code = TSDB_CODE_RPC_NETWORK_UNAVAIL; - qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true); - return pRsp->code; - } - - } else { - assert(pQInfo == NULL); - } - - if (handle != NULL) { - vTrace("vgId:%d, QInfo:0x%" PRIx64 "-%p, query msg disposed, create qhandle and returns to app", vgId, qId, - *handle); - code = vnodeReputPutToRQueue(pVnode, handle, pRead->rpcHandle); - if (code != TSDB_CODE_SUCCESS) { - pRsp->code = code; - qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true); - return pRsp->code; - } - } - - int32_t remain = atomic_add_fetch_32(&pVnode->numOfQHandle, 1); - vTrace("vgId:%d, new qhandle created, total qhandle:%d", pVnode->vgId, remain); - } else { - assert(pCont != NULL); - void ** qhandle = (void **)pRead->qhandle; - uint64_t qId = 0; - - vTrace("vgId:%d, QInfo:%p, continues to exec query", pVnode->vgId, *qhandle); - - // In the retrieve blocking model, only 50% CPU will be used in query processing - if (tsRetrieveBlockingModel) { - qTableQuery(*qhandle, &qId); // do execute query - qReleaseQInfo(pVnode->qMgmt, (void **)&qhandle, false); - } else { - bool freehandle = false; - bool buildRes = qTableQuery(*qhandle, &qId); // do execute query - - // build query rsp, the retrieve request has reached here already - if (buildRes) { - // update the connection info according to the retrieve connection - pRead->rpcHandle = qGetResultRetrieveMsg(*qhandle); - assert(pRead->rpcHandle != NULL); - - vTrace("vgId:%d, QInfo:%p, start to build retrieval rsp after query paused, %p", pVnode->vgId, *qhandle, - pRead->rpcHandle); - - // set the real rsp error code - pRead->code = vnodeDumpQueryResult(&pRead->rspRet, pVnode, qId, qhandle, &freehandle, pRead->rpcHandle); - - // NOTE: set return code to be TSDB_CODE_QRY_HAS_RSP to notify dnode to return msg to client - code = TSDB_CODE_QRY_HAS_RSP; - } else { - // void *h1 = qGetResultRetrieveMsg(*qhandle); - - /* remove this assert, one possible case that will cause h1 not NULL: query thread unlock pQInfo->lock, and then - * FETCH thread execute twice before query thread reach here */ - // assert(h1 == NULL); - - freehandle = qQueryCompleted(*qhandle); - } - - // NOTE: if the qhandle is not put into vread queue or query is completed, free the qhandle. - // If the building of result is not required, simply free it. Otherwise, mandatorily free the qhandle - if (freehandle || (!buildRes)) { - if (freehandle) { - int32_t remain = atomic_sub_fetch_32(&pVnode->numOfQHandle, 1); - vTrace("vgId:%d, QInfo:%p, start to free qhandle, remain qhandle:%d", pVnode->vgId, *qhandle, remain); - } - - qReleaseQInfo(pVnode->qMgmt, (void **)&qhandle, freehandle); - } - } - } - - return code; -#endif - return 0; -} - -//mq related -int32_t vnodeProcessConsumeMsg(SVnode *pVnode, SReadMsg *pRead) { - //parse message and optionally move offset - void* pMsg = pRead->pCont; - TmqConsumeReq *pConsumeMsg = (TmqConsumeReq*) pMsg; - TmqMsgHead msgHead = pConsumeMsg->head; - //extract head - STQ *pTq = pVnode->pTQ; - /*tqBufferHandle *pHandle = tqGetHandle(pTq, msgHead.clientId);*/ - //return msg if offset not moved - /*if(pConsumeMsg->commitOffset == pHandle->consumeOffset) {*/ - //return msg - /*return 0;*/ - /*}*/ - //or move offset - /*tqMoveOffsetToNext(pHandle);*/ - //fetch or register context - /*tqFetchMsg(pHandle, pRead);*/ - //judge mode, tail read or catch up read - /*int64_t lastVer = walLastVer(pVnode->wal);*/ - //launch new query - return 0; -} - -int32_t vnodeProcessTqQueryMsg(SVnode *pVnode, SReadMsg *pRead) { - //get operator tree from tq data structure - //execute operator tree - //put data into ringbuffer - //unref memory - return 0; -} -//mq related end - -int32_t vnodeProcessFetchMsg(SVnode *pVnode, SReadMsg *pRead) { -#if 0 - void * pCont = pRead->pCont; - SVnRsp *pRet = &pRead->rspRet; - - SRetrieveTableMsg *pRetrieve = pCont; - pRetrieve->free = htons(pRetrieve->free); - pRetrieve->qId = htobe64(pRetrieve->qId); - - vTrace("vgId:%d, qId:0x%" PRIx64 ", retrieve msg is disposed, free:%d, conn:%p", pVnode->vgId, pRetrieve->qId, - pRetrieve->free, pRead->rpcHandle); - - memset(pRet, 0, sizeof(SVnRsp)); - - terrno = TSDB_CODE_SUCCESS; - int32_t code = TSDB_CODE_SUCCESS; - void ** handle = qAcquireQInfo(pVnode->qMgmt, pRetrieve->qId); - if (handle == NULL) { - code = terrno; - terrno = TSDB_CODE_SUCCESS; - } else if (!checkQIdEqual(*handle, pRetrieve->qId)) { - code = TSDB_CODE_QRY_INVALID_QHANDLE; - } - - if (code != TSDB_CODE_SUCCESS) { - vError("vgId:%d, invalid qId in retrieving result, code:%s, QInfo:%" PRIu64, pVnode->vgId, tstrerror(code), - pRetrieve->qId); - vnodeBuildNoResultQueryRsp(pRet); - return code; - } - - // kill current query and free corresponding resources. - if (pRetrieve->free == 1) { - int32_t remain = atomic_sub_fetch_32(&pVnode->numOfQHandle, 1); - vWarn("vgId:%d, QInfo:%" PRIx64 "-%p, retrieve msg received to kill query and free qhandle, remain qhandle:%d", - pVnode->vgId, pRetrieve->qId, *handle, remain); - - qKillQuery(*handle); - qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true); - - vnodeBuildNoResultQueryRsp(pRet); - code = TSDB_CODE_TSC_QUERY_CANCELLED; - return code; - } - - // register the qhandle to connect to quit query immediate if connection is broken - if (vnodeNotifyCurrentQhandle(pRead->rpcHandle, pRetrieve->qId, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) { - int32_t remain = atomic_sub_fetch_32(&pVnode->numOfQHandle, 1); - vError("vgId:%d, QInfo:%" PRIu64 "-%p, retrieve discarded since link is broken, conn:%p, remain qhandle:%d", - pVnode->vgId, pRetrieve->qhandle, *handle, pRead->rpcHandle, remain); - - code = TSDB_CODE_RPC_NETWORK_UNAVAIL; - qKillQuery(*handle); - qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true); - return code; - } - - bool freeHandle = true; - bool buildRes = false; - - code = qRetrieveQueryResultInfo(*handle, &buildRes, pRead->rpcHandle); - if (code != TSDB_CODE_SUCCESS) { - // TODO handle malloc failure - pRet->rsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp)); - pRet->len = sizeof(SRetrieveTableRsp); - memset(pRet->rsp, 0, sizeof(SRetrieveTableRsp)); - freeHandle = true; - } else { // result is not ready, return immediately - // Only affects the non-blocking model - if (!tsRetrieveBlockingModel) { - if (!buildRes) { - assert(pRead->rpcHandle != NULL); - qReleaseQInfo(pVnode->qMgmt, (void **)&handle, false); - return TSDB_CODE_QRY_NOT_READY; - } - } - - // ahandle is the sqlObj pointer - code = vnodeDumpQueryResult(pRet, pVnode, pRetrieve->qId, handle, &freeHandle, pRead->rpcHandle); - } - - // If qhandle is not added into vread queue, the query should be completed already or paused with error. - // Here free qhandle immediately - if (freeHandle) { - int32_t remain = atomic_sub_fetch_32(&pVnode->numOfQHandle, 1); - vTrace("vgId:%d, QInfo:%p, start to free qhandle, remain qhandle:%d", pVnode->vgId, *handle, remain); - qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true); - } - - return code; -#endif - return 0; -} - diff --git a/source/server/vnode/impl/src/vnodeWrite.c b/source/server/vnode/impl/src/vnodeWrite.c index 119cd29537..dc12ffb241 100644 --- a/source/server/vnode/impl/src/vnodeWrite.c +++ b/source/server/vnode/impl/src/vnodeWrite.c @@ -14,216 +14,4 @@ */ #define _DEFAULT_SOURCE -#include "os.h" -#include "vnodeMain.h" #include "vnodeWrite.h" -#include "vnodeWriteMsg.h" - -typedef int32_t (*WriteMsgFp)(SVnode *, void *pCont, SVnRsp *); - -typedef struct { - int32_t code; - int8_t qtype; - SVnode * pVnode; - SRpcMsg rpcMsg; - SVnRsp rspRet; - char reserveForSync[24]; - SWalHead walHead; -} SVnWriteMsg; - -static struct { - SMWorkerPool pool; - int64_t queuedBytes; - int32_t queuedMsgs; -} tsVwrite = {0}; - -void vnodeStartWrite(SVnode *pVnode) {} -void vnodeStopWrite(SVnode *pVnode) { - while (pVnode->queuedWMsg > 0) { - vTrace("vgId:%d, queued wmsg num:%d", pVnode->vgId, pVnode->queuedWMsg); - taosMsleep(10); - } -} - -static int32_t vnodeWriteToWQueue(SVnode *pVnode, SWalHead *pHead, int32_t qtype, SRpcMsg *pRpcMsg) { - if (!(pVnode->accessState & TSDB_VN_WRITE_ACCCESS)) { - vWarn("vgId:%d, no write auth", pVnode->vgId); - return TSDB_CODE_VND_NO_WRITE_AUTH; - } - - if (tsAvailDataDirGB <= tsMinimalDataDirGB) { - vWarn("vgId:%d, failed to write into vwqueue since no diskspace, avail:%fGB", pVnode->vgId, tsAvailDataDirGB); - return TSDB_CODE_VND_NO_DISKSPACE; - } - - if (pHead->len > TSDB_MAX_WAL_SIZE) { - vError("vgId:%d, wal len:%d exceeds limit, hver:%" PRIu64, pVnode->vgId, pHead->len, pHead->version); - return TSDB_CODE_WAL_SIZE_LIMIT; - } - - if (tsVwrite.queuedBytes > tsMaxVnodeQueuedBytes) { - vDebug("vgId:%d, too many bytes:%" PRId64 " in vwqueue, flow control", pVnode->vgId, tsVwrite.queuedBytes); - return TSDB_CODE_VND_IS_FLOWCTRL; - } - - int32_t size = sizeof(SVnWriteMsg) + pHead->len; - SVnWriteMsg *pWrite = taosAllocateQitem(size); - if (pWrite == NULL) { - return TSDB_CODE_VND_OUT_OF_MEMORY; - } - - if (pRpcMsg != NULL) { - pWrite->rpcMsg = *pRpcMsg; - } - - memcpy(&pWrite->walHead, pHead, sizeof(SWalHead) + pHead->len); - pWrite->pVnode = pVnode; - pWrite->qtype = qtype; - - atomic_add_fetch_64(&tsVwrite.queuedBytes, size); - atomic_add_fetch_32(&tsVwrite.queuedMsgs, 1); - atomic_add_fetch_32(&pVnode->refCount, 1); - atomic_add_fetch_32(&pVnode->queuedWMsg, 1); - taosWriteQitem(pVnode->pWriteQ, pWrite); - - return TSDB_CODE_SUCCESS; -} - -static void vnodeFreeFromWQueue(SVnode *pVnode, SVnWriteMsg *pWrite) { - int64_t size = sizeof(SVnWriteMsg) + pWrite->walHead.len; - atomic_sub_fetch_64(&tsVwrite.queuedBytes, size); - atomic_sub_fetch_32(&tsVwrite.queuedMsgs, 1); - atomic_sub_fetch_32(&pVnode->queuedWMsg, 1); - - taosFreeQitem(pWrite); - vnodeRelease(pVnode); -} - -void vnodeProcessWriteReq(SRpcMsg *pRpcMsg) { - int32_t code; - - SMsgHead *pMsg = pRpcMsg->pCont; - pMsg->vgId = htonl(pMsg->vgId); - pMsg->contLen = htonl(pMsg->contLen); - - SVnode *pVnode = vnodeAcquire(pMsg->vgId); - if (pVnode == NULL) { - code = TSDB_CODE_VND_INVALID_VGROUP_ID; - } else { - SWalHead *pHead = (SWalHead *)((char *)pRpcMsg->pCont - sizeof(SWalHead)); - pHead->msgType = pRpcMsg->msgType; - pHead->version = 0; - pHead->len = pMsg->contLen; - code = vnodeWriteToWQueue(pVnode, pHead, TAOS_QTYPE_RPC, pRpcMsg); - } - - if (code != TSDB_CODE_SUCCESS) { - SRpcMsg rpcRsp = {.handle = pRpcMsg->handle, .code = code}; - rpcSendResponse(&rpcRsp); - } - - vnodeRelease(pVnode); - rpcFreeCont(pRpcMsg->pCont); -} - -static void vnodeProcessWrite(SVnWriteMsg *pWrite, SVnode *pVnode) { -} - // SWalHead *pHead = &pWrite->walHead; - // SVnRsp * pRet = &pWrite->rspRet; - // int32_t msgType = pHead->msgType; - - // vTrace("vgId:%d, msg:%s will be processed, hver:%" PRIu64, pVnode->vgId, taosMsg[pHead->msgType], pHead->version); - - // // write data locally - // switch (msgType) { - // case TSDB_MSG_TYPE_SUBMIT: - // pRet->len = sizeof(SSubmitRsp); - // pRet->rsp = rpcMallocCont(pRet->len); - // pWrite->code = vnodeProcessSubmitReq(pVnode, (void*)pHead->cont, pRet->rsp); - // break; - // case TSDB_MSG_TYPE_MD_CREATE_TABLE: - // pWrite->code = vnodeProcessCreateTableReq(pVnode, (void*)pHead->cont, NULL); - // break; - // case TSDB_MSG_TYPE_MD_DROP_TABLE: - // pWrite->code = vnodeProcessDropTableReq(pVnode, (void*)pHead->cont, NULL); - // break; - // case TSDB_MSG_TYPE_MD_ALTER_TABLE: - // pWrite->code = vnodeProcessAlterTableReq(pVnode, (void*)pHead->cont, NULL); - // break; - // case TSDB_MSG_TYPE_MD_DROP_STABLE: - // pWrite->code = vnodeProcessDropStableReq(pVnode, (void*)pHead->cont, NULL); - // break; - // case TSDB_MSG_TYPE_UPDATE_TAG_VAL: - // pWrite->code = vnodeProcessUpdateTagValReq(pVnode, (void*)pHead->cont, NULL); - // break; - // //mq related - // case TSDB_MSG_TYPE_MQ_CONNECT: - // pWrite->code = vnodeProcessMqConnectReq(pVnode, (void*)pHead->cont, NULL); - // break; - // case TSDB_MSG_TYPE_MQ_DISCONNECT: - // pWrite->code = vnodeProcessMqDisconnectReq(pVnode, (void*)pHead->cont, NULL); - // break; - // case TSDB_MSG_TYPE_MQ_ACK: - // pWrite->code = vnodeProcessMqAckReq(pVnode, (void*)pHead->cont, NULL); - // break; - // case TSDB_MSG_TYPE_MQ_RESET: - // pWrite->code = vnodeProcessMqResetReq(pVnode, (void*)pHead->cont, NULL); - // break; - // //mq related end - // default: - // pWrite->code = TSDB_CODE_VND_MSG_NOT_PROCESSED; - // break; - // } - - // if (pWrite->code < 0) return false; - - // // update fsync - // return (pWrite->code == 0 && msgType != TSDB_MSG_TYPE_SUBMIT); - - - // // walFsync(pVnode->wal, fsync); - - -// static void vnodeProcessWriteEnd(SVnWriteMsg *pWrite, SVnode *pVnode) { -// if (qtype == TAOS_QTYPE_RPC) { -// SRpcMsg rpcRsp = { -// .handle = pWrite->rpcMsg.handle, -// .pCont = pWrite->rspRet.rsp, -// .contLen = pWrite->rspRet.len, -// .code = pWrite->code, -// }; -// rpcSendResponse(&rpcRsp); -// } else { -// if (pWrite->rspRet.rsp) { -// rpcFreeCont(pWrite->rspRet.rsp); -// } -// } -// vnodeFreeFromWQueue(pVnode, pWrite); -// } - -int32_t vnodeInitWrite() { - SMWorkerPool *pPool = &tsVwrite.pool; - pPool->name = "vnode-write"; - pPool->max = tsNumOfCores; - if (tMWorkerInit(pPool) != 0) return -1; - - vInfo("vwrite is initialized, max worker %d", pPool->max); - return TSDB_CODE_SUCCESS; -} - -void vnodeCleanupWrite() { - tMWorkerCleanup(&tsVwrite.pool); - vInfo("vwrite is closed"); -} - -taos_queue vnodeAllocWriteQueue(SVnode *pVnode) { - return tMWorkerAllocQueue(&tsVwrite.pool, pVnode, NULL); -} - -void vnodeFreeWriteQueue(taos_queue pQueue) { tMWorkerFreeQueue(&tsVwrite.pool, pQueue); } - -taos_queue vnodeAllocApplyQueue(SVnode *pVnode) { - return tMWorkerAllocQueue(&tsVwrite.pool, pVnode, NULL); -} - -void vnodeFreeApplyQueue(taos_queue pQueue) { tMWorkerFreeQueue(&tsVwrite.pool, pQueue); } diff --git a/source/server/vnode/impl/src/vnodeWriteMsg.c b/source/server/vnode/impl/src/vnodeWriteMsg.c deleted file mode 100644 index 2e13d0035d..0000000000 --- a/source/server/vnode/impl/src/vnodeWriteMsg.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "vnodeWriteMsg.h" - -int32_t vnodeProcessSubmitReq(SVnode *pVnode, SSubmitReq *pReq, SSubmitRsp *pRsp) { - // TODO: Check inputs - -#if 0 - void *pMem = NULL; - if ((pMem = amalloc(pVnode->allocator, REQ_SIZE(pReq))) == NULL) { - // No more memory to allocate, schedule an async commit - // and continue - vnodeAsyncCommit(pVnode); - - // Reset allocator and allocat more - vnodeResetAllocator(pVnode); - pMem = amalloc(pVnode->allocator, REQ_SIZE(pReq)); - if (pMem == NULL) { - // TODO: handle the error - } - } - - // TODO: if SSubmitReq is compressed or encoded, we need to decode the request - memcpy(pMem, pReq, REQ_SIZE(pReq)); - - if (tqPushMsg((SSubmitReq *)pReq) < 0) { - // TODO: handle error - } - - SSubmitReqReader reader; - taosInitSubmitReqReader(&reader, (SSubmitReq *)pMem); - - if (tsdbInsert(pVnode->pTsdb, (SSubmitReq *)pMem) < 0) { - // TODO: handler error - } -#endif - - return 0; -} - -int32_t vnodeProcessCreateTableReq(SVnode *pVnode, SCreateTableReq *pReq, SCreateTableRsp *pRsp) { - // TODO - return 0; -} - - int32_t vnodeProcessDropTableReq(SVnode *pVnode, SDropTableReq *pReq, SDropTableRsp *pRsp) { - // TODO - return 0; -} - -int32_t vnodeProcessAlterTableReq(SVnode *pVnode, SAlterTableReq *pReq, SAlterTableRsp *pRsp) { - // TODO - return 0; -} - -int32_t vnodeProcessDropStableReq(SVnode *pVnode, SDropStableReq *pReq, SDropStableRsp *pRsp) { - // TODO - return 0; -} - -int32_t vnodeProcessUpdateTagValReq(SVnode *pVnode, SUpdateTagValReq *pReq, SUpdateTagValRsp *pRsp) { - // TODO - return 0; -} - -//mq related -int32_t vnodeProcessMqConnectReq(SVnode* pVnode, SMqConnectReq *pReq, SMqConnectRsp *pRsp){ - return 0; -} -int32_t vnodeProcessMqDisconnectReq(SVnode* pVnode, SMqConnectReq *pReq, SMqConnectRsp *pRsp) { - return 0; -} -int32_t vnodeProcessMqAckReq(SVnode* pVnode, SMqAckReq *pReq, SMqAckRsp *pRsp) { - return 0; -} -int32_t vnodeProcessMqResetReq(SVnode* pVnode, SMqResetReq *pReq, SMqResetRsp *pRsp) { - return 0; -} -//mq related end diff --git a/source/server/vnode/impl/test/CMakeLists.txt b/source/server/vnode/impl/test/CMakeLists.txt index fad366e6ef..9c09be56fb 100644 --- a/source/server/vnode/impl/test/CMakeLists.txt +++ b/source/server/vnode/impl/test/CMakeLists.txt @@ -6,4 +6,4 @@ target_sources(VMATest "vnodeMemAllocatorTest.cpp" ) target_include_directories(VMATest PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../inc") -target_link_libraries(VMATest os gtest_main) \ No newline at end of file +target_link_libraries(VMATest os gtest_main vnode) \ No newline at end of file diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index bb0303c04a..2813a55fea 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -31,8 +31,8 @@ typedef struct STaosQueue { struct STaosQueue *next; // for queue set struct STaosQset *qset; // for queue set void *ahandle; // for queue set - FProcessOneItem fpOneItem; - FProcessAllItem fpAllItem; + FProcessItem itemFp; + FProcessItems itemsFp; pthread_mutex_t mutex; } STaosQueue; @@ -65,11 +65,11 @@ taos_queue taosOpenQueue() { return queue; } -void taosSetQueueFp(taos_queue param, FProcessOneItem fpOneItem, FProcessAllItem fpAllItem) { +void taosSetQueueFp(taos_queue param, FProcessItem itemFp, FProcessItems itemsFp) { if (param == NULL) return; STaosQueue *queue = (STaosQueue *)param; - queue->fpOneItem = fpOneItem; - queue->fpAllItem = fpAllItem; + queue->itemFp = itemFp; + queue->itemsFp = itemsFp; } void taosCloseQueue(taos_queue param) { @@ -341,7 +341,7 @@ void taosRemoveFromQset(taos_qset p1, taos_queue p2) { int taosGetQueueNumber(taos_qset param) { return ((STaosQset *)param)->numOfQueues; } -int taosReadQitemFromQset(taos_qset param, void **pitem, void **ahandle, FProcessOneItem *fpOneItem) { +int taosReadQitemFromQset(taos_qset param, void **pitem, void **ahandle, FProcessItem *itemFp) { STaosQset *qset = (STaosQset *)param; STaosQnode *pNode = NULL; int code = 0; @@ -363,7 +363,7 @@ int taosReadQitemFromQset(taos_qset param, void **pitem, void **ahandle, FProces pNode = queue->head; *pitem = pNode->item; if (ahandle) *ahandle = queue->ahandle; - if (fpOneItem) *fpOneItem = queue->fpOneItem; + if (itemFp) *itemFp = queue->itemFp; queue->head = pNode->next; if (queue->head == NULL) queue->tail = NULL; queue->numOfItems--; @@ -381,7 +381,7 @@ int taosReadQitemFromQset(taos_qset param, void **pitem, void **ahandle, FProces return code; } -int taosReadAllQitemsFromQset(taos_qset param, taos_qall p2, void **ahandle, FProcessAllItem *fpAllItem) { +int taosReadAllQitemsFromQset(taos_qset param, taos_qall p2, void **ahandle, FProcessItems *itemsFp) { STaosQset *qset = (STaosQset *)param; STaosQueue *queue; STaosQall *qall = (STaosQall *)p2; @@ -407,7 +407,7 @@ int taosReadAllQitemsFromQset(taos_qset param, taos_qall p2, void **ahandle, FPr qall->itemSize = queue->itemSize; code = qall->numOfItems; if (ahandle) *ahandle = queue->ahandle; - if (fpAllItem) *fpAllItem = queue->fpAllItem; + if (itemsFp) *itemsFp = queue->itemsFp; queue->head = NULL; queue->tail = NULL; diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 12f1aac9f9..7df12089b7 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -58,8 +58,8 @@ void tWorkerCleanup(SWorkerPool *pool) { } static void *tWorkerThreadFp(SWorker *worker) { - SWorkerPool *pool = worker->pool; - FProcessOneItem fp = NULL; + SWorkerPool *pool = worker->pool; + FProcessItem fp = NULL; void *msg = NULL; void *ahandle = NULL; @@ -83,7 +83,7 @@ static void *tWorkerThreadFp(SWorker *worker) { return NULL; } -taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessOneItem fp) { +taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessItem fp) { pthread_mutex_lock(&pool->mutex); taos_queue queue = taosOpenQueue(); if (queue == NULL) { @@ -166,8 +166,8 @@ void tMWorkerCleanup(SMWorkerPool *pool) { } static void *tWriteWorkerThreadFp(SMWorker *worker) { - SMWorkerPool *pool = worker->pool; - FProcessAllItem fp = NULL; + SMWorkerPool *pool = worker->pool; + FProcessItems fp = NULL; void *msg = NULL; void *ahandle = NULL; @@ -193,7 +193,7 @@ static void *tWriteWorkerThreadFp(SMWorker *worker) { return NULL; } -taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessAllItem fp) { +taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessItems fp) { pthread_mutex_lock(&pool->mutex); SMWorker *worker = pool->workers + pool->nextId; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 308898950a..caa334aaed 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1166,7 +1166,7 @@ int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCreateDbMsg); - pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_CM_CREATE_DB : TSDB_MSG_TYPE_CM_CREATE_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_CREATE_DB : TSDB_MSG_TYPE_CREATE_TP; SCreateDbMsg *pCreateDbMsg = (SCreateDbMsg *)pCmd->payload; @@ -1182,7 +1182,7 @@ int32_t tscBuildCreateFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; SCreateFuncMsg *pCreateFuncMsg = (SCreateFuncMsg *)pCmd->payload; - pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_FUNCTION; + pCmd->msgType = TSDB_MSG_TYPE_CREATE_FUNCTION; pCmd->payloadLen = sizeof(SCreateFuncMsg) + htonl(pCreateFuncMsg->codeLen); @@ -1203,7 +1203,7 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SStrToken* t0 = taosArrayGet(pInfo->pMiscInfo->a, 0); strncpy(pCreate->ep, t0->z, t0->n); - pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_DNODE; + pCmd->msgType = TSDB_MSG_TYPE_CREATE_DNODE; return TSDB_CODE_SUCCESS; } @@ -1249,7 +1249,7 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } } - pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_ACCT; + pCmd->msgType = TSDB_MSG_TYPE_CREATE_ACCT; return TSDB_CODE_SUCCESS; } @@ -1277,9 +1277,9 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } if (pUser->type == TSDB_ALTER_USER_PASSWD || pUser->type == TSDB_ALTER_USER_PRIVILEGES) { - pCmd->msgType = TSDB_MSG_TYPE_CM_ALTER_USER; + pCmd->msgType = TSDB_MSG_TYPE_ALTER_USER; } else { - pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_USER; + pCmd->msgType = TSDB_MSG_TYPE_CREATE_USER; } return TSDB_CODE_SUCCESS; @@ -1288,7 +1288,7 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SCfgDnodeMsg); - pCmd->msgType = TSDB_MSG_TYPE_CM_CONFIG_DNODE; + pCmd->msgType = TSDB_MSG_TYPE_CONFIG_DNODE; return TSDB_CODE_SUCCESS; } @@ -1310,14 +1310,14 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - pCmd->msgType = (pInfo->pMiscInfo->dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_CM_DROP_DB : TSDB_MSG_TYPE_CM_DROP_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_DROP_DB : TSDB_MSG_TYPE_DROP_TP; return TSDB_CODE_SUCCESS; } int32_t tscBuildDropFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_FUNCTION; + pCmd->msgType = TSDB_MSG_TYPE_DROP_FUNCTION; pCmd->payloadLen = sizeof(SDropFuncMsg); @@ -1340,7 +1340,7 @@ int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pDropTableMsg->supertable = (pInfo->pMiscInfo->tableType == TSDB_SUPER_TABLE)? 1:0; pDropTableMsg->igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_TABLE; + pCmd->msgType = TSDB_MSG_TYPE_DROP_TABLE; return TSDB_CODE_SUCCESS; } @@ -1358,7 +1358,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SDropDnodeMsg * pDrop = (SDropDnodeMsg *)pCmd->payload; tstrncpy(pDrop->ep, dnodeEp, tListLen(pDrop->ep)); - pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DNODE; + pCmd->msgType = TSDB_MSG_TYPE_DROP_DNODE; return TSDB_CODE_SUCCESS; } @@ -1370,7 +1370,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { tstrncpy(user, pCmd->payload, TSDB_USER_LEN); pCmd->payloadLen = sizeof(SDropUserMsg); - pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TSDB_MSG_TYPE_CM_DROP_USER:TSDB_MSG_TYPE_CM_DROP_ACCT; + pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TSDB_MSG_TYPE_DROP_USER:TSDB_MSG_TYPE_DROP_ACCT; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); @@ -1395,7 +1395,7 @@ int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SUseDbMsg *pUseDbMsg = (SUseDbMsg *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); tNameExtractFullName(&pTableMetaInfo->name, pUseDbMsg->db); - pCmd->msgType = TSDB_MSG_TYPE_CM_USE_DB; + pCmd->msgType = TSDB_MSG_TYPE_USE_DB; return TSDB_CODE_SUCCESS; } @@ -1412,14 +1412,14 @@ int32_t tscBuildSyncDbReplicaMsg(SSqlObj* pSql, SSqlInfo *pInfo) { SSyncDbMsg *pSyncMsg = (SSyncDbMsg *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); tNameExtractFullName(&pTableMetaInfo->name, pSyncMsg->db); - pCmd->msgType = TSDB_MSG_TYPE_CM_SYNC_DB; + pCmd->msgType = TSDB_MSG_TYPE_SYNC_DB; return TSDB_CODE_SUCCESS; } int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_CM_SHOW; + pCmd->msgType = TSDB_MSG_TYPE_SHOW; pCmd->payloadLen = sizeof(SShowMsg) + 100; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1473,13 +1473,13 @@ int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) { switch (pCmd->command) { case TSDB_SQL_KILL_QUERY: - pCmd->msgType = TSDB_MSG_TYPE_CM_KILL_QUERY; + pCmd->msgType = TSDB_MSG_TYPE_KILL_QUERY; break; case TSDB_SQL_KILL_CONNECTION: - pCmd->msgType = TSDB_MSG_TYPE_CM_KILL_CONN; + pCmd->msgType = TSDB_MSG_TYPE_KILL_CONN; break; case TSDB_SQL_KILL_STREAM: - pCmd->msgType = TSDB_MSG_TYPE_CM_KILL_STREAM; + pCmd->msgType = TSDB_MSG_TYPE_KILL_STREAM; break; } return TSDB_CODE_SUCCESS; @@ -1592,7 +1592,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { msgLen = (int32_t)(pMsg - (char*)pCreateTableMsg); pCreateTableMsg->contLen = htonl(msgLen); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_TABLE; + pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE; assert(msgLen + minMsgSize() <= size); return TSDB_CODE_SUCCESS; @@ -1645,7 +1645,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { msgLen = (int32_t)(pMsg - (char*)pAlterTableMsg); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CM_ALTER_TABLE; + pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE; assert(msgLen + minMsgSize() <= size); @@ -1674,7 +1674,7 @@ int tscBuildUpdateTagMsg(SSqlObj* pSql, SSqlInfo *pInfo) { int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->payloadLen = sizeof(SAlterDbMsg); - pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_CM_ALTER_DB : TSDB_MSG_TYPE_CM_ALTER_TP; + pCmd->msgType = (pInfo->pMiscInfo->dbOpt.dbType == TSDB_DB_TYPE_DEFAULT) ? TSDB_MSG_TYPE_ALTER_DB : TSDB_MSG_TYPE_ALTER_TP; SAlterDbMsg *pAlterDbMsg = (SAlterDbMsg* )pCmd->payload; pAlterDbMsg->dbType = -1; @@ -1711,7 +1711,7 @@ int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int count = removeDupVgid(result, size); pCmd->payloadLen = sizeof(SCompactMsg) + count * sizeof(int32_t); - pCmd->msgType = TSDB_MSG_TYPE_CM_COMPACT_VNODE; + pCmd->msgType = TSDB_MSG_TYPE_COMPACT_VNODE; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); @@ -1741,7 +1741,7 @@ int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_CM_RETRIEVE; + pCmd->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE; pCmd->payloadLen = sizeof(SRetrieveTableMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1861,7 +1861,7 @@ int tscProcessEmptyResultRsp(SSqlObj *pSql) { return tscLocalResultCommonBuilder int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { STscObj *pObj = pSql->pTscObj; SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_CM_CONNECT; + pCmd->msgType = TSDB_MSG_TYPE_CONNECT; pCmd->payloadLen = sizeof(SConnectMsg); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1898,7 +1898,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildMultiTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->msgType = TSDB_MSG_TYPE_CM_TABLES_META; + pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; assert(pCmd->payloadLen + minMsgSize() <= pCmd->allocSize); tscDebug("0x%"PRIx64" build load multi-tablemeta msg completed, numOfTables:%d, msg size:%d", pSql->self, pCmd->count, @@ -1925,7 +1925,7 @@ int tscBuildSTableVgroupMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pMsg += TSDB_TABLE_FNAME_LEN; } - pCmd->msgType = TSDB_MSG_TYPE_CM_STABLE_VGROUP; + pCmd->msgType = TSDB_MSG_TYPE_STABLE_VGROUP; pCmd->payloadLen = (int32_t)(pMsg - pCmd->payload); return TSDB_CODE_SUCCESS; @@ -1948,7 +1948,7 @@ int tscBuildRetrieveFuncMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pMsg += varDataNetTLen(pMsg); } - pCmd->msgType = TSDB_MSG_TYPE_CM_RETRIEVE_FUNC; + pCmd->msgType = TSDB_MSG_TYPE_RETRIEVE_FUNC; pCmd->payloadLen = (int32_t)(pMsg - pCmd->payload); return TSDB_CODE_SUCCESS; @@ -1996,7 +1996,7 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pthread_mutex_unlock(&pObj->mutex); pCmd->payloadLen = msgLen; - pCmd->msgType = TSDB_MSG_TYPE_CM_HEARTBEAT; + pCmd->msgType = TSDB_MSG_TYPE_HEARTBEAT; return TSDB_CODE_SUCCESS; } @@ -2838,7 +2838,7 @@ static int32_t getTableMetaFromMnode(SSqlObj *pSql, STableMetaInfo *pTableMetaIn } pNew->cmd.payloadLen = (int32_t)(pMsg - (char*)pInfoMsg); - pNew->cmd.msgType = TSDB_MSG_TYPE_CM_TABLE_META; + pNew->cmd.msgType = TSDB_MSG_TYPE_TABLE_META; } int32_t code = tscBuildAndSendRequest(pNew, NULL); @@ -2913,7 +2913,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg } pNew->cmd.payloadLen = (int32_t) ((start - pInfo->tableNames) + sizeof(SMultiTableInfoMsg)); - pNew->cmd.msgType = TSDB_MSG_TYPE_CM_TABLES_META; + pNew->cmd.msgType = TSDB_MSG_TYPE_TABLES_META; registerSqlObj(pNew); tscDebug("0x%"PRIx64" new pSqlObj:0x%"PRIx64" to get %d tableMeta, vgroupInfo:%d, udf:%d, msg size:%d", pSql->self, diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 59c20270ec..986ce41a9c 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -5011,7 +5011,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt SSqlCmd *pCmd = &pSql->cmd; pCmd->command = TSDB_SQL_MULTI_META; - pCmd->msgType = TSDB_MSG_TYPE_CM_TABLES_META; + pCmd->msgType = TSDB_MSG_TYPE_TABLES_META; int code = TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH; char *str = (char *)pNameList; From a3eef865beae60b3a681efc546ca7bcdf092f96d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 19:55:39 +0800 Subject: [PATCH 09/17] remove dnode to mgmt --- source/{server => dnode}/CMakeLists.txt | 0 source/{server/dnode => dnode/mgmt}/CMakeLists.txt | 0 source/{server/dnode => dnode/mgmt}/inc/dnodeCheck.h | 0 source/{server/dnode => dnode/mgmt}/inc/dnodeEps.h | 0 source/{server/dnode => dnode/mgmt}/inc/dnodeInt.h | 0 source/{server/dnode => dnode/mgmt}/inc/dnodeMsg.h | 0 source/{server/dnode => dnode/mgmt}/inc/dnodeTrans.h | 0 source/{server/dnode => dnode/mgmt}/src/dnodeCheck.c | 0 source/{server/dnode => dnode/mgmt}/src/dnodeEps.c | 0 source/{server/dnode => dnode/mgmt}/src/dnodeInt.c | 0 source/{server/dnode => dnode/mgmt}/src/dnodeMsg.c | 0 source/{server/dnode => dnode/mgmt}/src/dnodeTrans.c | 0 source/{server => dnode}/mnode/CMakeLists.txt | 0 source/{server => dnode}/mnode/inc/mnodeAcct.h | 0 source/{server => dnode}/mnode/inc/mnodeAuth.h | 0 source/{server => dnode}/mnode/inc/mnodeBalance.h | 0 source/{server => dnode}/mnode/inc/mnodeCluster.h | 0 source/{server => dnode}/mnode/inc/mnodeDb.h | 0 source/{server => dnode}/mnode/inc/mnodeDef.h | 0 source/{server => dnode}/mnode/inc/mnodeDnode.h | 0 source/{server => dnode}/mnode/inc/mnodeFunc.h | 0 source/{server => dnode}/mnode/inc/mnodeInt.h | 0 source/{server => dnode}/mnode/inc/mnodeMnode.h | 0 source/{server => dnode}/mnode/inc/mnodeOper.h | 0 source/{server => dnode}/mnode/inc/mnodeProfile.h | 0 source/{server => dnode}/mnode/inc/mnodeSdb.h | 0 source/{server => dnode}/mnode/inc/mnodeShow.h | 0 source/{server => dnode}/mnode/inc/mnodeStable.h | 0 source/{server => dnode}/mnode/inc/mnodeSync.h | 0 source/{server => dnode}/mnode/inc/mnodeTelem.h | 0 source/{server => dnode}/mnode/inc/mnodeUser.h | 0 source/{server => dnode}/mnode/inc/mnodeVgroup.h | 0 source/{server => dnode}/mnode/inc/mnodeWorker.h | 0 source/{server => dnode}/mnode/src/mnodeAcct.c | 0 source/{server => dnode}/mnode/src/mnodeAuth.c | 0 source/{server => dnode}/mnode/src/mnodeBalance.c | 0 source/{server => dnode}/mnode/src/mnodeCluster.c | 0 source/{server => dnode}/mnode/src/mnodeDb.c | 0 source/{server => dnode}/mnode/src/mnodeDnode.c | 0 source/{server => dnode}/mnode/src/mnodeFunc.c | 0 source/{server => dnode}/mnode/src/mnodeMnode.c | 0 source/{server => dnode}/mnode/src/mnodeOper.c | 0 source/{server => dnode}/mnode/src/mnodeProfile.c | 0 source/{server => dnode}/mnode/src/mnodeSdb.c | 0 source/{server => dnode}/mnode/src/mnodeShow.c | 0 source/{server => dnode}/mnode/src/mnodeStable.c | 0 source/{server => dnode}/mnode/src/mnodeSync.c | 0 source/{server => dnode}/mnode/src/mnodeTelem.c | 0 source/{server => dnode}/mnode/src/mnodeUser.c | 0 source/{server => dnode}/mnode/src/mnodeVgroup.c | 0 source/{server => dnode}/mnode/src/mnodeWorker.c | 0 source/{server => dnode}/mnode/src/mondeInt.c | 0 source/{server => dnode}/mnode/test/mnodeTests.cpp | 0 source/{server => dnode}/qnode/CMakeLists.txt | 0 source/{server => dnode}/qnode/inc/qnodeInt.h | 0 source/{server => dnode}/qnode/src/qnode.c | 0 source/{server => dnode}/qnode/test/qnodeTests.cpp | 0 source/{server => dnode}/server.c | 0 source/{server => dnode}/vnode/CMakeLists.txt | 0 source/{server => dnode}/vnode/impl/CMakeLists.txt | 0 source/{server => dnode}/vnode/impl/inc/vnodeCommit.h | 0 source/{server => dnode}/vnode/impl/inc/vnodeInt.h | 0 source/{server => dnode}/vnode/impl/inc/vnodeMemAllocator.h | 0 source/{server => dnode}/vnode/impl/inc/vnodeRead.h | 0 source/{server => dnode}/vnode/impl/inc/vnodeWrite.h | 0 source/{server => dnode}/vnode/impl/src/vnodeCommit.c | 0 source/{server => dnode}/vnode/impl/src/vnodeInt.c | 0 source/{server => dnode}/vnode/impl/src/vnodeMemAllocator.c | 0 source/{server => dnode}/vnode/impl/src/vnodeRead.c | 0 source/{server => dnode}/vnode/impl/src/vnodeWrite.c | 0 source/{server => dnode}/vnode/impl/test/CMakeLists.txt | 0 .../{server => dnode}/vnode/impl/test/vnodeMemAllocatorTest.cpp | 0 source/{server => dnode}/vnode/impl/test/vnodeTests.cpp | 0 source/{server => dnode}/vnode/meta/CMakeLists.txt | 0 source/{server => dnode}/vnode/meta/inc/metaDef.h | 0 source/{server => dnode}/vnode/meta/inc/metaUid.h | 0 source/{server => dnode}/vnode/meta/src/metaMain.c | 0 source/{server => dnode}/vnode/meta/src/metaUid.c | 0 source/{server => dnode}/vnode/meta/test/CMakeLists.txt | 0 source/{server => dnode}/vnode/meta/test/metaTests.cpp | 0 source/{server => dnode}/vnode/tq/CMakeLists.txt | 0 source/{server => dnode}/vnode/tq/inc/tqCommit.h | 0 source/{server => dnode}/vnode/tq/inc/tqInt.h | 0 source/{server => dnode}/vnode/tq/inc/tqMetaStore.h | 0 source/{server => dnode}/vnode/tq/src/tq.c | 0 source/{server => dnode}/vnode/tq/src/tqCommit.c | 0 source/{server => dnode}/vnode/tq/src/tqMetaStore.c | 0 source/{server => dnode}/vnode/tq/test/tqTests.cpp | 0 source/{server => dnode}/vnode/tsdb/CMakeLists.txt | 0 source/{server => dnode}/vnode/tsdb/inc/tsdbInt.h | 0 source/{server => dnode}/vnode/tsdb/inc/tsdbMemTable.h | 0 source/{server => dnode}/vnode/tsdb/inc/tsdbWriteBatch.h | 0 source/{server => dnode}/vnode/tsdb/src/tsdb.c | 0 source/{server => dnode}/vnode/tsdb/src/tsdbMemTable.c | 0 source/{server => dnode}/vnode/tsdb/src/tsdbSMA.c | 0 source/{server => dnode}/vnode/tsdb/test/tsdbTests.cpp | 0 96 files changed, 0 insertions(+), 0 deletions(-) rename source/{server => dnode}/CMakeLists.txt (100%) rename source/{server/dnode => dnode/mgmt}/CMakeLists.txt (100%) rename source/{server/dnode => dnode/mgmt}/inc/dnodeCheck.h (100%) rename source/{server/dnode => dnode/mgmt}/inc/dnodeEps.h (100%) rename source/{server/dnode => dnode/mgmt}/inc/dnodeInt.h (100%) rename source/{server/dnode => dnode/mgmt}/inc/dnodeMsg.h (100%) rename source/{server/dnode => dnode/mgmt}/inc/dnodeTrans.h (100%) rename source/{server/dnode => dnode/mgmt}/src/dnodeCheck.c (100%) rename source/{server/dnode => dnode/mgmt}/src/dnodeEps.c (100%) rename source/{server/dnode => dnode/mgmt}/src/dnodeInt.c (100%) rename source/{server/dnode => dnode/mgmt}/src/dnodeMsg.c (100%) rename source/{server/dnode => dnode/mgmt}/src/dnodeTrans.c (100%) rename source/{server => dnode}/mnode/CMakeLists.txt (100%) rename source/{server => dnode}/mnode/inc/mnodeAcct.h (100%) rename source/{server => dnode}/mnode/inc/mnodeAuth.h (100%) rename source/{server => dnode}/mnode/inc/mnodeBalance.h (100%) rename source/{server => dnode}/mnode/inc/mnodeCluster.h (100%) rename source/{server => dnode}/mnode/inc/mnodeDb.h (100%) rename source/{server => dnode}/mnode/inc/mnodeDef.h (100%) rename source/{server => dnode}/mnode/inc/mnodeDnode.h (100%) rename source/{server => dnode}/mnode/inc/mnodeFunc.h (100%) rename source/{server => dnode}/mnode/inc/mnodeInt.h (100%) rename source/{server => dnode}/mnode/inc/mnodeMnode.h (100%) rename source/{server => dnode}/mnode/inc/mnodeOper.h (100%) rename source/{server => dnode}/mnode/inc/mnodeProfile.h (100%) rename source/{server => dnode}/mnode/inc/mnodeSdb.h (100%) rename source/{server => dnode}/mnode/inc/mnodeShow.h (100%) rename source/{server => dnode}/mnode/inc/mnodeStable.h (100%) rename source/{server => dnode}/mnode/inc/mnodeSync.h (100%) rename source/{server => dnode}/mnode/inc/mnodeTelem.h (100%) rename source/{server => dnode}/mnode/inc/mnodeUser.h (100%) rename source/{server => dnode}/mnode/inc/mnodeVgroup.h (100%) rename source/{server => dnode}/mnode/inc/mnodeWorker.h (100%) rename source/{server => dnode}/mnode/src/mnodeAcct.c (100%) rename source/{server => dnode}/mnode/src/mnodeAuth.c (100%) rename source/{server => dnode}/mnode/src/mnodeBalance.c (100%) rename source/{server => dnode}/mnode/src/mnodeCluster.c (100%) rename source/{server => dnode}/mnode/src/mnodeDb.c (100%) rename source/{server => dnode}/mnode/src/mnodeDnode.c (100%) rename source/{server => dnode}/mnode/src/mnodeFunc.c (100%) rename source/{server => dnode}/mnode/src/mnodeMnode.c (100%) rename source/{server => dnode}/mnode/src/mnodeOper.c (100%) rename source/{server => dnode}/mnode/src/mnodeProfile.c (100%) rename source/{server => dnode}/mnode/src/mnodeSdb.c (100%) rename source/{server => dnode}/mnode/src/mnodeShow.c (100%) rename source/{server => dnode}/mnode/src/mnodeStable.c (100%) rename source/{server => dnode}/mnode/src/mnodeSync.c (100%) rename source/{server => dnode}/mnode/src/mnodeTelem.c (100%) rename source/{server => dnode}/mnode/src/mnodeUser.c (100%) rename source/{server => dnode}/mnode/src/mnodeVgroup.c (100%) rename source/{server => dnode}/mnode/src/mnodeWorker.c (100%) rename source/{server => dnode}/mnode/src/mondeInt.c (100%) rename source/{server => dnode}/mnode/test/mnodeTests.cpp (100%) rename source/{server => dnode}/qnode/CMakeLists.txt (100%) rename source/{server => dnode}/qnode/inc/qnodeInt.h (100%) rename source/{server => dnode}/qnode/src/qnode.c (100%) rename source/{server => dnode}/qnode/test/qnodeTests.cpp (100%) rename source/{server => dnode}/server.c (100%) rename source/{server => dnode}/vnode/CMakeLists.txt (100%) rename source/{server => dnode}/vnode/impl/CMakeLists.txt (100%) rename source/{server => dnode}/vnode/impl/inc/vnodeCommit.h (100%) rename source/{server => dnode}/vnode/impl/inc/vnodeInt.h (100%) rename source/{server => dnode}/vnode/impl/inc/vnodeMemAllocator.h (100%) rename source/{server => dnode}/vnode/impl/inc/vnodeRead.h (100%) rename source/{server => dnode}/vnode/impl/inc/vnodeWrite.h (100%) rename source/{server => dnode}/vnode/impl/src/vnodeCommit.c (100%) rename source/{server => dnode}/vnode/impl/src/vnodeInt.c (100%) rename source/{server => dnode}/vnode/impl/src/vnodeMemAllocator.c (100%) rename source/{server => dnode}/vnode/impl/src/vnodeRead.c (100%) rename source/{server => dnode}/vnode/impl/src/vnodeWrite.c (100%) rename source/{server => dnode}/vnode/impl/test/CMakeLists.txt (100%) rename source/{server => dnode}/vnode/impl/test/vnodeMemAllocatorTest.cpp (100%) rename source/{server => dnode}/vnode/impl/test/vnodeTests.cpp (100%) rename source/{server => dnode}/vnode/meta/CMakeLists.txt (100%) rename source/{server => dnode}/vnode/meta/inc/metaDef.h (100%) rename source/{server => dnode}/vnode/meta/inc/metaUid.h (100%) rename source/{server => dnode}/vnode/meta/src/metaMain.c (100%) rename source/{server => dnode}/vnode/meta/src/metaUid.c (100%) rename source/{server => dnode}/vnode/meta/test/CMakeLists.txt (100%) rename source/{server => dnode}/vnode/meta/test/metaTests.cpp (100%) rename source/{server => dnode}/vnode/tq/CMakeLists.txt (100%) rename source/{server => dnode}/vnode/tq/inc/tqCommit.h (100%) rename source/{server => dnode}/vnode/tq/inc/tqInt.h (100%) rename source/{server => dnode}/vnode/tq/inc/tqMetaStore.h (100%) rename source/{server => dnode}/vnode/tq/src/tq.c (100%) rename source/{server => dnode}/vnode/tq/src/tqCommit.c (100%) rename source/{server => dnode}/vnode/tq/src/tqMetaStore.c (100%) rename source/{server => dnode}/vnode/tq/test/tqTests.cpp (100%) rename source/{server => dnode}/vnode/tsdb/CMakeLists.txt (100%) rename source/{server => dnode}/vnode/tsdb/inc/tsdbInt.h (100%) rename source/{server => dnode}/vnode/tsdb/inc/tsdbMemTable.h (100%) rename source/{server => dnode}/vnode/tsdb/inc/tsdbWriteBatch.h (100%) rename source/{server => dnode}/vnode/tsdb/src/tsdb.c (100%) rename source/{server => dnode}/vnode/tsdb/src/tsdbMemTable.c (100%) rename source/{server => dnode}/vnode/tsdb/src/tsdbSMA.c (100%) rename source/{server => dnode}/vnode/tsdb/test/tsdbTests.cpp (100%) diff --git a/source/server/CMakeLists.txt b/source/dnode/CMakeLists.txt similarity index 100% rename from source/server/CMakeLists.txt rename to source/dnode/CMakeLists.txt diff --git a/source/server/dnode/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt similarity index 100% rename from source/server/dnode/CMakeLists.txt rename to source/dnode/mgmt/CMakeLists.txt diff --git a/source/server/dnode/inc/dnodeCheck.h b/source/dnode/mgmt/inc/dnodeCheck.h similarity index 100% rename from source/server/dnode/inc/dnodeCheck.h rename to source/dnode/mgmt/inc/dnodeCheck.h diff --git a/source/server/dnode/inc/dnodeEps.h b/source/dnode/mgmt/inc/dnodeEps.h similarity index 100% rename from source/server/dnode/inc/dnodeEps.h rename to source/dnode/mgmt/inc/dnodeEps.h diff --git a/source/server/dnode/inc/dnodeInt.h b/source/dnode/mgmt/inc/dnodeInt.h similarity index 100% rename from source/server/dnode/inc/dnodeInt.h rename to source/dnode/mgmt/inc/dnodeInt.h diff --git a/source/server/dnode/inc/dnodeMsg.h b/source/dnode/mgmt/inc/dnodeMsg.h similarity index 100% rename from source/server/dnode/inc/dnodeMsg.h rename to source/dnode/mgmt/inc/dnodeMsg.h diff --git a/source/server/dnode/inc/dnodeTrans.h b/source/dnode/mgmt/inc/dnodeTrans.h similarity index 100% rename from source/server/dnode/inc/dnodeTrans.h rename to source/dnode/mgmt/inc/dnodeTrans.h diff --git a/source/server/dnode/src/dnodeCheck.c b/source/dnode/mgmt/src/dnodeCheck.c similarity index 100% rename from source/server/dnode/src/dnodeCheck.c rename to source/dnode/mgmt/src/dnodeCheck.c diff --git a/source/server/dnode/src/dnodeEps.c b/source/dnode/mgmt/src/dnodeEps.c similarity index 100% rename from source/server/dnode/src/dnodeEps.c rename to source/dnode/mgmt/src/dnodeEps.c diff --git a/source/server/dnode/src/dnodeInt.c b/source/dnode/mgmt/src/dnodeInt.c similarity index 100% rename from source/server/dnode/src/dnodeInt.c rename to source/dnode/mgmt/src/dnodeInt.c diff --git a/source/server/dnode/src/dnodeMsg.c b/source/dnode/mgmt/src/dnodeMsg.c similarity index 100% rename from source/server/dnode/src/dnodeMsg.c rename to source/dnode/mgmt/src/dnodeMsg.c diff --git a/source/server/dnode/src/dnodeTrans.c b/source/dnode/mgmt/src/dnodeTrans.c similarity index 100% rename from source/server/dnode/src/dnodeTrans.c rename to source/dnode/mgmt/src/dnodeTrans.c diff --git a/source/server/mnode/CMakeLists.txt b/source/dnode/mnode/CMakeLists.txt similarity index 100% rename from source/server/mnode/CMakeLists.txt rename to source/dnode/mnode/CMakeLists.txt diff --git a/source/server/mnode/inc/mnodeAcct.h b/source/dnode/mnode/inc/mnodeAcct.h similarity index 100% rename from source/server/mnode/inc/mnodeAcct.h rename to source/dnode/mnode/inc/mnodeAcct.h diff --git a/source/server/mnode/inc/mnodeAuth.h b/source/dnode/mnode/inc/mnodeAuth.h similarity index 100% rename from source/server/mnode/inc/mnodeAuth.h rename to source/dnode/mnode/inc/mnodeAuth.h diff --git a/source/server/mnode/inc/mnodeBalance.h b/source/dnode/mnode/inc/mnodeBalance.h similarity index 100% rename from source/server/mnode/inc/mnodeBalance.h rename to source/dnode/mnode/inc/mnodeBalance.h diff --git a/source/server/mnode/inc/mnodeCluster.h b/source/dnode/mnode/inc/mnodeCluster.h similarity index 100% rename from source/server/mnode/inc/mnodeCluster.h rename to source/dnode/mnode/inc/mnodeCluster.h diff --git a/source/server/mnode/inc/mnodeDb.h b/source/dnode/mnode/inc/mnodeDb.h similarity index 100% rename from source/server/mnode/inc/mnodeDb.h rename to source/dnode/mnode/inc/mnodeDb.h diff --git a/source/server/mnode/inc/mnodeDef.h b/source/dnode/mnode/inc/mnodeDef.h similarity index 100% rename from source/server/mnode/inc/mnodeDef.h rename to source/dnode/mnode/inc/mnodeDef.h diff --git a/source/server/mnode/inc/mnodeDnode.h b/source/dnode/mnode/inc/mnodeDnode.h similarity index 100% rename from source/server/mnode/inc/mnodeDnode.h rename to source/dnode/mnode/inc/mnodeDnode.h diff --git a/source/server/mnode/inc/mnodeFunc.h b/source/dnode/mnode/inc/mnodeFunc.h similarity index 100% rename from source/server/mnode/inc/mnodeFunc.h rename to source/dnode/mnode/inc/mnodeFunc.h diff --git a/source/server/mnode/inc/mnodeInt.h b/source/dnode/mnode/inc/mnodeInt.h similarity index 100% rename from source/server/mnode/inc/mnodeInt.h rename to source/dnode/mnode/inc/mnodeInt.h diff --git a/source/server/mnode/inc/mnodeMnode.h b/source/dnode/mnode/inc/mnodeMnode.h similarity index 100% rename from source/server/mnode/inc/mnodeMnode.h rename to source/dnode/mnode/inc/mnodeMnode.h diff --git a/source/server/mnode/inc/mnodeOper.h b/source/dnode/mnode/inc/mnodeOper.h similarity index 100% rename from source/server/mnode/inc/mnodeOper.h rename to source/dnode/mnode/inc/mnodeOper.h diff --git a/source/server/mnode/inc/mnodeProfile.h b/source/dnode/mnode/inc/mnodeProfile.h similarity index 100% rename from source/server/mnode/inc/mnodeProfile.h rename to source/dnode/mnode/inc/mnodeProfile.h diff --git a/source/server/mnode/inc/mnodeSdb.h b/source/dnode/mnode/inc/mnodeSdb.h similarity index 100% rename from source/server/mnode/inc/mnodeSdb.h rename to source/dnode/mnode/inc/mnodeSdb.h diff --git a/source/server/mnode/inc/mnodeShow.h b/source/dnode/mnode/inc/mnodeShow.h similarity index 100% rename from source/server/mnode/inc/mnodeShow.h rename to source/dnode/mnode/inc/mnodeShow.h diff --git a/source/server/mnode/inc/mnodeStable.h b/source/dnode/mnode/inc/mnodeStable.h similarity index 100% rename from source/server/mnode/inc/mnodeStable.h rename to source/dnode/mnode/inc/mnodeStable.h diff --git a/source/server/mnode/inc/mnodeSync.h b/source/dnode/mnode/inc/mnodeSync.h similarity index 100% rename from source/server/mnode/inc/mnodeSync.h rename to source/dnode/mnode/inc/mnodeSync.h diff --git a/source/server/mnode/inc/mnodeTelem.h b/source/dnode/mnode/inc/mnodeTelem.h similarity index 100% rename from source/server/mnode/inc/mnodeTelem.h rename to source/dnode/mnode/inc/mnodeTelem.h diff --git a/source/server/mnode/inc/mnodeUser.h b/source/dnode/mnode/inc/mnodeUser.h similarity index 100% rename from source/server/mnode/inc/mnodeUser.h rename to source/dnode/mnode/inc/mnodeUser.h diff --git a/source/server/mnode/inc/mnodeVgroup.h b/source/dnode/mnode/inc/mnodeVgroup.h similarity index 100% rename from source/server/mnode/inc/mnodeVgroup.h rename to source/dnode/mnode/inc/mnodeVgroup.h diff --git a/source/server/mnode/inc/mnodeWorker.h b/source/dnode/mnode/inc/mnodeWorker.h similarity index 100% rename from source/server/mnode/inc/mnodeWorker.h rename to source/dnode/mnode/inc/mnodeWorker.h diff --git a/source/server/mnode/src/mnodeAcct.c b/source/dnode/mnode/src/mnodeAcct.c similarity index 100% rename from source/server/mnode/src/mnodeAcct.c rename to source/dnode/mnode/src/mnodeAcct.c diff --git a/source/server/mnode/src/mnodeAuth.c b/source/dnode/mnode/src/mnodeAuth.c similarity index 100% rename from source/server/mnode/src/mnodeAuth.c rename to source/dnode/mnode/src/mnodeAuth.c diff --git a/source/server/mnode/src/mnodeBalance.c b/source/dnode/mnode/src/mnodeBalance.c similarity index 100% rename from source/server/mnode/src/mnodeBalance.c rename to source/dnode/mnode/src/mnodeBalance.c diff --git a/source/server/mnode/src/mnodeCluster.c b/source/dnode/mnode/src/mnodeCluster.c similarity index 100% rename from source/server/mnode/src/mnodeCluster.c rename to source/dnode/mnode/src/mnodeCluster.c diff --git a/source/server/mnode/src/mnodeDb.c b/source/dnode/mnode/src/mnodeDb.c similarity index 100% rename from source/server/mnode/src/mnodeDb.c rename to source/dnode/mnode/src/mnodeDb.c diff --git a/source/server/mnode/src/mnodeDnode.c b/source/dnode/mnode/src/mnodeDnode.c similarity index 100% rename from source/server/mnode/src/mnodeDnode.c rename to source/dnode/mnode/src/mnodeDnode.c diff --git a/source/server/mnode/src/mnodeFunc.c b/source/dnode/mnode/src/mnodeFunc.c similarity index 100% rename from source/server/mnode/src/mnodeFunc.c rename to source/dnode/mnode/src/mnodeFunc.c diff --git a/source/server/mnode/src/mnodeMnode.c b/source/dnode/mnode/src/mnodeMnode.c similarity index 100% rename from source/server/mnode/src/mnodeMnode.c rename to source/dnode/mnode/src/mnodeMnode.c diff --git a/source/server/mnode/src/mnodeOper.c b/source/dnode/mnode/src/mnodeOper.c similarity index 100% rename from source/server/mnode/src/mnodeOper.c rename to source/dnode/mnode/src/mnodeOper.c diff --git a/source/server/mnode/src/mnodeProfile.c b/source/dnode/mnode/src/mnodeProfile.c similarity index 100% rename from source/server/mnode/src/mnodeProfile.c rename to source/dnode/mnode/src/mnodeProfile.c diff --git a/source/server/mnode/src/mnodeSdb.c b/source/dnode/mnode/src/mnodeSdb.c similarity index 100% rename from source/server/mnode/src/mnodeSdb.c rename to source/dnode/mnode/src/mnodeSdb.c diff --git a/source/server/mnode/src/mnodeShow.c b/source/dnode/mnode/src/mnodeShow.c similarity index 100% rename from source/server/mnode/src/mnodeShow.c rename to source/dnode/mnode/src/mnodeShow.c diff --git a/source/server/mnode/src/mnodeStable.c b/source/dnode/mnode/src/mnodeStable.c similarity index 100% rename from source/server/mnode/src/mnodeStable.c rename to source/dnode/mnode/src/mnodeStable.c diff --git a/source/server/mnode/src/mnodeSync.c b/source/dnode/mnode/src/mnodeSync.c similarity index 100% rename from source/server/mnode/src/mnodeSync.c rename to source/dnode/mnode/src/mnodeSync.c diff --git a/source/server/mnode/src/mnodeTelem.c b/source/dnode/mnode/src/mnodeTelem.c similarity index 100% rename from source/server/mnode/src/mnodeTelem.c rename to source/dnode/mnode/src/mnodeTelem.c diff --git a/source/server/mnode/src/mnodeUser.c b/source/dnode/mnode/src/mnodeUser.c similarity index 100% rename from source/server/mnode/src/mnodeUser.c rename to source/dnode/mnode/src/mnodeUser.c diff --git a/source/server/mnode/src/mnodeVgroup.c b/source/dnode/mnode/src/mnodeVgroup.c similarity index 100% rename from source/server/mnode/src/mnodeVgroup.c rename to source/dnode/mnode/src/mnodeVgroup.c diff --git a/source/server/mnode/src/mnodeWorker.c b/source/dnode/mnode/src/mnodeWorker.c similarity index 100% rename from source/server/mnode/src/mnodeWorker.c rename to source/dnode/mnode/src/mnodeWorker.c diff --git a/source/server/mnode/src/mondeInt.c b/source/dnode/mnode/src/mondeInt.c similarity index 100% rename from source/server/mnode/src/mondeInt.c rename to source/dnode/mnode/src/mondeInt.c diff --git a/source/server/mnode/test/mnodeTests.cpp b/source/dnode/mnode/test/mnodeTests.cpp similarity index 100% rename from source/server/mnode/test/mnodeTests.cpp rename to source/dnode/mnode/test/mnodeTests.cpp diff --git a/source/server/qnode/CMakeLists.txt b/source/dnode/qnode/CMakeLists.txt similarity index 100% rename from source/server/qnode/CMakeLists.txt rename to source/dnode/qnode/CMakeLists.txt diff --git a/source/server/qnode/inc/qnodeInt.h b/source/dnode/qnode/inc/qnodeInt.h similarity index 100% rename from source/server/qnode/inc/qnodeInt.h rename to source/dnode/qnode/inc/qnodeInt.h diff --git a/source/server/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c similarity index 100% rename from source/server/qnode/src/qnode.c rename to source/dnode/qnode/src/qnode.c diff --git a/source/server/qnode/test/qnodeTests.cpp b/source/dnode/qnode/test/qnodeTests.cpp similarity index 100% rename from source/server/qnode/test/qnodeTests.cpp rename to source/dnode/qnode/test/qnodeTests.cpp diff --git a/source/server/server.c b/source/dnode/server.c similarity index 100% rename from source/server/server.c rename to source/dnode/server.c diff --git a/source/server/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt similarity index 100% rename from source/server/vnode/CMakeLists.txt rename to source/dnode/vnode/CMakeLists.txt diff --git a/source/server/vnode/impl/CMakeLists.txt b/source/dnode/vnode/impl/CMakeLists.txt similarity index 100% rename from source/server/vnode/impl/CMakeLists.txt rename to source/dnode/vnode/impl/CMakeLists.txt diff --git a/source/server/vnode/impl/inc/vnodeCommit.h b/source/dnode/vnode/impl/inc/vnodeCommit.h similarity index 100% rename from source/server/vnode/impl/inc/vnodeCommit.h rename to source/dnode/vnode/impl/inc/vnodeCommit.h diff --git a/source/server/vnode/impl/inc/vnodeInt.h b/source/dnode/vnode/impl/inc/vnodeInt.h similarity index 100% rename from source/server/vnode/impl/inc/vnodeInt.h rename to source/dnode/vnode/impl/inc/vnodeInt.h diff --git a/source/server/vnode/impl/inc/vnodeMemAllocator.h b/source/dnode/vnode/impl/inc/vnodeMemAllocator.h similarity index 100% rename from source/server/vnode/impl/inc/vnodeMemAllocator.h rename to source/dnode/vnode/impl/inc/vnodeMemAllocator.h diff --git a/source/server/vnode/impl/inc/vnodeRead.h b/source/dnode/vnode/impl/inc/vnodeRead.h similarity index 100% rename from source/server/vnode/impl/inc/vnodeRead.h rename to source/dnode/vnode/impl/inc/vnodeRead.h diff --git a/source/server/vnode/impl/inc/vnodeWrite.h b/source/dnode/vnode/impl/inc/vnodeWrite.h similarity index 100% rename from source/server/vnode/impl/inc/vnodeWrite.h rename to source/dnode/vnode/impl/inc/vnodeWrite.h diff --git a/source/server/vnode/impl/src/vnodeCommit.c b/source/dnode/vnode/impl/src/vnodeCommit.c similarity index 100% rename from source/server/vnode/impl/src/vnodeCommit.c rename to source/dnode/vnode/impl/src/vnodeCommit.c diff --git a/source/server/vnode/impl/src/vnodeInt.c b/source/dnode/vnode/impl/src/vnodeInt.c similarity index 100% rename from source/server/vnode/impl/src/vnodeInt.c rename to source/dnode/vnode/impl/src/vnodeInt.c diff --git a/source/server/vnode/impl/src/vnodeMemAllocator.c b/source/dnode/vnode/impl/src/vnodeMemAllocator.c similarity index 100% rename from source/server/vnode/impl/src/vnodeMemAllocator.c rename to source/dnode/vnode/impl/src/vnodeMemAllocator.c diff --git a/source/server/vnode/impl/src/vnodeRead.c b/source/dnode/vnode/impl/src/vnodeRead.c similarity index 100% rename from source/server/vnode/impl/src/vnodeRead.c rename to source/dnode/vnode/impl/src/vnodeRead.c diff --git a/source/server/vnode/impl/src/vnodeWrite.c b/source/dnode/vnode/impl/src/vnodeWrite.c similarity index 100% rename from source/server/vnode/impl/src/vnodeWrite.c rename to source/dnode/vnode/impl/src/vnodeWrite.c diff --git a/source/server/vnode/impl/test/CMakeLists.txt b/source/dnode/vnode/impl/test/CMakeLists.txt similarity index 100% rename from source/server/vnode/impl/test/CMakeLists.txt rename to source/dnode/vnode/impl/test/CMakeLists.txt diff --git a/source/server/vnode/impl/test/vnodeMemAllocatorTest.cpp b/source/dnode/vnode/impl/test/vnodeMemAllocatorTest.cpp similarity index 100% rename from source/server/vnode/impl/test/vnodeMemAllocatorTest.cpp rename to source/dnode/vnode/impl/test/vnodeMemAllocatorTest.cpp diff --git a/source/server/vnode/impl/test/vnodeTests.cpp b/source/dnode/vnode/impl/test/vnodeTests.cpp similarity index 100% rename from source/server/vnode/impl/test/vnodeTests.cpp rename to source/dnode/vnode/impl/test/vnodeTests.cpp diff --git a/source/server/vnode/meta/CMakeLists.txt b/source/dnode/vnode/meta/CMakeLists.txt similarity index 100% rename from source/server/vnode/meta/CMakeLists.txt rename to source/dnode/vnode/meta/CMakeLists.txt diff --git a/source/server/vnode/meta/inc/metaDef.h b/source/dnode/vnode/meta/inc/metaDef.h similarity index 100% rename from source/server/vnode/meta/inc/metaDef.h rename to source/dnode/vnode/meta/inc/metaDef.h diff --git a/source/server/vnode/meta/inc/metaUid.h b/source/dnode/vnode/meta/inc/metaUid.h similarity index 100% rename from source/server/vnode/meta/inc/metaUid.h rename to source/dnode/vnode/meta/inc/metaUid.h diff --git a/source/server/vnode/meta/src/metaMain.c b/source/dnode/vnode/meta/src/metaMain.c similarity index 100% rename from source/server/vnode/meta/src/metaMain.c rename to source/dnode/vnode/meta/src/metaMain.c diff --git a/source/server/vnode/meta/src/metaUid.c b/source/dnode/vnode/meta/src/metaUid.c similarity index 100% rename from source/server/vnode/meta/src/metaUid.c rename to source/dnode/vnode/meta/src/metaUid.c diff --git a/source/server/vnode/meta/test/CMakeLists.txt b/source/dnode/vnode/meta/test/CMakeLists.txt similarity index 100% rename from source/server/vnode/meta/test/CMakeLists.txt rename to source/dnode/vnode/meta/test/CMakeLists.txt diff --git a/source/server/vnode/meta/test/metaTests.cpp b/source/dnode/vnode/meta/test/metaTests.cpp similarity index 100% rename from source/server/vnode/meta/test/metaTests.cpp rename to source/dnode/vnode/meta/test/metaTests.cpp diff --git a/source/server/vnode/tq/CMakeLists.txt b/source/dnode/vnode/tq/CMakeLists.txt similarity index 100% rename from source/server/vnode/tq/CMakeLists.txt rename to source/dnode/vnode/tq/CMakeLists.txt diff --git a/source/server/vnode/tq/inc/tqCommit.h b/source/dnode/vnode/tq/inc/tqCommit.h similarity index 100% rename from source/server/vnode/tq/inc/tqCommit.h rename to source/dnode/vnode/tq/inc/tqCommit.h diff --git a/source/server/vnode/tq/inc/tqInt.h b/source/dnode/vnode/tq/inc/tqInt.h similarity index 100% rename from source/server/vnode/tq/inc/tqInt.h rename to source/dnode/vnode/tq/inc/tqInt.h diff --git a/source/server/vnode/tq/inc/tqMetaStore.h b/source/dnode/vnode/tq/inc/tqMetaStore.h similarity index 100% rename from source/server/vnode/tq/inc/tqMetaStore.h rename to source/dnode/vnode/tq/inc/tqMetaStore.h diff --git a/source/server/vnode/tq/src/tq.c b/source/dnode/vnode/tq/src/tq.c similarity index 100% rename from source/server/vnode/tq/src/tq.c rename to source/dnode/vnode/tq/src/tq.c diff --git a/source/server/vnode/tq/src/tqCommit.c b/source/dnode/vnode/tq/src/tqCommit.c similarity index 100% rename from source/server/vnode/tq/src/tqCommit.c rename to source/dnode/vnode/tq/src/tqCommit.c diff --git a/source/server/vnode/tq/src/tqMetaStore.c b/source/dnode/vnode/tq/src/tqMetaStore.c similarity index 100% rename from source/server/vnode/tq/src/tqMetaStore.c rename to source/dnode/vnode/tq/src/tqMetaStore.c diff --git a/source/server/vnode/tq/test/tqTests.cpp b/source/dnode/vnode/tq/test/tqTests.cpp similarity index 100% rename from source/server/vnode/tq/test/tqTests.cpp rename to source/dnode/vnode/tq/test/tqTests.cpp diff --git a/source/server/vnode/tsdb/CMakeLists.txt b/source/dnode/vnode/tsdb/CMakeLists.txt similarity index 100% rename from source/server/vnode/tsdb/CMakeLists.txt rename to source/dnode/vnode/tsdb/CMakeLists.txt diff --git a/source/server/vnode/tsdb/inc/tsdbInt.h b/source/dnode/vnode/tsdb/inc/tsdbInt.h similarity index 100% rename from source/server/vnode/tsdb/inc/tsdbInt.h rename to source/dnode/vnode/tsdb/inc/tsdbInt.h diff --git a/source/server/vnode/tsdb/inc/tsdbMemTable.h b/source/dnode/vnode/tsdb/inc/tsdbMemTable.h similarity index 100% rename from source/server/vnode/tsdb/inc/tsdbMemTable.h rename to source/dnode/vnode/tsdb/inc/tsdbMemTable.h diff --git a/source/server/vnode/tsdb/inc/tsdbWriteBatch.h b/source/dnode/vnode/tsdb/inc/tsdbWriteBatch.h similarity index 100% rename from source/server/vnode/tsdb/inc/tsdbWriteBatch.h rename to source/dnode/vnode/tsdb/inc/tsdbWriteBatch.h diff --git a/source/server/vnode/tsdb/src/tsdb.c b/source/dnode/vnode/tsdb/src/tsdb.c similarity index 100% rename from source/server/vnode/tsdb/src/tsdb.c rename to source/dnode/vnode/tsdb/src/tsdb.c diff --git a/source/server/vnode/tsdb/src/tsdbMemTable.c b/source/dnode/vnode/tsdb/src/tsdbMemTable.c similarity index 100% rename from source/server/vnode/tsdb/src/tsdbMemTable.c rename to source/dnode/vnode/tsdb/src/tsdbMemTable.c diff --git a/source/server/vnode/tsdb/src/tsdbSMA.c b/source/dnode/vnode/tsdb/src/tsdbSMA.c similarity index 100% rename from source/server/vnode/tsdb/src/tsdbSMA.c rename to source/dnode/vnode/tsdb/src/tsdbSMA.c diff --git a/source/server/vnode/tsdb/test/tsdbTests.cpp b/source/dnode/vnode/tsdb/test/tsdbTests.cpp similarity index 100% rename from source/server/vnode/tsdb/test/tsdbTests.cpp rename to source/dnode/vnode/tsdb/test/tsdbTests.cpp From d9fc5d8c3f227dcda49ec753389785277f9d8162 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 19:59:09 +0800 Subject: [PATCH 10/17] rename dnode to mgmt --- source/CMakeLists.txt | 2 +- source/dnode/CMakeLists.txt | 10 +--------- source/dnode/mgmt/CMakeLists.txt | 8 ++++---- source/dnode/{server.c => mgmt/src/dnodeMain.c} | 0 4 files changed, 6 insertions(+), 14 deletions(-) rename source/dnode/{server.c => mgmt/src/dnodeMain.c} (100%) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 11193d7185..2833b329a7 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -3,4 +3,4 @@ add_subdirectory(util) add_subdirectory(common) add_subdirectory(libs) add_subdirectory(client) -add_subdirectory(server) \ No newline at end of file +add_subdirectory(dnode) \ No newline at end of file diff --git a/source/dnode/CMakeLists.txt b/source/dnode/CMakeLists.txt index 8afa650d36..d719a2d106 100644 --- a/source/dnode/CMakeLists.txt +++ b/source/dnode/CMakeLists.txt @@ -1,12 +1,4 @@ add_subdirectory(mnode) add_subdirectory(vnode) add_subdirectory(qnode) -add_subdirectory(dnode) - -aux_source_directory(. TAOSD_SRC) -add_executable(taosd ${TAOSD_SRC}) -target_link_libraries( - taosd - PUBLIC dnode - PUBLIC util -) \ No newline at end of file +add_subdirectory(mgmt) diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index e1462ab3c8..74ee422bb0 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,7 +1,7 @@ aux_source_directory(src DNODE_SRC) -add_library(dnode ${DNODE_SRC}) +add_executable(taosd ${DNODE_SRC}) target_link_libraries( - dnode + taosd PUBLIC cjson PUBLIC mnode PUBLIC vnode @@ -10,7 +10,7 @@ target_link_libraries( PUBLIC taos ) target_include_directories( - dnode + taosd PUBLIC "${CMAKE_SOURCE_DIR}/include/server/dnode" private "${CMAKE_CURRENT_SOURCE_DIR}/inc" -) \ No newline at end of file +) diff --git a/source/dnode/server.c b/source/dnode/mgmt/src/dnodeMain.c similarity index 100% rename from source/dnode/server.c rename to source/dnode/mgmt/src/dnodeMain.c From f528d5a13d0ae4ef04fcb54c6eafb802c9544df6 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 20:02:30 +0800 Subject: [PATCH 11/17] remove dnode.h --- include/server/dnode/dnode.h | 79 ------------------------------- source/dnode/mgmt/inc/dnodeInt.h | 4 +- source/dnode/mgmt/src/dnodeMain.c | 2 +- 3 files changed, 4 insertions(+), 81 deletions(-) delete mode 100644 include/server/dnode/dnode.h diff --git a/include/server/dnode/dnode.h b/include/server/dnode/dnode.h deleted file mode 100644 index bc0d1e89b0..0000000000 --- a/include/server/dnode/dnode.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_DNODE_H_ -#define _TD_DNODE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -struct SRpcEpSet; -struct SRpcMsg; -/** - * Initialize and start the dnode module. - * - * @return Error code. - */ -int32_t dnodeInit(); - -/** - * Stop and cleanup dnode module. - */ -void dnodeCleanup(); - -/** - * Send messages to other dnodes, such as create vnode message. - * - * @param epSet, the endpoint list of the dnodes. - * @param rpcMsg, message to be sent. - */ -void dnodeSendMsgToDnode(struct SRpcEpSet *epSet, struct SRpcMsg *rpcMsg); - -/** - * Send messages to mnode, such as config message. - * - * @param rpcMsg, message to be sent. - */ -void dnodeSendMsgToMnode(struct SRpcMsg *rpcMsg); - -/** - * Send redirect message to dnode or shell. - * - * @param rpcMsg, message to be sent. - * @param forShell, used to identify whether to send to shell or dnode. - */ -void dnodeSendRedirectMsg(struct SRpcMsg *rpcMsg, bool forShell); - -/** - * Get the corresponding endpoint information from dnodeId. - * - * @param dnodeId, the id ot dnode. - * @param ep, the endpoint of dnode. - * @param fqdn, the fqdn of dnode. - * @param port, the port of dnode. - */ -void dnodeGetEp(int32_t dnodeId, char *ep, char *fqdn, uint16_t *port); - -/** - * Report the startup progress. - */ -void dnodeReportStartup(char *name, char *desc); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_DNODE_H_*/ diff --git a/source/dnode/mgmt/inc/dnodeInt.h b/source/dnode/mgmt/inc/dnodeInt.h index 85f474a391..20257140d6 100644 --- a/source/dnode/mgmt/inc/dnodeInt.h +++ b/source/dnode/mgmt/inc/dnodeInt.h @@ -25,7 +25,6 @@ extern "C" { #include "tlog.h" #include "trpc.h" #include "ttimer.h" -#include "dnode.h" extern int32_t dDebugFlag; @@ -38,6 +37,9 @@ extern int32_t dDebugFlag; typedef enum { DN_RUN_STAT_INIT, DN_RUN_STAT_RUNNING, DN_RUN_STAT_STOPPED } EDnStat; +int32_t dnodeInit(); +void dnodeCleanup(); + EDnStat dnodeGetRunStat(); void dnodeSetRunStat(); void dnodeGetStartup(SStartupStep *); diff --git a/source/dnode/mgmt/src/dnodeMain.c b/source/dnode/mgmt/src/dnodeMain.c index 67e8e7bc58..c41acc6853 100644 --- a/source/dnode/mgmt/src/dnodeMain.c +++ b/source/dnode/mgmt/src/dnodeMain.c @@ -14,7 +14,7 @@ */ #include "os.h" #include "ulog.h" -#include "dnode.h" +#include "dnodeInt.h" static bool stop = false; static void sigintHandler(int32_t signum, void *info, void *ctx) { stop = true; } From 401cf95662b7d9c56de0f773cd50abeffae68c8f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 20:08:54 +0800 Subject: [PATCH 12/17] refact file directory --- .../mgmt/inc/{dnodeEps.h => dnodeConfig.h} | 6 +- source/dnode/mgmt/inc/dnodeDnode.h | 34 ++ source/dnode/mgmt/inc/dnodeMnode.h | 30 ++ .../inc/{dnodeTrans.h => dnodeTransport.h} | 6 +- .../mgmt/inc/{dnodeMsg.h => dnodeVnodes.h} | 6 +- .../mgmt/src/{dnodeEps.c => dnodeConfig.c} | 2 +- source/dnode/mgmt/src/dnodeDnode.c | 174 ++++++++ source/dnode/mgmt/src/dnodeInt.c | 6 +- source/dnode/mgmt/src/dnodeTransport.c | 382 ++++++++++++++++++ source/dnode/mgmt/src/dnodeVnodes.c | 0 source/server/dnode/src/dnodeInt.c | 204 ++++++++++ .../mgmt => server/dnode}/src/dnodeMsg.c | 4 +- .../mgmt => server/dnode}/src/dnodeTrans.c | 6 +- 13 files changed, 842 insertions(+), 18 deletions(-) rename source/dnode/mgmt/inc/{dnodeEps.h => dnodeConfig.h} (93%) create mode 100644 source/dnode/mgmt/inc/dnodeDnode.h create mode 100644 source/dnode/mgmt/inc/dnodeMnode.h rename source/dnode/mgmt/inc/{dnodeTrans.h => dnodeTransport.h} (90%) rename source/dnode/mgmt/inc/{dnodeMsg.h => dnodeVnodes.h} (91%) rename source/dnode/mgmt/src/{dnodeEps.c => dnodeConfig.c} (99%) create mode 100644 source/dnode/mgmt/src/dnodeDnode.c create mode 100644 source/dnode/mgmt/src/dnodeTransport.c create mode 100644 source/dnode/mgmt/src/dnodeVnodes.c create mode 100644 source/server/dnode/src/dnodeInt.c rename source/{dnode/mgmt => server/dnode}/src/dnodeMsg.c (99%) rename source/{dnode/mgmt => server/dnode}/src/dnodeTrans.c (99%) diff --git a/source/dnode/mgmt/inc/dnodeEps.h b/source/dnode/mgmt/inc/dnodeConfig.h similarity index 93% rename from source/dnode/mgmt/inc/dnodeEps.h rename to source/dnode/mgmt/inc/dnodeConfig.h index ac68d16374..9d446a9f1a 100644 --- a/source/dnode/mgmt/inc/dnodeEps.h +++ b/source/dnode/mgmt/inc/dnodeConfig.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_DNODE_EPS_H_ -#define _TD_DNODE_EPS_H_ +#ifndef _TD_DNODE_CONFIG_H_ +#define _TD_DNODE_CONFIG_H_ #ifdef __cplusplus extern "C" { @@ -39,4 +39,4 @@ void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell); } #endif -#endif /*_TD_DNODE_EPS_H_*/ \ No newline at end of file +#endif /*_TD_DNODE_CONFIG_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/inc/dnodeDnode.h b/source/dnode/mgmt/inc/dnodeDnode.h new file mode 100644 index 0000000000..35f68f0306 --- /dev/null +++ b/source/dnode/mgmt/inc/dnodeDnode.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_DNODE_DNODE_H_ +#define _TD_DNODE_DNODE_H_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "dnodeInt.h" + +int32_t dnodeInitMsg(); +void dnodeCleanupMsg(); +void dnodeProcessStatusRsp(SRpcMsg *pMsg); +void dnodeProcessStartupReq(SRpcMsg *pMsg); +void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DNODE_DNODE_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/inc/dnodeMnode.h b/source/dnode/mgmt/inc/dnodeMnode.h new file mode 100644 index 0000000000..0dccb8c39d --- /dev/null +++ b/source/dnode/mgmt/inc/dnodeMnode.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_DNODE_MNODE_H_ +#define _TD_DNODE_MNODE_H_ + +#ifdef __cplusplus +extern "C" { +#endif +#include "dnodeInt.h" + +void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DNODE_MNODE_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/inc/dnodeTrans.h b/source/dnode/mgmt/inc/dnodeTransport.h similarity index 90% rename from source/dnode/mgmt/inc/dnodeTrans.h rename to source/dnode/mgmt/inc/dnodeTransport.h index f2dc647de3..e8223f4c06 100644 --- a/source/dnode/mgmt/inc/dnodeTrans.h +++ b/source/dnode/mgmt/inc/dnodeTransport.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_DNODE_TRANS_H_ -#define _TD_DNODE_TRANS_H_ +#ifndef _TD_DNODE_TRANSPORT_H_ +#define _TD_DNODE_TRANSPORT_H_ #ifdef __cplusplus extern "C" { @@ -30,4 +30,4 @@ void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg); } #endif -#endif /*_TD_DNODE_TRANS_H_*/ +#endif /*_TD_DNODE_TRANSPORT_H_*/ diff --git a/source/dnode/mgmt/inc/dnodeMsg.h b/source/dnode/mgmt/inc/dnodeVnodes.h similarity index 91% rename from source/dnode/mgmt/inc/dnodeMsg.h rename to source/dnode/mgmt/inc/dnodeVnodes.h index 0790fa7e3e..d54fda654a 100644 --- a/source/dnode/mgmt/inc/dnodeMsg.h +++ b/source/dnode/mgmt/inc/dnodeVnodes.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_DNODE_STATUS_H_ -#define _TD_DNODE_STATUS_H_ +#ifndef _TD_DNODE_VNODES_H_ +#define _TD_DNODE_VNODES_H_ #ifdef __cplusplus extern "C" { @@ -32,4 +32,4 @@ void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg); } #endif -#endif /*_TD_DNODE_STATUS_H_*/ \ No newline at end of file +#endif /*_TD_DNODE_VNODES_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/src/dnodeEps.c b/source/dnode/mgmt/src/dnodeConfig.c similarity index 99% rename from source/dnode/mgmt/src/dnodeEps.c rename to source/dnode/mgmt/src/dnodeConfig.c index 5b843df2f2..fc4c821bb6 100644 --- a/source/dnode/mgmt/src/dnodeEps.c +++ b/source/dnode/mgmt/src/dnodeConfig.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dnodeEps.h" +#include "dnodeConfig.h" #include "cJSON.h" #include "thash.h" diff --git a/source/dnode/mgmt/src/dnodeDnode.c b/source/dnode/mgmt/src/dnodeDnode.c new file mode 100644 index 0000000000..0a598527b4 --- /dev/null +++ b/source/dnode/mgmt/src/dnodeDnode.c @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dnodeDnode.h" +#include "dnodeConfig.h" +#include "mnode.h" +#include "tthread.h" +#include "ttime.h" +#include "vnode.h" + +static struct { + pthread_t *threadId; + bool stop; + uint32_t rebootTime; +} tsMsg; + +static void dnodeSendStatusMsg() { + int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); + SStatusMsg *pStatus = rpcMallocCont(contLen); + if (pStatus == NULL) { + dError("failed to malloc status message"); + return; + } + + pStatus->version = htonl(tsVersion); + pStatus->dnodeId = htonl(dnodeGetDnodeId()); + tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN); + pStatus->clusterId = htobe64(dnodeGetClusterId()); + pStatus->lastReboot = htonl(tsMsg.rebootTime); + pStatus->numOfCores = htonl(tsNumOfCores); + pStatus->diskAvailable = tsAvailDataDirGB; + + // fill cluster cfg parameters + pStatus->clusterCfg.statusInterval = htonl(tsStatusInterval); + pStatus->clusterCfg.checkTime = 0; + tstrncpy(pStatus->clusterCfg.timezone, tsTimezone, 64); + char timestr[32] = "1970-01-01 00:00:00.00"; + (void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); + tstrncpy(pStatus->clusterCfg.locale, tsLocale, TSDB_LOCALE_LEN); + tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN); + + // vnodeGetStatus(NULL, pStatus); + // contLen = sizeof(SStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad); + // pStatus->openVnodes = htons(pStatus->openVnodes); + + SRpcMsg rpcMsg = {.ahandle = NULL, .pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_DM_STATUS}; + + dnodeSendMsgToMnode(&rpcMsg); +} + +void dnodeProcessStatusRsp(SRpcMsg *pMsg) { + dTrace("status rsp is received, code:%s", tstrerror(pMsg->code)); + if (pMsg->code != TSDB_CODE_SUCCESS) return; + + SStatusRsp *pStatusRsp = pMsg->pCont; + + SDnodeCfg *pCfg = &pStatusRsp->dnodeCfg; + pCfg->dnodeId = htonl(pCfg->dnodeId); + pCfg->clusterId = htobe64(pCfg->clusterId); + pCfg->numOfVnodes = htonl(pCfg->numOfVnodes); + pCfg->numOfDnodes = htonl(pCfg->numOfDnodes); + dnodeUpdateCfg(pCfg); + + if (pCfg->dropped) { + dError("status rsp is received, and set dnode to drop status"); + return; + } + + // vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes); + + SDnodeEps *eps = (SDnodeEps *)((char *)pStatusRsp->vgAccess + pCfg->numOfVnodes * sizeof(SVgroupAccess)); + eps->dnodeNum = htonl(eps->dnodeNum); + for (int32_t i = 0; i < eps->dnodeNum; ++i) { + eps->dnodeEps[i].dnodeId = htonl(eps->dnodeEps[i].dnodeId); + eps->dnodeEps[i].dnodePort = htons(eps->dnodeEps[i].dnodePort); + } + + dnodeUpdateDnodeEps(eps); +} + +static void *dnodeThreadRoutine(void *param) { + int32_t ms = tsStatusInterval * 1000; + while (!tsMsg.stop) { + taosMsleep(ms); + dnodeSendStatusMsg(); + } +} + +int32_t dnodeInitMsg() { + tsMsg.stop = false; + tsMsg.rebootTime = taosGetTimestampSec(); + tsMsg.threadId = taosCreateThread(dnodeThreadRoutine, NULL); + if (tsMsg.threadId == NULL) { + return -1; + } + + dInfo("dnode msg is initialized"); + return 0; +} + +void dnodeCleanupMsg() { + if (tsMsg.threadId != NULL) { + tsMsg.stop = true; + taosDestoryThread(tsMsg.threadId); + tsMsg.threadId = NULL; + } + + dInfo("dnode msg is cleanuped"); +} + +static int32_t dnodeStartMnode(SRpcMsg *pMsg) { + SCreateMnodeMsg *pCfg = pMsg->pCont; + pCfg->dnodeId = htonl(pCfg->dnodeId); + pCfg->mnodeNum = htonl(pCfg->mnodeNum); + for (int32_t i = 0; i < pCfg->mnodeNum; ++i) { + pCfg->mnodeEps[i].dnodeId = htonl(pCfg->mnodeEps[i].dnodeId); + pCfg->mnodeEps[i].dnodePort = htons(pCfg->mnodeEps[i].dnodePort); + } + + if (pCfg->dnodeId != dnodeGetDnodeId()) { + dDebug("dnode:%d, in create meps msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId()); + return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED; + } + + if (mnodeGetStatus() == MN_STATUS_READY) return 0; + + return mnodeDeploy(); +} + +void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg) { + int32_t code = dnodeStartMnode(pMsg); + + SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code}; + + rpcSendResponse(&rspMsg); + rpcFreeCont(pMsg->pCont); +} + +void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg) { + SCfgDnodeMsg *pCfg = pMsg->pCont; + + int32_t code = taosCfgDynamicOptions(pCfg->config); + + SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code}; + + rpcSendResponse(&rspMsg); + rpcFreeCont(pMsg->pCont); +} + +void dnodeProcessStartupReq(SRpcMsg *pMsg) { + dInfo("startup msg is received, cont:%s", (char *)pMsg->pCont); + + SStartupStep *pStep = rpcMallocCont(sizeof(SStartupStep)); + dnodeGetStartup(pStep); + + dDebug("startup msg is sent, step:%s desc:%s finished:%d", pStep->name, pStep->desc, pStep->finished); + + SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStep, .contLen = sizeof(SStartupStep)}; + rpcSendResponse(&rpcRsp); + rpcFreeCont(pMsg->pCont); +} diff --git a/source/dnode/mgmt/src/dnodeInt.c b/source/dnode/mgmt/src/dnodeInt.c index 1166a06d38..aa66ab3da3 100644 --- a/source/dnode/mgmt/src/dnodeInt.c +++ b/source/dnode/mgmt/src/dnodeInt.c @@ -15,9 +15,9 @@ #define _DEFAULT_SOURCE #include "dnodeCheck.h" -#include "dnodeEps.h" -#include "dnodeMsg.h" -#include "dnodeTrans.h" +#include "dnodeConfig.h" +#include "dnodeDnode.h" +#include "dnodeTransport.h" #include "mnode.h" #include "sync.h" #include "tcache.h" diff --git a/source/dnode/mgmt/src/dnodeTransport.c b/source/dnode/mgmt/src/dnodeTransport.c new file mode 100644 index 0000000000..68ec0a44e5 --- /dev/null +++ b/source/dnode/mgmt/src/dnodeTransport.c @@ -0,0 +1,382 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +/* this file is mainly responsible for the communication between DNODEs. Each + * dnode works as both server and client. Dnode may send status, grant, config + * messages to mnode, mnode may send create/alter/drop table/vnode messages + * to dnode. All theses messages are handled from here + */ + +#define _DEFAULT_SOURCE +#include "dnodeTransport.h" +#include "dnodeConfig.h" +#include "dnodeDnode.h" +#include "dnodeMnode.h" +#include "dnodeVnodes.h" +#include "mnode.h" +#include "vnode.h" + +typedef void (*MsgFp)(SRpcMsg *pMsg); + +static struct { + void *serverRpc; + void *clientRpc; + void *shellRpc; + MsgFp msgFp[TSDB_MSG_TYPE_MAX]; +} tsTrans; + +static void dnodeInitMsgFp() { + // msg from client to dnode + tsTrans.msgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_TABLE] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_TABLE_META] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_TABLES_META] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeProcessStartupReq; + + // msg from client to mnode + tsTrans.msgFp[TSDB_MSG_TYPE_CONNECT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_ACCT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_USER] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_USER] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_USER] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_DNODE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_USE_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_DB] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_TOPIC] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_TOPIC] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_TOPIC] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_FUNCTION] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_KILL_QUERY] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_KILL_CONN] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_HEARTBEAT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SHOW] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE_FUNC] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = mnodeProcessMsg; + + // message from mnode to dnode + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN] = vnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN] = dnodeProcessCreateMnodeReq; + tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN] = NULL; + tsTrans.msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN_RSP] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN] = NULL; + tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = mnodeProcessMsg; + + // message from dnode to mnode + tsTrans.msgFp[TSDB_MSG_TYPE_DM_AUTH] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_AUTH_RSP] = NULL; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_GRANT] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_GRANT_RSP] = NULL; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_STATUS] = mnodeProcessMsg; + tsTrans.msgFp[TSDB_MSG_TYPE_DM_STATUS_RSP] = dnodeProcessStatusRsp; +} + +static void dnodeProcessPeerReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { + SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0}; + int32_t msgType = pMsg->msgType; + + if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) { + dnodeProcessStartupReq(pMsg); + return; + } + + if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) { + rspMsg.code = TSDB_CODE_APP_NOT_READY; + rpcSendResponse(&rspMsg); + rpcFreeCont(pMsg->pCont); + dTrace("RPC %p, peer req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]); + return; + } + + if (pMsg->pCont == NULL) { + rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN; + rpcSendResponse(&rspMsg); + return; + } + + MsgFp fp = tsTrans.msgFp[msgType]; + if (fp != NULL) { + dTrace("RPC %p, peer req:%s will be processed", pMsg->handle, taosMsg[msgType]); + (*fp)(pMsg); + } else { + dError("RPC %p, peer req:%s not processed", pMsg->handle, taosMsg[msgType]); + rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; + rpcSendResponse(&rspMsg); + rpcFreeCont(pMsg->pCont); + } +} + +static int32_t dnodeInitServer() { + SRpcInit rpcInit; + memset(&rpcInit, 0, sizeof(rpcInit)); + rpcInit.localPort = tsDnodeDnodePort; + rpcInit.label = "DND-S"; + rpcInit.numOfThreads = 1; + rpcInit.cfp = dnodeProcessPeerReq; + rpcInit.sessions = TSDB_MAX_VNODES << 4; + rpcInit.connType = TAOS_CONN_SERVER; + rpcInit.idleTime = tsShellActivityTimer * 1000; + + tsTrans.serverRpc = rpcOpen(&rpcInit); + if (tsTrans.serverRpc == NULL) { + dError("failed to init peer rpc server"); + return -1; + } + + dInfo("dnode peer rpc server is initialized"); + return 0; +} + +static void dnodeCleanupServer() { + if (tsTrans.serverRpc) { + rpcClose(tsTrans.serverRpc); + tsTrans.serverRpc = NULL; + dInfo("dnode peer server is closed"); + } +} + +static void dnodeProcessPeerRsp(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { + int32_t msgType = pMsg->msgType; + + if (dnodeGetRunStat() == DN_RUN_STAT_STOPPED) { + if (pMsg == NULL || pMsg->pCont == NULL) return; + dTrace("RPC %p, peer rsp:%s is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType]); + rpcFreeCont(pMsg->pCont); + return; + } + + if (msgType == TSDB_MSG_TYPE_DM_STATUS_RSP && pEpSet) { + dnodeUpdateMnodeEps(pEpSet); + } + + MsgFp fp = tsTrans.msgFp[msgType]; + if (fp != NULL) { + dTrace("RPC %p, peer rsp:%s will be processed", pMsg->handle, taosMsg[msgType]); + (*fp)(pMsg); + } else { + dDebug("RPC %p, peer rsp:%s not processed", pMsg->handle, taosMsg[msgType]); + } + + rpcFreeCont(pMsg->pCont); +} + +static int32_t dnodeInitClient() { + char secret[TSDB_KEY_LEN] = "secret"; + SRpcInit rpcInit; + memset(&rpcInit, 0, sizeof(rpcInit)); + rpcInit.label = "DND-C"; + rpcInit.numOfThreads = 1; + rpcInit.cfp = dnodeProcessPeerRsp; + rpcInit.sessions = TSDB_MAX_VNODES << 4; + rpcInit.connType = TAOS_CONN_CLIENT; + rpcInit.idleTime = tsShellActivityTimer * 1000; + rpcInit.user = "t"; + rpcInit.ckey = "key"; + rpcInit.secret = secret; + + tsTrans.clientRpc = rpcOpen(&rpcInit); + if (tsTrans.clientRpc == NULL) { + dError("failed to init peer rpc client"); + return -1; + } + + dInfo("dnode peer rpc client is initialized"); + return 0; +} + +static void dnodeCleanupClient() { + if (tsTrans.clientRpc) { + rpcClose(tsTrans.clientRpc); + tsTrans.clientRpc = NULL; + dInfo("dnode peer rpc client is closed"); + } +} + +static void dnodeProcessShellReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { + SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0}; + int32_t msgType = pMsg->msgType; + + if (dnodeGetRunStat() == DN_RUN_STAT_STOPPED) { + dError("RPC %p, shell req:%s is ignored since dnode exiting", pMsg->handle, taosMsg[msgType]); + rspMsg.code = TSDB_CODE_DND_EXITING; + rpcSendResponse(&rspMsg); + rpcFreeCont(pMsg->pCont); + return; + } else if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) { + dError("RPC %p, shell req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]); + rspMsg.code = TSDB_CODE_APP_NOT_READY; + rpcSendResponse(&rspMsg); + rpcFreeCont(pMsg->pCont); + return; + } + + if (pMsg->pCont == NULL) { + rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN; + rpcSendResponse(&rspMsg); + return; + } + + MsgFp fp = tsTrans.msgFp[msgType]; + if (fp != NULL) { + dTrace("RPC %p, shell req:%s will be processed", pMsg->handle, taosMsg[msgType]); + (*fp)(pMsg); + } else { + dError("RPC %p, shell req:%s is not processed", pMsg->handle, taosMsg[msgType]); + rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; + rpcSendResponse(&rspMsg); + rpcFreeCont(pMsg->pCont); + } +} + +void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg) { rpcSendRequest(tsTrans.clientRpc, epSet, rpcMsg, NULL); } + +void dnodeSendMsgToMnode(SRpcMsg *rpcMsg) { + SRpcEpSet epSet = {0}; + dnodeGetEpSetForPeer(&epSet); + dnodeSendMsgToDnode(&epSet, rpcMsg); +} + +static void dnodeSendMsgToMnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) { + SRpcEpSet epSet = {0}; + dnodeGetEpSetForPeer(&epSet); + rpcSendRecv(tsTrans.clientRpc, &epSet, rpcMsg, rpcRsp); +} + +static int32_t dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) { + int32_t code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey); + if (code != TSDB_CODE_APP_NOT_READY) return code; + + SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg)); + tstrncpy(pMsg->user, user, sizeof(pMsg->user)); + + SRpcMsg rpcMsg = {0}; + rpcMsg.pCont = pMsg; + rpcMsg.contLen = sizeof(SAuthMsg); + rpcMsg.msgType = TSDB_MSG_TYPE_DM_AUTH; + + dDebug("user:%s, send auth msg to mnodes", user); + SRpcMsg rpcRsp = {0}; + dnodeSendMsgToMnodeRecv(&rpcMsg, &rpcRsp); + + if (rpcRsp.code != 0) { + dError("user:%s, auth msg received from mnodes, error:%s", user, tstrerror(rpcRsp.code)); + } else { + SAuthRsp *pRsp = rpcRsp.pCont; + dDebug("user:%s, auth msg received from mnodes", user); + memcpy(secret, pRsp->secret, TSDB_KEY_LEN); + memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN); + *spi = pRsp->spi; + *encrypt = pRsp->encrypt; + } + + rpcFreeCont(rpcRsp.pCont); + return rpcRsp.code; +} + +static int32_t dnodeInitShell() { + int32_t numOfThreads = (int32_t)((tsNumOfCores * tsNumOfThreadsPerCore) / 2.0); + if (numOfThreads < 1) { + numOfThreads = 1; + } + + SRpcInit rpcInit; + memset(&rpcInit, 0, sizeof(rpcInit)); + rpcInit.localPort = tsDnodeShellPort; + rpcInit.label = "SHELL"; + rpcInit.numOfThreads = numOfThreads; + rpcInit.cfp = dnodeProcessShellReq; + rpcInit.sessions = tsMaxShellConns; + rpcInit.connType = TAOS_CONN_SERVER; + rpcInit.idleTime = tsShellActivityTimer * 1000; + rpcInit.afp = dnodeRetrieveUserAuthInfo; + + tsTrans.shellRpc = rpcOpen(&rpcInit); + if (tsTrans.shellRpc == NULL) { + dError("failed to init shell rpc server"); + return -1; + } + + dInfo("dnode shell rpc server is initialized"); + return 0; +} + +static void dnodeCleanupShell() { + if (tsTrans.shellRpc) { + rpcClose(tsTrans.shellRpc); + tsTrans.shellRpc = NULL; + } +} + +int32_t dnodeInitTrans() { + if (dnodeInitClient() != 0) { + return -1; + } + + if (dnodeInitServer() != 0) { + return -1; + } + + if (dnodeInitShell() != 0) { + return -1; + } + + return 0; +} + +void dnodeCleanupTrans() { + dnodeCleanupShell(); + dnodeCleanupServer(); + dnodeCleanupClient(); +} diff --git a/source/dnode/mgmt/src/dnodeVnodes.c b/source/dnode/mgmt/src/dnodeVnodes.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/server/dnode/src/dnodeInt.c b/source/server/dnode/src/dnodeInt.c new file mode 100644 index 0000000000..aa66ab3da3 --- /dev/null +++ b/source/server/dnode/src/dnodeInt.c @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dnodeCheck.h" +#include "dnodeConfig.h" +#include "dnodeDnode.h" +#include "dnodeTransport.h" +#include "mnode.h" +#include "sync.h" +#include "tcache.h" +#include "tconfig.h" +#include "tnote.h" +#include "tstep.h" +#include "vnode.h" +#include "wal.h" + +static struct { + EDnStat runStatus; + SStartupStep startup; + SSteps *steps; +} tsDnode; + +EDnStat dnodeGetRunStat() { return tsDnode.runStatus; } + +void dnodeSetRunStat(EDnStat stat) { tsDnode.runStatus = stat; } + +void dnodeReportStartup(char *name, char *desc) { + SStartupStep *startup = &tsDnode.startup; + tstrncpy(startup->name, name, strlen(startup->name)); + tstrncpy(startup->desc, desc, strlen(startup->desc)); + startup->finished = 0; +} + +static void dnodeReportStartupFinished(char *name, char *desc) { + SStartupStep *startup = &tsDnode.startup; + tstrncpy(startup->name, name, strlen(startup->name)); + tstrncpy(startup->desc, desc, strlen(startup->desc)); + startup->finished = 1; +} + +void dnodeGetStartup(SStartupStep *pStep) { memcpy(pStep, &tsDnode.startup, sizeof(SStartupStep)); } + +static int32_t dnodeInitVnode() { + return vnodeInit(); +} + +static int32_t dnodeInitMnode() { + SMnodePara para; + para.fp.GetDnodeEp = dnodeGetEp; + para.fp.SendMsgToDnode = dnodeSendMsgToDnode; + para.fp.SendMsgToMnode = dnodeSendMsgToMnode; + para.fp.SendRedirectMsg = dnodeSendRedirectMsg; + para.dnodeId = dnodeGetDnodeId(); + para.clusterId = dnodeGetClusterId(); + + return mnodeInit(para); +} + +static int32_t dnodeInitTfs() {} + +static int32_t dnodeInitMain() { + tsDnode.runStatus = DN_RUN_STAT_STOPPED; + tscEmbedded = 1; + taosIgnSIGPIPE(); + taosBlockSIGPIPE(); + taosResolveCRC(); + taosInitGlobalCfg(); + taosReadGlobalLogCfg(); + taosSetCoreDump(tsEnableCoreFile); + + if (!taosMkDir(tsLogDir)) { + printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno)); + return -1; + } + + char temp[TSDB_FILENAME_LEN]; + sprintf(temp, "%s/taosdlog", tsLogDir); + if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) { + printf("failed to init log file\n"); + } + + if (!taosReadGlobalCfg()) { + taosPrintGlobalCfg(); + dError("TDengine read global config failed"); + return -1; + } + + dInfo("start to initialize TDengine"); + + taosInitNotes(); + + return taosCheckGlobalCfg(); +} + +static void dnodeCleanupMain() { + taos_cleanup(); + taosCloseLog(); + taosStopCacheRefreshWorker(); +} + +static int32_t dnodeCheckRunning(char *dir) { + char filepath[256] = {0}; + snprintf(filepath, sizeof(filepath), "%s/.running", dir); + + FileFd fd = taosOpenFileCreateWriteTrunc(filepath); + if (fd < 0) { + dError("failed to open lock file:%s since %s, quit", filepath, strerror(errno)); + return -1; + } + + int32_t ret = taosLockFile(fd); + if (ret != 0) { + dError("failed to lock file:%s since %s, quit", filepath, strerror(errno)); + taosCloseFile(fd); + return -1; + } + + return 0; +} + +static int32_t dnodeInitDir() { + sprintf(tsMnodeDir, "%s/mnode", tsDataDir); + sprintf(tsVnodeDir, "%s/vnode", tsDataDir); + sprintf(tsDnodeDir, "%s/dnode", tsDataDir); + + if (!taosMkDir(tsDnodeDir)) { + dError("failed to create dir:%s since %s", tsDnodeDir, strerror(errno)); + return -1; + } + + if (!taosMkDir(tsMnodeDir)) { + dError("failed to create dir:%s since %s", tsMnodeDir, strerror(errno)); + return -1; + } + + if (!taosMkDir(tsVnodeDir)) { + dError("failed to create dir:%s since %s", tsVnodeDir, strerror(errno)); + return -1; + } + + if (dnodeCheckRunning(tsDnodeDir) != 0) { + return -1; + } + + return 0; +} + +static void dnodeCleanupDir() {} + +int32_t dnodeInit() { + SSteps *steps = taosStepInit(24, dnodeReportStartup); + if (steps == NULL) return -1; + + taosStepAdd(steps, "dnode-main", dnodeInitMain, dnodeCleanupMain); + taosStepAdd(steps, "dnode-dir", dnodeInitDir, dnodeCleanupDir); + taosStepAdd(steps, "dnode-check", dnodeInitCheck, dnodeCleanupCheck); + taosStepAdd(steps, "dnode-rpc", rpcInit, rpcCleanup); + taosStepAdd(steps, "dnode-tfs", dnodeInitTfs, NULL); + taosStepAdd(steps, "dnode-wal", walInit, walCleanUp); + taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp); + taosStepAdd(steps, "dnode-eps", dnodeInitEps, dnodeCleanupEps); + taosStepAdd(steps, "dnode-vnode", dnodeInitVnode, vnodeCleanup); + taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, mnodeCleanup); + taosStepAdd(steps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans); + taosStepAdd(steps, "dnode-msg", dnodeInitMsg, dnodeCleanupMsg); + + tsDnode.steps = steps; + taosStepExec(tsDnode.steps); + + dnodeSetRunStat(DN_RUN_STAT_RUNNING); + dnodeReportStartupFinished("TDengine", "initialized successfully"); + dInfo("TDengine is initialized successfully"); + + return 0; +} + +void dnodeCleanup() { + if (dnodeGetRunStat() != DN_RUN_STAT_STOPPED) { + dnodeSetRunStat(DN_RUN_STAT_STOPPED); + taosStepCleanup(tsDnode.steps); + tsDnode.steps = NULL; + } +} + +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMgmtMsg; +// tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMgmtMsg; + \ No newline at end of file diff --git a/source/dnode/mgmt/src/dnodeMsg.c b/source/server/dnode/src/dnodeMsg.c similarity index 99% rename from source/dnode/mgmt/src/dnodeMsg.c rename to source/server/dnode/src/dnodeMsg.c index a5c3db5e14..0a598527b4 100644 --- a/source/dnode/mgmt/src/dnodeMsg.c +++ b/source/server/dnode/src/dnodeMsg.c @@ -14,8 +14,8 @@ */ #define _DEFAULT_SOURCE -#include "dnodeMsg.h" -#include "dnodeEps.h" +#include "dnodeDnode.h" +#include "dnodeConfig.h" #include "mnode.h" #include "tthread.h" #include "ttime.h" diff --git a/source/dnode/mgmt/src/dnodeTrans.c b/source/server/dnode/src/dnodeTrans.c similarity index 99% rename from source/dnode/mgmt/src/dnodeTrans.c rename to source/server/dnode/src/dnodeTrans.c index 3e32510df9..a9e130cd58 100644 --- a/source/dnode/mgmt/src/dnodeTrans.c +++ b/source/server/dnode/src/dnodeTrans.c @@ -20,9 +20,9 @@ */ #define _DEFAULT_SOURCE -#include "dnodeTrans.h" -#include "dnodeEps.h" -#include "dnodeMsg.h" +#include "dnodeTransport.h" +#include "dnodeConfig.h" +#include "dnodeDnode.h" #include "mnode.h" #include "vnode.h" From 0dddcdfbeb3d8d3bd27fafbb0c04b5e416d2eb0e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 20:21:21 +0800 Subject: [PATCH 13/17] refact files --- source/dnode/mgmt/inc/dnodeConfig.h | 5 +- source/dnode/mgmt/src/dnodeConfig.c | 228 ++++++++-------- source/dnode/mgmt/src/dnodeInt.c | 2 +- source/dnode/mgmt/src/dnodeMain.c | 6 +- source/server/dnode/src/dnodeInt.c | 204 -------------- source/server/dnode/src/dnodeMsg.c | 174 ------------ source/server/dnode/src/dnodeTrans.c | 380 --------------------------- 7 files changed, 120 insertions(+), 879 deletions(-) delete mode 100644 source/server/dnode/src/dnodeInt.c delete mode 100644 source/server/dnode/src/dnodeMsg.c delete mode 100644 source/server/dnode/src/dnodeTrans.c diff --git a/source/dnode/mgmt/inc/dnodeConfig.h b/source/dnode/mgmt/inc/dnodeConfig.h index 9d446a9f1a..71f3ac3f97 100644 --- a/source/dnode/mgmt/inc/dnodeConfig.h +++ b/source/dnode/mgmt/inc/dnodeConfig.h @@ -21,8 +21,8 @@ extern "C" { #endif #include "dnodeInt.h" -int32_t dnodeInitEps(); -void dnodeCleanupEps(); +int32_t dnodeInitConfig(); +void dnodeCleanupConfig(); void dnodeUpdateCfg(SDnodeCfg *data); void dnodeUpdateDnodeEps(SDnodeEps *data); @@ -32,7 +32,6 @@ int64_t dnodeGetClusterId(); void dnodeGetEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port); void dnodeGetEpSetForPeer(SRpcEpSet *epSet); -void dnodeGetEpSetForShell(SRpcEpSet *epSet); void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell); #ifdef __cplusplus diff --git a/source/dnode/mgmt/src/dnodeConfig.c b/source/dnode/mgmt/src/dnodeConfig.c index fc4c821bb6..d6189eb632 100644 --- a/source/dnode/mgmt/src/dnodeConfig.c +++ b/source/dnode/mgmt/src/dnodeConfig.c @@ -19,27 +19,27 @@ #include "thash.h" static struct { - int32_t dnodeId; - int32_t dropped; - int64_t clusterId; - SDnodeEps *dnodeEps; - SHashObj *dnodeHash; - SRpcEpSet mnodeEpSetForShell; - SRpcEpSet mnodeEpSetForPeer; - char file[PATH_MAX + 20]; + int32_t dnodeId; + int32_t dropped; + int64_t clusterId; + SDnodeEps *dnodeEps; + SHashObj *dnodeHash; + SRpcEpSet mnodeEpSetForShell; + SRpcEpSet mnodeEpSetForPeer; + char file[PATH_MAX + 20]; pthread_mutex_t mutex; -} tsEps; +} tsConfig; -void dnodeGetEpSetForPeer(SRpcEpSet *epSet) { - pthread_mutex_lock(&tsEps.mutex); - *epSet = tsEps.mnodeEpSetForPeer; - pthread_mutex_unlock(&tsEps.mutex); +vstaticoid dnodeGetEpSetForPeer(SRpcEpSet *epSet) { + pthread_mutex_lock(&tsConfig.mutex); + *epSet = tsConfig.mnodeEpSetForPeer; + pthread_mutex_unlock(&tsConfig.mutex); } -void dnodeGetEpSetForShell(SRpcEpSet *epSet) { - pthread_mutex_lock(&tsEps.mutex); - *epSet = tsEps.mnodeEpSetForShell; - pthread_mutex_unlock(&tsEps.mutex); +static void dnodeGetEpSetForShell(SRpcEpSet *epSet) { + pthread_mutex_lock(&tsConfig.mutex); + *epSet = tsConfig.mnodeEpSetForShell; + pthread_mutex_unlock(&tsConfig.mutex); } void dnodeUpdateMnodeEps(SRpcEpSet *ep) { @@ -48,18 +48,18 @@ void dnodeUpdateMnodeEps(SRpcEpSet *ep) { return; } - pthread_mutex_lock(&tsEps.mutex); + pthread_mutex_lock(&tsConfig.mutex); dInfo("mnode is changed, num:%d use:%d", ep->numOfEps, ep->inUse); - tsEps.mnodeEpSetForPeer = *ep; + tsConfig.mnodeEpSetForPeer = *ep; for (int32_t i = 0; i < ep->numOfEps; ++i) { ep->port[i] -= TSDB_PORT_DNODEDNODE; dInfo("mnode index:%d %s:%u", i, ep->fqdn[i], ep->port[i]); } - tsEps.mnodeEpSetForShell = *ep; + tsConfig.mnodeEpSetForShell = *ep; - pthread_mutex_unlock(&tsEps.mutex); + pthread_mutex_unlock(&tsConfig.mutex); } void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell) { @@ -92,9 +92,9 @@ void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell) { } static void dnodePrintEps() { - dDebug("print dnode list, num:%d", tsEps.dnodeEps->dnodeNum); - for (int32_t i = 0; i < tsEps.dnodeEps->dnodeNum; i++) { - SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i]; + dDebug("print dnode list, num:%d", tsConfig.dnodeEps->dnodeNum); + for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; i++) { + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort, ep->isMnode); } } @@ -104,35 +104,35 @@ static void dnodeResetEps(SDnodeEps *data) { int32_t size = sizeof(SDnodeEps) + data->dnodeNum * sizeof(SDnodeEp); - if (data->dnodeNum > tsEps.dnodeEps->dnodeNum) { + if (data->dnodeNum > tsConfig.dnodeEps->dnodeNum) { SDnodeEps *tmp = calloc(1, size); if (tmp == NULL) return; - tfree(tsEps.dnodeEps); - tsEps.dnodeEps = tmp; + tfree(tsConfig.dnodeEps); + tsConfig.dnodeEps = tmp; } - if (tsEps.dnodeEps != data) { - memcpy(tsEps.dnodeEps, data, size); + if (tsConfig.dnodeEps != data) { + memcpy(tsConfig.dnodeEps, data, size); } - tsEps.mnodeEpSetForPeer.inUse = 0; - tsEps.mnodeEpSetForShell.inUse = 0; + tsConfig.mnodeEpSetForPeer.inUse = 0; + tsConfig.mnodeEpSetForShell.inUse = 0; int32_t index = 0; - for (int32_t i = 0; i < tsEps.dnodeEps->dnodeNum; i++) { - SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i]; + for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; i++) { + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; if (!ep->isMnode) continue; if (index >= TSDB_MAX_REPLICA) continue; - strcpy(tsEps.mnodeEpSetForShell.fqdn[index], ep->dnodeFqdn); - strcpy(tsEps.mnodeEpSetForPeer.fqdn[index], ep->dnodeFqdn); - tsEps.mnodeEpSetForShell.port[index] = ep->dnodePort; - tsEps.mnodeEpSetForShell.port[index] = ep->dnodePort + tsDnodeDnodePort; + strcpy(tsConfig.mnodeEpSetForShell.fqdn[index], ep->dnodeFqdn); + strcpy(tsConfig.mnodeEpSetForPeer.fqdn[index], ep->dnodeFqdn); + tsConfig.mnodeEpSetForShell.port[index] = ep->dnodePort; + tsConfig.mnodeEpSetForShell.port[index] = ep->dnodePort + tsDnodeDnodePort; index++; } - for (int32_t i = 0; i < tsEps.dnodeEps->dnodeNum; ++i) { - SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i]; - taosHashPut(tsEps.dnodeHash, &ep->dnodeId, sizeof(int32_t), ep, sizeof(SDnodeEp)); + for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; ++i) { + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; + taosHashPut(tsConfig.dnodeHash, &ep->dnodeId, sizeof(int32_t), ep, sizeof(SDnodeEp)); } dnodePrintEps(); @@ -141,9 +141,9 @@ static void dnodeResetEps(SDnodeEps *data) { static bool dnodeIsDnodeEpChanged(int32_t dnodeId, char *epstr) { bool changed = false; - pthread_mutex_lock(&tsEps.mutex); + pthread_mutex_lock(&tsConfig.mutex); - SDnodeEp *ep = taosHashGet(tsEps.dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeEp *ep = taosHashGet(tsConfig.dnodeHash, &dnodeId, sizeof(int32_t)); if (ep != NULL) { char epSaved[TSDB_EP_LEN + 1]; snprintf(epSaved, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort); @@ -151,7 +151,7 @@ static bool dnodeIsDnodeEpChanged(int32_t dnodeId, char *epstr) { tstrncpy(epstr, epSaved, TSDB_EP_LEN); } - pthread_mutex_unlock(&tsEps.mutex); + pthread_mutex_unlock(&tsConfig.mutex); return changed; } @@ -163,101 +163,101 @@ static int32_t dnodeReadEps() { cJSON *root = NULL; FILE *fp = NULL; - fp = fopen(tsEps.file, "r"); + fp = fopen(tsConfig.file, "r"); if (!fp) { - dDebug("file %s not exist", tsEps.file); + dDebug("file %s not exist", tsConfig.file); goto PRASE_EPS_OVER; } len = (int32_t)fread(content, 1, maxLen, fp); if (len <= 0) { - dError("failed to read %s since content is null", tsEps.file); + dError("failed to read %s since content is null", tsConfig.file); goto PRASE_EPS_OVER; } content[len] = 0; root = cJSON_Parse(content); if (root == NULL) { - dError("failed to read %s since invalid json format", tsEps.file); + dError("failed to read %s since invalid json format", tsConfig.file); goto PRASE_EPS_OVER; } cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId"); if (!dnodeId || dnodeId->type != cJSON_String) { - dError("failed to read %s since dnodeId not found", tsEps.file); + dError("failed to read %s since dnodeId not found", tsConfig.file); goto PRASE_EPS_OVER; } - tsEps.dnodeId = atoi(dnodeId->valuestring); + tsConfig.dnodeId = atoi(dnodeId->valuestring); cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); if (!dropped || dropped->type != cJSON_String) { - dError("failed to read %s since dropped not found", tsEps.file); + dError("failed to read %s since dropped not found", tsConfig.file); goto PRASE_EPS_OVER; } - tsEps.dropped = atoi(dropped->valuestring); + tsConfig.dropped = atoi(dropped->valuestring); cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); if (!clusterId || clusterId->type != cJSON_String) { - dError("failed to read %s since clusterId not found", tsEps.file); + dError("failed to read %s since clusterId not found", tsConfig.file); goto PRASE_EPS_OVER; } - tsEps.clusterId = atoll(clusterId->valuestring); + tsConfig.clusterId = atoll(clusterId->valuestring); cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos"); if (!dnodeInfos || dnodeInfos->type != cJSON_Array) { - dError("failed to read %s since dnodeInfos not found", tsEps.file); + dError("failed to read %s since dnodeInfos not found", tsConfig.file); goto PRASE_EPS_OVER; } int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos); if (dnodeInfosSize <= 0) { - dError("failed to read %s since dnodeInfos size:%d invalid", tsEps.file, dnodeInfosSize); + dError("failed to read %s since dnodeInfos size:%d invalid", tsConfig.file, dnodeInfosSize); goto PRASE_EPS_OVER; } - tsEps.dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps)); - if (tsEps.dnodeEps == NULL) { + tsConfig.dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps)); + if (tsConfig.dnodeEps == NULL) { dError("failed to calloc dnodeEpList since %s", strerror(errno)); goto PRASE_EPS_OVER; } - tsEps.dnodeEps->dnodeNum = dnodeInfosSize; + tsConfig.dnodeEps->dnodeNum = dnodeInfosSize; for (int32_t i = 0; i < dnodeInfosSize; ++i) { cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i); if (dnodeInfo == NULL) break; - SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i]; + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId"); if (!dnodeId || dnodeId->type != cJSON_String) { - dError("failed to read %s, dnodeId not found", tsEps.file); + dError("failed to read %s, dnodeId not found", tsConfig.file); goto PRASE_EPS_OVER; } ep->dnodeId = atoi(dnodeId->valuestring); cJSON *isMnode = cJSON_GetObjectItem(dnodeInfo, "isMnode"); if (!isMnode || isMnode->type != cJSON_String) { - dError("failed to read %s, isMnode not found", tsEps.file); + dError("failed to read %s, isMnode not found", tsConfig.file); goto PRASE_EPS_OVER; } ep->isMnode = atoi(isMnode->valuestring); cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn"); if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) { - dError("failed to read %s, dnodeFqdn not found", tsEps.file); + dError("failed to read %s, dnodeFqdn not found", tsConfig.file); goto PRASE_EPS_OVER; } tstrncpy(ep->dnodeFqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN); cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort"); if (!dnodePort || dnodePort->type != cJSON_String) { - dError("failed to read %s, dnodePort not found", tsEps.file); + dError("failed to read %s, dnodePort not found", tsConfig.file); goto PRASE_EPS_OVER; } ep->dnodePort = atoi(dnodePort->valuestring); } - dInfo("succcessed to read file %s", tsEps.file); + dInfo("succcessed to read file %s", tsConfig.file); dnodePrintEps(); PRASE_EPS_OVER: @@ -265,21 +265,21 @@ PRASE_EPS_OVER: if (root != NULL) cJSON_Delete(root); if (fp != NULL) fclose(fp); - if (dnodeIsDnodeEpChanged(tsEps.dnodeId, tsLocalEp)) { - dError("dnode:%d, localEp %s different with dnodeEps.json and need reconfigured", tsEps.dnodeId, tsLocalEp); + if (dnodeIsDnodeEpChanged(tsConfig.dnodeId, tsLocalEp)) { + dError("dnode:%d, localEp %s different with dnodeEps.json and need reconfigured", tsConfig.dnodeId, tsLocalEp); return -1; } - dnodeResetEps(tsEps.dnodeEps); + dnodeResetEps(tsConfig.dnodeEps); terrno = 0; return 0; } static int32_t dnodeWriteEps() { - FILE *fp = fopen(tsEps.file, "w"); + FILE *fp = fopen(tsConfig.file, "w"); if (!fp) { - dError("failed to write %s since %s", tsEps.file, strerror(errno)); + dError("failed to write %s since %s", tsConfig.file, strerror(errno)); return -1; } @@ -288,17 +288,17 @@ static int32_t dnodeWriteEps() { char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", tsEps.dnodeId); - len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", tsEps.dropped); - len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", tsEps.clusterId); + len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", tsConfig.dnodeId); + len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", tsConfig.dropped); + len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", tsConfig.clusterId); len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n"); - for (int32_t i = 0; i < tsEps.dnodeEps->dnodeNum; ++i) { - SDnodeEp *ep = &tsEps.dnodeEps->dnodeEps[i]; + for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; ++i) { + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", ep->dnodeId); len += snprintf(content + len, maxLen - len, " \"isMnode\": \"%d\",\n", ep->isMnode); len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", ep->dnodeFqdn); len += snprintf(content + len, maxLen - len, " \"dnodePort\": \"%u\"\n", ep->dnodePort); - if (i < tsEps.dnodeEps->dnodeNum - 1) { + if (i < tsConfig.dnodeEps->dnodeNum - 1) { len += snprintf(content + len, maxLen - len, " },{\n"); } else { len += snprintf(content + len, maxLen - len, " }]\n"); @@ -312,20 +312,20 @@ static int32_t dnodeWriteEps() { free(content); terrno = 0; - dInfo("successed to write %s", tsEps.file); + dInfo("successed to write %s", tsConfig.file); return 0; } -int32_t dnodeInitEps() { - tsEps.dnodeId = 0; - tsEps.dropped = 0; - tsEps.clusterId = 0; - tsEps.dnodeEps = NULL; - snprintf(tsEps.file, sizeof(tsEps.file), "%s/dnodeEps.json", tsDnodeDir); - pthread_mutex_init(&tsEps.mutex, NULL); +int32_t dnodeInitConfig() { + tsConfig.dnodeId = 0; + tsConfig.dropped = 0; + tsConfig.clusterId = 0; + tsConfig.dnodeEps = NULL; + snprintf(tsConfig.file, sizeof(tsConfig.file), "%s/dnodeEps.json", tsDnodeDir); + pthread_mutex_init(&tsConfig.mutex, NULL); - tsEps.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); - if (tsEps.dnodeHash == NULL) return -1; + tsConfig.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); + if (tsConfig.dnodeHash == NULL) return -1; int32_t ret = dnodeReadEps(); if (ret == 0) { @@ -335,81 +335,81 @@ int32_t dnodeInitEps() { return ret; } -void dnodeCleanupEps() { - pthread_mutex_lock(&tsEps.mutex); +void dnodeCleanupConfig() { + pthread_mutex_lock(&tsConfig.mutex); - if (tsEps.dnodeEps != NULL) { - free(tsEps.dnodeEps); - tsEps.dnodeEps = NULL; + if (tsConfig.dnodeEps != NULL) { + free(tsConfig.dnodeEps); + tsConfig.dnodeEps = NULL; } - if (tsEps.dnodeHash) { - taosHashCleanup(tsEps.dnodeHash); - tsEps.dnodeHash = NULL; + if (tsConfig.dnodeHash) { + taosHashCleanup(tsConfig.dnodeHash); + tsConfig.dnodeHash = NULL; } - pthread_mutex_unlock(&tsEps.mutex); - pthread_mutex_destroy(&tsEps.mutex); + pthread_mutex_unlock(&tsConfig.mutex); + pthread_mutex_destroy(&tsConfig.mutex); } void dnodeUpdateDnodeEps(SDnodeEps *data) { if (data == NULL || data->dnodeNum <= 0) return; - pthread_mutex_lock(&tsEps.mutex); + pthread_mutex_lock(&tsConfig.mutex); - if (data->dnodeNum != tsEps.dnodeEps->dnodeNum) { + if (data->dnodeNum != tsConfig.dnodeEps->dnodeNum) { dnodeResetEps(data); dnodeWriteEps(); } else { int32_t size = data->dnodeNum * sizeof(SDnodeEp) + sizeof(SDnodeEps); - if (memcmp(tsEps.dnodeEps, data, size) != 0) { + if (memcmp(tsConfig.dnodeEps, data, size) != 0) { dnodeResetEps(data); dnodeWriteEps(); } } - pthread_mutex_unlock(&tsEps.mutex); + pthread_mutex_unlock(&tsConfig.mutex); } void dnodeGetEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port) { - pthread_mutex_lock(&tsEps.mutex); + pthread_mutex_lock(&tsConfig.mutex); - SDnodeEp *ep = taosHashGet(tsEps.dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeEp *ep = taosHashGet(tsConfig.dnodeHash, &dnodeId, sizeof(int32_t)); if (ep != NULL) { if (port) *port = ep->dnodePort; if (fqdn) tstrncpy(fqdn, ep->dnodeFqdn, TSDB_FQDN_LEN); if (epstr) snprintf(epstr, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort); } - pthread_mutex_unlock(&tsEps.mutex); + pthread_mutex_unlock(&tsConfig.mutex); } void dnodeUpdateCfg(SDnodeCfg *data) { - if (tsEps.dnodeId != 0 && !data->dropped) return; + if (tsConfig.dnodeId != 0 && !data->dropped) return; - pthread_mutex_lock(&tsEps.mutex); + pthread_mutex_lock(&tsConfig.mutex); - tsEps.dnodeId = data->dnodeId; - tsEps.clusterId = data->clusterId; - tsEps.dropped = data->dropped; + tsConfig.dnodeId = data->dnodeId; + tsConfig.clusterId = data->clusterId; + tsConfig.dropped = data->dropped; dInfo("dnodeId is set to %d, clusterId is set to %" PRId64, data->dnodeId, data->clusterId); dnodeWriteEps(); - pthread_mutex_unlock(&tsEps.mutex); + pthread_mutex_unlock(&tsConfig.mutex); } int32_t dnodeGetDnodeId() { int32_t dnodeId = 0; - pthread_mutex_lock(&tsEps.mutex); - dnodeId = tsEps.dnodeId; - pthread_mutex_unlock(&tsEps.mutex); + pthread_mutex_lock(&tsConfig.mutex); + dnodeId = tsConfig.dnodeId; + pthread_mutex_unlock(&tsConfig.mutex); return dnodeId; } int64_t dnodeGetClusterId() { int64_t clusterId = 0; - pthread_mutex_lock(&tsEps.mutex); - clusterId = tsEps.clusterId; - pthread_mutex_unlock(&tsEps.mutex); + pthread_mutex_lock(&tsConfig.mutex); + clusterId = tsConfig.clusterId; + pthread_mutex_unlock(&tsConfig.mutex); return clusterId; } diff --git a/source/dnode/mgmt/src/dnodeInt.c b/source/dnode/mgmt/src/dnodeInt.c index aa66ab3da3..de1d03ae7a 100644 --- a/source/dnode/mgmt/src/dnodeInt.c +++ b/source/dnode/mgmt/src/dnodeInt.c @@ -171,7 +171,7 @@ int32_t dnodeInit() { taosStepAdd(steps, "dnode-tfs", dnodeInitTfs, NULL); taosStepAdd(steps, "dnode-wal", walInit, walCleanUp); taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp); - taosStepAdd(steps, "dnode-eps", dnodeInitEps, dnodeCleanupEps); + taosStepAdd(steps, "dnode-eps", dnodeInitConfig, dnodeCleanupConfig); taosStepAdd(steps, "dnode-vnode", dnodeInitVnode, vnodeCleanup); taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, mnodeCleanup); taosStepAdd(steps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans); diff --git a/source/dnode/mgmt/src/dnodeMain.c b/source/dnode/mgmt/src/dnodeMain.c index c41acc6853..69960173f4 100644 --- a/source/dnode/mgmt/src/dnodeMain.c +++ b/source/dnode/mgmt/src/dnodeMain.c @@ -31,17 +31,17 @@ int main(int argc, char const *argv[]) { int32_t code = dnodeInit(); if (code != 0) { - uInfo("Failed to start TDengine, please check the log at:%s", tsLogDir); + dInfo("Failed to start TDengine, please check the log at:%s", tsLogDir); exit(EXIT_FAILURE); } - uInfo("Started TDengine service successfully."); + dInfo("Started TDengine service successfully."); while (!stop) { taosMsleep(100); } - uInfo("TDengine is shut down!"); + dInfo("TDengine is shut down!"); dnodeCleanup(); return 0; diff --git a/source/server/dnode/src/dnodeInt.c b/source/server/dnode/src/dnodeInt.c deleted file mode 100644 index aa66ab3da3..0000000000 --- a/source/server/dnode/src/dnodeInt.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dnodeCheck.h" -#include "dnodeConfig.h" -#include "dnodeDnode.h" -#include "dnodeTransport.h" -#include "mnode.h" -#include "sync.h" -#include "tcache.h" -#include "tconfig.h" -#include "tnote.h" -#include "tstep.h" -#include "vnode.h" -#include "wal.h" - -static struct { - EDnStat runStatus; - SStartupStep startup; - SSteps *steps; -} tsDnode; - -EDnStat dnodeGetRunStat() { return tsDnode.runStatus; } - -void dnodeSetRunStat(EDnStat stat) { tsDnode.runStatus = stat; } - -void dnodeReportStartup(char *name, char *desc) { - SStartupStep *startup = &tsDnode.startup; - tstrncpy(startup->name, name, strlen(startup->name)); - tstrncpy(startup->desc, desc, strlen(startup->desc)); - startup->finished = 0; -} - -static void dnodeReportStartupFinished(char *name, char *desc) { - SStartupStep *startup = &tsDnode.startup; - tstrncpy(startup->name, name, strlen(startup->name)); - tstrncpy(startup->desc, desc, strlen(startup->desc)); - startup->finished = 1; -} - -void dnodeGetStartup(SStartupStep *pStep) { memcpy(pStep, &tsDnode.startup, sizeof(SStartupStep)); } - -static int32_t dnodeInitVnode() { - return vnodeInit(); -} - -static int32_t dnodeInitMnode() { - SMnodePara para; - para.fp.GetDnodeEp = dnodeGetEp; - para.fp.SendMsgToDnode = dnodeSendMsgToDnode; - para.fp.SendMsgToMnode = dnodeSendMsgToMnode; - para.fp.SendRedirectMsg = dnodeSendRedirectMsg; - para.dnodeId = dnodeGetDnodeId(); - para.clusterId = dnodeGetClusterId(); - - return mnodeInit(para); -} - -static int32_t dnodeInitTfs() {} - -static int32_t dnodeInitMain() { - tsDnode.runStatus = DN_RUN_STAT_STOPPED; - tscEmbedded = 1; - taosIgnSIGPIPE(); - taosBlockSIGPIPE(); - taosResolveCRC(); - taosInitGlobalCfg(); - taosReadGlobalLogCfg(); - taosSetCoreDump(tsEnableCoreFile); - - if (!taosMkDir(tsLogDir)) { - printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno)); - return -1; - } - - char temp[TSDB_FILENAME_LEN]; - sprintf(temp, "%s/taosdlog", tsLogDir); - if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) { - printf("failed to init log file\n"); - } - - if (!taosReadGlobalCfg()) { - taosPrintGlobalCfg(); - dError("TDengine read global config failed"); - return -1; - } - - dInfo("start to initialize TDengine"); - - taosInitNotes(); - - return taosCheckGlobalCfg(); -} - -static void dnodeCleanupMain() { - taos_cleanup(); - taosCloseLog(); - taosStopCacheRefreshWorker(); -} - -static int32_t dnodeCheckRunning(char *dir) { - char filepath[256] = {0}; - snprintf(filepath, sizeof(filepath), "%s/.running", dir); - - FileFd fd = taosOpenFileCreateWriteTrunc(filepath); - if (fd < 0) { - dError("failed to open lock file:%s since %s, quit", filepath, strerror(errno)); - return -1; - } - - int32_t ret = taosLockFile(fd); - if (ret != 0) { - dError("failed to lock file:%s since %s, quit", filepath, strerror(errno)); - taosCloseFile(fd); - return -1; - } - - return 0; -} - -static int32_t dnodeInitDir() { - sprintf(tsMnodeDir, "%s/mnode", tsDataDir); - sprintf(tsVnodeDir, "%s/vnode", tsDataDir); - sprintf(tsDnodeDir, "%s/dnode", tsDataDir); - - if (!taosMkDir(tsDnodeDir)) { - dError("failed to create dir:%s since %s", tsDnodeDir, strerror(errno)); - return -1; - } - - if (!taosMkDir(tsMnodeDir)) { - dError("failed to create dir:%s since %s", tsMnodeDir, strerror(errno)); - return -1; - } - - if (!taosMkDir(tsVnodeDir)) { - dError("failed to create dir:%s since %s", tsVnodeDir, strerror(errno)); - return -1; - } - - if (dnodeCheckRunning(tsDnodeDir) != 0) { - return -1; - } - - return 0; -} - -static void dnodeCleanupDir() {} - -int32_t dnodeInit() { - SSteps *steps = taosStepInit(24, dnodeReportStartup); - if (steps == NULL) return -1; - - taosStepAdd(steps, "dnode-main", dnodeInitMain, dnodeCleanupMain); - taosStepAdd(steps, "dnode-dir", dnodeInitDir, dnodeCleanupDir); - taosStepAdd(steps, "dnode-check", dnodeInitCheck, dnodeCleanupCheck); - taosStepAdd(steps, "dnode-rpc", rpcInit, rpcCleanup); - taosStepAdd(steps, "dnode-tfs", dnodeInitTfs, NULL); - taosStepAdd(steps, "dnode-wal", walInit, walCleanUp); - taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp); - taosStepAdd(steps, "dnode-eps", dnodeInitEps, dnodeCleanupEps); - taosStepAdd(steps, "dnode-vnode", dnodeInitVnode, vnodeCleanup); - taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, mnodeCleanup); - taosStepAdd(steps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans); - taosStepAdd(steps, "dnode-msg", dnodeInitMsg, dnodeCleanupMsg); - - tsDnode.steps = steps; - taosStepExec(tsDnode.steps); - - dnodeSetRunStat(DN_RUN_STAT_RUNNING); - dnodeReportStartupFinished("TDengine", "initialized successfully"); - dInfo("TDengine is initialized successfully"); - - return 0; -} - -void dnodeCleanup() { - if (dnodeGetRunStat() != DN_RUN_STAT_STOPPED) { - dnodeSetRunStat(DN_RUN_STAT_STOPPED); - taosStepCleanup(tsDnode.steps); - tsDnode.steps = NULL; - } -} - -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMgmtMsg; - \ No newline at end of file diff --git a/source/server/dnode/src/dnodeMsg.c b/source/server/dnode/src/dnodeMsg.c deleted file mode 100644 index 0a598527b4..0000000000 --- a/source/server/dnode/src/dnodeMsg.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dnodeDnode.h" -#include "dnodeConfig.h" -#include "mnode.h" -#include "tthread.h" -#include "ttime.h" -#include "vnode.h" - -static struct { - pthread_t *threadId; - bool stop; - uint32_t rebootTime; -} tsMsg; - -static void dnodeSendStatusMsg() { - int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); - SStatusMsg *pStatus = rpcMallocCont(contLen); - if (pStatus == NULL) { - dError("failed to malloc status message"); - return; - } - - pStatus->version = htonl(tsVersion); - pStatus->dnodeId = htonl(dnodeGetDnodeId()); - tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN); - pStatus->clusterId = htobe64(dnodeGetClusterId()); - pStatus->lastReboot = htonl(tsMsg.rebootTime); - pStatus->numOfCores = htonl(tsNumOfCores); - pStatus->diskAvailable = tsAvailDataDirGB; - - // fill cluster cfg parameters - pStatus->clusterCfg.statusInterval = htonl(tsStatusInterval); - pStatus->clusterCfg.checkTime = 0; - tstrncpy(pStatus->clusterCfg.timezone, tsTimezone, 64); - char timestr[32] = "1970-01-01 00:00:00.00"; - (void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); - tstrncpy(pStatus->clusterCfg.locale, tsLocale, TSDB_LOCALE_LEN); - tstrncpy(pStatus->clusterCfg.charset, tsCharset, TSDB_LOCALE_LEN); - - // vnodeGetStatus(NULL, pStatus); - // contLen = sizeof(SStatusMsg) + pStatus->openVnodes * sizeof(SVnodeLoad); - // pStatus->openVnodes = htons(pStatus->openVnodes); - - SRpcMsg rpcMsg = {.ahandle = NULL, .pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_DM_STATUS}; - - dnodeSendMsgToMnode(&rpcMsg); -} - -void dnodeProcessStatusRsp(SRpcMsg *pMsg) { - dTrace("status rsp is received, code:%s", tstrerror(pMsg->code)); - if (pMsg->code != TSDB_CODE_SUCCESS) return; - - SStatusRsp *pStatusRsp = pMsg->pCont; - - SDnodeCfg *pCfg = &pStatusRsp->dnodeCfg; - pCfg->dnodeId = htonl(pCfg->dnodeId); - pCfg->clusterId = htobe64(pCfg->clusterId); - pCfg->numOfVnodes = htonl(pCfg->numOfVnodes); - pCfg->numOfDnodes = htonl(pCfg->numOfDnodes); - dnodeUpdateCfg(pCfg); - - if (pCfg->dropped) { - dError("status rsp is received, and set dnode to drop status"); - return; - } - - // vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes); - - SDnodeEps *eps = (SDnodeEps *)((char *)pStatusRsp->vgAccess + pCfg->numOfVnodes * sizeof(SVgroupAccess)); - eps->dnodeNum = htonl(eps->dnodeNum); - for (int32_t i = 0; i < eps->dnodeNum; ++i) { - eps->dnodeEps[i].dnodeId = htonl(eps->dnodeEps[i].dnodeId); - eps->dnodeEps[i].dnodePort = htons(eps->dnodeEps[i].dnodePort); - } - - dnodeUpdateDnodeEps(eps); -} - -static void *dnodeThreadRoutine(void *param) { - int32_t ms = tsStatusInterval * 1000; - while (!tsMsg.stop) { - taosMsleep(ms); - dnodeSendStatusMsg(); - } -} - -int32_t dnodeInitMsg() { - tsMsg.stop = false; - tsMsg.rebootTime = taosGetTimestampSec(); - tsMsg.threadId = taosCreateThread(dnodeThreadRoutine, NULL); - if (tsMsg.threadId == NULL) { - return -1; - } - - dInfo("dnode msg is initialized"); - return 0; -} - -void dnodeCleanupMsg() { - if (tsMsg.threadId != NULL) { - tsMsg.stop = true; - taosDestoryThread(tsMsg.threadId); - tsMsg.threadId = NULL; - } - - dInfo("dnode msg is cleanuped"); -} - -static int32_t dnodeStartMnode(SRpcMsg *pMsg) { - SCreateMnodeMsg *pCfg = pMsg->pCont; - pCfg->dnodeId = htonl(pCfg->dnodeId); - pCfg->mnodeNum = htonl(pCfg->mnodeNum); - for (int32_t i = 0; i < pCfg->mnodeNum; ++i) { - pCfg->mnodeEps[i].dnodeId = htonl(pCfg->mnodeEps[i].dnodeId); - pCfg->mnodeEps[i].dnodePort = htons(pCfg->mnodeEps[i].dnodePort); - } - - if (pCfg->dnodeId != dnodeGetDnodeId()) { - dDebug("dnode:%d, in create meps msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId()); - return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED; - } - - if (mnodeGetStatus() == MN_STATUS_READY) return 0; - - return mnodeDeploy(); -} - -void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg) { - int32_t code = dnodeStartMnode(pMsg); - - SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code}; - - rpcSendResponse(&rspMsg); - rpcFreeCont(pMsg->pCont); -} - -void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg) { - SCfgDnodeMsg *pCfg = pMsg->pCont; - - int32_t code = taosCfgDynamicOptions(pCfg->config); - - SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code}; - - rpcSendResponse(&rspMsg); - rpcFreeCont(pMsg->pCont); -} - -void dnodeProcessStartupReq(SRpcMsg *pMsg) { - dInfo("startup msg is received, cont:%s", (char *)pMsg->pCont); - - SStartupStep *pStep = rpcMallocCont(sizeof(SStartupStep)); - dnodeGetStartup(pStep); - - dDebug("startup msg is sent, step:%s desc:%s finished:%d", pStep->name, pStep->desc, pStep->finished); - - SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStep, .contLen = sizeof(SStartupStep)}; - rpcSendResponse(&rpcRsp); - rpcFreeCont(pMsg->pCont); -} diff --git a/source/server/dnode/src/dnodeTrans.c b/source/server/dnode/src/dnodeTrans.c deleted file mode 100644 index a9e130cd58..0000000000 --- a/source/server/dnode/src/dnodeTrans.c +++ /dev/null @@ -1,380 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -/* this file is mainly responsible for the communication between DNODEs. Each - * dnode works as both server and client. Dnode may send status, grant, config - * messages to mnode, mnode may send create/alter/drop table/vnode messages - * to dnode. All theses messages are handled from here - */ - -#define _DEFAULT_SOURCE -#include "dnodeTransport.h" -#include "dnodeConfig.h" -#include "dnodeDnode.h" -#include "mnode.h" -#include "vnode.h" - -typedef void (*MsgFp)(SRpcMsg *pMsg); - -static struct { - void *serverRpc; - void *clientRpc; - void *shellRpc; - MsgFp msgFp[TSDB_MSG_TYPE_MAX]; -} tsTrans; - -static void dnodeInitMsgFp() { - // msg from client to dnode - tsTrans.msgFp[TSDB_MSG_TYPE_SUBMIT] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_QUERY] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_FETCH] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_TABLE] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_TABLE] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_TABLE_META] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_TABLES_META] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_MQ_QUERY] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_MQ_ACK] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_MQ_RESET] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dnodeProcessStartupReq; - - // msg from client to mnode - tsTrans.msgFp[TSDB_MSG_TYPE_CONNECT] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_ACCT] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_ACCT] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_ACCT] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_USER] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_USER] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_USER] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_DNODE] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_DNODE] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_DB] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_DB] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_USE_DB] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_DB] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_DB] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_TOPIC] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_TOPIC] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_TOPIC] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_FUNCTION] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_KILL_QUERY] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_KILL_CONN] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_HEARTBEAT] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_SHOW] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_SHOW_RETRIEVE_FUNC] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE] = mnodeProcessMsg; - - // message from mnode to dnode - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_ALTER_VNODE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_VNODE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_SYNC_VNODE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN] = vnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_COMPACT_VNODE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN] = dnodeProcessCreateMnodeReq; - tsTrans.msgFp[TSDB_MSG_TYPE_CREATE_MNODE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN] = NULL; - tsTrans.msgFp[TSDB_MSG_TYPE_DROP_MNODE_IN_RSP] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN] = NULL; - tsTrans.msgFp[TSDB_MSG_TYPE_CONFIG_DNODE_IN_RSP] = mnodeProcessMsg; - - // message from dnode to mnode - tsTrans.msgFp[TSDB_MSG_TYPE_DM_AUTH] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DM_AUTH_RSP] = NULL; - tsTrans.msgFp[TSDB_MSG_TYPE_DM_GRANT] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DM_GRANT_RSP] = NULL; - tsTrans.msgFp[TSDB_MSG_TYPE_DM_STATUS] = mnodeProcessMsg; - tsTrans.msgFp[TSDB_MSG_TYPE_DM_STATUS_RSP] = dnodeProcessStatusRsp; -} - -static void dnodeProcessPeerReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { - SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0}; - int32_t msgType = pMsg->msgType; - - if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) { - dnodeProcessStartupReq(pMsg); - return; - } - - if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) { - rspMsg.code = TSDB_CODE_APP_NOT_READY; - rpcSendResponse(&rspMsg); - rpcFreeCont(pMsg->pCont); - dTrace("RPC %p, peer req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]); - return; - } - - if (pMsg->pCont == NULL) { - rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN; - rpcSendResponse(&rspMsg); - return; - } - - MsgFp fp = tsTrans.msgFp[msgType]; - if (fp != NULL) { - dTrace("RPC %p, peer req:%s will be processed", pMsg->handle, taosMsg[msgType]); - (*fp)(pMsg); - } else { - dError("RPC %p, peer req:%s not processed", pMsg->handle, taosMsg[msgType]); - rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; - rpcSendResponse(&rspMsg); - rpcFreeCont(pMsg->pCont); - } -} - -static int32_t dnodeInitServer() { - SRpcInit rpcInit; - memset(&rpcInit, 0, sizeof(rpcInit)); - rpcInit.localPort = tsDnodeDnodePort; - rpcInit.label = "DND-S"; - rpcInit.numOfThreads = 1; - rpcInit.cfp = dnodeProcessPeerReq; - rpcInit.sessions = TSDB_MAX_VNODES << 4; - rpcInit.connType = TAOS_CONN_SERVER; - rpcInit.idleTime = tsShellActivityTimer * 1000; - - tsTrans.serverRpc = rpcOpen(&rpcInit); - if (tsTrans.serverRpc == NULL) { - dError("failed to init peer rpc server"); - return -1; - } - - dInfo("dnode peer rpc server is initialized"); - return 0; -} - -static void dnodeCleanupServer() { - if (tsTrans.serverRpc) { - rpcClose(tsTrans.serverRpc); - tsTrans.serverRpc = NULL; - dInfo("dnode peer server is closed"); - } -} - -static void dnodeProcessPeerRsp(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { - int32_t msgType = pMsg->msgType; - - if (dnodeGetRunStat() == DN_RUN_STAT_STOPPED) { - if (pMsg == NULL || pMsg->pCont == NULL) return; - dTrace("RPC %p, peer rsp:%s is ignored since dnode is stopping", pMsg->handle, taosMsg[msgType]); - rpcFreeCont(pMsg->pCont); - return; - } - - if (msgType == TSDB_MSG_TYPE_DM_STATUS_RSP && pEpSet) { - dnodeUpdateMnodeEps(pEpSet); - } - - MsgFp fp = tsTrans.msgFp[msgType]; - if (fp != NULL) { - dTrace("RPC %p, peer rsp:%s will be processed", pMsg->handle, taosMsg[msgType]); - (*fp)(pMsg); - } else { - dDebug("RPC %p, peer rsp:%s not processed", pMsg->handle, taosMsg[msgType]); - } - - rpcFreeCont(pMsg->pCont); -} - -static int32_t dnodeInitClient() { - char secret[TSDB_KEY_LEN] = "secret"; - SRpcInit rpcInit; - memset(&rpcInit, 0, sizeof(rpcInit)); - rpcInit.label = "DND-C"; - rpcInit.numOfThreads = 1; - rpcInit.cfp = dnodeProcessPeerRsp; - rpcInit.sessions = TSDB_MAX_VNODES << 4; - rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.idleTime = tsShellActivityTimer * 1000; - rpcInit.user = "t"; - rpcInit.ckey = "key"; - rpcInit.secret = secret; - - tsTrans.clientRpc = rpcOpen(&rpcInit); - if (tsTrans.clientRpc == NULL) { - dError("failed to init peer rpc client"); - return -1; - } - - dInfo("dnode peer rpc client is initialized"); - return 0; -} - -static void dnodeCleanupClient() { - if (tsTrans.clientRpc) { - rpcClose(tsTrans.clientRpc); - tsTrans.clientRpc = NULL; - dInfo("dnode peer rpc client is closed"); - } -} - -static void dnodeProcessShellReq(SRpcMsg *pMsg, SRpcEpSet *pEpSet) { - SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0}; - int32_t msgType = pMsg->msgType; - - if (dnodeGetRunStat() == DN_RUN_STAT_STOPPED) { - dError("RPC %p, shell req:%s is ignored since dnode exiting", pMsg->handle, taosMsg[msgType]); - rspMsg.code = TSDB_CODE_DND_EXITING; - rpcSendResponse(&rspMsg); - rpcFreeCont(pMsg->pCont); - return; - } else if (dnodeGetRunStat() != DN_RUN_STAT_RUNNING) { - dError("RPC %p, shell req:%s is ignored since dnode not running", pMsg->handle, taosMsg[msgType]); - rspMsg.code = TSDB_CODE_APP_NOT_READY; - rpcSendResponse(&rspMsg); - rpcFreeCont(pMsg->pCont); - return; - } - - if (pMsg->pCont == NULL) { - rspMsg.code = TSDB_CODE_DND_INVALID_MSG_LEN; - rpcSendResponse(&rspMsg); - return; - } - - MsgFp fp = tsTrans.msgFp[msgType]; - if (fp != NULL) { - dTrace("RPC %p, shell req:%s will be processed", pMsg->handle, taosMsg[msgType]); - (*fp)(pMsg); - } else { - dError("RPC %p, shell req:%s is not processed", pMsg->handle, taosMsg[msgType]); - rspMsg.code = TSDB_CODE_DND_MSG_NOT_PROCESSED; - rpcSendResponse(&rspMsg); - rpcFreeCont(pMsg->pCont); - } -} - -void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg) { rpcSendRequest(tsTrans.clientRpc, epSet, rpcMsg, NULL); } - -void dnodeSendMsgToMnode(SRpcMsg *rpcMsg) { - SRpcEpSet epSet = {0}; - dnodeGetEpSetForPeer(&epSet); - dnodeSendMsgToDnode(&epSet, rpcMsg); -} - -static void dnodeSendMsgToMnodeRecv(SRpcMsg *rpcMsg, SRpcMsg *rpcRsp) { - SRpcEpSet epSet = {0}; - dnodeGetEpSetForPeer(&epSet); - rpcSendRecv(tsTrans.clientRpc, &epSet, rpcMsg, rpcRsp); -} - -static int32_t dnodeRetrieveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) { - int32_t code = mnodeRetriveAuth(user, spi, encrypt, secret, ckey); - if (code != TSDB_CODE_APP_NOT_READY) return code; - - SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg)); - tstrncpy(pMsg->user, user, sizeof(pMsg->user)); - - SRpcMsg rpcMsg = {0}; - rpcMsg.pCont = pMsg; - rpcMsg.contLen = sizeof(SAuthMsg); - rpcMsg.msgType = TSDB_MSG_TYPE_DM_AUTH; - - dDebug("user:%s, send auth msg to mnodes", user); - SRpcMsg rpcRsp = {0}; - dnodeSendMsgToMnodeRecv(&rpcMsg, &rpcRsp); - - if (rpcRsp.code != 0) { - dError("user:%s, auth msg received from mnodes, error:%s", user, tstrerror(rpcRsp.code)); - } else { - SAuthRsp *pRsp = rpcRsp.pCont; - dDebug("user:%s, auth msg received from mnodes", user); - memcpy(secret, pRsp->secret, TSDB_KEY_LEN); - memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN); - *spi = pRsp->spi; - *encrypt = pRsp->encrypt; - } - - rpcFreeCont(rpcRsp.pCont); - return rpcRsp.code; -} - -static int32_t dnodeInitShell() { - int32_t numOfThreads = (int32_t)((tsNumOfCores * tsNumOfThreadsPerCore) / 2.0); - if (numOfThreads < 1) { - numOfThreads = 1; - } - - SRpcInit rpcInit; - memset(&rpcInit, 0, sizeof(rpcInit)); - rpcInit.localPort = tsDnodeShellPort; - rpcInit.label = "SHELL"; - rpcInit.numOfThreads = numOfThreads; - rpcInit.cfp = dnodeProcessShellReq; - rpcInit.sessions = tsMaxShellConns; - rpcInit.connType = TAOS_CONN_SERVER; - rpcInit.idleTime = tsShellActivityTimer * 1000; - rpcInit.afp = dnodeRetrieveUserAuthInfo; - - tsTrans.shellRpc = rpcOpen(&rpcInit); - if (tsTrans.shellRpc == NULL) { - dError("failed to init shell rpc server"); - return -1; - } - - dInfo("dnode shell rpc server is initialized"); - return 0; -} - -static void dnodeCleanupShell() { - if (tsTrans.shellRpc) { - rpcClose(tsTrans.shellRpc); - tsTrans.shellRpc = NULL; - } -} - -int32_t dnodeInitTrans() { - if (dnodeInitClient() != 0) { - return -1; - } - - if (dnodeInitServer() != 0) { - return -1; - } - - if (dnodeInitShell() != 0) { - return -1; - } - - return 0; -} - -void dnodeCleanupTrans() { - dnodeCleanupShell(); - dnodeCleanupServer(); - dnodeCleanupClient(); -} From 89a19fdbe19a9e4d11e938a6707e69a1d95248e4 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 20:22:16 +0800 Subject: [PATCH 14/17] fix compile errors --- source/dnode/mgmt/inc/dnodeDnode.h | 4 ++-- source/dnode/mgmt/inc/dnodeVnodes.h | 4 ++-- source/dnode/mgmt/src/dnodeConfig.c | 2 +- source/dnode/mgmt/src/dnodeDnode.c | 26 +++++++++++++------------- source/dnode/mgmt/src/dnodeInt.c | 24 ++++++++++++------------ 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/source/dnode/mgmt/inc/dnodeDnode.h b/source/dnode/mgmt/inc/dnodeDnode.h index 35f68f0306..b126b39d1c 100644 --- a/source/dnode/mgmt/inc/dnodeDnode.h +++ b/source/dnode/mgmt/inc/dnodeDnode.h @@ -21,8 +21,8 @@ extern "C" { #endif #include "dnodeInt.h" -int32_t dnodeInitMsg(); -void dnodeCleanupMsg(); +int32_t dnodeInitDnode(); +void dnodeCleanupDnode(); void dnodeProcessStatusRsp(SRpcMsg *pMsg); void dnodeProcessStartupReq(SRpcMsg *pMsg); void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/inc/dnodeVnodes.h b/source/dnode/mgmt/inc/dnodeVnodes.h index d54fda654a..33848042bd 100644 --- a/source/dnode/mgmt/inc/dnodeVnodes.h +++ b/source/dnode/mgmt/inc/dnodeVnodes.h @@ -21,8 +21,8 @@ extern "C" { #endif #include "dnodeInt.h" -int32_t dnodeInitMsg(); -void dnodeCleanupMsg(); +int32_t dnodeInitDnode(); +void dnodeCleanupDnode(); void dnodeProcessStatusRsp(SRpcMsg *pMsg); void dnodeProcessStartupReq(SRpcMsg *pMsg); void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/src/dnodeConfig.c b/source/dnode/mgmt/src/dnodeConfig.c index d6189eb632..2a0374ffaf 100644 --- a/source/dnode/mgmt/src/dnodeConfig.c +++ b/source/dnode/mgmt/src/dnodeConfig.c @@ -30,7 +30,7 @@ static struct { pthread_mutex_t mutex; } tsConfig; -vstaticoid dnodeGetEpSetForPeer(SRpcEpSet *epSet) { +void dnodeGetEpSetForPeer(SRpcEpSet *epSet) { pthread_mutex_lock(&tsConfig.mutex); *epSet = tsConfig.mnodeEpSetForPeer; pthread_mutex_unlock(&tsConfig.mutex); diff --git a/source/dnode/mgmt/src/dnodeDnode.c b/source/dnode/mgmt/src/dnodeDnode.c index 0a598527b4..3c6a743e05 100644 --- a/source/dnode/mgmt/src/dnodeDnode.c +++ b/source/dnode/mgmt/src/dnodeDnode.c @@ -25,7 +25,7 @@ static struct { pthread_t *threadId; bool stop; uint32_t rebootTime; -} tsMsg; +} tsDnode; static void dnodeSendStatusMsg() { int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); @@ -39,7 +39,7 @@ static void dnodeSendStatusMsg() { pStatus->dnodeId = htonl(dnodeGetDnodeId()); tstrncpy(pStatus->dnodeEp, tsLocalEp, TSDB_EP_LEN); pStatus->clusterId = htobe64(dnodeGetClusterId()); - pStatus->lastReboot = htonl(tsMsg.rebootTime); + pStatus->lastReboot = htonl(tsDnode.rebootTime); pStatus->numOfCores = htonl(tsNumOfCores); pStatus->diskAvailable = tsAvailDataDirGB; @@ -93,17 +93,17 @@ void dnodeProcessStatusRsp(SRpcMsg *pMsg) { static void *dnodeThreadRoutine(void *param) { int32_t ms = tsStatusInterval * 1000; - while (!tsMsg.stop) { + while (!tsDnode.stop) { taosMsleep(ms); dnodeSendStatusMsg(); } } -int32_t dnodeInitMsg() { - tsMsg.stop = false; - tsMsg.rebootTime = taosGetTimestampSec(); - tsMsg.threadId = taosCreateThread(dnodeThreadRoutine, NULL); - if (tsMsg.threadId == NULL) { +int32_t dnodeInitDnode() { + tsDnode.stop = false; + tsDnode.rebootTime = taosGetTimestampSec(); + tsDnode.threadId = taosCreateThread(dnodeThreadRoutine, NULL); + if (tsDnode.threadId == NULL) { return -1; } @@ -111,11 +111,11 @@ int32_t dnodeInitMsg() { return 0; } -void dnodeCleanupMsg() { - if (tsMsg.threadId != NULL) { - tsMsg.stop = true; - taosDestoryThread(tsMsg.threadId); - tsMsg.threadId = NULL; +void dnodeCleanupDnode() { + if (tsDnode.threadId != NULL) { + tsDnode.stop = true; + taosDestoryThread(tsDnode.threadId); + tsDnode.threadId = NULL; } dInfo("dnode msg is cleanuped"); diff --git a/source/dnode/mgmt/src/dnodeInt.c b/source/dnode/mgmt/src/dnodeInt.c index de1d03ae7a..6368fe95f7 100644 --- a/source/dnode/mgmt/src/dnodeInt.c +++ b/source/dnode/mgmt/src/dnodeInt.c @@ -31,27 +31,27 @@ static struct { EDnStat runStatus; SStartupStep startup; SSteps *steps; -} tsDnode; +} tsInt; -EDnStat dnodeGetRunStat() { return tsDnode.runStatus; } +EDnStat dnodeGetRunStat() { return tsInt.runStatus; } -void dnodeSetRunStat(EDnStat stat) { tsDnode.runStatus = stat; } +void dnodeSetRunStat(EDnStat stat) { tsInt.runStatus = stat; } void dnodeReportStartup(char *name, char *desc) { - SStartupStep *startup = &tsDnode.startup; + SStartupStep *startup = &tsInt.startup; tstrncpy(startup->name, name, strlen(startup->name)); tstrncpy(startup->desc, desc, strlen(startup->desc)); startup->finished = 0; } static void dnodeReportStartupFinished(char *name, char *desc) { - SStartupStep *startup = &tsDnode.startup; + SStartupStep *startup = &tsInt.startup; tstrncpy(startup->name, name, strlen(startup->name)); tstrncpy(startup->desc, desc, strlen(startup->desc)); startup->finished = 1; } -void dnodeGetStartup(SStartupStep *pStep) { memcpy(pStep, &tsDnode.startup, sizeof(SStartupStep)); } +void dnodeGetStartup(SStartupStep *pStep) { memcpy(pStep, &tsInt.startup, sizeof(SStartupStep)); } static int32_t dnodeInitVnode() { return vnodeInit(); @@ -72,7 +72,7 @@ static int32_t dnodeInitMnode() { static int32_t dnodeInitTfs() {} static int32_t dnodeInitMain() { - tsDnode.runStatus = DN_RUN_STAT_STOPPED; + tsInt.runStatus = DN_RUN_STAT_STOPPED; tscEmbedded = 1; taosIgnSIGPIPE(); taosBlockSIGPIPE(); @@ -175,10 +175,10 @@ int32_t dnodeInit() { taosStepAdd(steps, "dnode-vnode", dnodeInitVnode, vnodeCleanup); taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, mnodeCleanup); taosStepAdd(steps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans); - taosStepAdd(steps, "dnode-msg", dnodeInitMsg, dnodeCleanupMsg); + taosStepAdd(steps, "dnode-msg", dnodeInitDnode, dnodeCleanupDnode); - tsDnode.steps = steps; - taosStepExec(tsDnode.steps); + tsInt.steps = steps; + taosStepExec(tsInt.steps); dnodeSetRunStat(DN_RUN_STAT_RUNNING); dnodeReportStartupFinished("TDengine", "initialized successfully"); @@ -190,8 +190,8 @@ int32_t dnodeInit() { void dnodeCleanup() { if (dnodeGetRunStat() != DN_RUN_STAT_STOPPED) { dnodeSetRunStat(DN_RUN_STAT_STOPPED); - taosStepCleanup(tsDnode.steps); - tsDnode.steps = NULL; + taosStepCleanup(tsInt.steps); + tsInt.steps = NULL; } } From 7354b9e193ea2160d169209723c6a0c99b96d566 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 20:38:50 +0800 Subject: [PATCH 15/17] minor changes --- source/dnode/mgmt/inc/dnodeInt.h | 1 - source/dnode/mgmt/inc/dnodeMnode.h | 3 +++ source/dnode/mgmt/inc/dnodeVnodes.h | 8 ++---- source/dnode/mgmt/src/dnodeInt.c | 42 ++++++----------------------- source/dnode/mgmt/src/dnodeMain.c | 6 ++--- source/dnode/mgmt/src/dnodeMnode.c | 34 +++++++++++++++++++++++ source/dnode/mgmt/src/dnodeVnodes.c | 22 +++++++++++++++ 7 files changed, 71 insertions(+), 45 deletions(-) create mode 100644 source/dnode/mgmt/src/dnodeMnode.c diff --git a/source/dnode/mgmt/inc/dnodeInt.h b/source/dnode/mgmt/inc/dnodeInt.h index 20257140d6..bccafcee85 100644 --- a/source/dnode/mgmt/inc/dnodeInt.h +++ b/source/dnode/mgmt/inc/dnodeInt.h @@ -24,7 +24,6 @@ extern "C" { #include "tglobal.h" #include "tlog.h" #include "trpc.h" -#include "ttimer.h" extern int32_t dDebugFlag; diff --git a/source/dnode/mgmt/inc/dnodeMnode.h b/source/dnode/mgmt/inc/dnodeMnode.h index 0dccb8c39d..00868535c1 100644 --- a/source/dnode/mgmt/inc/dnodeMnode.h +++ b/source/dnode/mgmt/inc/dnodeMnode.h @@ -21,6 +21,9 @@ extern "C" { #endif #include "dnodeInt.h" +int32_t dnodeInitMnode(); +void dnodeCleanupMnode(); + void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg); #ifdef __cplusplus diff --git a/source/dnode/mgmt/inc/dnodeVnodes.h b/source/dnode/mgmt/inc/dnodeVnodes.h index 33848042bd..fae1de7217 100644 --- a/source/dnode/mgmt/inc/dnodeVnodes.h +++ b/source/dnode/mgmt/inc/dnodeVnodes.h @@ -21,12 +21,8 @@ extern "C" { #endif #include "dnodeInt.h" -int32_t dnodeInitDnode(); -void dnodeCleanupDnode(); -void dnodeProcessStatusRsp(SRpcMsg *pMsg); -void dnodeProcessStartupReq(SRpcMsg *pMsg); -void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg); -void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg); +int32_t dnodeInitVnodes(); +void dnodeCleanupVnodes(); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/src/dnodeInt.c b/source/dnode/mgmt/src/dnodeInt.c index 6368fe95f7..df84896be7 100644 --- a/source/dnode/mgmt/src/dnodeInt.c +++ b/source/dnode/mgmt/src/dnodeInt.c @@ -17,14 +17,14 @@ #include "dnodeCheck.h" #include "dnodeConfig.h" #include "dnodeDnode.h" +#include "dnodeMnode.h" #include "dnodeTransport.h" -#include "mnode.h" +#include "dnodeVnodes.h" #include "sync.h" #include "tcache.h" #include "tconfig.h" #include "tnote.h" #include "tstep.h" -#include "vnode.h" #include "wal.h" static struct { @@ -37,7 +37,7 @@ EDnStat dnodeGetRunStat() { return tsInt.runStatus; } void dnodeSetRunStat(EDnStat stat) { tsInt.runStatus = stat; } -void dnodeReportStartup(char *name, char *desc) { +static void dnodeReportStartup(char *name, char *desc) { SStartupStep *startup = &tsInt.startup; tstrncpy(startup->name, name, strlen(startup->name)); tstrncpy(startup->desc, desc, strlen(startup->desc)); @@ -53,24 +53,6 @@ static void dnodeReportStartupFinished(char *name, char *desc) { void dnodeGetStartup(SStartupStep *pStep) { memcpy(pStep, &tsInt.startup, sizeof(SStartupStep)); } -static int32_t dnodeInitVnode() { - return vnodeInit(); -} - -static int32_t dnodeInitMnode() { - SMnodePara para; - para.fp.GetDnodeEp = dnodeGetEp; - para.fp.SendMsgToDnode = dnodeSendMsgToDnode; - para.fp.SendMsgToMnode = dnodeSendMsgToMnode; - para.fp.SendRedirectMsg = dnodeSendRedirectMsg; - para.dnodeId = dnodeGetDnodeId(); - para.clusterId = dnodeGetClusterId(); - - return mnodeInit(para); -} - -static int32_t dnodeInitTfs() {} - static int32_t dnodeInitMain() { tsInt.runStatus = DN_RUN_STAT_STOPPED; tscEmbedded = 1; @@ -168,14 +150,14 @@ int32_t dnodeInit() { taosStepAdd(steps, "dnode-dir", dnodeInitDir, dnodeCleanupDir); taosStepAdd(steps, "dnode-check", dnodeInitCheck, dnodeCleanupCheck); taosStepAdd(steps, "dnode-rpc", rpcInit, rpcCleanup); - taosStepAdd(steps, "dnode-tfs", dnodeInitTfs, NULL); + taosStepAdd(steps, "dnode-tfs", NULL, NULL); taosStepAdd(steps, "dnode-wal", walInit, walCleanUp); taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp); - taosStepAdd(steps, "dnode-eps", dnodeInitConfig, dnodeCleanupConfig); - taosStepAdd(steps, "dnode-vnode", dnodeInitVnode, vnodeCleanup); - taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, mnodeCleanup); + taosStepAdd(steps, "dnode-config", dnodeInitConfig, dnodeCleanupConfig); + taosStepAdd(steps, "dnode-vnodes", dnodeInitVnodes, dnodeCleanupVnodes); + taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, dnodeCleanupMnode); taosStepAdd(steps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans); - taosStepAdd(steps, "dnode-msg", dnodeInitDnode, dnodeCleanupDnode); + taosStepAdd(steps, "dnode-dnode", dnodeInitDnode, dnodeCleanupDnode); tsInt.steps = steps; taosStepExec(tsInt.steps); @@ -194,11 +176,3 @@ void dnodeCleanup() { tsInt.steps = NULL; } } - -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_CREATE_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_SYNC_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_COMPACT_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_DROP_VNODE] = vnodeProcessMgmtMsg; -// tsVnode.msgFp[TSDB_MSG_TYPE_MD_ALTER_STREAM] = vnodeProcessMgmtMsg; - \ No newline at end of file diff --git a/source/dnode/mgmt/src/dnodeMain.c b/source/dnode/mgmt/src/dnodeMain.c index 69960173f4..1fbeb1e732 100644 --- a/source/dnode/mgmt/src/dnodeMain.c +++ b/source/dnode/mgmt/src/dnodeMain.c @@ -12,8 +12,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "os.h" -#include "ulog.h" + +#define _DEFAULT_SOURCE #include "dnodeInt.h" static bool stop = false; @@ -35,8 +35,6 @@ int main(int argc, char const *argv[]) { exit(EXIT_FAILURE); } - dInfo("Started TDengine service successfully."); - while (!stop) { taosMsleep(100); } diff --git a/source/dnode/mgmt/src/dnodeMnode.c b/source/dnode/mgmt/src/dnodeMnode.c new file mode 100644 index 0000000000..47b1d89bb8 --- /dev/null +++ b/source/dnode/mgmt/src/dnodeMnode.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dnodeMnode.h" +#include "dnodeConfig.h" +#include "dnodeTransport.h" +#include "mnode.h" + +int32_t dnodeInitMnode() { + SMnodePara para; + para.fp.GetDnodeEp = dnodeGetEp; + para.fp.SendMsgToDnode = dnodeSendMsgToDnode; + para.fp.SendMsgToMnode = dnodeSendMsgToMnode; + para.fp.SendRedirectMsg = dnodeSendRedirectMsg; + para.dnodeId = dnodeGetDnodeId(); + para.clusterId = dnodeGetClusterId(); + + return mnodeInit(para); +} + +void dnodeCleanupMnode() { mnodeCleanup(); } \ No newline at end of file diff --git a/source/dnode/mgmt/src/dnodeVnodes.c b/source/dnode/mgmt/src/dnodeVnodes.c index e69de29bb2..765bd6fc22 100644 --- a/source/dnode/mgmt/src/dnodeVnodes.c +++ b/source/dnode/mgmt/src/dnodeVnodes.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dnodeDnode.h" +#include "vnode.h" + +int32_t dnodeInitVnodes() { return vnodeInit(); } + +void dnodeCleanupVnodes() { vnodeCleanup(); } \ No newline at end of file From da0a115c6e35e35d18703d714a39bfd67dcb341d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 20:51:34 +0800 Subject: [PATCH 16/17] rename files --- source/dnode/mgmt/inc/dnodeCheck.h | 31 -- source/dnode/mgmt/inc/dnodeConfig.h | 41 --- source/dnode/mgmt/inc/dnodeDnode.h | 14 + source/dnode/mgmt/src/dnodeCheck.c | 191 ----------- source/dnode/mgmt/src/dnodeConfig.c | 415 ----------------------- source/dnode/mgmt/src/dnodeDnode.c | 438 +++++++++++++++++++++++-- source/dnode/mgmt/src/dnodeInt.c | 93 +++--- source/dnode/mgmt/src/dnodeMnode.c | 32 +- source/dnode/mgmt/src/dnodeTransport.c | 1 - 9 files changed, 493 insertions(+), 763 deletions(-) delete mode 100644 source/dnode/mgmt/inc/dnodeCheck.h delete mode 100644 source/dnode/mgmt/inc/dnodeConfig.h delete mode 100644 source/dnode/mgmt/src/dnodeCheck.c delete mode 100644 source/dnode/mgmt/src/dnodeConfig.c diff --git a/source/dnode/mgmt/inc/dnodeCheck.h b/source/dnode/mgmt/inc/dnodeCheck.h deleted file mode 100644 index 97ac524b3f..0000000000 --- a/source/dnode/mgmt/inc/dnodeCheck.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_DNODE_CHECK_H_ -#define _TD_DNODE_CHECK_H_ - -#ifdef __cplusplus -extern "C" { -#endif -#include "dnodeInt.h" - -int32_t dnodeInitCheck(); -void dnodeCleanupCheck(); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_DNODE_CHECK_H_*/ diff --git a/source/dnode/mgmt/inc/dnodeConfig.h b/source/dnode/mgmt/inc/dnodeConfig.h deleted file mode 100644 index 71f3ac3f97..0000000000 --- a/source/dnode/mgmt/inc/dnodeConfig.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_DNODE_CONFIG_H_ -#define _TD_DNODE_CONFIG_H_ - -#ifdef __cplusplus -extern "C" { -#endif -#include "dnodeInt.h" - -int32_t dnodeInitConfig(); -void dnodeCleanupConfig(); - -void dnodeUpdateCfg(SDnodeCfg *data); -void dnodeUpdateDnodeEps(SDnodeEps *data); -void dnodeUpdateMnodeEps(SRpcEpSet *pEpSet); -int32_t dnodeGetDnodeId(); -int64_t dnodeGetClusterId(); -void dnodeGetEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port); - -void dnodeGetEpSetForPeer(SRpcEpSet *epSet); -void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_DNODE_CONFIG_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/inc/dnodeDnode.h b/source/dnode/mgmt/inc/dnodeDnode.h index b126b39d1c..aba80752a2 100644 --- a/source/dnode/mgmt/inc/dnodeDnode.h +++ b/source/dnode/mgmt/inc/dnodeDnode.h @@ -27,6 +27,20 @@ void dnodeProcessStatusRsp(SRpcMsg *pMsg); void dnodeProcessStartupReq(SRpcMsg *pMsg); void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg); +int32_t dnodeInitConfig(); +void dnodeCleanupConfig(); + +void dnodeUpdateCfg(SDnodeCfg *data); +void dnodeUpdateDnodeEps(SDnodeEps *data); +void dnodeUpdateMnodeEps(SRpcEpSet *pEpSet); +int32_t dnodeGetDnodeId(); +int64_t dnodeGetClusterId(); +void dnodeGetEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port); + +void dnodeGetEpSetForPeer(SRpcEpSet *epSet); +void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell); + + #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/src/dnodeCheck.c b/source/dnode/mgmt/src/dnodeCheck.c deleted file mode 100644 index b7bd930bb3..0000000000 --- a/source/dnode/mgmt/src/dnodeCheck.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dnodeCheck.h" - -#define MIN_AVAIL_MEMORY_MB 32 - -static int32_t dnodeBindTcpPort(uint16_t port) { -#if 0 - SOCKET serverSocket; - struct sockaddr_in server_addr; - - if ((serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { - dError("failed to create tcp socket since %s", strerror(errno)); - return -1; - } - - bzero(&server_addr, sizeof(server_addr)); - server_addr.sin_family = AF_INET; - server_addr.sin_port = htons(port); - server_addr.sin_addr.s_addr = htonl(INADDR_ANY); - - if (bind(serverSocket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { - dError("failed to bind tcp port:%d since %s", port, strerror(errno)); - taosCloseSocket(serverSocket); - return -1; - } - - if (listen(serverSocket, 5) < 0) { - dError("failed to listen tcp port:%d since %s", port, strerror(errno)); - taosCloseSocket(serverSocket); - return -1; - } - - taosCloseSocket(serverSocket); -#endif - return 0; -} - -static int32_t dnodeBindUdpPort(int16_t port) { -#if 0 - SOCKET serverSocket; - struct sockaddr_in server_addr; - - if ((serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - dError("failed to create udp socket since %s", strerror(errno)); - return -1; - } - - bzero(&server_addr, sizeof(server_addr)); - server_addr.sin_family = AF_INET; - server_addr.sin_port = htons(port); - server_addr.sin_addr.s_addr = htonl(INADDR_ANY); - - if (bind(serverSocket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { - dError("failed to bind udp port:%d since %s", port, strerror(errno)); - taosCloseSocket(serverSocket); - return -1; - } - - taosCloseSocket(serverSocket); -#endif - return 0; -} - -static int32_t dnodeCheckNetwork() { - int32_t ret; - uint16_t startPort = tsServerPort; - - for (uint16_t port = startPort; port < startPort + 12; port++) { - ret = dnodeBindTcpPort(port); - if (0 != ret) { - dError("failed to bind tcp port:%d", port); - return -1; - } - ret = dnodeBindUdpPort(port); - if (0 != ret) { - dError("failed to bind udp port:%d", port); - return -1; - } - } - - return 0; -} - -static int32_t dnodeCheckMem() { -#if 0 - float memoryUsedMB; - float memoryAvailMB; - if (true != taosGetSysMemory(&memoryUsedMB)) { - dError("failed to get system memory since %s, errno:%u,", strerror(errno), errno); - return -1; - } - - memoryAvailMB = (float)tsTotalMemoryMB - memoryUsedMB; - - if (memoryAvailMB < MIN_AVAIL_MEMORY_MB) { - dError("available memory %fMB less than the threshold %dMB", memoryAvailMB, MIN_AVAIL_MEMORY_MB); - return -1; - } -#endif - return 0; -} - -static int32_t dnodeCheckDisk() { -#if 0 - taosGetDisk(); - - if (tsAvailDataDirGB < tsMinimalDataDirGB) { - dError("dataDir disk size:%fGB less than threshold %fGB ", tsAvailDataDirGB, tsMinimalDataDirGB); - return -1; - } - - if (tsAvailLogDirGB < tsMinimalLogDirGB) { - dError("logDir disk size:%fGB less than threshold %fGB", tsAvailLogDirGB, tsMinimalLogDirGB); - return -1; - } - - if (tsAvailTmpDirectorySpace < tsReservedTmpDirectorySpace) { - dError("tmpDir disk size:%fGB less than threshold %fGB", tsAvailTmpDirectorySpace, tsReservedTmpDirectorySpace); - return -1; - } -#endif - return 0; -} - -static int32_t dnodeCheckCpu() { return 0; } -static int32_t dnodeCheckOs() { return 0; } -static int32_t dnodeCheckAccess() { return 0; } -static int32_t dnodeCheckVersion() { return 0; } -static int32_t dnodeCheckDatafile() { return 0; } - -int32_t dnodeInitCheck() { - if (dnodeCheckNetwork() != 0) { - dError("failed to check network"); - return -1; - } - - if (dnodeCheckMem() != 0) { - dError("failed to check memory"); - return -1; - } - - if (dnodeCheckCpu() != 0) { - dError("failed to check cpu"); - return -1; - } - - if (dnodeCheckDisk() != 0) { - dError("failed to check disk"); - return -1; - } - - if (dnodeCheckOs() != 0) { - dError("failed to check os"); - return -1; - } - - if (dnodeCheckAccess() != 0) { - dError("failed to check access"); - return -1; - } - - if (dnodeCheckVersion() != 0) { - dError("failed to check version"); - return -1; - } - - if (dnodeCheckDatafile() != 0) { - dError("failed to check datafile"); - return -1; - } - - dInfo("dnode check is finished"); - return 0; -} - -void dnodeCleanupCheck() {} \ No newline at end of file diff --git a/source/dnode/mgmt/src/dnodeConfig.c b/source/dnode/mgmt/src/dnodeConfig.c deleted file mode 100644 index 2a0374ffaf..0000000000 --- a/source/dnode/mgmt/src/dnodeConfig.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dnodeConfig.h" -#include "cJSON.h" -#include "thash.h" - -static struct { - int32_t dnodeId; - int32_t dropped; - int64_t clusterId; - SDnodeEps *dnodeEps; - SHashObj *dnodeHash; - SRpcEpSet mnodeEpSetForShell; - SRpcEpSet mnodeEpSetForPeer; - char file[PATH_MAX + 20]; - pthread_mutex_t mutex; -} tsConfig; - -void dnodeGetEpSetForPeer(SRpcEpSet *epSet) { - pthread_mutex_lock(&tsConfig.mutex); - *epSet = tsConfig.mnodeEpSetForPeer; - pthread_mutex_unlock(&tsConfig.mutex); -} - -static void dnodeGetEpSetForShell(SRpcEpSet *epSet) { - pthread_mutex_lock(&tsConfig.mutex); - *epSet = tsConfig.mnodeEpSetForShell; - pthread_mutex_unlock(&tsConfig.mutex); -} - -void dnodeUpdateMnodeEps(SRpcEpSet *ep) { - if (ep != NULL || ep->numOfEps <= 0) { - dError("mnode is changed, but content is invalid, discard it"); - return; - } - - pthread_mutex_lock(&tsConfig.mutex); - - dInfo("mnode is changed, num:%d use:%d", ep->numOfEps, ep->inUse); - - tsConfig.mnodeEpSetForPeer = *ep; - for (int32_t i = 0; i < ep->numOfEps; ++i) { - ep->port[i] -= TSDB_PORT_DNODEDNODE; - dInfo("mnode index:%d %s:%u", i, ep->fqdn[i], ep->port[i]); - } - tsConfig.mnodeEpSetForShell = *ep; - - pthread_mutex_unlock(&tsConfig.mutex); -} - -void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell) { - SRpcConnInfo connInfo = {0}; - rpcGetConnInfo(rpcMsg->handle, &connInfo); - - SRpcEpSet epSet = {0}; - if (forShell) { - dnodeGetEpSetForShell(&epSet); - } else { - dnodeGetEpSetForPeer(&epSet); - } - - dDebug("msg:%s will be redirected, num:%d use:%d", taosMsg[rpcMsg->msgType], epSet.numOfEps, epSet.inUse); - - for (int32_t i = 0; i < epSet.numOfEps; ++i) { - dDebug("mnode index:%d %s:%d", i, epSet.fqdn[i], epSet.port[i]); - if (strcmp(epSet.fqdn[i], tsLocalFqdn) == 0) { - if ((epSet.port[i] == tsServerPort + TSDB_PORT_DNODEDNODE && !forShell) || - (epSet.port[i] == tsServerPort && forShell)) { - epSet.inUse = (i + 1) % epSet.numOfEps; - dDebug("mnode index:%d %s:%d set inUse to %d", i, epSet.fqdn[i], epSet.port[i], epSet.inUse); - } - } - - epSet.port[i] = htons(epSet.port[i]); - } - - rpcSendRedirectRsp(rpcMsg->handle, &epSet); -} - -static void dnodePrintEps() { - dDebug("print dnode list, num:%d", tsConfig.dnodeEps->dnodeNum); - for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; i++) { - SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; - dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort, ep->isMnode); - } -} - -static void dnodeResetEps(SDnodeEps *data) { - assert(data != NULL); - - int32_t size = sizeof(SDnodeEps) + data->dnodeNum * sizeof(SDnodeEp); - - if (data->dnodeNum > tsConfig.dnodeEps->dnodeNum) { - SDnodeEps *tmp = calloc(1, size); - if (tmp == NULL) return; - - tfree(tsConfig.dnodeEps); - tsConfig.dnodeEps = tmp; - } - - if (tsConfig.dnodeEps != data) { - memcpy(tsConfig.dnodeEps, data, size); - } - - tsConfig.mnodeEpSetForPeer.inUse = 0; - tsConfig.mnodeEpSetForShell.inUse = 0; - int32_t index = 0; - for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; i++) { - SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; - if (!ep->isMnode) continue; - if (index >= TSDB_MAX_REPLICA) continue; - strcpy(tsConfig.mnodeEpSetForShell.fqdn[index], ep->dnodeFqdn); - strcpy(tsConfig.mnodeEpSetForPeer.fqdn[index], ep->dnodeFqdn); - tsConfig.mnodeEpSetForShell.port[index] = ep->dnodePort; - tsConfig.mnodeEpSetForShell.port[index] = ep->dnodePort + tsDnodeDnodePort; - index++; - } - - for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; ++i) { - SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; - taosHashPut(tsConfig.dnodeHash, &ep->dnodeId, sizeof(int32_t), ep, sizeof(SDnodeEp)); - } - - dnodePrintEps(); -} - -static bool dnodeIsDnodeEpChanged(int32_t dnodeId, char *epstr) { - bool changed = false; - - pthread_mutex_lock(&tsConfig.mutex); - - SDnodeEp *ep = taosHashGet(tsConfig.dnodeHash, &dnodeId, sizeof(int32_t)); - if (ep != NULL) { - char epSaved[TSDB_EP_LEN + 1]; - snprintf(epSaved, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort); - changed = strcmp(epstr, epSaved) != 0; - tstrncpy(epstr, epSaved, TSDB_EP_LEN); - } - - pthread_mutex_unlock(&tsConfig.mutex); - - return changed; -} - -static int32_t dnodeReadEps() { - int32_t len = 0; - int32_t maxLen = 30000; - char *content = calloc(1, maxLen + 1); - cJSON *root = NULL; - FILE *fp = NULL; - - fp = fopen(tsConfig.file, "r"); - if (!fp) { - dDebug("file %s not exist", tsConfig.file); - goto PRASE_EPS_OVER; - } - - len = (int32_t)fread(content, 1, maxLen, fp); - if (len <= 0) { - dError("failed to read %s since content is null", tsConfig.file); - goto PRASE_EPS_OVER; - } - - content[len] = 0; - root = cJSON_Parse(content); - if (root == NULL) { - dError("failed to read %s since invalid json format", tsConfig.file); - goto PRASE_EPS_OVER; - } - - cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId"); - if (!dnodeId || dnodeId->type != cJSON_String) { - dError("failed to read %s since dnodeId not found", tsConfig.file); - goto PRASE_EPS_OVER; - } - tsConfig.dnodeId = atoi(dnodeId->valuestring); - - cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); - if (!dropped || dropped->type != cJSON_String) { - dError("failed to read %s since dropped not found", tsConfig.file); - goto PRASE_EPS_OVER; - } - tsConfig.dropped = atoi(dropped->valuestring); - - cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); - if (!clusterId || clusterId->type != cJSON_String) { - dError("failed to read %s since clusterId not found", tsConfig.file); - goto PRASE_EPS_OVER; - } - tsConfig.clusterId = atoll(clusterId->valuestring); - - cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos"); - if (!dnodeInfos || dnodeInfos->type != cJSON_Array) { - dError("failed to read %s since dnodeInfos not found", tsConfig.file); - goto PRASE_EPS_OVER; - } - - int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos); - if (dnodeInfosSize <= 0) { - dError("failed to read %s since dnodeInfos size:%d invalid", tsConfig.file, dnodeInfosSize); - goto PRASE_EPS_OVER; - } - - tsConfig.dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps)); - if (tsConfig.dnodeEps == NULL) { - dError("failed to calloc dnodeEpList since %s", strerror(errno)); - goto PRASE_EPS_OVER; - } - tsConfig.dnodeEps->dnodeNum = dnodeInfosSize; - - for (int32_t i = 0; i < dnodeInfosSize; ++i) { - cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i); - if (dnodeInfo == NULL) break; - - SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; - - cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId"); - if (!dnodeId || dnodeId->type != cJSON_String) { - dError("failed to read %s, dnodeId not found", tsConfig.file); - goto PRASE_EPS_OVER; - } - ep->dnodeId = atoi(dnodeId->valuestring); - - cJSON *isMnode = cJSON_GetObjectItem(dnodeInfo, "isMnode"); - if (!isMnode || isMnode->type != cJSON_String) { - dError("failed to read %s, isMnode not found", tsConfig.file); - goto PRASE_EPS_OVER; - } - ep->isMnode = atoi(isMnode->valuestring); - - cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn"); - if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) { - dError("failed to read %s, dnodeFqdn not found", tsConfig.file); - goto PRASE_EPS_OVER; - } - tstrncpy(ep->dnodeFqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN); - - cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort"); - if (!dnodePort || dnodePort->type != cJSON_String) { - dError("failed to read %s, dnodePort not found", tsConfig.file); - goto PRASE_EPS_OVER; - } - ep->dnodePort = atoi(dnodePort->valuestring); - } - - dInfo("succcessed to read file %s", tsConfig.file); - dnodePrintEps(); - -PRASE_EPS_OVER: - if (content != NULL) free(content); - if (root != NULL) cJSON_Delete(root); - if (fp != NULL) fclose(fp); - - if (dnodeIsDnodeEpChanged(tsConfig.dnodeId, tsLocalEp)) { - dError("dnode:%d, localEp %s different with dnodeEps.json and need reconfigured", tsConfig.dnodeId, tsLocalEp); - return -1; - } - - dnodeResetEps(tsConfig.dnodeEps); - - terrno = 0; - return 0; -} - -static int32_t dnodeWriteEps() { - FILE *fp = fopen(tsConfig.file, "w"); - if (!fp) { - dError("failed to write %s since %s", tsConfig.file, strerror(errno)); - return -1; - } - - int32_t len = 0; - int32_t maxLen = 30000; - char *content = calloc(1, maxLen + 1); - - len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", tsConfig.dnodeId); - len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", tsConfig.dropped); - len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", tsConfig.clusterId); - len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n"); - for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; ++i) { - SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; - len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", ep->dnodeId); - len += snprintf(content + len, maxLen - len, " \"isMnode\": \"%d\",\n", ep->isMnode); - len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", ep->dnodeFqdn); - len += snprintf(content + len, maxLen - len, " \"dnodePort\": \"%u\"\n", ep->dnodePort); - if (i < tsConfig.dnodeEps->dnodeNum - 1) { - len += snprintf(content + len, maxLen - len, " },{\n"); - } else { - len += snprintf(content + len, maxLen - len, " }]\n"); - } - } - len += snprintf(content + len, maxLen - len, "}\n"); - - fwrite(content, 1, len, fp); - taosFsyncFile(fileno(fp)); - fclose(fp); - free(content); - terrno = 0; - - dInfo("successed to write %s", tsConfig.file); - return 0; -} - -int32_t dnodeInitConfig() { - tsConfig.dnodeId = 0; - tsConfig.dropped = 0; - tsConfig.clusterId = 0; - tsConfig.dnodeEps = NULL; - snprintf(tsConfig.file, sizeof(tsConfig.file), "%s/dnodeEps.json", tsDnodeDir); - pthread_mutex_init(&tsConfig.mutex, NULL); - - tsConfig.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); - if (tsConfig.dnodeHash == NULL) return -1; - - int32_t ret = dnodeReadEps(); - if (ret == 0) { - dInfo("dnode eps is initialized"); - } - - return ret; -} - -void dnodeCleanupConfig() { - pthread_mutex_lock(&tsConfig.mutex); - - if (tsConfig.dnodeEps != NULL) { - free(tsConfig.dnodeEps); - tsConfig.dnodeEps = NULL; - } - - if (tsConfig.dnodeHash) { - taosHashCleanup(tsConfig.dnodeHash); - tsConfig.dnodeHash = NULL; - } - - pthread_mutex_unlock(&tsConfig.mutex); - pthread_mutex_destroy(&tsConfig.mutex); -} - -void dnodeUpdateDnodeEps(SDnodeEps *data) { - if (data == NULL || data->dnodeNum <= 0) return; - - pthread_mutex_lock(&tsConfig.mutex); - - if (data->dnodeNum != tsConfig.dnodeEps->dnodeNum) { - dnodeResetEps(data); - dnodeWriteEps(); - } else { - int32_t size = data->dnodeNum * sizeof(SDnodeEp) + sizeof(SDnodeEps); - if (memcmp(tsConfig.dnodeEps, data, size) != 0) { - dnodeResetEps(data); - dnodeWriteEps(); - } - } - - pthread_mutex_unlock(&tsConfig.mutex); -} - -void dnodeGetEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port) { - pthread_mutex_lock(&tsConfig.mutex); - - SDnodeEp *ep = taosHashGet(tsConfig.dnodeHash, &dnodeId, sizeof(int32_t)); - if (ep != NULL) { - if (port) *port = ep->dnodePort; - if (fqdn) tstrncpy(fqdn, ep->dnodeFqdn, TSDB_FQDN_LEN); - if (epstr) snprintf(epstr, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort); - } - - pthread_mutex_unlock(&tsConfig.mutex); -} - -void dnodeUpdateCfg(SDnodeCfg *data) { - if (tsConfig.dnodeId != 0 && !data->dropped) return; - - pthread_mutex_lock(&tsConfig.mutex); - - tsConfig.dnodeId = data->dnodeId; - tsConfig.clusterId = data->clusterId; - tsConfig.dropped = data->dropped; - dInfo("dnodeId is set to %d, clusterId is set to %" PRId64, data->dnodeId, data->clusterId); - - dnodeWriteEps(); - pthread_mutex_unlock(&tsConfig.mutex); -} - -int32_t dnodeGetDnodeId() { - int32_t dnodeId = 0; - pthread_mutex_lock(&tsConfig.mutex); - dnodeId = tsConfig.dnodeId; - pthread_mutex_unlock(&tsConfig.mutex); - return dnodeId; -} - -int64_t dnodeGetClusterId() { - int64_t clusterId = 0; - pthread_mutex_lock(&tsConfig.mutex); - clusterId = tsConfig.clusterId; - pthread_mutex_unlock(&tsConfig.mutex); - return clusterId; -} diff --git a/source/dnode/mgmt/src/dnodeDnode.c b/source/dnode/mgmt/src/dnodeDnode.c index 3c6a743e05..722ef30099 100644 --- a/source/dnode/mgmt/src/dnodeDnode.c +++ b/source/dnode/mgmt/src/dnodeDnode.c @@ -15,15 +15,411 @@ #define _DEFAULT_SOURCE #include "dnodeDnode.h" -#include "dnodeConfig.h" -#include "mnode.h" +#include "dnodeTransport.h" #include "tthread.h" #include "ttime.h" -#include "vnode.h" +#include "cJSON.h" +#include "thash.h" + +static struct { + int32_t dnodeId; + int32_t dropped; + int64_t clusterId; + SDnodeEps *dnodeEps; + SHashObj *dnodeHash; + SRpcEpSet mnodeEpSetForShell; + SRpcEpSet mnodeEpSetForPeer; + char file[PATH_MAX + 20]; + pthread_mutex_t mutex; +} tsConfig; + +void dnodeGetEpSetForPeer(SRpcEpSet *epSet) { + pthread_mutex_lock(&tsConfig.mutex); + *epSet = tsConfig.mnodeEpSetForPeer; + pthread_mutex_unlock(&tsConfig.mutex); +} + +static void dnodeGetEpSetForShell(SRpcEpSet *epSet) { + pthread_mutex_lock(&tsConfig.mutex); + *epSet = tsConfig.mnodeEpSetForShell; + pthread_mutex_unlock(&tsConfig.mutex); +} + +void dnodeUpdateMnodeEps(SRpcEpSet *ep) { + if (ep != NULL || ep->numOfEps <= 0) { + dError("mnode is changed, but content is invalid, discard it"); + return; + } + + pthread_mutex_lock(&tsConfig.mutex); + + dInfo("mnode is changed, num:%d use:%d", ep->numOfEps, ep->inUse); + + tsConfig.mnodeEpSetForPeer = *ep; + for (int32_t i = 0; i < ep->numOfEps; ++i) { + ep->port[i] -= TSDB_PORT_DNODEDNODE; + dInfo("mnode index:%d %s:%u", i, ep->fqdn[i], ep->port[i]); + } + tsConfig.mnodeEpSetForShell = *ep; + + pthread_mutex_unlock(&tsConfig.mutex); +} + +void dnodeSendRedirectMsg(SRpcMsg *rpcMsg, bool forShell) { + SRpcConnInfo connInfo = {0}; + rpcGetConnInfo(rpcMsg->handle, &connInfo); + + SRpcEpSet epSet = {0}; + if (forShell) { + dnodeGetEpSetForShell(&epSet); + } else { + dnodeGetEpSetForPeer(&epSet); + } + + dDebug("msg:%s will be redirected, num:%d use:%d", taosMsg[rpcMsg->msgType], epSet.numOfEps, epSet.inUse); + + for (int32_t i = 0; i < epSet.numOfEps; ++i) { + dDebug("mnode index:%d %s:%d", i, epSet.fqdn[i], epSet.port[i]); + if (strcmp(epSet.fqdn[i], tsLocalFqdn) == 0) { + if ((epSet.port[i] == tsServerPort + TSDB_PORT_DNODEDNODE && !forShell) || + (epSet.port[i] == tsServerPort && forShell)) { + epSet.inUse = (i + 1) % epSet.numOfEps; + dDebug("mnode index:%d %s:%d set inUse to %d", i, epSet.fqdn[i], epSet.port[i], epSet.inUse); + } + } + + epSet.port[i] = htons(epSet.port[i]); + } + + rpcSendRedirectRsp(rpcMsg->handle, &epSet); +} + +static void dnodePrintEps() { + dDebug("print dnode list, num:%d", tsConfig.dnodeEps->dnodeNum); + for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; i++) { + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; + dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", ep->dnodeId, ep->dnodeFqdn, ep->dnodePort, ep->isMnode); + } +} + +static void dnodeResetEps(SDnodeEps *data) { + assert(data != NULL); + + int32_t size = sizeof(SDnodeEps) + data->dnodeNum * sizeof(SDnodeEp); + + if (data->dnodeNum > tsConfig.dnodeEps->dnodeNum) { + SDnodeEps *tmp = calloc(1, size); + if (tmp == NULL) return; + + tfree(tsConfig.dnodeEps); + tsConfig.dnodeEps = tmp; + } + + if (tsConfig.dnodeEps != data) { + memcpy(tsConfig.dnodeEps, data, size); + } + + tsConfig.mnodeEpSetForPeer.inUse = 0; + tsConfig.mnodeEpSetForShell.inUse = 0; + int32_t index = 0; + for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; i++) { + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; + if (!ep->isMnode) continue; + if (index >= TSDB_MAX_REPLICA) continue; + strcpy(tsConfig.mnodeEpSetForShell.fqdn[index], ep->dnodeFqdn); + strcpy(tsConfig.mnodeEpSetForPeer.fqdn[index], ep->dnodeFqdn); + tsConfig.mnodeEpSetForShell.port[index] = ep->dnodePort; + tsConfig.mnodeEpSetForShell.port[index] = ep->dnodePort + tsDnodeDnodePort; + index++; + } + + for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; ++i) { + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; + taosHashPut(tsConfig.dnodeHash, &ep->dnodeId, sizeof(int32_t), ep, sizeof(SDnodeEp)); + } + + dnodePrintEps(); +} + +static bool dnodeIsDnodeEpChanged(int32_t dnodeId, char *epstr) { + bool changed = false; + + pthread_mutex_lock(&tsConfig.mutex); + + SDnodeEp *ep = taosHashGet(tsConfig.dnodeHash, &dnodeId, sizeof(int32_t)); + if (ep != NULL) { + char epSaved[TSDB_EP_LEN + 1]; + snprintf(epSaved, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort); + changed = strcmp(epstr, epSaved) != 0; + tstrncpy(epstr, epSaved, TSDB_EP_LEN); + } + + pthread_mutex_unlock(&tsConfig.mutex); + + return changed; +} + +static int32_t dnodeReadEps() { + int32_t len = 0; + int32_t maxLen = 30000; + char *content = calloc(1, maxLen + 1); + cJSON *root = NULL; + FILE *fp = NULL; + + fp = fopen(tsConfig.file, "r"); + if (!fp) { + dDebug("file %s not exist", tsConfig.file); + goto PRASE_EPS_OVER; + } + + len = (int32_t)fread(content, 1, maxLen, fp); + if (len <= 0) { + dError("failed to read %s since content is null", tsConfig.file); + goto PRASE_EPS_OVER; + } + + content[len] = 0; + root = cJSON_Parse(content); + if (root == NULL) { + dError("failed to read %s since invalid json format", tsConfig.file); + goto PRASE_EPS_OVER; + } + + cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId"); + if (!dnodeId || dnodeId->type != cJSON_String) { + dError("failed to read %s since dnodeId not found", tsConfig.file); + goto PRASE_EPS_OVER; + } + tsConfig.dnodeId = atoi(dnodeId->valuestring); + + cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); + if (!dropped || dropped->type != cJSON_String) { + dError("failed to read %s since dropped not found", tsConfig.file); + goto PRASE_EPS_OVER; + } + tsConfig.dropped = atoi(dropped->valuestring); + + cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); + if (!clusterId || clusterId->type != cJSON_String) { + dError("failed to read %s since clusterId not found", tsConfig.file); + goto PRASE_EPS_OVER; + } + tsConfig.clusterId = atoll(clusterId->valuestring); + + cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos"); + if (!dnodeInfos || dnodeInfos->type != cJSON_Array) { + dError("failed to read %s since dnodeInfos not found", tsConfig.file); + goto PRASE_EPS_OVER; + } + + int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos); + if (dnodeInfosSize <= 0) { + dError("failed to read %s since dnodeInfos size:%d invalid", tsConfig.file, dnodeInfosSize); + goto PRASE_EPS_OVER; + } + + tsConfig.dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps)); + if (tsConfig.dnodeEps == NULL) { + dError("failed to calloc dnodeEpList since %s", strerror(errno)); + goto PRASE_EPS_OVER; + } + tsConfig.dnodeEps->dnodeNum = dnodeInfosSize; + + for (int32_t i = 0; i < dnodeInfosSize; ++i) { + cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i); + if (dnodeInfo == NULL) break; + + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; + + cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId"); + if (!dnodeId || dnodeId->type != cJSON_String) { + dError("failed to read %s, dnodeId not found", tsConfig.file); + goto PRASE_EPS_OVER; + } + ep->dnodeId = atoi(dnodeId->valuestring); + + cJSON *isMnode = cJSON_GetObjectItem(dnodeInfo, "isMnode"); + if (!isMnode || isMnode->type != cJSON_String) { + dError("failed to read %s, isMnode not found", tsConfig.file); + goto PRASE_EPS_OVER; + } + ep->isMnode = atoi(isMnode->valuestring); + + cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn"); + if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) { + dError("failed to read %s, dnodeFqdn not found", tsConfig.file); + goto PRASE_EPS_OVER; + } + tstrncpy(ep->dnodeFqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN); + + cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort"); + if (!dnodePort || dnodePort->type != cJSON_String) { + dError("failed to read %s, dnodePort not found", tsConfig.file); + goto PRASE_EPS_OVER; + } + ep->dnodePort = atoi(dnodePort->valuestring); + } + + dInfo("succcessed to read file %s", tsConfig.file); + dnodePrintEps(); + +PRASE_EPS_OVER: + if (content != NULL) free(content); + if (root != NULL) cJSON_Delete(root); + if (fp != NULL) fclose(fp); + + if (dnodeIsDnodeEpChanged(tsConfig.dnodeId, tsLocalEp)) { + dError("dnode:%d, localEp %s different with dnodeEps.json and need reconfigured", tsConfig.dnodeId, tsLocalEp); + return -1; + } + + dnodeResetEps(tsConfig.dnodeEps); + + terrno = 0; + return 0; +} + +static int32_t dnodeWriteEps() { + FILE *fp = fopen(tsConfig.file, "w"); + if (!fp) { + dError("failed to write %s since %s", tsConfig.file, strerror(errno)); + return -1; + } + + int32_t len = 0; + int32_t maxLen = 30000; + char *content = calloc(1, maxLen + 1); + + len += snprintf(content + len, maxLen - len, "{\n"); + len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", tsConfig.dnodeId); + len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", tsConfig.dropped); + len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", tsConfig.clusterId); + len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n"); + for (int32_t i = 0; i < tsConfig.dnodeEps->dnodeNum; ++i) { + SDnodeEp *ep = &tsConfig.dnodeEps->dnodeEps[i]; + len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", ep->dnodeId); + len += snprintf(content + len, maxLen - len, " \"isMnode\": \"%d\",\n", ep->isMnode); + len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", ep->dnodeFqdn); + len += snprintf(content + len, maxLen - len, " \"dnodePort\": \"%u\"\n", ep->dnodePort); + if (i < tsConfig.dnodeEps->dnodeNum - 1) { + len += snprintf(content + len, maxLen - len, " },{\n"); + } else { + len += snprintf(content + len, maxLen - len, " }]\n"); + } + } + len += snprintf(content + len, maxLen - len, "}\n"); + + fwrite(content, 1, len, fp); + taosFsyncFile(fileno(fp)); + fclose(fp); + free(content); + terrno = 0; + + dInfo("successed to write %s", tsConfig.file); + return 0; +} + +int32_t dnodeInitConfig() { + tsConfig.dnodeId = 0; + tsConfig.dropped = 0; + tsConfig.clusterId = 0; + tsConfig.dnodeEps = NULL; + snprintf(tsConfig.file, sizeof(tsConfig.file), "%s/dnodeEps.json", tsDnodeDir); + pthread_mutex_init(&tsConfig.mutex, NULL); + + tsConfig.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); + if (tsConfig.dnodeHash == NULL) return -1; + + int32_t ret = dnodeReadEps(); + if (ret == 0) { + dInfo("dnode eps is initialized"); + } + + return ret; +} + +void dnodeCleanupConfig() { + pthread_mutex_lock(&tsConfig.mutex); + + if (tsConfig.dnodeEps != NULL) { + free(tsConfig.dnodeEps); + tsConfig.dnodeEps = NULL; + } + + if (tsConfig.dnodeHash) { + taosHashCleanup(tsConfig.dnodeHash); + tsConfig.dnodeHash = NULL; + } + + pthread_mutex_unlock(&tsConfig.mutex); + pthread_mutex_destroy(&tsConfig.mutex); +} + +void dnodeUpdateDnodeEps(SDnodeEps *data) { + if (data == NULL || data->dnodeNum <= 0) return; + + pthread_mutex_lock(&tsConfig.mutex); + + if (data->dnodeNum != tsConfig.dnodeEps->dnodeNum) { + dnodeResetEps(data); + dnodeWriteEps(); + } else { + int32_t size = data->dnodeNum * sizeof(SDnodeEp) + sizeof(SDnodeEps); + if (memcmp(tsConfig.dnodeEps, data, size) != 0) { + dnodeResetEps(data); + dnodeWriteEps(); + } + } + + pthread_mutex_unlock(&tsConfig.mutex); +} + +void dnodeGetEp(int32_t dnodeId, char *epstr, char *fqdn, uint16_t *port) { + pthread_mutex_lock(&tsConfig.mutex); + + SDnodeEp *ep = taosHashGet(tsConfig.dnodeHash, &dnodeId, sizeof(int32_t)); + if (ep != NULL) { + if (port) *port = ep->dnodePort; + if (fqdn) tstrncpy(fqdn, ep->dnodeFqdn, TSDB_FQDN_LEN); + if (epstr) snprintf(epstr, TSDB_EP_LEN, "%s:%u", ep->dnodeFqdn, ep->dnodePort); + } + + pthread_mutex_unlock(&tsConfig.mutex); +} + +void dnodeUpdateCfg(SDnodeCfg *data) { + if (tsConfig.dnodeId != 0 && !data->dropped) return; + + pthread_mutex_lock(&tsConfig.mutex); + + tsConfig.dnodeId = data->dnodeId; + tsConfig.clusterId = data->clusterId; + tsConfig.dropped = data->dropped; + dInfo("dnodeId is set to %d, clusterId is set to %" PRId64, data->dnodeId, data->clusterId); + + dnodeWriteEps(); + pthread_mutex_unlock(&tsConfig.mutex); +} + +int32_t dnodeGetDnodeId() { + int32_t dnodeId = 0; + pthread_mutex_lock(&tsConfig.mutex); + dnodeId = tsConfig.dnodeId; + pthread_mutex_unlock(&tsConfig.mutex); + return dnodeId; +} + +int64_t dnodeGetClusterId() { + int64_t clusterId = 0; + pthread_mutex_lock(&tsConfig.mutex); + clusterId = tsConfig.clusterId; + pthread_mutex_unlock(&tsConfig.mutex); + return clusterId; +} static struct { pthread_t *threadId; - bool stop; + bool threadStop; uint32_t rebootTime; } tsDnode; @@ -93,14 +489,14 @@ void dnodeProcessStatusRsp(SRpcMsg *pMsg) { static void *dnodeThreadRoutine(void *param) { int32_t ms = tsStatusInterval * 1000; - while (!tsDnode.stop) { + while (!tsDnode.threadStop) { taosMsleep(ms); dnodeSendStatusMsg(); } } int32_t dnodeInitDnode() { - tsDnode.stop = false; + tsDnode.threadStop = false; tsDnode.rebootTime = taosGetTimestampSec(); tsDnode.threadId = taosCreateThread(dnodeThreadRoutine, NULL); if (tsDnode.threadId == NULL) { @@ -113,7 +509,7 @@ int32_t dnodeInitDnode() { void dnodeCleanupDnode() { if (tsDnode.threadId != NULL) { - tsDnode.stop = true; + tsDnode.threadStop = true; taosDestoryThread(tsDnode.threadId); tsDnode.threadId = NULL; } @@ -121,34 +517,6 @@ void dnodeCleanupDnode() { dInfo("dnode msg is cleanuped"); } -static int32_t dnodeStartMnode(SRpcMsg *pMsg) { - SCreateMnodeMsg *pCfg = pMsg->pCont; - pCfg->dnodeId = htonl(pCfg->dnodeId); - pCfg->mnodeNum = htonl(pCfg->mnodeNum); - for (int32_t i = 0; i < pCfg->mnodeNum; ++i) { - pCfg->mnodeEps[i].dnodeId = htonl(pCfg->mnodeEps[i].dnodeId); - pCfg->mnodeEps[i].dnodePort = htons(pCfg->mnodeEps[i].dnodePort); - } - - if (pCfg->dnodeId != dnodeGetDnodeId()) { - dDebug("dnode:%d, in create meps msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId()); - return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED; - } - - if (mnodeGetStatus() == MN_STATUS_READY) return 0; - - return mnodeDeploy(); -} - -void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg) { - int32_t code = dnodeStartMnode(pMsg); - - SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code}; - - rpcSendResponse(&rspMsg); - rpcFreeCont(pMsg->pCont); -} - void dnodeProcessConfigDnodeReq(SRpcMsg *pMsg) { SCfgDnodeMsg *pCfg = pMsg->pCont; diff --git a/source/dnode/mgmt/src/dnodeInt.c b/source/dnode/mgmt/src/dnodeInt.c index df84896be7..a1e7bc1c7e 100644 --- a/source/dnode/mgmt/src/dnodeInt.c +++ b/source/dnode/mgmt/src/dnodeInt.c @@ -14,8 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "dnodeCheck.h" -#include "dnodeConfig.h" #include "dnodeDnode.h" #include "dnodeMnode.h" #include "dnodeTransport.h" @@ -53,46 +51,6 @@ static void dnodeReportStartupFinished(char *name, char *desc) { void dnodeGetStartup(SStartupStep *pStep) { memcpy(pStep, &tsInt.startup, sizeof(SStartupStep)); } -static int32_t dnodeInitMain() { - tsInt.runStatus = DN_RUN_STAT_STOPPED; - tscEmbedded = 1; - taosIgnSIGPIPE(); - taosBlockSIGPIPE(); - taosResolveCRC(); - taosInitGlobalCfg(); - taosReadGlobalLogCfg(); - taosSetCoreDump(tsEnableCoreFile); - - if (!taosMkDir(tsLogDir)) { - printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno)); - return -1; - } - - char temp[TSDB_FILENAME_LEN]; - sprintf(temp, "%s/taosdlog", tsLogDir); - if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) { - printf("failed to init log file\n"); - } - - if (!taosReadGlobalCfg()) { - taosPrintGlobalCfg(); - dError("TDengine read global config failed"); - return -1; - } - - dInfo("start to initialize TDengine"); - - taosInitNotes(); - - return taosCheckGlobalCfg(); -} - -static void dnodeCleanupMain() { - taos_cleanup(); - taosCloseLog(); - taosStopCacheRefreshWorker(); -} - static int32_t dnodeCheckRunning(char *dir) { char filepath[256] = {0}; snprintf(filepath, sizeof(filepath), "%s/.running", dir); @@ -140,24 +98,65 @@ static int32_t dnodeInitDir() { return 0; } -static void dnodeCleanupDir() {} +static int32_t dnodeInitMain() { + tsInt.runStatus = DN_RUN_STAT_STOPPED; + tscEmbedded = 1; + taosIgnSIGPIPE(); + taosBlockSIGPIPE(); + taosResolveCRC(); + taosInitGlobalCfg(); + taosReadGlobalLogCfg(); + taosSetCoreDump(tsEnableCoreFile); + + if (!taosMkDir(tsLogDir)) { + printf("failed to create dir: %s, reason: %s\n", tsLogDir, strerror(errno)); + return -1; + } + + char temp[TSDB_FILENAME_LEN]; + sprintf(temp, "%s/taosdlog", tsLogDir); + if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) { + printf("failed to init log file\n"); + } + + if (!taosReadGlobalCfg()) { + taosPrintGlobalCfg(); + dError("TDengine read global config failed"); + return -1; + } + + dInfo("start to initialize TDengine"); + + taosInitNotes(); + + if (taosCheckGlobalCfg() != 0) { + return -1; + } + + dnodeInitDir(); + + return -1; +} + +static void dnodeCleanupMain() { + taos_cleanup(); + taosCloseLog(); + taosStopCacheRefreshWorker(); +} int32_t dnodeInit() { SSteps *steps = taosStepInit(24, dnodeReportStartup); if (steps == NULL) return -1; taosStepAdd(steps, "dnode-main", dnodeInitMain, dnodeCleanupMain); - taosStepAdd(steps, "dnode-dir", dnodeInitDir, dnodeCleanupDir); - taosStepAdd(steps, "dnode-check", dnodeInitCheck, dnodeCleanupCheck); taosStepAdd(steps, "dnode-rpc", rpcInit, rpcCleanup); taosStepAdd(steps, "dnode-tfs", NULL, NULL); taosStepAdd(steps, "dnode-wal", walInit, walCleanUp); taosStepAdd(steps, "dnode-sync", syncInit, syncCleanUp); - taosStepAdd(steps, "dnode-config", dnodeInitConfig, dnodeCleanupConfig); + taosStepAdd(steps, "dnode-dnode", dnodeInitDnode, dnodeCleanupDnode); taosStepAdd(steps, "dnode-vnodes", dnodeInitVnodes, dnodeCleanupVnodes); taosStepAdd(steps, "dnode-mnode", dnodeInitMnode, dnodeCleanupMnode); taosStepAdd(steps, "dnode-trans", dnodeInitTrans, dnodeCleanupTrans); - taosStepAdd(steps, "dnode-dnode", dnodeInitDnode, dnodeCleanupDnode); tsInt.steps = steps; taosStepExec(tsInt.steps); diff --git a/source/dnode/mgmt/src/dnodeMnode.c b/source/dnode/mgmt/src/dnodeMnode.c index 47b1d89bb8..6019fbd1f6 100644 --- a/source/dnode/mgmt/src/dnodeMnode.c +++ b/source/dnode/mgmt/src/dnodeMnode.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "dnodeMnode.h" -#include "dnodeConfig.h" +#include "dnodeDnode.h" #include "dnodeTransport.h" #include "mnode.h" @@ -31,4 +31,32 @@ int32_t dnodeInitMnode() { return mnodeInit(para); } -void dnodeCleanupMnode() { mnodeCleanup(); } \ No newline at end of file +void dnodeCleanupMnode() { mnodeCleanup(); } + +static int32_t dnodeStartMnode(SRpcMsg *pMsg) { + SCreateMnodeMsg *pCfg = pMsg->pCont; + pCfg->dnodeId = htonl(pCfg->dnodeId); + pCfg->mnodeNum = htonl(pCfg->mnodeNum); + for (int32_t i = 0; i < pCfg->mnodeNum; ++i) { + pCfg->mnodeEps[i].dnodeId = htonl(pCfg->mnodeEps[i].dnodeId); + pCfg->mnodeEps[i].dnodePort = htons(pCfg->mnodeEps[i].dnodePort); + } + + if (pCfg->dnodeId != dnodeGetDnodeId()) { + dDebug("dnode:%d, in create meps msg is not equal with saved dnodeId:%d", pCfg->dnodeId, dnodeGetDnodeId()); + return TSDB_CODE_MND_DNODE_ID_NOT_CONFIGURED; + } + + if (mnodeGetStatus() == MN_STATUS_READY) return 0; + + return mnodeDeploy(); +} + +void dnodeProcessCreateMnodeReq(SRpcMsg *pMsg) { + int32_t code = dnodeStartMnode(pMsg); + + SRpcMsg rspMsg = {.handle = pMsg->handle, .pCont = NULL, .contLen = 0, .code = code}; + + rpcSendResponse(&rspMsg); + rpcFreeCont(pMsg->pCont); +} \ No newline at end of file diff --git a/source/dnode/mgmt/src/dnodeTransport.c b/source/dnode/mgmt/src/dnodeTransport.c index 68ec0a44e5..39747d4350 100644 --- a/source/dnode/mgmt/src/dnodeTransport.c +++ b/source/dnode/mgmt/src/dnodeTransport.c @@ -21,7 +21,6 @@ #define _DEFAULT_SOURCE #include "dnodeTransport.h" -#include "dnodeConfig.h" #include "dnodeDnode.h" #include "dnodeMnode.h" #include "dnodeVnodes.h" From 1284e413b0e306db0948789e4c7635045fbf1443 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 1 Nov 2021 20:53:46 +0800 Subject: [PATCH 17/17] minor changes --- source/dnode/mgmt/src/{dnodeMain.c => dnode.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/dnode/mgmt/src/{dnodeMain.c => dnode.c} (100%) diff --git a/source/dnode/mgmt/src/dnodeMain.c b/source/dnode/mgmt/src/dnode.c similarity index 100% rename from source/dnode/mgmt/src/dnodeMain.c rename to source/dnode/mgmt/src/dnode.c