From c3a25985a73ea65e9500f01b0e643494194a4eff Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Nov 2021 16:20:47 +0800 Subject: [PATCH 01/18] change lock type in dndDnode --- source/dnode/mgmt/impl/src/dndDnode.c | 81 ++++++++++++----------- source/dnode/mgmt/impl/src/dndTransport.c | 2 + source/dnode/mgmt/impl/src/dnode.c | 5 +- 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index fa601a0d99..0f47c5b409 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -18,32 +18,27 @@ #include "dndTransport.h" #include "dndVnodes.h" -static inline void dndRLockDnode(SDnode *pDnode) { taosRLockLatch(&pDnode->dmgmt.latch); } - -static inline void dndRUnLockDnode(SDnode *pDnode) { taosRUnLockLatch(&pDnode->dmgmt.latch); } - -static inline void dndWLockDnode(SDnode *pDnode) { taosWLockLatch(&pDnode->dmgmt.latch); } - -static inline void dndWUnLockDnode(SDnode *pDnode) { taosWUnLockLatch(&pDnode->dmgmt.latch); } - int32_t dndGetDnodeId(SDnode *pDnode) { - dndRLockDnode(pDnode); - int32_t dnodeId = pDnode->dmgmt.dnodeId; - dndRUnLockDnode(pDnode); + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + taosRLockLatch(&pMgmt->latch); + int32_t dnodeId = pMgmt->dnodeId; + taosRUnLockLatch(&pMgmt->latch); return dnodeId; } int64_t dndGetClusterId(SDnode *pDnode) { - dndRLockDnode(pDnode); - int64_t clusterId = pDnode->dmgmt.clusterId; - dndRUnLockDnode(pDnode); + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + taosRLockLatch(&pMgmt->latch); + int64_t clusterId = pMgmt->clusterId; + taosRUnLockLatch(&pMgmt->latch); return clusterId; } void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { - dndRLockDnode(pDnode); + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + taosRLockLatch(&pMgmt->latch); - SDnodeEp *pDnodeEp = taosHashGet(pDnode->dmgmt.dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { if (pPort != NULL) { *pPort = pDnodeEp->port; @@ -56,13 +51,14 @@ void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint } } - dndRUnLockDnode(pDnode); + taosRUnLockLatch(&pMgmt->latch); } void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { - dndRLockDnode(pDnode); - *pEpSet = pDnode->dmgmt.mnodeEpSet; - dndRUnLockDnode(pDnode); + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + taosRLockLatch(&pMgmt->latch); + *pEpSet = pMgmt->mnodeEpSet; + taosRUnLockLatch(&pMgmt->latch); } void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { @@ -87,14 +83,15 @@ void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { dInfo("mnode is changed, num:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse); - dndWLockDnode(pDnode); + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + taosWLockLatch(&pMgmt->latch); - pDnode->dmgmt.mnodeEpSet = *pEpSet; + pMgmt->mnodeEpSet = *pEpSet; for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]); } - dndWUnLockDnode(pDnode); + taosWUnLockLatch(&pMgmt->latch); } static void dndPrintDnodes(SDnode *pDnode) { @@ -145,16 +142,18 @@ static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) { static bool dndIsEpChanged(SDnode *pDnode, int32_t dnodeId, char *pEp) { bool changed = false; - dndRLockDnode(pDnode); - SDnodeEp *pDnodeEp = taosHashGet(pDnode->dmgmt.dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + taosRLockLatch(&pMgmt->latch); + + SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { char epstr[TSDB_EP_LEN + 1]; snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->fqdn, pDnodeEp->port); changed = strcmp(pEp, epstr) != 0; } - dndRUnLockDnode(pDnode); + taosRUnLockLatch(&pMgmt->latch); return changed; } @@ -342,11 +341,14 @@ static void dndSendStatusMsg(SDnode *pDnode) { return; } - dndRLockDnode(pDnode); + bool changed = false; + + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + taosRLockLatch(&pMgmt->latch); pStatus->sversion = htonl(pDnode->opt.sver); - pStatus->dnodeId = htonl(pDnode->dmgmt.dnodeId); - pStatus->clusterId = htobe64(pDnode->dmgmt.clusterId); - pStatus->rebootTime = htonl(pDnode->dmgmt.rebootTime); + pStatus->dnodeId = htonl(pMgmt->dnodeId); + pStatus->clusterId = htobe64(pMgmt->clusterId); + pStatus->rebootTime = htonl(pMgmt->rebootTime); pStatus->numOfCores = htonl(pDnode->opt.numOfCores); tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN); pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval); @@ -356,7 +358,7 @@ static void dndSendStatusMsg(SDnode *pDnode) { pStatus->clusterCfg.checkTime = 0; 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); - dndRUnLockDnode(pDnode); + taosRUnLockLatch(&pMgmt->latch); dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads); contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad); @@ -370,32 +372,33 @@ static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { if (pMgmt->dnodeId == 0 || pMgmt->dropped != pCfg->dropped) { dInfo("set dnodeId:%d clusterId:%" PRId64 " dropped:%d", pCfg->dnodeId, pCfg->clusterId, pCfg->dropped); - dndWLockDnode(pDnode); + taosWLockLatch(&pMgmt->latch); pMgmt->dnodeId = pCfg->dnodeId; pMgmt->clusterId = pCfg->clusterId; pMgmt->dropped = pCfg->dropped; (void)dndWriteDnodes(pDnode); - dndWUnLockDnode(pDnode); + taosWUnLockLatch(&pMgmt->latch); } } static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) { if (pDnodeEps == NULL || pDnodeEps->num <= 0) return; - dndWLockDnode(pDnode); + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + taosWLockLatch(&pMgmt->latch); - if (pDnodeEps->num != pDnode->dmgmt.dnodeEps->num) { + if (pDnodeEps->num != pMgmt->dnodeEps->num) { dndResetDnodes(pDnode, pDnodeEps); dndWriteDnodes(pDnode); } else { int32_t size = pDnodeEps->num * sizeof(SDnodeEp) + sizeof(SDnodeEps); - if (memcmp(pDnode->dmgmt.dnodeEps, pDnodeEps, size) != 0) { + if (memcmp(pMgmt->dnodeEps, pDnodeEps, size) != 0) { dndResetDnodes(pDnode, pDnodeEps); dndWriteDnodes(pDnode); } } - dndWUnLockDnode(pDnode); + taosWUnLockLatch(&pMgmt->latch); } static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { @@ -512,7 +515,7 @@ void dndCleanupDnode(SDnode *pDnode) { pMgmt->threadId = NULL; } - dndWLockDnode(pDnode); + taosWLockLatch(&pMgmt->latch); if (pMgmt->dnodeEps != NULL) { free(pMgmt->dnodeEps); @@ -529,7 +532,7 @@ void dndCleanupDnode(SDnode *pDnode) { pMgmt->file = NULL; } - dndWUnLockDnode(pDnode); + taosWUnLockLatch(&pMgmt->latch); dInfo("dnode-dnode is cleaned up"); } diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index c3940cd3cc..0364c4db38 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -187,6 +187,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { int32_t msgType = pMsg->msgType; if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) { + dTrace("RPC %p, network test req will be processed", pMsg->handle); dndProcessDnodeReq(pDnode, pMsg, pEpSet); return; } @@ -206,6 +207,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { } if (pMsg->pCont == NULL) { + dTrace("RPC %p, req:%s not processed since content is null", pMsg->handle, taosMsg[msgType]); SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN}; rpcSendResponse(&rspMsg); return; diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 23c9ee0ebf..1159bbb4c5 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -26,7 +26,7 @@ EStat dndGetStat(SDnode *pDnode) { return pDnode->stat; } void dndSetStat(SDnode *pDnode, EStat stat) { - dDebug("dnode stat set from %s to %s", dndStatStr(pDnode->stat), dndStatStr(stat)); + dDebug("dnode status set from %s to %s", dndStatStr(pDnode->stat), dndStatStr(stat)); pDnode->stat = stat; } @@ -214,8 +214,7 @@ void dndCleanup(SDnode *pDnode) { dndCleanupDnode(pDnode); walCleanUp(); rpcCleanup(); - - dInfo("TDengine is cleaned up successfully"); dndCleanupEnv(pDnode); free(pDnode); + dInfo("TDengine is cleaned up successfully"); } From c4306958c788d5b828336cfee34387e16e33ded2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Nov 2021 17:23:57 +0800 Subject: [PATCH 02/18] TD-11265 fix transport in dnode-mgmt --- include/dnode/mnode/mnode.h | 12 +++---- source/dnode/mgmt/impl/src/dndDnode.c | 3 ++ source/dnode/mgmt/impl/src/dndMnode.c | 38 ++++++++++++++--------- source/dnode/mgmt/impl/src/dndTransport.c | 6 ++-- source/dnode/mnode/impl/src/mnode.c | 8 ++--- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 824eb24191..2ffbd395e8 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -137,38 +137,34 @@ void mnodeSendRsp(SMnodeMsg *pMsg, int32_t code); /** * @brief Process the read request * - * @param pMnode The mnode object * @param pMsg The request msg * @return int32_t 0 for success, -1 for failure */ -void mnodeProcessReadMsg(SMnode *pMnode, SMnodeMsg *pMsg); +void mnodeProcessReadMsg(SMnodeMsg *pMsg); /** * @brief Process the write request * - * @param pMnode The mnode object * @param pMsg The request msg * @return int32_t 0 for success, -1 for failure */ -void mnodeProcessWriteMsg(SMnode *pMnode, SMnodeMsg *pMsg); +void mnodeProcessWriteMsg(SMnodeMsg *pMsg); /** * @brief Process the sync request * - * @param pMnode The mnode object * @param pMsg The request msg * @return int32_t 0 for success, -1 for failure */ -void mnodeProcessSyncMsg(SMnode *pMnode, SMnodeMsg *pMsg); +void mnodeProcessSyncMsg(SMnodeMsg *pMsg); /** * @brief Process the apply request * - * @param pMnode The mnode object * @param pMsg The request msg * @return int32_t 0 for success, -1 for failure */ -void mnodeProcessApplyMsg(SMnode *pMnode, SMnodeMsg *pMsg); +void mnodeProcessApplyMsg(SMnodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 0f47c5b409..9e70bf1ae9 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -121,12 +121,14 @@ static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) { } pMgmt->mnodeEpSet.inUse = 0; + pMgmt->mnodeEpSet.numOfEps = 0; int32_t mIndex = 0; for (int32_t i = 0; i < pMgmt->dnodeEps->num; i++) { SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i]; if (!pDnodeEp->isMnode) continue; if (mIndex >= TSDB_MAX_REPLICA) continue; + pMgmt->mnodeEpSet.numOfEps++; strcpy(pMgmt->mnodeEpSet.fqdn[mIndex], pDnodeEp->fqdn); pMgmt->mnodeEpSet.port[mIndex] = pDnodeEp->port; mIndex++; @@ -279,6 +281,7 @@ PRASE_DNODE_OVER: if (pMgmt->dnodeEps == NULL) { pMgmt->dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp)); pMgmt->dnodeEps->num = 1; + pMgmt->dnodeEps->eps[0].isMnode = 1; pMgmt->dnodeEps->eps[0].port = pDnode->opt.serverPort; tstrncpy(pMgmt->dnodeEps->eps[0].fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN); } diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index fe3accdd84..d42891f1e4 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -80,7 +80,9 @@ static SMnode *dndAcquireMnode(SDnode *pDnode) { } taosRUnLockLatch(&pMgmt->latch); - dTrace("acquire mnode, refCount:%d", refCount); + if (pMnode != NULL) { + dTrace("acquire mnode, refCount:%d", refCount); + } return pMnode; } @@ -94,7 +96,9 @@ static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) { } taosRUnLockLatch(&pMgmt->latch); - dTrace("release mnode, refCount:%d", refCount); + if (pMnode != NULL) { + dTrace("release mnode, refCount:%d", refCount); + } } static int32_t dndReadMnodeFile(SDnode *pDnode) { @@ -550,7 +554,7 @@ static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mnodeProcessReadMsg(pMnode, pMsg); + mnodeProcessReadMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { mnodeSendRsp(pMsg, terrno); @@ -564,7 +568,7 @@ static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mnodeProcessWriteMsg(pMnode, pMsg); + mnodeProcessWriteMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { mnodeSendRsp(pMsg, terrno); @@ -578,7 +582,7 @@ static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mnodeProcessApplyMsg(pMnode, pMsg); + mnodeProcessApplyMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { mnodeSendRsp(pMsg, terrno); @@ -592,7 +596,7 @@ static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mnodeProcessSyncMsg(pMnode, pMsg); + mnodeProcessSyncMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { mnodeSendRsp(pMsg, terrno); @@ -683,7 +687,7 @@ static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, NULL, (FProcessItem)dndProcessMnodeMgmtQueue); + pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMnodeMgmtQueue); if (pMgmt->pMgmtQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -708,18 +712,19 @@ static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) { return -1; } + dDebug("mnode mgmt worker is initialized"); return 0; } static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->mgmtPool); - dDebug("mnode mgmt worker is stopped"); + dDebug("mnode mgmt worker is closed"); } static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, NULL, (FProcessItem)dndProcessMnodeReadQueue); + pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, pDnode, (FProcessItem)dndProcessMnodeReadQueue); if (pMgmt->pReadQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -745,18 +750,19 @@ static int32_t dndInitMnodeReadWorker(SDnode *pDnode) { return -1; } + dDebug("mnode read worker is initialized"); return 0; } static void dndCleanupMnodeReadWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->readPool); - dDebug("mnode read worker is stopped"); + dDebug("mnode read worker is closed"); } static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, NULL, (FProcessItem)dndProcessMnodeWriteQueue); + pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeWriteQueue); if (pMgmt->pWriteQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -773,7 +779,7 @@ static void dndFreeMnodeWriteQueue(SDnode *pDnode) { static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, NULL, (FProcessItem)dndProcessMnodeApplyQueue); + pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, pDnode, (FProcessItem)dndProcessMnodeApplyQueue); if (pMgmt->pApplyQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -799,18 +805,19 @@ static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) { return -1; } + dDebug("mnode write worker is initialized"); return 0; } static void dndCleanupMnodeWriteWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->writePool); - dDebug("mnode write worker is stopped"); + dDebug("mnode write worker is closed"); } static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; - pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, NULL, (FProcessItem)dndProcessMnodeSyncQueue); + pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, pDnode, (FProcessItem)dndProcessMnodeSyncQueue); if (pMgmt->pSyncQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -836,13 +843,14 @@ static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) { return -1; } + dDebug("mnode sync worker is initialized"); return 0; } static void dndCleanupMnodeSyncWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->syncPool); - dDebug("mnode sync worker is stopped"); + dDebug("mnode sync worker is closed"); } int32_t dndInitMnode(SDnode *pDnode) { diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index 0364c4db38..eee2e36c0f 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -261,12 +261,12 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char SDnode *pDnode = parent; if (dndAuthInternalMsg(parent, user, spi, encrypt, secret, ckey) == 0) { - dTrace("get internal auth success"); + // dTrace("get internal auth success"); return 0; } if (dndGetUserAuthFromMnode(pDnode, user, spi, encrypt, secret, ckey) == 0) { - dTrace("get auth from internal mnode"); + // dTrace("get auth from internal mnode"); return 0; } @@ -275,7 +275,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char return -1; } - dDebug("user:%s, send auth msg to other mnodes", user); + // dDebug("user:%s, send auth msg to other mnodes", user); SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg)); tstrncpy(pMsg->user, user, TSDB_USER_LEN); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 8fc5de588f..128a834729 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -234,13 +234,13 @@ void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp) { } } -void mnodeProcessReadMsg(SMnode *pMnode, SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } +void mnodeProcessReadMsg(SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } -void mnodeProcessWriteMsg(SMnode *pMnode, SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } +void mnodeProcessWriteMsg(SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } -void mnodeProcessSyncMsg(SMnode *pMnode, SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } +void mnodeProcessSyncMsg(SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } -void mnodeProcessApplyMsg(SMnode *pMnode, SMnodeMsg *pMsg) {} +void mnodeProcessApplyMsg(SMnodeMsg *pMsg) {} #if 0 From 5cebfe33f4e8c4f6398dc304e93434cafa1d4f7e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Nov 2021 22:46:12 +0800 Subject: [PATCH 03/18] minor changes in mnode --- source/dnode/mnode/impl/inc/mnodeInt.h | 21 ++++++++++----------- source/dnode/mnode/impl/src/mnode.c | 8 ++++---- source/dnode/mnode/impl/src/mnodeUser.c | 4 ++-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mnodeInt.h b/source/dnode/mnode/impl/inc/mnodeInt.h index 7f7f91a3af..16322eeb55 100644 --- a/source/dnode/mnode/impl/inc/mnodeInt.h +++ b/source/dnode/mnode/impl/inc/mnodeInt.h @@ -24,16 +24,16 @@ extern "C" { #endif -typedef int32_t (*MnodeRpcFp)(SMnodeMsg *pMsg); +typedef int32_t (*MndMsgFp)(SMnode *pMnode, SMnodeMsg *pMsg); typedef struct SMnodeBak { - int32_t dnodeId; - int64_t clusterId; - tmr_h timer; - SSteps *pInitSteps; - SSteps *pStartSteps; - SMnodeOpt para; - MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX]; + int32_t dnodeId; + int64_t clusterId; + tmr_h timer; + SSteps *pInitSteps; + SSteps *pStartSteps; + SMnodeOpt para; + MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; } SMnodeBak; typedef struct SMnode { @@ -47,7 +47,7 @@ typedef struct SMnode { SSteps *pStartSteps; struct SSdb *pSdb; struct SDnode *pServer; - MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX]; + MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; PutMsgToMnodeQFp putMsgToApplyMsgFp; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; @@ -61,8 +61,7 @@ int64_t mnodeGetClusterId(); void mnodeSendMsgToDnode(SMnode *pMnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg); void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell); - -void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp); +void mnodeSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 128a834729..6ea47b41fc 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -218,18 +218,18 @@ static void mnodeProcessRpcMsg(SMnodeMsg *pMsg) { int32_t msgType = pMsg->rpcMsg.msgType; - MnodeRpcFp fp = tsMint.msgFp[msgType]; + MndMsgFp fp = tsMint.msgFp[msgType]; if (fp == NULL) { } - int32_t code = (fp)(pMsg); + int32_t code = (*fp)(NULL, pMsg); if (code != 0) { assert(code); } } -void mnodeSetMsgFp(int32_t msgType, MnodeRpcFp fp) { - if (msgType > 0 || msgType < TSDB_MSG_TYPE_MAX) { +void mnodeSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) { + if (msgType >= 0 && msgType < TSDB_MSG_TYPE_MAX) { tsMint.msgFp[msgType] = fp; } } diff --git a/source/dnode/mnode/impl/src/mnodeUser.c b/source/dnode/mnode/impl/src/mnodeUser.c index b8e5706484..e67fedd5eb 100644 --- a/source/dnode/mnode/impl/src/mnodeUser.c +++ b/source/dnode/mnode/impl/src/mnodeUser.c @@ -179,7 +179,7 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM return 0; } -static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) { +static int32_t mnodeProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont; if (pCreate->user[0] == 0) { @@ -231,7 +231,7 @@ int32_t mnodeInitUser() { .deleteFp = (SdbDeleteFp)mnodeUserActionDelete}; sdbSetTable(table); - mnodeSetMsgFp(TSDB_MSG_TYPE_CREATE_USER, mnodeProcessCreateUserMsg); + mnodeSetMsgHandle(NULL, TSDB_MSG_TYPE_CREATE_USER, mnodeProcessCreateUserMsg); return 0; } From ad361ee1df8ea3abe9e492172454245ea6a5d564 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Nov 2021 22:56:18 +0800 Subject: [PATCH 04/18] rename files --- .../mnode/impl/inc/{mnodeAcct.h => mndAcct.h} | 2 +- .../mnode/impl/inc/{mnodeAuth.h => mndAuth.h} | 2 +- .../impl/inc/{mnodeBalance.h => mndBalance.h} | 2 +- .../impl/inc/{mnodeCluster.h => mndCluster.h} | 2 +- .../mnode/impl/inc/{mnodeDb.h => mndDb.h} | 2 +- .../mnode/impl/inc/{mnodeDef.h => mndDef.h} | 0 .../impl/inc/{mnodeDnode.h => mndDnode.h} | 2 +- .../mnode/impl/inc/{mnodeFunc.h => mndFunc.h} | 2 +- .../mnode/impl/inc/{mnodeInt.h => mndInt.h} | 2 +- .../impl/inc/{mnodeMnode.h => mndMnode.h} | 2 +- .../mnode/impl/inc/{mnodeOper.h => mndOper.h} | 0 .../impl/inc/{mnodeProfile.h => mndProfile.h} | 2 +- .../mnode/impl/inc/{mnodeShow.h => mndShow.h} | 2 +- .../impl/inc/{mnodeStable.h => mndStable.h} | 2 +- .../mnode/impl/inc/{mnodeSync.h => mndSync.h} | 2 +- .../impl/inc/{mnodeTelem.h => mndTelem.h} | 2 +- .../impl/inc/{mnodeTrans.h => mndTrans.h} | 2 +- .../mnode/impl/inc/{mnodeUser.h => mndUser.h} | 2 +- .../impl/inc/{mnodeVgroup.h => mndVgroup.h} | 2 +- .../mnode/impl/src/{mnodeAcct.c => mndAcct.c} | 2 +- .../mnode/impl/src/{mnodeAuth.c => mndAuth.c} | 2 +- .../impl/src/{mnodeBalance.c => mndBalance.c} | 2 +- .../impl/src/{mnodeCluster.c => mndCluster.c} | 2 +- .../mnode/impl/src/{mnodeDb.c => mndDb.c} | 2 +- .../impl/src/{mnodeDnode.c => mndDnode.c} | 2 +- .../mnode/impl/src/{mnodeFunc.c => mndFunc.c} | 2 +- .../impl/src/{mnodeMnode.c => mndMnode.c} | 2 +- .../mnode/impl/src/{mnodeOper.c => mndOper.c} | 2 +- .../impl/src/{mnodeProfile.c => mndProfile.c} | 2 +- .../mnode/impl/src/{mnodeShow.c => mndShow.c} | 2 +- .../impl/src/{mnodeStable.c => mndStable.c} | 2 +- .../mnode/impl/src/{mnodeSync.c => mndSync.c} | 4 +-- .../impl/src/{mnodeTelem.c => mndTelem.c} | 4 +-- .../impl/src/{mnodeTrans.c => mndTrans.c} | 2 +- .../mnode/impl/src/{mnodeUser.c => mndUser.c} | 4 +-- .../impl/src/{mnodeVgroup.c => mndVgroup.c} | 2 +- source/dnode/mnode/impl/src/mnode.c | 34 +++++++++---------- 37 files changed, 54 insertions(+), 54 deletions(-) rename source/dnode/mnode/impl/inc/{mnodeAcct.h => mndAcct.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeAuth.h => mndAuth.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeBalance.h => mndBalance.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeCluster.h => mndCluster.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeDb.h => mndDb.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeDef.h => mndDef.h} (100%) rename source/dnode/mnode/impl/inc/{mnodeDnode.h => mndDnode.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeFunc.h => mndFunc.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeInt.h => mndInt.h} (98%) rename source/dnode/mnode/impl/inc/{mnodeMnode.h => mndMnode.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeOper.h => mndOper.h} (100%) rename source/dnode/mnode/impl/inc/{mnodeProfile.h => mndProfile.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeShow.h => mndShow.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeStable.h => mndStable.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeSync.h => mndSync.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeTelem.h => mndTelem.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeTrans.h => mndTrans.h} (98%) rename source/dnode/mnode/impl/inc/{mnodeUser.h => mndUser.h} (97%) rename source/dnode/mnode/impl/inc/{mnodeVgroup.h => mndVgroup.h} (97%) rename source/dnode/mnode/impl/src/{mnodeAcct.c => mndAcct.c} (99%) rename source/dnode/mnode/impl/src/{mnodeAuth.c => mndAuth.c} (97%) rename source/dnode/mnode/impl/src/{mnodeBalance.c => mndBalance.c} (97%) rename source/dnode/mnode/impl/src/{mnodeCluster.c => mndCluster.c} (97%) rename source/dnode/mnode/impl/src/{mnodeDb.c => mndDb.c} (97%) rename source/dnode/mnode/impl/src/{mnodeDnode.c => mndDnode.c} (97%) rename source/dnode/mnode/impl/src/{mnodeFunc.c => mndFunc.c} (97%) rename source/dnode/mnode/impl/src/{mnodeMnode.c => mndMnode.c} (97%) rename source/dnode/mnode/impl/src/{mnodeOper.c => mndOper.c} (97%) rename source/dnode/mnode/impl/src/{mnodeProfile.c => mndProfile.c} (97%) rename source/dnode/mnode/impl/src/{mnodeShow.c => mndShow.c} (97%) rename source/dnode/mnode/impl/src/{mnodeStable.c => mndStable.c} (97%) rename source/dnode/mnode/impl/src/{mnodeSync.c => mndSync.c} (95%) rename source/dnode/mnode/impl/src/{mnodeTelem.c => mndTelem.c} (99%) rename source/dnode/mnode/impl/src/{mnodeTrans.c => mndTrans.c} (99%) rename source/dnode/mnode/impl/src/{mnodeUser.c => mndUser.c} (99%) rename source/dnode/mnode/impl/src/{mnodeVgroup.c => mndVgroup.c} (97%) diff --git a/source/dnode/mnode/impl/inc/mnodeAcct.h b/source/dnode/mnode/impl/inc/mndAcct.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeAcct.h rename to source/dnode/mnode/impl/inc/mndAcct.h index 9491410ddf..a45d865c03 100644 --- a/source/dnode/mnode/impl/inc/mnodeAcct.h +++ b/source/dnode/mnode/impl/inc/mndAcct.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_ACCT_H_ #define _TD_MNODE_ACCT_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeAuth.h b/source/dnode/mnode/impl/inc/mndAuth.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeAuth.h rename to source/dnode/mnode/impl/inc/mndAuth.h index fc828aca27..a759e0169e 100644 --- a/source/dnode/mnode/impl/inc/mnodeAuth.h +++ b/source/dnode/mnode/impl/inc/mndAuth.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_AUTH_H_ #define _TD_MNODE_AUTH_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeBalance.h b/source/dnode/mnode/impl/inc/mndBalance.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeBalance.h rename to source/dnode/mnode/impl/inc/mndBalance.h index c851d58c30..84de9bcb32 100644 --- a/source/dnode/mnode/impl/inc/mnodeBalance.h +++ b/source/dnode/mnode/impl/inc/mndBalance.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_BALANCE_H_ #define _TD_MNODE_BALANCE_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeCluster.h rename to source/dnode/mnode/impl/inc/mndCluster.h index 06001a7757..f9047e6e25 100644 --- a/source/dnode/mnode/impl/inc/mnodeCluster.h +++ b/source/dnode/mnode/impl/inc/mndCluster.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_CLUSTER_H_ #define _TD_MNODE_CLUSTER_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeDb.h b/source/dnode/mnode/impl/inc/mndDb.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeDb.h rename to source/dnode/mnode/impl/inc/mndDb.h index ba16235348..1ab4844873 100644 --- a/source/dnode/mnode/impl/inc/mnodeDb.h +++ b/source/dnode/mnode/impl/inc/mndDb.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_DATABASE_H_ #define _TD_MNODE_DATABASE_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeDef.h b/source/dnode/mnode/impl/inc/mndDef.h similarity index 100% rename from source/dnode/mnode/impl/inc/mnodeDef.h rename to source/dnode/mnode/impl/inc/mndDef.h diff --git a/source/dnode/mnode/impl/inc/mnodeDnode.h b/source/dnode/mnode/impl/inc/mndDnode.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeDnode.h rename to source/dnode/mnode/impl/inc/mndDnode.h index ccbd359f38..7b25061b95 100644 --- a/source/dnode/mnode/impl/inc/mnodeDnode.h +++ b/source/dnode/mnode/impl/inc/mndDnode.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_DNODE_H_ #define _TD_MNODE_DNODE_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeFunc.h b/source/dnode/mnode/impl/inc/mndFunc.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeFunc.h rename to source/dnode/mnode/impl/inc/mndFunc.h index 18154d1c00..ff1ebde8b0 100644 --- a/source/dnode/mnode/impl/inc/mnodeFunc.h +++ b/source/dnode/mnode/impl/inc/mndFunc.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_FUNC_H_ #define _TD_MNODE_FUNC_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeInt.h b/source/dnode/mnode/impl/inc/mndInt.h similarity index 98% rename from source/dnode/mnode/impl/inc/mnodeInt.h rename to source/dnode/mnode/impl/inc/mndInt.h index 16322eeb55..17db21fe18 100644 --- a/source/dnode/mnode/impl/inc/mnodeInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_INT_H_ #define _TD_MNODE_INT_H_ -#include "mnodeDef.h" +#include "mndDef.h" #include "sdb.h" #include "tstep.h" diff --git a/source/dnode/mnode/impl/inc/mnodeMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeMnode.h rename to source/dnode/mnode/impl/inc/mndMnode.h index 0c8069a917..9e7f1766a6 100644 --- a/source/dnode/mnode/impl/inc/mnodeMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_MNODE_H_ #define _TD_MNODE_MNODE_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeOper.h b/source/dnode/mnode/impl/inc/mndOper.h similarity index 100% rename from source/dnode/mnode/impl/inc/mnodeOper.h rename to source/dnode/mnode/impl/inc/mndOper.h diff --git a/source/dnode/mnode/impl/inc/mnodeProfile.h b/source/dnode/mnode/impl/inc/mndProfile.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeProfile.h rename to source/dnode/mnode/impl/inc/mndProfile.h index b3735a02a3..405a6f8dac 100644 --- a/source/dnode/mnode/impl/inc/mnodeProfile.h +++ b/source/dnode/mnode/impl/inc/mndProfile.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_PROFILE_H_ #define _TD_MNODE_PROFILE_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeShow.h b/source/dnode/mnode/impl/inc/mndShow.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeShow.h rename to source/dnode/mnode/impl/inc/mndShow.h index 50beee2897..5045fde1a8 100644 --- a/source/dnode/mnode/impl/inc/mnodeShow.h +++ b/source/dnode/mnode/impl/inc/mndShow.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_SHOW_H_ #define _TD_MNODE_SHOW_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeStable.h b/source/dnode/mnode/impl/inc/mndStable.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeStable.h rename to source/dnode/mnode/impl/inc/mndStable.h index e81fa74d0f..f55d7737de 100644 --- a/source/dnode/mnode/impl/inc/mnodeStable.h +++ b/source/dnode/mnode/impl/inc/mndStable.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_STABLE_H_ #define _TD_MNODE_STABLE_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeSync.h b/source/dnode/mnode/impl/inc/mndSync.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeSync.h rename to source/dnode/mnode/impl/inc/mndSync.h index 380ad36e23..8877bc9c82 100644 --- a/source/dnode/mnode/impl/inc/mnodeSync.h +++ b/source/dnode/mnode/impl/inc/mndSync.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_SYNC_H_ #define _TD_MNODE_SYNC_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeTelem.h b/source/dnode/mnode/impl/inc/mndTelem.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeTelem.h rename to source/dnode/mnode/impl/inc/mndTelem.h index 9122775a31..bb2e6635b1 100644 --- a/source/dnode/mnode/impl/inc/mnodeTelem.h +++ b/source/dnode/mnode/impl/inc/mndTelem.h @@ -19,7 +19,7 @@ #ifdef __cplusplus extern "C" { #endif -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitTelem(); void mnodeCleanupTelem(); diff --git a/source/dnode/mnode/impl/inc/mnodeTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h similarity index 98% rename from source/dnode/mnode/impl/inc/mnodeTrans.h rename to source/dnode/mnode/impl/inc/mndTrans.h index 2abe101dfd..ba6b9fff79 100644 --- a/source/dnode/mnode/impl/inc/mnodeTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -16,7 +16,7 @@ #ifndef _TD_TRANSACTION_INT_H_ #define _TD_TRANSACTION_INT_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeUser.h b/source/dnode/mnode/impl/inc/mndUser.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeUser.h rename to source/dnode/mnode/impl/inc/mndUser.h index 144dd532d9..47fc32c634 100644 --- a/source/dnode/mnode/impl/inc/mnodeUser.h +++ b/source/dnode/mnode/impl/inc/mndUser.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_USER_H_ #define _TD_MNODE_USER_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/inc/mnodeVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h similarity index 97% rename from source/dnode/mnode/impl/inc/mnodeVgroup.h rename to source/dnode/mnode/impl/inc/mndVgroup.h index ebd98bb798..d6e5e00ba8 100644 --- a/source/dnode/mnode/impl/inc/mnodeVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -16,7 +16,7 @@ #ifndef _TD_MNODE_VGROUP_H_ #define _TD_MNODE_VGROUP_H_ -#include "mnodeInt.h" +#include "mndInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mnode/impl/src/mnodeAcct.c b/source/dnode/mnode/impl/src/mndAcct.c similarity index 99% rename from source/dnode/mnode/impl/src/mnodeAcct.c rename to source/dnode/mnode/impl/src/mndAcct.c index 6f5c498ed2..b503a27b11 100644 --- a/source/dnode/mnode/impl/src/mnodeAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "mnodeInt.h" +#include "mndInt.h" #define SDB_ACCT_VER 1 diff --git a/source/dnode/mnode/impl/src/mnodeAuth.c b/source/dnode/mnode/impl/src/mndAuth.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeAuth.c rename to source/dnode/mnode/impl/src/mndAuth.c index f8e704d16d..bb50645cee 100644 --- a/source/dnode/mnode/impl/src/mnodeAuth.c +++ b/source/dnode/mnode/impl/src/mndAuth.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeAuth.h" +#include "mndAuth.h" int32_t mnodeInitAuth() { return 0; } void mnodeCleanupAuth() {} diff --git a/source/dnode/mnode/impl/src/mnodeBalance.c b/source/dnode/mnode/impl/src/mndBalance.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeBalance.c rename to source/dnode/mnode/impl/src/mndBalance.c index a9542ab457..f3acb9b4b3 100644 --- a/source/dnode/mnode/impl/src/mnodeBalance.c +++ b/source/dnode/mnode/impl/src/mndBalance.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitBalance() { return 0; } void mnodeCleanupBalance() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeCluster.c b/source/dnode/mnode/impl/src/mndCluster.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeCluster.c rename to source/dnode/mnode/impl/src/mndCluster.c index 8ce26270e2..f1dbe1df7d 100644 --- a/source/dnode/mnode/impl/src/mnodeCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitCluster() { return 0; } void mnodeCleanupCluster() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeDb.c b/source/dnode/mnode/impl/src/mndDb.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeDb.c rename to source/dnode/mnode/impl/src/mndDb.c index da5e3e5542..c8aa347c7b 100644 --- a/source/dnode/mnode/impl/src/mnodeDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitDb() { return 0; } void mnodeCleanupDb() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeDnode.c b/source/dnode/mnode/impl/src/mndDnode.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeDnode.c rename to source/dnode/mnode/impl/src/mndDnode.c index 36766f72a8..61cd4c01bc 100644 --- a/source/dnode/mnode/impl/src/mnodeDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitDnode() { return 0; } void mnodeCleanupDnode() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeFunc.c b/source/dnode/mnode/impl/src/mndFunc.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeFunc.c rename to source/dnode/mnode/impl/src/mndFunc.c index 2d8628c2be..19a8b8dd0e 100644 --- a/source/dnode/mnode/impl/src/mnodeFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitFunc() { return 0; } void mnodeCleanupFunc() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeMnode.c b/source/dnode/mnode/impl/src/mndMnode.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeMnode.c rename to source/dnode/mnode/impl/src/mndMnode.c index 60e1627ad4..da4d77b440 100644 --- a/source/dnode/mnode/impl/src/mnodeMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitMnode() { return 0; } void mnodeCleanupMnode() {} diff --git a/source/dnode/mnode/impl/src/mnodeOper.c b/source/dnode/mnode/impl/src/mndOper.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeOper.c rename to source/dnode/mnode/impl/src/mndOper.c index 35f4db0261..d25748882a 100644 --- a/source/dnode/mnode/impl/src/mnodeOper.c +++ b/source/dnode/mnode/impl/src/mndOper.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitOper() { return 0; } void mnodeCleanupOper() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeProfile.c b/source/dnode/mnode/impl/src/mndProfile.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeProfile.c rename to source/dnode/mnode/impl/src/mndProfile.c index 9cf9e184cf..64378b0093 100644 --- a/source/dnode/mnode/impl/src/mnodeProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitProfile() { return 0; } void mnodeCleanupProfile() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeShow.c b/source/dnode/mnode/impl/src/mndShow.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeShow.c rename to source/dnode/mnode/impl/src/mndShow.c index 9918ad28e0..338c199afc 100644 --- a/source/dnode/mnode/impl/src/mnodeShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitShow() { return 0; } void mnodeCleanUpShow() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeStable.c b/source/dnode/mnode/impl/src/mndStable.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeStable.c rename to source/dnode/mnode/impl/src/mndStable.c index 87e887a11b..fe0fc59d25 100644 --- a/source/dnode/mnode/impl/src/mnodeStable.c +++ b/source/dnode/mnode/impl/src/mndStable.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitStable() { return 0; } void mnodeCleanupStable() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnodeSync.c b/source/dnode/mnode/impl/src/mndSync.c similarity index 95% rename from source/dnode/mnode/impl/src/mnodeSync.c rename to source/dnode/mnode/impl/src/mndSync.c index 6e4084ffa6..4ba0c7dc27 100644 --- a/source/dnode/mnode/impl/src/mnodeSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -15,8 +15,8 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" -#include "mnodeTrans.h" +#include "mndInt.h" +#include "mndTrans.h" int32_t mnodeInitSync() { return 0; } void mnodeCleanUpSync() {} diff --git a/source/dnode/mnode/impl/src/mnodeTelem.c b/source/dnode/mnode/impl/src/mndTelem.c similarity index 99% rename from source/dnode/mnode/impl/src/mnodeTelem.c rename to source/dnode/mnode/impl/src/mndTelem.c index 206b94a6c7..50934f05e4 100644 --- a/source/dnode/mnode/impl/src/mnodeTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -14,10 +14,10 @@ */ #define _DEFAULT_SOURCE -#include "mnodeTelem.h" +#include "mndTelem.h" #include "tbuffer.h" #include "tglobal.h" -#include "mnodeSync.h" +#include "mndSync.h" #define TELEMETRY_SERVER "telemetry.taosdata.com" #define TELEMETRY_PORT 80 diff --git a/source/dnode/mnode/impl/src/mnodeTrans.c b/source/dnode/mnode/impl/src/mndTrans.c similarity index 99% rename from source/dnode/mnode/impl/src/mnodeTrans.c rename to source/dnode/mnode/impl/src/mndTrans.c index 4cd6bf7bdb..2ea889903e 100644 --- a/source/dnode/mnode/impl/src/mnodeTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "mnodeTrans.h" +#include "mndTrans.h" #include "trpc.h" #define SDB_TRANS_VER 1 diff --git a/source/dnode/mnode/impl/src/mnodeUser.c b/source/dnode/mnode/impl/src/mndUser.c similarity index 99% rename from source/dnode/mnode/impl/src/mnodeUser.c rename to source/dnode/mnode/impl/src/mndUser.c index e67fedd5eb..e8cc6df378 100644 --- a/source/dnode/mnode/impl/src/mnodeUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -14,11 +14,11 @@ */ #define _DEFAULT_SOURCE -#include "mnodeSync.h" +#include "mndSync.h" #include "os.h" #include "tglobal.h" #include "tkey.h" -#include "mnodeTrans.h" +#include "mndTrans.h" #define SDB_USER_VER 1 diff --git a/source/dnode/mnode/impl/src/mnodeVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c similarity index 97% rename from source/dnode/mnode/impl/src/mnodeVgroup.c rename to source/dnode/mnode/impl/src/mndVgroup.c index 6f9df1f69f..134603ce27 100644 --- a/source/dnode/mnode/impl/src/mnodeVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "mnodeInt.h" +#include "mndInt.h" int32_t mnodeInitVgroup() { return 0; } void mnodeCleanupVgroup() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 6ea47b41fc..30eb85b9d1 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -17,23 +17,23 @@ #include "os.h" #include "tglobal.h" #include "tqueue.h" -#include "mnodeAcct.h" -#include "mnodeAuth.h" -#include "mnodeBalance.h" -#include "mnodeCluster.h" -#include "mnodeDb.h" -#include "mnodeDnode.h" -#include "mnodeFunc.h" -#include "mnodeMnode.h" -#include "mnodeOper.h" -#include "mnodeProfile.h" -#include "mnodeShow.h" -#include "mnodeStable.h" -#include "mnodeSync.h" -#include "mnodeTelem.h" -#include "mnodeTrans.h" -#include "mnodeUser.h" -#include "mnodeVgroup.h" +#include "mndAcct.h" +#include "mndAuth.h" +#include "mndBalance.h" +#include "mndCluster.h" +#include "mndDb.h" +#include "mndDnode.h" +#include "mndFunc.h" +#include "mndMnode.h" +#include "mndOper.h" +#include "mndProfile.h" +#include "mndShow.h" +#include "mndStable.h" +#include "mndSync.h" +#include "mndTelem.h" +#include "mndTrans.h" +#include "mndUser.h" +#include "mndVgroup.h" SMnodeBak tsMint = {0}; From a17d9811795303e77c0ec5d2b0e12a04b0f258e5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Nov 2021 23:02:20 +0800 Subject: [PATCH 05/18] rename some defs --- include/dnode/mnode/mnode.h | 6 +- source/dnode/mnode/impl/inc/mndAcct.h | 6 +- source/dnode/mnode/impl/inc/mndAuth.h | 6 +- source/dnode/mnode/impl/inc/mndBalance.h | 6 +- source/dnode/mnode/impl/inc/mndCluster.h | 6 +- source/dnode/mnode/impl/inc/mndDb.h | 6 +- source/dnode/mnode/impl/inc/mndDef.h | 6 +- source/dnode/mnode/impl/inc/mndDnode.h | 6 +- source/dnode/mnode/impl/inc/mndFunc.h | 6 +- source/dnode/mnode/impl/inc/mndInt.h | 6 +- source/dnode/mnode/impl/inc/mndMnode.h | 6 +- source/dnode/mnode/impl/inc/mndOper.h | 6 +- source/dnode/mnode/impl/inc/mndProfile.h | 6 +- source/dnode/mnode/impl/inc/mndShow.h | 6 +- source/dnode/mnode/impl/inc/mndStable.h | 6 +- source/dnode/mnode/impl/inc/mndSync.h | 6 +- source/dnode/mnode/impl/inc/mndTelem.h | 6 +- source/dnode/mnode/impl/inc/mndUser.h | 6 +- source/dnode/mnode/impl/inc/mndVgroup.h | 6 +- source/dnode/mnode/impl/inc/mnodeInt.h | 70 ++++++++++++++++++++++++ source/dnode/mnode/impl/inc/mnodeUser.h | 32 +++++++++++ 21 files changed, 159 insertions(+), 57 deletions(-) create mode 100644 source/dnode/mnode/impl/inc/mnodeInt.h create mode 100644 source/dnode/mnode/impl/inc/mnodeUser.h diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 2ffbd395e8..fa357fc814 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_H_ -#define _TD_MNODE_H_ +#ifndef _TD_MND_H_ +#define _TD_MND_H_ #ifdef __cplusplus extern "C" { @@ -170,4 +170,4 @@ void mnodeProcessApplyMsg(SMnodeMsg *pMsg); } #endif -#endif /*_TD_MNODE_H_*/ +#endif /*_TD_MND_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndAcct.h b/source/dnode/mnode/impl/inc/mndAcct.h index a45d865c03..e52739104c 100644 --- a/source/dnode/mnode/impl/inc/mndAcct.h +++ b/source/dnode/mnode/impl/inc/mndAcct.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_ACCT_H_ -#define _TD_MNODE_ACCT_H_ +#ifndef _TD_MND_ACCT_H_ +#define _TD_MND_ACCT_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupAcct(); } #endif -#endif /*_TD_MNODE_ACCT_H_*/ +#endif /*_TD_MND_ACCT_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndAuth.h b/source/dnode/mnode/impl/inc/mndAuth.h index a759e0169e..cba1682fa5 100644 --- a/source/dnode/mnode/impl/inc/mndAuth.h +++ b/source/dnode/mnode/impl/inc/mndAuth.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_AUTH_H_ -#define _TD_MNODE_AUTH_H_ +#ifndef _TD_MND_AUTH_H_ +#define _TD_MND_AUTH_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupAuth(); } #endif -#endif /*_TD_MNODE_AUTH_H_*/ +#endif /*_TD_MND_AUTH_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndBalance.h b/source/dnode/mnode/impl/inc/mndBalance.h index 84de9bcb32..3ec572d32e 100644 --- a/source/dnode/mnode/impl/inc/mndBalance.h +++ b/source/dnode/mnode/impl/inc/mndBalance.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_BALANCE_H_ -#define _TD_MNODE_BALANCE_H_ +#ifndef _TD_MND_BALANCE_H_ +#define _TD_MND_BALANCE_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupBalance(); } #endif -#endif /*_TD_MNODE_BALANCE_H_*/ +#endif /*_TD_MND_BALANCE_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h index f9047e6e25..cb01a9e414 100644 --- a/source/dnode/mnode/impl/inc/mndCluster.h +++ b/source/dnode/mnode/impl/inc/mndCluster.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_CLUSTER_H_ -#define _TD_MNODE_CLUSTER_H_ +#ifndef _TD_MND_CLUSTER_H_ +#define _TD_MND_CLUSTER_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupCluster(); } #endif -#endif /*_TD_MNODE_CLUSTER_H_*/ +#endif /*_TD_MND_CLUSTER_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndDb.h b/source/dnode/mnode/impl/inc/mndDb.h index 1ab4844873..d694badb54 100644 --- a/source/dnode/mnode/impl/inc/mndDb.h +++ b/source/dnode/mnode/impl/inc/mndDb.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_DATABASE_H_ -#define _TD_MNODE_DATABASE_H_ +#ifndef _TD_MND_DATABASE_H_ +#define _TD_MND_DATABASE_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupDb(); } #endif -#endif /*_TD_MNODE_DATABASE_H_*/ +#endif /*_TD_MND_DATABASE_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index ccdba13006..baed0b44e4 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_DEF_H_ -#define _TD_MNODE_DEF_H_ +#ifndef _TD_MND_DEF_H_ +#define _TD_MND_DEF_H_ #include "os.h" #include "taosmsg.h" @@ -305,4 +305,4 @@ typedef struct SMnodeMsg { } #endif -#endif /*_TD_MNODE_DEF_H_*/ +#endif /*_TD_MND_DEF_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndDnode.h b/source/dnode/mnode/impl/inc/mndDnode.h index 7b25061b95..5babb99a42 100644 --- a/source/dnode/mnode/impl/inc/mndDnode.h +++ b/source/dnode/mnode/impl/inc/mndDnode.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_DNODE_H_ -#define _TD_MNODE_DNODE_H_ +#ifndef _TD_MND_DNODE_H_ +#define _TD_MND_DNODE_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupDnode(); } #endif -#endif /*_TD_MNODE_DNODE_H_*/ +#endif /*_TD_MND_DNODE_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndFunc.h b/source/dnode/mnode/impl/inc/mndFunc.h index ff1ebde8b0..22ee7018f2 100644 --- a/source/dnode/mnode/impl/inc/mndFunc.h +++ b/source/dnode/mnode/impl/inc/mndFunc.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_FUNC_H_ -#define _TD_MNODE_FUNC_H_ +#ifndef _TD_MND_FUNC_H_ +#define _TD_MND_FUNC_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupFunc(); } #endif -#endif /*_TD_MNODE_FUNC_H_*/ +#endif /*_TD_MND_FUNC_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 17db21fe18..62f591a26e 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_INT_H_ -#define _TD_MNODE_INT_H_ +#ifndef _TD_MND_INT_H_ +#define _TD_MND_INT_H_ #include "mndDef.h" #include "sdb.h" @@ -67,4 +67,4 @@ void mnodeSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp); } #endif -#endif /*_TD_MNODE_INT_H_*/ +#endif /*_TD_MND_INT_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h index 9e7f1766a6..4c20cbf833 100644 --- a/source/dnode/mnode/impl/inc/mndMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_MNODE_H_ -#define _TD_MNODE_MNODE_H_ +#ifndef _TD_MND_MNODE_H_ +#define _TD_MND_MNODE_H_ #include "mndInt.h" @@ -31,4 +31,4 @@ void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect); } #endif -#endif /*_TD_MNODE_MNODE_H_*/ +#endif /*_TD_MND_MNODE_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndOper.h b/source/dnode/mnode/impl/inc/mndOper.h index 4392422b23..7ab396a019 100644 --- a/source/dnode/mnode/impl/inc/mndOper.h +++ b/source/dnode/mnode/impl/inc/mndOper.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_OPER_H_ -#define _TD_MNODE_OPER_H_ +#ifndef _TD_MND_OPER_H_ +#define _TD_MND_OPER_H_ #ifdef __cplusplus extern "C" { @@ -27,4 +27,4 @@ void mnodeCleanupOper(); } #endif -#endif /*_TD_MNODE_OPER_H_*/ +#endif /*_TD_MND_OPER_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndProfile.h b/source/dnode/mnode/impl/inc/mndProfile.h index 405a6f8dac..d2b402227b 100644 --- a/source/dnode/mnode/impl/inc/mndProfile.h +++ b/source/dnode/mnode/impl/inc/mndProfile.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_PROFILE_H_ -#define _TD_MNODE_PROFILE_H_ +#ifndef _TD_MND_PROFILE_H_ +#define _TD_MND_PROFILE_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupProfile(); } #endif -#endif /*_TD_MNODE_PROFILE_H_*/ +#endif /*_TD_MND_PROFILE_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndShow.h b/source/dnode/mnode/impl/inc/mndShow.h index 5045fde1a8..cc3bd55cf4 100644 --- a/source/dnode/mnode/impl/inc/mndShow.h +++ b/source/dnode/mnode/impl/inc/mndShow.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_SHOW_H_ -#define _TD_MNODE_SHOW_H_ +#ifndef _TD_MND_SHOW_H_ +#define _TD_MND_SHOW_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanUpShow(); } #endif -#endif /*_TD_MNODE_SHOW_H_*/ +#endif /*_TD_MND_SHOW_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndStable.h b/source/dnode/mnode/impl/inc/mndStable.h index f55d7737de..b2469aaaa8 100644 --- a/source/dnode/mnode/impl/inc/mndStable.h +++ b/source/dnode/mnode/impl/inc/mndStable.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_STABLE_H_ -#define _TD_MNODE_STABLE_H_ +#ifndef _TD_MND_STABLE_H_ +#define _TD_MND_STABLE_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupStable(); } #endif -#endif /*_TD_MNODE_STABLE_H_*/ +#endif /*_TD_MND_STABLE_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndSync.h b/source/dnode/mnode/impl/inc/mndSync.h index 8877bc9c82..863aaccf0c 100644 --- a/source/dnode/mnode/impl/inc/mndSync.h +++ b/source/dnode/mnode/impl/inc/mndSync.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_SYNC_H_ -#define _TD_MNODE_SYNC_H_ +#ifndef _TD_MND_SYNC_H_ +#define _TD_MND_SYNC_H_ #include "mndInt.h" @@ -32,4 +32,4 @@ bool mnodeIsMaster(); } #endif -#endif /*_TD_MNODE_SYNC_H_*/ +#endif /*_TD_MND_SYNC_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndTelem.h b/source/dnode/mnode/impl/inc/mndTelem.h index bb2e6635b1..f2a11a3d32 100644 --- a/source/dnode/mnode/impl/inc/mndTelem.h +++ b/source/dnode/mnode/impl/inc/mndTelem.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_TELEMETRY_H_ -#define _TD_MNODE_TELEMETRY_H_ +#ifndef _TD_MND_TELEMETRY_H_ +#define _TD_MND_TELEMETRY_H_ #ifdef __cplusplus extern "C" { @@ -28,4 +28,4 @@ void mnodeCleanupTelem(); } #endif -#endif /*_TD_MNODE_TELEMETRY_H_*/ +#endif /*_TD_MND_TELEMETRY_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndUser.h b/source/dnode/mnode/impl/inc/mndUser.h index 47fc32c634..adc7a0db13 100644 --- a/source/dnode/mnode/impl/inc/mndUser.h +++ b/source/dnode/mnode/impl/inc/mndUser.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_USER_H_ -#define _TD_MNODE_USER_H_ +#ifndef _TD_MND_USER_H_ +#define _TD_MND_USER_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupUser(); } #endif -#endif /*_TD_MNODE_USER_H_*/ +#endif /*_TD_MND_USER_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index d6e5e00ba8..18c2ea7ecf 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_MNODE_VGROUP_H_ -#define _TD_MNODE_VGROUP_H_ +#ifndef _TD_MND_VGROUP_H_ +#define _TD_MND_VGROUP_H_ #include "mndInt.h" @@ -29,4 +29,4 @@ void mnodeCleanupVgroup(); } #endif -#endif /*_TD_MNODE_VGROUP_H_*/ +#endif /*_TD_MND_VGROUP_H_*/ diff --git a/source/dnode/mnode/impl/inc/mnodeInt.h b/source/dnode/mnode/impl/inc/mnodeInt.h new file mode 100644 index 0000000000..62f591a26e --- /dev/null +++ b/source/dnode/mnode/impl/inc/mnodeInt.h @@ -0,0 +1,70 @@ +/* + * 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_MND_INT_H_ +#define _TD_MND_INT_H_ + +#include "mndDef.h" +#include "sdb.h" +#include "tstep.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef int32_t (*MndMsgFp)(SMnode *pMnode, SMnodeMsg *pMsg); + +typedef struct SMnodeBak { + int32_t dnodeId; + int64_t clusterId; + tmr_h timer; + SSteps *pInitSteps; + SSteps *pStartSteps; + SMnodeOpt para; + MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; +} SMnodeBak; + +typedef struct SMnode { + int32_t dnodeId; + int64_t clusterId; + int8_t replica; + int8_t selfIndex; + SReplica replicas[TSDB_MAX_REPLICA]; + tmr_h timer; + SSteps *pInitSteps; + SSteps *pStartSteps; + struct SSdb *pSdb; + struct SDnode *pServer; + MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; + PutMsgToMnodeQFp putMsgToApplyMsgFp; + SendMsgToDnodeFp sendMsgToDnodeFp; + SendMsgToMnodeFp sendMsgToMnodeFp; + SendRedirectMsgFp sendRedirectMsgFp; +} SMnode; + +tmr_h mnodeGetTimer(); +int32_t mnodeGetDnodeId(); +int64_t mnodeGetClusterId(); + +void mnodeSendMsgToDnode(SMnode *pMnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg); +void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell); +void mnodeSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_INT_H_*/ diff --git a/source/dnode/mnode/impl/inc/mnodeUser.h b/source/dnode/mnode/impl/inc/mnodeUser.h new file mode 100644 index 0000000000..adc7a0db13 --- /dev/null +++ b/source/dnode/mnode/impl/inc/mnodeUser.h @@ -0,0 +1,32 @@ +/* + * 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_MND_USER_H_ +#define _TD_MND_USER_H_ + +#include "mndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t mnodeInitUser(); +void mnodeCleanupUser(); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_MND_USER_H_*/ From 32ac2d02c87d7f5ba46db2204fa4f78289b199ae Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 29 Nov 2021 10:54:49 +0800 Subject: [PATCH 06/18] update fst core struct --- source/libs/index/inc/index_fst.h | 4 +++ source/libs/index/inc/index_fst_node.h | 2 +- source/libs/index/src/index_fst.c | 5 +++ source/libs/index/src/index_fst_node.c | 43 +++++++++++++------------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 37feb79ac8..01be2f8b2b 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -255,4 +255,8 @@ FstType fstGetType(Fst *fst); CompiledAddr fstGetRootAddr(Fst *fst); Output fstEmptyFinalOutput(Fst *fst, bool *null); bool fstVerify(Fst *fst); + + +//refactor this function +bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); #endif diff --git a/source/libs/index/inc/index_fst_node.h b/source/libs/index/inc/index_fst_node.h index ddd7e1f450..0645aa1158 100644 --- a/source/libs/index/inc/index_fst_node.h +++ b/source/libs/index/inc/index_fst_node.h @@ -41,7 +41,7 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src); void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src); -bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); +//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); void fstBuilderNodeDestroy(FstBuilderNode *node); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 6c1ea8cfeb..f9cb68baa9 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -733,6 +733,11 @@ bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr return true; } +bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) { + return fstNodeCompile(NULL, wrt, lastAddr, startAddr, b); +} + + FstBuilder *fstBuilderCreate(void *w, FstType ty) { FstBuilder *b = malloc(sizeof(FstBuilder)); diff --git a/source/libs/index/src/index_fst_node.c b/source/libs/index/src/index_fst_node.c index 5452f9cb89..b33b8e4428 100644 --- a/source/libs/index/src/index_fst_node.c +++ b/source/libs/index/src/index_fst_node.c @@ -59,26 +59,27 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) { src->trans = NULL; } -bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) { - size_t sz = taosArrayGetSize(b->trans); - assert(sz < 256); - if (FST_BUILDER_NODE_IS_FINAL(b) - && FST_BUILDER_NODE_TRANS_ISEMPTY(b) - && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) { - return true; - } else if (sz != 1 || b->isFinal) { - // AnyTrans->Compile(w, addr, node); - } else { - FstTransition *tran = taosArrayGet(b->trans, 0); - if (tran->addr == lastAddr && tran->out == 0) { - //OneTransNext::compile(w, lastAddr, tran->inp); - return true; - } else { - //OneTrans::Compile(w, lastAddr, *tran); - return true; - } - } - return true; -} +//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) { + + //size_t sz = taosArrayGetSize(b->trans); + //assert(sz < 256); + //if (FST_BUILDER_NODE_IS_FINAL(b) + // && FST_BUILDER_NODE_TRANS_ISEMPTY(b) + // && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) { + // return true; + //} else if (sz != 1 || b->isFinal) { + // // AnyTrans->Compile(w, addr, node); + //} else { + // FstTransition *tran = taosArrayGet(b->trans, 0); + // if (tran->addr == lastAddr && tran->out == 0) { + // //OneTransNext::compile(w, lastAddr, tran->inp); + // return true; + // } else { + // //OneTrans::Compile(w, lastAddr, *tran); + // return true; + // } + //} + //return true; +//} From a09dcbdd85fd343f49963d561bc3c805bd2479d4 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 29 Nov 2021 10:59:51 +0800 Subject: [PATCH 07/18] update fst core struct --- source/libs/index/src/index_fst.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index f9cb68baa9..1ee364d4ad 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -1026,10 +1026,10 @@ bool fstVerify(Fst *fst) { uint32_t checkSum = fst->meta->checkSum; FstSlice *data = fst->data; TSCKSUM initSum = 0; - if (taosCheckChecksumWhole(data->data, data->dLen)) { + if (!taosCheckChecksumWhole(data->data, data->dLen)) { return false; } - + return true; } From 6ee8832271103f33baa7f6759661283cd87eec88 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 12:09:18 +0800 Subject: [PATCH 08/18] TD-10431 fix compile errors in mnode --- include/dnode/mnode/mnode.h | 28 +-- source/dnode/mgmt/impl/src/dndMnode.c | 45 ++-- source/dnode/mnode/impl/inc/mndAcct.h | 4 +- source/dnode/mnode/impl/inc/mndAuth.h | 4 +- source/dnode/mnode/impl/inc/mndBalance.h | 4 +- source/dnode/mnode/impl/inc/mndCluster.h | 4 +- source/dnode/mnode/impl/inc/mndDb.h | 4 +- source/dnode/mnode/impl/inc/mndDef.h | 96 ++++--- source/dnode/mnode/impl/inc/mndDnode.h | 4 +- source/dnode/mnode/impl/inc/mndFunc.h | 4 +- source/dnode/mnode/impl/inc/mndInt.h | 41 ++- source/dnode/mnode/impl/inc/mndMnode.h | 4 +- source/dnode/mnode/impl/inc/mndOper.h | 4 +- source/dnode/mnode/impl/inc/mndProfile.h | 4 +- source/dnode/mnode/impl/inc/mndShow.h | 4 +- source/dnode/mnode/impl/inc/mndStable.h | 4 +- source/dnode/mnode/impl/inc/mndSync.h | 4 +- source/dnode/mnode/impl/inc/mndTelem.h | 4 +- source/dnode/mnode/impl/inc/mndTrans.h | 4 +- source/dnode/mnode/impl/inc/mndUser.h | 4 +- source/dnode/mnode/impl/inc/mndVgroup.h | 4 +- source/dnode/mnode/impl/inc/mnodeInt.h | 70 ------ source/dnode/mnode/impl/inc/mnodeUser.h | 32 --- source/dnode/mnode/impl/src/mndAcct.c | 4 +- source/dnode/mnode/impl/src/mndAuth.c | 6 +- source/dnode/mnode/impl/src/mndBalance.c | 4 +- source/dnode/mnode/impl/src/mndCluster.c | 4 +- source/dnode/mnode/impl/src/mndDb.c | 4 +- source/dnode/mnode/impl/src/mndDnode.c | 4 +- source/dnode/mnode/impl/src/mndFunc.c | 4 +- source/dnode/mnode/impl/src/mndMnode.c | 4 +- source/dnode/mnode/impl/src/mndOper.c | 4 +- source/dnode/mnode/impl/src/mndProfile.c | 4 +- source/dnode/mnode/impl/src/mndShow.c | 4 +- source/dnode/mnode/impl/src/mndStable.c | 4 +- source/dnode/mnode/impl/src/mndSync.c | 4 +- source/dnode/mnode/impl/src/mndTelem.c | 8 +- source/dnode/mnode/impl/src/mndTrans.c | 4 +- source/dnode/mnode/impl/src/mndUser.c | 6 +- source/dnode/mnode/impl/src/mndVgroup.c | 4 +- source/dnode/mnode/impl/src/mnode.c | 307 ++++++++++++++--------- 41 files changed, 364 insertions(+), 399 deletions(-) delete mode 100644 source/dnode/mnode/impl/inc/mnodeInt.h delete mode 100644 source/dnode/mnode/impl/inc/mnodeUser.h diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index fa357fc814..9d4c27a9dc 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -48,7 +48,7 @@ typedef struct { int8_t replica; int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; - struct SDnode *pDnode; + SDnode *pDnode; PutMsgToMnodeQFp putMsgToApplyMsgFp; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; @@ -63,14 +63,14 @@ typedef struct { * @param pOption Option of the mnode * @return SMnode* The mnode object */ -SMnode *mnodeOpen(const char *path, const SMnodeOpt *pOption); +SMnode *mndOpen(const char *path, const SMnodeOpt *pOption); /** * @brief Close a mnode * * @param pMnode The mnode object to close */ -void mnodeClose(SMnode *pMnode); +void mndClose(SMnode *pMnode); /** * @brief Close a mnode @@ -79,14 +79,14 @@ void mnodeClose(SMnode *pMnode); * @param pOption Options of the mnode * @return int32_t 0 for success, -1 for failure */ -int32_t mnodeAlter(SMnode *pMnode, const SMnodeOpt *pOption); +int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); /** * @brief Drop a mnode. * * @param path Path of the mnode. */ -void mnodeDestroy(const char *path); +void mndDestroy(const char *path); /** * @brief Get mnode statistics info @@ -95,7 +95,7 @@ void mnodeDestroy(const char *path); * @param pLoad Statistics of the mnode. * @return int32_t 0 for success, -1 for failure */ -int32_t mnodeGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); +int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); /** * @brief Get user authentication info @@ -108,7 +108,7 @@ int32_t mnodeGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); * @param ckey * @return int32_t 0 for success, -1 for failure */ -int32_t mnodeRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey); +int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey); /** * @brief Initialize mnode msg @@ -117,14 +117,14 @@ int32_t mnodeRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, c * @param pMsg The request rpc msg * @return int32_t The created mnode msg */ -SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg); +SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg); /** * @brief Cleanup mnode msg * * @param pMsg The request msg */ -void mnodeCleanupMsg(SMnodeMsg *pMsg); +void mndCleanupMsg(SMnodeMsg *pMsg); /** * @brief Cleanup mnode msg @@ -132,7 +132,7 @@ void mnodeCleanupMsg(SMnodeMsg *pMsg); * @param pMsg The request msg * @param code The error code */ -void mnodeSendRsp(SMnodeMsg *pMsg, int32_t code); +void mndSendRsp(SMnodeMsg *pMsg, int32_t code); /** * @brief Process the read request @@ -140,7 +140,7 @@ void mnodeSendRsp(SMnodeMsg *pMsg, int32_t code); * @param pMsg The request msg * @return int32_t 0 for success, -1 for failure */ -void mnodeProcessReadMsg(SMnodeMsg *pMsg); +void mndProcessReadMsg(SMnodeMsg *pMsg); /** * @brief Process the write request @@ -148,7 +148,7 @@ void mnodeProcessReadMsg(SMnodeMsg *pMsg); * @param pMsg The request msg * @return int32_t 0 for success, -1 for failure */ -void mnodeProcessWriteMsg(SMnodeMsg *pMsg); +void mndProcessWriteMsg(SMnodeMsg *pMsg); /** * @brief Process the sync request @@ -156,7 +156,7 @@ void mnodeProcessWriteMsg(SMnodeMsg *pMsg); * @param pMsg The request msg * @return int32_t 0 for success, -1 for failure */ -void mnodeProcessSyncMsg(SMnodeMsg *pMsg); +void mndProcessSyncMsg(SMnodeMsg *pMsg); /** * @brief Process the apply request @@ -164,7 +164,7 @@ void mnodeProcessSyncMsg(SMnodeMsg *pMsg); * @param pMsg The request msg * @return int32_t 0 for success, -1 for failure */ -void mnodeProcessApplyMsg(SMnodeMsg *pMsg); +void mndProcessApplyMsg(SMnodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index d42891f1e4..f2ef420cc0 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -396,7 +396,7 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) { return code; } - SMnode *pMnode = mnodeOpen(pDnode->dir.mnode, pOption); + SMnode *pMnode = mndOpen(pDnode->dir.mnode, pOption); if (pMnode == NULL) { dError("failed to open mnode since %s", terrstr()); code = terrno; @@ -409,8 +409,8 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) { dError("failed to write mnode file since %s", terrstr()); code = terrno; dndStopMnodeWorker(pDnode); - mnodeClose(pMnode); - mnodeDestroy(pDnode->dir.mnode); + mndClose(pMnode); + mndDestroy(pDnode->dir.mnode); terrno = code; return code; } @@ -432,7 +432,7 @@ static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption) { return -1; } - if (mnodeAlter(pMnode, pOption) != 0) { + if (mndAlter(pMnode, pOption) != 0) { dError("failed to alter mnode since %s", terrstr()); dndReleaseMnode(pDnode, pMnode); return -1; @@ -467,8 +467,8 @@ static int32_t dndDropMnode(SDnode *pDnode) { dndStopMnodeWorker(pDnode); dndWriteMnodeFile(pDnode); - mnodeClose(pMnode); - mnodeDestroy(pDnode->dir.mnode); + mndClose(pMnode); + mndDestroy(pDnode->dir.mnode); return 0; } @@ -495,6 +495,7 @@ static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) { return -1; } + return dndOpenMnode(pDnode, &option); } } @@ -554,13 +555,13 @@ static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mnodeProcessReadMsg(pMsg); + mndProcessReadMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { - mnodeSendRsp(pMsg, terrno); + mndSendRsp(pMsg, terrno); } - mnodeCleanupMsg(pMsg); + mndCleanupMsg(pMsg); } static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) { @@ -568,13 +569,13 @@ static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mnodeProcessWriteMsg(pMsg); + mndProcessWriteMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { - mnodeSendRsp(pMsg, terrno); + mndSendRsp(pMsg, terrno); } - mnodeCleanupMsg(pMsg); + mndCleanupMsg(pMsg); } static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { @@ -582,13 +583,13 @@ static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mnodeProcessApplyMsg(pMsg); + mndProcessApplyMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { - mnodeSendRsp(pMsg, terrno); + mndSendRsp(pMsg, terrno); } - mnodeCleanupMsg(pMsg); + mndCleanupMsg(pMsg); } static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) { @@ -596,26 +597,26 @@ static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) { SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { - mnodeProcessSyncMsg(pMsg); + mndProcessSyncMsg(pMsg); dndReleaseMnode(pDnode, pMnode); } else { - mnodeSendRsp(pMsg, terrno); + mndSendRsp(pMsg, terrno); } - mnodeCleanupMsg(pMsg); + mndCleanupMsg(pMsg); } static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMsg *pRpcMsg) { assert(pQueue); - SMnodeMsg *pMsg = mnodeInitMsg(pMnode, pRpcMsg); + SMnodeMsg *pMsg = mndInitMsg(pMnode, pRpcMsg); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } if (taosWriteQitem(pQueue, pMsg) != 0) { - mnodeCleanupMsg(pMsg); + mndCleanupMsg(pMsg); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -877,7 +878,7 @@ int32_t dndInitMnode(SDnode *pDnode) { if (pMgmt->dropped) { dInfo("mnode has been deployed and needs to be deleted"); - mnodeDestroy(pDnode->dir.mnode); + mndDestroy(pDnode->dir.mnode); return 0; } @@ -920,7 +921,7 @@ int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *enc return -1; } - int32_t code = mnodeRetriveAuth(pMnode, user, spi, encrypt, secret, ckey); + int32_t code = mndRetriveAuth(pMnode, user, spi, encrypt, secret, ckey); dndReleaseMnode(pDnode, pMnode); return code; } diff --git a/source/dnode/mnode/impl/inc/mndAcct.h b/source/dnode/mnode/impl/inc/mndAcct.h index e52739104c..3289c24110 100644 --- a/source/dnode/mnode/impl/inc/mndAcct.h +++ b/source/dnode/mnode/impl/inc/mndAcct.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitAcct(); -void mnodeCleanupAcct(); +int32_t mndInitAcct(); +void mndCleanupAcct(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndAuth.h b/source/dnode/mnode/impl/inc/mndAuth.h index cba1682fa5..3f0deeec6c 100644 --- a/source/dnode/mnode/impl/inc/mndAuth.h +++ b/source/dnode/mnode/impl/inc/mndAuth.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitAuth(); -void mnodeCleanupAuth(); +int32_t mndInitAuth(); +void mndCleanupAuth(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndBalance.h b/source/dnode/mnode/impl/inc/mndBalance.h index 3ec572d32e..66d85eb2c3 100644 --- a/source/dnode/mnode/impl/inc/mndBalance.h +++ b/source/dnode/mnode/impl/inc/mndBalance.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitBalance(); -void mnodeCleanupBalance(); +int32_t mndInitBalance(); +void mndCleanupBalance(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h index cb01a9e414..d8dba66a63 100644 --- a/source/dnode/mnode/impl/inc/mndCluster.h +++ b/source/dnode/mnode/impl/inc/mndCluster.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitCluster(); -void mnodeCleanupCluster(); +int32_t mndInitCluster(); +void mndCleanupCluster(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndDb.h b/source/dnode/mnode/impl/inc/mndDb.h index d694badb54..c9a888a115 100644 --- a/source/dnode/mnode/impl/inc/mndDb.h +++ b/source/dnode/mnode/impl/inc/mndDb.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitDb(); -void mnodeCleanupDb(); +int32_t mndInitDb(); +void mndCleanupDb(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index baed0b44e4..c0d02d3fc4 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -39,42 +39,34 @@ extern int32_t mDebugFlag; #define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }} #define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }} -// #define mLError(...) { monSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) } -// #define mLWarn(...) { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) } -// #define mLInfo(...) { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) } - -#define mLError(...) {mError(__VA_ARGS__) } -#define mLWarn(...) {mWarn(__VA_ARGS__) } -#define mLInfo(...) {mInfo(__VA_ARGS__) } - -typedef struct SClusterObj SClusterObj; -typedef struct SDnodeObj SDnodeObj; -typedef struct SMnodeObj SMnodeObj; -typedef struct SAcctObj SAcctObj; -typedef struct SUserObj SUserObj; -typedef struct SDbObj SDbObj; -typedef struct SVgObj SVgObj; -typedef struct SSTableObj SSTableObj; -typedef struct SFuncObj SFuncObj; -typedef struct SOperObj SOperObj; +typedef struct SClusterObj SClusterObj; +typedef struct SDnodeObj SDnodeObj; +typedef struct SMnodeObj SMnodeObj; +typedef struct SAcctObj SAcctObj; +typedef struct SUserObj SUserObj; +typedef struct SDbObj SDbObj; +typedef struct SVgObj SVgObj; +typedef struct SSTableObj SSTableObj; +typedef struct SFuncObj SFuncObj; +typedef struct SOperObj SOperObj; typedef enum { - MN_AUTH_ACCT_START = 0, - MN_AUTH_ACCT_USER, - MN_AUTH_ACCT_DNODE, - MN_AUTH_ACCT_MNODE, - MN_AUTH_ACCT_DB, - MN_AUTH_ACCT_TABLE, - MN_AUTH_ACCT_MAX -} EMnAuthAcct; + MND_AUTH_ACCT_START = 0, + MND_AUTH_ACCT_USER, + MND_AUTH_ACCT_DNODE, + MND_AUTH_ACCT_MNODE, + MND_AUTH_ACCT_DB, + MND_AUTH_ACCT_TABLE, + MND_AUTH_ACCT_MAX +} EAuthAcct; typedef enum { - MN_AUTH_OP_START = 0, - MN_AUTH_OP_CREATE_USER, - MN_AUTH_OP_ALTER_USER, - MN_AUTH_OP_DROP_USER, - MN_AUTH_MAX -} EMnAuthOp; + MND_AUTH_OP_START = 0, + MND_AUTH_OP_CREATE_USER, + MND_AUTH_OP_ALTER_USER, + MND_AUTH_OP_DROP_USER, + MND_AUTH_MAX +} EAuthOp; typedef enum { TRN_STAGE_PREPARE = 1, @@ -86,7 +78,6 @@ typedef enum { typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy; - typedef struct STrans { int32_t id; ETrnStage stage; @@ -99,7 +90,6 @@ typedef struct STrans { SArray *undoActions; } STrans; - typedef struct SClusterObj { int64_t id; char uid[TSDB_CLUSTER_ID_LEN]; @@ -202,6 +192,7 @@ typedef struct SDbObj { int64_t createdTime; int64_t updateTime; SDbCfg cfg; + int64_t uid; int8_t status; int32_t numOfVgroups; int32_t numOfTables; @@ -240,13 +231,13 @@ typedef struct SVgObj { } SVgObj; typedef struct SSTableObj { - char tableId[TSDB_TABLE_NAME_LEN]; - uint64_t uid; - int64_t createdTime; - int64_t updateTime; - int32_t numOfColumns; // used by normal table - int32_t numOfTags; - SSchema * schema; + char tableId[TSDB_TABLE_NAME_LEN]; + uint64_t uid; + int64_t createdTime; + int64_t updateTime; + int32_t numOfColumns; // used by normal table + int32_t numOfTags; + SSchema *schema; } SSTableObj; typedef struct SFuncObj { @@ -284,21 +275,22 @@ typedef struct { typedef struct { int32_t len; void *rsp; -} SMnRsp; +} SMnodeRsp; typedef struct SMnodeMsg { + SMnode *pMnode; void (*fp)(SMnodeMsg *pMsg, int32_t code); SRpcConnInfo conn; - SUserObj *pUser; - int16_t received; - int16_t successed; - int16_t expected; - int16_t retry; - int32_t code; - int64_t createdTime; - SMnRsp rpcRsp; - SRpcMsg rpcMsg; - char pCont[]; + SUserObj *pUser; + int16_t received; + int16_t successed; + int16_t expected; + int16_t retry; + int32_t code; + int64_t createdTime; + SMnodeRsp rpcRsp; + SRpcMsg rpcMsg; + char pCont[]; } SMnodeMsg; #ifdef __cplusplus diff --git a/source/dnode/mnode/impl/inc/mndDnode.h b/source/dnode/mnode/impl/inc/mndDnode.h index 5babb99a42..0c484b0724 100644 --- a/source/dnode/mnode/impl/inc/mndDnode.h +++ b/source/dnode/mnode/impl/inc/mndDnode.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitDnode(); -void mnodeCleanupDnode(); +int32_t mndInitDnode(); +void mndCleanupDnode(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndFunc.h b/source/dnode/mnode/impl/inc/mndFunc.h index 22ee7018f2..3e17aae389 100644 --- a/source/dnode/mnode/impl/inc/mndFunc.h +++ b/source/dnode/mnode/impl/inc/mndFunc.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitFunc(); -void mnodeCleanupFunc(); +int32_t mndInitFunc(); +void mndCleanupFunc(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 62f591a26e..ac9c715adc 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -18,23 +18,21 @@ #include "mndDef.h" #include "sdb.h" -#include "tstep.h" +#include "tqueue.h" #ifdef __cplusplus extern "C" { #endif typedef int32_t (*MndMsgFp)(SMnode *pMnode, SMnodeMsg *pMsg); +typedef int32_t (*MndInitFp)(SMnode *pMnode); +typedef void (*MndCleanupFp)(SMnode *pMnode); -typedef struct SMnodeBak { - int32_t dnodeId; - int64_t clusterId; - tmr_h timer; - SSteps *pInitSteps; - SSteps *pStartSteps; - SMnodeOpt para; - MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; -} SMnodeBak; +typedef struct { + const char *name; + MndInitFp initFp; + MndCleanupFp cleanupFp; +} SMnodeStep; typedef struct SMnode { int32_t dnodeId; @@ -43,25 +41,24 @@ typedef struct SMnode { int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; tmr_h timer; - SSteps *pInitSteps; - SSteps *pStartSteps; - struct SSdb *pSdb; - struct SDnode *pServer; + SSdb *pSdb; + SDnode *pDnode; + SArray steps; MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; - PutMsgToMnodeQFp putMsgToApplyMsgFp; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; SendRedirectMsgFp sendRedirectMsgFp; + PutMsgToMnodeQFp putMsgToApplyMsgFp; } SMnode; -tmr_h mnodeGetTimer(); -int32_t mnodeGetDnodeId(); -int64_t mnodeGetClusterId(); +tmr_h mndGetTimer(SMnode *pMnode); +int32_t mndGetDnodeId(SMnode *pMnode); +int64_t mndGetClusterId(SMnode *pMnode); -void mnodeSendMsgToDnode(SMnode *pMnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg); -void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell); -void mnodeSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp); +void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); +void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg); +void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg); +void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h index 4c20cbf833..7e969baf37 100644 --- a/source/dnode/mnode/impl/inc/mndMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitMnode(); -void mnodeCleanupMnode(); +int32_t mndInitMnode(); +void mndCleanupMnode(); void mnodeGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect); void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect); diff --git a/source/dnode/mnode/impl/inc/mndOper.h b/source/dnode/mnode/impl/inc/mndOper.h index 7ab396a019..d07567635d 100644 --- a/source/dnode/mnode/impl/inc/mndOper.h +++ b/source/dnode/mnode/impl/inc/mndOper.h @@ -20,8 +20,8 @@ extern "C" { #endif -int32_t mnodeInitOper(); -void mnodeCleanupOper(); +int32_t mndInitOper(); +void mndCleanupOper(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndProfile.h b/source/dnode/mnode/impl/inc/mndProfile.h index d2b402227b..4433478caa 100644 --- a/source/dnode/mnode/impl/inc/mndProfile.h +++ b/source/dnode/mnode/impl/inc/mndProfile.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitProfile(); -void mnodeCleanupProfile(); +int32_t mndInitProfile(); +void mndCleanupProfile(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndShow.h b/source/dnode/mnode/impl/inc/mndShow.h index cc3bd55cf4..2161c81b74 100644 --- a/source/dnode/mnode/impl/inc/mndShow.h +++ b/source/dnode/mnode/impl/inc/mndShow.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitShow(); -void mnodeCleanUpShow(); +int32_t mndInitShow(); +void mndCleanupShow(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndStable.h b/source/dnode/mnode/impl/inc/mndStable.h index b2469aaaa8..429f4d947a 100644 --- a/source/dnode/mnode/impl/inc/mndStable.h +++ b/source/dnode/mnode/impl/inc/mndStable.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitStable(); -void mnodeCleanupStable(); +int32_t mndInitStable(); +void mndCleanupStable(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndSync.h b/source/dnode/mnode/impl/inc/mndSync.h index 863aaccf0c..7d7f9d69d0 100644 --- a/source/dnode/mnode/impl/inc/mndSync.h +++ b/source/dnode/mnode/impl/inc/mndSync.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitSync(); -void mnodeCleanUpSync(); +int32_t mndInitSync(); +void mndCleanupSync(); int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData); bool mnodeIsMaster(); diff --git a/source/dnode/mnode/impl/inc/mndTelem.h b/source/dnode/mnode/impl/inc/mndTelem.h index f2a11a3d32..ccee629aad 100644 --- a/source/dnode/mnode/impl/inc/mndTelem.h +++ b/source/dnode/mnode/impl/inc/mndTelem.h @@ -21,8 +21,8 @@ extern "C" { #endif #include "mndInt.h" -int32_t mnodeInitTelem(); -void mnodeCleanupTelem(); +int32_t mndInitTelem(); +void mndCleanupTelem(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index ba6b9fff79..42a5c391b4 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitTrans(); -void mnodeCleanupTrans(); +int32_t mndInitTrans(); +void mndCleanupTrans(); STrans *trnCreate(ETrnPolicy policy, void *rpcHandle); void trnDrop(STrans *pTrans); diff --git a/source/dnode/mnode/impl/inc/mndUser.h b/source/dnode/mnode/impl/inc/mndUser.h index adc7a0db13..19554ccd37 100644 --- a/source/dnode/mnode/impl/inc/mndUser.h +++ b/source/dnode/mnode/impl/inc/mndUser.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitUser(); -void mnodeCleanupUser(); +int32_t mndInitUser(); +void mndCleanupUser(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index 18c2ea7ecf..bf2cb60092 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mnodeInitVgroup(); -void mnodeCleanupVgroup(); +int32_t mndInitVgroup(); +void mndCleanupVgroup(); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mnodeInt.h b/source/dnode/mnode/impl/inc/mnodeInt.h deleted file mode 100644 index 62f591a26e..0000000000 --- a/source/dnode/mnode/impl/inc/mnodeInt.h +++ /dev/null @@ -1,70 +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_MND_INT_H_ -#define _TD_MND_INT_H_ - -#include "mndDef.h" -#include "sdb.h" -#include "tstep.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef int32_t (*MndMsgFp)(SMnode *pMnode, SMnodeMsg *pMsg); - -typedef struct SMnodeBak { - int32_t dnodeId; - int64_t clusterId; - tmr_h timer; - SSteps *pInitSteps; - SSteps *pStartSteps; - SMnodeOpt para; - MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; -} SMnodeBak; - -typedef struct SMnode { - int32_t dnodeId; - int64_t clusterId; - int8_t replica; - int8_t selfIndex; - SReplica replicas[TSDB_MAX_REPLICA]; - tmr_h timer; - SSteps *pInitSteps; - SSteps *pStartSteps; - struct SSdb *pSdb; - struct SDnode *pServer; - MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; - PutMsgToMnodeQFp putMsgToApplyMsgFp; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; -} SMnode; - -tmr_h mnodeGetTimer(); -int32_t mnodeGetDnodeId(); -int64_t mnodeGetClusterId(); - -void mnodeSendMsgToDnode(SMnode *pMnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg); -void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell); -void mnodeSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_MND_INT_H_*/ diff --git a/source/dnode/mnode/impl/inc/mnodeUser.h b/source/dnode/mnode/impl/inc/mnodeUser.h deleted file mode 100644 index adc7a0db13..0000000000 --- a/source/dnode/mnode/impl/inc/mnodeUser.h +++ /dev/null @@ -1,32 +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_MND_USER_H_ -#define _TD_MND_USER_H_ - -#include "mndInt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t mnodeInitUser(); -void mnodeCleanupUser(); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_MND_USER_H_*/ diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index b503a27b11..c8087dbc2d 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -101,7 +101,7 @@ static int32_t mnodeCreateDefaultAcct() { return sdbWrite(pRaw); } -int32_t mnodeInitAcct() { +int32_t mndInitAcct() { SSdbTable table = {.sdbType = SDB_ACCT, .keyType = SDB_KEY_BINARY, .deployFp = (SdbDeployFp)mnodeCreateDefaultAcct, @@ -115,4 +115,4 @@ int32_t mnodeInitAcct() { return 0; } -void mnodeCleanupAcct() {} +void mndCleanupAcct() {} diff --git a/source/dnode/mnode/impl/src/mndAuth.c b/source/dnode/mnode/impl/src/mndAuth.c index bb50645cee..d37c7bd4da 100644 --- a/source/dnode/mnode/impl/src/mndAuth.c +++ b/source/dnode/mnode/impl/src/mndAuth.c @@ -17,9 +17,9 @@ #include "os.h" #include "mndAuth.h" -int32_t mnodeInitAuth() { return 0; } -void mnodeCleanupAuth() {} +int32_t mndInitAuth() { return 0; } +void mndCleanupAuth() {} -int32_t mnodeRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { +int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { return 0; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndBalance.c b/source/dnode/mnode/impl/src/mndBalance.c index f3acb9b4b3..7b919af3f8 100644 --- a/source/dnode/mnode/impl/src/mndBalance.c +++ b/source/dnode/mnode/impl/src/mndBalance.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitBalance() { return 0; } -void mnodeCleanupBalance() {} \ No newline at end of file +int32_t mndInitBalance() { return 0; } +void mndCleanupBalance() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index f1dbe1df7d..f926959b9f 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitCluster() { return 0; } -void mnodeCleanupCluster() {} \ No newline at end of file +int32_t mndInitCluster() { return 0; } +void mndCleanupCluster() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index c8aa347c7b..4c0e54f436 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitDb() { return 0; } -void mnodeCleanupDb() {} \ No newline at end of file +int32_t mndInitDb() { return 0; } +void mndCleanupDb() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 61cd4c01bc..f9329e871f 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitDnode() { return 0; } -void mnodeCleanupDnode() {} \ No newline at end of file +int32_t mndInitDnode() { return 0; } +void mndCleanupDnode() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 19a8b8dd0e..a84178ea6e 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitFunc() { return 0; } -void mnodeCleanupFunc() {} \ No newline at end of file +int32_t mndInitFunc() { return 0; } +void mndCleanupFunc() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index da4d77b440..ce38049a36 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -17,8 +17,8 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitMnode() { return 0; } -void mnodeCleanupMnode() {} +int32_t mndInitMnode() { return 0; } +void mndCleanupMnode() {} void mnodeGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {} void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndOper.c b/source/dnode/mnode/impl/src/mndOper.c index d25748882a..aa3a1d5e25 100644 --- a/source/dnode/mnode/impl/src/mndOper.c +++ b/source/dnode/mnode/impl/src/mndOper.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitOper() { return 0; } -void mnodeCleanupOper() {} \ No newline at end of file +int32_t mndInitOper() { return 0; } +void mndCleanupOper() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 64378b0093..7c86778eb4 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitProfile() { return 0; } -void mnodeCleanupProfile() {} \ No newline at end of file +int32_t mndInitProfile() { return 0; } +void mndCleanupProfile() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 338c199afc..3f97470fd4 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitShow() { return 0; } -void mnodeCleanUpShow() {} \ No newline at end of file +int32_t mndInitShow() { return 0; } +void mndCleanupShow() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndStable.c b/source/dnode/mnode/impl/src/mndStable.c index fe0fc59d25..0a8320c9fa 100644 --- a/source/dnode/mnode/impl/src/mndStable.c +++ b/source/dnode/mnode/impl/src/mndStable.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitStable() { return 0; } -void mnodeCleanupStable() {} \ No newline at end of file +int32_t mndInitStable() { return 0; } +void mndCleanupStable() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 4ba0c7dc27..8db79e1e32 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -18,8 +18,8 @@ #include "mndInt.h" #include "mndTrans.h" -int32_t mnodeInitSync() { return 0; } -void mnodeCleanUpSync() {} +int32_t mndInitSync() { return 0; } +void mndCleanupSync() {} int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData) { trnApply(pData, pData, 0); diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index 50934f05e4..e9748ec12e 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -174,7 +174,7 @@ static void mnodeAddVersionInfo(SBufferWriter* bw) { static void mnodeAddRuntimeInfo(SBufferWriter* bw) { SMnodeLoad load = {0}; - if (mnodeGetLoad(NULL, &load) != 0) { + if (mndGetLoad(NULL, &load) != 0) { return; } @@ -203,7 +203,7 @@ static void mnodeSendTelemetryReport() { return; } - int64_t clusterId = mnodeGetClusterId(); + int64_t clusterId = mndGetClusterId(NULL); char clusterIdStr[20] = {0}; snprintf(clusterIdStr, sizeof(clusterIdStr), "%" PRId64, clusterId); @@ -278,7 +278,7 @@ static void mnodeGetEmail(char* filepath) { taosCloseFile(fd); } -int32_t mnodeInitTelem() { +int32_t mndInitTelem() { tsTelem.enable = tsEnableTelemetryReporting; if (!tsTelem.enable) return 0; @@ -303,7 +303,7 @@ int32_t mnodeInitTelem() { return 0; } -void mnodeCleanupTelem() { +void mndCleanupTelem() { if (!tsTelem.enable) return; if (taosCheckPthreadValid(tsTelem.thread)) { diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 2ea889903e..ed5a2a7b14 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -312,7 +312,7 @@ int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { return code; } -int32_t mnodeInitTrans() { +int32_t mndInitTrans() { SSdbTable table = {.sdbType = SDB_TRANS, .keyType = SDB_KEY_INT32, .encodeFp = (SdbEncodeFp)trnActionEncode, @@ -326,7 +326,7 @@ int32_t mnodeInitTrans() { return 0; } -void mnodeCleanupTrans() { mInfo("trn module is cleaned up"); } +void mndCleanupTrans() { mInfo("trn module is cleaned up"); } int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) { diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index e8cc6df378..a51133d427 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -220,7 +220,7 @@ static int32_t mnodeProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -int32_t mnodeInitUser() { +int32_t mndInitUser() { SSdbTable table = {.sdbType = SDB_USER, .keyType = SDB_KEY_BINARY, .deployFp = (SdbDeployFp)mnodeCreateDefaultUsers, @@ -231,9 +231,9 @@ int32_t mnodeInitUser() { .deleteFp = (SdbDeleteFp)mnodeUserActionDelete}; sdbSetTable(table); - mnodeSetMsgHandle(NULL, TSDB_MSG_TYPE_CREATE_USER, mnodeProcessCreateUserMsg); + mndSetMsgHandle(NULL, TSDB_MSG_TYPE_CREATE_USER, mnodeProcessCreateUserMsg); return 0; } -void mnodeCleanupUser() {} \ No newline at end of file +void mndCleanupUser() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 134603ce27..f7af6e5fa8 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mnodeInitVgroup() { return 0; } -void mnodeCleanupVgroup() {} \ No newline at end of file +int32_t mndInitVgroup() { return 0; } +void mndCleanupVgroup() {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 30eb85b9d1..426c86f728 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -14,9 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "os.h" -#include "tglobal.h" -#include "tqueue.h" #include "mndAcct.h" #include "mndAuth.h" #include "mndBalance.h" @@ -35,55 +32,70 @@ #include "mndUser.h" #include "mndVgroup.h" -SMnodeBak tsMint = {0}; - -int32_t mnodeGetDnodeId() { return tsMint.para.dnodeId; } - -int64_t mnodeGetClusterId() { return tsMint.para.clusterId; } - -void mnodeSendMsgToDnode(SMnode *pMnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg) { - assert(pMnode); - (*pMnode->sendMsgToDnodeFp)(pMnode->pServer, epSet, rpcMsg); +int32_t mndGetDnodeId(SMnode *pMnode) { + if (pMnode != NULL) { + return pMnode->dnodeId; + } + return -1; } -void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg) { - assert(pMnode); - (*pMnode->sendMsgToMnodeFp)(pMnode->pServer, rpcMsg); +int64_t mndGetClusterId(SMnode *pMnode) { + if (pMnode != NULL) { + return pMnode->clusterId; + } + return -1; } -void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell) { - assert(pMnode); - (*pMnode->sendRedirectMsgFp)(pMnode->pServer, rpcMsg); +void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { + if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) { + (*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); + } } -static int32_t mnodeInitTimer() { - if (tsMint.timer == NULL) { - tsMint.timer = taosTmrInit(tsMaxShellConns, 200, 3600000, "MND"); +void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg) { + if (pMnode != NULL && pMnode->sendMsgToMnodeFp != NULL) { + (*pMnode->sendMsgToMnodeFp)(pMnode->pDnode, pMsg); + } +} + +void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg) { + if (pMnode != NULL && pMnode->sendRedirectMsgFp != NULL) { + (*pMnode->sendRedirectMsgFp)(pMnode->pDnode, pMsg); + } +} + +static int32_t mndInitTimer(SMnode *pMnode) { + if (pMnode->timer == NULL) { + pMnode->timer = taosTmrInit(5000, 200, 3600000, "MND"); } - if (tsMint.timer == NULL) { + if (pMnode->timer == NULL) { return -1; } return 0; } -static void mnodeCleanupTimer() { - if (tsMint.timer != NULL) { - taosTmrCleanUp(tsMint.timer); - tsMint.timer = NULL; +static void mndCleanupTimer(SMnode *pMnode) { + if (pMnode->timer != NULL) { + taosTmrCleanUp(pMnode->timer); + pMnode->timer = NULL; } } -tmr_h mnodeGetTimer() { return tsMint.timer; } +tmr_h mndGetTimer(SMnode *pMnode) { + if (pMnode != NULL) { + return pMnode->timer; + } +} -static int32_t mnodeSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { +static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->dnodeId = pOption->dnodeId; pMnode->clusterId = pOption->clusterId; pMnode->replica = pOption->replica; pMnode->selfIndex = pOption->selfIndex; memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); - pMnode->pServer = pOption->pDnode; + pMnode->pDnode = pOption->pDnode; pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp; pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; @@ -98,88 +110,143 @@ static int32_t mnodeSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { return 0; } -static int32_t mnodeAllocInitSteps() { - struct SSteps *steps = taosStepInit(16, NULL); - if (steps == NULL) return -1; +static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCleanupFp cleanupFp) { + SMnodeStep step = {0}; + step.name = name; + step.initFp = initFp; + step.cleanupFp = cleanupFp; + if (taosArrayPush(&pMnode->steps, &step) != NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to alloc step:%s since %s", name, terrstr()); + return -1; + } - if (taosStepAdd(steps, "mnode-trans", mnodeInitTrans, mnodeCleanupTrans) != 0) return -1; - if (taosStepAdd(steps, "mnode-cluster", mnodeInitCluster, mnodeCleanupCluster) != 0) return -1; - if (taosStepAdd(steps, "mnode-dnode", mnodeInitDnode, mnodeCleanupDnode) != 0) return -1; - if (taosStepAdd(steps, "mnode-mnode", mnodeInitMnode, mnodeCleanupMnode) != 0) return -1; - if (taosStepAdd(steps, "mnode-acct", mnodeInitAcct, mnodeCleanupAcct) != 0) return -1; - if (taosStepAdd(steps, "mnode-auth", mnodeInitAuth, mnodeCleanupAuth) != 0) return -1; - if (taosStepAdd(steps, "mnode-user", mnodeInitUser, mnodeCleanupUser) != 0) return -1; - if (taosStepAdd(steps, "mnode-db", mnodeInitDb, mnodeCleanupDb) != 0) return -1; - if (taosStepAdd(steps, "mnode-vgroup", mnodeInitVgroup, mnodeCleanupVgroup) != 0) return -1; - if (taosStepAdd(steps, "mnode-stable", mnodeInitStable, mnodeCleanupStable) != 0) return -1; - if (taosStepAdd(steps, "mnode-func", mnodeInitFunc, mnodeCleanupFunc) != 0) return -1; - if (taosStepAdd(steps, "mnode-sdb", sdbInit, sdbCleanup) != 0) return -1; - - tsMint.pInitSteps = steps; return 0; } -static int32_t mnodeAllocStartSteps() { - struct SSteps *steps = taosStepInit(8, NULL); - if (steps == NULL) return -1; +static int32_t mndInitSteps(SMnode *pMnode) { + if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-stable", mndInitStable, mndCleanupStable) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-sdb", sdbInit, sdbCleanup) != 0) return -1; - taosStepAdd(steps, "mnode-timer", mnodeInitTimer, NULL); - taosStepAdd(steps, "mnode-sdb-file", sdbOpen, sdbClose); - taosStepAdd(steps, "mnode-balance", mnodeInitBalance, mnodeCleanupBalance); - taosStepAdd(steps, "mnode-profile", mnodeInitProfile, mnodeCleanupProfile); - taosStepAdd(steps, "mnode-show", mnodeInitShow, mnodeCleanUpShow); - taosStepAdd(steps, "mnode-sync", mnodeInitSync, mnodeCleanUpSync); - taosStepAdd(steps, "mnode-telem", mnodeInitTelem, mnodeCleanupTelem); - taosStepAdd(steps, "mnode-timer", NULL, mnodeCleanupTimer); + if (pMnode->replica == 1) { + if (mndAllocStep(pMnode, "mnode-deploy-sdb", sdbDeploy, sdbClose) != 0) return -1; + } else { + if (mndAllocStep(pMnode, "mnode-open-sdb", sdbOpen, sdbClose) != 0) return -1; + } + + if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-sdb-file", sdbOpen, sdbClose) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-balance", mndInitBalance, mndCleanupBalance) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return -1; - tsMint.pStartSteps = steps; return 0; } -SMnode *mnodeOpen(const char *path, const SMnodeOpt *pOption) { - SMnode *pMnode = calloc(1, sizeof(SMnode)); - - if (mnodeSetOptions(pMnode, pOption) != 0) { - free(pMnode); - mError("failed to init mnode options since %s", terrstr()); - return NULL; +static void mndCleanupSteps(SMnode *pMnode, int32_t pos) { + if (pos == -1) { + pos = taosArrayGetSize(&pMnode->steps); } - if (mnodeAllocInitSteps() != 0) { - mError("failed to alloc init steps since %s", terrstr()); - return NULL; - } - - if (mnodeAllocStartSteps() != 0) { - mError("failed to alloc start steps since %s", terrstr()); - return NULL; - } - - taosStepExec(tsMint.pInitSteps); - - if (tsMint.para.dnodeId <= 0 && tsMint.para.clusterId <= 0) { - if (sdbDeploy() != 0) { - mError("failed to deploy sdb since %s", terrstr()); - return NULL; - } else { - mInfo("mnode is deployed"); + for (int32_t s = pos; s >= 0; s--) { + SMnodeStep *pStep = taosArrayGet(&pMnode->steps, pos); + mDebug("step:%s will cleanup", pStep->name); + if (pStep->cleanupFp != NULL) { + (*pStep->cleanupFp)(pMnode); } } - taosStepExec(tsMint.pStartSteps); + taosArrayClear(&pMnode->steps); +} +static int32_t mndExecSteps(SMnode *pMnode) { + int32_t size = taosArrayGetSize(&pMnode->steps); + for (int32_t pos = 0; pos < size; pos++) { + SMnodeStep *pStep = taosArrayGet(&pMnode->steps, pos); + if (pStep->initFp == NULL) continue; + + // (*pMnode->reportProgress)(pStep->name, "start initialize"); + + int32_t code = (*pStep->initFp)(pMnode); + if (code != 0) { + mError("step:%s exec failed since %s, start to cleanup", pStep->name, tstrerror(code)); + mndCleanupSteps(pMnode, pos); + terrno = code; + return code; + } else { + mDebug("step:%s is initialized", pStep->name); + } + + // (*pMnode->reportProgress)(pStep->name, "initialize completed"); + } +} + +SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { + SMnode *pMnode = calloc(1, sizeof(SMnode)); + + int32_t code = mndSetOptions(pMnode, pOption); + if (code != 0) { + mndClose(pMnode); + terrno = code; + mError("failed to set mnode options since %s", terrstr()); + return NULL; + } + + code = mndInitSteps(pMnode); + if (code != 0) { + mndClose(pMnode); + terrno = code; + mError("failed to int steps since %s", terrstr()); + return NULL; + } + + code = mndExecSteps(pMnode); + if (code != 0) { + mndClose(pMnode); + terrno = code; + mError("failed to execute steps since %s", terrstr()); + return NULL; + } + + mDebug("mnode:%p object is created", pMnode); return pMnode; } -void mnodeClose(SMnode *pMnode) { free(pMnode); } +void mndClose(SMnode *pMnode) { + mndCleanupSteps(pMnode, -1); + free(pMnode); + mDebug("mnode:%p object is cleaned up", pMnode); +} -int32_t mnodeAlter(SMnode *pMnode, const SMnodeOpt *pOption) { return 0; } +int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { + assert(1); + return 0; +} -void mnodeDestroy(const char *path) { sdbUnDeploy(); } +void mndDestroy(const char *path) { + mDebug("mnode in %s will be destroyed", path); + sdbUnDeploy(); +} -int32_t mnodeGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { return 0; } +int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { + assert(1); + return 0; +} -SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { +SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -187,7 +254,7 @@ SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { } if (rpcGetConnInfo(pRpcMsg->handle, &pMsg->conn) != 0) { - mnodeCleanupMsg(pMsg); + mndCleanupMsg(pMsg); mError("can not get user from conn:%p", pMsg->rpcMsg.handle); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; return NULL; @@ -199,7 +266,7 @@ SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { return pMsg; } -void mnodeCleanupMsg(SMnodeMsg *pMsg) { +void mndCleanupMsg(SMnodeMsg *pMsg) { if (pMsg->pUser != NULL) { sdbRelease(pMsg->pUser); } @@ -207,40 +274,50 @@ void mnodeCleanupMsg(SMnodeMsg *pMsg) { taosFreeQitem(pMsg); } -void mnodeSendRsp(SMnodeMsg *pMsg, int32_t code) {} +void mndSendRsp(SMnodeMsg *pMsg, int32_t code) {} -static void mnodeProcessRpcMsg(SMnodeMsg *pMsg) { - if (!mnodeIsMaster()) { - mnodeSendRedirectMsg(NULL, &pMsg->rpcMsg, true); - mnodeCleanupMsg(pMsg); +static void mndProcessRpcMsg(SMnodeMsg *pMsg) { + SMnode *pMnode = pMsg->pMnode; + + if (!mnodeIsMaster(pMnode)) { + mndSendRedirectMsg(pMnode, &pMsg->rpcMsg); + mndCleanupMsg(pMsg); return; } - int32_t msgType = pMsg->rpcMsg.msgType; - - MndMsgFp fp = tsMint.msgFp[msgType]; + int32_t msgType = pMsg->rpcMsg.msgType; + MndMsgFp fp = pMnode->msgFp[msgType]; if (fp == NULL) { + mError("RPC %p, req:%s is not processed", pMsg->rpcMsg.handle, taosMsg[msgType]); + SRpcMsg rspMsg = {.handle = pMsg->rpcMsg.handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; + rpcSendResponse(&rspMsg); + mndCleanupMsg(pMsg); + return; } - int32_t code = (*fp)(NULL, pMsg); + int32_t code = (*fp)(pMnode, pMsg); if (code != 0) { - assert(code); + mError("RPC %p, req:%s processed error since %s", pMsg->rpcMsg.handle, taosMsg[msgType], tstrerror(code)); + SRpcMsg rspMsg = {.handle = pMsg->rpcMsg.handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; + rpcSendResponse(&rspMsg); } + + mndCleanupMsg(pMsg); } -void mnodeSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) { +void mndSetMsgHandle(SMnode *pMnode, int32_t msgType, MndMsgFp fp) { if (msgType >= 0 && msgType < TSDB_MSG_TYPE_MAX) { - tsMint.msgFp[msgType] = fp; + pMnode->msgFp[msgType] = fp; } } -void mnodeProcessReadMsg(SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } +void mndProcessReadMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } -void mnodeProcessWriteMsg(SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } +void mndProcessWriteMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } -void mnodeProcessSyncMsg(SMnodeMsg *pMsg) { mnodeProcessRpcMsg(pMsg); } +void mndProcessSyncMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } -void mnodeProcessApplyMsg(SMnodeMsg *pMsg) {} +void mndProcessApplyMsg(SMnodeMsg *pMsg) {} #if 0 @@ -256,7 +333,7 @@ static void mnodeProcessWriteReq(SMnodeMsg *pMsg, void *unused) { } if (!mnodeIsMaster()) { - SMnRsp *rpcRsp = &pMsg->rpcRsp; + SMnodeRsp *rpcRsp = &pMsg->rpcRsp; SEpSet *epSet = rpcMallocCont(sizeof(SEpSet)); mnodeGetMnodeEpSetForShell(epSet, true); rpcRsp->rsp = epSet; @@ -278,7 +355,7 @@ static void mnodeProcessWriteReq(SMnodeMsg *pMsg, void *unused) { code = (*tsMworker.writeMsgFp[msgType])(pMsg); PROCESS_WRITE_REQ_END: - mnodeSendRsp(pMsg, code); + mndSendRsp(pMsg, code); } static void mnodeProcessReadReq(SMnodeMsg *pMsg, void *unused) { @@ -293,7 +370,7 @@ static void mnodeProcessReadReq(SMnodeMsg *pMsg, void *unused) { } if (!mnodeIsMaster()) { - SMnRsp *rpcRsp = &pMsg->rpcRsp; + SMnodeRsp *rpcRsp = &pMsg->rpcRsp; SEpSet *epSet = rpcMallocCont(sizeof(SEpSet)); if (!epSet) { code = TSDB_CODE_OUT_OF_MEMORY; @@ -319,7 +396,7 @@ static void mnodeProcessReadReq(SMnodeMsg *pMsg, void *unused) { code = (*tsMworker.readMsgFp[msgType])(pMsg); PROCESS_READ_REQ_END: - mnodeSendRsp(pMsg, code); + mndSendRsp(pMsg, code); } static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) { @@ -334,7 +411,7 @@ static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) { } if (!mnodeIsMaster()) { - SMnRsp *rpcRsp = &pMsg->rpcRsp; + SMnodeRsp *rpcRsp = &pMsg->rpcRsp; SEpSet *epSet = rpcMallocCont(sizeof(SEpSet)); mnodeGetMnodeEpSetForPeer(epSet, true); rpcRsp->rsp = epSet; @@ -356,7 +433,7 @@ static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) { code = (*tsMworker.peerReqFp[msgType])(pMsg); PROCESS_PEER_REQ_END: - mnodeSendRsp(pMsg, code); + mndSendRsp(pMsg, code); } static void mnodeProcessPeerRsp(SMnodeMsg *pMsg, void *unused) { @@ -365,7 +442,7 @@ static void mnodeProcessPeerRsp(SMnodeMsg *pMsg, void *unused) { if (!mnodeIsMaster()) { mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]); - mnodeCleanupMsg2(pMsg); + mndCleanupMsg2(pMsg); } if (tsMworker.peerRspFp[msgType]) { @@ -374,6 +451,6 @@ static void mnodeProcessPeerRsp(SMnodeMsg *pMsg, void *unused) { mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]); } - mnodeCleanupMsg2(pMsg); + mndCleanupMsg2(pMsg); } #endif \ No newline at end of file From e63637fcce2029fb51d29f8265471c5ff95565b3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 13:19:00 +0800 Subject: [PATCH 09/18] TD-10431 rename some functions --- source/dnode/mnode/impl/inc/mndMnode.h | 4 +- source/dnode/mnode/impl/inc/mndSync.h | 5 +- source/dnode/mnode/impl/src/mndMnode.c | 4 +- source/dnode/mnode/impl/src/mndSync.c | 4 +- source/dnode/mnode/impl/src/mndTelem.c | 98 +++++++------- source/dnode/mnode/impl/src/mndUser.c | 54 ++++---- source/dnode/mnode/impl/src/mnode.c | 180 +++++-------------------- 7 files changed, 111 insertions(+), 238 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h index 7e969baf37..260d238c65 100644 --- a/source/dnode/mnode/impl/inc/mndMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -24,8 +24,8 @@ extern "C" { int32_t mndInitMnode(); void mndCleanupMnode(); -void mnodeGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect); -void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect); +void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect); +void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndSync.h b/source/dnode/mnode/impl/inc/mndSync.h index 7d7f9d69d0..af091882a3 100644 --- a/source/dnode/mnode/impl/inc/mndSync.h +++ b/source/dnode/mnode/impl/inc/mndSync.h @@ -24,9 +24,8 @@ extern "C" { int32_t mndInitSync(); void mndCleanupSync(); -int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData); - -bool mnodeIsMaster(); +bool mndIsMaster(); +int32_t mndSyncPropose(SSdbRaw *pRaw, void *pData); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index ce38049a36..66df205f6e 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -20,5 +20,5 @@ int32_t mndInitMnode() { return 0; } void mndCleanupMnode() {} -void mnodeGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {} -void mnodeGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {} \ No newline at end of file +void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {} +void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 8db79e1e32..89098e7ec0 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -21,10 +21,10 @@ int32_t mndInitSync() { return 0; } void mndCleanupSync() {} -int32_t mnodeSyncPropose(SSdbRaw *pRaw, void *pData) { +int32_t mndSyncPropose(SSdbRaw *pRaw, void *pData) { trnApply(pData, pData, 0); free(pData); return 0; } -bool mnodeIsMaster() { return true; } \ No newline at end of file +bool mndIsMaster() { return true; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index e9748ec12e..f5f5464822 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -36,9 +36,9 @@ static struct { char email[TSDB_FQDN_LEN]; } tsTelem; -static void mnodeBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); } +static void mndBeginObject(SBufferWriter* bw) { tbufWriteChar(bw, '{'); } -static void mnodeCloseObject(SBufferWriter* bw) { +static void mndCloseObject(SBufferWriter* bw) { size_t len = tbufTell(bw); if (tbufGetData(bw, false)[len - 1] == ',') { tbufWriteCharAt(bw, len - 1, '}'); @@ -64,14 +64,14 @@ static void closeArray(SBufferWriter* bw) { } #endif -static void mnodeWriteString(SBufferWriter* bw, const char* str) { +static void mndWriteString(SBufferWriter* bw, const char* str) { tbufWriteChar(bw, '"'); tbufWrite(bw, str, strlen(str)); tbufWriteChar(bw, '"'); } -static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) { - mnodeWriteString(bw, k); +static void mndAddIntField(SBufferWriter* bw, const char* k, int64_t v) { + mndWriteString(bw, k); tbufWriteChar(bw, ':'); char buf[32]; sprintf(buf, "%" PRId64, v); @@ -79,14 +79,14 @@ static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) { tbufWriteChar(bw, ','); } -static void mnodeAddStringField(SBufferWriter* bw, const char* k, const char* v) { - mnodeWriteString(bw, k); +static void mndAddStringField(SBufferWriter* bw, const char* k, const char* v) { + mndWriteString(bw, k); tbufWriteChar(bw, ':'); - mnodeWriteString(bw, v); + mndWriteString(bw, v); tbufWriteChar(bw, ','); } -static void mnodeAddCpuInfo(SBufferWriter* bw) { +static void mndAddCpuInfo(SBufferWriter* bw) { char* line = NULL; size_t size = 0; int32_t done = 0; @@ -100,11 +100,11 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) { line[size - 1] = '\0'; if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) { const char* v = strchr(line, ':') + 2; - mnodeAddStringField(bw, "cpuModel", v); + mndAddStringField(bw, "cpuModel", v); done |= 1; } else if (((done & 2) == 0) && strncmp(line, "cpu cores", 9) == 0) { const char* v = strchr(line, ':') + 2; - mnodeWriteString(bw, "numOfCpu"); + mndWriteString(bw, "numOfCpu"); tbufWriteChar(bw, ':'); tbufWrite(bw, v, strlen(v)); tbufWriteChar(bw, ','); @@ -116,7 +116,7 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) { fclose(fp); } -static void mnodeAddOsInfo(SBufferWriter* bw) { +static void mndAddOsInfo(SBufferWriter* bw) { char* line = NULL; size_t size = 0; @@ -133,7 +133,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) { p++; line[size - 2] = 0; } - mnodeAddStringField(bw, "os", p); + mndAddStringField(bw, "os", p); break; } } @@ -142,7 +142,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) { fclose(fp); } -static void mnodeAddMemoryInfo(SBufferWriter* bw) { +static void mndAddMemoryInfo(SBufferWriter* bw) { char* line = NULL; size_t size = 0; @@ -156,7 +156,7 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) { if (strncmp(line, "MemTotal", 8) == 0) { const char* p = strchr(line, ':') + 1; while (*p == ' ') p++; - mnodeAddStringField(bw, "memory", p); + mndAddStringField(bw, "memory", p); break; } } @@ -165,32 +165,32 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) { fclose(fp); } -static void mnodeAddVersionInfo(SBufferWriter* bw) { - mnodeAddStringField(bw, "version", version); - mnodeAddStringField(bw, "buildInfo", buildinfo); - mnodeAddStringField(bw, "gitInfo", gitinfo); - mnodeAddStringField(bw, "email", tsTelem.email); +static void mndAddVersionInfo(SBufferWriter* bw) { + mndAddStringField(bw, "version", version); + mndAddStringField(bw, "buildInfo", buildinfo); + mndAddStringField(bw, "gitInfo", gitinfo); + mndAddStringField(bw, "email", tsTelem.email); } -static void mnodeAddRuntimeInfo(SBufferWriter* bw) { +static void mndAddRuntimeInfo(SBufferWriter* bw) { SMnodeLoad load = {0}; if (mndGetLoad(NULL, &load) != 0) { return; } - mnodeAddIntField(bw, "numOfDnode", load.numOfDnode); - mnodeAddIntField(bw, "numOfMnode", load.numOfMnode); - mnodeAddIntField(bw, "numOfVgroup", load.numOfVgroup); - mnodeAddIntField(bw, "numOfDatabase", load.numOfDatabase); - mnodeAddIntField(bw, "numOfSuperTable", load.numOfSuperTable); - mnodeAddIntField(bw, "numOfChildTable", load.numOfChildTable); - mnodeAddIntField(bw, "numOfColumn", load.numOfColumn); - mnodeAddIntField(bw, "numOfPoint", load.totalPoints); - mnodeAddIntField(bw, "totalStorage", load.totalStorage); - mnodeAddIntField(bw, "compStorage", load.compStorage); + mndAddIntField(bw, "numOfDnode", load.numOfDnode); + mndAddIntField(bw, "numOfMnode", load.numOfMnode); + mndAddIntField(bw, "numOfVgroup", load.numOfVgroup); + mndAddIntField(bw, "numOfDatabase", load.numOfDatabase); + mndAddIntField(bw, "numOfSuperTable", load.numOfSuperTable); + mndAddIntField(bw, "numOfChildTable", load.numOfChildTable); + mndAddIntField(bw, "numOfColumn", load.numOfColumn); + mndAddIntField(bw, "numOfPoint", load.totalPoints); + mndAddIntField(bw, "totalStorage", load.totalStorage); + mndAddIntField(bw, "compStorage", load.compStorage); } -static void mnodeSendTelemetryReport() { +static void mndSendTelemetryReport() { char buf[128] = {0}; uint32_t ip = taosGetIpv4FromFqdn(TELEMETRY_SERVER); if (ip == 0xffffffff) { @@ -208,15 +208,15 @@ static void mnodeSendTelemetryReport() { snprintf(clusterIdStr, sizeof(clusterIdStr), "%" PRId64, clusterId); SBufferWriter bw = tbufInitWriter(NULL, false); - mnodeBeginObject(&bw); - mnodeAddStringField(&bw, "instanceId", clusterIdStr); - mnodeAddIntField(&bw, "reportVersion", 1); - mnodeAddOsInfo(&bw); - mnodeAddCpuInfo(&bw); - mnodeAddMemoryInfo(&bw); - mnodeAddVersionInfo(&bw); - mnodeAddRuntimeInfo(&bw); - mnodeCloseObject(&bw); + mndBeginObject(&bw); + mndAddStringField(&bw, "instanceId", clusterIdStr); + mndAddIntField(&bw, "reportVersion", 1); + mndAddOsInfo(&bw); + mndAddCpuInfo(&bw); + mndAddMemoryInfo(&bw); + mndAddVersionInfo(&bw); + mndAddRuntimeInfo(&bw); + mndCloseObject(&bw); const char* header = "POST /report HTTP/1.1\n" @@ -240,12 +240,12 @@ static void mnodeSendTelemetryReport() { taosCloseSocket(fd); } -static void* mnodeTelemThreadFp(void* param) { +static void* mndTelemThreadFp(void* param) { struct timespec end = {0}; clock_gettime(CLOCK_REALTIME, &end); end.tv_sec += 300; // wait 5 minutes before send first report - setThreadName("mnode-telem"); + setThreadName("mnd-telem"); while (!tsTelem.exit) { int32_t r = 0; @@ -256,8 +256,8 @@ static void* mnodeTelemThreadFp(void* param) { if (r == 0) break; if (r != ETIMEDOUT) continue; - if (mnodeIsMaster()) { - mnodeSendTelemetryReport(); + if (mndIsMaster()) { + mndSendTelemetryReport(); } end.tv_sec += REPORT_INTERVAL; } @@ -265,7 +265,7 @@ static void* mnodeTelemThreadFp(void* param) { return NULL; } -static void mnodeGetEmail(char* filepath) { +static void mndGetEmail(char* filepath) { int32_t fd = taosOpenFileRead(filepath); if (fd < 0) { return; @@ -287,19 +287,19 @@ int32_t mndInitTelem() { pthread_cond_init(&tsTelem.cond, NULL); tsTelem.email[0] = 0; - mnodeGetEmail("/usr/local/taos/email"); + mndGetEmail("/usr/local/taos/email"); pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - int32_t code = pthread_create(&tsTelem.thread, &attr, mnodeTelemThreadFp, NULL); + int32_t code = pthread_create(&tsTelem.thread, &attr, mndTelemThreadFp, NULL); pthread_attr_destroy(&attr); if (code != 0) { mTrace("failed to create telemetry thread since :%s", strerror(code)); } - mInfo("mnode telemetry is initialized"); + mInfo("mnd telemetry is initialized"); return 0; } diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index a51133d427..32c2c459e5 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -15,14 +15,12 @@ #define _DEFAULT_SOURCE #include "mndSync.h" -#include "os.h" -#include "tglobal.h" #include "tkey.h" #include "mndTrans.h" #define SDB_USER_VER 1 -static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) { +static SSdbRaw *mndUserActionEncode(SUserObj *pUser) { SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, SDB_USER_VER, sizeof(SAcctObj)); if (pRaw == NULL) return NULL; @@ -38,7 +36,7 @@ static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) { return pRaw; } -static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) { +static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { int8_t sver = 0; if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; @@ -62,7 +60,7 @@ static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) { return pRow; } -static int32_t mnodeUserActionInsert(SUserObj *pUser) { +static int32_t mndUserActionInsert(SUserObj *pUser) { pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pUser->prohibitDbHash == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -78,7 +76,7 @@ static int32_t mnodeUserActionInsert(SUserObj *pUser) { return 0; } -static int32_t mnodeUserActionDelete(SUserObj *pUser) { +static int32_t mndUserActionDelete(SUserObj *pUser) { if (pUser->prohibitDbHash) { taosHashCleanup(pUser->prohibitDbHash); pUser->prohibitDbHash = NULL; @@ -92,14 +90,14 @@ static int32_t mnodeUserActionDelete(SUserObj *pUser) { return 0; } -static int32_t mnodeUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) { +static int32_t mndUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) { SUserObj tObj; int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj); memcpy(pDstUser, pSrcUser, len); return 0; } -static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) { +static int32_t mndCreateDefaultUser(char *acct, char *user, char *pass) { SUserObj userObj = {0}; tstrncpy(userObj.user, user, TSDB_USER_LEN); tstrncpy(userObj.acct, acct, TSDB_USER_LEN); @@ -111,30 +109,26 @@ static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) { userObj.rootAuth = 1; } - SSdbRaw *pRaw = mnodeUserActionEncode(&userObj); + SSdbRaw *pRaw = mndUserActionEncode(&userObj); if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); return sdbWrite(pRaw); } -static int32_t mnodeCreateDefaultUsers() { - if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { +static int32_t mndCreateDefaultUsers() { + if (mndCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { return -1; } - if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "monitor", tsInternalPass) != 0) { - return -1; - } - - if (mnodeCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, tsInternalPass) != 0) { + if (mndCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { return -1; } return 0; } -static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pMsg) { +static int32_t mndCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pMsg) { SUserObj userObj = {0}; tstrncpy(userObj.user, user, TSDB_USER_LEN); tstrncpy(userObj.acct, acct, TSDB_USER_LEN); @@ -146,7 +140,7 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM STrans *pTrans = trnCreate(TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); if (pTrans == NULL) return -1; - SSdbRaw *pRedoRaw = mnodeUserActionEncode(&userObj); + SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj); if (pRedoRaw == NULL || trnAppendRedoLog(pTrans, pRedoRaw) != 0) { mError("failed to append redo log since %s", terrstr()); trnDrop(pTrans); @@ -154,7 +148,7 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM } sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING); - SSdbRaw *pUndoRaw = mnodeUserActionEncode(&userObj); + SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj); if (pUndoRaw == NULL || trnAppendUndoLog(pTrans, pUndoRaw) != 0) { mError("failed to append undo log since %s", terrstr()); trnDrop(pTrans); @@ -162,7 +156,7 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM } sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED); - SSdbRaw *pCommitRaw = mnodeUserActionEncode(&userObj); + SSdbRaw *pCommitRaw = mndUserActionEncode(&userObj); if (pCommitRaw == NULL || trnAppendCommitLog(pTrans, pCommitRaw) != 0) { mError("failed to append commit log since %s", terrstr()); trnDrop(pTrans); @@ -170,7 +164,7 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM } sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); - if (trnPrepare(pTrans, mnodeSyncPropose) != 0) { + if (trnPrepare(pTrans, mndSyncPropose) != 0) { trnDrop(pTrans); return -1; } @@ -179,7 +173,7 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM return 0; } -static int32_t mnodeProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { +static int32_t mndProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont; if (pCreate->user[0] == 0) { @@ -209,7 +203,7 @@ static int32_t mnodeProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return -1; } - int32_t code = mnodeCreateUser(pOperUser->acct, pCreate->user, pCreate->pass, pMsg); + int32_t code = mndCreateUser(pOperUser->acct, pCreate->user, pCreate->pass, pMsg); sdbRelease(pOperUser); if (code != 0) { @@ -223,15 +217,15 @@ static int32_t mnodeProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { int32_t mndInitUser() { SSdbTable table = {.sdbType = SDB_USER, .keyType = SDB_KEY_BINARY, - .deployFp = (SdbDeployFp)mnodeCreateDefaultUsers, - .encodeFp = (SdbEncodeFp)mnodeUserActionEncode, - .decodeFp = (SdbDecodeFp)mnodeUserActionDecode, - .insertFp = (SdbInsertFp)mnodeUserActionInsert, - .updateFp = (SdbUpdateFp)mnodeUserActionUpdate, - .deleteFp = (SdbDeleteFp)mnodeUserActionDelete}; + .deployFp = (SdbDeployFp)mndCreateDefaultUsers, + .encodeFp = (SdbEncodeFp)mndUserActionEncode, + .decodeFp = (SdbDecodeFp)mndUserActionDecode, + .insertFp = (SdbInsertFp)mndUserActionInsert, + .updateFp = (SdbUpdateFp)mndUserActionUpdate, + .deleteFp = (SdbDeleteFp)mndUserActionDelete}; sdbSetTable(table); - mndSetMsgHandle(NULL, TSDB_MSG_TYPE_CREATE_USER, mnodeProcessCreateUserMsg); + mndSetMsgHandle(NULL, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg); return 0; } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 426c86f728..369994c2bb 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -278,28 +278,44 @@ void mndSendRsp(SMnodeMsg *pMsg, int32_t code) {} static void mndProcessRpcMsg(SMnodeMsg *pMsg) { SMnode *pMnode = pMsg->pMnode; + int32_t code = 0; + int32_t msgType = pMsg->rpcMsg.msgType; + void *ahandle = pMsg->rpcMsg.ahandle; + bool isReq = (msgType % 2 == 1); - if (!mnodeIsMaster(pMnode)) { - mndSendRedirectMsg(pMnode, &pMsg->rpcMsg); - mndCleanupMsg(pMsg); - return; + if (isReq && !mndIsMaster(pMnode)) { + code = TSDB_CODE_APP_NOT_READY; + goto PROCESS_RPC_END; + } + + if (isReq && pMsg->rpcMsg.pCont == NULL) { + mError("msg:%p, app:%p type:%s content is null", pMsg, ahandle, taosMsg[msgType]); + code = TSDB_CODE_MND_INVALID_MSG_LEN; + goto PROCESS_RPC_END; } - int32_t msgType = pMsg->rpcMsg.msgType; MndMsgFp fp = pMnode->msgFp[msgType]; if (fp == NULL) { - mError("RPC %p, req:%s is not processed", pMsg->rpcMsg.handle, taosMsg[msgType]); - SRpcMsg rspMsg = {.handle = pMsg->rpcMsg.handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; - rpcSendResponse(&rspMsg); - mndCleanupMsg(pMsg); - return; + mError("msg:%p, app:%p type:%s not processed", pMsg, ahandle, taosMsg[msgType]); + code = TSDB_CODE_MSG_NOT_PROCESSED; + goto PROCESS_RPC_END; } - int32_t code = (*fp)(pMnode, pMsg); + code = (*fp)(pMnode, pMsg); if (code != 0) { - mError("RPC %p, req:%s processed error since %s", pMsg->rpcMsg.handle, taosMsg[msgType], tstrerror(code)); - SRpcMsg rspMsg = {.handle = pMsg->rpcMsg.handle, .code = TSDB_CODE_MSG_NOT_PROCESSED}; - rpcSendResponse(&rspMsg); + mError("msg:%p, app:%p type:%s failed to process since %s", pMsg, ahandle, taosMsg[msgType], tstrerror(code)); + goto PROCESS_RPC_END; + } + +PROCESS_RPC_END: + if (isReq) { + if (code == TSDB_CODE_APP_NOT_READY) { + mndSendRedirectMsg(pMnode, &pMsg->rpcMsg); + } else if (code != 0) { + SRpcMsg rspMsg = {.handle = pMsg->rpcMsg.handle, .code = code}; + rpcSendResponse(&rspMsg); + } else { + } } mndCleanupMsg(pMsg); @@ -318,139 +334,3 @@ void mndProcessWriteMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } void mndProcessSyncMsg(SMnodeMsg *pMsg) { mndProcessRpcMsg(pMsg); } void mndProcessApplyMsg(SMnodeMsg *pMsg) {} - -#if 0 - -static void mnodeProcessWriteReq(SMnodeMsg *pMsg, void *unused) { - int32_t msgType = pMsg->rpcMsg.msgType; - 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]); - code = TSDB_CODE_MND_INVALID_MSG_LEN; - goto PROCESS_WRITE_REQ_END; - } - - if (!mnodeIsMaster()) { - SMnodeRsp *rpcRsp = &pMsg->rpcRsp; - SEpSet *epSet = rpcMallocCont(sizeof(SEpSet)); - mnodeGetMnodeEpSetForShell(epSet, true); - rpcRsp->rsp = epSet; - rpcRsp->len = sizeof(SEpSet); - - mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, - taosMsg[msgType], epSet->numOfEps, epSet->inUse); - - 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]); - code = TSDB_CODE_MND_MSG_NOT_PROCESSED; - goto PROCESS_WRITE_REQ_END; - } - - code = (*tsMworker.writeMsgFp[msgType])(pMsg); - -PROCESS_WRITE_REQ_END: - mndSendRsp(pMsg, code); -} - -static void mnodeProcessReadReq(SMnodeMsg *pMsg, void *unused) { - int32_t msgType = pMsg->rpcMsg.msgType; - 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]); - code = TSDB_CODE_MND_INVALID_MSG_LEN; - goto PROCESS_READ_REQ_END; - } - - if (!mnodeIsMaster()) { - SMnodeRsp *rpcRsp = &pMsg->rpcRsp; - SEpSet *epSet = rpcMallocCont(sizeof(SEpSet)); - if (!epSet) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto PROCESS_READ_REQ_END; - } - mnodeGetMnodeEpSetForShell(epSet, true); - rpcRsp->rsp = epSet; - rpcRsp->len = sizeof(SEpSet); - - mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType], - epSet->numOfEps, epSet->inUse); - 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]); - 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]); - code = (*tsMworker.readMsgFp[msgType])(pMsg); - -PROCESS_READ_REQ_END: - mndSendRsp(pMsg, code); -} - -static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) { - int32_t msgType = pMsg->rpcMsg.msgType; - 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]); - code = TSDB_CODE_MND_INVALID_MSG_LEN; - goto PROCESS_PEER_REQ_END; - } - - if (!mnodeIsMaster()) { - SMnodeRsp *rpcRsp = &pMsg->rpcRsp; - SEpSet *epSet = rpcMallocCont(sizeof(SEpSet)); - mnodeGetMnodeEpSetForPeer(epSet, true); - rpcRsp->rsp = epSet; - rpcRsp->len = sizeof(SEpSet); - - mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, - taosMsg[msgType], epSet->numOfEps, epSet->inUse); - - 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]); - code = TSDB_CODE_MND_MSG_NOT_PROCESSED; - goto PROCESS_PEER_REQ_END; - } - - code = (*tsMworker.peerReqFp[msgType])(pMsg); - -PROCESS_PEER_REQ_END: - mndSendRsp(pMsg, code); -} - -static void mnodeProcessPeerRsp(SMnodeMsg *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]); - mndCleanupMsg2(pMsg); - } - - if (tsMworker.peerRspFp[msgType]) { - (*tsMworker.peerRspFp[msgType])(pRpcMsg); - } else { - mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]); - } - - mndCleanupMsg2(pMsg); -} -#endif \ No newline at end of file From 35b0c693331bf8ce9ec9c8572c8ba9522205fda4 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 13:29:13 +0800 Subject: [PATCH 10/18] TD-10431 rename some funcs --- source/dnode/mnode/impl/inc/mndAcct.h | 4 ++-- source/dnode/mnode/impl/inc/mndAuth.h | 4 ++-- source/dnode/mnode/impl/inc/mndBalance.h | 4 ++-- source/dnode/mnode/impl/inc/mndCluster.h | 4 ++-- source/dnode/mnode/impl/inc/mndDb.h | 4 ++-- source/dnode/mnode/impl/inc/mndDnode.h | 4 ++-- source/dnode/mnode/impl/inc/mndFunc.h | 4 ++-- source/dnode/mnode/impl/inc/mndMnode.h | 4 ++-- source/dnode/mnode/impl/inc/mndOper.h | 4 ++-- source/dnode/mnode/impl/inc/mndProfile.h | 4 ++-- source/dnode/mnode/impl/inc/mndShow.h | 4 ++-- source/dnode/mnode/impl/inc/mndStable.h | 4 ++-- source/dnode/mnode/impl/inc/mndSync.h | 6 +++--- source/dnode/mnode/impl/inc/mndTelem.h | 4 ++-- source/dnode/mnode/impl/inc/mndTrans.h | 4 ++-- source/dnode/mnode/impl/inc/mndUser.h | 4 ++-- source/dnode/mnode/impl/inc/mndVgroup.h | 4 ++-- source/dnode/mnode/impl/src/mndAcct.c | 4 ++-- source/dnode/mnode/impl/src/mndAuth.c | 4 ++-- source/dnode/mnode/impl/src/mndBalance.c | 4 ++-- source/dnode/mnode/impl/src/mndCluster.c | 4 ++-- source/dnode/mnode/impl/src/mndDb.c | 4 ++-- source/dnode/mnode/impl/src/mndDnode.c | 4 ++-- source/dnode/mnode/impl/src/mndFunc.c | 4 ++-- source/dnode/mnode/impl/src/mndMnode.c | 4 ++-- source/dnode/mnode/impl/src/mndOper.c | 4 ++-- source/dnode/mnode/impl/src/mndProfile.c | 4 ++-- source/dnode/mnode/impl/src/mndShow.c | 4 ++-- source/dnode/mnode/impl/src/mndStable.c | 4 ++-- source/dnode/mnode/impl/src/mndSync.c | 4 ++-- source/dnode/mnode/impl/src/mndTelem.c | 6 +++--- source/dnode/mnode/impl/src/mndTrans.c | 4 ++-- source/dnode/mnode/impl/src/mndUser.c | 6 +++--- source/dnode/mnode/impl/src/mndVgroup.c | 4 ++-- 34 files changed, 71 insertions(+), 71 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndAcct.h b/source/dnode/mnode/impl/inc/mndAcct.h index 3289c24110..2073944cc1 100644 --- a/source/dnode/mnode/impl/inc/mndAcct.h +++ b/source/dnode/mnode/impl/inc/mndAcct.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitAcct(); -void mndCleanupAcct(); +int32_t mndInitAcct(SMnode *pMnode); +void mndCleanupAcct(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndAuth.h b/source/dnode/mnode/impl/inc/mndAuth.h index 3f0deeec6c..b426ce23cf 100644 --- a/source/dnode/mnode/impl/inc/mndAuth.h +++ b/source/dnode/mnode/impl/inc/mndAuth.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitAuth(); -void mndCleanupAuth(); +int32_t mndInitAuth(SMnode *pMnode); +void mndCleanupAuth(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndBalance.h b/source/dnode/mnode/impl/inc/mndBalance.h index 66d85eb2c3..fa3679d033 100644 --- a/source/dnode/mnode/impl/inc/mndBalance.h +++ b/source/dnode/mnode/impl/inc/mndBalance.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitBalance(); -void mndCleanupBalance(); +int32_t mndInitBalance(SMnode *pMnode); +void mndCleanupBalance(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndCluster.h b/source/dnode/mnode/impl/inc/mndCluster.h index d8dba66a63..efc1ada67d 100644 --- a/source/dnode/mnode/impl/inc/mndCluster.h +++ b/source/dnode/mnode/impl/inc/mndCluster.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitCluster(); -void mndCleanupCluster(); +int32_t mndInitCluster(SMnode *pMnode); +void mndCleanupCluster(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndDb.h b/source/dnode/mnode/impl/inc/mndDb.h index c9a888a115..acccb62603 100644 --- a/source/dnode/mnode/impl/inc/mndDb.h +++ b/source/dnode/mnode/impl/inc/mndDb.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitDb(); -void mndCleanupDb(); +int32_t mndInitDb(SMnode *pMnode); +void mndCleanupDb(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndDnode.h b/source/dnode/mnode/impl/inc/mndDnode.h index 0c484b0724..d7bfdba122 100644 --- a/source/dnode/mnode/impl/inc/mndDnode.h +++ b/source/dnode/mnode/impl/inc/mndDnode.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitDnode(); -void mndCleanupDnode(); +int32_t mndInitDnode(SMnode *pMnode); +void mndCleanupDnode(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndFunc.h b/source/dnode/mnode/impl/inc/mndFunc.h index 3e17aae389..a531ef31a4 100644 --- a/source/dnode/mnode/impl/inc/mndFunc.h +++ b/source/dnode/mnode/impl/inc/mndFunc.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitFunc(); -void mndCleanupFunc(); +int32_t mndInitFunc(SMnode *pMnode); +void mndCleanupFunc(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h index 260d238c65..c57e1d42a5 100644 --- a/source/dnode/mnode/impl/inc/mndMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitMnode(); -void mndCleanupMnode(); +int32_t mndInitMnode(SMnode *pMnode); +void mndCleanupMnode(SMnode *pMnode); void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect); void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect); diff --git a/source/dnode/mnode/impl/inc/mndOper.h b/source/dnode/mnode/impl/inc/mndOper.h index d07567635d..5ad5059a0f 100644 --- a/source/dnode/mnode/impl/inc/mndOper.h +++ b/source/dnode/mnode/impl/inc/mndOper.h @@ -20,8 +20,8 @@ extern "C" { #endif -int32_t mndInitOper(); -void mndCleanupOper(); +int32_t mndInitOper(SMnode *pMnode); +void mndCleanupOper(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndProfile.h b/source/dnode/mnode/impl/inc/mndProfile.h index 4433478caa..df857be73e 100644 --- a/source/dnode/mnode/impl/inc/mndProfile.h +++ b/source/dnode/mnode/impl/inc/mndProfile.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitProfile(); -void mndCleanupProfile(); +int32_t mndInitProfile(SMnode *pMnode); +void mndCleanupProfile(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndShow.h b/source/dnode/mnode/impl/inc/mndShow.h index 2161c81b74..06c18cb029 100644 --- a/source/dnode/mnode/impl/inc/mndShow.h +++ b/source/dnode/mnode/impl/inc/mndShow.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitShow(); -void mndCleanupShow(); +int32_t mndInitShow(SMnode *pMnode); +void mndCleanupShow(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndStable.h b/source/dnode/mnode/impl/inc/mndStable.h index 429f4d947a..c7767a59e4 100644 --- a/source/dnode/mnode/impl/inc/mndStable.h +++ b/source/dnode/mnode/impl/inc/mndStable.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitStable(); -void mndCleanupStable(); +int32_t mndInitStable(SMnode *pMnode); +void mndCleanupStable(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndSync.h b/source/dnode/mnode/impl/inc/mndSync.h index af091882a3..3e45b0adb1 100644 --- a/source/dnode/mnode/impl/inc/mndSync.h +++ b/source/dnode/mnode/impl/inc/mndSync.h @@ -22,9 +22,9 @@ extern "C" { #endif -int32_t mndInitSync(); -void mndCleanupSync(); -bool mndIsMaster(); +int32_t mndInitSync(SMnode *pMnode); +void mndCleanupSync(SMnode *pMnode); +bool mndIsMaster(SMnode *pMnode); int32_t mndSyncPropose(SSdbRaw *pRaw, void *pData); #ifdef __cplusplus diff --git a/source/dnode/mnode/impl/inc/mndTelem.h b/source/dnode/mnode/impl/inc/mndTelem.h index ccee629aad..4cbf0cdc77 100644 --- a/source/dnode/mnode/impl/inc/mndTelem.h +++ b/source/dnode/mnode/impl/inc/mndTelem.h @@ -21,8 +21,8 @@ extern "C" { #endif #include "mndInt.h" -int32_t mndInitTelem(); -void mndCleanupTelem(); +int32_t mndInitTelem(SMnode *pMnode); +void mndCleanupTelem(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 42a5c391b4..4443dd2e1c 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitTrans(); -void mndCleanupTrans(); +int32_t mndInitTrans(SMnode *pMnode); +void mndCleanupTrans(SMnode *pMnode); STrans *trnCreate(ETrnPolicy policy, void *rpcHandle); void trnDrop(STrans *pTrans); diff --git a/source/dnode/mnode/impl/inc/mndUser.h b/source/dnode/mnode/impl/inc/mndUser.h index 19554ccd37..ce570773bd 100644 --- a/source/dnode/mnode/impl/inc/mndUser.h +++ b/source/dnode/mnode/impl/inc/mndUser.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitUser(); -void mndCleanupUser(); +int32_t mndInitUser(SMnode *pMnode); +void mndCleanupUser(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index bf2cb60092..c75bdb5949 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -22,8 +22,8 @@ extern "C" { #endif -int32_t mndInitVgroup(); -void mndCleanupVgroup(); +int32_t mndInitVgroup(SMnode *pMnode); +void mndCleanupVgroup(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index c8087dbc2d..0ee290943e 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -101,7 +101,7 @@ static int32_t mnodeCreateDefaultAcct() { return sdbWrite(pRaw); } -int32_t mndInitAcct() { +int32_t mndInitAcct(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_ACCT, .keyType = SDB_KEY_BINARY, .deployFp = (SdbDeployFp)mnodeCreateDefaultAcct, @@ -115,4 +115,4 @@ int32_t mndInitAcct() { return 0; } -void mndCleanupAcct() {} +void mndCleanupAcct(SMnode *pMnode) {} diff --git a/source/dnode/mnode/impl/src/mndAuth.c b/source/dnode/mnode/impl/src/mndAuth.c index d37c7bd4da..bcefbfde21 100644 --- a/source/dnode/mnode/impl/src/mndAuth.c +++ b/source/dnode/mnode/impl/src/mndAuth.c @@ -17,8 +17,8 @@ #include "os.h" #include "mndAuth.h" -int32_t mndInitAuth() { return 0; } -void mndCleanupAuth() {} +int32_t mndInitAuth(SMnode *pMnode) { return 0; } +void mndCleanupAuth(SMnode *pMnode) {} int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { return 0; diff --git a/source/dnode/mnode/impl/src/mndBalance.c b/source/dnode/mnode/impl/src/mndBalance.c index 7b919af3f8..6ce89b96a3 100644 --- a/source/dnode/mnode/impl/src/mndBalance.c +++ b/source/dnode/mnode/impl/src/mndBalance.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitBalance() { return 0; } -void mndCleanupBalance() {} \ No newline at end of file +int32_t mndInitBalance(SMnode *pMnode) { return 0; } +void mndCleanupBalance(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index f926959b9f..98e9e70229 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitCluster() { return 0; } -void mndCleanupCluster() {} \ No newline at end of file +int32_t mndInitCluster(SMnode *pMnode) { return 0; } +void mndCleanupCluster(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 4c0e54f436..3a5a221677 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitDb() { return 0; } -void mndCleanupDb() {} \ No newline at end of file +int32_t mndInitDb(SMnode *pMnode) { return 0; } +void mndCleanupDb(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index f9329e871f..11f3dc1ee9 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitDnode() { return 0; } -void mndCleanupDnode() {} \ No newline at end of file +int32_t mndInitDnode(SMnode *pMnode) { return 0; } +void mndCleanupDnode(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index a84178ea6e..d859da029f 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitFunc() { return 0; } -void mndCleanupFunc() {} \ No newline at end of file +int32_t mndInitFunc(SMnode *pMnode) { return 0; } +void mndCleanupFunc(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 66df205f6e..c2e05687c7 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -17,8 +17,8 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitMnode() { return 0; } -void mndCleanupMnode() {} +int32_t mndInitMnode(SMnode *pMnode) { return 0; } +void mndCleanupMnode(SMnode *pMnode) {} void mndGetMnodeEpSetForPeer(SEpSet *epSet, bool redirect) {} void mndGetMnodeEpSetForShell(SEpSet *epSet, bool redirect) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndOper.c b/source/dnode/mnode/impl/src/mndOper.c index aa3a1d5e25..4416a1fc2d 100644 --- a/source/dnode/mnode/impl/src/mndOper.c +++ b/source/dnode/mnode/impl/src/mndOper.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitOper() { return 0; } -void mndCleanupOper() {} \ No newline at end of file +int32_t mndInitOper(SMnode *pMnode) { return 0; } +void mndCleanupOper(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 7c86778eb4..845e50210a 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitProfile() { return 0; } -void mndCleanupProfile() {} \ No newline at end of file +int32_t mndInitProfile(SMnode *pMnode) { return 0; } +void mndCleanupProfile(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 3f97470fd4..9938e95a73 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitShow() { return 0; } -void mndCleanupShow() {} \ No newline at end of file +int32_t mndInitShow(SMnode *pMnode) { return 0; } +void mndCleanupShow(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndStable.c b/source/dnode/mnode/impl/src/mndStable.c index 0a8320c9fa..e54bb17451 100644 --- a/source/dnode/mnode/impl/src/mndStable.c +++ b/source/dnode/mnode/impl/src/mndStable.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitStable() { return 0; } -void mndCleanupStable() {} \ No newline at end of file +int32_t mndInitStable(SMnode *pMnode) { return 0; } +void mndCleanupStable(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 89098e7ec0..a3452d39c9 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -18,8 +18,8 @@ #include "mndInt.h" #include "mndTrans.h" -int32_t mndInitSync() { return 0; } -void mndCleanupSync() {} +int32_t mndInitSync(SMnode *pMnode) { return 0; } +void mndCleanupSync(SMnode *pMnode) {} int32_t mndSyncPropose(SSdbRaw *pRaw, void *pData) { trnApply(pData, pData, 0); diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index f5f5464822..f7fafc7095 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -256,7 +256,7 @@ static void* mndTelemThreadFp(void* param) { if (r == 0) break; if (r != ETIMEDOUT) continue; - if (mndIsMaster()) { + if (mndIsMaster(NULL)) { mndSendTelemetryReport(); } end.tv_sec += REPORT_INTERVAL; @@ -278,7 +278,7 @@ static void mndGetEmail(char* filepath) { taosCloseFile(fd); } -int32_t mndInitTelem() { +int32_t mndInitTelem(SMnode *pMnode) { tsTelem.enable = tsEnableTelemetryReporting; if (!tsTelem.enable) return 0; @@ -303,7 +303,7 @@ int32_t mndInitTelem() { return 0; } -void mndCleanupTelem() { +void mndCleanupTelem(SMnode *pMnode) { if (!tsTelem.enable) return; if (taosCheckPthreadValid(tsTelem.thread)) { diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index ed5a2a7b14..f2fe420013 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -312,7 +312,7 @@ int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { return code; } -int32_t mndInitTrans() { +int32_t mndInitTrans(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_TRANS, .keyType = SDB_KEY_INT32, .encodeFp = (SdbEncodeFp)trnActionEncode, @@ -326,7 +326,7 @@ int32_t mndInitTrans() { return 0; } -void mndCleanupTrans() { mInfo("trn module is cleaned up"); } +void mndCleanupTrans(SMnode *pMnode) { mInfo("trn module is cleaned up"); } int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) { diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 32c2c459e5..bfc2da9118 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -214,7 +214,7 @@ static int32_t mndProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -int32_t mndInitUser() { +int32_t mndInitUser(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_USER, .keyType = SDB_KEY_BINARY, .deployFp = (SdbDeployFp)mndCreateDefaultUsers, @@ -225,9 +225,9 @@ int32_t mndInitUser() { .deleteFp = (SdbDeleteFp)mndUserActionDelete}; sdbSetTable(table); - mndSetMsgHandle(NULL, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg); + mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg); return 0; } -void mndCleanupUser() {} \ No newline at end of file +void mndCleanupUser(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index f7af6e5fa8..b98468b63e 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -17,5 +17,5 @@ #include "os.h" #include "mndInt.h" -int32_t mndInitVgroup() { return 0; } -void mndCleanupVgroup() {} \ No newline at end of file +int32_t mndInitVgroup(SMnode *pMnode) { return 0; } +void mndCleanupVgroup(SMnode *pMnode) {} \ No newline at end of file From 2082e86476bbe7778e289013a7684619f7ad4e05 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 29 Nov 2021 14:01:25 +0800 Subject: [PATCH 11/18] update fst core struct --- source/libs/index/inc/index_fst.h | 2 ++ source/libs/index/src/index_fst.c | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 01be2f8b2b..8f76c2d5cf 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -251,8 +251,10 @@ void fstDestroy(Fst *fst); bool fstGet(Fst *fst, FstSlice *b, Output *out); FstNode* fstGetNode(Fst *fst, CompiledAddr); +FstNode* fstGetRoot(Fst *fst); FstType fstGetType(Fst *fst); CompiledAddr fstGetRootAddr(Fst *fst); + Output fstEmptyFinalOutput(Fst *fst, bool *null); bool fstVerify(Fst *fst); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 1ee364d4ad..94be05d0c1 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -990,15 +990,39 @@ void fstDestroy(Fst *fst) { } bool fstGet(Fst *fst, FstSlice *b, Output *out) { - + FstNode *root = fstGetRoot(fst); + Output tOut = 0; + for (uint32_t i = 0; i < b->dLen; i++) { + uint8_t inp = b->data[i]; + Output res = 0; + bool null = fstNodeFindInput(root, inp, &res); + if (null) { return false; } + + FstTransition trn; + fstNodeGetTransitionAt(root, res, &trn); + tOut += trn.out; + root = fstGetNode(fst, trn.addr); + } + if (!FST_NODE_IS_FINAL(root)) { + return false; + } else { + tOut = tOut + FST_NODE_FINAL_OUTPUT(root); + } + *out = tOut; + return false; } +FstNode *fstGetRoot(Fst *fst) { + CompiledAddr root = fstGetRootAddr(fst); + return fstGetNode(fst, root); +} FstNode* fstGetNode(Fst *fst, CompiledAddr addr) { if (fst->root != NULL) { return fst->root; } fst->root = fstNodeCreate(fst->meta->version, addr, fst->data); + return fst->root; } @@ -1021,7 +1045,6 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) { return res; } - bool fstVerify(Fst *fst) { uint32_t checkSum = fst->meta->checkSum; FstSlice *data = fst->data; From 18c871a9f17b741d51901d3ab120adf80172a330 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 14:14:03 +0800 Subject: [PATCH 12/18] TD-10431 add global variables in sdb --- include/dnode/mnode/sdb/sdb.h | 14 ++- source/dnode/mnode/impl/inc/mndInt.h | 1 + source/dnode/mnode/impl/src/mndAcct.c | 2 +- source/dnode/mnode/impl/src/mndTrans.c | 2 +- source/dnode/mnode/impl/src/mndUser.c | 2 +- source/dnode/mnode/impl/src/mnode.c | 130 ++++++++++++++++--------- source/dnode/mnode/sdb/src/sdb.c | 76 ++++++++------- source/dnode/mnode/sdb/src/sdbFile.c | 40 ++++---- 8 files changed, 159 insertions(+), 108 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 784672e0ec..3f746f2b29 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -126,6 +126,10 @@ typedef enum { SDB_MAX = 12 } ESdbType; +typedef struct SSdbOpt { + const char *path; +} SSdbOpt; + typedef int32_t (*SdbInsertFp)(void *pObj); typedef int32_t (*SdbUpdateFp)(void *pSrcObj, void *pDstObj); typedef int32_t (*SdbDeleteFp)(void *pObj); @@ -146,12 +150,12 @@ typedef struct { typedef struct SSdb SSdb; -int32_t sdbInit(); -void sdbCleanup(); -void sdbSetTable(SSdbTable table); +SSdb *sdbOpen(SSdbOpt *pOption); +void sdbClose(SSdb *pSdb); +void sdbSetTable(SSdb *pSdb, SSdbTable table); -int32_t sdbOpen(); -void sdbClose(); +// int32_t sdbOpen(); +// void sdbClose(); int32_t sdbWrite(SSdbRaw *pRaw); int32_t sdbDeploy(); diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index ac9c715adc..8a870091d4 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -43,6 +43,7 @@ typedef struct SMnode { tmr_h timer; SSdb *pSdb; SDnode *pDnode; + char *path; SArray steps; MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; SendMsgToDnodeFp sendMsgToDnodeFp; diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 0ee290943e..98434482c8 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -110,8 +110,8 @@ int32_t mndInitAcct(SMnode *pMnode) { .insertFp = (SdbInsertFp)mnodeAcctActionInsert, .updateFp = (SdbUpdateFp)mnodeAcctActionUpdate, .deleteFp = (SdbDeleteFp)mnodeAcctActionDelete}; - sdbSetTable(table); + sdbSetTable(pMnode->pSdb, table); return 0; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index f2fe420013..c1c2d9b3d3 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -320,7 +320,7 @@ int32_t mndInitTrans(SMnode *pMnode) { .insertFp = (SdbInsertFp)trnActionInsert, .updateFp = (SdbUpdateFp)trnActionUpdate, .deleteFp = (SdbDeleteFp)trnActionDelete}; - sdbSetTable(table); + sdbSetTable(pMnode->pSdb, table); mInfo("trn module is initialized"); return 0; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index bfc2da9118..c50b220126 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -223,7 +223,7 @@ int32_t mndInitUser(SMnode *pMnode) { .insertFp = (SdbInsertFp)mndUserActionInsert, .updateFp = (SdbUpdateFp)mndUserActionUpdate, .deleteFp = (SdbDeleteFp)mndUserActionDelete}; - sdbSetTable(table); + sdbSetTable(pMnode->pSdb, table); mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 369994c2bb..4459dc2572 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -46,6 +46,12 @@ int64_t mndGetClusterId(SMnode *pMnode) { return -1; } +tmr_h mndGetTimer(SMnode *pMnode) { + if (pMnode != NULL) { + return pMnode->timer; + } +} + void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) { (*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); @@ -83,33 +89,42 @@ static void mndCleanupTimer(SMnode *pMnode) { } } -tmr_h mndGetTimer(SMnode *pMnode) { - if (pMnode != NULL) { - return pMnode->timer; +static int32_t mnodeCreateDir(SMnode *pMnode, const char *path) { + pMnode->path = strdup(path); + if (pMnode->path == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } + + if (taosMkDir(pMnode->path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; + } + + return 0; } -static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { - pMnode->dnodeId = pOption->dnodeId; - pMnode->clusterId = pOption->clusterId; - pMnode->replica = pOption->replica; - pMnode->selfIndex = pOption->selfIndex; - memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); - pMnode->pDnode = pOption->pDnode; - pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp; - pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; - pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; - pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; +static int32_t mndInitSdb(SMnode *pMnode) { + SSdbOpt opt = {0}; + opt.path = pMnode->path; - if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || - pMnode->putMsgToApplyMsgFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0) { - terrno = TSDB_CODE_MND_APP_ERROR; + pMnode->pSdb = sdbOpen(&opt); + if (pMnode->pSdb == NULL) { return -1; } return 0; } +static int32_t mndDeploySdb(SMnode *pMnode) { return sdbDeploy(pMnode->pSdb); } + +static void mndCleanupSdb(SMnode *pMnode) { + if (pMnode->pSdb) { + sdbClose(pMnode->pSdb); + pMnode->pSdb = NULL; + } +} + static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCleanupFp cleanupFp) { SMnodeStep step = {0}; step.name = name; @@ -125,33 +140,28 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle } static int32_t mndInitSteps(SMnode *pMnode) { - if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-stable", mndInitStable, mndCleanupStable) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-sdb", sdbInit, sdbCleanup) != 0) return -1; - - if (pMnode->replica == 1) { - if (mndAllocStep(pMnode, "mnode-deploy-sdb", sdbDeploy, sdbClose) != 0) return -1; - } else { - if (mndAllocStep(pMnode, "mnode-open-sdb", sdbOpen, sdbClose) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-stable", mndInitStable, mndCleanupStable) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return terrno; + if (pMnode->clusterId <= 0) { + if (mndAllocStep(pMnode, "mnode-deploy", mndDeploySdb, NULL) != 0) return terrno; } - - if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-sdb-file", sdbOpen, sdbClose) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-balance", mndInitBalance, mndCleanupBalance) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-balance", mndInitBalance, mndCleanupBalance) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return terrno; return 0; } @@ -194,10 +204,39 @@ static int32_t mndExecSteps(SMnode *pMnode) { } } +static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { + pMnode->dnodeId = pOption->dnodeId; + pMnode->clusterId = pOption->clusterId; + pMnode->replica = pOption->replica; + pMnode->selfIndex = pOption->selfIndex; + memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); + pMnode->pDnode = pOption->pDnode; + pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp; + pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; + pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; + pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; + + if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || + pMnode->putMsgToApplyMsgFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0) { + terrno = TSDB_CODE_MND_APP_ERROR; + return terrno; + } + + return 0; +} + SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { SMnode *pMnode = calloc(1, sizeof(SMnode)); - int32_t code = mndSetOptions(pMnode, pOption); + int32_t code = mnodeCreateDir(pMnode, path); + if (code != 0) { + mError("failed to set mnode options since %s", terrstr()); + mndClose(pMnode); + terrno = code; + return NULL; + } + + code = mndSetOptions(pMnode, pOption); if (code != 0) { mndClose(pMnode); terrno = code; @@ -227,7 +266,8 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { void mndClose(SMnode *pMnode) { mndCleanupSteps(pMnode, -1); - free(pMnode); + tfree(pMnode->path); + tfree(pMnode); mDebug("mnode:%p object is cleaned up", pMnode); } diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 83496f3794..f7af8fb4bd 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -19,27 +19,31 @@ SSdb tsSdb = {0}; -int32_t sdbInit() { +SSdb *sdbOpen(SSdbOpt *pOption) { + SSdb *pSdb = calloc(1, sizeof(SSdb)); + if (pSdb == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + char path[PATH_MAX + 100]; - - snprintf(path, PATH_MAX + 100, "%s%scur%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP); - tsSdb.currDir = strdup(path); - - snprintf(path, PATH_MAX + 100, "%s%ssync%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP); - tsSdb.syncDir = strdup(path); - - snprintf(path, PATH_MAX + 100, "%s%stmp%s", tsMnodeDir, TD_DIRSEP, TD_DIRSEP); - tsSdb.tmpDir = strdup(path); - - if (tsSdb.currDir == NULL || tsSdb.currDir == NULL || tsSdb.currDir == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + snprintf(path, PATH_MAX + 100, "%s%scur%s", pOption->path, TD_DIRSEP, TD_DIRSEP); + pSdb->currDir = strdup(path); + snprintf(path, PATH_MAX + 100, "%s%ssync%s", pOption->path, TD_DIRSEP, TD_DIRSEP); + pSdb->syncDir = strdup(path); + snprintf(path, PATH_MAX + 100, "%s%stmp%s", pOption->path, TD_DIRSEP, TD_DIRSEP); + pSdb->tmpDir = strdup(path); + if (pSdb->currDir == NULL || pSdb->currDir == NULL || pSdb->currDir == NULL) { + sdbClose(pSdb); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; } for (int32_t i = 0; i < SDB_MAX; ++i) { int32_t type; - if (tsSdb.keyTypes[i] == SDB_KEY_INT32) { + if (pSdb->keyTypes[i] == SDB_KEY_INT32) { type = TSDB_DATA_TYPE_INT; - } else if (tsSdb.keyTypes[i] == SDB_KEY_INT64) { + } else if (pSdb->keyTypes[i] == SDB_KEY_INT64) { type = TSDB_DATA_TYPE_BIGINT; } else { type = TSDB_DATA_TYPE_BINARY; @@ -47,45 +51,47 @@ int32_t sdbInit() { SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK); if (hash == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + sdbClose(pSdb); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; } - tsSdb.hashObjs[i] = hash; - taosInitRWLatch(&tsSdb.locks[i]); + pSdb->hashObjs[i] = hash; + taosInitRWLatch(&pSdb->locks[i]); } return 0; } -void sdbCleanup() { - if (tsSdb.currDir != NULL) { - tfree(tsSdb.currDir); +void sdbClose(SSdb *pSdb) { + if (pSdb->currDir != NULL) { + tfree(pSdb->currDir); } - if (tsSdb.syncDir != NULL) { - tfree(tsSdb.syncDir); + if (pSdb->syncDir != NULL) { + tfree(pSdb->syncDir); } - if (tsSdb.tmpDir != NULL) { - tfree(tsSdb.tmpDir); + if (pSdb->tmpDir != NULL) { + tfree(pSdb->tmpDir); } for (int32_t i = 0; i < SDB_MAX; ++i) { - SHashObj *hash = tsSdb.hashObjs[i]; + SHashObj *hash = pSdb->hashObjs[i]; if (hash != NULL) { taosHashCleanup(hash); } - tsSdb.hashObjs[i] = NULL; + pSdb->hashObjs[i] = NULL; } } -void sdbSetTable(SSdbTable table) { +void sdbSetTable(SSdb *pSdb, SSdbTable table) { ESdbType sdb = table.sdbType; - tsSdb.keyTypes[sdb] = table.keyType; - tsSdb.insertFps[sdb] = table.insertFp; - tsSdb.updateFps[sdb] = table.updateFp; - tsSdb.deleteFps[sdb] = table.deleteFp; - tsSdb.deployFps[sdb] = table.deployFp; - tsSdb.encodeFps[sdb] = table.encodeFp; - tsSdb.decodeFps[sdb] = table.decodeFp; + pSdb->keyTypes[sdb] = table.keyType; + pSdb->insertFps[sdb] = table.insertFp; + pSdb->updateFps[sdb] = table.updateFp; + pSdb->deleteFps[sdb] = table.deleteFp; + pSdb->deployFps[sdb] = table.deployFp; + pSdb->encodeFps[sdb] = table.encodeFp; + pSdb->decodeFps[sdb] = table.decodeFp; } \ No newline at end of file diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index d77ec6ef8f..1764dff226 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -212,29 +212,29 @@ static int32_t sdbWriteDataFile() { return code; } -int32_t sdbOpen() { - mDebug("start to read mnode file"); +// int32_t sdbOpen() { +// mDebug("start to read mnode file"); - if (sdbReadDataFile() != 0) { - return -1; - } +// if (sdbReadDataFile() != 0) { +// return -1; +// } - return 0; -} +// return 0; +// } -void sdbClose() { - if (tsSdb.curVer != tsSdb.lastCommitVer) { - mDebug("start to write mnode file"); - sdbWriteDataFile(); - } +// void sdbClose() { +// if (tsSdb.curVer != tsSdb.lastCommitVer) { +// mDebug("start to write mnode file"); +// sdbWriteDataFile(); +// } - for (int32_t i = 0; i < SDB_MAX; ++i) { - SHashObj *hash = tsSdb.hashObjs[i]; - if (hash != NULL) { - taosHashClear(hash); - } - } -} +// for (int32_t i = 0; i < SDB_MAX; ++i) { +// SHashObj *hash = tsSdb.hashObjs[i]; +// if (hash != NULL) { +// taosHashClear(hash); +// } +// } +// } int32_t sdbDeploy() { if (sdbCreateDir() != 0) { @@ -249,7 +249,7 @@ int32_t sdbDeploy() { return -1; } - sdbClose(); + // sdbClose(); return 0; } From 1bf566a701d0f730fe9205327e62816c1eaaf4e9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 15:53:02 +0800 Subject: [PATCH 13/18] TD-10431 remove global variables --- include/dnode/mnode/sdb/sdb.h | 44 +++---- source/dnode/mnode/impl/inc/mndDef.h | 1 + source/dnode/mnode/impl/inc/mndTrans.h | 6 +- source/dnode/mnode/impl/src/mndAcct.c | 16 +-- source/dnode/mnode/impl/src/mndSync.c | 6 +- source/dnode/mnode/impl/src/mndTrans.c | 50 +++---- source/dnode/mnode/impl/src/mndUser.c | 34 ++--- source/dnode/mnode/impl/src/mnode.c | 4 +- source/dnode/mnode/sdb/inc/sdbInt.h | 6 +- source/dnode/mnode/sdb/src/sdb.c | 38 +++++- source/dnode/mnode/sdb/src/sdbFile.c | 172 +++++++++++-------------- source/dnode/mnode/sdb/src/sdbHash.c | 121 +++++++++-------- source/dnode/mnode/sdb/src/sdbRow.c | 2 +- 13 files changed, 251 insertions(+), 249 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 3f746f2b29..2c2d24268e 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -126,14 +126,11 @@ typedef enum { SDB_MAX = 12 } ESdbType; -typedef struct SSdbOpt { - const char *path; -} SSdbOpt; - -typedef int32_t (*SdbInsertFp)(void *pObj); -typedef int32_t (*SdbUpdateFp)(void *pSrcObj, void *pDstObj); -typedef int32_t (*SdbDeleteFp)(void *pObj); -typedef int32_t (*SdbDeployFp)(); +typedef struct SSdb SSdb; +typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj); +typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj); +typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj); +typedef int32_t (*SdbDeployFp)(SSdb*pSdb); typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw); typedef SSdbRaw *(*SdbEncodeFp)(void *pObj); @@ -148,26 +145,23 @@ typedef struct { SdbDeleteFp deleteFp; } SSdbTable; -typedef struct SSdb SSdb; +typedef struct SSdbOpt { + const char *path; +} SSdbOpt; -SSdb *sdbOpen(SSdbOpt *pOption); -void sdbClose(SSdb *pSdb); -void sdbSetTable(SSdb *pSdb, SSdbTable table); +SSdb *sdbOpen(SSdbOpt *pOption); +void sdbClose(SSdb *pSdb); +int32_t sdbDeploy(SSdb *pSdb); +void sdbSetTable(SSdb *pSdb, SSdbTable table); +int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw); -// int32_t sdbOpen(); -// void sdbClose(); -int32_t sdbWrite(SSdbRaw *pRaw); +void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey); +void sdbRelease(SSdb *pSdb, void *pObj); +void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj); +void sdbCancelFetch(SSdb *pSdb, void *pIter); +int32_t sdbGetSize(SSdb *pSdb, ESdbType type); -int32_t sdbDeploy(); -void sdbUnDeploy(); - -void *sdbAcquire(ESdbType sdb, void *pKey); -void sdbRelease(void *pObj); -void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj); -void sdbCancelFetch(void *pIter); -int32_t sdbGetSize(ESdbType sdb); - -SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen); +SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen); void sdbFreeRaw(SSdbRaw *pRaw); int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val); int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index c0d02d3fc4..9b8c6eccc8 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -82,6 +82,7 @@ typedef struct STrans { int32_t id; ETrnStage stage; ETrnPolicy policy; + SMnode *pMnode; void *rpcHandle; SArray *redoLogs; SArray *undoLogs; diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 4443dd2e1c..0a6395c900 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -25,7 +25,7 @@ extern "C" { int32_t mndInitTrans(SMnode *pMnode); void mndCleanupTrans(SMnode *pMnode); -STrans *trnCreate(ETrnPolicy policy, void *rpcHandle); +STrans *trnCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle); void trnDrop(STrans *pTrans); int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw); int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw); @@ -34,8 +34,8 @@ int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *, void *pMsg); int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *, void *pMsg); int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)); -int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code); -int32_t trnExecute(int32_t tranId); +int32_t trnApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code); +int32_t trnExecute(SSdb *pSdb, int32_t tranId); SSdbRaw *trnActionEncode(STrans *pTrans); SSdbRow *trnActionDecode(SSdbRaw *pRaw); diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 98434482c8..b52c7d1e8e 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -48,10 +48,10 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) { return NULL; } - SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); SAcctObj *pAcct = sdbGetRowObj(pRow); if (pAcct == NULL) return NULL; - + int32_t dataPos = 0; SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN) SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime) @@ -68,18 +68,18 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) { return pRow; } -static int32_t mnodeAcctActionInsert(SAcctObj *pAcct) { return 0; } +static int32_t mnodeAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) { return 0; } -static int32_t mnodeAcctActionDelete(SAcctObj *pAcct) { return 0; } +static int32_t mnodeAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { return 0; } -static int32_t mnodeAcctActionUpdate(SAcctObj *pSrcAcct, SAcctObj *pDstAcct) { +static int32_t mnodeAcctActionUpdate(SSdb *pSdb, SAcctObj *pSrcAcct, SAcctObj *pDstAcct) { SAcctObj tObj; int32_t len = (int32_t)((int8_t *)&tObj.info - (int8_t *)&tObj); memcpy(pDstAcct, pSrcAcct, len); return 0; } -static int32_t mnodeCreateDefaultAcct() { +static int32_t mnodeCreateDefaultAcct(SSdb *pSdb) { int32_t code = 0; SAcctObj acctObj = {0}; @@ -98,13 +98,13 @@ static int32_t mnodeCreateDefaultAcct() { if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - return sdbWrite(pRaw); + return sdbWrite(pSdb, pRaw); } int32_t mndInitAcct(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_ACCT, .keyType = SDB_KEY_BINARY, - .deployFp = (SdbDeployFp)mnodeCreateDefaultAcct, + .deployFp = mnodeCreateDefaultAcct, .encodeFp = (SdbEncodeFp)mnodeAcctActionEncode, .decodeFp = (SdbDecodeFp)mnodeAcctActionDecode, .insertFp = (SdbInsertFp)mnodeAcctActionInsert, diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index a3452d39c9..3535dcb677 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -21,10 +21,10 @@ int32_t mndInitSync(SMnode *pMnode) { return 0; } void mndCleanupSync(SMnode *pMnode) {} -int32_t mndSyncPropose(SSdbRaw *pRaw, void *pData) { - trnApply(pData, pData, 0); +int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, void *pData) { + trnApply(pMnode, pData, pData, 0); free(pData); return 0; } -bool mndIsMaster() { return true; } \ No newline at end of file +bool mndIsMaster(SMnode *pMnode) { return true; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index c1c2d9b3d3..168cb27757 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -158,13 +158,13 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) { return pRow; } -static int32_t trnActionInsert(STrans *pTrans) { +static int32_t trnActionInsert(SSdb *pSdb, STrans *pTrans) { SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); for (int32_t index = 0; index < arraySize; ++index) { SSdbRaw *pRaw = taosArrayGet(pArray, index); - int32_t code = sdbWrite(pRaw); + int32_t code = sdbWrite(pSdb, pRaw); if (code != 0) { mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr()); return code; @@ -175,13 +175,13 @@ static int32_t trnActionInsert(STrans *pTrans) { return 0; } -static int32_t trnActionDelete(STrans *pTrans) { +static int32_t trnActionDelete(SSdb *pSdb, STrans *pTrans) { SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); for (int32_t index = 0; index < arraySize; ++index) { SSdbRaw *pRaw = taosArrayGet(pArray, index); - int32_t code = sdbWrite(pRaw); + int32_t code = sdbWrite(pSdb, pRaw); if (code != 0) { mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr()); return code; @@ -192,14 +192,14 @@ static int32_t trnActionDelete(STrans *pTrans) { return 0; } -static int32_t trnActionUpdate(STrans *pTrans, STrans *pDstTrans) { +static int32_t trnActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans) { assert(true); SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); for (int32_t index = 0; index < arraySize; ++index) { SSdbRaw *pRaw = taosArrayGet(pArray, index); - int32_t code = sdbWrite(pRaw); + int32_t code = sdbWrite(pSdb, pRaw); if (code != 0) { mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr()); return code; @@ -213,7 +213,7 @@ static int32_t trnActionUpdate(STrans *pTrans, STrans *pDstTrans) { static int32_t trnGenerateTransId() { return 1; } -STrans *trnCreate(ETrnPolicy policy, void *rpcHandle) { +STrans *trnCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { STrans *pTrans = calloc(1, sizeof(STrans)); if (pTrans == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -339,7 +339,7 @@ int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData) } sdbSetRawStatus(pRaw, SDB_STATUS_CREATING); - if (sdbWrite(pRaw) != 0) { + if (sdbWrite(pTrans->pMnode->pSdb, pRaw) != 0) { mError("trn:%d, failed to write trans since %s", pTrans->id, terrstr()); return -1; } @@ -359,13 +359,13 @@ static void trnSendRpcRsp(void *rpcHandle, int32_t code) { } } -int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code) { +int32_t trnApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code) { if (code != 0) { trnSendRpcRsp(pData, terrno); return 0; } - if (sdbWrite(pData) != 0) { + if (sdbWrite(pMnode->pSdb, pData) != 0) { code = terrno; trnSendRpcRsp(pData, code); terrno = code; @@ -375,10 +375,10 @@ int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code) { return 0; } -static int32_t trnExecuteArray(SArray *pArray) { +static int32_t trnExecuteArray(SMnode *pMnode, SArray *pArray) { for (int32_t index = 0; index < pArray->size; ++index) { SSdbRaw *pRaw = taosArrayGetP(pArray, index); - if (sdbWrite(pRaw) != 0) { + if (sdbWrite(pMnode->pSdb, pRaw) != 0) { return -1; } } @@ -386,15 +386,15 @@ static int32_t trnExecuteArray(SArray *pArray) { return 0; } -static int32_t trnExecuteRedoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->redoLogs); } +static int32_t trnExecuteRedoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->redoLogs); } -static int32_t trnExecuteUndoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->undoLogs); } +static int32_t trnExecuteUndoLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->undoLogs); } -static int32_t trnExecuteCommitLogs(STrans *pTrans) { return trnExecuteArray(pTrans->commitLogs); } +static int32_t trnExecuteCommitLogs(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->commitLogs); } -static int32_t trnExecuteRedoActions(STrans *pTrans) { return trnExecuteArray(pTrans->redoActions); } +static int32_t trnExecuteRedoActions(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->redoActions); } -static int32_t trnExecuteUndoActions(STrans *pTrans) { return trnExecuteArray(pTrans->undoActions); } +static int32_t trnExecuteUndoActions(STrans *pTrans) { return trnExecuteArray(pTrans->pMnode, pTrans->undoActions); } static int32_t trnPerformPrepareStage(STrans *pTrans) { if (trnExecuteRedoLogs(pTrans) == 0) { @@ -454,49 +454,49 @@ static int32_t trnPerformRetryStage(STrans *pTrans) { } } -int32_t trnExecute(int32_t tranId) { +int32_t trnExecute(SSdb *pSdb, int32_t tranId) { int32_t code = 0; - STrans *pTrans = sdbAcquire(SDB_TRANS, &tranId); + STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &tranId); if (pTrans == NULL) { return -1; } if (pTrans->stage == TRN_STAGE_PREPARE) { if (trnPerformPrepareStage(pTrans) != 0) { - sdbRelease(pTrans); + sdbRelease(pSdb, pTrans); return -1; } } if (pTrans->stage == TRN_STAGE_EXECUTE) { if (trnPerformExecuteStage(pTrans) != 0) { - sdbRelease(pTrans); + sdbRelease(pSdb, pTrans); return -1; } } if (pTrans->stage == TRN_STAGE_COMMIT) { if (trnPerformCommitStage(pTrans) != 0) { - sdbRelease(pTrans); + sdbRelease(pSdb, pTrans); return -1; } } if (pTrans->stage == TRN_STAGE_ROLLBACK) { if (trnPerformRollbackStage(pTrans) != 0) { - sdbRelease(pTrans); + sdbRelease(pSdb, pTrans); return -1; } } if (pTrans->stage == TRN_STAGE_RETRY) { if (trnPerformRetryStage(pTrans) != 0) { - sdbRelease(pTrans); + sdbRelease(pSdb, pTrans); return -1; } } - sdbRelease(pTrans); + sdbRelease(pSdb, pTrans); return 0; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index c50b220126..95c1a75ced 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -60,14 +60,14 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { return pRow; } -static int32_t mndUserActionInsert(SUserObj *pUser) { +static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pUser->prohibitDbHash == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pUser->pAcct = sdbAcquire(SDB_ACCT, pUser->acct); + pUser->pAcct = sdbAcquire(pSdb, SDB_ACCT, pUser->acct); if (pUser->pAcct == NULL) { terrno = TSDB_CODE_MND_ACCT_NOT_EXIST; return -1; @@ -76,28 +76,28 @@ static int32_t mndUserActionInsert(SUserObj *pUser) { return 0; } -static int32_t mndUserActionDelete(SUserObj *pUser) { +static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { if (pUser->prohibitDbHash) { taosHashCleanup(pUser->prohibitDbHash); pUser->prohibitDbHash = NULL; } if (pUser->acct != NULL) { - sdbRelease(pUser->pAcct); + sdbRelease(pSdb, pUser->pAcct); pUser->pAcct = NULL; } return 0; } -static int32_t mndUserActionUpdate(SUserObj *pSrcUser, SUserObj *pDstUser) { +static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDstUser) { SUserObj tObj; int32_t len = (int32_t)((int8_t *)tObj.prohibitDbHash - (int8_t *)&tObj); memcpy(pDstUser, pSrcUser, len); return 0; } -static int32_t mndCreateDefaultUser(char *acct, char *user, char *pass) { +static int32_t mndCreateDefaultUser(SSdb *pSdb, char *acct, char *user, char *pass) { SUserObj userObj = {0}; tstrncpy(userObj.user, user, TSDB_USER_LEN); tstrncpy(userObj.acct, acct, TSDB_USER_LEN); @@ -113,22 +113,22 @@ static int32_t mndCreateDefaultUser(char *acct, char *user, char *pass) { if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - return sdbWrite(pRaw); + return sdbWrite(pSdb, pRaw); } -static int32_t mndCreateDefaultUsers() { - if (mndCreateDefaultUser(TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { +static int32_t mndCreateDefaultUsers(SSdb *pSdb) { + if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { return -1; } - if (mndCreateDefaultUser(TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { + if (mndCreateDefaultUser(pSdb, TSDB_DEFAULT_USER, "_" TSDB_DEFAULT_USER, TSDB_DEFAULT_PASS) != 0) { return -1; } return 0; } -static int32_t mndCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pMsg) { +static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg) { SUserObj userObj = {0}; tstrncpy(userObj.user, user, TSDB_USER_LEN); tstrncpy(userObj.acct, acct, TSDB_USER_LEN); @@ -137,7 +137,7 @@ static int32_t mndCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pMsg userObj.updateTime = userObj.createdTime; userObj.rootAuth = 0; - STrans *pTrans = trnCreate(TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = trnCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); if (pTrans == NULL) return -1; SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj); @@ -188,23 +188,23 @@ static int32_t mndProcessCreateUserMsg(SMnode *pMnode, SMnodeMsg *pMsg) { return -1; } - SUserObj *pUser = sdbAcquire(SDB_USER, pCreate->user); + SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user); if (pUser != NULL) { - sdbRelease(pUser); + sdbRelease(pMnode->pSdb, pUser); terrno = TSDB_CODE_MND_USER_ALREADY_EXIST; mError("user:%s, failed to create since %s", pCreate->user, terrstr()); return -1; } - SUserObj *pOperUser = sdbAcquire(SDB_USER, pMsg->conn.user); + SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->conn.user); if (pOperUser == NULL) { terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; mError("user:%s, failed to create since %s", pCreate->user, terrstr()); return -1; } - int32_t code = mndCreateUser(pOperUser->acct, pCreate->user, pCreate->pass, pMsg); - sdbRelease(pOperUser); + int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg); + sdbRelease(pMnode->pSdb, pOperUser); if (code != 0) { mError("user:%s, failed to create since %s", pCreate->user, terrstr()); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 4459dc2572..9217fa7194 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -278,7 +278,7 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { void mndDestroy(const char *path) { mDebug("mnode in %s will be destroyed", path); - sdbUnDeploy(); + taosRemoveDir(path); } int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { @@ -308,7 +308,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { void mndCleanupMsg(SMnodeMsg *pMsg) { if (pMsg->pUser != NULL) { - sdbRelease(pMsg->pUser); + sdbRelease(pMsg->pMnode->pSdb, pMsg->pUser); } taosFreeQitem(pMsg); diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 2b3c577ba9..5c25349b5c 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -69,9 +69,9 @@ typedef struct SSdb { SdbDecodeFp decodeFps[SDB_MAX]; } SSdb; -extern SSdb tsSdb; - -int32_t sdbWriteImp(SSdbRaw *pRaw); +int32_t sdbReadFile(SSdb *pSdb); +int32_t sdbWriteFile(SSdb *pSdb); +int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw); #ifdef __cplusplus } diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index f7af8fb4bd..c4c6a553f7 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -15,27 +15,28 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" -#include "tglobal.h" - -SSdb tsSdb = {0}; SSdb *sdbOpen(SSdbOpt *pOption) { + mDebug("start to open sdb in %s", pOption->path); + SSdb *pSdb = calloc(1, sizeof(SSdb)); if (pSdb == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to open sdb since %s", terrstr()); return NULL; } char path[PATH_MAX + 100]; - snprintf(path, PATH_MAX + 100, "%s%scur%s", pOption->path, TD_DIRSEP, TD_DIRSEP); + snprintf(path, PATH_MAX + 100, "%s%scur", pOption->path, TD_DIRSEP); pSdb->currDir = strdup(path); - snprintf(path, PATH_MAX + 100, "%s%ssync%s", pOption->path, TD_DIRSEP, TD_DIRSEP); + snprintf(path, PATH_MAX + 100, "%s%ssync", pOption->path, TD_DIRSEP); pSdb->syncDir = strdup(path); - snprintf(path, PATH_MAX + 100, "%s%stmp%s", pOption->path, TD_DIRSEP, TD_DIRSEP); + snprintf(path, PATH_MAX + 100, "%s%stmp", pOption->path, TD_DIRSEP); pSdb->tmpDir = strdup(path); if (pSdb->currDir == NULL || pSdb->currDir == NULL || pSdb->currDir == NULL) { sdbClose(pSdb); terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to open sdb since %s", terrstr()); return NULL; } @@ -53,6 +54,7 @@ SSdb *sdbOpen(SSdbOpt *pOption) { if (hash == NULL) { sdbClose(pSdb); terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to open sdb since %s", terrstr()); return NULL; } @@ -60,10 +62,27 @@ SSdb *sdbOpen(SSdbOpt *pOption) { taosInitRWLatch(&pSdb->locks[i]); } - return 0; + int32_t code = sdbReadFile(pSdb); + if (code != 0) { + sdbClose(pSdb); + terrno = code; + mError("failed to open sdb since %s", terrstr()); + return NULL; + } + + mDebug("sdb open successfully"); + return pSdb; } void sdbClose(SSdb *pSdb) { + mDebug("start to close sdb"); + + if (pSdb->curVer != pSdb->lastCommitVer) { + mDebug("start to write sdb file since curVer:% " PRId64 " and lastCommitVer:%" PRId64 " inequal", pSdb->curVer, + pSdb->lastCommitVer); + sdbWriteFile(pSdb); + } + if (pSdb->currDir != NULL) { tfree(pSdb->currDir); } @@ -79,10 +98,13 @@ void sdbClose(SSdb *pSdb) { for (int32_t i = 0; i < SDB_MAX; ++i) { SHashObj *hash = pSdb->hashObjs[i]; if (hash != NULL) { + taosHashClear(hash); taosHashCleanup(hash); } pSdb->hashObjs[i] = NULL; } + + mDebug("sdb is closed"); } void sdbSetTable(SSdb *pSdb, SSdbTable table) { @@ -94,4 +116,6 @@ void sdbSetTable(SSdb *pSdb, SSdbTable table) { pSdb->deployFps[sdb] = table.deployFp; pSdb->encodeFps[sdb] = table.encodeFp; pSdb->decodeFps[sdb] = table.decodeFp; + + mDebug("set sdb handle of table %d", pSdb, table); } \ No newline at end of file diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 1764dff226..fbbb602882 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -15,71 +15,75 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" -#include "tglobal.h" #include "tchecksum.h" -static int32_t sdbCreateDir() { - mDebug("start to create mnode at %s", tsMnodeDir); - - if (taosMkDir(tsSdb.currDir) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", tsSdb.currDir, terrstr()); - return -1; +static int32_t sdbCreateDir(SSdb *pSdb) { + int32_t code = taosMkDir(pSdb->currDir); + if (code != 0) { + code = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->currDir, tstrerror(code)); + return code; } - if (taosMkDir(tsSdb.syncDir) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", tsSdb.syncDir, terrstr()); - return -1; + code = taosMkDir(pSdb->syncDir); + if (code != 0) { + code = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->syncDir, tstrerror(code)); + return code; } - if (taosMkDir(tsSdb.tmpDir) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", tsSdb.tmpDir, terrstr()); - return -1; + code = taosMkDir(pSdb->tmpDir); + if (code != 0) { + code = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->tmpDir, tstrerror(code)); + return code; } return 0; } -static int32_t sdbRunDeployFp() { - mDebug("start to run deploy functions"); +static int32_t sdbRunDeployFp(SSdb *pSdb) { + mDebug("start to run sdb deploy functions"); for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) { - SdbDeployFp fp = tsSdb.deployFps[i]; + SdbDeployFp fp = pSdb->deployFps[i]; if (fp == NULL) continue; - if ((*fp)() != 0) { - mError("failed to deploy sdb:%d since %s", i, terrstr()); - return -1; + + int32_t code = (*fp)(pSdb); + if (code != 0) { + mError("failed to deploy sdb:%d since %s", i, tstrerror(code)); + return code; } } - mDebug("end of run deploy functions"); + mDebug("sdb deploy functions run finished"); return 0; } -static int32_t sdbReadDataFile() { - SSdbRaw *pRaw = malloc(SDB_MAX_SIZE); - if (pRaw == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - char file[PATH_MAX] = {0}; - snprintf(file, sizeof(file), "%ssdb.data", tsSdb.currDir); - FileFd fd = taosOpenFileRead(file); - if (fd <= 0) { - free(pRaw); - terrno = TAOS_SYSTEM_ERROR(errno); - mError("failed to open file:%s for read since %s", file, terrstr()); - return -1; - } - +int32_t sdbReadFile(SSdb *pSdb) { int64_t offset = 0; int32_t code = 0; int32_t readLen = 0; int64_t ret = 0; + SSdbRaw *pRaw = malloc(SDB_MAX_SIZE); + if (pRaw == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + mError("failed read file since %s", tstrerror(code)); + return code; + } + + char file[PATH_MAX] = {0}; + snprintf(file, sizeof(file), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); + + FileFd fd = taosOpenFileRead(file); + if (fd <= 0) { + free(pRaw); + code = TAOS_SYSTEM_ERROR(errno); + mError("failed to read file:%s since %s", file, tstrerror(code)); + return code; + } + while (1) { readLen = sizeof(SSdbRaw); ret = taosReadFile(fd, pRaw, readLen); @@ -118,7 +122,7 @@ static int32_t sdbReadDataFile() { break; } - code = sdbWriteImp(pRaw); + code = sdbWriteRaw(pSdb, pRaw); if (code != 0) { mError("failed to read file:%s since %s", file, terrstr()); goto PARSE_SDB_DATA_ERROR; @@ -130,29 +134,31 @@ static int32_t sdbReadDataFile() { PARSE_SDB_DATA_ERROR: taosCloseFile(fd); sdbFreeRaw(pRaw); - terrno = code; + return code; } -static int32_t sdbWriteDataFile() { +int32_t sdbWriteFile(SSdb *pSdb) { + int32_t code = 0; + char tmpfile[PATH_MAX] = {0}; - snprintf(tmpfile, sizeof(tmpfile), "%ssdb.data", tsSdb.tmpDir); + snprintf(tmpfile, sizeof(tmpfile), "%ssdb.data", pSdb->tmpDir); + char curfile[PATH_MAX] = {0}; + snprintf(curfile, sizeof(curfile), "%ssdb.data", pSdb->currDir); FileFd fd = taosOpenFileCreateWrite(tmpfile); if (fd <= 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - mError("failed to open file:%s for write since %s", tmpfile, terrstr()); - return -1; + code = TAOS_SYSTEM_ERROR(errno); + mError("failed to open file:%s for write since %s", tmpfile, tstrerror(code)); + return code; } - int32_t code = 0; - for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) { - SdbEncodeFp encodeFp = tsSdb.encodeFps[i]; + SdbEncodeFp encodeFp = pSdb->encodeFps[i]; if (encodeFp == NULL) continue; - SHashObj *hash = tsSdb.hashObjs[i]; - SRWLatch *pLock = &tsSdb.locks[i]; + SHashObj *hash = pSdb->hashObjs[i]; + SRWLatch *pLock = &pSdb->locks[i]; taosWLockLatch(pLock); SSdbRow **ppRow = taosHashIterate(hash, NULL); @@ -192,68 +198,46 @@ static int32_t sdbWriteDataFile() { if (code == 0) { code = taosFsyncFile(fd); + if (code != 0) { + code = TAOS_SYSTEM_ERROR(errno); + mError("failed to write file:%s since %s", tmpfile, tstrerror(code)); + } } taosCloseFile(fd); if (code == 0) { - char curfile[PATH_MAX] = {0}; - snprintf(curfile, sizeof(curfile), "%ssdb.data", tsSdb.currDir); code = taosRenameFile(tmpfile, curfile); + if (code != 0) { + code = TAOS_SYSTEM_ERROR(errno); + mError("failed to write file:%s since %s", curfile, tstrerror(code)); + } } if (code != 0) { - terrno = code; - mError("failed to write sdb file since %s", terrstr()); + mError("failed to write file:%s since %s", curfile, tstrerror(code)); } else { - mDebug("write sdb file successfully"); + mDebug("write file:%s successfully", curfile); } return code; } -// int32_t sdbOpen() { -// mDebug("start to read mnode file"); - -// if (sdbReadDataFile() != 0) { -// return -1; -// } - -// return 0; -// } - -// void sdbClose() { -// if (tsSdb.curVer != tsSdb.lastCommitVer) { -// mDebug("start to write mnode file"); -// sdbWriteDataFile(); -// } - -// for (int32_t i = 0; i < SDB_MAX; ++i) { -// SHashObj *hash = tsSdb.hashObjs[i]; -// if (hash != NULL) { -// taosHashClear(hash); -// } -// } -// } - -int32_t sdbDeploy() { - if (sdbCreateDir() != 0) { - return -1; +int32_t sdbDeploy(SSdb *pSdb) { + int32_t code = sdbCreateDir(pSdb); + if (code != 0) { + return code; } - if (sdbRunDeployFp() != 0) { - return -1; + code = sdbRunDeployFp(pSdb); + if (code != 0) { + return code; } - if (sdbWriteDataFile() != 0) { - return -1; + code = sdbWriteFile(pSdb); + if (code != 0) { + return code; } - // sdbClose(); return 0; } - -void sdbUnDeploy() { - mDebug("start to undeploy mnode"); - taosRemoveDir(tsMnodeDir); -} diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 9c19e7f1a2..1ac983d538 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -15,15 +15,14 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" -#include "tglobal.h" -static SHashObj *sdbGetHash(int32_t sdb) { - if (sdb >= SDB_MAX || sdb <= SDB_START) { +static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) { + if (type >= SDB_MAX || type <= SDB_START) { terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE; return NULL; } - SHashObj *hash = tsSdb.hashObjs[sdb]; + SHashObj *hash = pSdb->hashObjs[type]; if (hash == NULL) { terrno = TSDB_CODE_SDB_APP_ERROR; return NULL; @@ -32,9 +31,9 @@ static SHashObj *sdbGetHash(int32_t sdb) { return hash; } -static int32_t sdbGetkeySize(ESdbType sdb, void *pKey) { +static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) { int32_t keySize; - EKeyType keyType = tsSdb.keyTypes[sdb]; + EKeyType keyType = pSdb->keyTypes[type]; if (keyType == SDB_KEY_INT32) { keySize = sizeof(int32_t); @@ -47,77 +46,81 @@ static int32_t sdbGetkeySize(ESdbType sdb, void *pKey) { return keySize; } -static int32_t sdbInsertRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - SRWLatch *pLock = &tsSdb.locks[pRow->sdb]; +static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { + int32_t code = 0; + + SRWLatch *pLock = &pSdb->locks[pRow->sdb]; taosWLockLatch(pLock); SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize); if (pDstRow != NULL) { - terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE; taosWUnLockLatch(pLock); sdbFreeRow(pRow); - return -1; + return TSDB_CODE_SDB_OBJ_ALREADY_THERE; } pRow->refCount = 1; pRow->status = pRaw->status; if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; taosWUnLockLatch(pLock); sdbFreeRow(pRow); - return -1; + return TSDB_CODE_SDB_OBJ_ALREADY_THERE; } taosWUnLockLatch(pLock); - SdbInsertFp insertFp = tsSdb.insertFps[pRow->sdb]; + SdbInsertFp insertFp = pSdb->insertFps[pRow->sdb]; if (insertFp != NULL) { - if ((*insertFp)(pRow->pObj) != 0) { + code = (*insertFp)(pSdb, pRow->pObj); + if (code != 0) { taosWLockLatch(pLock); taosHashRemove(hash, pRow->pObj, keySize); taosWUnLockLatch(pLock); sdbFreeRow(pRow); - return -1; + return code; } } return 0; } -static int32_t sdbUpdateRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - SRWLatch *pLock = &tsSdb.locks[pRow->sdb]; +static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { + int32_t code = 0; + + SRWLatch *pLock = &pSdb->locks[pRow->sdb]; taosRLockLatch(pLock); SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize); if (ppDstRow == NULL || *ppDstRow == NULL) { taosRUnLockLatch(pLock); - return sdbInsertRow(hash, pRaw, pRow, keySize); + return sdbInsertRow(pSdb, hash, pRaw, pRow, keySize); } SSdbRow *pDstRow = *ppDstRow; pRow->status = pRaw->status; taosRUnLockLatch(pLock); - SdbUpdateFp updateFp = tsSdb.updateFps[pRow->sdb]; + SdbUpdateFp updateFp = pSdb->updateFps[pRow->sdb]; if (updateFp != NULL) { - (*updateFp)(pRow->pObj, pDstRow->pObj); + code = (*updateFp)(pSdb, pRow->pObj, pDstRow->pObj); } sdbFreeRow(pRow); - return 0; + return code; } -static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - SRWLatch *pLock = &tsSdb.locks[pRow->sdb]; +static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { + int32_t code = 0; + + SRWLatch *pLock = &pSdb->locks[pRow->sdb]; taosWLockLatch(pLock); SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize); if (ppDstRow == NULL || *ppDstRow == NULL) { - terrno = TSDB_CODE_SDB_OBJ_NOT_THERE; taosWUnLockLatch(pLock); sdbFreeRow(pRow); - return -1; + return TSDB_CODE_SDB_OBJ_NOT_THERE; } SSdbRow *pDstRow = *ppDstRow; @@ -125,71 +128,67 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ taosHashRemove(hash, pDstRow->pObj, keySize); taosWUnLockLatch(pLock); - SdbDeleteFp deleteFp = tsSdb.deleteFps[pDstRow->sdb]; + SdbDeleteFp deleteFp = pSdb->deleteFps[pDstRow->sdb]; if (deleteFp != NULL) { - (void)(*deleteFp)(pDstRow->pObj); + code = (*deleteFp)(pSdb, pDstRow->pObj); } - sdbRelease(pDstRow->pObj); + sdbRelease(pSdb, pDstRow->pObj); sdbFreeRow(pRow); - return 0; + return code; } -int32_t sdbWriteImp(SSdbRaw *pRaw) { - SHashObj *hash = sdbGetHash(pRaw->sdb); - if (hash == NULL) return -1; +int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw) { + SHashObj *hash = sdbGetHash(pSdb, pRaw->sdb); + if (hash == NULL) return terrno; - SdbDecodeFp decodeFp = tsSdb.decodeFps[pRaw->sdb]; + SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->sdb]; SSdbRow *pRow = (*decodeFp)(pRaw); if (pRow == NULL) { - terrno = TSDB_CODE_SDB_INVALID_DATA_CONTENT; - return -1; + return terrno; } pRow->sdb = pRaw->sdb; - int32_t keySize = sdbGetkeySize(pRow->sdb, pRow->pObj); - int32_t code = -1; + int32_t keySize = sdbGetkeySize(pSdb, pRow->sdb, pRow->pObj); + int32_t code = TSDB_CODE_SDB_INVALID_ACTION_TYPE; switch (pRaw->status) { case SDB_STATUS_CREATING: - code = sdbInsertRow(hash, pRaw, pRow, keySize); + code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize); break; case SDB_STATUS_READY: case SDB_STATUS_DROPPING: - code = sdbUpdateRow(hash, pRaw, pRow, keySize); + code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize); break; case SDB_STATUS_DROPPED: - code = sdbDeleteRow(hash, pRaw, pRow, keySize); - break; - default: - terrno = TSDB_CODE_SDB_INVALID_ACTION_TYPE; + code = sdbDeleteRow(pSdb, hash, pRaw, pRow, keySize); break; } return code; } -int32_t sdbWrite(SSdbRaw *pRaw) { - int32_t code = sdbWriteImp(pRaw); +int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) { + int32_t code = sdbWriteRaw(pSdb, pRaw); sdbFreeRaw(pRaw); return code; } -void *sdbAcquire(ESdbType sdb, void *pKey) { - SHashObj *hash = sdbGetHash(sdb); +void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) { + SHashObj *hash = sdbGetHash(pSdb, type); if (hash == NULL) return NULL; void *pRet = NULL; - int32_t keySize = sdbGetkeySize(sdb, pKey); + int32_t keySize = sdbGetkeySize(pSdb, type, pKey); - SRWLatch *pLock = &tsSdb.locks[sdb]; + SRWLatch *pLock = &pSdb->locks[type]; taosRLockLatch(pLock); SSdbRow **ppRow = taosHashGet(hash, pKey, keySize); if (ppRow == NULL || *ppRow == NULL) { - terrno = TSDB_CODE_SDB_OBJ_NOT_THERE; taosRUnLockLatch(pLock); + terrno = TSDB_CODE_SDB_OBJ_NOT_THERE; return NULL; } @@ -214,13 +213,13 @@ void *sdbAcquire(ESdbType sdb, void *pKey) { return pRet; } -void sdbRelease(void *pObj) { +void sdbRelease(SSdb *pSdb, void *pObj) { if (pObj == NULL) return; SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow)); if (pRow->sdb >= SDB_MAX || pRow->sdb <= SDB_START) return; - SRWLatch *pLock = &tsSdb.locks[pRow->sdb]; + SRWLatch *pLock = &pSdb->locks[pRow->sdb]; taosRLockLatch(pLock); int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1); @@ -231,11 +230,11 @@ void sdbRelease(void *pObj) { taosRUnLockLatch(pLock); } -void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) { - SHashObj *hash = sdbGetHash(sdb); +void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { + SHashObj *hash = sdbGetHash(pSdb, type); if (hash == NULL) return NULL; - SRWLatch *pLock = &tsSdb.locks[sdb]; + SRWLatch *pLock = &pSdb->locks[type]; taosRLockLatch(pLock); SSdbRow **ppRow = taosHashIterate(hash, ppRow); @@ -255,23 +254,23 @@ void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) { return ppRow; } -void sdbCancelFetch(void *pIter) { +void sdbCancelFetch(SSdb *pSdb, void *pIter) { if (pIter == NULL) return; SSdbRow *pRow = *(SSdbRow **)pIter; - SHashObj *hash = sdbGetHash(pRow->sdb); + SHashObj *hash = sdbGetHash(pSdb, pRow->sdb); if (hash == NULL) return; - SRWLatch *pLock = &tsSdb.locks[pRow->sdb]; + SRWLatch *pLock = &pSdb->locks[pRow->sdb]; taosRLockLatch(pLock); taosHashCancelIterate(hash, pIter); taosRUnLockLatch(pLock); } -int32_t sdbGetSize(ESdbType sdb) { - SHashObj *hash = sdbGetHash(sdb); +int32_t sdbGetSize(SSdb *pSdb, ESdbType type) { + SHashObj *hash = sdbGetHash(pSdb, type); if (hash == NULL) return 0; - SRWLatch *pLock = &tsSdb.locks[sdb]; + SRWLatch *pLock = &pSdb->locks[type]; taosRLockLatch(pLock); int32_t size = taosHashGetSize(hash); taosRUnLockLatch(pLock); diff --git a/source/dnode/mnode/sdb/src/sdbRow.c b/source/dnode/mnode/sdb/src/sdbRow.c index 68a0faa7b9..ec1dcf39e6 100644 --- a/source/dnode/mnode/sdb/src/sdbRow.c +++ b/source/dnode/mnode/sdb/src/sdbRow.c @@ -35,4 +35,4 @@ void *sdbGetRowObj(SSdbRow *pRow) { return pRow->pObj; } -void sdbFreeRow(SSdbRow *pRow) { free(pRow); } +void sdbFreeRow(SSdbRow *pRow) { tfree(pRow); } From c7451a9949e1775a90de264f1133e27aff79cace Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 16:02:37 +0800 Subject: [PATCH 14/18] TD-10431 rename variables --- source/dnode/mnode/impl/inc/mndTrans.h | 24 +++++------ source/dnode/mnode/impl/src/mndSync.c | 2 +- source/dnode/mnode/impl/src/mndTrans.c | 58 +++++++++++++------------- source/dnode/mnode/impl/src/mndUser.c | 20 ++++----- 4 files changed, 52 insertions(+), 52 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 0a6395c900..745c0a0447 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -25,20 +25,20 @@ extern "C" { int32_t mndInitTrans(SMnode *pMnode); void mndCleanupTrans(SMnode *pMnode); -STrans *trnCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle); -void trnDrop(STrans *pTrans); -int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw); -int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw); -int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw); -int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *, void *pMsg); -int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *, void *pMsg); +STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle); +void mndTransDrop(STrans *pTrans); +int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw); +int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw); +int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw); +int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *, void *pMsg); +int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *, void *pMsg); -int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)); -int32_t trnApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code); -int32_t trnExecute(SSdb *pSdb, int32_t tranId); +int32_t mndTransPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)); +int32_t mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code); +int32_t mndTransExecute(SSdb *pSdb, int32_t tranId); -SSdbRaw *trnActionEncode(STrans *pTrans); -SSdbRow *trnActionDecode(SSdbRaw *pRaw); +SSdbRaw *mndTransActionEncode(STrans *pTrans); +SSdbRow *mndTransActionDecode(SSdbRaw *pRaw); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 3535dcb677..7231915311 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -22,7 +22,7 @@ int32_t mndInitSync(SMnode *pMnode) { return 0; } void mndCleanupSync(SMnode *pMnode) {} int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, void *pData) { - trnApply(pMnode, pData, pData, 0); + mndTransApply(pMnode, pData, pData, 0); free(pData); return 0; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 168cb27757..91d0f20013 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -20,7 +20,7 @@ #define SDB_TRANS_VER 1 #define TRN_DEFAULT_ARRAY_SIZE 8 -SSdbRaw *trnActionEncode(STrans *pTrans) { +SSdbRaw *mndTransActionEncode(STrans *pTrans) { int32_t rawDataLen = 10 * sizeof(int32_t); int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs); int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs); @@ -84,7 +84,7 @@ SSdbRaw *trnActionEncode(STrans *pTrans) { return pRaw; } -SSdbRow *trnActionDecode(SSdbRaw *pRaw) { +SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { int8_t sver = 0; if (sdbGetRawSoftVer(pRaw, &sver) != 0) { mError("failed to get soft ver from raw:%p since %s", pRaw, terrstr()); @@ -150,7 +150,7 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) { if (code != 0) { terrno = code; mError("trn:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr()); - trnDrop(pTrans); + mndTransDrop(pTrans); return NULL; } @@ -158,7 +158,7 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) { return pRow; } -static int32_t trnActionInsert(SSdb *pSdb, STrans *pTrans) { +static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); @@ -175,7 +175,7 @@ static int32_t trnActionInsert(SSdb *pSdb, STrans *pTrans) { return 0; } -static int32_t trnActionDelete(SSdb *pSdb, STrans *pTrans) { +static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); @@ -192,7 +192,7 @@ static int32_t trnActionDelete(SSdb *pSdb, STrans *pTrans) { return 0; } -static int32_t trnActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans) { +static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans) { assert(true); SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); @@ -213,7 +213,7 @@ static int32_t trnActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTrans) { static int32_t trnGenerateTransId() { return 1; } -STrans *trnCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { +STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { STrans *pTrans = calloc(1, sizeof(STrans)); if (pTrans == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -251,7 +251,7 @@ static void trnDropArray(SArray *pArray) { taosArrayDestroy(pArray); } -void trnDrop(STrans *pTrans) { +void mndTransDrop(STrans *pTrans) { trnDropArray(pTrans->redoLogs); trnDropArray(pTrans->undoLogs); trnDropArray(pTrans->commitLogs); @@ -262,12 +262,12 @@ void trnDrop(STrans *pTrans) { tfree(pTrans); } -void trnSetRpcHandle(STrans *pTrans, void *rpcHandle) { +void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) { pTrans->rpcHandle = rpcHandle; mTrace("trn:%d, set rpc handle:%p", pTrans->id, rpcHandle); } -static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) { +static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) { if (pArray == NULL || pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -282,32 +282,32 @@ static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) { return 0; } -int32_t trnAppendRedoLog(STrans *pTrans, SSdbRaw *pRaw) { - int32_t code = trnAppendArray(pTrans->redoLogs, pRaw); +int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) { + int32_t code = mndTransAppendArray(pTrans->redoLogs, pRaw); mTrace("trn:%d, raw:%p append to redo logs, code:%d", pTrans->id, pRaw, code); return code; } -int32_t trnAppendUndoLog(STrans *pTrans, SSdbRaw *pRaw) { - int32_t code = trnAppendArray(pTrans->undoLogs, pRaw); +int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) { + int32_t code = mndTransAppendArray(pTrans->undoLogs, pRaw); mTrace("trn:%d, raw:%p append to undo logs, code:%d", pTrans->id, pRaw, code); return code; } -int32_t trnAppendCommitLog(STrans *pTrans, SSdbRaw *pRaw) { - int32_t code = trnAppendArray(pTrans->commitLogs, pRaw); +int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) { + int32_t code = mndTransAppendArray(pTrans->commitLogs, pRaw); mTrace("trn:%d, raw:%p append to commit logs, code:%d", pTrans->id, pRaw, code); return code; } -int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { - int32_t code = trnAppendArray(pTrans->redoActions, pMsg); +int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { + int32_t code = mndTransAppendArray(pTrans->redoActions, pMsg); mTrace("trn:%d, msg:%p append to redo actions", pTrans->id, pMsg); return code; } -int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { - int32_t code = trnAppendArray(pTrans->undoActions, pMsg); +int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { + int32_t code = mndTransAppendArray(pTrans->undoActions, pMsg); mTrace("trn:%d, msg:%p append to undo actions", pTrans->id, pMsg); return code; } @@ -315,11 +315,11 @@ int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) { int32_t mndInitTrans(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_TRANS, .keyType = SDB_KEY_INT32, - .encodeFp = (SdbEncodeFp)trnActionEncode, - .decodeFp = (SdbDecodeFp)trnActionDecode, - .insertFp = (SdbInsertFp)trnActionInsert, - .updateFp = (SdbUpdateFp)trnActionUpdate, - .deleteFp = (SdbDeleteFp)trnActionDelete}; + .encodeFp = (SdbEncodeFp)mndTransActionEncode, + .decodeFp = (SdbDecodeFp)mndTransActionDecode, + .insertFp = (SdbInsertFp)mndTransActionInsert, + .updateFp = (SdbUpdateFp)mndTransActionUpdate, + .deleteFp = (SdbDeleteFp)mndTransActionDelete}; sdbSetTable(pMnode->pSdb, table); mInfo("trn module is initialized"); @@ -329,10 +329,10 @@ int32_t mndInitTrans(SMnode *pMnode) { void mndCleanupTrans(SMnode *pMnode) { mInfo("trn module is cleaned up"); } -int32_t trnPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) { +int32_t mndTransPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) { if (syncfp == NULL) return -1; - SSdbRaw *pRaw = trnActionEncode(pTrans); + SSdbRaw *pRaw = mndTransActionEncode(pTrans); if (pRaw == NULL) { mError("trn:%d, failed to decode trans since %s", pTrans->id, terrstr()); return -1; @@ -359,7 +359,7 @@ static void trnSendRpcRsp(void *rpcHandle, int32_t code) { } } -int32_t trnApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code) { +int32_t mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code) { if (code != 0) { trnSendRpcRsp(pData, terrno); return 0; @@ -454,7 +454,7 @@ static int32_t trnPerformRetryStage(STrans *pTrans) { } } -int32_t trnExecute(SSdb *pSdb, int32_t tranId) { +int32_t mndTransExecute(SSdb *pSdb, int32_t tranId) { int32_t code = 0; STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &tranId); diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 95c1a75ced..b762a5cddf 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -137,39 +137,39 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, userObj.updateTime = userObj.createdTime; userObj.rootAuth = 0; - STrans *pTrans = trnCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); if (pTrans == NULL) return -1; SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj); - if (pRedoRaw == NULL || trnAppendRedoLog(pTrans, pRedoRaw) != 0) { + if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { mError("failed to append redo log since %s", terrstr()); - trnDrop(pTrans); + mndTransDrop(pTrans); return -1; } sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING); SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj); - if (pUndoRaw == NULL || trnAppendUndoLog(pTrans, pUndoRaw) != 0) { + if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) { mError("failed to append undo log since %s", terrstr()); - trnDrop(pTrans); + mndTransDrop(pTrans); return -1; } sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED); SSdbRaw *pCommitRaw = mndUserActionEncode(&userObj); - if (pCommitRaw == NULL || trnAppendCommitLog(pTrans, pCommitRaw) != 0) { + if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) { mError("failed to append commit log since %s", terrstr()); - trnDrop(pTrans); + mndTransDrop(pTrans); return -1; } sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); - if (trnPrepare(pTrans, mndSyncPropose) != 0) { - trnDrop(pTrans); + if (mndTransPrepare(pTrans, mndSyncPropose) != 0) { + mndTransDrop(pTrans); return -1; } - trnDrop(pTrans); + mndTransDrop(pTrans); return 0; } From 67814005086eef58b9a3f453e9acd63aa25520ea Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 19:35:42 +0800 Subject: [PATCH 15/18] TD-10431 fix bug in sdb --- include/dnode/mnode/sdb/sdb.h | 15 +-- source/dnode/mgmt/impl/src/dndDnode.c | 2 +- source/dnode/mnode/impl/inc/mndInt.h | 4 +- source/dnode/mnode/impl/src/mndAcct.c | 3 +- source/dnode/mnode/impl/src/mndTrans.c | 7 +- source/dnode/mnode/impl/src/mndUser.c | 3 +- source/dnode/mnode/impl/src/mnode.c | 150 ++++++++++++++++--------- source/dnode/mnode/sdb/inc/sdbInt.h | 5 +- source/dnode/mnode/sdb/src/sdb.c | 73 ++++++------ source/dnode/mnode/sdb/src/sdbFile.c | 77 ++++++------- source/dnode/mnode/sdb/src/sdbHash.c | 28 ++--- source/dnode/mnode/sdb/src/sdbRaw.c | 4 +- 12 files changed, 200 insertions(+), 171 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 2c2d24268e..e5667e352f 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -114,14 +114,14 @@ typedef enum { SDB_START = 0, SDB_TRANS = 1, SDB_CLUSTER = 2, - SDB_DNODE = 3, - SDB_MNODE = 4, + SDB_MNODE = 3, + SDB_DNODE = 4, SDB_USER = 5, SDB_AUTH = 6, SDB_ACCT = 7, - SDB_DB = 8, SDB_VGROUP = 9, - SDB_STABLE = 10, + SDB_STABLE = 9, + SDB_DB = 10, SDB_FUNC = 11, SDB_MAX = 12 } ESdbType; @@ -149,10 +149,11 @@ typedef struct SSdbOpt { const char *path; } SSdbOpt; -SSdb *sdbOpen(SSdbOpt *pOption); -void sdbClose(SSdb *pSdb); +SSdb *sdbInit(SSdbOpt *pOption); +void sdbCleanup(SSdb *pSdb); +int32_t sdbSetTable(SSdb *pSdb, SSdbTable table); int32_t sdbDeploy(SSdb *pSdb); -void sdbSetTable(SSdb *pSdb, SSdbTable table); +int32_t sdbReadFile(SSdb *pSdb); int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw); void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey); diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 9e70bf1ae9..4265c8a3cd 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -464,7 +464,7 @@ static void *dnodeThreadRoutine(void *param) { pthread_testcancel(); if (dndGetStat(pDnode) == DND_STAT_RUNNING) { - dndSendStatusMsg(pDnode); + // dndSendStatusMsg(pDnode); } } } diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 8a870091d4..2c7e597774 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -41,10 +41,10 @@ typedef struct SMnode { int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; tmr_h timer; + char *path; SSdb *pSdb; SDnode *pDnode; - char *path; - SArray steps; + SArray *pSteps; MndMsgFp msgFp[TSDB_MSG_TYPE_MAX]; SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index b52c7d1e8e..dd91de1c95 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -111,8 +111,7 @@ int32_t mndInitAcct(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mnodeAcctActionUpdate, .deleteFp = (SdbDeleteFp)mnodeAcctActionDelete}; - sdbSetTable(pMnode->pSdb, table); - return 0; + return sdbSetTable(pMnode->pSdb, table); } void mndCleanupAcct(SMnode *pMnode) {} diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 91d0f20013..9333fe3f57 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -320,14 +320,11 @@ int32_t mndInitTrans(SMnode *pMnode) { .insertFp = (SdbInsertFp)mndTransActionInsert, .updateFp = (SdbUpdateFp)mndTransActionUpdate, .deleteFp = (SdbDeleteFp)mndTransActionDelete}; - sdbSetTable(pMnode->pSdb, table); - mInfo("trn module is initialized"); - return 0; + return sdbSetTable(pMnode->pSdb, table); } -void mndCleanupTrans(SMnode *pMnode) { mInfo("trn module is cleaned up"); } - +void mndCleanupTrans(SMnode *pMnode) {} int32_t mndTransPrepare(STrans *pTrans, int32_t (*syncfp)(SSdbRaw *pRaw, void *pData)) { if (syncfp == NULL) return -1; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index b762a5cddf..d63e3662e0 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -223,11 +223,10 @@ int32_t mndInitUser(SMnode *pMnode) { .insertFp = (SdbInsertFp)mndUserActionInsert, .updateFp = (SdbUpdateFp)mndUserActionUpdate, .deleteFp = (SdbDeleteFp)mndUserActionDelete}; - sdbSetTable(pMnode->pSdb, table); mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_USER, mndProcessCreateUserMsg); - return 0; + return sdbSetTable(pMnode->pSdb, table); } void mndCleanupUser(SMnode *pMnode) {} \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 9217fa7194..bc2ed92197 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -36,6 +36,7 @@ int32_t mndGetDnodeId(SMnode *pMnode) { if (pMnode != NULL) { return pMnode->dnodeId; } + return -1; } @@ -43,6 +44,7 @@ int64_t mndGetClusterId(SMnode *pMnode) { if (pMnode != NULL) { return pMnode->clusterId; } + return -1; } @@ -50,6 +52,8 @@ tmr_h mndGetTimer(SMnode *pMnode) { if (pMnode != NULL) { return pMnode->timer; } + + return NULL; } void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { @@ -76,6 +80,7 @@ static int32_t mndInitTimer(SMnode *pMnode) { } if (pMnode->timer == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -93,12 +98,12 @@ static int32_t mnodeCreateDir(SMnode *pMnode, const char *path) { pMnode->path = strdup(path); if (pMnode->path == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; + return -1; } if (taosMkDir(pMnode->path) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - return terrno; + return -1; } return 0; @@ -108,7 +113,7 @@ static int32_t mndInitSdb(SMnode *pMnode) { SSdbOpt opt = {0}; opt.path = pMnode->path; - pMnode->pSdb = sdbOpen(&opt); + pMnode->pSdb = sdbInit(&opt); if (pMnode->pSdb == NULL) { return -1; } @@ -117,10 +122,11 @@ static int32_t mndInitSdb(SMnode *pMnode) { } static int32_t mndDeploySdb(SMnode *pMnode) { return sdbDeploy(pMnode->pSdb); } +static int32_t mndReadSdb(SMnode *pMnode) { return sdbReadFile(pMnode->pSdb); } static void mndCleanupSdb(SMnode *pMnode) { if (pMnode->pSdb) { - sdbClose(pMnode->pSdb); + sdbCleanup(pMnode->pSdb); pMnode->pSdb = NULL; } } @@ -130,9 +136,8 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle step.name = name; step.initFp = initFp; step.cleanupFp = cleanupFp; - if (taosArrayPush(&pMnode->steps, &step) != NULL) { + if (taosArrayPush(pMnode->pSteps, &step) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed to alloc step:%s since %s", name, terrstr()); return -1; } @@ -140,68 +145,73 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle } static int32_t mndInitSteps(SMnode *pMnode) { - if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-stable", mndInitStable, mndCleanupStable) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-stable", mndInitStable, mndCleanupStable) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; if (pMnode->clusterId <= 0) { - if (mndAllocStep(pMnode, "mnode-deploy", mndDeploySdb, NULL) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-sdb-deploy", mndDeploySdb, NULL) != 0) return -1; + } else { + if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1; } - if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-balance", mndInitBalance, mndCleanupBalance) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return terrno; - if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return terrno; + if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-balance", mndInitBalance, mndCleanupBalance) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return -1; return 0; } static void mndCleanupSteps(SMnode *pMnode, int32_t pos) { + if (pMnode->pSteps == NULL) return; + if (pos == -1) { - pos = taosArrayGetSize(&pMnode->steps); + pos = taosArrayGetSize(pMnode->pSteps); } for (int32_t s = pos; s >= 0; s--) { - SMnodeStep *pStep = taosArrayGet(&pMnode->steps, pos); + SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos); mDebug("step:%s will cleanup", pStep->name); if (pStep->cleanupFp != NULL) { (*pStep->cleanupFp)(pMnode); } } - taosArrayClear(&pMnode->steps); + taosArrayClear(pMnode->pSteps); + pMnode->pSteps = NULL; } static int32_t mndExecSteps(SMnode *pMnode) { - int32_t size = taosArrayGetSize(&pMnode->steps); + int32_t size = taosArrayGetSize(pMnode->pSteps); for (int32_t pos = 0; pos < size; pos++) { - SMnodeStep *pStep = taosArrayGet(&pMnode->steps, pos); + SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos); if (pStep->initFp == NULL) continue; // (*pMnode->reportProgress)(pStep->name, "start initialize"); - int32_t code = (*pStep->initFp)(pMnode); - if (code != 0) { - mError("step:%s exec failed since %s, start to cleanup", pStep->name, tstrerror(code)); + if ((*pStep->initFp)(pMnode) != 0) { + mError("step:%s exec failed since %s, start to cleanup", pStep->name, terrstr()); mndCleanupSteps(pMnode, pos); - terrno = code; - return code; + return -1; } else { mDebug("step:%s is initialized", pStep->name); } // (*pMnode->reportProgress)(pStep->name, "initialize completed"); } + + return 0; } static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { @@ -217,20 +227,40 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || - pMnode->putMsgToApplyMsgFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0) { + pMnode->putMsgToApplyMsgFp == NULL) { terrno = TSDB_CODE_MND_APP_ERROR; - return terrno; + return -1; + } + + if (pMnode->dnodeId < 0 || pMnode->clusterId < 0) { + terrno = TSDB_CODE_MND_APP_ERROR; + return -1; } return 0; } SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { + mDebug("start to open mnode in %s", path); + SMnode *pMnode = calloc(1, sizeof(SMnode)); + if (pMnode == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to open mnode since %s", terrstr()); + return NULL; + } + + pMnode->pSteps = taosArrayInit(24, sizeof(SMnodeStep)); + if (pMnode->pSteps == NULL) { + free(pMnode); + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed to open mnode since %s", terrstr()); + return NULL; + } int32_t code = mnodeCreateDir(pMnode, path); - if (code != 0) { - mError("failed to set mnode options since %s", terrstr()); + if (mnodeCreateDir(pMnode, path) != 0) { + mError("failed to open mnode since %s", tstrerror(code)); mndClose(pMnode); terrno = code; return NULL; @@ -238,51 +268,66 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { code = mndSetOptions(pMnode, pOption); if (code != 0) { + mError("failed to open mnode since %s", tstrerror(code)); mndClose(pMnode); terrno = code; - mError("failed to set mnode options since %s", terrstr()); return NULL; } code = mndInitSteps(pMnode); if (code != 0) { + mError("failed to open mnode since %s", tstrerror(code)); mndClose(pMnode); terrno = code; - mError("failed to int steps since %s", terrstr()); return NULL; } code = mndExecSteps(pMnode); if (code != 0) { + mError("failed to open mnode since %s", tstrerror(code)); mndClose(pMnode); terrno = code; - mError("failed to execute steps since %s", terrstr()); return NULL; } - mDebug("mnode:%p object is created", pMnode); + mDebug("mnode open successfully "); return pMnode; } void mndClose(SMnode *pMnode) { - mndCleanupSteps(pMnode, -1); - tfree(pMnode->path); - tfree(pMnode); - mDebug("mnode:%p object is cleaned up", pMnode); + if (pMnode != NULL) { + mDebug("start to close mnode"); + mndCleanupSteps(pMnode, -1); + tfree(pMnode->path); + tfree(pMnode); + mDebug("mnode is closed"); + } } int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { - assert(1); + mDebug("start to alter mnode"); + mDebug("mnode is altered"); return 0; } void mndDestroy(const char *path) { - mDebug("mnode in %s will be destroyed", path); + mDebug("start to destroy mnode at %s", path); taosRemoveDir(path); + mDebug("mnode is destroyed"); } int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { - assert(1); + pLoad->numOfDnode = 0; + pLoad->numOfMnode = 0; + pLoad->numOfVgroup = 0; + pLoad->numOfDatabase = 0; + pLoad->numOfSuperTable = 0; + pLoad->numOfChildTable = 0; + pLoad->numOfColumn = 0; + pLoad->totalPoints = 0; + pLoad->totalStorage = 0; + pLoad->compStorage = 0; + return 0; } @@ -343,7 +388,8 @@ static void mndProcessRpcMsg(SMnodeMsg *pMsg) { code = (*fp)(pMnode, pMsg); if (code != 0) { - mError("msg:%p, app:%p type:%s failed to process since %s", pMsg, ahandle, taosMsg[msgType], tstrerror(code)); + code = terrno; + mError("msg:%p, app:%p type:%s failed to process since %s", pMsg, ahandle, taosMsg[msgType], terrstr()); goto PROCESS_RPC_END; } diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index 5c25349b5c..6162617568 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -37,7 +37,7 @@ extern "C" { #define SDB_MAX_SIZE (32 * 1024) typedef struct SSdbRaw { - int8_t sdb; + int8_t type; int8_t sver; int8_t status; int8_t reserved; @@ -46,7 +46,7 @@ typedef struct SSdbRaw { } SSdbRaw; typedef struct SSdbRow { - ESdbType sdb; + ESdbType type; ESdbStatus status; int32_t refCount; char pObj[]; @@ -69,7 +69,6 @@ typedef struct SSdb { SdbDecodeFp decodeFps[SDB_MAX]; } SSdb; -int32_t sdbReadFile(SSdb *pSdb); int32_t sdbWriteFile(SSdb *pSdb); int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw); diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index c4c6a553f7..4f1267498c 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -16,70 +16,43 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" -SSdb *sdbOpen(SSdbOpt *pOption) { - mDebug("start to open sdb in %s", pOption->path); +SSdb *sdbInit(SSdbOpt *pOption) { + mDebug("start to init sdb in %s", pOption->path); SSdb *pSdb = calloc(1, sizeof(SSdb)); if (pSdb == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed to open sdb since %s", terrstr()); + mError("failed to init sdb since %s", terrstr()); return NULL; } char path[PATH_MAX + 100]; - snprintf(path, PATH_MAX + 100, "%s%scur", pOption->path, TD_DIRSEP); + snprintf(path, PATH_MAX + 100, "%s", pOption->path); pSdb->currDir = strdup(path); snprintf(path, PATH_MAX + 100, "%s%ssync", pOption->path, TD_DIRSEP); pSdb->syncDir = strdup(path); snprintf(path, PATH_MAX + 100, "%s%stmp", pOption->path, TD_DIRSEP); pSdb->tmpDir = strdup(path); if (pSdb->currDir == NULL || pSdb->currDir == NULL || pSdb->currDir == NULL) { - sdbClose(pSdb); + sdbCleanup(pSdb); terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed to open sdb since %s", terrstr()); + mError("failed to init sdb since %s", terrstr()); return NULL; } for (int32_t i = 0; i < SDB_MAX; ++i) { - int32_t type; - if (pSdb->keyTypes[i] == SDB_KEY_INT32) { - type = TSDB_DATA_TYPE_INT; - } else if (pSdb->keyTypes[i] == SDB_KEY_INT64) { - type = TSDB_DATA_TYPE_BIGINT; - } else { - type = TSDB_DATA_TYPE_BINARY; - } - - SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK); - if (hash == NULL) { - sdbClose(pSdb); - terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed to open sdb since %s", terrstr()); - return NULL; - } - - pSdb->hashObjs[i] = hash; taosInitRWLatch(&pSdb->locks[i]); } - int32_t code = sdbReadFile(pSdb); - if (code != 0) { - sdbClose(pSdb); - terrno = code; - mError("failed to open sdb since %s", terrstr()); - return NULL; - } - - mDebug("sdb open successfully"); + mDebug("sdb init successfully"); return pSdb; } -void sdbClose(SSdb *pSdb) { - mDebug("start to close sdb"); +void sdbCleanup(SSdb *pSdb) { + mDebug("start to cleanup sdb"); if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("start to write sdb file since curVer:% " PRId64 " and lastCommitVer:%" PRId64 " inequal", pSdb->curVer, - pSdb->lastCommitVer); + mDebug("write sdb file for curVer:% " PRId64 " and lastVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); sdbWriteFile(pSdb); } @@ -104,10 +77,10 @@ void sdbClose(SSdb *pSdb) { pSdb->hashObjs[i] = NULL; } - mDebug("sdb is closed"); + mDebug("sdb is cleaned up"); } -void sdbSetTable(SSdb *pSdb, SSdbTable table) { +int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { ESdbType sdb = table.sdbType; pSdb->keyTypes[sdb] = table.keyType; pSdb->insertFps[sdb] = table.insertFp; @@ -117,5 +90,25 @@ void sdbSetTable(SSdb *pSdb, SSdbTable table) { pSdb->encodeFps[sdb] = table.encodeFp; pSdb->decodeFps[sdb] = table.decodeFp; - mDebug("set sdb handle of table %d", pSdb, table); + for (int32_t i = 0; i < SDB_MAX; ++i) { + int32_t type; + if (pSdb->keyTypes[i] == SDB_KEY_INT32) { + type = TSDB_DATA_TYPE_INT; + } else if (pSdb->keyTypes[i] == SDB_KEY_INT64) { + type = TSDB_DATA_TYPE_BIGINT; + } else { + type = TSDB_DATA_TYPE_BINARY; + } + + SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(type), true, HASH_NO_LOCK); + if (hash == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + pSdb->hashObjs[i] = hash; + taosInitRWLatch(&pSdb->locks[i]); + } + + return 0; } \ No newline at end of file diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index fbbb602882..37fcdc19ef 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -18,45 +18,41 @@ #include "tchecksum.h" static int32_t sdbCreateDir(SSdb *pSdb) { - int32_t code = taosMkDir(pSdb->currDir); - if (code != 0) { - code = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", pSdb->currDir, tstrerror(code)); - return code; + if (taosMkDir(pSdb->currDir) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->currDir, terrstr()); + return -1; } - code = taosMkDir(pSdb->syncDir); - if (code != 0) { - code = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", pSdb->syncDir, tstrerror(code)); - return code; + if (taosMkDir(pSdb->syncDir) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->syncDir, terrstr()); + return -1; } - code = taosMkDir(pSdb->tmpDir); - if (code != 0) { - code = TAOS_SYSTEM_ERROR(errno); - mError("failed to create dir:%s since %s", pSdb->tmpDir, tstrerror(code)); - return code; + if (taosMkDir(pSdb->tmpDir) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + mError("failed to create dir:%s since %s", pSdb->tmpDir, terrstr()); + return -1; } return 0; } static int32_t sdbRunDeployFp(SSdb *pSdb) { - mDebug("start to run sdb deploy functions"); + mDebug("start to deploy sdb"); for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) { SdbDeployFp fp = pSdb->deployFps[i]; if (fp == NULL) continue; - int32_t code = (*fp)(pSdb); - if (code != 0) { - mError("failed to deploy sdb:%d since %s", i, tstrerror(code)); - return code; + if ((*fp)(pSdb) != 0) { + mError("failed to deploy sdb:%d since %s", i, terrstr()); + return -1; } } - mDebug("sdb deploy functions run finished"); + mDebug("sdb deploy successfully"); return 0; } @@ -68,9 +64,9 @@ int32_t sdbReadFile(SSdb *pSdb) { SSdbRaw *pRaw = malloc(SDB_MAX_SIZE); if (pRaw == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - mError("failed read file since %s", tstrerror(code)); - return code; + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed read file since %s", terrstr()); + return -1; } char file[PATH_MAX] = {0}; @@ -79,9 +75,9 @@ int32_t sdbReadFile(SSdb *pSdb) { FileFd fd = taosOpenFileRead(file); if (fd <= 0) { free(pRaw); - code = TAOS_SYSTEM_ERROR(errno); - mError("failed to read file:%s since %s", file, tstrerror(code)); - return code; + terrno = TAOS_SYSTEM_ERROR(errno); + mError("failed to read file:%s since %s", file, terrstr()); + return -1; } while (1) { @@ -135,6 +131,7 @@ PARSE_SDB_DATA_ERROR: taosCloseFile(fd); sdbFreeRaw(pRaw); + terrno = code; return code; } @@ -142,15 +139,15 @@ int32_t sdbWriteFile(SSdb *pSdb) { int32_t code = 0; char tmpfile[PATH_MAX] = {0}; - snprintf(tmpfile, sizeof(tmpfile), "%ssdb.data", pSdb->tmpDir); + snprintf(tmpfile, sizeof(tmpfile), "%s%ssdb.data", pSdb->tmpDir, TD_DIRSEP); char curfile[PATH_MAX] = {0}; - snprintf(curfile, sizeof(curfile), "%ssdb.data", pSdb->currDir); + snprintf(curfile, sizeof(curfile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); FileFd fd = taosOpenFileCreateWrite(tmpfile); if (fd <= 0) { - code = TAOS_SYSTEM_ERROR(errno); - mError("failed to open file:%s for write since %s", tmpfile, tstrerror(code)); - return code; + terrno = TAOS_SYSTEM_ERROR(errno); + mError("failed to open file:%s for write since %s", tmpfile, terrstr()); + return -1; } for (int32_t i = SDB_MAX - 1; i > SDB_START; --i) { @@ -220,23 +217,21 @@ int32_t sdbWriteFile(SSdb *pSdb) { mDebug("write file:%s successfully", curfile); } + terrno = code; return code; } int32_t sdbDeploy(SSdb *pSdb) { - int32_t code = sdbCreateDir(pSdb); - if (code != 0) { - return code; + if (sdbCreateDir(pSdb) != 0) { + return -1; } - code = sdbRunDeployFp(pSdb); - if (code != 0) { - return code; + if (sdbRunDeployFp(pSdb) != 0) { + return -1; } - code = sdbWriteFile(pSdb); - if (code != 0) { - return code; + if (sdbWriteFile(pSdb) != 0) { + return -1; } return 0; diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 1ac983d538..0db5c0beb6 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -49,7 +49,7 @@ static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) { static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->sdb]; + SRWLatch *pLock = &pSdb->locks[pRow->type]; taosWLockLatch(pLock); SSdbRow *pDstRow = taosHashGet(hash, pRow->pObj, keySize); @@ -70,7 +70,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosWUnLockLatch(pLock); - SdbInsertFp insertFp = pSdb->insertFps[pRow->sdb]; + SdbInsertFp insertFp = pSdb->insertFps[pRow->type]; if (insertFp != NULL) { code = (*insertFp)(pSdb, pRow->pObj); if (code != 0) { @@ -88,7 +88,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->sdb]; + SRWLatch *pLock = &pSdb->locks[pRow->type]; taosRLockLatch(pLock); SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize); @@ -101,7 +101,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * pRow->status = pRaw->status; taosRUnLockLatch(pLock); - SdbUpdateFp updateFp = pSdb->updateFps[pRow->sdb]; + SdbUpdateFp updateFp = pSdb->updateFps[pRow->type]; if (updateFp != NULL) { code = (*updateFp)(pSdb, pRow->pObj, pDstRow->pObj); } @@ -113,7 +113,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->sdb]; + SRWLatch *pLock = &pSdb->locks[pRow->type]; taosWLockLatch(pLock); SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize); @@ -128,7 +128,7 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosHashRemove(hash, pDstRow->pObj, keySize); taosWUnLockLatch(pLock); - SdbDeleteFp deleteFp = pSdb->deleteFps[pDstRow->sdb]; + SdbDeleteFp deleteFp = pSdb->deleteFps[pDstRow->type]; if (deleteFp != NULL) { code = (*deleteFp)(pSdb, pDstRow->pObj); } @@ -139,18 +139,18 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * } int32_t sdbWriteRaw(SSdb *pSdb, SSdbRaw *pRaw) { - SHashObj *hash = sdbGetHash(pSdb, pRaw->sdb); + SHashObj *hash = sdbGetHash(pSdb, pRaw->type); if (hash == NULL) return terrno; - SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->sdb]; + SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->type]; SSdbRow *pRow = (*decodeFp)(pRaw); if (pRow == NULL) { return terrno; } - pRow->sdb = pRaw->sdb; + pRow->type = pRaw->type; - int32_t keySize = sdbGetkeySize(pSdb, pRow->sdb, pRow->pObj); + int32_t keySize = sdbGetkeySize(pSdb, pRow->type, pRow->pObj); int32_t code = TSDB_CODE_SDB_INVALID_ACTION_TYPE; switch (pRaw->status) { @@ -217,9 +217,9 @@ void sdbRelease(SSdb *pSdb, void *pObj) { if (pObj == NULL) return; SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow)); - if (pRow->sdb >= SDB_MAX || pRow->sdb <= SDB_START) return; + if (pRow->type >= SDB_MAX || pRow->type <= SDB_START) return; - SRWLatch *pLock = &pSdb->locks[pRow->sdb]; + SRWLatch *pLock = &pSdb->locks[pRow->type]; taosRLockLatch(pLock); int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1); @@ -257,10 +257,10 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { void sdbCancelFetch(SSdb *pSdb, void *pIter) { if (pIter == NULL) return; SSdbRow *pRow = *(SSdbRow **)pIter; - SHashObj *hash = sdbGetHash(pSdb, pRow->sdb); + SHashObj *hash = sdbGetHash(pSdb, pRow->type); if (hash == NULL) return; - SRWLatch *pLock = &pSdb->locks[pRow->sdb]; + SRWLatch *pLock = &pSdb->locks[pRow->type]; taosRLockLatch(pLock); taosHashCancelIterate(hash, pIter); taosRUnLockLatch(pLock); diff --git a/source/dnode/mnode/sdb/src/sdbRaw.c b/source/dnode/mnode/sdb/src/sdbRaw.c index 68a0abc859..2abff74168 100644 --- a/source/dnode/mnode/sdb/src/sdbRaw.c +++ b/source/dnode/mnode/sdb/src/sdbRaw.c @@ -16,14 +16,14 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" -SSdbRaw *sdbAllocRaw(ESdbType sdb, int8_t sver, int32_t dataLen) { +SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) { SSdbRaw *pRaw = calloc(1, dataLen + sizeof(SSdbRaw)); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - pRaw->sdb = sdb; + pRaw->type = type; pRaw->sver = sver; pRaw->dataLen = dataLen; return pRaw; From 939c3b3a26a8e0f6dfbf005d337d6e79bcb50f2d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 20:24:16 +0800 Subject: [PATCH 16/18] TD-10431 interface of mnode --- include/dnode/mnode/mnode.h | 194 +++++++++++++++++++------ include/dnode/mnode/sdb/sdb.h | 144 ++++++++++++++++-- source/dnode/mgmt/impl/CMakeLists.txt | 2 +- source/dnode/mnode/impl/CMakeLists.txt | 6 +- source/dnode/mnode/sdb/CMakeLists.txt | 2 +- 5 files changed, 289 insertions(+), 59 deletions(-) diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 9d4c27a9dc..5066b881b5 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -30,28 +30,132 @@ typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg); typedef struct SMnodeLoad { + /** + * @brief the number of dnodes in cluster. + * + */ int64_t numOfDnode; + + /** + * @brief the number of mnodes in cluster. + * + */ int64_t numOfMnode; + + /** + * @brief the number of vgroups in cluster. + * + */ int64_t numOfVgroup; + + /** + * @brief the number of databases in cluster. + * + */ int64_t numOfDatabase; + + /** + * @brief the number of super tables in cluster. + * + */ int64_t numOfSuperTable; + + /** + * @brief the number of child tables in cluster. + * + */ int64_t numOfChildTable; + + /** + * @brief the number of normal tables in cluster. + * + */ + int64_t numOfNormalTable; + + /** + * @brief the number of numOfTimeseries in cluster. + * + */ int64_t numOfColumn; + + /** + * @brief total points written in cluster. + * + */ int64_t totalPoints; + + /** + * @brief total storage in cluster. + * + */ int64_t totalStorage; + + /** + * @brief total compressed storage in cluster. + * + */ int64_t compStorage; } SMnodeLoad; typedef struct { - int32_t dnodeId; - int64_t clusterId; - int8_t replica; - int8_t selfIndex; - SReplica replicas[TSDB_MAX_REPLICA]; - SDnode *pDnode; - PutMsgToMnodeQFp putMsgToApplyMsgFp; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; + /** + * @brief dnodeId of this mnode. + * + */ + int32_t dnodeId; + + /** + * @brief clusterId of this mnode. + * + */ + int64_t clusterId; + + /** + * @brief replica num of this mnode. + * + */ + int8_t replica; + + /** + * @brief self index in the array of replicas. + * + */ + int8_t selfIndex; + + /** + * @brief detail replica information of this mnode. + * + */ + SReplica replicas[TSDB_MAX_REPLICA]; + + /** + * @brief the parent dnode of this mnode. + * + */ + SDnode *pDnode; + + /** + * @brief put apply msg to the write queue in dnode. + * + */ + PutMsgToMnodeQFp putMsgToApplyMsgFp; + + /** + * @brief the callback function while send msg to dnode. + * + */ + SendMsgToDnodeFp sendMsgToDnodeFp; + + /** + * @brief the callback function while send msg to mnode. + * + */ + SendMsgToMnodeFp sendMsgToMnodeFp; + + /** + * @brief the callback function while send redirect msg to clients or peers. + * + */ SendRedirectMsgFp sendRedirectMsgFp; } SMnodeOpt; @@ -59,25 +163,25 @@ typedef struct { /** * @brief Open a mnode. * - * @param path Path of the mnode - * @param pOption Option of the mnode - * @return SMnode* The mnode object + * @param path Path of the mnode. + * @param pOption Option of the mnode. + * @return SMnode* The mnode object. */ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption); /** - * @brief Close a mnode + * @brief Close a mnode. * - * @param pMnode The mnode object to close + * @param pMnode The mnode object to close. */ void mndClose(SMnode *pMnode); /** - * @brief Close a mnode + * @brief Close a mnode. * - * @param pMnode The mnode object to close - * @param pOption Options of the mnode - * @return int32_t 0 for success, -1 for failure + * @param pMnode The mnode object to close. + * @param pOption Options of the mnode. + * @return int32_t 0 for success, -1 for failure. */ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); @@ -89,80 +193,80 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); void mndDestroy(const char *path); /** - * @brief Get mnode statistics info + * @brief Get mnode statistics info. * - * @param pMnode The mnode object + * @param pMnode The mnode object. * @param pLoad Statistics of the mnode. - * @return int32_t 0 for success, -1 for failure + * @return int32_t 0 for success, -1 for failure. */ int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); /** - * @brief Get user authentication info + * @brief Get user authentication info. * - * @param pMnode The mnode object + * @param pMnode The mnode object. * @param user * @param spi * @param encrypt * @param secret * @param ckey - * @return int32_t 0 for success, -1 for failure + * @return int32_t 0 for success, -1 for failure. */ int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey); /** - * @brief Initialize mnode msg + * @brief Initialize mnode msg. * - * @param pMnode The mnode object - * @param pMsg The request rpc msg - * @return int32_t The created mnode msg + * @param pMnode The mnode object. + * @param pMsg The request rpc msg. + * @return int32_t The created mnode msg. */ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg); /** - * @brief Cleanup mnode msg + * @brief Cleanup mnode msg. * - * @param pMsg The request msg + * @param pMsg The request msg. */ void mndCleanupMsg(SMnodeMsg *pMsg); /** - * @brief Cleanup mnode msg + * @brief Cleanup mnode msg. * - * @param pMsg The request msg - * @param code The error code + * @param pMsg The request msg. + * @param code The error code. */ void mndSendRsp(SMnodeMsg *pMsg, int32_t code); /** - * @brief Process the read request + * @brief Process the read request. * - * @param pMsg The request msg - * @return int32_t 0 for success, -1 for failure + * @param pMsg The request msg. + * @return int32_t 0 for success, -1 for failure. */ void mndProcessReadMsg(SMnodeMsg *pMsg); /** - * @brief Process the write request + * @brief Process the write request. * - * @param pMsg The request msg - * @return int32_t 0 for success, -1 for failure + * @param pMsg The request msg. + * @return int32_t 0 for success, -1 for failure. */ void mndProcessWriteMsg(SMnodeMsg *pMsg); /** - * @brief Process the sync request + * @brief Process the sync request. * - * @param pMsg The request msg - * @return int32_t 0 for success, -1 for failure + * @param pMsg The request msg. + * @return int32_t 0 for success, -1 for failure. */ void mndProcessSyncMsg(SMnodeMsg *pMsg); /** - * @brief Process the apply request + * @brief Process the apply request. * - * @param pMsg The request msg - * @return int32_t 0 for success, -1 for failure + * @param pMsg The request msg. + * @return int32_t 0 for success, -1 for failure. */ void mndProcessApplyMsg(SMnodeMsg *pMsg); diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index e5667e352f..3648af5fcb 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -130,36 +130,162 @@ typedef struct SSdb SSdb; typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj); typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj); typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj); -typedef int32_t (*SdbDeployFp)(SSdb*pSdb); +typedef int32_t (*SdbDeployFp)(SSdb *pSdb); typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw); typedef SSdbRaw *(*SdbEncodeFp)(void *pObj); typedef struct { - ESdbType sdbType; - EKeyType keyType; + /** + * @brief The sdb type of the table. + * + */ + ESdbType sdbType; + + /** + * @brief The key type of the table. + * + */ + EKeyType keyType; + + /** + * @brief The callback function when the table is first deployed. + * + */ SdbDeployFp deployFp; + + /** + * @brief Encode one row of the table into rawdata. + * + */ SdbEncodeFp encodeFp; + + /** + * @brief Decode one row of the table from rawdata. + * + */ SdbDecodeFp decodeFp; + + /** + * @brief The callback function when insert a row to sdb. + * + */ SdbInsertFp insertFp; + + /** + * @brief The callback function when undate a row in sdb. + * + */ SdbUpdateFp updateFp; + + /** + * @brief The callback function when delete a row from sdb. + * + */ SdbDeleteFp deleteFp; } SSdbTable; typedef struct SSdbOpt { + /** + * @brief The path of the sdb file. + * + */ const char *path; } SSdbOpt; -SSdb *sdbInit(SSdbOpt *pOption); -void sdbCleanup(SSdb *pSdb); +/** + * @brief Initialize and start the sdb. + * + * @param pOption Option of the sdb. + * @return SSdb* The sdb object. + */ +SSdb *sdbInit(SSdbOpt *pOption); + +/** + * @brief Stop and cleanup the sdb. + * + * @param pSdb The sdb object to close. + */ +void sdbCleanup(SSdb *pSdb); + +/** + * @brief Set the properties of sdb table. + * + * @param pSdb The sdb object. + * @param table The properties of the table. + * @return int32_t 0 for success, -1 for failure. + */ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table); + +/** + * @brief Set the initial rows of sdb. + * + * @param pSdb The sdb object. + * @return int32_t 0 for success, -1 for failure. + */ int32_t sdbDeploy(SSdb *pSdb); + +/** + * @brief Load sdb from file. + * + * @param pSdb The sdb object. + * @return int32_t 0 for success, -1 for failure. + */ int32_t sdbReadFile(SSdb *pSdb); + +/** + * @brief Parse and write raw data to sdb. + * + * @param pSdb The sdb object. + * @param pRaw The raw data. + * @return int32_t 0 for success, -1 for failure. + */ int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw); -void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey); -void sdbRelease(SSdb *pSdb, void *pObj); -void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj); -void sdbCancelFetch(SSdb *pSdb, void *pIter); +/** + * @brief Acquire a row from sdb + * + * @param pSdb The sdb object. + * @param type The type of the row. + * @param pKey The key value of the row. + * @return void* The object of the row. + */ +void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey); + +/** + * @brief Release a row from sdb. + * + * @param pSdb The sdb object. + * @param pObj The object of the row. + */ +void sdbRelease(SSdb *pSdb, void *pObj); + +/** + * @brief Traverse a sdb table + * + * @param pSdb The sdb object. + * @param type The type of the table. + * @param type The initial iterator of the table. + * @param pObj The object of the row just fetched. + * @return void* The next iterator of the table. + */ +void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj); + +/** + * @brief Cancel a traversal + * + * @param pSdb The sdb object. + * @param pIter The iterator of the table. + * @param type The initial iterator of table. + */ +void sdbCancelFetch(SSdb *pSdb, void *pIter); + +/** + * @brief Get the number of rows in the table + * + * @param pSdb The sdb object. + * @param pIter The type of the table. + * @record int32_t The number of rows in the table + */ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen); diff --git a/source/dnode/mgmt/impl/CMakeLists.txt b/source/dnode/mgmt/impl/CMakeLists.txt index d0830484ed..3eadf24164 100644 --- a/source/dnode/mgmt/impl/CMakeLists.txt +++ b/source/dnode/mgmt/impl/CMakeLists.txt @@ -12,5 +12,5 @@ target_link_libraries( target_include_directories( dnode PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt" - private "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index 49c9d54513..6fecb457c0 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -3,11 +3,11 @@ add_library(mnode ${MNODE_SRC}) target_include_directories( mnode PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode" - private "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( mnode PRIVATE sdb - PUBLIC transport - PUBLIC cjson + PRIVATE transport + PRIVATE cjson ) \ No newline at end of file diff --git a/source/dnode/mnode/sdb/CMakeLists.txt b/source/dnode/mnode/sdb/CMakeLists.txt index c5a0b7299a..b6620f8be4 100644 --- a/source/dnode/mnode/sdb/CMakeLists.txt +++ b/source/dnode/mnode/sdb/CMakeLists.txt @@ -3,7 +3,7 @@ add_library(sdb ${MNODE_SRC}) target_include_directories( sdb PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mnode/sdb" - private "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( sdb From a63b2e873414a39bc54d000ed05d5db55a3470ba Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 29 Nov 2021 20:26:00 +0800 Subject: [PATCH 17/18] TD-10431 remove index vars while use for synatx --- source/dnode/mgmt/impl/src/dndMnode.c | 12 +++---- source/dnode/mnode/impl/src/mndTrans.c | 46 +++++++++++++------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index f2ef420cc0..ca48642899 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -364,13 +364,13 @@ static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SC pOption->replica = pMsg->replica; pOption->selfIndex = -1; - for (int32_t index = 0; index < pMsg->replica; ++index) { - SReplica *pReplica = &pOption->replicas[index]; - pReplica->id = pMsg->replicas[index].id; - pReplica->port = pMsg->replicas[index].port; - tstrncpy(pReplica->fqdn, pMsg->replicas[index].fqdn, TSDB_FQDN_LEN); + for (int32_t i = 0; i < pMsg->replica; ++i) { + SReplica *pReplica = &pOption->replicas[i]; + pReplica->id = pMsg->replicas[i].id; + pReplica->port = pMsg->replicas[i].port; + tstrncpy(pReplica->fqdn, pMsg->replicas[i].fqdn, TSDB_FQDN_LEN); if (pReplica->id == pOption->dnodeId) { - pOption->selfIndex = index; + pOption->selfIndex = i; } } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 9333fe3f57..7eab16895c 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -28,18 +28,18 @@ SSdbRaw *mndTransActionEncode(STrans *pTrans) { int32_t redoActionNum = taosArrayGetSize(pTrans->redoActions); int32_t undoActionNum = taosArrayGetSize(pTrans->undoActions); - for (int32_t index = 0; index < redoLogNum; ++index) { - SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, index); + for (int32_t i = 0; i < redoLogNum; ++i) { + SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, i); rawDataLen += sdbGetRawTotalSize(pTmp); } - for (int32_t index = 0; index < undoLogNum; ++index) { - SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, index); + for (int32_t i = 0; i < undoLogNum; ++i) { + SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, i); rawDataLen += sdbGetRawTotalSize(pTmp); } - for (int32_t index = 0; index < commitLogNum; ++index) { - SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, index); + for (int32_t i = 0; i < commitLogNum; ++i) { + SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, i); rawDataLen += sdbGetRawTotalSize(pTmp); } @@ -59,22 +59,22 @@ SSdbRaw *mndTransActionEncode(STrans *pTrans) { SDB_SET_INT32(pRaw, dataPos, redoActionNum) SDB_SET_INT32(pRaw, dataPos, undoActionNum) - for (int32_t index = 0; index < redoLogNum; ++index) { - SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, index); + for (int32_t i = 0; i < redoLogNum; ++i) { + SSdbRaw *pTmp = taosArrayGet(pTrans->redoLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); SDB_SET_INT32(pRaw, dataPos, len) SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) } - for (int32_t index = 0; index < undoLogNum; ++index) { - SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, index); + for (int32_t i = 0; i < undoLogNum; ++i) { + SSdbRaw *pTmp = taosArrayGet(pTrans->undoLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); SDB_SET_INT32(pRaw, dataPos, len) SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) } - for (int32_t index = 0; index < commitLogNum; ++index) { - SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, index); + for (int32_t i = 0; i < commitLogNum; ++i) { + SSdbRaw *pTmp = taosArrayGet(pTrans->commitLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); SDB_SET_INT32(pRaw, dataPos, len) SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) @@ -134,7 +134,7 @@ SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, pRow, dataPos, &undoActionNum) int32_t code = 0; - for (int32_t index = 0; index < redoLogNum; ++index) { + for (int32_t i = 0; i < redoLogNum; ++i) { int32_t dataLen = 0; SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen) @@ -162,8 +162,8 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); - for (int32_t index = 0; index < arraySize; ++index) { - SSdbRaw *pRaw = taosArrayGet(pArray, index); + for (int32_t i = 0; i < arraySize; ++i) { + SSdbRaw *pRaw = taosArrayGet(pArray, i); int32_t code = sdbWrite(pSdb, pRaw); if (code != 0) { mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr()); @@ -179,8 +179,8 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); - for (int32_t index = 0; index < arraySize; ++index) { - SSdbRaw *pRaw = taosArrayGet(pArray, index); + for (int32_t i = 0; i < arraySize; ++i) { + SSdbRaw *pRaw = taosArrayGet(pArray, i); int32_t code = sdbWrite(pSdb, pRaw); if (code != 0) { mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr()); @@ -197,8 +197,8 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pTrans, STrans *pDstTran SArray *pArray = pTrans->redoLogs; int32_t arraySize = taosArrayGetSize(pArray); - for (int32_t index = 0; index < arraySize; ++index) { - SSdbRaw *pRaw = taosArrayGet(pArray, index); + for (int32_t i = 0; i < arraySize; ++i) { + SSdbRaw *pRaw = taosArrayGet(pArray, i); int32_t code = sdbWrite(pSdb, pRaw); if (code != 0) { mError("trn:%d, failed to write raw:%p to sdb since %s", pTrans->id, pRaw, terrstr()); @@ -243,8 +243,8 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) { } static void trnDropArray(SArray *pArray) { - for (int32_t index = 0; index < pArray->size; ++index) { - SSdbRaw *pRaw = taosArrayGet(pArray, index); + for (int32_t i = 0; i < pArray->size; ++i) { + SSdbRaw *pRaw = taosArrayGet(pArray, i); tfree(pRaw); } @@ -373,8 +373,8 @@ int32_t mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, void *pData, int32_t code) } static int32_t trnExecuteArray(SMnode *pMnode, SArray *pArray) { - for (int32_t index = 0; index < pArray->size; ++index) { - SSdbRaw *pRaw = taosArrayGetP(pArray, index); + for (int32_t i = 0; i < pArray->size; ++i) { + SSdbRaw *pRaw = taosArrayGetP(pArray, i); if (sdbWrite(pMnode->pSdb, pRaw) != 0) { return -1; } From 23c9ea680b3097cf78a3753ad2104716f680bc62 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Mon, 29 Nov 2021 23:37:21 +0800 Subject: [PATCH 18/18] update fst core struct --- source/libs/index/inc/index_fst.h | 46 +++++- source/libs/index/inc/index_fst_automation.h | 21 ++- source/libs/index/src/index_fst.c | 154 +++++++++++++++++++ source/libs/index/src/index_fst_util.c | 1 + 4 files changed, 213 insertions(+), 9 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 8f76c2d5cf..35858bb789 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -21,6 +21,7 @@ #include "index_fst_util.h" #include "index_fst_registry.h" #include "index_fst_counting_writer.h" +#include "index_fst_automation.h" typedef struct FstNode FstNode; @@ -34,11 +35,28 @@ typedef struct FstRange { typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State; -typedef enum { Included, Excluded, Unbounded} FstBound; typedef enum {Ordered, OutOfOrdered, DuplicateKey} OrderType; +typedef enum { Included, Excluded, Unbounded} FstBound; +typedef struct FstBoundWithData { + FstSlice data; + FstBound type; +} FstBoundWithData; + +FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice *data); +bool fstBoundWithDataExceededBy(FstBoundWithData *bound, FstSlice *slice); +bool fstBoundWithDataIsEmpty(FstBoundWithData *bound); +bool fstBoundWithDataIsIncluded(FstBoundWithData *bound); + + +typedef struct FstOutput { + bool null; + Output out; +} FstOutput; + + /* * @@ -261,4 +279,30 @@ bool fstVerify(Fst *fst); //refactor this function bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr); + + + + + +typedef struct StreamState { + FstNode *node; + uint64_t trans; + FstOutput out; + void *autState; +} StreamState; + +typedef struct StreamWithState { + Fst *fst; + Automation *aut; + SArray *inp; + FstOutput emptyOutput; + SArray *stack; // + FstBoundWithData *endAt; +} StreamWithState ; + +typedef void* (*StreamCallback)(void *); +StreamWithState *streamWithStateCreate(Fst *fst, Automation *automation, FstBoundWithData *min, FstBoundWithData *max) ; +void streamWithStateDestroy(StreamWithState *sws); +bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min); +void *streamWithStateNextWith(StreamWithState *sws, StreamCallback callback); #endif diff --git a/source/libs/index/inc/index_fst_automation.h b/source/libs/index/inc/index_fst_automation.h index 7ad9a500cc..63243a0189 100644 --- a/source/libs/index/inc/index_fst_automation.h +++ b/source/libs/index/inc/index_fst_automation.h @@ -15,7 +15,7 @@ #ifndef __INDEX_FST_AUTAOMATION_H__ #define __INDEX_FST_AUTAOMATION_H__ -struct AutomationCtx; +typedef struct AutomationCtx AutomationCtx; typedef struct StartWith { AutomationCtx *autoSelf; @@ -23,20 +23,25 @@ typedef struct StartWith { typedef struct Complement { AutomationCtx *autoSelf; + } Complement; // automation typedef struct AutomationCtx { +// automation interface void *data; } AutomationCtx; -// automation interface -void (*start)(AutomationCtx *ctx); -bool (*isMatch)(AutomationCtx *ctx); -bool (*canMatch)(AutomationCtx *ctx, void *data); -bool (*willAlwaysMatch)(AutomationCtx *ctx, void *state); -void* (*accpet)(AutomationCtx *ctx, void *state, uint8_t byte); -void* (*accpetEof)(AutomationCtx *ctx, *state); +typedef struct Automation { + void* (*start)() ; + bool (*isMatch)(); + bool (*canMatch)(void *data); + bool (*willAlwaysMatch)(void *state); + void* (*accpet)(void *state, uint8_t byte); + void* (*accpetEof)(void *state); + void *data; +} Automation; + #endif diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 94be05d0c1..6c777e704e 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -1055,4 +1055,158 @@ bool fstVerify(Fst *fst) { return true; } +// data bound function +FstBoundWithData* fstBoundStateCreate(FstBound type, FstSlice *data) { + FstBoundWithData *b = calloc(1, sizeof(FstBoundWithData)); + if (b == NULL) { return NULL; } + + b->type = type; + b->data = fstSliceCopy(data, data->start, data->end); + return b; +} + +bool fstBoundWithDataExceededBy(FstBoundWithData *bound, FstSlice *slice) { + int comp = fstSliceCompare(slice, &bound->data); + if (bound->type == Included) { + return comp > 0 ? true : false; + } else if (bound->type == Excluded) { + return comp >= 0 ? true : false; + } else { + return true; + } +} +bool fstBoundWithDataIsEmpty(FstBoundWithData *bound) { + if (bound->type == Unbounded) { + return true; + } else { + return fstSliceEmpty(&bound->data); + } +} + + +bool fstBoundWithDataIsIncluded(FstBoundWithData *bound) { + return bound->type == Included ? true : false; +} + +void fstBoundDestroy(FstBoundWithData *bound) { + free(bound); +} + +StreamWithState *streamWithStateCreate(Fst *fst, Automation *automation, FstBoundWithData *min, FstBoundWithData *max) { + StreamWithState *sws = calloc(1, sizeof(StreamWithState)); + if (sws == NULL) { return NULL; } + + sws->fst = fst; + sws->aut = automation; + sws->inp = (SArray *)taosArrayInit(256, sizeof(uint8_t)); + + sws->emptyOutput.null = false; + sws->emptyOutput.out = 0; + + sws->stack = (SArray *)taosArrayInit(256, sizeof(StreamState)); + sws->endAt = max; + streamWithStateSeekMin(sws, min); + + return sws; +} +void streamWithStateDestroy(StreamWithState *sws) { + if (sws == NULL) { return; } + + taosArrayDestroy(sws->inp); + taosArrayDestroy(sws->stack); + + free(sws); +} + +bool streamWithStateSeekMin(StreamWithState *sws, FstBoundWithData *min) { + if (fstBoundWithDataIsEmpty(min)) { + if (fstBoundWithDataIsIncluded(min)) { + sws->emptyOutput.out = fstEmptyFinalOutput(sws->fst, &(sws->emptyOutput.null)); + } + StreamState s = {.node = fstGetRoot(sws->fst), + .trans = 0, + .out = {.null = false, .out = 0}, + .autState = sws->aut->start()}; // auto.start callback + taosArrayPush(sws->stack, &s); + return true; + } + FstSlice *key = NULL; + bool inclusize = false;; + + if (min->type == Included) { + key = &min->data; + inclusize = true; + } else if (min->type == Excluded) { + key = &min->data; + } else { + return false; + } + + FstNode *node = fstGetRoot(sws->fst); + Output out = 0; + void* autState = sws->aut->start(); + + for (uint32_t i = 0; i < key->dLen; i++) { + uint8_t b = key->data[i]; + uint64_t res = 0; + bool null = fstNodeFindInput(node, b, &res); + if (null == false) { + FstTransition trn; + fstNodeGetTransitionAt(node, res, &trn); + void *preState = autState; + autState = sws->aut->accpet(preState, b); + taosArrayPush(sws->inp, &b); + StreamState s = {.node = node, + .trans = res + 1, + .out = {.null = false, .out = out}, + .autState = preState}; + taosArrayPush(sws->stack, &s); + out += trn.out; + node = fstGetNode(sws->fst, trn.addr); + } else { + + // This is a little tricky. We're in this case if the + // given bound is not a prefix of any key in the FST. + // Since this is a minimum bound, we need to find the + // first transition in this node that proceeds the current + // input byte. + FstTransitions *trans = fstNodeTransitions(node); + uint64_t i = 0; + for (i = trans->range.start; i < trans->range.end; i++) { + FstTransition trn; + if (fstNodeGetTransitionAt(node, i, &trn) && trn.inp > b) { + break; + } + } + + StreamState s = {.node = node, + .trans = i, + .out = {.null = false, .out = out}, + .autState = autState}; + taosArrayPush(sws->stack, &s); + return true; + } + } + uint32_t sz = taosArrayGetSize(sws->stack); + if (sz != 0) { + StreamState *s = taosArrayGet(sws->stack, sz - 1); + if (inclusize) { + s->trans -= 1; + taosArrayPop(sws->inp); + } else { + FstNode *n = s->node; + uint64_t trans = s->trans; + FstTransition trn; + fstNodeGetTransitionAt(n, trans - 1, &trn); + StreamState s = {.node = fstGetNode(sws->fst, trn.addr), + .trans= 0, + .out = {.null = false, .out = out}, + .autState = autState}; + taosArrayPush(sws->stack, &s); + return true; + } + return false; + } +} + diff --git a/source/libs/index/src/index_fst_util.c b/source/libs/index/src/index_fst_util.c index 94bf650acd..952c710676 100644 --- a/source/libs/index/src/index_fst_util.c +++ b/source/libs/index/src/index_fst_util.c @@ -95,6 +95,7 @@ FstSlice fstSliceCreate(uint8_t *data, uint64_t dLen) { FstSlice slice = {.data = data, .dLen = dLen, .start = 0, .end = dLen - 1}; return slice; } +// just shallow copy FstSlice fstSliceCopy(FstSlice *slice, int32_t start, int32_t end) { FstSlice t; if (start >= slice->dLen || end >= slice->dLen || start > end) {