From 4fedc23b26a278113a7d2038130b8590cf051587 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 12 Apr 2022 15:49:21 +0800 Subject: [PATCH 01/19] refact(cluster): node mgmt --- include/common/tmsg.h | 6 +- source/common/src/tmsg.c | 8 +- source/dnode/mgmt/CMakeLists.txt | 7 +- source/dnode/mgmt/bm/bmHandle.c | 6 +- source/dnode/mgmt/bm/bmInt.c | 4 +- source/dnode/mgmt/dm/dmFile.c | 36 ++-- source/dnode/mgmt/dm/dmHandle.c | 48 ++--- source/dnode/mgmt/dm/dmInt.c | 23 +- source/dnode/mgmt/dm/dmMonitor.c | 8 +- source/dnode/mgmt/dm/dmWorker.c | 16 +- source/dnode/mgmt/exe/dndMain.c | 10 +- source/dnode/mgmt/inc/dmInt.h | 39 ++-- source/dnode/mgmt/inc/dndInt.h | 199 ------------------ source/dnode/mgmt/interface/CMakeLists.txt | 10 + source/dnode/mgmt/interface/inc/dndDef.h | 153 ++++++++++++++ source/dnode/mgmt/interface/inc/dndInt.h | 86 ++++++++ source/dnode/mgmt/interface/inc/dndLog.h | 36 ++++ source/dnode/mgmt/interface/src/dndInt.c | 86 ++++++++ source/dnode/mgmt/main/dndEnv.c | 60 ------ source/dnode/mgmt/main/dndExec.c | 66 +++--- source/dnode/mgmt/main/dndFile.c | 38 ++-- source/dnode/mgmt/main/{dndInt.c => dndObj.c} | 77 +++---- source/dnode/mgmt/main/dndTransport.c | 88 ++++---- source/dnode/mgmt/mm/mmHandle.c | 8 +- source/dnode/mgmt/mm/mmInt.c | 20 +- source/dnode/mgmt/qm/qmHandle.c | 4 +- source/dnode/mgmt/qm/qmInt.c | 4 +- source/dnode/mgmt/sm/smHandle.c | 4 +- source/dnode/mgmt/sm/smInt.c | 4 +- source/dnode/mgmt/vm/vmInt.c | 8 +- source/dnode/mnode/impl/src/mndDnode.c | 4 +- 31 files changed, 628 insertions(+), 538 deletions(-) delete mode 100644 source/dnode/mgmt/inc/dndInt.h create mode 100644 source/dnode/mgmt/interface/CMakeLists.txt create mode 100644 source/dnode/mgmt/interface/inc/dndDef.h create mode 100644 source/dnode/mgmt/interface/inc/dndInt.h create mode 100644 source/dnode/mgmt/interface/inc/dndLog.h create mode 100644 source/dnode/mgmt/interface/src/dndInt.c rename source/dnode/mgmt/main/{dndInt.c => dndObj.c} (72%) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ba9147dcdd..7839754735 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -744,8 +744,8 @@ typedef struct { } SVnodeLoad; typedef struct { - int32_t sver; // software version - int64_t dver; // dnode table version in sdb + int32_t sver; // software version + int64_t dnodeVer; // dnode table version in sdb int32_t dnodeId; int64_t clusterId; int64_t rebootTime; @@ -772,7 +772,7 @@ typedef struct { } SDnodeEp; typedef struct { - int64_t dver; + int64_t dnodeVer; SDnodeCfg dnodeCfg; SArray* pDnodeEps; // Array of SDnodeEp } SStatusRsp; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 0edfcb3314..a9ecdd659f 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -868,7 +868,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { // status if (tEncodeI32(&encoder, pReq->sver) < 0) return -1; - if (tEncodeI64(&encoder, pReq->dver) < 0) return -1; + if (tEncodeI64(&encoder, pReq->dnodeVer) < 0) return -1; if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1; if (tEncodeI64(&encoder, pReq->clusterId) < 0) return -1; if (tEncodeI64(&encoder, pReq->rebootTime) < 0) return -1; @@ -913,7 +913,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { // status if (tDecodeI32(&decoder, &pReq->sver) < 0) return -1; - if (tDecodeI64(&decoder, &pReq->dver) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->dnodeVer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->clusterId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->rebootTime) < 0) return -1; @@ -965,7 +965,7 @@ int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { if (tStartEncode(&encoder) < 0) return -1; // status - if (tEncodeI64(&encoder, pRsp->dver) < 0) return -1; + if (tEncodeI64(&encoder, pRsp->dnodeVer) < 0) return -1; // dnode cfg if (tEncodeI32(&encoder, pRsp->dnodeCfg.dnodeId) < 0) return -1; @@ -996,7 +996,7 @@ int32_t tDeserializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { if (tStartDecode(&decoder) < 0) return -1; // status - if (tDecodeI64(&decoder, &pRsp->dver) < 0) return -1; + if (tDecodeI64(&decoder, &pRsp->dnodeVer) < 0) return -1; // cluster cfg if (tDecodeI32(&decoder, &pRsp->dnodeCfg.dnodeId) < 0) return -1; diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index f498773462..40c3f5b1d3 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,3 +1,5 @@ +add_subdirectory(interface) + aux_source_directory(dm DNODE_SRC) aux_source_directory(qm DNODE_SRC) aux_source_directory(bm DNODE_SRC) @@ -7,19 +9,20 @@ aux_source_directory(mm DNODE_SRC) aux_source_directory(main DNODE_SRC) add_library(dnode STATIC ${DNODE_SRC}) target_link_libraries( - dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor + dnode dnode_interface ) target_include_directories( dnode PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface/inc" ) aux_source_directory(exe EXEC_SRC) add_executable(taosd ${EXEC_SRC}) target_include_directories( taosd - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface/inc" ) target_link_libraries(taosd dnode) diff --git a/source/dnode/mgmt/bm/bmHandle.c b/source/dnode/mgmt/bm/bmHandle.c index d110592603..9b33533a8a 100644 --- a/source/dnode/mgmt/bm/bmHandle.c +++ b/source/dnode/mgmt/bm/bmHandle.c @@ -53,9 +53,9 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (createReq.dnodeId != pDnode->dnodeId) { + if (createReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->dnodeId); + dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->data.dnodeId); return -1; } else { return dndOpenNode(pWrapper); @@ -72,7 +72,7 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->dnodeId) { + if (dropReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop bnode since %s", terrstr()); return -1; diff --git a/source/dnode/mgmt/bm/bmInt.c b/source/dnode/mgmt/bm/bmInt.c index 990c7873a9..71ba2bab8c 100644 --- a/source/dnode/mgmt/bm/bmInt.c +++ b/source/dnode/mgmt/bm/bmInt.c @@ -113,8 +113,8 @@ void bmSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = bmOpen; mgmtFp.closeFp = bmClose; - mgmtFp.createMsgFp = bmProcessCreateReq; - mgmtFp.dropMsgFp = bmProcessDropReq; + mgmtFp.createFp = bmProcessCreateReq; + mgmtFp.dropFp = bmProcessDropReq; mgmtFp.requiredFp = bmRequire; bmInitMsgHandle(pWrapper); diff --git a/source/dnode/mgmt/dm/dmFile.c b/source/dnode/mgmt/dm/dmFile.c index c1964ac8c4..aefc28c46d 100644 --- a/source/dnode/mgmt/dm/dmFile.c +++ b/source/dnode/mgmt/dm/dmFile.c @@ -16,11 +16,11 @@ #define _DEFAULT_SOURCE #include "dmInt.h" -static void dmPrintDnodes(SDnodeMgmt *pMgmt); -static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep); -static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps); +static void dmPrintDnodes(SDnodeData *pMgmt); +static bool dmIsEpChanged(SDnodeData *pMgmt, int32_t dnodeId, const char *ep); +static void dmResetDnodes(SDnodeData *pMgmt, SArray *dnodeEps); -int32_t dmReadFile(SDnodeMgmt *pMgmt) { +int32_t dmReadFile(SDnodeData *pMgmt) { int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int32_t len = 0; int32_t maxLen = 256 * 1024; @@ -62,21 +62,21 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { dError("failed to read %s since dnodeId not found", file); goto PRASE_DNODE_OVER; } - pDnode->dnodeId = dnodeId->valueint; + pDnode->data.dnodeId = dnodeId->valueint; cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); if (!clusterId || clusterId->type != cJSON_String) { dError("failed to read %s since clusterId not found", file); goto PRASE_DNODE_OVER; } - pDnode->clusterId = atoll(clusterId->valuestring); + pDnode->data.clusterId = atoll(clusterId->valuestring); cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); if (!dropped || dropped->type != cJSON_Number) { dError("failed to read %s since dropped not found", file); goto PRASE_DNODE_OVER; } - pDnode->dropped = dropped->valueint; + pDnode->data.dropped = dropped->valueint; cJSON *dnodes = cJSON_GetObjectItem(root, "dnodes"); if (!dnodes || dnodes->type != cJSON_Array) { @@ -138,15 +138,15 @@ PRASE_DNODE_OVER: if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); - if (dmIsEpChanged(pMgmt, pDnode->dnodeId, pDnode->localEp)) { - dError("localEp %s different with %s and need reconfigured", pDnode->localEp, file); + if (dmIsEpChanged(pMgmt, pDnode->data.dnodeId, pDnode->data.localEp)) { + dError("localEp %s different with %s and need reconfigured", pDnode->data.localEp, file); return -1; } if (taosArrayGetSize(pMgmt->dnodeEps) == 0) { SDnodeEp dnodeEp = {0}; dnodeEp.isMnode = 1; - taosGetFqdnPortFromEp(pDnode->firstEp, &dnodeEp.ep); + taosGetFqdnPortFromEp(pDnode->data.firstEp, &dnodeEp.ep); taosArrayPush(pMgmt->dnodeEps, &dnodeEp); } @@ -156,7 +156,7 @@ PRASE_DNODE_OVER: return code; } -int32_t dmWriteFile(SDnodeMgmt *pMgmt) { +int32_t dmWriteFile(SDnodeData *pMgmt) { SDnode *pDnode = pMgmt->pDnode; char file[PATH_MAX]; @@ -174,9 +174,9 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { char *content = taosMemoryCalloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->dnodeId); - len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->clusterId); - len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->dropped); + len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->data.dnodeId); + len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->data.clusterId); + len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->data.dropped); len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n"); int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); @@ -213,7 +213,7 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { return 0; } -void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *dnodeEps) { +void dmUpdateDnodeEps(SDnodeData *pMgmt, SArray *dnodeEps) { int32_t numOfEps = taosArrayGetSize(dnodeEps); if (numOfEps <= 0) return; @@ -234,7 +234,7 @@ void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *dnodeEps) { taosWUnLockLatch(&pMgmt->latch); } -static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) { +static void dmResetDnodes(SDnodeData *pMgmt, SArray *dnodeEps) { if (pMgmt->dnodeEps != dnodeEps) { SArray *tmp = pMgmt->dnodeEps; pMgmt->dnodeEps = taosArrayDup(dnodeEps); @@ -265,7 +265,7 @@ static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) { dmPrintDnodes(pMgmt); } -static void dmPrintDnodes(SDnodeMgmt *pMgmt) { +static void dmPrintDnodes(SDnodeData *pMgmt) { int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); dDebug("print dnode ep list, num:%d", numOfEps); for (int32_t i = 0; i < numOfEps; i++) { @@ -274,7 +274,7 @@ static void dmPrintDnodes(SDnodeMgmt *pMgmt) { } } -static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep) { +static bool dmIsEpChanged(SDnodeData *pMgmt, int32_t dnodeId, const char *ep) { bool changed = false; taosRLockLatch(&pMgmt->latch); diff --git a/source/dnode/mgmt/dm/dmHandle.c b/source/dnode/mgmt/dm/dmHandle.c index 46d94fb844..36edc089f0 100644 --- a/source/dnode/mgmt/dm/dmHandle.c +++ b/source/dnode/mgmt/dm/dmHandle.c @@ -16,20 +16,20 @@ #define _DEFAULT_SOURCE #include "dmInt.h" -void dmSendStatusReq(SDnodeMgmt *pMgmt) { +void dmSendStatusReq(SDnodeData *pMgmt) { SDnode *pDnode = pMgmt->pDnode; SStatusReq req = {0}; taosRLockLatch(&pMgmt->latch); req.sver = tsVersion; - req.dver = pMgmt->dver; - req.dnodeId = pDnode->dnodeId; - req.clusterId = pDnode->clusterId; - req.rebootTime = pDnode->rebootTime; + req.dnodeVer = pMgmt->dnodeVer; + req.dnodeId = pDnode->data.dnodeId; + req.clusterId = pDnode->data.clusterId; + req.rebootTime = pDnode->data.rebootTime; req.updateTime = pMgmt->updateTime; req.numOfCores = tsNumOfCores; - req.numOfSupportVnodes = pDnode->numOfSupportVnodes; - tstrncpy(req.dnodeEp, pDnode->localEp, TSDB_EP_LEN); + req.numOfSupportVnodes = pDnode->data.supportVnodes; + tstrncpy(req.dnodeEp, pDnode->data.localEp, TSDB_EP_LEN); req.clusterCfg.statusInterval = tsStatusInterval; req.clusterCfg.checkTime = 0; @@ -40,7 +40,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); taosRUnLockLatch(&pMgmt->latch); - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES); + SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODE); if (pWrapper != NULL) { SMonVloadInfo info = {0}; dmGetVnodeLoads(pWrapper, &info); @@ -62,34 +62,34 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { tmsgSendReq(&pMgmt->msgCb, &epSet, &rpcMsg); } -static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) { +static void dmUpdateDnodeCfg(SDnodeData *pMgmt, SDnodeCfg *pCfg) { SDnode *pDnode = pMgmt->pDnode; - if (pDnode->dnodeId == 0) { + if (pDnode->data.dnodeId == 0) { dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); taosWLockLatch(&pMgmt->latch); - pDnode->dnodeId = pCfg->dnodeId; - pDnode->clusterId = pCfg->clusterId; + pDnode->data.dnodeId = pCfg->dnodeId; + pDnode->data.clusterId = pCfg->clusterId; dmWriteFile(pMgmt); taosWUnLockLatch(&pMgmt->latch); } } -int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessStatusRsp(SDnodeData *pMgmt, SNodeMsg *pMsg) { SDnode *pDnode = pMgmt->pDnode; SRpcMsg *pRsp = &pMsg->rpcMsg; if (pRsp->code != TSDB_CODE_SUCCESS) { - if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->dropped && pDnode->dnodeId > 0) { - dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->dnodeId); - pDnode->dropped = 1; + if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->data.dropped && pDnode->data.dnodeId > 0) { + dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->data.dnodeId); + pDnode->data.dropped = 1; dmWriteFile(pMgmt); } } else { SStatusRsp statusRsp = {0}; if (pRsp->pCont != NULL && pRsp->contLen != 0 && tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) { - pMgmt->dver = statusRsp.dver; + pMgmt->dnodeVer = statusRsp.dnodeVer; dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg); dmUpdateDnodeEps(pMgmt, statusRsp.pDnodeEps); } @@ -100,26 +100,26 @@ int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { return TSDB_CODE_SUCCESS; } -int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessAuthRsp(SDnodeData *pMgmt, SNodeMsg *pMsg) { SRpcMsg *pRsp = &pMsg->rpcMsg; dError("auth rsp is received, but not supported yet"); return 0; } -int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessGrantRsp(SDnodeData *pMgmt, SNodeMsg *pMsg) { SRpcMsg *pRsp = &pMsg->rpcMsg; dError("grant rsp is received, but not supported yet"); return 0; } -int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessConfigReq(SDnodeData *pMgmt, SNodeMsg *pMsg) { SRpcMsg *pReq = &pMsg->rpcMsg; SDCfgDnodeReq *pCfg = pReq->pCont; dError("config req is received, but not supported yet"); return TSDB_CODE_OPS_NOT_SUPPORT; } -static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { +static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) { SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); if (pWrapper != NULL) { dndReleaseWrapper(pWrapper); @@ -136,7 +136,7 @@ static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg * return -1; } - int32_t code = (*pWrapper->fp.createMsgFp)(pWrapper, pMsg); + int32_t code = (*pWrapper->fp.createFp)(pWrapper, pMsg); if (code != 0) { dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); } else { @@ -147,7 +147,7 @@ static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg * return code; } -static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { +static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) { SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); if (pWrapper == NULL) { terrno = TSDB_CODE_NODE_NOT_DEPLOYED; @@ -158,7 +158,7 @@ static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pM taosWLockLatch(&pWrapper->latch); pWrapper->deployed = false; - int32_t code = (*pWrapper->fp.dropMsgFp)(pWrapper, pMsg); + int32_t code = (*pWrapper->fp.dropFp)(pWrapper, pMsg); if (code != 0) { pWrapper->deployed = true; dError("node:%s, failed to drop since %s", pWrapper->name, terrstr()); diff --git a/source/dnode/mgmt/dm/dmInt.c b/source/dnode/mgmt/dm/dmInt.c index c710af9006..8151aa8d1e 100644 --- a/source/dnode/mgmt/dm/dmInt.c +++ b/source/dnode/mgmt/dm/dmInt.c @@ -16,13 +16,13 @@ #define _DEFAULT_SOURCE #include "dmInt.h" -void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) { +void dmGetMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet) { taosRLockLatch(&pMgmt->latch); *pEpSet = pMgmt->mnodeEpSet; taosRUnLockLatch(&pMgmt->latch); } -void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) { +void dmUpdateMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet) { dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); taosWLockLatch(&pMgmt->latch); @@ -35,7 +35,7 @@ void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) { } void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; + SDnodeData *pMgmt = pWrapper->pMgmt; taosRLockLatch(&pMgmt->latch); SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); @@ -54,7 +54,7 @@ void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqd taosRUnLockLatch(&pMgmt->latch); } -void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pReq) { +void dmSendRedirectRsp(SDnodeData *pMgmt, const SRpcMsg *pReq) { SDnode *pDnode = pMgmt->pDnode; SEpSet epSet = {0}; @@ -63,7 +63,7 @@ void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pReq) { dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse); for (int32_t i = 0; i < epSet.numOfEps; ++i) { dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); - if (strcmp(epSet.eps[i].fqdn, pDnode->localFqdn) == 0 && epSet.eps[i].port == pDnode->serverPort) { + if (strcmp(epSet.eps[i].fqdn, pDnode->data.localFqdn) == 0 && epSet.eps[i].port == pDnode->data.serverPort) { epSet.inUse = (i + 1) % epSet.numOfEps; } @@ -80,15 +80,14 @@ static int32_t dmStart(SMgmtWrapper *pWrapper) { static int32_t dmInit(SMgmtWrapper *pWrapper) { SDnode *pDnode = pWrapper->pDnode; - SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt)); + SDnodeData *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeData)); dInfo("dnode-mgmt start to init"); - pDnode->dnodeId = 0; - pDnode->dropped = 0; - pDnode->clusterId = 0; + pDnode->data.dnodeId = 0; + pDnode->data.dropped = 0; + pDnode->data.clusterId = 0; pMgmt->path = pWrapper->path; pMgmt->pDnode = pDnode; - pMgmt->pWrapper = pWrapper; taosInitRWLatch(&pMgmt->latch); pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); @@ -103,7 +102,7 @@ static int32_t dmInit(SMgmtWrapper *pWrapper) { return -1; } - if (pDnode->dropped) { + if (pDnode->data.dropped) { dError("dnode will not start since its already dropped"); return -1; } @@ -125,7 +124,7 @@ static int32_t dmInit(SMgmtWrapper *pWrapper) { } static void dmCleanup(SMgmtWrapper *pWrapper) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; + SDnodeData *pMgmt = pWrapper->pMgmt; if (pMgmt == NULL) return; dInfo("dnode-mgmt start to clean up"); diff --git a/source/dnode/mgmt/dm/dmMonitor.c b/source/dnode/mgmt/dm/dmMonitor.c index 6edf85106b..136158e10f 100644 --- a/source/dnode/mgmt/dm/dmMonitor.c +++ b/source/dnode/mgmt/dm/dmMonitor.c @@ -18,13 +18,13 @@ static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { pInfo->protocol = 1; - pInfo->dnode_id = pDnode->dnodeId; - pInfo->cluster_id = pDnode->clusterId; + pInfo->dnode_id = pDnode->data.dnodeId; + pInfo->cluster_id = pDnode->data.clusterId; tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN); } static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { - pInfo->uptime = (taosGetTimestampMs() - pDnode->rebootTime) / (86400000.0f); + pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) / (86400000.0f); pInfo->has_mnode = pDnode->wrappers[MNODE].required; pInfo->has_qnode = pDnode->wrappers[QNODE].required; pInfo->has_snode = pDnode->wrappers[SNODE].required; @@ -79,7 +79,7 @@ void dmSendMonitorReport(SDnode *pDnode) { } } - pWrapper = &pDnode->wrappers[VNODES]; + pWrapper = &pDnode->wrappers[VNODE]; if (getFromAPI) { if (dndMarkWrapper(pWrapper) == 0) { vmGetMonitorInfo(pWrapper, &vmInfo); diff --git a/source/dnode/mgmt/dm/dmWorker.c b/source/dnode/mgmt/dm/dmWorker.c index 7009469c00..6886c56fab 100644 --- a/source/dnode/mgmt/dm/dmWorker.c +++ b/source/dnode/mgmt/dm/dmWorker.c @@ -17,7 +17,7 @@ #include "dmInt.h" static void *dmThreadRoutine(void *param) { - SDnodeMgmt *pMgmt = param; + SDnodeData *pMgmt = param; SDnode *pDnode = pMgmt->pDnode; int64_t lastStatusTime = taosGetTimestampMs(); int64_t lastMonitorTime = lastStatusTime; @@ -27,7 +27,7 @@ static void *dmThreadRoutine(void *param) { while (true) { taosThreadTestCancel(); taosMsleep(200); - if (dndGetStatus(pDnode) != DND_STAT_RUNNING || pDnode->dropped) { + if (dndGetStatus(pDnode) != DND_STAT_RUNNING || pDnode->data.dropped) { continue; } @@ -47,7 +47,7 @@ static void *dmThreadRoutine(void *param) { return TSDB_CODE_SUCCESS; } -int32_t dmStartThread(SDnodeMgmt *pMgmt) { +int32_t dmStartThread(SDnodeData *pMgmt) { pMgmt->threadId = taosCreateThread(dmThreadRoutine, pMgmt); if (pMgmt->threadId == NULL) { dError("failed to init dnode thread"); @@ -59,7 +59,7 @@ int32_t dmStartThread(SDnodeMgmt *pMgmt) { } static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pInfo->ahandle; + SDnodeData *pMgmt = pInfo->ahandle; SDnode *pDnode = pMgmt->pDnode; SRpcMsg *pRpc = &pMsg->rpcMsg; @@ -95,7 +95,7 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { taosFreeQitem(pMsg); } -int32_t dmStartWorker(SDnodeMgmt *pMgmt) { +int32_t dmStartWorker(SDnodeData *pMgmt) { SSingleWorkerCfg mcfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mcfg) != 0) { dError("failed to start dnode mgmt worker since %s", terrstr()); @@ -112,7 +112,7 @@ int32_t dmStartWorker(SDnodeMgmt *pMgmt) { return 0; } -void dmStopWorker(SDnodeMgmt *pMgmt) { +void dmStopWorker(SDnodeData *pMgmt) { tSingleWorkerCleanup(&pMgmt->mgmtWorker); tSingleWorkerCleanup(&pMgmt->monitorWorker); @@ -124,7 +124,7 @@ void dmStopWorker(SDnodeMgmt *pMgmt) { } int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; + SDnodeData *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->mgmtWorker; dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); @@ -133,7 +133,7 @@ int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { } int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; + SDnodeData *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->monitorWorker; dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); diff --git a/source/dnode/mgmt/exe/dndMain.c b/source/dnode/mgmt/exe/dndMain.c index 997c56f9fb..3779f94620 100644 --- a/source/dnode/mgmt/exe/dndMain.c +++ b/source/dnode/mgmt/exe/dndMain.c @@ -26,7 +26,7 @@ static struct { char apolloUrl[PATH_MAX]; SArray *pArgs; // SConfigPair SDnode *pDnode; - EDndType ntype; + EDndNodeType ntype; } global = {0}; static void dndStopDnode(int signum, void *info, void *ctx) { @@ -46,7 +46,7 @@ static void dndSetSignalHandle() { taosSetSignal(SIGQUIT, dndStopDnode); if (!tsMultiProcess) { - } else if (global.ntype == DNODE || global.ntype == NODE_MAX) { + } else if (global.ntype == NODE_BEGIN || global.ntype == NODE_END) { taosIgnSignal(SIGCHLD); } else { taosKillChildOnParentStopped(); @@ -72,8 +72,8 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { tstrncpy(global.envFile, argv[++i], PATH_MAX); } else if (strcmp(argv[i], "-n") == 0) { global.ntype = atoi(argv[++i]); - if (global.ntype <= DNODE || global.ntype > NODE_MAX) { - printf("'-n' range is [1 - %d], default is 0\n", NODE_MAX - 1); + if (global.ntype <= NODE_BEGIN || global.ntype > NODE_END) { + printf("'-n' range is [1 - %d], default is 0\n", NODE_END - 1); return -1; } } else if (strcmp(argv[i], "-k") == 0) { @@ -135,7 +135,7 @@ static int32_t dndInitLog() { static void dndSetProcInfo(int32_t argc, char **argv) { taosSetProcPath(argc, argv); - if (global.ntype != DNODE && global.ntype != NODE_MAX) { + if (global.ntype != NODE_BEGIN && global.ntype != NODE_END) { const char *name = dndNodeProcStr(global.ntype); taosSetProcName(argc, argv, name); } diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/inc/dmInt.h index a671368f06..4d6ebd63d2 100644 --- a/source/dnode/mgmt/inc/dmInt.h +++ b/source/dnode/mgmt/inc/dmInt.h @@ -22,35 +22,20 @@ extern "C" { #endif -typedef struct SDnodeMgmt { - int64_t dver; - int64_t updateTime; - int8_t statusSent; - SEpSet mnodeEpSet; - SHashObj *dnodeHash; - SArray *dnodeEps; - TdThread *threadId; - SRWLatch latch; - SSingleWorker mgmtWorker; - SSingleWorker monitorWorker; - SMsgCb msgCb; - const char *path; - SDnode *pDnode; - SMgmtWrapper *pWrapper; -} SDnodeMgmt; + // dmFile.c -int32_t dmReadFile(SDnodeMgmt *pMgmt); -int32_t dmWriteFile(SDnodeMgmt *pMgmt); -void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *pDnodeEps); +int32_t dmReadFile(SDnodeData *pMgmt); +int32_t dmWriteFile(SDnodeData *pMgmt); +void dmUpdateDnodeEps(SDnodeData *pMgmt, SArray *pDnodeEps); // dmHandle.c void dmInitMsgHandle(SMgmtWrapper *pWrapper); -void dmSendStatusReq(SDnodeMgmt *pMgmt); -int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); +void dmSendStatusReq(SDnodeData *pMgmt); +int32_t dmProcessConfigReq(SDnodeData *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessStatusRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessAuthRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessGrantRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); // dmMonitor.c @@ -58,9 +43,9 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); void dmSendMonitorReport(SDnode *pDnode); // dmWorker.c -int32_t dmStartThread(SDnodeMgmt *pMgmt); -int32_t dmStartWorker(SDnodeMgmt *pMgmt); -void dmStopWorker(SDnodeMgmt *pMgmt); +int32_t dmStartThread(SDnodeData *pMgmt); +int32_t dmStartWorker(SDnodeData *pMgmt); +void dmStopWorker(SDnodeData *pMgmt); int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); diff --git a/source/dnode/mgmt/inc/dndInt.h b/source/dnode/mgmt/inc/dndInt.h deleted file mode 100644 index a38fe87b59..0000000000 --- a/source/dnode/mgmt/inc/dndInt.h +++ /dev/null @@ -1,199 +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_DND_INT_H_ -#define _TD_DND_INT_H_ - -#include "os.h" - -#include "cJSON.h" -#include "tcache.h" -#include "tcrc32c.h" -#include "tdatablock.h" -#include "tglobal.h" -#include "thash.h" -#include "tlockfree.h" -#include "tlog.h" -#include "tmsg.h" -#include "tmsgcb.h" -#include "tprocess.h" -#include "tqueue.h" -#include "trpc.h" -#include "tthread.h" -#include "ttime.h" -#include "tworker.h" - -#include "dnode.h" -#include "monitor.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} -#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} -#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} -#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }} -#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} -#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} - -typedef enum { DNODE, VNODES, QNODE, SNODE, MNODE, BNODE, NODE_MAX } EDndType; -typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus; -typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EEnvStatus; -typedef enum { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType; - -typedef struct SMgmtFp SMgmtFp; -typedef struct SMgmtWrapper SMgmtWrapper; -typedef struct SMsgHandle SMsgHandle; -typedef struct SDnodeMgmt SDnodeMgmt; -typedef struct SVnodesMgmt SVnodesMgmt; -typedef struct SMnodeMgmt SMnodeMgmt; -typedef struct SQnodeMgmt SQnodeMgmt; -typedef struct SSnodeMgmt SSnodeMgmt; -typedef struct SBnodeMgmt SBnodeMgmt; - -typedef int32_t (*NodeMsgFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper); -typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper); -typedef int32_t (*StartNodeFp)(SMgmtWrapper *pWrapper); -typedef int32_t (*CreateNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -typedef int32_t (*DropNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -typedef int32_t (*RequireNodeFp)(SMgmtWrapper *pWrapper, bool *required); - -typedef struct SMsgHandle { - SMgmtWrapper *pQndWrapper; - SMgmtWrapper *pMndWrapper; - SMgmtWrapper *pWrapper; -} SMsgHandle; - -typedef struct SMgmtFp { - OpenNodeFp openFp; - CloseNodeFp closeFp; - StartNodeFp startFp; - CreateNodeFp createMsgFp; - DropNodeFp dropMsgFp; - RequireNodeFp requiredFp; -} SMgmtFp; - -typedef struct SMgmtWrapper { - const char *name; - char *path; - int32_t refCount; - SRWLatch latch; - EDndType ntype; - bool deployed; - bool required; - EProcType procType; - int32_t procId; - SProcObj *pProc; - SShm shm; - void *pMgmt; - SDnode *pDnode; - SMgmtFp fp; - int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode - NodeMsgFp msgFps[TDMT_MAX]; -} SMgmtWrapper; - -typedef struct { - void *serverRpc; - void *clientRpc; - SMsgHandle msgHandles[TDMT_MAX]; -} STransMgmt; - -typedef struct SDnode { - int64_t clusterId; - int32_t dnodeId; - int32_t numOfSupportVnodes; - int64_t rebootTime; - char *localEp; - char *localFqdn; - char *firstEp; - char *secondEp; - char *dataDir; - SDiskCfg *disks; - int32_t numOfDisks; - uint16_t serverPort; - bool dropped; - EProcType procType; - EDndType ntype; - EDndStatus status; - EDndEvent event; - SStartupReq startup; - TdFilePtr lockfile; - STransMgmt trans; - SMgmtWrapper wrappers[NODE_MAX]; -} SDnode; - -// dndEnv.c -const char *dndStatStr(EDndStatus stat); -const char *dndNodeLogStr(EDndType ntype); -const char *dndNodeProcStr(EDndType ntype); -const char *dndEventStr(EDndEvent ev); - -// dndExec.c -int32_t dndOpenNode(SMgmtWrapper *pWrapper); -void dndCloseNode(SMgmtWrapper *pWrapper); - -// dndFile.c -int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); -int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed); -TdFilePtr dndCheckRunning(const char *dataDir); -int32_t dndReadShmFile(SDnode *pDnode); -int32_t dndWriteShmFile(SDnode *pDnode); - -// dndInt.c -EDndStatus dndGetStatus(SDnode *pDnode); -void dndSetStatus(SDnode *pDnode, EDndStatus stat); -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType nType); -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); -void dndReleaseWrapper(SMgmtWrapper *pWrapper); -void dndHandleEvent(SDnode *pDnode, EDndEvent event); -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); - -// dndTransport.c -int32_t dndInitTrans(SDnode *pDnode); -void dndCleanupTrans(SDnode *pDnode); -SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); -SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); -int32_t dndInitMsgHandle(SDnode *pDnode); -void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); - -// mgmt -void dmSetMgmtFp(SMgmtWrapper *pWrapper); -void bmSetMgmtFp(SMgmtWrapper *pWrapper); -void qmSetMgmtFp(SMgmtWrapper *pMgmt); -void smSetMgmtFp(SMgmtWrapper *pWrapper); -void vmSetMgmtFp(SMgmtWrapper *pWrapper); -void mmSetMgmtFp(SMgmtWrapper *pMgmt); - -void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); -void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); -void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pMsg); - -void dmGetMonitorSysInfo(SMonSysInfo *pInfo); -void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); -void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); -void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); -void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); -void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); -void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_DND_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/CMakeLists.txt b/source/dnode/mgmt/interface/CMakeLists.txt new file mode 100644 index 0000000000..78f6ef03e5 --- /dev/null +++ b/source/dnode/mgmt/interface/CMakeLists.txt @@ -0,0 +1,10 @@ +aux_source_directory(src DNODE_INTERFACE) +add_library(dnode_interface STATIC ${DNODE_INTERFACE}) +target_include_directories( + dnode_interface + PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt" + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + dnode_interface cjson mnode vnode qnode snode bnode wal sync taos tfs monitor util +) \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dndDef.h b/source/dnode/mgmt/interface/inc/dndDef.h new file mode 100644 index 0000000000..0ce5a64ed0 --- /dev/null +++ b/source/dnode/mgmt/interface/inc/dndDef.h @@ -0,0 +1,153 @@ +/* + * 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_DND_DEF_H_ +#define _TD_DND_DEF_H_ + +#include "dndLog.h" + +#include "cJSON.h" +#include "tcache.h" +#include "tcrc32c.h" +#include "tdatablock.h" +#include "tglobal.h" +#include "thash.h" +#include "tlockfree.h" +#include "tlog.h" +#include "tmsg.h" +#include "tmsgcb.h" +#include "tprocess.h" +#include "tqueue.h" +#include "trpc.h" +#include "tthread.h" +#include "ttime.h" +#include "tworker.h" + +#include "dnode.h" +#include "monitor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { NODE_BEGIN, VNODE, QNODE, SNODE, MNODE, BNODE, NODE_END } EDndNodeType; +typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndRunStatus; +typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EDndEnvStatus; +typedef enum { DND_PROC_SINGLE, DND_PROC_CHILD, DND_PROC_PARENT } EDndProcType; + +typedef int32_t (*NodeMsgFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +typedef int32_t (*OpenNodeFp)(struct SMgmtWrapper *pWrapper); +typedef void (*CloseNodeFp)(struct SMgmtWrapper *pWrapper); +typedef int32_t (*StartNodeFp)(struct SMgmtWrapper *pWrapper); +typedef void (*StopNodeFp)(struct SMgmtWrapper *pWrapper); +typedef int32_t (*CreateNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +typedef int32_t (*DropNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +typedef int32_t (*RequireNodeFp)(struct SMgmtWrapper *pWrapper, bool *required); + +typedef struct { + SMgmtWrapper *pQndWrapper; + SMgmtWrapper *pMndWrapper; + SMgmtWrapper *pNdWrapper; +} SMsgHandle; + +typedef struct { + OpenNodeFp openFp; + CloseNodeFp closeFp; + StartNodeFp startFp; + StopNodeFp stopFp; + CreateNodeFp createFp; + DropNodeFp dropFp; + RequireNodeFp requiredFp; +} SMgmtFp; + +typedef struct SMgmtWrapper { + SDnode *pDnode; + struct { + const char *name; + char *path; + int32_t refCount; + SRWLatch latch; + EDndNodeType ntype; + bool deployed; + bool required; + SMgmtFp fp; + void *pMgmt; + }; + struct { + EDndProcType procType; + int32_t procId; + SProcObj *procObj; + SShm procShm; + }; + struct { + int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode + NodeMsgFp msgFps[TDMT_MAX]; + }; +} SMgmtWrapper; + +typedef struct { + void *serverRpc; + void *clientRpc; + SMsgHandle msgHandles[TDMT_MAX]; +} SDnodeTrans; + +typedef struct { + int32_t dnodeId; + int64_t clusterId; + int64_t dnodeVer; + int64_t updateTime; + int64_t rebootTime; + bool dropped; + int8_t statusSent; + SEpSet mnodeEpSet; + SHashObj *dnodeHash; + SArray *dnodeEps; + TdThread *threadId; + SRWLatch latch; + SSingleWorker mgmtWorker; + SSingleWorker monitorWorker; + SMsgCb msgCb; + SDnode *pDnode; + const char *path; + TdFilePtr lockfile; + struct { + char *localEp; + char *localFqdn; + char *firstEp; + char *secondEp; + char *dataDir; + SDiskCfg *disks; + int32_t numOfDisks; + int32_t supportVnodes; + uint16_t serverPort; + }; +} SDnodeData; + +typedef struct SDnode { + EDndProcType ptype; + EDndNodeType ntype; + EDndRunStatus status; + EDndEvent event; + SStartupReq startup; + SDnodeTrans trans; + SDnodeData data; + SMgmtWrapper wrappers[NODE_END]; +} SDnode; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_DEF_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dndInt.h b/source/dnode/mgmt/interface/inc/dndInt.h new file mode 100644 index 0000000000..b08f372daa --- /dev/null +++ b/source/dnode/mgmt/interface/inc/dndInt.h @@ -0,0 +1,86 @@ +/* + * 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_DND_INT_H_ +#define _TD_DND_INT_H_ + +#include "dndLog.h" +#include "dndDef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// dndEnv.c +const char *dndStatStr(EDndRunStatus stat); +const char *dndNodeLogStr(EDndNodeType ntype); +const char *dndNodeProcStr(EDndNodeType ntype); +const char *dndEventStr(EDndEvent ev); + +// dndExec.c +int32_t dndOpenNode(SMgmtWrapper *pWrapper); +void dndCloseNode(SMgmtWrapper *pWrapper); + +// dndFile.c +int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); +int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed); +TdFilePtr dndCheckRunning(const char *dataDir); +int32_t dndReadShmFile(SDnode *pDnode); +int32_t dndWriteShmFile(SDnode *pDnode); + +// dndInt.c +EDndRunStatus dndGetStatus(SDnode *pDnode); +void dndSetStatus(SDnode *pDnode, EDndRunStatus stat); +void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); +SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType nType); +int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); +void dndReleaseWrapper(SMgmtWrapper *pWrapper); +void dndHandleEvent(SDnode *pDnode, EDndEvent event); +void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); + +// dndTransport.c +int32_t dndInitTrans(SDnode *pDnode); +void dndCleanupTrans(SDnode *pDnode); +SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); +SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); +int32_t dndInitMsgHandle(SDnode *pDnode); +void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); + +// mgmt +void dmSetMgmtFp(SMgmtWrapper *pWrapper); +void bmSetMgmtFp(SMgmtWrapper *pWrapper); +void qmSetMgmtFp(SMgmtWrapper *pMgmt); +void smSetMgmtFp(SMgmtWrapper *pWrapper); +void vmSetMgmtFp(SMgmtWrapper *pWrapper); +void mmSetMgmtFp(SMgmtWrapper *pMgmt); + +void dmGetMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); +void dmUpdateMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); +void dmSendRedirectRsp(SDnodeData *pMgmt, const SRpcMsg *pMsg); + +void dmGetMonitorSysInfo(SMonSysInfo *pInfo); +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); +void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); +void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); +void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); +void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dndLog.h b/source/dnode/mgmt/interface/inc/dndLog.h new file mode 100644 index 0000000000..78d24e0ef5 --- /dev/null +++ b/source/dnode/mgmt/interface/inc/dndLog.h @@ -0,0 +1,36 @@ +/* + * 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_DND_LOG_H_ +#define _TD_DND_LOG_H_ + +#include "tlog.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} +#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_LOG_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/src/dndInt.c b/source/dnode/mgmt/interface/src/dndInt.c new file mode 100644 index 0000000000..9ec37b5d04 --- /dev/null +++ b/source/dnode/mgmt/interface/src/dndInt.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dndInt.h" + +EDndRunStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; } + +void dndSetStatus(SDnode *pDnode, EDndRunStatus status) { + if (pDnode->status != status) { + dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status)); + pDnode->status = status; + } +} + +const char *dndStatStr(EDndRunStatus status) { + switch (status) { + case DND_STAT_INIT: + return "init"; + case DND_STAT_RUNNING: + return "running"; + case DND_STAT_STOPPED: + return "stopped"; + default: + return "UNKNOWN"; + } +} + +const char *dndNodeLogStr(EDndNodeType ntype) { + switch (ntype) { + case VNODE: + return "vnode"; + case QNODE: + return "qnode"; + case SNODE: + return "snode"; + case MNODE: + return "mnode"; + case BNODE: + return "bnode"; + default: + return "taosd"; + } +} + +const char *dndNodeProcStr(EDndNodeType ntype) { + switch (ntype) { + case VNODE: + return "taosv"; + case QNODE: + return "taosq"; + case SNODE: + return "taoss"; + case MNODE: + return "taosm"; + case BNODE: + return "taosb"; + default: + return "taosd"; + } +} + +const char *dndEventStr(EDndEvent ev) { + switch (ev) { + case DND_EVENT_START: + return "start"; + case DND_EVENT_STOP: + return "stop"; + case DND_EVENT_CHILD: + return "child"; + default: + return "UNKNOWN"; + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/main/dndEnv.c b/source/dnode/mgmt/main/dndEnv.c index 3c3f2144ab..9f75594335 100644 --- a/source/dnode/mgmt/main/dndEnv.c +++ b/source/dnode/mgmt/main/dndEnv.c @@ -57,63 +57,3 @@ void dndCleanup() { taosStopCacheRefreshWorker(); dInfo("dnode env is cleaned up"); } - -const char *dndStatStr(EDndStatus status) { - switch (status) { - case DND_STAT_INIT: - return "init"; - case DND_STAT_RUNNING: - return "running"; - case DND_STAT_STOPPED: - return "stopped"; - default: - return "UNKNOWN"; - } -} - -const char *dndNodeLogStr(EDndType ntype) { - switch (ntype) { - case VNODES: - return "vnode"; - case QNODE: - return "qnode"; - case SNODE: - return "snode"; - case MNODE: - return "mnode"; - case BNODE: - return "bnode"; - default: - return "taosd"; - } -} - -const char *dndNodeProcStr(EDndType ntype) { - switch (ntype) { - case VNODES: - return "taosv"; - case QNODE: - return "taosq"; - case SNODE: - return "taoss"; - case MNODE: - return "taosm"; - case BNODE: - return "taosb"; - default: - return "taosd"; - } -} - -const char *dndEventStr(EDndEvent ev) { - switch (ev) { - case DND_EVENT_START: - return "start"; - case DND_EVENT_STOP: - return "stop"; - case DND_EVENT_CHILD: - return "child"; - default: - return "UNKNOWN"; - } -} \ No newline at end of file diff --git a/source/dnode/mgmt/main/dndExec.c b/source/dnode/mgmt/main/dndExec.c index 51569d2ed4..bdc9a2751a 100644 --- a/source/dnode/mgmt/main/dndExec.c +++ b/source/dnode/mgmt/main/dndExec.c @@ -29,7 +29,7 @@ static bool dndRequireNode(SMgmtWrapper *pWrapper) { static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { int32_t shmsize = tsMnodeShmSize; - if (pWrapper->ntype == VNODES) { + if (pWrapper->ntype == VNODE) { shmsize = tsVnodeShmSize; } else if (pWrapper->ntype == QNODE) { shmsize = tsQnodeShmSize; @@ -43,18 +43,18 @@ static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { return -1; } - if (taosCreateShm(&pWrapper->shm, pWrapper->ntype, shmsize) != 0) { + if (taosCreateShm(&pWrapper->procShm, pWrapper->ntype, shmsize) != 0) { terrno = TAOS_SYSTEM_ERROR(terrno); dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr()); return -1; } - dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize); + dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->procShm.id, shmsize); SProcCfg cfg = dndGenProcCfg(pWrapper); cfg.isChild = false; - pWrapper->procType = PROC_PARENT; - pWrapper->pProc = taosProcInit(&cfg); - if (pWrapper->pProc == NULL) { + pWrapper->procType = DND_PROC_PARENT; + pWrapper->procObj = taosProcInit(&cfg); + if (pWrapper->procObj == NULL) { dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); return -1; } @@ -62,7 +62,7 @@ static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { return 0; } -static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndType n) { +static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) { char tstr[8] = {0}; char *args[6] = {0}; snprintf(tstr, sizeof(tstr), "%d", n); @@ -85,7 +85,7 @@ static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndType n) { } static int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) { - if (pWrapper->pDnode->ntype == NODE_MAX) { + if (pWrapper->pDnode->ntype == NODE_END) { dInfo("node:%s, should be started manually", pWrapper->name); } else { if (dndNewNodeProc(pWrapper, pWrapper->ntype) != 0) { @@ -93,7 +93,7 @@ static int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) { } } - if (taosProcRun(pWrapper->pProc) != 0) { + if (taosProcRun(pWrapper->procObj) != 0) { dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); return -1; } @@ -120,9 +120,9 @@ static int32_t dndOpenNodeImp(SMgmtWrapper *pWrapper) { int32_t dndOpenNode(SMgmtWrapper *pWrapper) { SDnode *pDnode = pWrapper->pDnode; - if (pDnode->procType == PROC_SINGLE) { + if (pDnode->ptype == DND_PROC_SINGLE) { return dndOpenNodeImp(pWrapper); - } else if (pDnode->procType == PROC_PARENT) { + } else if (pDnode->ptype == DND_PROC_PARENT) { if (dndInitNodeProc(pWrapper) != 0) return -1; if (dndWriteShmFile(pDnode) != 0) return -1; if (dndRunNodeProc(pWrapper) != 0) return -1; @@ -144,15 +144,15 @@ static void dndCloseNodeImp(SMgmtWrapper *pWrapper) { taosMsleep(10); } - if (pWrapper->pProc) { - taosProcCleanup(pWrapper->pProc); - pWrapper->pProc = NULL; + if (pWrapper->procObj) { + taosProcCleanup(pWrapper->procObj); + pWrapper->procObj = NULL; } dDebug("node:%s, mgmt has been closed", pWrapper->name); } void dndCloseNode(SMgmtWrapper *pWrapper) { - if (pWrapper->pDnode->procType == PROC_PARENT) { + if (pWrapper->pDnode->ptype == DND_PROC_PARENT) { if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); taosKillProc(pWrapper->procId); @@ -172,9 +172,9 @@ static void dndProcessProcHandle(void *handle) { static int32_t dndRunInSingleProcess(SDnode *pDnode) { dInfo("dnode run in single process"); - pDnode->procType = PROC_SINGLE; + pDnode->ptype = DND_PROC_SINGLE; - for (EDndType n = DNODE; n < NODE_MAX; ++n) { + for (EDndNodeType n = NODE_BEGIN; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; pWrapper->required = dndRequireNode(pWrapper); if (!pWrapper->required) continue; @@ -187,7 +187,7 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { dndSetStatus(pDnode, DND_STAT_RUNNING); - for (EDndType n = 0; n < NODE_MAX; ++n) { + for (EDndNodeType n = 0; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; if (!pWrapper->required) continue; if (pWrapper->fp.startFp == NULL) continue; @@ -213,15 +213,15 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { static int32_t dndRunInParentProcess(SDnode *pDnode) { dInfo("dnode run in parent process"); - pDnode->procType = PROC_PARENT; + pDnode->ptype = DND_PROC_PARENT; - SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE]; + SMgmtWrapper *pDWrapper = &pDnode->wrappers[NODE_BEGIN]; if (dndOpenNodeImp(pDWrapper) != 0) { dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); return -1; } - for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { + for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; pWrapper->required = dndRequireNode(pWrapper); if (!pWrapper->required) continue; @@ -233,7 +233,7 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { return -1; } - for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { + for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; if (!pWrapper->required) continue; if (dndRunNodeProc(pWrapper) != 0) return -1; @@ -254,10 +254,10 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { dInfo("dnode is about to stop"); dndSetStatus(pDnode, DND_STAT_STOPPED); - for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { + for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; if (!pWrapper->required) continue; - if (pDnode->ntype == NODE_MAX) continue; + if (pDnode->ntype == NODE_END) continue; if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); @@ -269,14 +269,14 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { } break; } else { - for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { + for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; if (!pWrapper->required) continue; - if (pDnode->ntype == NODE_MAX) continue; + if (pDnode->ntype == NODE_END) continue; if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); - taosProcCloseHandles(pWrapper->pProc, dndProcessProcHandle); + taosProcCloseHandles(pWrapper->procObj, dndProcessProcHandle); dndNewNodeProc(pWrapper, n); } } @@ -291,7 +291,7 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { static int32_t dndRunInChildProcess(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; dInfo("%s run in child process", pWrapper->name); - pDnode->procType = PROC_CHILD; + pDnode->ptype = DND_PROC_CHILD; pWrapper->required = dndRequireNode(pWrapper); if (!pWrapper->required) { @@ -301,7 +301,7 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { SMsgCb msgCb = dndCreateMsgcb(pWrapper); tmsgSetDefaultMsgCb(&msgCb); - pWrapper->procType = PROC_CHILD; + pWrapper->procType = DND_PROC_CHILD; if (dndOpenNodeImp(pWrapper) != 0) { dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); @@ -310,8 +310,8 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { SProcCfg cfg = dndGenProcCfg(pWrapper); cfg.isChild = true; - pWrapper->pProc = taosProcInit(&cfg); - if (pWrapper->pProc == NULL) { + pWrapper->procObj = taosProcInit(&cfg); + if (pWrapper->procObj == NULL) { dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); return -1; } @@ -325,7 +325,7 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { dndSetStatus(pDnode, DND_STAT_RUNNING); - if (taosProcRun(pWrapper->pProc) != 0) { + if (taosProcRun(pWrapper->procObj) != 0) { dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); return -1; } @@ -347,7 +347,7 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { int32_t dndRun(SDnode *pDnode) { if (!tsMultiProcess) { return dndRunInSingleProcess(pDnode); - } else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { + } else if (pDnode->ntype == NODE_BEGIN || pDnode->ntype == NODE_END) { return dndRunInParentProcess(pDnode); } else { return dndRunInChildProcess(pDnode); diff --git a/source/dnode/mgmt/main/dndFile.c b/source/dnode/mgmt/main/dndFile.c index 905624f072..45d80543a1 100644 --- a/source/dnode/mgmt/main/dndFile.c +++ b/source/dnode/mgmt/main/dndFile.c @@ -148,7 +148,7 @@ int32_t dndReadShmFile(SDnode *pDnode) { cJSON *root = NULL; TdFilePtr pFile = NULL; - snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->data.dataDir, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { dDebug("file %s not exist", file); @@ -164,37 +164,37 @@ int32_t dndReadShmFile(SDnode *pDnode) { goto _OVER; } - for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { + for (EDndNodeType ntype = NODE_BEGIN + 1; ntype < NODE_END; ++ntype) { snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype)); cJSON *shmid = cJSON_GetObjectItem(root, itemName); if (shmid && shmid->type == cJSON_Number) { - pDnode->wrappers[ntype].shm.id = shmid->valueint; + pDnode->wrappers[ntype].procShm.id = shmid->valueint; } snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype)); cJSON *shmsize = cJSON_GetObjectItem(root, itemName); if (shmsize && shmsize->type == cJSON_Number) { - pDnode->wrappers[ntype].shm.size = shmsize->valueint; + pDnode->wrappers[ntype].procShm.size = shmsize->valueint; } } } - if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { - for (EDndType ntype = DNODE; ntype < NODE_MAX; ++ntype) { + if (!tsMultiProcess || pDnode->ntype == NODE_BEGIN || pDnode->ntype == NODE_END) { + for (EDndNodeType ntype = NODE_BEGIN; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - if (pWrapper->shm.id >= 0) { - dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size); - taosDropShm(&pWrapper->shm); + if (pWrapper->procShm.id >= 0) { + dDebug("shmid:%d, is closed, size:%d", pWrapper->procShm.id, pWrapper->procShm.size); + taosDropShm(&pWrapper->procShm); } } } else { SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; - if (taosAttachShm(&pWrapper->shm) != 0) { + if (taosAttachShm(&pWrapper->procShm) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr()); + dError("shmid:%d, failed to attach shm since %s", pWrapper->procShm.id, terrstr()); goto _OVER; } - dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->shm.id, pWrapper->shm.size); + dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size); } dDebug("successed to load %s", file); @@ -215,8 +215,8 @@ int32_t dndWriteShmFile(SDnode *pDnode) { char realfile[PATH_MAX] = {0}; TdFilePtr pFile = NULL; - snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP); - snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->data.dataDir, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->data.dataDir, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -226,13 +226,13 @@ int32_t dndWriteShmFile(SDnode *pDnode) { } len += snprintf(content + len, MAXLEN - len, "{\n"); - for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { + for (EDndNodeType ntype = NODE_BEGIN + 1; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.id); - if (ntype == NODE_MAX - 1) { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->shm.size); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->procShm.id); + if (ntype == NODE_END - 1) { + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->procShm.size); } else { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.size); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->procShm.size); } } len += snprintf(content + len, MAXLEN - len, "}\n"); diff --git a/source/dnode/mgmt/main/dndInt.c b/source/dnode/mgmt/main/dndObj.c similarity index 72% rename from source/dnode/mgmt/main/dndInt.c rename to source/dnode/mgmt/main/dndObj.c index d406b0c02e..ff2be42722 100644 --- a/source/dnode/mgmt/main/dndInt.c +++ b/source/dnode/mgmt/main/dndObj.c @@ -17,27 +17,27 @@ #include "dndInt.h" static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { - pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes; - pDnode->serverPort = pOption->serverPort; - pDnode->dataDir = strdup(pOption->dataDir); - pDnode->localEp = strdup(pOption->localEp); - pDnode->localFqdn = strdup(pOption->localFqdn); - pDnode->firstEp = strdup(pOption->firstEp); - pDnode->secondEp = strdup(pOption->secondEp); - pDnode->disks = pOption->disks; - pDnode->numOfDisks = pOption->numOfDisks; + pDnode->data.supportVnodes = pOption->numOfSupportVnodes; + pDnode->data.serverPort = pOption->serverPort; + pDnode->data.dataDir = strdup(pOption->dataDir); + pDnode->data.localEp = strdup(pOption->localEp); + pDnode->data.localFqdn = strdup(pOption->localFqdn); + pDnode->data.firstEp = strdup(pOption->firstEp); + pDnode->data.secondEp = strdup(pOption->secondEp); + pDnode->data.disks = pOption->disks; + pDnode->data.numOfDisks = pOption->numOfDisks; pDnode->ntype = pOption->ntype; - pDnode->rebootTime = taosGetTimestampMs(); + pDnode->data.rebootTime = taosGetTimestampMs(); - if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL || - pDnode->secondEp == NULL) { + if (pDnode->data.dataDir == NULL || pDnode->data.localEp == NULL || pDnode->data.localFqdn == NULL || pDnode->data.firstEp == NULL || + pDnode->data.secondEp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { - pDnode->lockfile = dndCheckRunning(pDnode->dataDir); - if (pDnode->lockfile == NULL) { + if (!tsMultiProcess || pDnode->ntype == NODE_BEGIN || pDnode->ntype == NODE_END) { + pDnode->data.lockfile = dndCheckRunning(pDnode->data.dataDir); + if (pDnode->data.lockfile == NULL) { return -1; } } @@ -46,20 +46,20 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { } static void dndClearVars(SDnode *pDnode) { - for (EDndType n = 0; n < NODE_MAX; ++n) { + for (EDndNodeType n = 0; n < NODE_END; ++n) { SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; taosMemoryFreeClear(pMgmt->path); } - if (pDnode->lockfile != NULL) { - taosUnLockFile(pDnode->lockfile); - taosCloseFile(&pDnode->lockfile); - pDnode->lockfile = NULL; + if (pDnode->data.lockfile != NULL) { + taosUnLockFile(pDnode->data.lockfile); + taosCloseFile(&pDnode->data.lockfile); + pDnode->data.lockfile = NULL; } - taosMemoryFreeClear(pDnode->localEp); - taosMemoryFreeClear(pDnode->localFqdn); - taosMemoryFreeClear(pDnode->firstEp); - taosMemoryFreeClear(pDnode->secondEp); - taosMemoryFreeClear(pDnode->dataDir); + taosMemoryFreeClear(pDnode->data.localEp); + taosMemoryFreeClear(pDnode->data.localFqdn); + taosMemoryFreeClear(pDnode->data.firstEp); + taosMemoryFreeClear(pDnode->data.secondEp); + taosMemoryFreeClear(pDnode->data.dataDir); taosMemoryFree(pDnode); dDebug("dnode memory is cleared, data:%p", pDnode); } @@ -82,18 +82,18 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { } dndSetStatus(pDnode, DND_STAT_INIT); - dmSetMgmtFp(&pDnode->wrappers[DNODE]); + dmSetMgmtFp(&pDnode->wrappers[NODE_BEGIN]); mmSetMgmtFp(&pDnode->wrappers[MNODE]); - vmSetMgmtFp(&pDnode->wrappers[VNODES]); + vmSetMgmtFp(&pDnode->wrappers[VNODE]); qmSetMgmtFp(&pDnode->wrappers[QNODE]); smSetMgmtFp(&pDnode->wrappers[SNODE]); bmSetMgmtFp(&pDnode->wrappers[BNODE]); - for (EDndType n = 0; n < NODE_MAX; ++n) { + for (EDndNodeType n = 0; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name); + snprintf(path, sizeof(path), "%s%s%s", pDnode->data.dataDir, TD_DIRSEP, pWrapper->name); pWrapper->path = strdup(path); - pWrapper->shm.id = -1; + pWrapper->procShm.id = -1; pWrapper->pDnode = pDnode; pWrapper->ntype = n; if (pWrapper->path == NULL) { @@ -101,7 +101,7 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { goto _OVER; } - pWrapper->procType = PROC_SINGLE; + pWrapper->procType = DND_PROC_SINGLE; taosInitRWLatch(&pWrapper->latch); } @@ -134,7 +134,7 @@ _OVER: void dndClose(SDnode *pDnode) { if (pDnode == NULL) return; - for (EDndType n = 0; n < NODE_MAX; ++n) { + for (EDndNodeType n = 0; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; dndCloseNode(pWrapper); } @@ -149,7 +149,7 @@ void dndHandleEvent(SDnode *pDnode, EDndEvent event) { } } -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) { +SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; SMgmtWrapper *pRetWrapper = pWrapper; @@ -170,7 +170,7 @@ int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { int32_t code = 0; taosRLockLatch(&pWrapper->latch); - if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) { + if (pWrapper->deployed || (pWrapper->procType == DND_PROC_PARENT && pWrapper->required)) { int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); } else { @@ -196,15 +196,6 @@ void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId; } -EDndStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; } - -void dndSetStatus(SDnode *pDnode, EDndStatus status) { - if (pDnode->status != status) { - dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status)); - pDnode->status = status; - } -} - void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { SStartupReq *pStartup = &pDnode->startup; tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/main/dndTransport.c index bcebd521b6..c5f195d71e 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/main/dndTransport.c @@ -21,7 +21,7 @@ #define INTERNAL_SECRET "_pwd" static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[DNODE]; + SMgmtWrapper *pWrapper = &pDnode->wrappers[NODE_BEGIN]; dmUpdateMnodeEpSet(pWrapper->pMgmt, pEpSet); } @@ -53,7 +53,7 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS int32_t code = -1; SNodeMsg *pMsg = NULL; NodeMsgFp msgFp = NULL; - uint16_t msgType = pRpc->msgType; + uint16_t msgType = pRpc->msgType; if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) { dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet); @@ -64,12 +64,12 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER; if (dndBuildMsg(pMsg, pRpc) != 0) goto _OVER; - if (pWrapper->procType == PROC_SINGLE) { + if (pWrapper->procType == DND_PROC_SINGLE) { dTrace("msg:%p, is created, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); code = (*msgFp)(pWrapper, pMsg); - } else if (pWrapper->procType == PROC_PARENT) { + } else if (pWrapper->procType == DND_PROC_PARENT) { dTrace("msg:%p, is created and put into child queue, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); - code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle, + code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle, PROC_REQ); } else { dTrace("msg:%p, should not processed in child process, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); @@ -78,7 +78,7 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS _OVER: if (code == 0) { - if (pWrapper->procType == PROC_PARENT) { + if (pWrapper->procType == DND_PROC_PARENT) { dTrace("msg:%p, is freed in parent process", pMsg); taosFreeQitem(pMsg); rpcFreeCont(pRpc->pCont); @@ -105,11 +105,11 @@ _OVER: } static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - STransMgmt *pMgmt = &pDnode->trans; + SDnodeTrans *pTrans = &pDnode->trans; tmsg_t msgType = pMsg->msgType; bool isReq = msgType & 1u; - SMsgHandle *pHandle = &pMgmt->msgHandles[TMSG_INDEX(msgType)]; - SMgmtWrapper *pWrapper = pHandle->pWrapper; + SMsgHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(msgType)]; + SMgmtWrapper *pWrapper = pHandle->pNdWrapper; if (msgType == TDMT_DND_NETWORK_TEST) { dTrace("network test req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle); @@ -159,7 +159,7 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { } static int32_t dndInitClient(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; + SDnodeTrans *pTrans = &pDnode->trans; SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); @@ -178,8 +178,8 @@ static int32_t dndInitClient(SDnode *pDnode) { taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); rpcInit.secret = pass; - pMgmt->clientRpc = rpcOpen(&rpcInit); - if (pMgmt->clientRpc == NULL) { + pTrans->clientRpc = rpcOpen(&rpcInit); + if (pTrans->clientRpc == NULL) { dError("failed to init dnode rpc client"); return -1; } @@ -189,17 +189,17 @@ static int32_t dndInitClient(SDnode *pDnode) { } static void dndCleanupClient(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; - if (pMgmt->clientRpc) { - rpcClose(pMgmt->clientRpc); - pMgmt->clientRpc = NULL; + SDnodeTrans *pTrans = &pDnode->trans; + if (pTrans->clientRpc) { + rpcClose(pTrans->clientRpc); + pTrans->clientRpc = NULL; dDebug("dnode rpc client is closed"); } } static inline void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) { SEpSet epSet = {0}; - SMgmtWrapper *pWrapper = &pDnode->wrappers[DNODE]; + SMgmtWrapper *pWrapper = &pDnode->wrappers[NODE_BEGIN]; dmGetMnodeEpSet(pWrapper->pMgmt, &epSet); rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp); } @@ -263,11 +263,11 @@ static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, ch } static int32_t dndInitServer(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; + SDnodeTrans *pTrans = &pDnode->trans; SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); - rpcInit.localPort = pDnode->serverPort; + rpcInit.localPort = pDnode->data.serverPort; rpcInit.label = "DND"; rpcInit.numOfThreads = tsNumOfRpcThreads; rpcInit.cfp = (RpcCfp)dndProcessMsg; @@ -277,8 +277,8 @@ static int32_t dndInitServer(SDnode *pDnode) { rpcInit.afp = (RpcAfp)dndRetrieveUserAuthInfo; rpcInit.parent = pDnode; - pMgmt->serverRpc = rpcOpen(&rpcInit); - if (pMgmt->serverRpc == NULL) { + pTrans->serverRpc = rpcOpen(&rpcInit); + if (pTrans->serverRpc == NULL) { dError("failed to init dnode rpc server"); return -1; } @@ -288,10 +288,10 @@ static int32_t dndInitServer(SDnode *pDnode) { } static void dndCleanupServer(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; - if (pMgmt->serverRpc) { - rpcClose(pMgmt->serverRpc); - pMgmt->serverRpc = NULL; + SDnodeTrans *pTrans = &pDnode->trans; + if (pTrans->serverRpc) { + rpcClose(pTrans->serverRpc); + pTrans->serverRpc = NULL; dDebug("dnode rpc server is closed"); } } @@ -308,9 +308,9 @@ void dndCleanupTrans(SDnode *pDnode) { } int32_t dndInitMsgHandle(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; + SDnodeTrans *pTrans = &pDnode->trans; - for (EDndType n = 0; n < NODE_MAX; ++n) { + for (EDndNodeType n = 0; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) { @@ -318,7 +318,7 @@ int32_t dndInitMsgHandle(SDnode *pDnode) { int8_t vgId = pWrapper->msgVgIds[msgIndex]; if (msgFp == NULL) continue; - SMsgHandle *pHandle = &pMgmt->msgHandles[msgIndex]; + SMsgHandle *pHandle = &pTrans->msgHandles[msgIndex]; if (vgId == QNODE_HANDLE) { if (pHandle->pQndWrapper != NULL) { dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); @@ -332,11 +332,11 @@ int32_t dndInitMsgHandle(SDnode *pDnode) { } pHandle->pMndWrapper = pWrapper; } else { - if (pHandle->pWrapper != NULL) { + if (pHandle->pNdWrapper != NULL) { dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); return -1; } - pHandle->pWrapper = pWrapper; + pHandle->pNdWrapper = pWrapper; } } } @@ -344,13 +344,13 @@ int32_t dndInitMsgHandle(SDnode *pDnode) { return 0; } -static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *pReq) { - if (pMgmt->clientRpc == NULL) { +static int32_t dndSendRpcReq(SDnodeTrans *pTrans, const SEpSet *pEpSet, SRpcMsg *pReq) { + if (pTrans->clientRpc == NULL) { terrno = TSDB_CODE_NODE_OFFLINE; return -1; } - rpcSendRequest(pMgmt->clientRpc, pEpSet, pReq, NULL); + rpcSendRequest(pTrans->clientRpc, pEpSet, pReq, NULL); return 0; } @@ -369,7 +369,7 @@ static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg return -1; } - if (pWrapper->procType != PROC_CHILD) { + if (pWrapper->procType != DND_PROC_CHILD) { return dndSendRpcReq(&pWrapper->pDnode->trans, pEpSet, pReq); } else { char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet)); @@ -380,7 +380,7 @@ static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg memcpy(pHead, pReq, sizeof(SRpcMsg)); memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet)); - taosProcPutToParentQ(pWrapper->pProc, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen, + taosProcPutToParentQ(pWrapper->procObj, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen, PROC_REQ); taosMemoryFree(pHead); return 0; @@ -388,27 +388,27 @@ static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg } static void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { - if (pWrapper->procType != PROC_CHILD) { + if (pWrapper->procType != DND_PROC_CHILD) { dndSendRpcRsp(pWrapper, pRsp); } else { - taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP); + taosProcPutToParentQ(pWrapper->procObj, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP); } } static void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { - if (pWrapper->procType != PROC_CHILD) { + if (pWrapper->procType != DND_PROC_CHILD) { rpcRegisterBrokenLinkArg(pMsg); } else { - taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REGIST); + taosProcPutToParentQ(pWrapper->procObj, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REGIST); } } static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) { - if (pWrapper->procType != PROC_CHILD) { + if (pWrapper->procType != DND_PROC_CHILD) { rpcReleaseHandle(handle, type); } else { SRpcMsg msg = {.handle = handle, .code = type}; - taosProcPutToParentQ(pWrapper->pProc, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE); + taosProcPutToParentQ(pWrapper->procObj, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE); } } @@ -456,7 +456,7 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t rpcRegisterBrokenLinkArg(pMsg); break; case PROC_RELEASE: - taosProcRemoveHandle(pWrapper->pProc, pMsg->handle); + taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); rpcFreeCont(pCont); break; @@ -464,7 +464,7 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t dndSendRpcReq(&pWrapper->pDnode->trans, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); break; case PROC_RSP: - taosProcRemoveHandle(pWrapper->pProc, pMsg->handle); + taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); dndSendRpcRsp(pWrapper, pMsg); break; default: @@ -484,7 +484,7 @@ SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) { .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .shm = pWrapper->shm, + .shm = pWrapper->procShm, .parent = pWrapper, .name = pWrapper->name}; return cfg; diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c index 63240c3224..08f1ff1cfa 100644 --- a/source/dnode/mgmt/mm/mmHandle.c +++ b/source/dnode/mgmt/mm/mmHandle.c @@ -56,7 +56,7 @@ int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (createReq.replica <= 1 || createReq.dnodeId != pDnode->dnodeId) { + if (createReq.replica <= 1 || createReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create mnode since %s", terrstr()); return -1; @@ -75,7 +75,7 @@ int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->dnodeId) { + if (dropReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop mnode since %s", terrstr()); return -1; @@ -95,9 +95,9 @@ int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { return -1; } - if (alterReq.dnodeId != pDnode->dnodeId) { + if (alterReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->dnodeId, alterReq.dnodeId); + dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->data.dnodeId, alterReq.dnodeId); return -1; } else { return mmAlter(pMgmt, &alterReq); diff --git a/source/dnode/mgmt/mm/mmInt.c b/source/dnode/mgmt/mm/mmInt.c index 49886621ec..374b33ed01 100644 --- a/source/dnode/mgmt/mm/mmInt.c +++ b/source/dnode/mgmt/mm/mmInt.c @@ -18,9 +18,9 @@ #include "wal.h" static bool mmDeployRequired(SDnode *pDnode) { - if (pDnode->dnodeId > 0) return false; - if (pDnode->clusterId > 0) return false; - if (strcmp(pDnode->localEp, pDnode->firstEp) != 0) return false; + if (pDnode->data.dnodeId > 0) return false; + if (pDnode->data.clusterId > 0) return false; + if (strcmp(pDnode->data.localEp, pDnode->data.firstEp) != 0) return false; return true; } @@ -53,8 +53,8 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { pOption->selfIndex = 0; SReplica *pReplica = &pOption->replicas[0]; pReplica->id = 1; - pReplica->port = pMgmt->pDnode->serverPort; - tstrncpy(pReplica->fqdn, pMgmt->pDnode->localFqdn, TSDB_FQDN_LEN); + pReplica->port = pMgmt->pDnode->data.serverPort; + tstrncpy(pReplica->fqdn, pMgmt->pDnode->data.localFqdn, TSDB_FQDN_LEN); pOption->deploy = true; pMgmt->selfIndex = pOption->selfIndex; @@ -80,7 +80,7 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre pReplica->id = pCreate->replicas[i].id; pReplica->port = pCreate->replicas[i].port; memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN); - if (pReplica->id == pMgmt->pDnode->dnodeId) { + if (pReplica->id == pMgmt->pDnode->data.dnodeId) { pOption->selfIndex = i; } } @@ -112,8 +112,8 @@ static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) { if (!deployed) { dInfo("mnode start to deploy"); - if (pMgmt->pWrapper->procType == PROC_CHILD) { - pMgmt->pDnode->dnodeId = 1; + if (pMgmt->pWrapper->procType == DND_PROC_CHILD) { + pMgmt->pDnode->data.dnodeId = 1; } mmBuildOptionForDeploy(pMgmt, &option); } else { @@ -230,8 +230,8 @@ void mmSetMgmtFp(SMgmtWrapper *pWrapper) { mgmtFp.openFp = mmOpen; mgmtFp.closeFp = mmClose; mgmtFp.startFp = mmStart; - mgmtFp.createMsgFp = mmProcessCreateReq; - mgmtFp.dropMsgFp = mmProcessDropReq; + mgmtFp.createFp = mmProcessCreateReq; + mgmtFp.dropFp = mmProcessDropReq; mgmtFp.requiredFp = mmRequire; mmInitMsgHandle(pWrapper); diff --git a/source/dnode/mgmt/qm/qmHandle.c b/source/dnode/mgmt/qm/qmHandle.c index 4fda72759a..af1f903f7e 100644 --- a/source/dnode/mgmt/qm/qmHandle.c +++ b/source/dnode/mgmt/qm/qmHandle.c @@ -53,7 +53,7 @@ int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (createReq.dnodeId != pDnode->dnodeId) { + if (createReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create qnode since %s", terrstr()); return -1; @@ -72,7 +72,7 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->dnodeId) { + if (dropReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop qnode since %s", terrstr()); return -1; diff --git a/source/dnode/mgmt/qm/qmInt.c b/source/dnode/mgmt/qm/qmInt.c index 585a7fb183..cb06fe5d25 100644 --- a/source/dnode/mgmt/qm/qmInt.c +++ b/source/dnode/mgmt/qm/qmInt.c @@ -116,8 +116,8 @@ void qmSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = qmOpen; mgmtFp.closeFp = qmClose; - mgmtFp.createMsgFp = qmProcessCreateReq; - mgmtFp.dropMsgFp = qmProcessDropReq; + mgmtFp.createFp = qmProcessCreateReq; + mgmtFp.dropFp = qmProcessDropReq; mgmtFp.requiredFp = qmRequire; qmInitMsgHandle(pWrapper); diff --git a/source/dnode/mgmt/sm/smHandle.c b/source/dnode/mgmt/sm/smHandle.c index 5b30dc04bc..0f9bb5369d 100644 --- a/source/dnode/mgmt/sm/smHandle.c +++ b/source/dnode/mgmt/sm/smHandle.c @@ -53,7 +53,7 @@ int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (createReq.dnodeId != pDnode->dnodeId) { + if (createReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create snode since %s", terrstr()); return -1; @@ -72,7 +72,7 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->dnodeId) { + if (dropReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop snode since %s", terrstr()); return -1; diff --git a/source/dnode/mgmt/sm/smInt.c b/source/dnode/mgmt/sm/smInt.c index ef4e95d915..02958104a0 100644 --- a/source/dnode/mgmt/sm/smInt.c +++ b/source/dnode/mgmt/sm/smInt.c @@ -113,8 +113,8 @@ void smSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = smOpen; mgmtFp.closeFp = smClose; - mgmtFp.createMsgFp = smProcessCreateReq; - mgmtFp.dropMsgFp = smProcessDropReq; + mgmtFp.createFp = smProcessCreateReq; + mgmtFp.dropFp = smProcessDropReq; mgmtFp.requiredFp = smRequire; smInitMsgHandle(pWrapper); diff --git a/source/dnode/mgmt/vm/vmInt.c b/source/dnode/mgmt/vm/vmInt.c index 6a1a5c3987..b298b4c93a 100644 --- a/source/dnode/mgmt/vm/vmInt.c +++ b/source/dnode/mgmt/vm/vmInt.c @@ -278,11 +278,11 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) { taosInitRWLatch(&pMgmt->latch); SDiskCfg dCfg = {0}; - tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN); + tstrncpy(dCfg.dir, pDnode->data.dataDir, TSDB_FILENAME_LEN); dCfg.level = 0; dCfg.primary = 1; - SDiskCfg *pDisks = pDnode->disks; - int32_t numOfDisks = pDnode->numOfDisks; + SDiskCfg *pDisks = pDnode->data.disks; + int32_t numOfDisks = pDnode->data.numOfDisks; if (numOfDisks <= 0 || pDisks == NULL) { pDisks = &dCfg; numOfDisks = 1; @@ -329,7 +329,7 @@ _OVER: static int32_t vmRequire(SMgmtWrapper *pWrapper, bool *required) { SDnode *pDnode = pWrapper->pDnode; - *required = pDnode->numOfSupportVnodes > 0; + *required = pDnode->data.supportVnodes > 0; return 0; } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 86ec49127a..85f0728076 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -354,7 +354,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) { int64_t curMs = taosGetTimestampMs(); bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); - bool dnodeChanged = (statusReq.dver != sdbGetTableVer(pMnode->pSdb, SDB_DNODE)); + bool dnodeChanged = (statusReq.dnodeVer != sdbGetTableVer(pMnode->pSdb, SDB_DNODE)); bool reboot = (pDnode->rebootTime != statusReq.rebootTime); bool needCheck = !online || dnodeChanged || reboot; @@ -405,7 +405,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) { pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes; SStatusRsp statusRsp = {0}; - statusRsp.dver = sdbGetTableVer(pMnode->pSdb, SDB_DNODE); + statusRsp.dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE); statusRsp.dnodeCfg.dnodeId = pDnode->id; statusRsp.dnodeCfg.clusterId = pMnode->clusterId; statusRsp.pDnodeEps = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(SDnodeEp)); From a86b9faa9f81c687ca628cc5f7518b3f2f7a1b48 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 12 Apr 2022 17:28:56 +0800 Subject: [PATCH 02/19] refact(cluster): node mgmt --- source/dnode/mgmt/CMakeLists.txt | 7 +- source/dnode/mgmt/exe/dndMain.c | 6 +- source/dnode/mgmt/implement/inc/dndNode.h | 68 +++++++++++++++++++ .../mgmt/{main => implement/src}/dndEnv.c | 2 +- .../mgmt/{main => implement/src}/dndExec.c | 2 +- .../mgmt/{main => implement/src}/dndObj.c | 2 +- .../{main => implement/src}/dndTransport.c | 2 +- source/dnode/mgmt/inc/bmInt.h | 2 +- source/dnode/mgmt/inc/dmInt.h | 2 +- source/dnode/mgmt/inc/mmInt.h | 2 +- source/dnode/mgmt/inc/qmInt.h | 2 +- source/dnode/mgmt/inc/smInt.h | 2 +- source/dnode/mgmt/inc/vmInt.h | 2 +- source/dnode/mgmt/interface/inc/dndInt.h | 9 ++- .../mgmt/{main => interface/src}/dndFile.c | 12 ++-- source/dnode/mgmt/interface/src/dndInt.c | 10 +-- 16 files changed, 100 insertions(+), 32 deletions(-) create mode 100644 source/dnode/mgmt/implement/inc/dndNode.h rename source/dnode/mgmt/{main => implement/src}/dndEnv.c (98%) rename source/dnode/mgmt/{main => implement/src}/dndExec.c (99%) rename source/dnode/mgmt/{main => implement/src}/dndObj.c (99%) rename source/dnode/mgmt/{main => implement/src}/dndTransport.c (99%) rename source/dnode/mgmt/{main => interface/src}/dndFile.c (95%) diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 40c3f5b1d3..d36a9b8de7 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -6,7 +6,7 @@ aux_source_directory(bm DNODE_SRC) aux_source_directory(sm DNODE_SRC) aux_source_directory(vm DNODE_SRC) aux_source_directory(mm DNODE_SRC) -aux_source_directory(main DNODE_SRC) +aux_source_directory(implement/src DNODE_SRC) add_library(dnode STATIC ${DNODE_SRC}) target_link_libraries( dnode dnode_interface @@ -15,14 +15,15 @@ target_include_directories( dnode PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" ) aux_source_directory(exe EXEC_SRC) add_executable(taosd ${EXEC_SRC}) target_include_directories( taosd - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" ) target_link_libraries(taosd dnode) diff --git a/source/dnode/mgmt/exe/dndMain.c b/source/dnode/mgmt/exe/dndMain.c index 3779f94620..20a73fd893 100644 --- a/source/dnode/mgmt/exe/dndMain.c +++ b/source/dnode/mgmt/exe/dndMain.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" #include "tconfig.h" static struct { @@ -129,14 +129,14 @@ static SDnodeOpt dndGetOpt() { static int32_t dndInitLog() { char logName[12] = {0}; - snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype)); + snprintf(logName, sizeof(logName), "%slog", dndLogName(global.ntype)); return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); } static void dndSetProcInfo(int32_t argc, char **argv) { taosSetProcPath(argc, argv); if (global.ntype != NODE_BEGIN && global.ntype != NODE_END) { - const char *name = dndNodeProcStr(global.ntype); + const char *name = dndProcName(global.ntype); taosSetProcName(argc, argv, name); } } diff --git a/source/dnode/mgmt/implement/inc/dndNode.h b/source/dnode/mgmt/implement/inc/dndNode.h new file mode 100644 index 0000000000..f5d93d2f61 --- /dev/null +++ b/source/dnode/mgmt/implement/inc/dndNode.h @@ -0,0 +1,68 @@ +/* + * 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_DND_NODE_H_ +#define _TD_DND_NODE_H_ + +#include "dndInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t dndOpenNode(SMgmtWrapper *pWrapper); +void dndCloseNode(SMgmtWrapper *pWrapper); + +void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); +SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType nType); +int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); +void dndReleaseWrapper(SMgmtWrapper *pWrapper); +void dndHandleEvent(SDnode *pDnode, EDndEvent event); +void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); + +// dndTransport.c +int32_t dndInitTrans(SDnode *pDnode); +void dndCleanupTrans(SDnode *pDnode); +SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); +SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); +int32_t dndInitMsgHandle(SDnode *pDnode); +void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); + +// mgmt +void dmSetMgmtFp(SMgmtWrapper *pWrapper); +void bmSetMgmtFp(SMgmtWrapper *pWrapper); +void qmSetMgmtFp(SMgmtWrapper *pMgmt); +void smSetMgmtFp(SMgmtWrapper *pWrapper); +void vmSetMgmtFp(SMgmtWrapper *pWrapper); +void mmSetMgmtFp(SMgmtWrapper *pMgmt); + +void dmGetMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); +void dmUpdateMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); +void dmSendRedirectRsp(SDnodeData *pMgmt, const SRpcMsg *pMsg); + +void dmGetMonitorSysInfo(SMonSysInfo *pInfo); +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); +void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); +void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); +void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); +void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_NODE_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/main/dndEnv.c b/source/dnode/mgmt/implement/src/dndEnv.c similarity index 98% rename from source/dnode/mgmt/main/dndEnv.c rename to source/dnode/mgmt/implement/src/dndEnv.c index 9f75594335..a7a3ee8c91 100644 --- a/source/dnode/mgmt/main/dndEnv.c +++ b/source/dnode/mgmt/implement/src/dndEnv.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" #include "wal.h" static int8_t once = DND_ENV_INIT; diff --git a/source/dnode/mgmt/main/dndExec.c b/source/dnode/mgmt/implement/src/dndExec.c similarity index 99% rename from source/dnode/mgmt/main/dndExec.c rename to source/dnode/mgmt/implement/src/dndExec.c index bdc9a2751a..7bdf0f3791 100644 --- a/source/dnode/mgmt/main/dndExec.c +++ b/source/dnode/mgmt/implement/src/dndExec.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" static bool dndRequireNode(SMgmtWrapper *pWrapper) { bool required = false; diff --git a/source/dnode/mgmt/main/dndObj.c b/source/dnode/mgmt/implement/src/dndObj.c similarity index 99% rename from source/dnode/mgmt/main/dndObj.c rename to source/dnode/mgmt/implement/src/dndObj.c index ff2be42722..4300ee0853 100644 --- a/source/dnode/mgmt/main/dndObj.c +++ b/source/dnode/mgmt/implement/src/dndObj.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->data.supportVnodes = pOption->numOfSupportVnodes; diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/implement/src/dndTransport.c similarity index 99% rename from source/dnode/mgmt/main/dndTransport.c rename to source/dnode/mgmt/implement/src/dndTransport.c index c5f195d71e..2d38d6311f 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/implement/src/dndTransport.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dndNode.h" #define INTERNAL_USER "_dnd" #define INTERNAL_CKEY "_key" diff --git a/source/dnode/mgmt/inc/bmInt.h b/source/dnode/mgmt/inc/bmInt.h index 3158fe7d34..627df93b01 100644 --- a/source/dnode/mgmt/inc/bmInt.h +++ b/source/dnode/mgmt/inc/bmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_BNODE_INT_H_ #define _TD_DND_BNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #include "bnode.h" diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/inc/dmInt.h index 4d6ebd63d2..5d787b36b5 100644 --- a/source/dnode/mgmt/inc/dmInt.h +++ b/source/dnode/mgmt/inc/dmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_DNODE_INT_H_ #define _TD_DND_DNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mgmt/inc/mmInt.h b/source/dnode/mgmt/inc/mmInt.h index 74b1cc44bf..4f7c1d9d8c 100644 --- a/source/dnode/mgmt/inc/mmInt.h +++ b/source/dnode/mgmt/inc/mmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_MNODE_INT_H_ #define _TD_DND_MNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #include "mnode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/inc/qmInt.h b/source/dnode/mgmt/inc/qmInt.h index 012869d637..67a00396ea 100644 --- a/source/dnode/mgmt/inc/qmInt.h +++ b/source/dnode/mgmt/inc/qmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_QNODE_INT_H_ #define _TD_DND_QNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #include "qnode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/inc/smInt.h b/source/dnode/mgmt/inc/smInt.h index 039dea2491..56cb954c22 100644 --- a/source/dnode/mgmt/inc/smInt.h +++ b/source/dnode/mgmt/inc/smInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_SNODE_INT_H_ #define _TD_DND_SNODE_INT_H_ -#include "dndInt.h" +#include "dndNode.h" #include "snode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/inc/vmInt.h b/source/dnode/mgmt/inc/vmInt.h index f8466fe4f2..da5ab8387e 100644 --- a/source/dnode/mgmt/inc/vmInt.h +++ b/source/dnode/mgmt/inc/vmInt.h @@ -17,7 +17,7 @@ #define _TD_DND_VNODES_INT_H_ #include "sync.h" -#include "dndInt.h" +#include "dndNode.h" #include "vnode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/interface/inc/dndInt.h b/source/dnode/mgmt/interface/inc/dndInt.h index b08f372daa..1f9d5cd8f4 100644 --- a/source/dnode/mgmt/interface/inc/dndInt.h +++ b/source/dnode/mgmt/interface/inc/dndInt.h @@ -23,11 +23,10 @@ extern "C" { #endif -// dndEnv.c -const char *dndStatStr(EDndRunStatus stat); -const char *dndNodeLogStr(EDndNodeType ntype); -const char *dndNodeProcStr(EDndNodeType ntype); -const char *dndEventStr(EDndEvent ev); +const char *dndStatName(EDndRunStatus stat); +const char *dndLogName(EDndNodeType ntype); +const char *dndProcName(EDndNodeType ntype); +const char *dndEventName(EDndEvent ev); // dndExec.c int32_t dndOpenNode(SMgmtWrapper *pWrapper); diff --git a/source/dnode/mgmt/main/dndFile.c b/source/dnode/mgmt/interface/src/dndFile.c similarity index 95% rename from source/dnode/mgmt/main/dndFile.c rename to source/dnode/mgmt/interface/src/dndFile.c index 45d80543a1..c35d7fbb4a 100644 --- a/source/dnode/mgmt/main/dndFile.c +++ b/source/dnode/mgmt/interface/src/dndFile.c @@ -23,7 +23,7 @@ int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { int64_t len = 0; char content[MAXLEN + 1] = {0}; cJSON *root = NULL; - char file[PATH_MAX]; + char file[PATH_MAX] = {0}; TdFilePtr pFile = NULL; snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); @@ -165,13 +165,13 @@ int32_t dndReadShmFile(SDnode *pDnode) { } for (EDndNodeType ntype = NODE_BEGIN + 1; ntype < NODE_END; ++ntype) { - snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype)); + snprintf(itemName, sizeof(itemName), "%s_shmid", dndProcName(ntype)); cJSON *shmid = cJSON_GetObjectItem(root, itemName); if (shmid && shmid->type == cJSON_Number) { pDnode->wrappers[ntype].procShm.id = shmid->valueint; } - snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype)); + snprintf(itemName, sizeof(itemName), "%s_shmsize", dndProcName(ntype)); cJSON *shmsize = cJSON_GetObjectItem(root, itemName); if (shmsize && shmsize->type == cJSON_Number) { pDnode->wrappers[ntype].procShm.size = shmsize->valueint; @@ -228,11 +228,11 @@ int32_t dndWriteShmFile(SDnode *pDnode) { len += snprintf(content + len, MAXLEN - len, "{\n"); for (EDndNodeType ntype = NODE_BEGIN + 1; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->procShm.id); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndProcName(ntype), pWrapper->procShm.id); if (ntype == NODE_END - 1) { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->procShm.size); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndProcName(ntype), pWrapper->procShm.size); } else { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->procShm.size); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndProcName(ntype), pWrapper->procShm.size); } } len += snprintf(content + len, MAXLEN - len, "}\n"); diff --git a/source/dnode/mgmt/interface/src/dndInt.c b/source/dnode/mgmt/interface/src/dndInt.c index 9ec37b5d04..5e4cd47824 100644 --- a/source/dnode/mgmt/interface/src/dndInt.c +++ b/source/dnode/mgmt/interface/src/dndInt.c @@ -20,12 +20,12 @@ EDndRunStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; } void dndSetStatus(SDnode *pDnode, EDndRunStatus status) { if (pDnode->status != status) { - dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status)); + dDebug("dnode status set from %s to %s", dndStatName(pDnode->status), dndStatName(status)); pDnode->status = status; } } -const char *dndStatStr(EDndRunStatus status) { +const char *dndStatName(EDndRunStatus status) { switch (status) { case DND_STAT_INIT: return "init"; @@ -38,7 +38,7 @@ const char *dndStatStr(EDndRunStatus status) { } } -const char *dndNodeLogStr(EDndNodeType ntype) { +const char *dndLogName(EDndNodeType ntype) { switch (ntype) { case VNODE: return "vnode"; @@ -55,7 +55,7 @@ const char *dndNodeLogStr(EDndNodeType ntype) { } } -const char *dndNodeProcStr(EDndNodeType ntype) { +const char *dndProcName(EDndNodeType ntype) { switch (ntype) { case VNODE: return "taosv"; @@ -72,7 +72,7 @@ const char *dndNodeProcStr(EDndNodeType ntype) { } } -const char *dndEventStr(EDndEvent ev) { +const char *dndEventName(EDndEvent ev) { switch (ev) { case DND_EVENT_START: return "start"; From f7cf8229c8f7b2582cf2288783415b206c3a6c8b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 12 Apr 2022 18:04:40 +0800 Subject: [PATCH 03/19] refact(cluster): node mgmt --- include/dnode/mgmt/dnode.h | 2 +- source/dnode/mgmt/exe/dndMain.c | 2 +- source/dnode/mgmt/implement/inc/dndNode.h | 8 -- source/dnode/mgmt/implement/src/dndObj.c | 68 ------------- source/dnode/mgmt/interface/inc/dndInt.h | 62 +++--------- .../{implement => interface}/src/dndEnv.c | 2 +- source/dnode/mgmt/interface/src/dndFile.c | 3 +- source/dnode/mgmt/interface/src/dndInt.c | 96 +++++++++++++++++-- source/dnode/mgmt/test/sut/src/server.cpp | 2 +- 9 files changed, 106 insertions(+), 139 deletions(-) rename source/dnode/mgmt/{implement => interface}/src/dndEnv.c (98%) diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index e4f4bdf8f9..576b44e14b 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -81,7 +81,7 @@ int32_t dndRun(SDnode *pDnode); * @param pDnode The dnode object to close. * @param event The event to handle. */ -void dndHandleEvent(SDnode *pDnode, EDndEvent event); +void dndSetEvent(SDnode *pDnode, EDndEvent event); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/exe/dndMain.c b/source/dnode/mgmt/exe/dndMain.c index 20a73fd893..93892996c7 100644 --- a/source/dnode/mgmt/exe/dndMain.c +++ b/source/dnode/mgmt/exe/dndMain.c @@ -32,7 +32,7 @@ static struct { static void dndStopDnode(int signum, void *info, void *ctx) { SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); if (pDnode != NULL) { - dndHandleEvent(pDnode, DND_EVENT_STOP); + dndSetEvent(pDnode, DND_EVENT_STOP); } } diff --git a/source/dnode/mgmt/implement/inc/dndNode.h b/source/dnode/mgmt/implement/inc/dndNode.h index f5d93d2f61..237b65a962 100644 --- a/source/dnode/mgmt/implement/inc/dndNode.h +++ b/source/dnode/mgmt/implement/inc/dndNode.h @@ -25,14 +25,6 @@ extern "C" { int32_t dndOpenNode(SMgmtWrapper *pWrapper); void dndCloseNode(SMgmtWrapper *pWrapper); -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType nType); -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); -void dndReleaseWrapper(SMgmtWrapper *pWrapper); -void dndHandleEvent(SDnode *pDnode, EDndEvent event); -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); - // dndTransport.c int32_t dndInitTrans(SDnode *pDnode); void dndCleanupTrans(SDnode *pDnode); diff --git a/source/dnode/mgmt/implement/src/dndObj.c b/source/dnode/mgmt/implement/src/dndObj.c index 4300ee0853..b008b5ce8a 100644 --- a/source/dnode/mgmt/implement/src/dndObj.c +++ b/source/dnode/mgmt/implement/src/dndObj.c @@ -149,72 +149,4 @@ void dndHandleEvent(SDnode *pDnode, EDndEvent event) { } } -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - SMgmtWrapper *pRetWrapper = pWrapper; - taosRLockLatch(&pWrapper->latch); - if (pWrapper->deployed) { - int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); - dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount); - } else { - terrno = TSDB_CODE_NODE_NOT_DEPLOYED; - pRetWrapper = NULL; - } - taosRUnLockLatch(&pWrapper->latch); - - return pRetWrapper; -} - -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { - int32_t code = 0; - - taosRLockLatch(&pWrapper->latch); - if (pWrapper->deployed || (pWrapper->procType == DND_PROC_PARENT && pWrapper->required)) { - int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); - dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); - } else { - terrno = TSDB_CODE_NODE_NOT_DEPLOYED; - code = -1; - } - taosRUnLockLatch(&pWrapper->latch); - - return code; -} - -void dndReleaseWrapper(SMgmtWrapper *pWrapper) { - if (pWrapper == NULL) return; - - taosRLockLatch(&pWrapper->latch); - int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1); - taosRUnLockLatch(&pWrapper->latch); - dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount); -} - -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { - pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp; - pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId; -} - -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { - SStartupReq *pStartup = &pDnode->startup; - tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); - tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); - pStartup->finished = 0; -} - -static void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { - memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq)); - pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); -} - -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { - dDebug("startup req is received"); - SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); - dndGetStartup(pDnode, pStartup); - - dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); - SRpcMsg rpcRsp = { - .handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle}; - rpcSendResponse(&rpcRsp); -} \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dndInt.h b/source/dnode/mgmt/interface/inc/dndInt.h index 1f9d5cd8f4..542df7c784 100644 --- a/source/dnode/mgmt/interface/inc/dndInt.h +++ b/source/dnode/mgmt/interface/inc/dndInt.h @@ -16,21 +16,26 @@ #ifndef _TD_DND_INT_H_ #define _TD_DND_INT_H_ -#include "dndLog.h" #include "dndDef.h" #ifdef __cplusplus extern "C" { #endif -const char *dndStatName(EDndRunStatus stat); -const char *dndLogName(EDndNodeType ntype); -const char *dndProcName(EDndNodeType ntype); -const char *dndEventName(EDndEvent ev); - -// dndExec.c -int32_t dndOpenNode(SMgmtWrapper *pWrapper); -void dndCloseNode(SMgmtWrapper *pWrapper); +// dndInt.c +const char *dndStatName(EDndRunStatus stat); +const char *dndLogName(EDndNodeType ntype); +const char *dndProcName(EDndNodeType ntype); +const char *dndEventName(EDndEvent ev); +SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType nType); +int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); +void dndReleaseWrapper(SMgmtWrapper *pWrapper); +EDndRunStatus dndGetStatus(SDnode *pDnode); +void dndSetStatus(SDnode *pDnode, EDndRunStatus stat); +void dndSetEvent(SDnode *pDnode, EDndEvent event); +void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); +void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); // dndFile.c int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); @@ -39,45 +44,6 @@ TdFilePtr dndCheckRunning(const char *dataDir); int32_t dndReadShmFile(SDnode *pDnode); int32_t dndWriteShmFile(SDnode *pDnode); -// dndInt.c -EDndRunStatus dndGetStatus(SDnode *pDnode); -void dndSetStatus(SDnode *pDnode, EDndRunStatus stat); -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType nType); -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); -void dndReleaseWrapper(SMgmtWrapper *pWrapper); -void dndHandleEvent(SDnode *pDnode, EDndEvent event); -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); - -// dndTransport.c -int32_t dndInitTrans(SDnode *pDnode); -void dndCleanupTrans(SDnode *pDnode); -SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); -SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); -int32_t dndInitMsgHandle(SDnode *pDnode); -void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); - -// mgmt -void dmSetMgmtFp(SMgmtWrapper *pWrapper); -void bmSetMgmtFp(SMgmtWrapper *pWrapper); -void qmSetMgmtFp(SMgmtWrapper *pMgmt); -void smSetMgmtFp(SMgmtWrapper *pWrapper); -void vmSetMgmtFp(SMgmtWrapper *pWrapper); -void mmSetMgmtFp(SMgmtWrapper *pMgmt); - -void dmGetMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); -void dmUpdateMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); -void dmSendRedirectRsp(SDnodeData *pMgmt, const SRpcMsg *pMsg); - -void dmGetMonitorSysInfo(SMonSysInfo *pInfo); -void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); -void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); -void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); -void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); -void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); -void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); - #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/implement/src/dndEnv.c b/source/dnode/mgmt/interface/src/dndEnv.c similarity index 98% rename from source/dnode/mgmt/implement/src/dndEnv.c rename to source/dnode/mgmt/interface/src/dndEnv.c index a7a3ee8c91..9f75594335 100644 --- a/source/dnode/mgmt/implement/src/dndEnv.c +++ b/source/dnode/mgmt/interface/src/dndEnv.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndNode.h" +#include "dndInt.h" #include "wal.h" static int8_t once = DND_ENV_INIT; diff --git a/source/dnode/mgmt/interface/src/dndFile.c b/source/dnode/mgmt/interface/src/dndFile.c index c35d7fbb4a..0358e90fb3 100644 --- a/source/dnode/mgmt/interface/src/dndFile.c +++ b/source/dnode/mgmt/interface/src/dndFile.c @@ -232,7 +232,8 @@ int32_t dndWriteShmFile(SDnode *pDnode) { if (ntype == NODE_END - 1) { len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndProcName(ntype), pWrapper->procShm.size); } else { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndProcName(ntype), pWrapper->procShm.size); + len += + snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndProcName(ntype), pWrapper->procShm.size); } } len += snprintf(content + len, MAXLEN - len, "}\n"); diff --git a/source/dnode/mgmt/interface/src/dndInt.c b/source/dnode/mgmt/interface/src/dndInt.c index 5e4cd47824..fb2338e698 100644 --- a/source/dnode/mgmt/interface/src/dndInt.c +++ b/source/dnode/mgmt/interface/src/dndInt.c @@ -16,15 +16,6 @@ #define _DEFAULT_SOURCE #include "dndInt.h" -EDndRunStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; } - -void dndSetStatus(SDnode *pDnode, EDndRunStatus status) { - if (pDnode->status != status) { - dDebug("dnode status set from %s to %s", dndStatName(pDnode->status), dndStatName(status)); - pDnode->status = status; - } -} - const char *dndStatName(EDndRunStatus status) { switch (status) { case DND_STAT_INIT: @@ -83,4 +74,89 @@ const char *dndEventName(EDndEvent ev) { default: return "UNKNOWN"; } -} \ No newline at end of file +} + +EDndRunStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; } + +void dndSetStatus(SDnode *pDnode, EDndRunStatus status) { + if (pDnode->status != status) { + dDebug("dnode status set from %s to %s", dndStatName(pDnode->status), dndStatName(status)); + pDnode->status = status; + } +} + +void dndSetEvent(SDnode *pDnode, EDndEvent event) { + if (event == DND_EVENT_STOP) { + pDnode->event = event; + } +} + +void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { + pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp; + pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId; +} + +SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; + SMgmtWrapper *pRetWrapper = pWrapper; + + taosRLockLatch(&pWrapper->latch); + if (pWrapper->deployed) { + int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); + dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount); + } else { + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; + pRetWrapper = NULL; + } + taosRUnLockLatch(&pWrapper->latch); + + return pRetWrapper; +} + +int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { + int32_t code = 0; + + taosRLockLatch(&pWrapper->latch); + if (pWrapper->deployed || (pWrapper->procType == DND_PROC_PARENT && pWrapper->required)) { + int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); + dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); + } else { + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; + code = -1; + } + taosRUnLockLatch(&pWrapper->latch); + + return code; +} + +void dndReleaseWrapper(SMgmtWrapper *pWrapper) { + if (pWrapper == NULL) return; + + taosRLockLatch(&pWrapper->latch); + int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1); + taosRUnLockLatch(&pWrapper->latch); + dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount); +} + +void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { + SStartupReq *pStartup = &pDnode->startup; + tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); + tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); + pStartup->finished = 0; +} + +static void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { + memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq)); + pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); +} + +void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { + dDebug("startup req is received"); + SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); + dndGetStartup(pDnode, pStartup); + + dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); + SRpcMsg rpcRsp = { + .handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle}; + rpcSendResponse(&rpcRsp); +} diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp index c5379c6d17..332dc9327c 100644 --- a/source/dnode/mgmt/test/sut/src/server.cpp +++ b/source/dnode/mgmt/test/sut/src/server.cpp @@ -68,7 +68,7 @@ bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const } void TestServer::Stop() { - dndHandleEvent(pDnode, DND_EVENT_STOP); + dndSetEvent(pDnode, DND_EVENT_STOP); taosThreadJoin(threadId, NULL); if (pDnode != NULL) { From 35e29f0bf6220a9bf1478372202bf2ce730440ce Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 12 Apr 2022 18:11:40 +0800 Subject: [PATCH 04/19] refact(cluster): node mgmt --- source/dnode/mgmt/CMakeLists.txt | 16 ++++++++++------ source/dnode/mgmt/{ => implement}/inc/dmInt.h | 0 source/dnode/mgmt/{dm => implement/src}/dmFile.c | 0 .../dnode/mgmt/{dm => implement/src}/dmHandle.c | 0 source/dnode/mgmt/{dm => implement/src}/dmInt.c | 0 .../dnode/mgmt/{dm => implement/src}/dmMonitor.c | 0 .../dnode/mgmt/{dm => implement/src}/dmWorker.c | 0 source/dnode/mgmt/{ => mgmt_bnode}/inc/bmInt.h | 0 .../dnode/mgmt/{bm => mgmt_bnode/src}/bmHandle.c | 0 source/dnode/mgmt/{bm => mgmt_bnode/src}/bmInt.c | 0 .../dnode/mgmt/{bm => mgmt_bnode/src}/bmWorker.c | 0 source/dnode/mgmt/{ => mgmt_mnode}/inc/mmInt.h | 0 .../dnode/mgmt/{mm => mgmt_mnode/src}/mmFile.c | 0 .../dnode/mgmt/{mm => mgmt_mnode/src}/mmHandle.c | 0 source/dnode/mgmt/{mm => mgmt_mnode/src}/mmInt.c | 0 .../dnode/mgmt/{mm => mgmt_mnode/src}/mmWorker.c | 0 source/dnode/mgmt/{ => mgmt_qnode}/inc/qmInt.h | 0 .../dnode/mgmt/{qm => mgmt_qnode/src}/qmHandle.c | 0 source/dnode/mgmt/{qm => mgmt_qnode/src}/qmInt.c | 0 .../dnode/mgmt/{qm => mgmt_qnode/src}/qmWorker.c | 0 source/dnode/mgmt/{ => mgmt_snode}/inc/smInt.h | 0 .../dnode/mgmt/{sm => mgmt_snode/src}/smHandle.c | 0 source/dnode/mgmt/{sm => mgmt_snode/src}/smInt.c | 0 .../dnode/mgmt/{sm => mgmt_snode/src}/smWorker.c | 0 source/dnode/mgmt/{ => mgmt_vnode}/inc/vmInt.h | 0 .../dnode/mgmt/{vm => mgmt_vnode/src}/vmFile.c | 0 .../dnode/mgmt/{vm => mgmt_vnode/src}/vmHandle.c | 0 source/dnode/mgmt/{vm => mgmt_vnode/src}/vmInt.c | 0 .../dnode/mgmt/{vm => mgmt_vnode/src}/vmWorker.c | 0 29 files changed, 10 insertions(+), 6 deletions(-) rename source/dnode/mgmt/{ => implement}/inc/dmInt.h (100%) rename source/dnode/mgmt/{dm => implement/src}/dmFile.c (100%) rename source/dnode/mgmt/{dm => implement/src}/dmHandle.c (100%) rename source/dnode/mgmt/{dm => implement/src}/dmInt.c (100%) rename source/dnode/mgmt/{dm => implement/src}/dmMonitor.c (100%) rename source/dnode/mgmt/{dm => implement/src}/dmWorker.c (100%) rename source/dnode/mgmt/{ => mgmt_bnode}/inc/bmInt.h (100%) rename source/dnode/mgmt/{bm => mgmt_bnode/src}/bmHandle.c (100%) rename source/dnode/mgmt/{bm => mgmt_bnode/src}/bmInt.c (100%) rename source/dnode/mgmt/{bm => mgmt_bnode/src}/bmWorker.c (100%) rename source/dnode/mgmt/{ => mgmt_mnode}/inc/mmInt.h (100%) rename source/dnode/mgmt/{mm => mgmt_mnode/src}/mmFile.c (100%) rename source/dnode/mgmt/{mm => mgmt_mnode/src}/mmHandle.c (100%) rename source/dnode/mgmt/{mm => mgmt_mnode/src}/mmInt.c (100%) rename source/dnode/mgmt/{mm => mgmt_mnode/src}/mmWorker.c (100%) rename source/dnode/mgmt/{ => mgmt_qnode}/inc/qmInt.h (100%) rename source/dnode/mgmt/{qm => mgmt_qnode/src}/qmHandle.c (100%) rename source/dnode/mgmt/{qm => mgmt_qnode/src}/qmInt.c (100%) rename source/dnode/mgmt/{qm => mgmt_qnode/src}/qmWorker.c (100%) rename source/dnode/mgmt/{ => mgmt_snode}/inc/smInt.h (100%) rename source/dnode/mgmt/{sm => mgmt_snode/src}/smHandle.c (100%) rename source/dnode/mgmt/{sm => mgmt_snode/src}/smInt.c (100%) rename source/dnode/mgmt/{sm => mgmt_snode/src}/smWorker.c (100%) rename source/dnode/mgmt/{ => mgmt_vnode}/inc/vmInt.h (100%) rename source/dnode/mgmt/{vm => mgmt_vnode/src}/vmFile.c (100%) rename source/dnode/mgmt/{vm => mgmt_vnode/src}/vmHandle.c (100%) rename source/dnode/mgmt/{vm => mgmt_vnode/src}/vmInt.c (100%) rename source/dnode/mgmt/{vm => mgmt_vnode/src}/vmWorker.c (100%) diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index d36a9b8de7..281fea48de 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,12 +1,11 @@ add_subdirectory(interface) -aux_source_directory(dm DNODE_SRC) -aux_source_directory(qm DNODE_SRC) -aux_source_directory(bm DNODE_SRC) -aux_source_directory(sm DNODE_SRC) -aux_source_directory(vm DNODE_SRC) -aux_source_directory(mm DNODE_SRC) aux_source_directory(implement/src DNODE_SRC) +aux_source_directory(mgmt_bnode/src DNODE_SRC) +aux_source_directory(mgmt_mnode/src DNODE_SRC) +aux_source_directory(mgmt_qnode/src DNODE_SRC) +aux_source_directory(mgmt_snode/src DNODE_SRC) +aux_source_directory(mgmt_vnode/src DNODE_SRC) add_library(dnode STATIC ${DNODE_SRC}) target_link_libraries( dnode dnode_interface @@ -16,6 +15,11 @@ target_include_directories( PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_bnode/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_mnode/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_qnode/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_snode/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_vnode/inc" ) aux_source_directory(exe EXEC_SRC) diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/implement/inc/dmInt.h similarity index 100% rename from source/dnode/mgmt/inc/dmInt.h rename to source/dnode/mgmt/implement/inc/dmInt.h diff --git a/source/dnode/mgmt/dm/dmFile.c b/source/dnode/mgmt/implement/src/dmFile.c similarity index 100% rename from source/dnode/mgmt/dm/dmFile.c rename to source/dnode/mgmt/implement/src/dmFile.c diff --git a/source/dnode/mgmt/dm/dmHandle.c b/source/dnode/mgmt/implement/src/dmHandle.c similarity index 100% rename from source/dnode/mgmt/dm/dmHandle.c rename to source/dnode/mgmt/implement/src/dmHandle.c diff --git a/source/dnode/mgmt/dm/dmInt.c b/source/dnode/mgmt/implement/src/dmInt.c similarity index 100% rename from source/dnode/mgmt/dm/dmInt.c rename to source/dnode/mgmt/implement/src/dmInt.c diff --git a/source/dnode/mgmt/dm/dmMonitor.c b/source/dnode/mgmt/implement/src/dmMonitor.c similarity index 100% rename from source/dnode/mgmt/dm/dmMonitor.c rename to source/dnode/mgmt/implement/src/dmMonitor.c diff --git a/source/dnode/mgmt/dm/dmWorker.c b/source/dnode/mgmt/implement/src/dmWorker.c similarity index 100% rename from source/dnode/mgmt/dm/dmWorker.c rename to source/dnode/mgmt/implement/src/dmWorker.c diff --git a/source/dnode/mgmt/inc/bmInt.h b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h similarity index 100% rename from source/dnode/mgmt/inc/bmInt.h rename to source/dnode/mgmt/mgmt_bnode/inc/bmInt.h diff --git a/source/dnode/mgmt/bm/bmHandle.c b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c similarity index 100% rename from source/dnode/mgmt/bm/bmHandle.c rename to source/dnode/mgmt/mgmt_bnode/src/bmHandle.c diff --git a/source/dnode/mgmt/bm/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c similarity index 100% rename from source/dnode/mgmt/bm/bmInt.c rename to source/dnode/mgmt/mgmt_bnode/src/bmInt.c diff --git a/source/dnode/mgmt/bm/bmWorker.c b/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c similarity index 100% rename from source/dnode/mgmt/bm/bmWorker.c rename to source/dnode/mgmt/mgmt_bnode/src/bmWorker.c diff --git a/source/dnode/mgmt/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h similarity index 100% rename from source/dnode/mgmt/inc/mmInt.h rename to source/dnode/mgmt/mgmt_mnode/inc/mmInt.h diff --git a/source/dnode/mgmt/mm/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c similarity index 100% rename from source/dnode/mgmt/mm/mmFile.c rename to source/dnode/mgmt/mgmt_mnode/src/mmFile.c diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c similarity index 100% rename from source/dnode/mgmt/mm/mmHandle.c rename to source/dnode/mgmt/mgmt_mnode/src/mmHandle.c diff --git a/source/dnode/mgmt/mm/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c similarity index 100% rename from source/dnode/mgmt/mm/mmInt.c rename to source/dnode/mgmt/mgmt_mnode/src/mmInt.c diff --git a/source/dnode/mgmt/mm/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c similarity index 100% rename from source/dnode/mgmt/mm/mmWorker.c rename to source/dnode/mgmt/mgmt_mnode/src/mmWorker.c diff --git a/source/dnode/mgmt/inc/qmInt.h b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h similarity index 100% rename from source/dnode/mgmt/inc/qmInt.h rename to source/dnode/mgmt/mgmt_qnode/inc/qmInt.h diff --git a/source/dnode/mgmt/qm/qmHandle.c b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c similarity index 100% rename from source/dnode/mgmt/qm/qmHandle.c rename to source/dnode/mgmt/mgmt_qnode/src/qmHandle.c diff --git a/source/dnode/mgmt/qm/qmInt.c b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c similarity index 100% rename from source/dnode/mgmt/qm/qmInt.c rename to source/dnode/mgmt/mgmt_qnode/src/qmInt.c diff --git a/source/dnode/mgmt/qm/qmWorker.c b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c similarity index 100% rename from source/dnode/mgmt/qm/qmWorker.c rename to source/dnode/mgmt/mgmt_qnode/src/qmWorker.c diff --git a/source/dnode/mgmt/inc/smInt.h b/source/dnode/mgmt/mgmt_snode/inc/smInt.h similarity index 100% rename from source/dnode/mgmt/inc/smInt.h rename to source/dnode/mgmt/mgmt_snode/inc/smInt.h diff --git a/source/dnode/mgmt/sm/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c similarity index 100% rename from source/dnode/mgmt/sm/smHandle.c rename to source/dnode/mgmt/mgmt_snode/src/smHandle.c diff --git a/source/dnode/mgmt/sm/smInt.c b/source/dnode/mgmt/mgmt_snode/src/smInt.c similarity index 100% rename from source/dnode/mgmt/sm/smInt.c rename to source/dnode/mgmt/mgmt_snode/src/smInt.c diff --git a/source/dnode/mgmt/sm/smWorker.c b/source/dnode/mgmt/mgmt_snode/src/smWorker.c similarity index 100% rename from source/dnode/mgmt/sm/smWorker.c rename to source/dnode/mgmt/mgmt_snode/src/smWorker.c diff --git a/source/dnode/mgmt/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h similarity index 100% rename from source/dnode/mgmt/inc/vmInt.h rename to source/dnode/mgmt/mgmt_vnode/inc/vmInt.h diff --git a/source/dnode/mgmt/vm/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c similarity index 100% rename from source/dnode/mgmt/vm/vmFile.c rename to source/dnode/mgmt/mgmt_vnode/src/vmFile.c diff --git a/source/dnode/mgmt/vm/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c similarity index 100% rename from source/dnode/mgmt/vm/vmHandle.c rename to source/dnode/mgmt/mgmt_vnode/src/vmHandle.c diff --git a/source/dnode/mgmt/vm/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c similarity index 100% rename from source/dnode/mgmt/vm/vmInt.c rename to source/dnode/mgmt/mgmt_vnode/src/vmInt.c diff --git a/source/dnode/mgmt/vm/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c similarity index 100% rename from source/dnode/mgmt/vm/vmWorker.c rename to source/dnode/mgmt/mgmt_vnode/src/vmWorker.c From 4df0c48fc0dbb9adf01a7d44ccfa6c20793c79ad Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 12 Apr 2022 19:43:42 +0800 Subject: [PATCH 05/19] refact(cluster): node mgmt --- source/dnode/mgmt/CMakeLists.txt | 43 ++++--------------- source/dnode/mgmt/exe/CMakeLists.txt | 7 +++ source/dnode/mgmt/implement/CMakeLists.txt | 9 ++++ source/dnode/mgmt/implement/inc/dndNode.h | 4 +- source/dnode/mgmt/implement/src/dmMonitor.c | 15 +------ .../dnode/mgmt/implement/src/dndTransport.c | 24 ++++++----- source/dnode/mgmt/interface/CMakeLists.txt | 2 +- source/dnode/mgmt/interface/inc/dndInt.h | 2 + source/dnode/mgmt/interface/src/dndInt.c | 19 ++++++++ source/dnode/mgmt/mgmt_bnode/CMakeLists.txt | 9 ++++ source/dnode/mgmt/mgmt_bnode/inc/bmInt.h | 2 +- source/dnode/mgmt/mgmt_bnode/src/bmHandle.c | 5 ++- source/dnode/mgmt/mgmt_mnode/CMakeLists.txt | 9 ++++ source/dnode/mgmt/mgmt_mnode/inc/mmInt.h | 3 +- source/dnode/mgmt/mgmt_mnode/src/mmHandle.c | 2 +- source/dnode/mgmt/mgmt_qnode/CMakeLists.txt | 9 ++++ source/dnode/mgmt/mgmt_qnode/inc/qmInt.h | 3 +- source/dnode/mgmt/mgmt_qnode/src/qmHandle.c | 5 ++- source/dnode/mgmt/mgmt_snode/CMakeLists.txt | 9 ++++ source/dnode/mgmt/mgmt_snode/inc/smInt.h | 3 +- source/dnode/mgmt/mgmt_snode/src/smHandle.c | 5 ++- source/dnode/mgmt/mgmt_vnode/CMakeLists.txt | 9 ++++ source/dnode/mgmt/mgmt_vnode/inc/vmInt.h | 4 +- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 2 +- source/dnode/mgmt/test/CMakeLists.txt | 17 ++++---- source/dnode/mgmt/test/bnode/CMakeLists.txt | 7 ++- source/dnode/mgmt/test/mnode/CMakeLists.txt | 7 ++- source/dnode/mgmt/test/qnode/CMakeLists.txt | 4 +- source/dnode/mgmt/test/snode/CMakeLists.txt | 4 +- source/dnode/mgmt/test/sut/CMakeLists.txt | 16 +++---- source/dnode/mgmt/test/vnode/CMakeLists.txt | 4 +- 31 files changed, 154 insertions(+), 109 deletions(-) create mode 100644 source/dnode/mgmt/exe/CMakeLists.txt create mode 100644 source/dnode/mgmt/implement/CMakeLists.txt create mode 100644 source/dnode/mgmt/mgmt_bnode/CMakeLists.txt create mode 100644 source/dnode/mgmt/mgmt_mnode/CMakeLists.txt create mode 100644 source/dnode/mgmt/mgmt_qnode/CMakeLists.txt create mode 100644 source/dnode/mgmt/mgmt_snode/CMakeLists.txt create mode 100644 source/dnode/mgmt/mgmt_vnode/CMakeLists.txt diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 281fea48de..52761ab646 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,36 +1,9 @@ +add_subdirectory(exe) add_subdirectory(interface) - -aux_source_directory(implement/src DNODE_SRC) -aux_source_directory(mgmt_bnode/src DNODE_SRC) -aux_source_directory(mgmt_mnode/src DNODE_SRC) -aux_source_directory(mgmt_qnode/src DNODE_SRC) -aux_source_directory(mgmt_snode/src DNODE_SRC) -aux_source_directory(mgmt_vnode/src DNODE_SRC) -add_library(dnode STATIC ${DNODE_SRC}) -target_link_libraries( - dnode dnode_interface -) -target_include_directories( - dnode - PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_bnode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_mnode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_qnode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_snode/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mgmt_vnode/inc" -) - -aux_source_directory(exe EXEC_SRC) -add_executable(taosd ${EXEC_SRC}) -target_include_directories( - taosd - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" -) -target_link_libraries(taosd dnode) - -if(${BUILD_TEST}) - add_subdirectory(test) -endif(${BUILD_TEST}) +add_subdirectory(implement) +add_subdirectory(mgmt_bnode) +add_subdirectory(mgmt_mnode) +add_subdirectory(mgmt_qnode) +add_subdirectory(mgmt_snode) +add_subdirectory(mgmt_vnode) +add_subdirectory(test) diff --git a/source/dnode/mgmt/exe/CMakeLists.txt b/source/dnode/mgmt/exe/CMakeLists.txt new file mode 100644 index 0000000000..931a07d261 --- /dev/null +++ b/source/dnode/mgmt/exe/CMakeLists.txt @@ -0,0 +1,7 @@ +aux_source_directory(. EXEC_SRC) +add_executable(taosd ${EXEC_SRC}) +target_include_directories( + taosd + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../implement/inc" +) +target_link_libraries(taosd dnode) diff --git a/source/dnode/mgmt/implement/CMakeLists.txt b/source/dnode/mgmt/implement/CMakeLists.txt new file mode 100644 index 0000000000..fbe7530395 --- /dev/null +++ b/source/dnode/mgmt/implement/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src IMPLEMENT_SRC) +add_library(dnode STATIC ${IMPLEMENT_SRC}) +target_link_libraries( + dnode mgmt_bnode mgmt_mnode mgmt_qnode mgmt_snode mgmt_vnode +) +target_include_directories( + dnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) \ No newline at end of file diff --git a/source/dnode/mgmt/implement/inc/dndNode.h b/source/dnode/mgmt/implement/inc/dndNode.h index 237b65a962..283df57707 100644 --- a/source/dnode/mgmt/implement/inc/dndNode.h +++ b/source/dnode/mgmt/implement/inc/dndNode.h @@ -28,7 +28,6 @@ void dndCloseNode(SMgmtWrapper *pWrapper); // dndTransport.c int32_t dndInitTrans(SDnode *pDnode); void dndCleanupTrans(SDnode *pDnode); -SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); int32_t dndInitMsgHandle(SDnode *pDnode); void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); @@ -45,8 +44,7 @@ void dmGetMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); void dmUpdateMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); void dmSendRedirectRsp(SDnodeData *pMgmt, const SRpcMsg *pMsg); -void dmGetMonitorSysInfo(SMonSysInfo *pInfo); -void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); diff --git a/source/dnode/mgmt/implement/src/dmMonitor.c b/source/dnode/mgmt/implement/src/dmMonitor.c index 136158e10f..dc086ffc96 100644 --- a/source/dnode/mgmt/implement/src/dmMonitor.c +++ b/source/dnode/mgmt/implement/src/dmMonitor.c @@ -37,7 +37,7 @@ static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { static void dmGetMonitorInfo(SDnode *pDnode, SMonDmInfo *pInfo) { dmGetMonitorBasicInfo(pDnode, &pInfo->basic); - dmGetMonitorSysInfo(&pInfo->sys); + dndGetMonitorSysInfo(&pInfo->sys); dmGetMonitorDnodeInfo(pDnode, &pInfo->dnode); } @@ -179,16 +179,3 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { rpcFreeCont(rsp.pCont); } } - -void dmGetMonitorSysInfo(SMonSysInfo *pInfo) { - taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system); - taosGetCpuCores(&pInfo->cpu_cores); - taosGetProcMemory(&pInfo->mem_engine); - taosGetSysMemory(&pInfo->mem_system); - pInfo->mem_total = tsTotalMemoryKB; - pInfo->disk_engine = 0; - pInfo->disk_used = tsDataSpace.size.used; - pInfo->disk_total = tsDataSpace.size.total; - taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); - taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); -} diff --git a/source/dnode/mgmt/implement/src/dndTransport.c b/source/dnode/mgmt/implement/src/dndTransport.c index 2d38d6311f..197cfffd7e 100644 --- a/source/dnode/mgmt/implement/src/dndTransport.c +++ b/source/dnode/mgmt/implement/src/dndTransport.c @@ -19,6 +19,10 @@ #define INTERNAL_USER "_dnd" #define INTERNAL_CKEY "_key" #define INTERNAL_SECRET "_pwd" +static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq); +static void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); +static void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); +static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type); static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { SMgmtWrapper *pWrapper = &pDnode->wrappers[NODE_BEGIN]; @@ -299,6 +303,15 @@ static void dndCleanupServer(SDnode *pDnode) { int32_t dndInitTrans(SDnode *pDnode) { if (dndInitServer(pDnode) != 0) return -1; if (dndInitClient(pDnode) != 0) return -1; + + SMsgCb msgCb = { + .sendReqFp = dndSendReq, + .sendRspFp = dndSendRsp, + .registerBrokenLinkArgFp = dndRegisterBrokenLinkArg, + .releaseHandleFp = dndReleaseHandle, + }; + pDnode->data.msgCb = msgCb; + return 0; } @@ -412,17 +425,6 @@ static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) } } -SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) { - SMsgCb msgCb = { - .pWrapper = pWrapper, - .sendReqFp = dndSendReq, - .sendRspFp = dndSendRsp, - .registerBrokenLinkArgFp = dndRegisterBrokenLinkArg, - .releaseHandleFp = dndReleaseHandle, - }; - return msgCb; -} - static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, ProcFuncType ftype) { SRpcMsg *pRpc = &pMsg->rpcMsg; diff --git a/source/dnode/mgmt/interface/CMakeLists.txt b/source/dnode/mgmt/interface/CMakeLists.txt index 78f6ef03e5..69cb6e040f 100644 --- a/source/dnode/mgmt/interface/CMakeLists.txt +++ b/source/dnode/mgmt/interface/CMakeLists.txt @@ -6,5 +6,5 @@ target_include_directories( PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( - dnode_interface cjson mnode vnode qnode snode bnode wal sync taos tfs monitor util + dnode_interface cjson mnode vnode qnode snode bnode wal sync taos tfs monitor ) \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dndInt.h b/source/dnode/mgmt/interface/inc/dndInt.h index 542df7c784..f158336037 100644 --- a/source/dnode/mgmt/interface/inc/dndInt.h +++ b/source/dnode/mgmt/interface/inc/dndInt.h @@ -36,6 +36,8 @@ void dndSetEvent(SDnode *pDnode, EDndEvent event); void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); +void dndGetMonitorSysInfo(SMonSysInfo *pInfo); +SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); // dndFile.c int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); diff --git a/source/dnode/mgmt/interface/src/dndInt.c b/source/dnode/mgmt/interface/src/dndInt.c index fb2338e698..52091ceb17 100644 --- a/source/dnode/mgmt/interface/src/dndInt.c +++ b/source/dnode/mgmt/interface/src/dndInt.c @@ -160,3 +160,22 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { .handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle}; rpcSendResponse(&rpcRsp); } + +void dndGetMonitorSysInfo(SMonSysInfo *pInfo) { + taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system); + taosGetCpuCores(&pInfo->cpu_cores); + taosGetProcMemory(&pInfo->mem_engine); + taosGetSysMemory(&pInfo->mem_system); + pInfo->mem_total = tsTotalMemoryKB; + pInfo->disk_engine = 0; + pInfo->disk_used = tsDataSpace.size.used; + pInfo->disk_total = tsDataSpace.size.total; + taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); + taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); +} + +SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) { + SMsgCb msgCb = pWrapper->pDnode->data.msgCb; + msgCb.pWrapper = pWrapper; + return msgCb; +} \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt new file mode 100644 index 0000000000..6a447dccf8 --- /dev/null +++ b/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_BNODE) +add_library(mgmt_bnode STATIC ${MGMT_BNODE}) +target_include_directories( + mgmt_bnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_bnode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h index 627df93b01..3158fe7d34 100644 --- a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h +++ b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_BNODE_INT_H_ #define _TD_DND_BNODE_INT_H_ -#include "dndNode.h" +#include "dndInt.h" #include "bnode.h" diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c index 9b33533a8a..fef5670aa8 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c @@ -21,7 +21,7 @@ void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo) {} int32_t bmProcessGetMonBmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonBmInfo bmInfo = {0}; bmGetMonitorInfo(pWrapper, &bmInfo); - dmGetMonitorSysInfo(&bmInfo.sys); + dndGetMonitorSysInfo(&bmInfo.sys); monGetLogs(&bmInfo.log); int32_t rspLen = tSerializeSMonBmInfo(NULL, 0, &bmInfo); @@ -58,7 +58,8 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->data.dnodeId); return -1; } else { - return dndOpenNode(pWrapper); + // return dndOpenNode(pWrapper); + return 0; } } diff --git a/source/dnode/mgmt/mgmt_mnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_mnode/CMakeLists.txt new file mode 100644 index 0000000000..5ca9af5628 --- /dev/null +++ b/source/dnode/mgmt/mgmt_mnode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_MNODE) +add_library(mgmt_mnode STATIC ${MGMT_MNODE}) +target_include_directories( + mgmt_mnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_mnode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index 4f7c1d9d8c..d744d981bf 100644 --- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -16,7 +16,8 @@ #ifndef _TD_DND_MNODE_INT_H_ #define _TD_DND_MNODE_INT_H_ -#include "dndNode.h" +#include "dndInt.h" + #include "mnode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 08f1ff1cfa..d98cadb295 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -24,7 +24,7 @@ void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonMmInfo mmInfo = {0}; mmGetMonitorInfo(pWrapper, &mmInfo); - dmGetMonitorSysInfo(&mmInfo.sys); + dndGetMonitorSysInfo(&mmInfo.sys); monGetLogs(&mmInfo.log); int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); diff --git a/source/dnode/mgmt/mgmt_qnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_qnode/CMakeLists.txt new file mode 100644 index 0000000000..bf31b2afc3 --- /dev/null +++ b/source/dnode/mgmt/mgmt_qnode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_QNODE) +add_library(mgmt_qnode STATIC ${MGMT_QNODE}) +target_include_directories( + mgmt_qnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_qnode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h index 67a00396ea..2bf2509b07 100644 --- a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h +++ b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h @@ -16,7 +16,8 @@ #ifndef _TD_DND_QNODE_INT_H_ #define _TD_DND_QNODE_INT_H_ -#include "dndNode.h" +#include "dndInt.h" + #include "qnode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c index af1f903f7e..935c6b2093 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c @@ -21,7 +21,7 @@ void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo) {} int32_t qmProcessGetMonQmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonQmInfo qmInfo = {0}; qmGetMonitorInfo(pWrapper, &qmInfo); - dmGetMonitorSysInfo(&qmInfo.sys); + dndGetMonitorSysInfo(&qmInfo.sys); monGetLogs(&qmInfo.log); int32_t rspLen = tSerializeSMonQmInfo(NULL, 0, &qmInfo); @@ -58,7 +58,8 @@ int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to create qnode since %s", terrstr()); return -1; } else { - return dndOpenNode(pWrapper); + // return dndOpenNode(pWrapper); + return 0; } } diff --git a/source/dnode/mgmt/mgmt_snode/CMakeLists.txt b/source/dnode/mgmt/mgmt_snode/CMakeLists.txt new file mode 100644 index 0000000000..b8a99c9d4d --- /dev/null +++ b/source/dnode/mgmt/mgmt_snode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_SNODE) +add_library(mgmt_snode STATIC ${MGMT_SNODE}) +target_include_directories( + mgmt_snode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_snode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_snode/inc/smInt.h b/source/dnode/mgmt/mgmt_snode/inc/smInt.h index 56cb954c22..697477ef42 100644 --- a/source/dnode/mgmt/mgmt_snode/inc/smInt.h +++ b/source/dnode/mgmt/mgmt_snode/inc/smInt.h @@ -16,7 +16,8 @@ #ifndef _TD_DND_SNODE_INT_H_ #define _TD_DND_SNODE_INT_H_ -#include "dndNode.h" +#include "dndInt.h" + #include "snode.h" #ifdef __cplusplus diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c index 0f9bb5369d..cd8153fd60 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -21,7 +21,7 @@ void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo) {} int32_t smProcessGetMonSmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonSmInfo smInfo = {0}; smGetMonitorInfo(pWrapper, &smInfo); - dmGetMonitorSysInfo(&smInfo.sys); + dndGetMonitorSysInfo(&smInfo.sys); monGetLogs(&smInfo.log); int32_t rspLen = tSerializeSMonSmInfo(NULL, 0, &smInfo); @@ -58,7 +58,8 @@ int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to create snode since %s", terrstr()); return -1; } else { - return dndOpenNode(pWrapper); + // return dndOpenNode(pWrapper); + return 0; } } diff --git a/source/dnode/mgmt/mgmt_vnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_vnode/CMakeLists.txt new file mode 100644 index 0000000000..55a76cf772 --- /dev/null +++ b/source/dnode/mgmt/mgmt_vnode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_VNODE) +add_library(mgmt_vnode STATIC ${MGMT_VNODE}) +target_include_directories( + mgmt_vnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_vnode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index da5ab8387e..00cd0e2b86 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -16,8 +16,9 @@ #ifndef _TD_DND_VNODES_INT_H_ #define _TD_DND_VNODES_INT_H_ +#include "dndInt.h" + #include "sync.h" -#include "dndNode.h" #include "vnode.h" #ifdef __cplusplus @@ -95,6 +96,7 @@ int32_t vmProcessSyncVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq); int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq); int32_t vmProcessGetMonVmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); int32_t vmProcessGetVnodeLoadsReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); // vmFile.c int32_t vmGetVnodesFromFile(SVnodesMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 0e74ca656c..f9e2b45d74 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -36,7 +36,7 @@ void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo) { int32_t vmProcessGetMonVmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonVmInfo vmInfo = {0}; vmGetMonitorInfo(pWrapper, &vmInfo); - dmGetMonitorSysInfo(&vmInfo.sys); + dndGetMonitorSysInfo(&vmInfo.sys); monGetLogs(&vmInfo.log); int32_t rspLen = tSerializeSMonVmInfo(NULL, 0, &vmInfo); diff --git a/source/dnode/mgmt/test/CMakeLists.txt b/source/dnode/mgmt/test/CMakeLists.txt index ce93a14d3f..e1656ceb34 100644 --- a/source/dnode/mgmt/test/CMakeLists.txt +++ b/source/dnode/mgmt/test/CMakeLists.txt @@ -1,8 +1,9 @@ -enable_testing() - -add_subdirectory(qnode) -add_subdirectory(bnode) -add_subdirectory(snode) -add_subdirectory(mnode) -add_subdirectory(vnode) -add_subdirectory(sut) +if(${BUILD_TEST}) + enable_testing() + add_subdirectory(qnode) + add_subdirectory(bnode) + add_subdirectory(snode) + add_subdirectory(mnode) + add_subdirectory(vnode) + add_subdirectory(sut) +endif(${BUILD_TEST}) diff --git a/source/dnode/mgmt/test/bnode/CMakeLists.txt b/source/dnode/mgmt/test/bnode/CMakeLists.txt index 0c0006488d..7108d3adb9 100644 --- a/source/dnode/mgmt/test/bnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/bnode/CMakeLists.txt @@ -1,8 +1,7 @@ -aux_source_directory(. BQTEST_SRC) -add_executable(dbnodeTest ${BQTEST_SRC}) +aux_source_directory(. DND_BNODE_TEST_SRC) +add_executable(dbnodeTest ${DND_BNODE_TEST_SRC}) target_link_libraries( - dbnodeTest - PUBLIC sut + dbnodeTest sut ) add_test( diff --git a/source/dnode/mgmt/test/mnode/CMakeLists.txt b/source/dnode/mgmt/test/mnode/CMakeLists.txt index 3237487242..e83f5dbbec 100644 --- a/source/dnode/mgmt/test/mnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/mnode/CMakeLists.txt @@ -1,8 +1,7 @@ -aux_source_directory(. DMTEST_SRC) -add_executable(dmnodeTest ${DMTEST_SRC}) +aux_source_directory(. DND_MNODE_TEST_SRC) +add_executable(dmnodeTest ${DND_MNODE_TEST_SRC}) target_link_libraries( - dmnodeTest - PUBLIC sut + dmnodeTest sut ) add_test( diff --git a/source/dnode/mgmt/test/qnode/CMakeLists.txt b/source/dnode/mgmt/test/qnode/CMakeLists.txt index d118a8723a..20cb53fc45 100644 --- a/source/dnode/mgmt/test/qnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/qnode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. DQTEST_SRC) -add_executable(dqnodeTest ${DQTEST_SRC}) +aux_source_directory(. DND_QNODE_TEST_SRC) +add_executable(dqnodeTest ${DND_QNODE_TEST_SRC}) target_link_libraries( dqnodeTest PUBLIC sut diff --git a/source/dnode/mgmt/test/snode/CMakeLists.txt b/source/dnode/mgmt/test/snode/CMakeLists.txt index eaabc5647b..70f3054381 100644 --- a/source/dnode/mgmt/test/snode/CMakeLists.txt +++ b/source/dnode/mgmt/test/snode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. SQTEST_SRC) -add_executable(dsnodeTest ${SQTEST_SRC}) +aux_source_directory(. DND_SNODE_TEST_SRC) +add_executable(dsnodeTest ${DND_SNODE_TEST_SRC}) target_link_libraries( dsnodeTest PUBLIC sut diff --git a/source/dnode/mgmt/test/sut/CMakeLists.txt b/source/dnode/mgmt/test/sut/CMakeLists.txt index 3a993986fe..c2e1d7e7cd 100644 --- a/source/dnode/mgmt/test/sut/CMakeLists.txt +++ b/source/dnode/mgmt/test/sut/CMakeLists.txt @@ -1,14 +1,10 @@ -aux_source_directory(src SUT_SRC) -add_library(sut STATIC STATIC ${SUT_SRC}) -target_link_libraries( - sut - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - +aux_source_directory(src DND_SUT_SRC) +add_library(sut STATIC STATIC ${DND_SUT_SRC}) target_include_directories( sut PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) + +target_link_libraries( + sut dnode gtest_main +) diff --git a/source/dnode/mgmt/test/vnode/CMakeLists.txt b/source/dnode/mgmt/test/vnode/CMakeLists.txt index e2cd868513..34402286aa 100644 --- a/source/dnode/mgmt/test/vnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/vnode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. VNODE_SRC) -add_executable(dvnodeTest ${VNODE_SRC}) +aux_source_directory(. DND_VNODE_TEST_SRC) +add_executable(dvnodeTest ${DND_VNODE_TEST_SRC}) target_link_libraries( dvnodeTest PUBLIC sut From a8b890bcae713138f1b9963849793eaf2f89f0b2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 12 Apr 2022 19:49:19 +0800 Subject: [PATCH 06/19] refact(cluster): node mgmt --- include/util/tprocess.h | 8 +- source/dnode/mgmt/exe/dndMain.c | 2 +- source/dnode/mgmt/implement/inc/dmInt.h | 56 --- .../implement/inc/{dndNode.h => dndImp.h} | 38 +- source/dnode/mgmt/implement/src/dmInt.c | 170 ------- .../mgmt/implement/src/{dmFile.c => dndEps.c} | 22 +- source/dnode/mgmt/implement/src/dndExec.c | 2 +- .../implement/src/{dmHandle.c => dndHandle.c} | 6 +- .../src/{dmMonitor.c => dndMonitor.c} | 2 +- source/dnode/mgmt/implement/src/dndObj.c | 99 +++- .../dnode/mgmt/implement/src/dndTransport.c | 426 ++++++++++-------- .../implement/src/{dmWorker.c => dndWorker.c} | 2 +- source/util/src/tprocess.c | 16 +- source/util/test/procTest.cpp | 28 +- 14 files changed, 409 insertions(+), 468 deletions(-) delete mode 100644 source/dnode/mgmt/implement/inc/dmInt.h rename source/dnode/mgmt/implement/inc/{dndNode.h => dndImp.h} (58%) delete mode 100644 source/dnode/mgmt/implement/src/dmInt.c rename source/dnode/mgmt/implement/src/{dmFile.c => dndEps.c} (94%) rename source/dnode/mgmt/implement/src/{dmHandle.c => dndHandle.c} (98%) rename source/dnode/mgmt/implement/src/{dmMonitor.c => dndMonitor.c} (99%) rename source/dnode/mgmt/implement/src/{dmWorker.c => dndWorker.c} (99%) diff --git a/include/util/tprocess.h b/include/util/tprocess.h index c5f33140dd..2b0fd89aa5 100644 --- a/include/util/tprocess.h +++ b/include/util/tprocess.h @@ -22,13 +22,13 @@ extern "C" { #endif -typedef enum { PROC_REQ = 1, PROC_RSP, PROC_REGIST, PROC_RELEASE } ProcFuncType; +typedef enum { PROC_FUNC_REQ = 1, PROC_FUNC_RSP, PROC_FUNC_REGIST, PROC_FUNC_RELEASE } EProcFuncType; typedef struct SProcObj SProcObj; typedef void *(*ProcMallocFp)(int32_t contLen); typedef void *(*ProcFreeFp)(void *pCont); typedef void (*ProcConsumeFp)(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, - ProcFuncType ftype); + EProcFuncType ftype); typedef struct { ProcConsumeFp childConsumeFp; @@ -53,11 +53,11 @@ int32_t taosProcRun(SProcObj *pProc); void taosProcStop(SProcObj *pProc); int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - void *handle, ProcFuncType ftype); + void *handle, EProcFuncType ftype); void taosProcRemoveHandle(SProcObj *pProc, void *handle); void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)); void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - ProcFuncType ftype); + EProcFuncType ftype); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/exe/dndMain.c b/source/dnode/mgmt/exe/dndMain.c index 93892996c7..2454375d46 100644 --- a/source/dnode/mgmt/exe/dndMain.c +++ b/source/dnode/mgmt/exe/dndMain.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndNode.h" +#include "dndImp.h" #include "tconfig.h" static struct { diff --git a/source/dnode/mgmt/implement/inc/dmInt.h b/source/dnode/mgmt/implement/inc/dmInt.h deleted file mode 100644 index 5d787b36b5..0000000000 --- a/source/dnode/mgmt/implement/inc/dmInt.h +++ /dev/null @@ -1,56 +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_DND_DNODE_INT_H_ -#define _TD_DND_DNODE_INT_H_ - -#include "dndNode.h" - -#ifdef __cplusplus -extern "C" { -#endif - - - -// dmFile.c -int32_t dmReadFile(SDnodeData *pMgmt); -int32_t dmWriteFile(SDnodeData *pMgmt); -void dmUpdateDnodeEps(SDnodeData *pMgmt, SArray *pDnodeEps); - -// dmHandle.c -void dmInitMsgHandle(SMgmtWrapper *pWrapper); -void dmSendStatusReq(SDnodeData *pMgmt); -int32_t dmProcessConfigReq(SDnodeData *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessStatusRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessAuthRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessGrantRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); - -// dmMonitor.c -void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); -void dmSendMonitorReport(SDnode *pDnode); - -// dmWorker.c -int32_t dmStartThread(SDnodeData *pMgmt); -int32_t dmStartWorker(SDnodeData *pMgmt); -void dmStopWorker(SDnodeData *pMgmt); -int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_DND_DNODE_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/implement/inc/dndNode.h b/source/dnode/mgmt/implement/inc/dndImp.h similarity index 58% rename from source/dnode/mgmt/implement/inc/dndNode.h rename to source/dnode/mgmt/implement/inc/dndImp.h index 283df57707..31b2f0a53a 100644 --- a/source/dnode/mgmt/implement/inc/dndNode.h +++ b/source/dnode/mgmt/implement/inc/dndImp.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_DND_NODE_H_ -#define _TD_DND_NODE_H_ +#ifndef _TD_DND_IMP_H_ +#define _TD_DND_IMP_H_ #include "dndInt.h" @@ -30,6 +30,7 @@ int32_t dndInitTrans(SDnode *pDnode); void dndCleanupTrans(SDnode *pDnode); SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); int32_t dndInitMsgHandle(SDnode *pDnode); +void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pReq); void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); // mgmt @@ -40,19 +41,40 @@ void smSetMgmtFp(SMgmtWrapper *pWrapper); void vmSetMgmtFp(SMgmtWrapper *pWrapper); void mmSetMgmtFp(SMgmtWrapper *pMgmt); -void dmGetMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); -void dmUpdateMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet); -void dmSendRedirectRsp(SDnodeData *pMgmt, const SRpcMsg *pMsg); - -void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); +// dmFile.c +int32_t dmReadFile(SDnodeData *pMgmt); +int32_t dmWriteFile(SDnodeData *pMgmt); +void dmUpdateDnodeEps(SDnodeData *pMgmt, SArray *pDnodeEps); + +// dmHandle.c +void dmInitMsgHandle(SMgmtWrapper *pWrapper); +void dmSendStatusReq(SDnodeData *pMgmt); +int32_t dmProcessConfigReq(SDnodeData *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessStatusRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessAuthRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessGrantRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); + +// dmMonitor.c +void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void dmSendMonitorReport(SDnode *pDnode); + +// dmWorker.c +int32_t dmStartThread(SDnodeData *pMgmt); +int32_t dmStartWorker(SDnodeData *pMgmt); +void dmStopWorker(SDnodeData *pMgmt); +int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); + #ifdef __cplusplus } #endif -#endif /*_TD_DND_NODE_H_*/ \ No newline at end of file +#endif /*_TD_DND_IMP_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/implement/src/dmInt.c b/source/dnode/mgmt/implement/src/dmInt.c deleted file mode 100644 index 8151aa8d1e..0000000000 --- a/source/dnode/mgmt/implement/src/dmInt.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dmInt.h" - -void dmGetMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet) { - taosRLockLatch(&pMgmt->latch); - *pEpSet = pMgmt->mnodeEpSet; - taosRUnLockLatch(&pMgmt->latch); -} - -void dmUpdateMnodeEpSet(SDnodeData *pMgmt, SEpSet *pEpSet) { - dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); - - taosWLockLatch(&pMgmt->latch); - pMgmt->mnodeEpSet = *pEpSet; - for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { - dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); - } - - taosWUnLockLatch(&pMgmt->latch); -} - -void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { - SDnodeData *pMgmt = pWrapper->pMgmt; - taosRLockLatch(&pMgmt->latch); - - SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); - if (pDnodeEp != NULL) { - if (pPort != NULL) { - *pPort = pDnodeEp->ep.port; - } - if (pFqdn != NULL) { - tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN); - } - if (pEp != NULL) { - snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port); - } - } - - taosRUnLockLatch(&pMgmt->latch); -} - -void dmSendRedirectRsp(SDnodeData *pMgmt, const SRpcMsg *pReq) { - SDnode *pDnode = pMgmt->pDnode; - - SEpSet epSet = {0}; - dmGetMnodeEpSet(pMgmt, &epSet); - - dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse); - for (int32_t i = 0; i < epSet.numOfEps; ++i) { - dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); - if (strcmp(epSet.eps[i].fqdn, pDnode->data.localFqdn) == 0 && epSet.eps[i].port == pDnode->data.serverPort) { - epSet.inUse = (i + 1) % epSet.numOfEps; - } - - epSet.eps[i].port = htons(epSet.eps[i].port); - } - - rpcSendRedirectRsp(pReq->handle, &epSet); -} - -static int32_t dmStart(SMgmtWrapper *pWrapper) { - dDebug("dnode-mgmt start to run"); - return dmStartThread(pWrapper->pMgmt); -} - -static int32_t dmInit(SMgmtWrapper *pWrapper) { - SDnode *pDnode = pWrapper->pDnode; - SDnodeData *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeData)); - dInfo("dnode-mgmt start to init"); - - pDnode->data.dnodeId = 0; - pDnode->data.dropped = 0; - pDnode->data.clusterId = 0; - pMgmt->path = pWrapper->path; - pMgmt->pDnode = pDnode; - taosInitRWLatch(&pMgmt->latch); - - pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - if (pMgmt->dnodeHash == NULL) { - dError("failed to init dnode hash"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - if (dmReadFile(pMgmt) != 0) { - dError("failed to read file since %s", terrstr()); - return -1; - } - - if (pDnode->data.dropped) { - dError("dnode will not start since its already dropped"); - return -1; - } - - if (dmStartWorker(pMgmt) != 0) { - return -1; - } - - if (dndInitTrans(pDnode) != 0) { - dError("failed to init transport since %s", terrstr()); - return -1; - } - - pWrapper->pMgmt = pMgmt; - pMgmt->msgCb = dndCreateMsgcb(pWrapper); - - dInfo("dnode-mgmt is initialized"); - return 0; -} - -static void dmCleanup(SMgmtWrapper *pWrapper) { - SDnodeData *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - - dInfo("dnode-mgmt start to clean up"); - SDnode *pDnode = pMgmt->pDnode; - dmStopWorker(pMgmt); - - taosWLockLatch(&pMgmt->latch); - - if (pMgmt->dnodeEps != NULL) { - taosArrayDestroy(pMgmt->dnodeEps); - pMgmt->dnodeEps = NULL; - } - - if (pMgmt->dnodeHash != NULL) { - taosHashCleanup(pMgmt->dnodeHash); - pMgmt->dnodeHash = NULL; - } - - taosWUnLockLatch(&pMgmt->latch); - - taosMemoryFree(pMgmt); - pWrapper->pMgmt = NULL; - dndCleanupTrans(pDnode); - - dInfo("dnode-mgmt is cleaned up"); -} - -static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) { - *required = true; - return 0; -} - -void dmSetMgmtFp(SMgmtWrapper *pWrapper) { - SMgmtFp mgmtFp = {0}; - mgmtFp.openFp = dmInit; - mgmtFp.closeFp = dmCleanup; - mgmtFp.startFp = dmStart; - mgmtFp.requiredFp = dmRequire; - - dmInitMsgHandle(pWrapper); - pWrapper->name = "dnode"; - pWrapper->fp = mgmtFp; -} diff --git a/source/dnode/mgmt/implement/src/dmFile.c b/source/dnode/mgmt/implement/src/dndEps.c similarity index 94% rename from source/dnode/mgmt/implement/src/dmFile.c rename to source/dnode/mgmt/implement/src/dndEps.c index aefc28c46d..04de19d6a8 100644 --- a/source/dnode/mgmt/implement/src/dmFile.c +++ b/source/dnode/mgmt/implement/src/dndEps.c @@ -14,12 +14,32 @@ */ #define _DEFAULT_SOURCE -#include "dmInt.h" +#include "dndImp.h" static void dmPrintDnodes(SDnodeData *pMgmt); static bool dmIsEpChanged(SDnodeData *pMgmt, int32_t dnodeId, const char *ep); static void dmResetDnodes(SDnodeData *pMgmt, SArray *dnodeEps); +void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { + SDnodeData *pMgmt = pWrapper->pMgmt; + taosRLockLatch(&pMgmt->latch); + + SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); + if (pDnodeEp != NULL) { + if (pPort != NULL) { + *pPort = pDnodeEp->ep.port; + } + if (pFqdn != NULL) { + tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN); + } + if (pEp != NULL) { + snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port); + } + } + + taosRUnLockLatch(&pMgmt->latch); +} + int32_t dmReadFile(SDnodeData *pMgmt) { int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int32_t len = 0; diff --git a/source/dnode/mgmt/implement/src/dndExec.c b/source/dnode/mgmt/implement/src/dndExec.c index 7bdf0f3791..c30e730d8a 100644 --- a/source/dnode/mgmt/implement/src/dndExec.c +++ b/source/dnode/mgmt/implement/src/dndExec.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndNode.h" +#include "dndImp.h" static bool dndRequireNode(SMgmtWrapper *pWrapper) { bool required = false; diff --git a/source/dnode/mgmt/implement/src/dmHandle.c b/source/dnode/mgmt/implement/src/dndHandle.c similarity index 98% rename from source/dnode/mgmt/implement/src/dmHandle.c rename to source/dnode/mgmt/implement/src/dndHandle.c index 36edc089f0..196671c916 100644 --- a/source/dnode/mgmt/implement/src/dmHandle.c +++ b/source/dnode/mgmt/implement/src/dndHandle.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dmInt.h" +#include "dndImp.h" void dmSendStatusReq(SDnodeData *pMgmt) { SDnode *pDnode = pMgmt->pDnode; @@ -57,9 +57,7 @@ void dmSendStatusReq(SDnodeData *pMgmt) { pMgmt->statusSent = 1; dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); - SEpSet epSet = {0}; - dmGetMnodeEpSet(pMgmt, &epSet); - tmsgSendReq(&pMgmt->msgCb, &epSet, &rpcMsg); + dndSendMsgToMnode(pDnode, &rpcMsg); } static void dmUpdateDnodeCfg(SDnodeData *pMgmt, SDnodeCfg *pCfg) { diff --git a/source/dnode/mgmt/implement/src/dmMonitor.c b/source/dnode/mgmt/implement/src/dndMonitor.c similarity index 99% rename from source/dnode/mgmt/implement/src/dmMonitor.c rename to source/dnode/mgmt/implement/src/dndMonitor.c index dc086ffc96..73aa8d9424 100644 --- a/source/dnode/mgmt/implement/src/dmMonitor.c +++ b/source/dnode/mgmt/implement/src/dndMonitor.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dmInt.h" +#include "dndImp.h" static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { pInfo->protocol = 1; diff --git a/source/dnode/mgmt/implement/src/dndObj.c b/source/dnode/mgmt/implement/src/dndObj.c index b008b5ce8a..bfbdb756c6 100644 --- a/source/dnode/mgmt/implement/src/dndObj.c +++ b/source/dnode/mgmt/implement/src/dndObj.c @@ -14,7 +14,104 @@ */ #define _DEFAULT_SOURCE -#include "dndNode.h" +#include "dndImp.h" + + +static int32_t dmStart(SMgmtWrapper *pWrapper) { + dDebug("dnode-mgmt start to run"); + return dmStartThread(pWrapper->pMgmt); +} + +static int32_t dmInit(SMgmtWrapper *pWrapper) { + SDnode *pDnode = pWrapper->pDnode; + SDnodeData *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeData)); + dInfo("dnode-mgmt start to init"); + + pDnode->data.dnodeId = 0; + pDnode->data.dropped = 0; + pDnode->data.clusterId = 0; + pMgmt->path = pWrapper->path; + pMgmt->pDnode = pDnode; + taosInitRWLatch(&pMgmt->latch); + + pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + if (pMgmt->dnodeHash == NULL) { + dError("failed to init dnode hash"); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (dmReadFile(pMgmt) != 0) { + dError("failed to read file since %s", terrstr()); + return -1; + } + + if (pDnode->data.dropped) { + dError("dnode will not start since its already dropped"); + return -1; + } + + if (dmStartWorker(pMgmt) != 0) { + return -1; + } + + if (dndInitTrans(pDnode) != 0) { + dError("failed to init transport since %s", terrstr()); + return -1; + } + + pWrapper->pMgmt = pMgmt; + pMgmt->msgCb = dndCreateMsgcb(pWrapper); + + dInfo("dnode-mgmt is initialized"); + return 0; +} + +static void dmCleanup(SMgmtWrapper *pWrapper) { + SDnodeData *pMgmt = pWrapper->pMgmt; + if (pMgmt == NULL) return; + + dInfo("dnode-mgmt start to clean up"); + SDnode *pDnode = pMgmt->pDnode; + dmStopWorker(pMgmt); + + taosWLockLatch(&pMgmt->latch); + + if (pMgmt->dnodeEps != NULL) { + taosArrayDestroy(pMgmt->dnodeEps); + pMgmt->dnodeEps = NULL; + } + + if (pMgmt->dnodeHash != NULL) { + taosHashCleanup(pMgmt->dnodeHash); + pMgmt->dnodeHash = NULL; + } + + taosWUnLockLatch(&pMgmt->latch); + + taosMemoryFree(pMgmt); + pWrapper->pMgmt = NULL; + dndCleanupTrans(pDnode); + + dInfo("dnode-mgmt is cleaned up"); +} + +static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) { + *required = true; + return 0; +} + +void dmSetMgmtFp(SMgmtWrapper *pWrapper) { + SMgmtFp mgmtFp = {0}; + mgmtFp.openFp = dmInit; + mgmtFp.closeFp = dmCleanup; + mgmtFp.startFp = dmStart; + mgmtFp.requiredFp = dmRequire; + + dmInitMsgHandle(pWrapper); + pWrapper->name = "dnode"; + pWrapper->fp = mgmtFp; +} static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->data.supportVnodes = pOption->numOfSupportVnodes; diff --git a/source/dnode/mgmt/implement/src/dndTransport.c b/source/dnode/mgmt/implement/src/dndTransport.c index 197cfffd7e..7d9ba1d56d 100644 --- a/source/dnode/mgmt/implement/src/dndTransport.c +++ b/source/dnode/mgmt/implement/src/dndTransport.c @@ -14,19 +14,28 @@ */ #define _DEFAULT_SOURCE -#include "dndNode.h" +#include "dndImp.h" #define INTERNAL_USER "_dnd" #define INTERNAL_CKEY "_key" #define INTERNAL_SECRET "_pwd" -static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq); -static void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp); -static void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); -static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type); -static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[NODE_BEGIN]; - dmUpdateMnodeEpSet(pWrapper->pMgmt, pEpSet); +static void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { + taosRLockLatch(&pDnode->data.latch); + *pEpSet = pDnode->data.mnodeEpSet; + taosRUnLockLatch(&pDnode->data.latch); +} + +static void dndSetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { + dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); + + taosWLockLatch(&pDnode->data.latch); + pDnode->data.mnodeEpSet = *pEpSet; + for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { + dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); + } + + taosWUnLockLatch(&pDnode->data.latch); } static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { @@ -60,7 +69,7 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS uint16_t msgType = pRpc->msgType; if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) { - dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet); + dndSetMnodeEpSet(pWrapper->pDnode, pEpSet); } if (dndMarkWrapper(pWrapper) != 0) goto _OVER; @@ -74,7 +83,7 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS } else if (pWrapper->procType == DND_PROC_PARENT) { dTrace("msg:%p, is created and put into child queue, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle, - PROC_REQ); + PROC_FUNC_REQ); } else { dTrace("msg:%p, should not processed in child process, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); ASSERT(1); @@ -162,11 +171,215 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { dndProcessRpcMsg(pWrapper, pMsg, pEpSet); } +int32_t dndInitMsgHandle(SDnode *pDnode) { + SDnodeTrans *pTrans = &pDnode->trans; + + for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + + for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) { + NodeMsgFp msgFp = pWrapper->msgFps[msgIndex]; + int8_t vgId = pWrapper->msgVgIds[msgIndex]; + if (msgFp == NULL) continue; + + SMsgHandle *pHandle = &pTrans->msgHandles[msgIndex]; + if (vgId == QNODE_HANDLE) { + if (pHandle->pQndWrapper != NULL) { + dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); + return -1; + } + pHandle->pQndWrapper = pWrapper; + } else if (vgId == MNODE_HANDLE) { + if (pHandle->pMndWrapper != NULL) { + dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); + return -1; + } + pHandle->pMndWrapper = pWrapper; + } else { + if (pHandle->pNdWrapper != NULL) { + dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); + return -1; + } + pHandle->pNdWrapper = pWrapper; + } + } + } + + return 0; +} + +static inline int32_t dndSendRpcReq(SDnode *pDnode, const SEpSet *pEpSet, SRpcMsg *pReq) { + if (pDnode->trans.clientRpc == NULL) { + terrno = TSDB_CODE_NODE_OFFLINE; + return -1; + } + + rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pReq, NULL); + return 0; +} + +static void dndSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) { + SEpSet epSet = {0}; + dndGetMnodeEpSet(pDnode, &epSet); + + dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse); + for (int32_t i = 0; i < epSet.numOfEps; ++i) { + dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); + if (strcmp(epSet.eps[i].fqdn, pDnode->data.localFqdn) == 0 && epSet.eps[i].port == pDnode->data.serverPort) { + epSet.inUse = (i + 1) % epSet.numOfEps; + } + + epSet.eps[i].port = htons(epSet.eps[i].port); + } + + rpcSendRedirectRsp(pReq->handle, &epSet); +} + +static inline void dndSendRpcRsp(SDnode *pDnode, const SRpcMsg *pRsp) { + if (pRsp->code == TSDB_CODE_NODE_REDIRECT) { + dndSendRpcRedirectRsp(pDnode, pRsp); + } else { + rpcSendResponse(pRsp); + } +} + +void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) { + rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp); +} + +void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pReq) { + SEpSet epSet = {0}; + dndGetMnodeEpSet(pDnode, &epSet); + dndSendRpcReq(pDnode, &epSet, pReq); +} + +static inline void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) { + SEpSet epSet = {0}; + dndGetMnodeEpSet(pDnode, &epSet); + rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp); +} + +static inline int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { + if (dndGetStatus(pWrapper->pDnode) != DND_STAT_RUNNING) { + terrno = TSDB_CODE_NODE_OFFLINE; + dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle); + return -1; + } + + if (pWrapper->procType != DND_PROC_CHILD) { + return dndSendRpcReq(pWrapper->pDnode, pEpSet, pReq); + } else { + char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet)); + if (pHead == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + memcpy(pHead, pReq, sizeof(SRpcMsg)); + memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet)); + taosProcPutToParentQ(pWrapper->procObj, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen, + PROC_FUNC_REQ); + taosMemoryFree(pHead); + return 0; + } +} + +static inline void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { + if (pWrapper->procType != DND_PROC_CHILD) { + dndSendRpcRsp(pWrapper->pDnode, pRsp); + } else { + taosProcPutToParentQ(pWrapper->procObj, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_FUNC_RSP); + } +} + +static inline void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { + if (pWrapper->procType != DND_PROC_CHILD) { + rpcRegisterBrokenLinkArg(pMsg); + } else { + taosProcPutToParentQ(pWrapper->procObj, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_FUNC_REGIST); + } +} + +static inline void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) { + if (pWrapper->procType != DND_PROC_CHILD) { + rpcReleaseHandle(handle, type); + } else { + SRpcMsg msg = {.handle = handle, .code = type}; + taosProcPutToParentQ(pWrapper->procObj, &msg, sizeof(SRpcMsg), NULL, 0, PROC_FUNC_RELEASE); + } +} + +static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + EProcFuncType ftype) { + SRpcMsg *pRpc = &pMsg->rpcMsg; + pRpc->pCont = pCont; + dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle); + + NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; + int32_t code = (*msgFp)(pWrapper, pMsg); + + if (code != 0) { + dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); + if (pRpc->msgType & 1U) { + SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; + dndSendRsp(pWrapper, &rsp); + } + + dTrace("msg:%p, is freed", pMsg); + taosFreeQitem(pMsg); + rpcFreeCont(pCont); + } +} + +static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + EProcFuncType ftype) { + pMsg->pCont = pCont; + dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle, + pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle); + + switch (ftype) { + case PROC_FUNC_REGIST: + rpcRegisterBrokenLinkArg(pMsg); + break; + case PROC_FUNC_RELEASE: + taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); + rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); + rpcFreeCont(pCont); + break; + case PROC_FUNC_REQ: + dndSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); + break; + case PROC_FUNC_RSP: + taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); + dndSendRpcRsp(pWrapper->pDnode, pMsg); + break; + default: + break; + } + taosMemoryFree(pMsg); +} + +SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) { + SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, + .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, + .childFreeHeadFp = (ProcFreeFp)taosFreeQitem, + .childMallocBodyFp = (ProcMallocFp)rpcMallocCont, + .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, + .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, + .parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, + .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, + .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, + .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, + .shm = pWrapper->procShm, + .parent = pWrapper, + .name = pWrapper->name}; + return cfg; +} + static int32_t dndInitClient(SDnode *pDnode) { SDnodeTrans *pTrans = &pDnode->trans; - SRpcInit rpcInit; - memset(&rpcInit, 0, sizeof(rpcInit)); + SRpcInit rpcInit = {0}; rpcInit.label = "DND"; rpcInit.numOfThreads = 1; rpcInit.cfp = (RpcCfp)dndProcessMsg; @@ -201,13 +414,6 @@ static void dndCleanupClient(SDnode *pDnode) { } } -static inline void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) { - SEpSet epSet = {0}; - SMgmtWrapper *pWrapper = &pDnode->wrappers[NODE_BEGIN]; - dmGetMnodeEpSet(pWrapper->pMgmt, &epSet); - rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp); -} - static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { int32_t code = 0; @@ -231,7 +437,8 @@ static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi, return code; } -static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { +static inline int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, + char *ckey) { if (dndGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) { dTrace("user:%s, get auth from mnode, spi:%d encrypt:%d", user, *spi, *encrypt); return 0; @@ -269,8 +476,7 @@ static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, ch static int32_t dndInitServer(SDnode *pDnode) { SDnodeTrans *pTrans = &pDnode->trans; - SRpcInit rpcInit; - memset(&rpcInit, 0, sizeof(rpcInit)); + SRpcInit rpcInit = {0}; rpcInit.localPort = pDnode->data.serverPort; rpcInit.label = "DND"; rpcInit.numOfThreads = tsNumOfRpcThreads; @@ -319,179 +525,3 @@ void dndCleanupTrans(SDnode *pDnode) { dndCleanupServer(pDnode); dndCleanupClient(pDnode); } - -int32_t dndInitMsgHandle(SDnode *pDnode) { - SDnodeTrans *pTrans = &pDnode->trans; - - for (EDndNodeType n = 0; n < NODE_END; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - - for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) { - NodeMsgFp msgFp = pWrapper->msgFps[msgIndex]; - int8_t vgId = pWrapper->msgVgIds[msgIndex]; - if (msgFp == NULL) continue; - - SMsgHandle *pHandle = &pTrans->msgHandles[msgIndex]; - if (vgId == QNODE_HANDLE) { - if (pHandle->pQndWrapper != NULL) { - dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); - return -1; - } - pHandle->pQndWrapper = pWrapper; - } else if (vgId == MNODE_HANDLE) { - if (pHandle->pMndWrapper != NULL) { - dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); - return -1; - } - pHandle->pMndWrapper = pWrapper; - } else { - if (pHandle->pNdWrapper != NULL) { - dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); - return -1; - } - pHandle->pNdWrapper = pWrapper; - } - } - } - - return 0; -} - -static int32_t dndSendRpcReq(SDnodeTrans *pTrans, const SEpSet *pEpSet, SRpcMsg *pReq) { - if (pTrans->clientRpc == NULL) { - terrno = TSDB_CODE_NODE_OFFLINE; - return -1; - } - - rpcSendRequest(pTrans->clientRpc, pEpSet, pReq, NULL); - return 0; -} - -static void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { - if (pRsp->code == TSDB_CODE_NODE_REDIRECT) { - dmSendRedirectRsp(pWrapper->pMgmt, pRsp); - } else { - rpcSendResponse(pRsp); - } -} - -static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { - if (dndGetStatus(pWrapper->pDnode) != DND_STAT_RUNNING) { - terrno = TSDB_CODE_NODE_OFFLINE; - dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle); - return -1; - } - - if (pWrapper->procType != DND_PROC_CHILD) { - return dndSendRpcReq(&pWrapper->pDnode->trans, pEpSet, pReq); - } else { - char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet)); - if (pHead == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - memcpy(pHead, pReq, sizeof(SRpcMsg)); - memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet)); - taosProcPutToParentQ(pWrapper->procObj, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen, - PROC_REQ); - taosMemoryFree(pHead); - return 0; - } -} - -static void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { - if (pWrapper->procType != DND_PROC_CHILD) { - dndSendRpcRsp(pWrapper, pRsp); - } else { - taosProcPutToParentQ(pWrapper->procObj, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP); - } -} - -static void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { - if (pWrapper->procType != DND_PROC_CHILD) { - rpcRegisterBrokenLinkArg(pMsg); - } else { - taosProcPutToParentQ(pWrapper->procObj, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REGIST); - } -} - -static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) { - if (pWrapper->procType != DND_PROC_CHILD) { - rpcReleaseHandle(handle, type); - } else { - SRpcMsg msg = {.handle = handle, .code = type}; - taosProcPutToParentQ(pWrapper->procObj, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE); - } -} - -static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, - ProcFuncType ftype) { - SRpcMsg *pRpc = &pMsg->rpcMsg; - pRpc->pCont = pCont; - dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle); - - NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; - int32_t code = (*msgFp)(pWrapper, pMsg); - - if (code != 0) { - dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); - if (pRpc->msgType & 1U) { - SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; - dndSendRsp(pWrapper, &rsp); - } - - dTrace("msg:%p, is freed", pMsg); - taosFreeQitem(pMsg); - rpcFreeCont(pCont); - } -} - -static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, - ProcFuncType ftype) { - pMsg->pCont = pCont; - dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle, - pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle); - - switch (ftype) { - case PROC_REGIST: - rpcRegisterBrokenLinkArg(pMsg); - break; - case PROC_RELEASE: - taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); - rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); - rpcFreeCont(pCont); - break; - case PROC_REQ: - dndSendRpcReq(&pWrapper->pDnode->trans, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); - break; - case PROC_RSP: - taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); - dndSendRpcRsp(pWrapper, pMsg); - break; - default: - break; - } - taosMemoryFree(pMsg); -} - -SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) { - SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, - .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, - .childFreeHeadFp = (ProcFreeFp)taosFreeQitem, - .childMallocBodyFp = (ProcMallocFp)rpcMallocCont, - .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, - .parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, - .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, - .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, - .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .shm = pWrapper->procShm, - .parent = pWrapper, - .name = pWrapper->name}; - return cfg; -} - -void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) { - rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp); -} \ No newline at end of file diff --git a/source/dnode/mgmt/implement/src/dmWorker.c b/source/dnode/mgmt/implement/src/dndWorker.c similarity index 99% rename from source/dnode/mgmt/implement/src/dmWorker.c rename to source/dnode/mgmt/implement/src/dndWorker.c index 6886c56fab..1f42c8105b 100644 --- a/source/dnode/mgmt/implement/src/dmWorker.c +++ b/source/dnode/mgmt/implement/src/dndWorker.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dmInt.h" +#include "dndImp.h" static void *dmThreadRoutine(void *param) { SDnodeData *pMgmt = param; diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index 2cafd3f7f6..ae7b3d6f1f 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -154,7 +154,7 @@ static void taosProcCleanupQueue(SProcQueue *pQueue) { } static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, - const char *pBody, int32_t rawBodyLen, int64_t handle, ProcFuncType ftype) { + const char *pBody, int32_t rawBodyLen, int64_t handle, EProcFuncType ftype) { if (rawHeadLen == 0 || pHead == NULL) { terrno = TSDB_CODE_INVALID_PARA; return -1; @@ -171,7 +171,7 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char return -1; } - if (handle != 0 && ftype == PROC_REQ) { + if (handle != 0 && ftype == PROC_FUNC_REQ) { if (taosHashPut(pProc->hash, &handle, sizeof(int64_t), &handle, sizeof(int64_t)) != 0) { taosThreadMutexUnlock(&pQueue->mutex); terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -232,7 +232,7 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char } static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, int32_t *pBodyLen, - ProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp, + EProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp, ProcMallocFp mallocBodyFp, ProcFreeFp freeBodyFp) { tsem_wait(&pQueue->sem); @@ -309,7 +309,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea *ppBody = pBody; *pHeadLen = rawHeadLen; *pBodyLen = rawBodyLen; - *pFuncType = (ProcFuncType)ftype; + *pFuncType = (EProcFuncType)ftype; uTrace("proc:%s, pop msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype, pQueue->items, rawHeadLen, pHead, rawBodyLen, pBody); @@ -364,7 +364,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { static void taosProcThreadLoop(SProcObj *pProc) { void *pHead, *pBody; int16_t headLen; - ProcFuncType ftype; + EProcFuncType ftype; int32_t bodyLen; SProcQueue *pQueue; ProcConsumeFp consumeFp; @@ -454,8 +454,8 @@ void taosProcCleanup(SProcObj *pProc) { } int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - void *handle, ProcFuncType ftype) { - if (ftype != PROC_REQ) { + void *handle, EProcFuncType ftype) { + if (ftype != PROC_FUNC_REQ) { terrno = TSDB_CODE_INVALID_PARA; return -1; } @@ -482,7 +482,7 @@ void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)) { } void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - ProcFuncType ftype) { + EProcFuncType ftype) { int32_t retry = 0; while (taosProcQueuePush(pProc, pProc->pParentQueue, pHead, headLen, pBody, bodyLen, 0, ftype) != 0) { uWarn("proc:%s, failed to put to queue:%p since %s, retry:%d", pProc->name, pProc->pParentQueue, terrstr(), retry); diff --git a/source/util/test/procTest.cpp b/source/util/test/procTest.cpp index 54aaf49673..e05008e8e1 100644 --- a/source/util/test/procTest.cpp +++ b/source/util/test/procTest.cpp @@ -89,7 +89,7 @@ TEST_F(UtilTesProc, 00_Init_Cleanup) { taosDropShm(&shm); } -void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -120,20 +120,20 @@ TEST_F(UtilTesProc, 01_Push_Pop_Child) { SProcObj *cproc = taosProcInit(&cfg); ASSERT_NE(cproc, nullptr); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_RSP), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_REGIST), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_RELEASE), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, NULL, 12, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, shm.size, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, shm.size, 0, PROC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_RSP), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_REGIST), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_RELEASE), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, NULL, 12, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, shm.size, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, shm.size, 0, PROC_FUNC_REQ), 0); for (int32_t j = 0; j < 1000; j++) { int32_t i = 0; for (i = 0; i < 20; ++i) { - ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_REQ), 0); + ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_FUNC_REQ), 0); } - ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_FUNC_REQ), 0); cfg.isChild = true; cfg.name = "1235_p"; @@ -147,7 +147,7 @@ TEST_F(UtilTesProc, 01_Push_Pop_Child) { taosDropShm(&shm); } -void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -186,7 +186,7 @@ TEST_F(UtilTesProc, 02_Push_Pop_Parent) { for (int32_t j = 0; j < 1000; j++) { int32_t i = 0; for (i = 0; i < 20; ++i) { - taosProcPutToParentQ(pproc, &head, sizeof(STestMsg), body, i, PROC_REQ); + taosProcPutToParentQ(pproc, &head, sizeof(STestMsg), body, i, PROC_FUNC_REQ); } taosProcRun(cproc); @@ -198,7 +198,7 @@ TEST_F(UtilTesProc, 02_Push_Pop_Parent) { taosDropShm(&shm); } -void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -236,7 +236,7 @@ TEST_F(UtilTesProc, 03_Handle) { int32_t i = 0; for (i = 0; i < 20; ++i) { head.handle = (void *)((int64_t)i); - ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), PROC_REQ), 0); + ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), PROC_FUNC_REQ), 0); } cfg.isChild = true; From 3de4b0ad05f29a88d6000ee6add23ece3ad65abc Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Apr 2022 09:59:33 +0800 Subject: [PATCH 07/19] refact(cluster): node mgmt --- source/dnode/mgmt/implement/inc/dndImp.h | 28 +-- source/dnode/mgmt/implement/src/dndExec.c | 2 +- source/dnode/mgmt/implement/src/dndHandle.c | 198 ++++++++++++------ source/dnode/mgmt/implement/src/dndObj.c | 101 +-------- .../dnode/mgmt/implement/src/dndTransport.c | 10 +- source/dnode/mgmt/implement/src/dndWorker.c | 117 +++++++---- source/dnode/mgmt/interface/inc/dndDef.h | 25 +-- source/dnode/mgmt/interface/inc/dndInt.h | 2 +- source/dnode/mgmt/interface/src/dndInt.c | 2 +- source/dnode/mgmt/mgmt_bnode/src/bmInt.c | 2 +- source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 2 +- source/dnode/mgmt/mgmt_qnode/src/qmInt.c | 2 +- source/dnode/mgmt/mgmt_snode/src/smInt.c | 2 +- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 2 +- source/dnode/mgmt/mgmt_vnode/src/vmInt.c | 2 +- 15 files changed, 252 insertions(+), 245 deletions(-) diff --git a/source/dnode/mgmt/implement/inc/dndImp.h b/source/dnode/mgmt/implement/inc/dndImp.h index 31b2f0a53a..804cc43d56 100644 --- a/source/dnode/mgmt/implement/inc/dndImp.h +++ b/source/dnode/mgmt/implement/inc/dndImp.h @@ -26,12 +26,13 @@ int32_t dndOpenNode(SMgmtWrapper *pWrapper); void dndCloseNode(SMgmtWrapper *pWrapper); // dndTransport.c -int32_t dndInitTrans(SDnode *pDnode); +int32_t dmInitTrans(SDnode *pDnode); void dndCleanupTrans(SDnode *pDnode); SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); int32_t dndInitMsgHandle(SDnode *pDnode); -void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pReq); +int32_t dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pReq); void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); +void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp); // mgmt void dmSetMgmtFp(SMgmtWrapper *pWrapper); @@ -54,12 +55,11 @@ int32_t dmWriteFile(SDnodeData *pMgmt); void dmUpdateDnodeEps(SDnodeData *pMgmt, SArray *pDnodeEps); // dmHandle.c -void dmInitMsgHandle(SMgmtWrapper *pWrapper); -void dmSendStatusReq(SDnodeData *pMgmt); -int32_t dmProcessConfigReq(SDnodeData *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessStatusRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessAuthRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessGrantRsp(SDnodeData *pMgmt, SNodeMsg *pMsg); +void dmSendStatusReq(SDnode *pDnode); +int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessStatusRsp(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg); int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); // dmMonitor.c @@ -67,11 +67,15 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); void dmSendMonitorReport(SDnode *pDnode); // dmWorker.c -int32_t dmStartThread(SDnodeData *pMgmt); -int32_t dmStartWorker(SDnodeData *pMgmt); -void dmStopWorker(SDnodeData *pMgmt); +int32_t dmStartStatusThread(SDnode *pDnode); +void dmStopStatusThread(SDnode *pDnode); +int32_t dmStartMonitorThread(SDnode *pDnode); +void dmStopMonitorThread(SDnode *pDnode); + +int32_t dmStartWorker(SDnode *pDnode); +void dmStopWorker(SDnode *pDnode); int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/implement/src/dndExec.c b/source/dnode/mgmt/implement/src/dndExec.c index c30e730d8a..6e49c588c6 100644 --- a/source/dnode/mgmt/implement/src/dndExec.c +++ b/source/dnode/mgmt/implement/src/dndExec.c @@ -299,7 +299,7 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { return -1; } - SMsgCb msgCb = dndCreateMsgcb(pWrapper); + SMsgCb msgCb = dmGetMsgcb(pWrapper); tmsgSetDefaultMsgCb(&msgCb); pWrapper->procType = DND_PROC_CHILD; diff --git a/source/dnode/mgmt/implement/src/dndHandle.c b/source/dnode/mgmt/implement/src/dndHandle.c index 196671c916..f8e3cc5c0c 100644 --- a/source/dnode/mgmt/implement/src/dndHandle.c +++ b/source/dnode/mgmt/implement/src/dndHandle.c @@ -16,67 +16,9 @@ #define _DEFAULT_SOURCE #include "dndImp.h" -void dmSendStatusReq(SDnodeData *pMgmt) { - SDnode *pDnode = pMgmt->pDnode; - SStatusReq req = {0}; - - taosRLockLatch(&pMgmt->latch); - req.sver = tsVersion; - req.dnodeVer = pMgmt->dnodeVer; - req.dnodeId = pDnode->data.dnodeId; - req.clusterId = pDnode->data.clusterId; - req.rebootTime = pDnode->data.rebootTime; - req.updateTime = pMgmt->updateTime; - req.numOfCores = tsNumOfCores; - req.numOfSupportVnodes = pDnode->data.supportVnodes; - tstrncpy(req.dnodeEp, pDnode->data.localEp, TSDB_EP_LEN); - - req.clusterCfg.statusInterval = tsStatusInterval; - req.clusterCfg.checkTime = 0; - char timestr[32] = "1970-01-01 00:00:00.00"; - (void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); - memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); - memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN); - memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); - taosRUnLockLatch(&pMgmt->latch); - - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODE); - if (pWrapper != NULL) { - SMonVloadInfo info = {0}; - dmGetVnodeLoads(pWrapper, &info); - req.pVloads = info.pVloads; - dndReleaseWrapper(pWrapper); - } - - int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); - void *pHead = rpcMallocCont(contLen); - tSerializeSStatusReq(pHead, contLen, &req); - taosArrayDestroy(req.pVloads); - - SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; - pMgmt->statusSent = 1; - - dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); - dndSendMsgToMnode(pDnode, &rpcMsg); -} - -static void dmUpdateDnodeCfg(SDnodeData *pMgmt, SDnodeCfg *pCfg) { +static int32_t dmProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) { SDnode *pDnode = pMgmt->pDnode; - if (pDnode->data.dnodeId == 0) { - dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); - taosWLockLatch(&pMgmt->latch); - pDnode->data.dnodeId = pCfg->dnodeId; - pDnode->data.clusterId = pCfg->clusterId; - dmWriteFile(pMgmt); - taosWUnLockLatch(&pMgmt->latch); - } -} - -int32_t dmProcessStatusRsp(SDnodeData *pMgmt, SNodeMsg *pMsg) { - SDnode *pDnode = pMgmt->pDnode; - SRpcMsg *pRsp = &pMsg->rpcMsg; - if (pRsp->code != TSDB_CODE_SUCCESS) { if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->data.dropped && pDnode->data.dnodeId > 0) { dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->data.dnodeId); @@ -94,10 +36,66 @@ int32_t dmProcessStatusRsp(SDnodeData *pMgmt, SNodeMsg *pMsg) { tFreeSStatusRsp(&statusRsp); } - pMgmt->statusSent = 0; return TSDB_CODE_SUCCESS; } +void dmSendStatusReq(SDnode *pDnode) { + SStatusReq req = {0}; + + taosRLockLatch(&pDnode->data.latch); + req.sver = tsVersion; + req.dnodeVer = pMgmt->dnodeVer; + req.dnodeId = pDnode->data.dnodeId; + req.clusterId = pDnode->data.clusterId; + req.rebootTime = pDnode->data.rebootTime; + req.updateTime = pMgmt->updateTime; + req.numOfCores = tsNumOfCores; + req.numOfSupportVnodes = pDnode->data.supportVnodes; + tstrncpy(req.dnodeEp, pDnode->data.localEp, TSDB_EP_LEN); + + req.clusterCfg.statusInterval = tsStatusInterval; + req.clusterCfg.checkTime = 0; + char timestr[32] = "1970-01-01 00:00:00.00"; + (void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); + memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); + memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN); + memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); + taosRUnLockLatch(&pDnode->data.latch); + + SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODE); + if (pWrapper != NULL) { + SMonVloadInfo info = {0}; + dmGetVnodeLoads(pWrapper, &info); + req.pVloads = info.pVloads; + dndReleaseWrapper(pWrapper); + } + + int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); + void *pHead = rpcMallocCont(contLen); + tSerializeSStatusReq(pHead, contLen, &req); + taosArrayDestroy(req.pVloads); + + SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; + SRpcMsg rspMsg = {0}; + + dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); + dmSendToMnodeRecv(pDnode, rpcMsg, &rpcRsp); + dmProcessStatusRsp(pDnode, &rpcRsp); +} + +static void dmUpdateDnodeCfg(SDnodeData *pMgmt, SDnodeCfg *pCfg) { + SDnode *pDnode = pMgmt->pDnode; + + if (pDnode->data.dnodeId == 0) { + dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); + taosWLockLatch(&pDnode->data.latch); + pDnode->data.dnodeId = pCfg->dnodeId; + pDnode->data.clusterId = pCfg->clusterId; + dmWriteFile(pMgmt); + taosWUnLockLatch(&pDnode->data.latch); + } +} + int32_t dmProcessAuthRsp(SDnodeData *pMgmt, SNodeMsg *pMsg) { SRpcMsg *pRsp = &pMsg->rpcMsg; dError("auth rsp is received, but not supported yet"); @@ -194,7 +192,7 @@ int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg) { } } -void dmInitMsgHandle(SMgmtWrapper *pWrapper) { +static void dmSetMsgHandle(SMgmtWrapper *pWrapper) { // Requests handled by DNODE dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); @@ -205,10 +203,84 @@ void dmInitMsgHandle(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, dmProcessMgmtMsg, DEFAULT_HANDLE); // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMonitorMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); } + +static int32_t dmStart(SMgmtWrapper *pWrapper) { return dmStartStatusThread(pWrapper->pDnode); } + +static void dmStop(SMgmtWrapper *pWrapper) { dmStopThread(pWrapper->pDnode); } + +static int32_t dmInit(SMgmtWrapper *pWrapper) { + dInfo("dnode-data start to init"); + SDnode *pDnode = pWrapper->pDnode; + + pDnode->data.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + if (pDnode->data.dnodeHash == NULL) { + dError("failed to init dnode hash"); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (dmReadFile(pDnode) != 0) { + dError("failed to read file since %s", terrstr()); + return -1; + } + + if (pDnode->data.dropped) { + dError("dnode will not start since its already dropped"); + return -1; + } + + if (dmStartWorker(pDnode) != 0) { + return -1; + } + + if (dmInitTrans(pDnode) != 0) { + dError("failed to init transport since %s", terrstr()); + return -1; + } + + dInfo("dnode-data is initialized"); + return 0; +} + +static void dmCleanup(SMgmtWrapper *pWrapper) { + dInfo("dnode-data start to clean up"); + SDnode *pDnode = pWrapper->pDnode; + dmStopWorker(pDnode); + + taosWLockLatch(&pDnode->data.latch); + if (pMgmt->dnodeEps != NULL) { + taosArrayDestroy(pMgmt->dnodeEps); + pMgmt->dnodeEps = NULL; + } + if (pMgmt->dnodeHash != NULL) { + taosHashCleanup(pMgmt->dnodeHash); + pMgmt->dnodeHash = NULL; + } + taosWUnLockLatch(&pDnode->data.latch); + + dndCleanupTrans(pDnode); + dInfo("dnode-data is cleaned up"); +} + +static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) { + *required = true; + return 0; +} + +void dmSetMgmtFp(SMgmtWrapper *pWrapper) { + SMgmtFp mgmtFp = {0}; + mgmtFp.openFp = dmInit; + mgmtFp.closeFp = dmCleanup; + mgmtFp.startFp = dmStart; + mgmtFp.stopFp = dmStop; + mgmtFp.requiredFp = dmRequire; + + dmSetMsgHandle(pWrapper); + pWrapper->name = "dnode"; + pWrapper->fp = mgmtFp; +} diff --git a/source/dnode/mgmt/implement/src/dndObj.c b/source/dnode/mgmt/implement/src/dndObj.c index bfbdb756c6..8b20a446db 100644 --- a/source/dnode/mgmt/implement/src/dndObj.c +++ b/source/dnode/mgmt/implement/src/dndObj.c @@ -17,103 +17,11 @@ #include "dndImp.h" -static int32_t dmStart(SMgmtWrapper *pWrapper) { - dDebug("dnode-mgmt start to run"); - return dmStartThread(pWrapper->pMgmt); -} - -static int32_t dmInit(SMgmtWrapper *pWrapper) { - SDnode *pDnode = pWrapper->pDnode; - SDnodeData *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeData)); - dInfo("dnode-mgmt start to init"); - +static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->data.dnodeId = 0; pDnode->data.dropped = 0; pDnode->data.clusterId = 0; - pMgmt->path = pWrapper->path; - pMgmt->pDnode = pDnode; - taosInitRWLatch(&pMgmt->latch); - - pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - if (pMgmt->dnodeHash == NULL) { - dError("failed to init dnode hash"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - if (dmReadFile(pMgmt) != 0) { - dError("failed to read file since %s", terrstr()); - return -1; - } - - if (pDnode->data.dropped) { - dError("dnode will not start since its already dropped"); - return -1; - } - - if (dmStartWorker(pMgmt) != 0) { - return -1; - } - - if (dndInitTrans(pDnode) != 0) { - dError("failed to init transport since %s", terrstr()); - return -1; - } - - pWrapper->pMgmt = pMgmt; - pMgmt->msgCb = dndCreateMsgcb(pWrapper); - - dInfo("dnode-mgmt is initialized"); - return 0; -} - -static void dmCleanup(SMgmtWrapper *pWrapper) { - SDnodeData *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - - dInfo("dnode-mgmt start to clean up"); - SDnode *pDnode = pMgmt->pDnode; - dmStopWorker(pMgmt); - - taosWLockLatch(&pMgmt->latch); - - if (pMgmt->dnodeEps != NULL) { - taosArrayDestroy(pMgmt->dnodeEps); - pMgmt->dnodeEps = NULL; - } - - if (pMgmt->dnodeHash != NULL) { - taosHashCleanup(pMgmt->dnodeHash); - pMgmt->dnodeHash = NULL; - } - - taosWUnLockLatch(&pMgmt->latch); - - taosMemoryFree(pMgmt); - pWrapper->pMgmt = NULL; - dndCleanupTrans(pDnode); - - dInfo("dnode-mgmt is cleaned up"); -} - -static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) { - *required = true; - return 0; -} - -void dmSetMgmtFp(SMgmtWrapper *pWrapper) { - SMgmtFp mgmtFp = {0}; - mgmtFp.openFp = dmInit; - mgmtFp.closeFp = dmCleanup; - mgmtFp.startFp = dmStart; - mgmtFp.requiredFp = dmRequire; - - dmInitMsgHandle(pWrapper); - pWrapper->name = "dnode"; - pWrapper->fp = mgmtFp; -} - -static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { + pDnode->data.supportVnodes = pOption->numOfSupportVnodes; pDnode->data.serverPort = pOption->serverPort; pDnode->data.dataDir = strdup(pOption->dataDir); @@ -139,6 +47,7 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { } } + taosInitRWLatch(&pDnode->data.latch); return 0; } @@ -212,7 +121,7 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { goto _OVER; } - SMsgCb msgCb = dndCreateMsgcb(&pDnode->wrappers[0]); + SMsgCb msgCb = dmGetMsgcb(&pDnode->wrappers[0]); tmsgSetDefaultMsgCb(&msgCb); dInfo("dnode is created, data:%p", pDnode); @@ -245,5 +154,3 @@ void dndHandleEvent(SDnode *pDnode, EDndEvent event) { pDnode->event = event; } } - - diff --git a/source/dnode/mgmt/implement/src/dndTransport.c b/source/dnode/mgmt/implement/src/dndTransport.c index 7d9ba1d56d..bf330b0f7b 100644 --- a/source/dnode/mgmt/implement/src/dndTransport.c +++ b/source/dnode/mgmt/implement/src/dndTransport.c @@ -247,13 +247,13 @@ void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) { rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp); } -void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pReq) { +int32_t dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pReq) { SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); - dndSendRpcReq(pDnode, &epSet, pReq); + return dndSendRpcReq(pDnode, &epSet, pReq); } -static inline void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) { +void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) { SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp); @@ -453,7 +453,7 @@ static inline int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char * SRpcMsg rpcMsg = {.pCont = pReq, .contLen = contLen, .msgType = TDMT_MND_AUTH, .ahandle = (void *)9528}; SRpcMsg rpcRsp = {0}; dTrace("user:%s, send user auth req to other mnodes, spi:%d encrypt:%d", user, authReq.spi, authReq.encrypt); - dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp); + dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp); if (rpcRsp.code != 0) { terrno = rpcRsp.code; @@ -506,7 +506,7 @@ static void dndCleanupServer(SDnode *pDnode) { } } -int32_t dndInitTrans(SDnode *pDnode) { +int32_t dmInitTrans(SDnode *pDnode) { if (dndInitServer(pDnode) != 0) return -1; if (dndInitClient(pDnode) != 0) return -1; diff --git a/source/dnode/mgmt/implement/src/dndWorker.c b/source/dnode/mgmt/implement/src/dndWorker.c index 1f42c8105b..975150e230 100644 --- a/source/dnode/mgmt/implement/src/dndWorker.c +++ b/source/dnode/mgmt/implement/src/dndWorker.c @@ -16,41 +16,60 @@ #define _DEFAULT_SOURCE #include "dndImp.h" -static void *dmThreadRoutine(void *param) { - SDnodeData *pMgmt = param; - SDnode *pDnode = pMgmt->pDnode; - int64_t lastStatusTime = taosGetTimestampMs(); - int64_t lastMonitorTime = lastStatusTime; +static void *dmStatusThreadFp(void *param) { + SDnode *pDnode = param; + int64_t lastTime = taosGetTimestampMs(); - setThreadName("dnode-hb"); + setThreadName("dnode-status"); - while (true) { + while (1) { taosThreadTestCancel(); taosMsleep(200); - if (dndGetStatus(pDnode) != DND_STAT_RUNNING || pDnode->data.dropped) { + + if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) { continue; } int64_t curTime = taosGetTimestampMs(); - float statusInterval = (curTime - lastStatusTime) / 1000.0f; - if (statusInterval >= tsStatusInterval && !pMgmt->statusSent) { + float interval = (curTime - lastTime) / 1000.0f; + if (interval >= tsStatusInterval) { dmSendStatusReq(pMgmt); - lastStatusTime = curTime; - } - - float monitorInterval = (curTime - lastMonitorTime) / 1000.0f; - if (monitorInterval >= tsMonitorInterval) { - dmSendMonitorReport(pDnode); - lastMonitorTime = curTime; + lastTime = curTime; } } - return TSDB_CODE_SUCCESS; + + return NULL; } -int32_t dmStartThread(SDnodeData *pMgmt) { - pMgmt->threadId = taosCreateThread(dmThreadRoutine, pMgmt); - if (pMgmt->threadId == NULL) { - dError("failed to init dnode thread"); +static void *dmMonitorThreadFp(void *param) { + SDnode *pDnode = param; + int64_t lastTime = taosGetTimestampMs(); + + setThreadName("dnode-monitor"); + + while (1) { + taosThreadTestCancel(); + taosMsleep(200); + + if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) { + continue; + } + + int64_t curTime = taosGetTimestampMs(); + float interval = (curTime - lastTime) / 1000.0f; + if (interval >= tsMonitorInterval) { + dmSendMonitorReport(pDnode); + lastTime = curTime; + } + } + + return NULL; +} + +int32_t dmStartStatusThread(SDnode *pDnode) { + pDnode->statusThreadId = taosCreateThread(dmStatusThreadFp, pDnode); + if (pDnode->statusThreadId == NULL) { + dError("failed to init dnode status thread"); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -58,21 +77,41 @@ int32_t dmStartThread(SDnodeData *pMgmt) { return 0; } -static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { - SDnodeData *pMgmt = pInfo->ahandle; +void dmStopStatusThread(SDnode *pDnode) { + if (pDnode->statusThreadId != NULL) { + taosDestoryThread(pDnode->statusThreadId); + pDnode->statusThreadId = NULL; + } +} - SDnode *pDnode = pMgmt->pDnode; +int32_t dmStartMonitorThread(SDnode *pDnode) { + pDnode->monitorThreadId = taosCreateThread(dmMonitorThreadFp, pDnode); + if (pDnode->monitorThreadId == NULL) { + dError("failed to init dnode monitor thread"); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + +void dmStopMonitorThread(SDnode *pDnode) { + if (pMgmt->monitorThreadId != NULL) { + taosDestoryThread(pMgmt->monitorThreadId); + pMgmt->monitorThreadId = NULL; + } +} + +static void dmProcessMgmtQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { + SDnode *pDnode = pInfo->ahandle; SRpcMsg *pRpc = &pMsg->rpcMsg; int32_t code = -1; - dTrace("msg:%p, will be processed in dnode queue", pMsg); + dTrace("msg:%p, will be processed in dnode-mgmt queue", pMsg); switch (pRpc->msgType) { case TDMT_DND_CONFIG_DNODE: code = dmProcessConfigReq(pMgmt, pMsg); break; - case TDMT_MND_STATUS_RSP: - code = dmProcessStatusRsp(pMgmt, pMsg); - break; case TDMT_MND_AUTH_RSP: code = dmProcessAuthRsp(pMgmt, pMsg); break; @@ -96,15 +135,9 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { } int32_t dmStartWorker(SDnodeData *pMgmt) { - SSingleWorkerCfg mcfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mcfg) != 0) { - dError("failed to start dnode mgmt worker since %s", terrstr()); - return -1; - } - - SSingleWorkerCfg scfg = {.min = 1, .max = 1, .name = "dnode-monitor", .fp = (FItem)dmProcessQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &scfg) != 0) { - dError("failed to start dnode monitor worker since %s", terrstr()); + SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessMgmtQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) { + dError("failed to start dnode-mgmt worker since %s", terrstr()); return -1; } @@ -114,12 +147,6 @@ int32_t dmStartWorker(SDnodeData *pMgmt) { void dmStopWorker(SDnodeData *pMgmt) { tSingleWorkerCleanup(&pMgmt->mgmtWorker); - tSingleWorkerCleanup(&pMgmt->monitorWorker); - - if (pMgmt->threadId != NULL) { - taosDestoryThread(pMgmt->threadId); - pMgmt->threadId = NULL; - } dDebug("dnode workers are closed"); } @@ -132,7 +159,7 @@ int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } -int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { +int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnodeData *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->monitorWorker; diff --git a/source/dnode/mgmt/interface/inc/dndDef.h b/source/dnode/mgmt/interface/inc/dndDef.h index 0ce5a64ed0..077b15d021 100644 --- a/source/dnode/mgmt/interface/inc/dndDef.h +++ b/source/dnode/mgmt/interface/inc/dndDef.h @@ -110,29 +110,26 @@ typedef struct { int64_t updateTime; int64_t rebootTime; bool dropped; - int8_t statusSent; SEpSet mnodeEpSet; SHashObj *dnodeHash; SArray *dnodeEps; - TdThread *threadId; + TdThread *statusThreadId; + TdThread *monitorThreadId; SRWLatch latch; SSingleWorker mgmtWorker; - SSingleWorker monitorWorker; SMsgCb msgCb; SDnode *pDnode; const char *path; TdFilePtr lockfile; - struct { - char *localEp; - char *localFqdn; - char *firstEp; - char *secondEp; - char *dataDir; - SDiskCfg *disks; - int32_t numOfDisks; - int32_t supportVnodes; - uint16_t serverPort; - }; + char *localEp; + char *localFqdn; + char *firstEp; + char *secondEp; + char *dataDir; + SDiskCfg *disks; + int32_t numOfDisks; + int32_t supportVnodes; + uint16_t serverPort; } SDnodeData; typedef struct SDnode { diff --git a/source/dnode/mgmt/interface/inc/dndInt.h b/source/dnode/mgmt/interface/inc/dndInt.h index f158336037..b178a64d35 100644 --- a/source/dnode/mgmt/interface/inc/dndInt.h +++ b/source/dnode/mgmt/interface/inc/dndInt.h @@ -37,7 +37,7 @@ void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); void dndGetMonitorSysInfo(SMonSysInfo *pInfo); -SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); +SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper); // dndFile.c int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); diff --git a/source/dnode/mgmt/interface/src/dndInt.c b/source/dnode/mgmt/interface/src/dndInt.c index 52091ceb17..88312202b6 100644 --- a/source/dnode/mgmt/interface/src/dndInt.c +++ b/source/dnode/mgmt/interface/src/dndInt.c @@ -174,7 +174,7 @@ void dndGetMonitorSysInfo(SMonSysInfo *pInfo) { taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); } -SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) { +SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) { SMsgCb msgCb = pWrapper->pDnode->data.msgCb; msgCb.pWrapper = pWrapper; return msgCb; diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c index 71ba2bab8c..bca6e0432a 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c @@ -19,7 +19,7 @@ static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 374b33ed01..2d8914df25 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -39,7 +39,7 @@ static int32_t mmRequire(SMgmtWrapper *pWrapper, bool *required) { } static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue; msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue; msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue; diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c index cb06fe5d25..d211faaa35 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c @@ -19,7 +19,7 @@ static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); msgCb.queueFps[QUERY_QUEUE] = qmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = qmPutMsgToFetchQueue; msgCb.qsizeFp = qmGetQueueSize; diff --git a/source/dnode/mgmt/mgmt_snode/src/smInt.c b/source/dnode/mgmt/mgmt_snode/src/smInt.c index 02958104a0..7d3bfd6ab2 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smInt.c +++ b/source/dnode/mgmt/mgmt_snode/src/smInt.c @@ -19,7 +19,7 @@ static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index f9e2b45d74..813bc9c5f7 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -143,7 +143,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return -1; } - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index b298b4c93a..94a6910ba3 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -128,7 +128,7 @@ static void *vmOpenVnodeFunc(void *param) { pMgmt->state.openVnodes, pMgmt->state.totalVnodes); dndReportStartup(pDnode, "open-vnodes", stepDesc); - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; From 271264f626c011e23f5667e0b0501d147c4d81c3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Apr 2022 10:00:50 +0800 Subject: [PATCH 08/19] refact(cluster): node mgmt --- source/dnode/mgmt/exe/{dndMain.c => dmMain.c} | 2 +- source/dnode/mgmt/implement/inc/{dndImp.h => dmImp.h} | 2 +- source/dnode/mgmt/implement/src/{dndEps.c => dmEps.c} | 2 +- source/dnode/mgmt/implement/src/{dndExec.c => dmExec.c} | 2 +- source/dnode/mgmt/implement/src/{dndHandle.c => dmHandle.c} | 2 +- source/dnode/mgmt/implement/src/{dndMonitor.c => dmMonitor.c} | 2 +- source/dnode/mgmt/implement/src/{dndObj.c => dmObj.c} | 2 +- .../dnode/mgmt/implement/src/{dndTransport.c => dmTransport.c} | 2 +- source/dnode/mgmt/implement/src/{dndWorker.c => dmWorker.c} | 2 +- source/dnode/mgmt/interface/inc/{dndDef.h => dmDef.h} | 2 +- source/dnode/mgmt/interface/inc/{dndInt.h => dmInt.h} | 2 +- source/dnode/mgmt/interface/inc/{dndLog.h => dmLog.h} | 0 source/dnode/mgmt/interface/src/{dndEnv.c => dmEnv.c} | 2 +- source/dnode/mgmt/interface/src/{dndFile.c => dmFile.c} | 2 +- source/dnode/mgmt/interface/src/{dndInt.c => dmInt.c} | 2 +- source/dnode/mgmt/mgmt_bnode/inc/bmInt.h | 2 +- source/dnode/mgmt/mgmt_mnode/inc/mmInt.h | 2 +- source/dnode/mgmt/mgmt_qnode/inc/qmInt.h | 2 +- source/dnode/mgmt/mgmt_snode/inc/smInt.h | 2 +- source/dnode/mgmt/mgmt_vnode/inc/vmInt.h | 2 +- 20 files changed, 19 insertions(+), 19 deletions(-) rename source/dnode/mgmt/exe/{dndMain.c => dmMain.c} (99%) rename source/dnode/mgmt/implement/inc/{dndImp.h => dmImp.h} (99%) rename source/dnode/mgmt/implement/src/{dndEps.c => dmEps.c} (99%) rename source/dnode/mgmt/implement/src/{dndExec.c => dmExec.c} (99%) rename source/dnode/mgmt/implement/src/{dndHandle.c => dmHandle.c} (99%) rename source/dnode/mgmt/implement/src/{dndMonitor.c => dmMonitor.c} (99%) rename source/dnode/mgmt/implement/src/{dndObj.c => dmObj.c} (99%) rename source/dnode/mgmt/implement/src/{dndTransport.c => dmTransport.c} (99%) rename source/dnode/mgmt/implement/src/{dndWorker.c => dmWorker.c} (99%) rename source/dnode/mgmt/interface/inc/{dndDef.h => dmDef.h} (99%) rename source/dnode/mgmt/interface/inc/{dndInt.h => dmInt.h} (98%) rename source/dnode/mgmt/interface/inc/{dndLog.h => dmLog.h} (100%) rename source/dnode/mgmt/interface/src/{dndEnv.c => dmEnv.c} (98%) rename source/dnode/mgmt/interface/src/{dndFile.c => dmFile.c} (99%) rename source/dnode/mgmt/interface/src/{dndInt.c => dmInt.c} (99%) diff --git a/source/dnode/mgmt/exe/dndMain.c b/source/dnode/mgmt/exe/dmMain.c similarity index 99% rename from source/dnode/mgmt/exe/dndMain.c rename to source/dnode/mgmt/exe/dmMain.c index 2454375d46..9213090a4e 100644 --- a/source/dnode/mgmt/exe/dndMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndImp.h" +#include "dmImp.h" #include "tconfig.h" static struct { diff --git a/source/dnode/mgmt/implement/inc/dndImp.h b/source/dnode/mgmt/implement/inc/dmImp.h similarity index 99% rename from source/dnode/mgmt/implement/inc/dndImp.h rename to source/dnode/mgmt/implement/inc/dmImp.h index 804cc43d56..d001c7be98 100644 --- a/source/dnode/mgmt/implement/inc/dndImp.h +++ b/source/dnode/mgmt/implement/inc/dmImp.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_IMP_H_ #define _TD_DND_IMP_H_ -#include "dndInt.h" +#include "dmInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mgmt/implement/src/dndEps.c b/source/dnode/mgmt/implement/src/dmEps.c similarity index 99% rename from source/dnode/mgmt/implement/src/dndEps.c rename to source/dnode/mgmt/implement/src/dmEps.c index 04de19d6a8..31ebb9955f 100644 --- a/source/dnode/mgmt/implement/src/dndEps.c +++ b/source/dnode/mgmt/implement/src/dmEps.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndImp.h" +#include "dmImp.h" static void dmPrintDnodes(SDnodeData *pMgmt); static bool dmIsEpChanged(SDnodeData *pMgmt, int32_t dnodeId, const char *ep); diff --git a/source/dnode/mgmt/implement/src/dndExec.c b/source/dnode/mgmt/implement/src/dmExec.c similarity index 99% rename from source/dnode/mgmt/implement/src/dndExec.c rename to source/dnode/mgmt/implement/src/dmExec.c index 6e49c588c6..c73e79a2da 100644 --- a/source/dnode/mgmt/implement/src/dndExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndImp.h" +#include "dmImp.h" static bool dndRequireNode(SMgmtWrapper *pWrapper) { bool required = false; diff --git a/source/dnode/mgmt/implement/src/dndHandle.c b/source/dnode/mgmt/implement/src/dmHandle.c similarity index 99% rename from source/dnode/mgmt/implement/src/dndHandle.c rename to source/dnode/mgmt/implement/src/dmHandle.c index f8e3cc5c0c..1beb36054b 100644 --- a/source/dnode/mgmt/implement/src/dndHandle.c +++ b/source/dnode/mgmt/implement/src/dmHandle.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndImp.h" +#include "dmImp.h" static int32_t dmProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) { SDnode *pDnode = pMgmt->pDnode; diff --git a/source/dnode/mgmt/implement/src/dndMonitor.c b/source/dnode/mgmt/implement/src/dmMonitor.c similarity index 99% rename from source/dnode/mgmt/implement/src/dndMonitor.c rename to source/dnode/mgmt/implement/src/dmMonitor.c index 73aa8d9424..467aab112b 100644 --- a/source/dnode/mgmt/implement/src/dndMonitor.c +++ b/source/dnode/mgmt/implement/src/dmMonitor.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndImp.h" +#include "dmImp.h" static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { pInfo->protocol = 1; diff --git a/source/dnode/mgmt/implement/src/dndObj.c b/source/dnode/mgmt/implement/src/dmObj.c similarity index 99% rename from source/dnode/mgmt/implement/src/dndObj.c rename to source/dnode/mgmt/implement/src/dmObj.c index 8b20a446db..3e9877292f 100644 --- a/source/dnode/mgmt/implement/src/dndObj.c +++ b/source/dnode/mgmt/implement/src/dmObj.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndImp.h" +#include "dmImp.h" static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { diff --git a/source/dnode/mgmt/implement/src/dndTransport.c b/source/dnode/mgmt/implement/src/dmTransport.c similarity index 99% rename from source/dnode/mgmt/implement/src/dndTransport.c rename to source/dnode/mgmt/implement/src/dmTransport.c index bf330b0f7b..a0251a69f5 100644 --- a/source/dnode/mgmt/implement/src/dndTransport.c +++ b/source/dnode/mgmt/implement/src/dmTransport.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndImp.h" +#include "dmImp.h" #define INTERNAL_USER "_dnd" #define INTERNAL_CKEY "_key" diff --git a/source/dnode/mgmt/implement/src/dndWorker.c b/source/dnode/mgmt/implement/src/dmWorker.c similarity index 99% rename from source/dnode/mgmt/implement/src/dndWorker.c rename to source/dnode/mgmt/implement/src/dmWorker.c index 975150e230..9c32d0bda6 100644 --- a/source/dnode/mgmt/implement/src/dndWorker.c +++ b/source/dnode/mgmt/implement/src/dmWorker.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndImp.h" +#include "dmImp.h" static void *dmStatusThreadFp(void *param) { SDnode *pDnode = param; diff --git a/source/dnode/mgmt/interface/inc/dndDef.h b/source/dnode/mgmt/interface/inc/dmDef.h similarity index 99% rename from source/dnode/mgmt/interface/inc/dndDef.h rename to source/dnode/mgmt/interface/inc/dmDef.h index 077b15d021..26d7d42af9 100644 --- a/source/dnode/mgmt/interface/inc/dndDef.h +++ b/source/dnode/mgmt/interface/inc/dmDef.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_DEF_H_ #define _TD_DND_DEF_H_ -#include "dndLog.h" +#include "dmLog.h" #include "cJSON.h" #include "tcache.h" diff --git a/source/dnode/mgmt/interface/inc/dndInt.h b/source/dnode/mgmt/interface/inc/dmInt.h similarity index 98% rename from source/dnode/mgmt/interface/inc/dndInt.h rename to source/dnode/mgmt/interface/inc/dmInt.h index b178a64d35..7b633671f8 100644 --- a/source/dnode/mgmt/interface/inc/dndInt.h +++ b/source/dnode/mgmt/interface/inc/dmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_INT_H_ #define _TD_DND_INT_H_ -#include "dndDef.h" +#include "dmDef.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/mgmt/interface/inc/dndLog.h b/source/dnode/mgmt/interface/inc/dmLog.h similarity index 100% rename from source/dnode/mgmt/interface/inc/dndLog.h rename to source/dnode/mgmt/interface/inc/dmLog.h diff --git a/source/dnode/mgmt/interface/src/dndEnv.c b/source/dnode/mgmt/interface/src/dmEnv.c similarity index 98% rename from source/dnode/mgmt/interface/src/dndEnv.c rename to source/dnode/mgmt/interface/src/dmEnv.c index 9f75594335..e7dc0e3e77 100644 --- a/source/dnode/mgmt/interface/src/dndEnv.c +++ b/source/dnode/mgmt/interface/src/dmEnv.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmInt.h" #include "wal.h" static int8_t once = DND_ENV_INIT; diff --git a/source/dnode/mgmt/interface/src/dndFile.c b/source/dnode/mgmt/interface/src/dmFile.c similarity index 99% rename from source/dnode/mgmt/interface/src/dndFile.c rename to source/dnode/mgmt/interface/src/dmFile.c index 0358e90fb3..70dbcc009f 100644 --- a/source/dnode/mgmt/interface/src/dndFile.c +++ b/source/dnode/mgmt/interface/src/dmFile.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmInt.h" #define MAXLEN 1024 diff --git a/source/dnode/mgmt/interface/src/dndInt.c b/source/dnode/mgmt/interface/src/dmInt.c similarity index 99% rename from source/dnode/mgmt/interface/src/dndInt.c rename to source/dnode/mgmt/interface/src/dmInt.c index 88312202b6..eab6c074b6 100644 --- a/source/dnode/mgmt/interface/src/dndInt.c +++ b/source/dnode/mgmt/interface/src/dmInt.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmInt.h" const char *dndStatName(EDndRunStatus status) { switch (status) { diff --git a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h index 3158fe7d34..8a7442efc3 100644 --- a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h +++ b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_BNODE_INT_H_ #define _TD_DND_BNODE_INT_H_ -#include "dndInt.h" +#include "dmInt.h" #include "bnode.h" diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index d744d981bf..0742d2b9f9 100644 --- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_MNODE_INT_H_ #define _TD_DND_MNODE_INT_H_ -#include "dndInt.h" +#include "dmInt.h" #include "mnode.h" diff --git a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h index 2bf2509b07..c0ed6599bd 100644 --- a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h +++ b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_QNODE_INT_H_ #define _TD_DND_QNODE_INT_H_ -#include "dndInt.h" +#include "dmInt.h" #include "qnode.h" diff --git a/source/dnode/mgmt/mgmt_snode/inc/smInt.h b/source/dnode/mgmt/mgmt_snode/inc/smInt.h index 697477ef42..5045f21272 100644 --- a/source/dnode/mgmt/mgmt_snode/inc/smInt.h +++ b/source/dnode/mgmt/mgmt_snode/inc/smInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_SNODE_INT_H_ #define _TD_DND_SNODE_INT_H_ -#include "dndInt.h" +#include "dmInt.h" #include "snode.h" diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index 00cd0e2b86..ab8328d038 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_VNODES_INT_H_ #define _TD_DND_VNODES_INT_H_ -#include "dndInt.h" +#include "dmInt.h" #include "sync.h" #include "vnode.h" From 318d774ba986f18922e0c4768af3de3381e3f1fe Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Apr 2022 14:00:56 +0800 Subject: [PATCH 09/19] refact(cluster): node mgmt --- include/common/tmsg.h | 1 + include/dnode/mgmt/dnode.h | 12 +- source/common/src/tmsg.c | 2 + source/dnode/mgmt/exe/dmMain.c | 84 ++++---- source/dnode/mgmt/implement/inc/dmImp.h | 76 ++++--- source/dnode/mgmt/implement/src/dmEps.c | 104 +++++----- source/dnode/mgmt/implement/src/dmExec.c | 88 ++++---- source/dnode/mgmt/implement/src/dmHandle.c | 191 ++++++++---------- source/dnode/mgmt/implement/src/dmMonitor.c | 40 ++-- source/dnode/mgmt/implement/src/dmObj.c | 37 ++-- source/dnode/mgmt/implement/src/dmTransport.c | 130 ++++++------ source/dnode/mgmt/implement/src/dmWorker.c | 76 ++++--- source/dnode/mgmt/interface/inc/dmDef.h | 11 +- source/dnode/mgmt/interface/inc/dmInt.h | 50 ++--- source/dnode/mgmt/interface/inc/dmLog.h | 6 +- source/dnode/mgmt/interface/src/dmEnv.c | 4 +- source/dnode/mgmt/interface/src/dmFile.c | 21 +- source/dnode/mgmt/interface/src/dmInt.c | 36 ++-- source/dnode/mgmt/mgmt_bnode/src/bmHandle.c | 8 +- source/dnode/mgmt/mgmt_bnode/src/bmInt.c | 6 +- source/dnode/mgmt/mgmt_mnode/src/mmHandle.c | 174 ++++++++-------- source/dnode/mgmt/mgmt_qnode/src/qmHandle.c | 26 +-- source/dnode/mgmt/mgmt_qnode/src/qmInt.c | 6 +- source/dnode/mgmt/mgmt_snode/src/smHandle.c | 12 +- source/dnode/mgmt/mgmt_snode/src/smInt.c | 6 +- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 96 ++++----- source/dnode/mgmt/mgmt_vnode/src/vmInt.c | 2 +- source/dnode/mgmt/test/sut/src/server.cpp | 8 +- source/dnode/mgmt/test/sut/src/sut.cpp | 4 +- 29 files changed, 650 insertions(+), 667 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 7839754735..7a4625289b 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -759,6 +759,7 @@ typedef struct { int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); +void tFreeSStatusReq(SStatusReq* pReq); typedef struct { int32_t dnodeId; diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index 576b44e14b..352f6d5b53 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -30,12 +30,12 @@ typedef struct SDnode SDnode; * * @return int32_t 0 for success and -1 for failure */ -int32_t dndInit(); +int32_t dmInit(); /** * @brief Clear the environment */ -void dndCleanup(); +void dmCleanup(); /* ------------------------ SDnode ----------------------- */ typedef struct { @@ -59,21 +59,21 @@ typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; * @param pOption Option of the dnode. * @return SDnode* The dnode object. */ -SDnode *dndCreate(const SDnodeOpt *pOption); +SDnode *dmCreate(const SDnodeOpt *pOption); /** * @brief Stop and cleanup the dnode. * * @param pDnode The dnode object to close. */ -void dndClose(SDnode *pDnode); +void dmClose(SDnode *pDnode); /** * @brief Run dnode until specific event is receive. * * @param pDnode The dnode object to run. */ -int32_t dndRun(SDnode *pDnode); +int32_t dmRun(SDnode *pDnode); /** * @brief Handle event in the dnode. @@ -81,7 +81,7 @@ int32_t dndRun(SDnode *pDnode); * @param pDnode The dnode object to close. * @param event The event to handle. */ -void dndSetEvent(SDnode *pDnode, EDndEvent event); +void dmSetEvent(SDnode *pDnode, EDndEvent event); #ifdef __cplusplus } diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index a9ecdd659f..83f8646364 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -958,6 +958,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { return 0; } +void tFreeSStatusReq(SStatusReq *pReq) { taosArrayDestroy(pReq->pVloads); } + int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 9213090a4e..12de4103a4 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -18,32 +18,32 @@ #include "tconfig.h" static struct { - bool dumpConfig; - bool generateGrant; - bool printAuth; - bool printVersion; - char envFile[PATH_MAX]; - char apolloUrl[PATH_MAX]; - SArray *pArgs; // SConfigPair - SDnode *pDnode; + bool dumpConfig; + bool generateGrant; + bool printAuth; + bool printVersion; + char envFile[PATH_MAX]; + char apolloUrl[PATH_MAX]; + SArray *pArgs; // SConfigPair + SDnode *pDnode; EDndNodeType ntype; } global = {0}; -static void dndStopDnode(int signum, void *info, void *ctx) { +static void dmStopDnode(int signum, void *info, void *ctx) { SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); if (pDnode != NULL) { - dndSetEvent(pDnode, DND_EVENT_STOP); + dmSetEvent(pDnode, DND_EVENT_STOP); } } -static void dndSetSignalHandle() { - taosSetSignal(SIGTERM, dndStopDnode); - taosSetSignal(SIGHUP, dndStopDnode); - taosSetSignal(SIGINT, dndStopDnode); - taosSetSignal(SIGTSTP, dndStopDnode); - taosSetSignal(SIGABRT, dndStopDnode); - taosSetSignal(SIGBREAK, dndStopDnode); - taosSetSignal(SIGQUIT, dndStopDnode); +static void dmSetSignalHandle() { + taosSetSignal(SIGTERM, dmStopDnode); + taosSetSignal(SIGHUP, dmStopDnode); + taosSetSignal(SIGINT, dmStopDnode); + taosSetSignal(SIGTSTP, dmStopDnode); + taosSetSignal(SIGABRT, dmStopDnode); + taosSetSignal(SIGBREAK, dmStopDnode); + taosSetSignal(SIGQUIT, dmStopDnode); if (!tsMultiProcess) { } else if (global.ntype == NODE_BEGIN || global.ntype == NODE_END) { @@ -53,7 +53,7 @@ static void dndSetSignalHandle() { } } -static int32_t dndParseArgs(int32_t argc, char const *argv[]) { +static int32_t dmParseArgs(int32_t argc, char const *argv[]) { for (int32_t i = 1; i < argc; ++i) { if (strcmp(argv[i], "-c") == 0) { if (i < argc - 1) { @@ -89,12 +89,12 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { return 0; } -static void dndGenerateGrant() { +static void dmGenerateGrant() { // grantParseParameter(); printf("this feature is not implemented yet\n"); } -static void dndPrintVersion() { +static void dmPrintVersion() { #ifdef TD_ENTERPRISE char *releaseName = "enterprise"; #else @@ -105,12 +105,12 @@ static void dndPrintVersion() { printf("buildInfo: %s\n", buildinfo); } -static void dndDumpCfg() { +static void dmDumpCfg() { SConfig *pCfg = taosGetCfg(); cfgDumpCfg(pCfg, 0, 1); } -static SDnodeOpt dndGetOpt() { +static SDnodeOpt dmGetOpt() { SConfig *pCfg = taosGetCfg(); SDnodeOpt option = {0}; @@ -127,43 +127,43 @@ static SDnodeOpt dndGetOpt() { return option; } -static int32_t dndInitLog() { +static int32_t dmInitLog() { char logName[12] = {0}; - snprintf(logName, sizeof(logName), "%slog", dndLogName(global.ntype)); + snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype)); return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); } -static void dndSetProcInfo(int32_t argc, char **argv) { +static void dmSetProcInfo(int32_t argc, char **argv) { taosSetProcPath(argc, argv); if (global.ntype != NODE_BEGIN && global.ntype != NODE_END) { - const char *name = dndProcName(global.ntype); + const char *name = dmProcName(global.ntype); taosSetProcName(argc, argv, name); } } -static int32_t dndRunDnode() { - if (dndInit() != 0) { +static int32_t dmRunDnode() { + if (dmInit() != 0) { dError("failed to init environment since %s", terrstr()); return -1; } - SDnodeOpt option = dndGetOpt(); - SDnode *pDnode = dndCreate(&option); + SDnodeOpt option = dmGetOpt(); + SDnode *pDnode = dmCreate(&option); if (pDnode == NULL) { dError("failed to to create dnode since %s", terrstr()); return -1; } else { global.pDnode = pDnode; - dndSetSignalHandle(); + dmSetSignalHandle(); } dInfo("start the service"); - int32_t code = dndRun(pDnode); + int32_t code = dmRun(pDnode); dInfo("start shutting down the service"); global.pDnode = NULL; - dndClose(pDnode); - dndCleanup(); + dmClose(pDnode); + dmCleanup(); taosCloseLog(); taosCleanupCfg(); return code; @@ -175,22 +175,22 @@ int main(int argc, char const *argv[]) { return -1; } - if (dndParseArgs(argc, argv) != 0) { + if (dmParseArgs(argc, argv) != 0) { printf("failed to start since parse args error\n"); return -1; } if (global.generateGrant) { - dndGenerateGrant(); + dmGenerateGrant(); return 0; } if (global.printVersion) { - dndPrintVersion(); + dmPrintVersion(); return 0; } - if (dndInitLog() != 0) { + if (dmInitLog() != 0) { printf("failed to start since init log error\n"); return -1; } @@ -201,12 +201,12 @@ int main(int argc, char const *argv[]) { } if (global.dumpConfig) { - dndDumpCfg(); + dmDumpCfg(); taosCleanupCfg(); taosCloseLog(); return 0; } - dndSetProcInfo(argc, (char **)argv); - return dndRunDnode(); + dmSetProcInfo(argc, (char **)argv); + return dmRunDnode(); } diff --git a/source/dnode/mgmt/implement/inc/dmImp.h b/source/dnode/mgmt/implement/inc/dmImp.h index d001c7be98..61dd7800b1 100644 --- a/source/dnode/mgmt/implement/inc/dmImp.h +++ b/source/dnode/mgmt/implement/inc/dmImp.h @@ -22,25 +22,51 @@ extern "C" { #endif -int32_t dndOpenNode(SMgmtWrapper *pWrapper); -void dndCloseNode(SMgmtWrapper *pWrapper); +int32_t dmOpenNode(SMgmtWrapper *pWrapper); +void dmCloseNode(SMgmtWrapper *pWrapper); -// dndTransport.c +// dmTransport.c int32_t dmInitTrans(SDnode *pDnode); -void dndCleanupTrans(SDnode *pDnode); -SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); -int32_t dndInitMsgHandle(SDnode *pDnode); -int32_t dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pReq); -void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); +void dmCleanupTrans(SDnode *pDnode); +SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper); +int32_t dmInitMsgHandle(SDnode *pDnode); +void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp); -// mgmt +// dmEps.c +int32_t dmReadEps(SDnode *pDnode); +int32_t dmWriteEps(SDnode *pDnode); +void dmUpdateEps(SDnode *pDnode, SArray *pDnodeEps); + +// dmHandle.c +void dmSendStatusReq(SDnode *pDnode); +int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg); +int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg); + +// dmMonitor.c +void dmGetVnodeLoads(SDnode *pDnode, SMonVloadInfo *pInfo); +void dmSendMonitorReport(SDnode *pDnode); + +// dmWorker.c +int32_t dmStartStatusThread(SDnode *pDnode); +void dmStopStatusThread(SDnode *pDnode); +int32_t dmStartMonitorThread(SDnode *pDnode); +void dmStopMonitorThread(SDnode *pDnode); +int32_t dmStartWorker(SDnode *pDnode); +void dmStopWorker(SDnode *pDnode); +int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); + +// mgmt nodes void dmSetMgmtFp(SMgmtWrapper *pWrapper); void bmSetMgmtFp(SMgmtWrapper *pWrapper); -void qmSetMgmtFp(SMgmtWrapper *pMgmt); +void qmSetMgmtFp(SMgmtWrapper *pWrapper); void smSetMgmtFp(SMgmtWrapper *pWrapper); void vmSetMgmtFp(SMgmtWrapper *pWrapper); -void mmSetMgmtFp(SMgmtWrapper *pMgmt); +void mmSetMgmtFp(SMgmtWrapper *pWrapper); void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); @@ -49,34 +75,6 @@ void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); -// dmFile.c -int32_t dmReadFile(SDnodeData *pMgmt); -int32_t dmWriteFile(SDnodeData *pMgmt); -void dmUpdateDnodeEps(SDnodeData *pMgmt, SArray *pDnodeEps); - -// dmHandle.c -void dmSendStatusReq(SDnode *pDnode); -int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg); -int32_t dmProcessStatusRsp(SDnode *pDnode, SNodeMsg *pMsg); -int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg); -int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg); -int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); - -// dmMonitor.c -void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); -void dmSendMonitorReport(SDnode *pDnode); - -// dmWorker.c -int32_t dmStartStatusThread(SDnode *pDnode); -void dmStopStatusThread(SDnode *pDnode); -int32_t dmStartMonitorThread(SDnode *pDnode); -void dmStopMonitorThread(SDnode *pDnode); - -int32_t dmStartWorker(SDnode *pDnode); -void dmStopWorker(SDnode *pDnode); -int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); - #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/implement/src/dmEps.c b/source/dnode/mgmt/implement/src/dmEps.c index 31ebb9955f..5dcdccfa4e 100644 --- a/source/dnode/mgmt/implement/src/dmEps.c +++ b/source/dnode/mgmt/implement/src/dmEps.c @@ -16,15 +16,14 @@ #define _DEFAULT_SOURCE #include "dmImp.h" -static void dmPrintDnodes(SDnodeData *pMgmt); -static bool dmIsEpChanged(SDnodeData *pMgmt, int32_t dnodeId, const char *ep); -static void dmResetDnodes(SDnodeData *pMgmt, SArray *dnodeEps); +static void dmPrintEps(SDnode *pDnode); +static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep); +static void dmResetEps(SDnode *pDnode, SArray *dnodeEps); -void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { - SDnodeData *pMgmt = pWrapper->pMgmt; - taosRLockLatch(&pMgmt->latch); +static void dmGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { + taosRLockLatch(&pDnode->data.latch); - SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { if (pPort != NULL) { *pPort = pDnodeEp->ep.port; @@ -37,10 +36,10 @@ void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqd } } - taosRUnLockLatch(&pMgmt->latch); + taosRUnLockLatch(&pDnode->data.latch); } -int32_t dmReadFile(SDnodeData *pMgmt) { +int32_t dmReadEps(SDnode *pDnode) { int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int32_t len = 0; int32_t maxLen = 256 * 1024; @@ -48,15 +47,14 @@ int32_t dmReadFile(SDnodeData *pMgmt) { cJSON *root = NULL; char file[PATH_MAX]; TdFilePtr pFile = NULL; - SDnode *pDnode = pMgmt->pDnode; - pMgmt->dnodeEps = taosArrayInit(1, sizeof(SDnodeEp)); - if (pMgmt->dnodeEps == NULL) { + pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp)); + if (pDnode->data.dnodeEps == NULL) { dError("failed to calloc dnodeEp array since %s", strerror(errno)); goto PRASE_DNODE_OVER; } - snprintf(file, sizeof(file), "%s%sdnode.json", pMgmt->path, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->data.path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { dDebug("file %s not exist", file); @@ -146,41 +144,39 @@ int32_t dmReadFile(SDnodeData *pMgmt) { } dnodeEp.isMnode = isMnode->valueint; - taosArrayPush(pMgmt->dnodeEps, &dnodeEp); + taosArrayPush(pDnode->data.dnodeEps, &dnodeEp); } code = 0; dDebug("succcessed to read file %s", file); - dmPrintDnodes(pMgmt); + dmPrintEps(pDnode); PRASE_DNODE_OVER: if (content != NULL) taosMemoryFree(content); if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); - if (dmIsEpChanged(pMgmt, pDnode->data.dnodeId, pDnode->data.localEp)) { + if (dmIsEpChanged(pDnode, pDnode->data.dnodeId, pDnode->data.localEp)) { dError("localEp %s different with %s and need reconfigured", pDnode->data.localEp, file); return -1; } - if (taosArrayGetSize(pMgmt->dnodeEps) == 0) { + if (taosArrayGetSize(pDnode->data.dnodeEps) == 0) { SDnodeEp dnodeEp = {0}; dnodeEp.isMnode = 1; taosGetFqdnPortFromEp(pDnode->data.firstEp, &dnodeEp.ep); - taosArrayPush(pMgmt->dnodeEps, &dnodeEp); + taosArrayPush(pDnode->data.dnodeEps, &dnodeEp); } - dmResetDnodes(pMgmt, pMgmt->dnodeEps); + dmResetEps(pDnode, pDnode->data.dnodeEps); terrno = code; return code; } -int32_t dmWriteFile(SDnodeData *pMgmt) { - SDnode *pDnode = pMgmt->pDnode; - +int32_t dmWriteEps(SDnode *pDnode) { char file[PATH_MAX]; - snprintf(file, sizeof(file), "%s%sdnode.json.bak", pMgmt->path, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->data.path, TD_DIRSEP); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -199,9 +195,9 @@ int32_t dmWriteFile(SDnodeData *pMgmt) { len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->data.dropped); len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n"); - int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); + int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps); for (int32_t i = 0; i < numOfEps; ++i) { - SDnodeEp *pDnodeEp = taosArrayGet(pMgmt->dnodeEps, i); + SDnodeEp *pDnodeEp = taosArrayGet(pDnode->data.dnodeEps, i); len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pDnodeEp->id); len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pDnodeEp->ep.fqdn); len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", pDnodeEp->ep.port); @@ -220,7 +216,7 @@ int32_t dmWriteFile(SDnodeData *pMgmt) { taosMemoryFree(content); char realfile[PATH_MAX]; - snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pMgmt->path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->data.path, TD_DIRSEP); if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -228,41 +224,41 @@ int32_t dmWriteFile(SDnodeData *pMgmt) { return -1; } - pMgmt->updateTime = taosGetTimestampMs(); + pDnode->data.updateTime = taosGetTimestampMs(); dDebug("successed to write %s", realfile); return 0; } -void dmUpdateDnodeEps(SDnodeData *pMgmt, SArray *dnodeEps) { - int32_t numOfEps = taosArrayGetSize(dnodeEps); +void dmUpdateEps(SDnode *pDnode, SArray *eps) { + int32_t numOfEps = taosArrayGetSize(eps); if (numOfEps <= 0) return; - taosWLockLatch(&pMgmt->latch); + taosWLockLatch(&pDnode->data.latch); - int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); + int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps); if (numOfEps != numOfEpsOld) { - dmResetDnodes(pMgmt, dnodeEps); - dmWriteFile(pMgmt); + dmResetEps(pDnode, eps); + dmWriteEps(pDnode); } else { int32_t size = numOfEps * sizeof(SDnodeEp); - if (memcmp(pMgmt->dnodeEps->pData, dnodeEps->pData, size) != 0) { - dmResetDnodes(pMgmt, dnodeEps); - dmWriteFile(pMgmt); + if (memcmp(pDnode->data.dnodeEps->pData, eps->pData, size) != 0) { + dmResetEps(pDnode, eps); + dmWriteEps(pDnode); } } - taosWUnLockLatch(&pMgmt->latch); + taosWUnLockLatch(&pDnode->data.latch); } -static void dmResetDnodes(SDnodeData *pMgmt, SArray *dnodeEps) { - if (pMgmt->dnodeEps != dnodeEps) { - SArray *tmp = pMgmt->dnodeEps; - pMgmt->dnodeEps = taosArrayDup(dnodeEps); +static void dmResetEps(SDnode *pDnode, SArray *dnodeEps) { + if (pDnode->data.dnodeEps != dnodeEps) { + SArray *tmp = pDnode->data.dnodeEps; + pDnode->data.dnodeEps = taosArrayDup(dnodeEps); taosArrayDestroy(tmp); } - pMgmt->mnodeEpSet.inUse = 0; - pMgmt->mnodeEpSet.numOfEps = 0; + pDnode->data.mnodeEps.inUse = 0; + pDnode->data.mnodeEps.numOfEps = 0; int32_t mIndex = 0; int32_t numOfEps = (int32_t)taosArrayGetSize(dnodeEps); @@ -271,40 +267,40 @@ static void dmResetDnodes(SDnodeData *pMgmt, SArray *dnodeEps) { SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i); if (!pDnodeEp->isMnode) continue; if (mIndex >= TSDB_MAX_REPLICA) continue; - pMgmt->mnodeEpSet.numOfEps++; + pDnode->data.mnodeEps.numOfEps++; - pMgmt->mnodeEpSet.eps[mIndex] = pDnodeEp->ep; + pDnode->data.mnodeEps.eps[mIndex] = pDnodeEp->ep; mIndex++; } for (int32_t i = 0; i < numOfEps; i++) { SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i); - taosHashPut(pMgmt->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); + taosHashPut(pDnode->data.dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); } - dmPrintDnodes(pMgmt); + dmPrintEps(pDnode); } -static void dmPrintDnodes(SDnodeData *pMgmt) { - int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); +static void dmPrintEps(SDnode *pDnode) { + int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps); dDebug("print dnode ep list, num:%d", numOfEps); for (int32_t i = 0; i < numOfEps; i++) { - SDnodeEp *pEp = taosArrayGet(pMgmt->dnodeEps, i); + SDnodeEp *pEp = taosArrayGet(pDnode->data.dnodeEps, i); dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", pEp->id, pEp->ep.fqdn, pEp->ep.port, pEp->isMnode); } } -static bool dmIsEpChanged(SDnodeData *pMgmt, int32_t dnodeId, const char *ep) { +static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep) { bool changed = false; - taosRLockLatch(&pMgmt->latch); + taosRLockLatch(&pDnode->data.latch); - SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { char epstr[TSDB_EP_LEN + 1]; snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port); changed = strcmp(ep, epstr) != 0; } - taosRUnLockLatch(&pMgmt->latch); + taosRUnLockLatch(&pDnode->data.latch); return changed; } diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c index c73e79a2da..a348cdf914 100644 --- a/source/dnode/mgmt/implement/src/dmExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "dmImp.h" -static bool dndRequireNode(SMgmtWrapper *pWrapper) { +static bool dmRequireNode(SMgmtWrapper *pWrapper) { bool required = false; int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required); if (!required) { @@ -27,7 +27,7 @@ static bool dndRequireNode(SMgmtWrapper *pWrapper) { return required; } -static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { +static int32_t dmInitNodeProc(SMgmtWrapper *pWrapper) { int32_t shmsize = tsMnodeShmSize; if (pWrapper->ntype == VNODE) { shmsize = tsVnodeShmSize; @@ -50,7 +50,7 @@ static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { } dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->procShm.id, shmsize); - SProcCfg cfg = dndGenProcCfg(pWrapper); + SProcCfg cfg = dmGenProcCfg(pWrapper); cfg.isChild = false; pWrapper->procType = DND_PROC_PARENT; pWrapper->procObj = taosProcInit(&cfg); @@ -62,7 +62,7 @@ static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { return 0; } -static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) { +static int32_t dmNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) { char tstr[8] = {0}; char *args[6] = {0}; snprintf(tstr, sizeof(tstr), "%d", n); @@ -84,11 +84,11 @@ static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) { return 0; } -static int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) { +static int32_t dmRunNodeProc(SMgmtWrapper *pWrapper) { if (pWrapper->pDnode->ntype == NODE_END) { dInfo("node:%s, should be started manually", pWrapper->name); } else { - if (dndNewNodeProc(pWrapper, pWrapper->ntype) != 0) { + if (dmNewNodeProc(pWrapper, pWrapper->ntype) != 0) { return -1; } } @@ -101,7 +101,7 @@ static int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) { return 0; } -static int32_t dndOpenNodeImp(SMgmtWrapper *pWrapper) { +static int32_t dmOpenNodeImp(SMgmtWrapper *pWrapper) { if (taosMkDir(pWrapper->path) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr()); @@ -118,19 +118,19 @@ static int32_t dndOpenNodeImp(SMgmtWrapper *pWrapper) { return 0; } -int32_t dndOpenNode(SMgmtWrapper *pWrapper) { +int32_t dmOpenNode(SMgmtWrapper *pWrapper) { SDnode *pDnode = pWrapper->pDnode; if (pDnode->ptype == DND_PROC_SINGLE) { - return dndOpenNodeImp(pWrapper); + return dmOpenNodeImp(pWrapper); } else if (pDnode->ptype == DND_PROC_PARENT) { - if (dndInitNodeProc(pWrapper) != 0) return -1; - if (dndWriteShmFile(pDnode) != 0) return -1; - if (dndRunNodeProc(pWrapper) != 0) return -1; + if (dmInitNodeProc(pWrapper) != 0) return -1; + if (dmWriteShmFile(pDnode) != 0) return -1; + if (dmRunNodeProc(pWrapper) != 0) return -1; } return 0; } -static void dndCloseNodeImp(SMgmtWrapper *pWrapper) { +static void dmCloseNodeImp(SMgmtWrapper *pWrapper) { dDebug("node:%s, mgmt start to close", pWrapper->name); pWrapper->required = false; taosWLockLatch(&pWrapper->latch); @@ -151,7 +151,7 @@ static void dndCloseNodeImp(SMgmtWrapper *pWrapper) { dDebug("node:%s, mgmt has been closed", pWrapper->name); } -void dndCloseNode(SMgmtWrapper *pWrapper) { +void dmCloseNode(SMgmtWrapper *pWrapper) { if (pWrapper->pDnode->ptype == DND_PROC_PARENT) { if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); @@ -161,31 +161,31 @@ void dndCloseNode(SMgmtWrapper *pWrapper) { dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId); } } - dndCloseNodeImp(pWrapper); + dmCloseNodeImp(pWrapper); } -static void dndProcessProcHandle(void *handle) { +static void dmProcessProcHandle(void *handle) { dWarn("handle:%p, the child process dies and send an offline rsp", handle); SRpcMsg rpcMsg = {.handle = handle, .code = TSDB_CODE_NODE_OFFLINE}; rpcSendResponse(&rpcMsg); } -static int32_t dndRunInSingleProcess(SDnode *pDnode) { +static int32_t dmRunInSingleProcess(SDnode *pDnode) { dInfo("dnode run in single process"); pDnode->ptype = DND_PROC_SINGLE; for (EDndNodeType n = NODE_BEGIN; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dndRequireNode(pWrapper); + pWrapper->required = dmRequireNode(pWrapper); if (!pWrapper->required) continue; - if (dndOpenNodeImp(pWrapper) != 0) { + if (dmOpenNodeImp(pWrapper) != 0) { dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); return -1; } } - dndSetStatus(pDnode, DND_STAT_RUNNING); + dmSetStatus(pDnode, DND_STAT_RUNNING); for (EDndNodeType n = 0; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; @@ -198,11 +198,11 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { } dInfo("TDengine initialized successfully"); - dndReportStartup(pDnode, "TDengine", "initialized successfully"); + dmReportStartup(pDnode, "TDengine", "initialized successfully"); while (1) { if (pDnode->event == DND_EVENT_STOP) { dInfo("dnode is about to stop"); - dndSetStatus(pDnode, DND_STAT_STOPPED); + dmSetStatus(pDnode, DND_STAT_STOPPED); break; } taosMsleep(100); @@ -211,24 +211,24 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) { return 0; } -static int32_t dndRunInParentProcess(SDnode *pDnode) { +static int32_t dmRunInParentProcess(SDnode *pDnode) { dInfo("dnode run in parent process"); pDnode->ptype = DND_PROC_PARENT; SMgmtWrapper *pDWrapper = &pDnode->wrappers[NODE_BEGIN]; - if (dndOpenNodeImp(pDWrapper) != 0) { + if (dmOpenNodeImp(pDWrapper) != 0) { dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); return -1; } for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dndRequireNode(pWrapper); + pWrapper->required = dmRequireNode(pWrapper); if (!pWrapper->required) continue; - if (dndInitNodeProc(pWrapper) != 0) return -1; + if (dmInitNodeProc(pWrapper) != 0) return -1; } - if (dndWriteShmFile(pDnode) != 0) { + if (dmWriteShmFile(pDnode) != 0) { dError("failed to write runtime file since %s", terrstr()); return -1; } @@ -236,10 +236,10 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; if (!pWrapper->required) continue; - if (dndRunNodeProc(pWrapper) != 0) return -1; + if (dmRunNodeProc(pWrapper) != 0) return -1; } - dndSetStatus(pDnode, DND_STAT_RUNNING); + dmSetStatus(pDnode, DND_STAT_RUNNING); if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) { dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); @@ -247,12 +247,12 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { } dInfo("TDengine initialized successfully"); - dndReportStartup(pDnode, "TDengine", "initialized successfully"); + dmReportStartup(pDnode, "TDengine", "initialized successfully"); while (1) { if (pDnode->event == DND_EVENT_STOP) { dInfo("dnode is about to stop"); - dndSetStatus(pDnode, DND_STAT_STOPPED); + dmSetStatus(pDnode, DND_STAT_STOPPED); for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; @@ -276,8 +276,8 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); - taosProcCloseHandles(pWrapper->procObj, dndProcessProcHandle); - dndNewNodeProc(pWrapper, n); + taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle); + dmNewNodeProc(pWrapper, n); } } } @@ -288,12 +288,12 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { return 0; } -static int32_t dndRunInChildProcess(SDnode *pDnode) { +static int32_t dmRunInChildProcess(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; dInfo("%s run in child process", pWrapper->name); pDnode->ptype = DND_PROC_CHILD; - pWrapper->required = dndRequireNode(pWrapper); + pWrapper->required = dmRequireNode(pWrapper); if (!pWrapper->required) { dError("%s does not require startup", pWrapper->name); return -1; @@ -303,12 +303,12 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { tmsgSetDefaultMsgCb(&msgCb); pWrapper->procType = DND_PROC_CHILD; - if (dndOpenNodeImp(pWrapper) != 0) { + if (dmOpenNodeImp(pWrapper) != 0) { dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); return -1; } - SProcCfg cfg = dndGenProcCfg(pWrapper); + SProcCfg cfg = dmGenProcCfg(pWrapper); cfg.isChild = true; pWrapper->procObj = taosProcInit(&cfg); if (pWrapper->procObj == NULL) { @@ -323,7 +323,7 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { } } - dndSetStatus(pDnode, DND_STAT_RUNNING); + dmSetStatus(pDnode, DND_STAT_RUNNING); if (taosProcRun(pWrapper->procObj) != 0) { dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); @@ -331,11 +331,11 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { } dInfo("TDengine initialized successfully"); - dndReportStartup(pDnode, "TDengine", "initialized successfully"); + dmReportStartup(pDnode, "TDengine", "initialized successfully"); while (1) { if (pDnode->event == DND_EVENT_STOP) { dInfo("%s is about to stop", pWrapper->name); - dndSetStatus(pDnode, DND_STAT_STOPPED); + dmSetStatus(pDnode, DND_STAT_STOPPED); break; } taosMsleep(100); @@ -344,13 +344,13 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) { return 0; } -int32_t dndRun(SDnode *pDnode) { +int32_t dmRun(SDnode *pDnode) { if (!tsMultiProcess) { - return dndRunInSingleProcess(pDnode); + return dmRunInSingleProcess(pDnode); } else if (pDnode->ntype == NODE_BEGIN || pDnode->ntype == NODE_END) { - return dndRunInParentProcess(pDnode); + return dmRunInParentProcess(pDnode); } else { - return dndRunInChildProcess(pDnode); + return dmRunInChildProcess(pDnode); } return 0; diff --git a/source/dnode/mgmt/implement/src/dmHandle.c b/source/dnode/mgmt/implement/src/dmHandle.c index 1beb36054b..1b0abd8c09 100644 --- a/source/dnode/mgmt/implement/src/dmHandle.c +++ b/source/dnode/mgmt/implement/src/dmHandle.c @@ -16,22 +16,31 @@ #define _DEFAULT_SOURCE #include "dmImp.h" -static int32_t dmProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) { - SDnode *pDnode = pMgmt->pDnode; +static void dmUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { + if (pDnode->data.dnodeId == 0) { + dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); + taosWLockLatch(&pDnode->data.latch); + pDnode->data.dnodeId = pCfg->dnodeId; + pDnode->data.clusterId = pCfg->clusterId; + dmWriteEps(pDnode); + taosWUnLockLatch(&pDnode->data.latch); + } +} +static int32_t dmProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) { if (pRsp->code != TSDB_CODE_SUCCESS) { if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->data.dropped && pDnode->data.dnodeId > 0) { dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->data.dnodeId); pDnode->data.dropped = 1; - dmWriteFile(pMgmt); + dmWriteEps(pDnode); } } else { SStatusRsp statusRsp = {0}; - if (pRsp->pCont != NULL && pRsp->contLen != 0 && + if (pRsp->pCont != NULL && pRsp->contLen > 0 && tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) { - pMgmt->dnodeVer = statusRsp.dnodeVer; - dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg); - dmUpdateDnodeEps(pMgmt, statusRsp.pDnodeEps); + pDnode->data.dnodeVer = statusRsp.dnodeVer; + dmUpdateDnodeCfg(pDnode, &statusRsp.dnodeCfg); + dmUpdateEps(pDnode, statusRsp.pDnodeEps); } tFreeSStatusRsp(&statusRsp); } @@ -44,11 +53,11 @@ void dmSendStatusReq(SDnode *pDnode) { taosRLockLatch(&pDnode->data.latch); req.sver = tsVersion; - req.dnodeVer = pMgmt->dnodeVer; + req.dnodeVer = pDnode->data.dnodeVer; req.dnodeId = pDnode->data.dnodeId; req.clusterId = pDnode->data.clusterId; req.rebootTime = pDnode->data.rebootTime; - req.updateTime = pMgmt->updateTime; + req.updateTime = pDnode->data.updateTime; req.numOfCores = tsNumOfCores; req.numOfSupportVnodes = pDnode->data.supportVnodes; tstrncpy(req.dnodeEp, pDnode->data.localEp, TSDB_EP_LEN); @@ -62,68 +71,52 @@ void dmSendStatusReq(SDnode *pDnode) { memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); taosRUnLockLatch(&pDnode->data.latch); - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODE); - if (pWrapper != NULL) { - SMonVloadInfo info = {0}; - dmGetVnodeLoads(pWrapper, &info); - req.pVloads = info.pVloads; - dndReleaseWrapper(pWrapper); - } + SMonVloadInfo info = {0}; + dmGetVnodeLoads(pDnode, &info); + req.pVloads = info.pVloads; int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); void *pHead = rpcMallocCont(contLen); tSerializeSStatusReq(pHead, contLen, &req); - taosArrayDestroy(req.pVloads); + tFreeSStatusReq(&req); SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; - SRpcMsg rspMsg = {0}; - + SRpcMsg rpcRsp = {0}; + dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); - dmSendToMnodeRecv(pDnode, rpcMsg, &rpcRsp); + dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp); dmProcessStatusRsp(pDnode, &rpcRsp); } -static void dmUpdateDnodeCfg(SDnodeData *pMgmt, SDnodeCfg *pCfg) { - SDnode *pDnode = pMgmt->pDnode; - - if (pDnode->data.dnodeId == 0) { - dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); - taosWLockLatch(&pDnode->data.latch); - pDnode->data.dnodeId = pCfg->dnodeId; - pDnode->data.clusterId = pCfg->clusterId; - dmWriteFile(pMgmt); - taosWUnLockLatch(&pDnode->data.latch); - } -} - -int32_t dmProcessAuthRsp(SDnodeData *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg) { SRpcMsg *pRsp = &pMsg->rpcMsg; dError("auth rsp is received, but not supported yet"); return 0; } -int32_t dmProcessGrantRsp(SDnodeData *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg) { SRpcMsg *pRsp = &pMsg->rpcMsg; dError("grant rsp is received, but not supported yet"); return 0; } -int32_t dmProcessConfigReq(SDnodeData *pMgmt, SNodeMsg *pMsg) { +int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg) { SRpcMsg *pReq = &pMsg->rpcMsg; SDCfgDnodeReq *pCfg = pReq->pCont; dError("config req is received, but not supported yet"); return TSDB_CODE_OPS_NOT_SUPPORT; } -static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); +int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) { + SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype); if (pWrapper != NULL) { - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED; dError("failed to create node since %s", terrstr()); return -1; } + taosWLockLatch(&pDnode->wrapperLock); pWrapper = &pDnode->wrappers[ntype]; if (taosMkDir(pWrapper->path) != 0) { @@ -134,17 +127,20 @@ static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndNodeType ntype, SNodeM int32_t code = (*pWrapper->fp.createFp)(pWrapper, pMsg); if (code != 0) { - dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + dError("node:%s, failed to create since %s", pWrapper->name, terrstr()); } else { - dDebug("node:%s, has been opened", pWrapper->name); + dDebug("node:%s, has been created", pWrapper->name); + pWrapper->required = true; pWrapper->deployed = true; + (void)dmOpenNode(pWrapper); } + taosWUnLockLatch(&pDnode->wrapperLock); return code; } -static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); +int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) { + SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype); if (pWrapper == NULL) { terrno = TSDB_CODE_NODE_NOT_DEPLOYED; dError("failed to drop node since %s", terrstr()); @@ -152,68 +148,57 @@ static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndNodeType ntype, SNodeMsg } taosWLockLatch(&pWrapper->latch); - pWrapper->deployed = false; int32_t code = (*pWrapper->fp.dropFp)(pWrapper, pMsg); if (code != 0) { - pWrapper->deployed = true; dError("node:%s, failed to drop since %s", pWrapper->name, terrstr()); + pWrapper->required = true; + pWrapper->deployed = true; } else { - pWrapper->deployed = false; dDebug("node:%s, has been dropped", pWrapper->name); + pWrapper->required = false; + pWrapper->deployed = false; + dmCloseNode(pWrapper); } taosWUnLockLatch(&pWrapper->latch); - dndReleaseWrapper(pWrapper); - return code; + dmReleaseWrapper(pWrapper); + return 0; } -int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg) { - switch (pMsg->rpcMsg.msgType) { - case TDMT_DND_CREATE_MNODE: - return dmProcessCreateNodeMsg(pDnode, MNODE, pMsg); - case TDMT_DND_DROP_MNODE: - return dmProcessDropNodeMsg(pDnode, MNODE, pMsg); - case TDMT_DND_CREATE_QNODE: - return dmProcessCreateNodeMsg(pDnode, QNODE, pMsg); - case TDMT_DND_DROP_QNODE: - return dmProcessDropNodeMsg(pDnode, QNODE, pMsg); - case TDMT_DND_CREATE_SNODE: - return dmProcessCreateNodeMsg(pDnode, SNODE, pMsg); - case TDMT_DND_DROP_SNODE: - return dmProcessDropNodeMsg(pDnode, SNODE, pMsg); - case TDMT_DND_CREATE_BNODE: - return dmProcessCreateNodeMsg(pDnode, BNODE, pMsg); - case TDMT_DND_DROP_BNODE: - return dmProcessDropNodeMsg(pDnode, BNODE, pMsg); - default: - terrno = TSDB_CODE_MSG_NOT_PROCESSED; - return -1; - } -} - -static void dmSetMsgHandle(SMgmtWrapper *pWrapper) { +static void dmSetMgmtMsgHandle(SMgmtWrapper *pWrapper) { // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); } -static int32_t dmStart(SMgmtWrapper *pWrapper) { return dmStartStatusThread(pWrapper->pDnode); } +static int32_t dmStartMgmt(SMgmtWrapper *pWrapper) { + if (dmStartStatusThread(pWrapper->pDnode) != 0) { + return -1; + } + if (dmStartMonitorThread(pWrapper->pDnode) != 0) { + return -1; + } + return 0; +} -static void dmStop(SMgmtWrapper *pWrapper) { dmStopThread(pWrapper->pDnode); } +static void dmStopMgmt(SMgmtWrapper *pWrapper) { + dmStopMonitorThread(pWrapper->pDnode); + dmStopStatusThread(pWrapper->pDnode); +} -static int32_t dmInit(SMgmtWrapper *pWrapper) { +static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) { dInfo("dnode-data start to init"); SDnode *pDnode = pWrapper->pDnode; @@ -224,7 +209,7 @@ static int32_t dmInit(SMgmtWrapper *pWrapper) { return -1; } - if (dmReadFile(pDnode) != 0) { + if (dmReadEps(pDnode) != 0) { dError("failed to read file since %s", terrstr()); return -1; } @@ -247,40 +232,40 @@ static int32_t dmInit(SMgmtWrapper *pWrapper) { return 0; } -static void dmCleanup(SMgmtWrapper *pWrapper) { +static void dmCleanupMgmt(SMgmtWrapper *pWrapper) { dInfo("dnode-data start to clean up"); SDnode *pDnode = pWrapper->pDnode; dmStopWorker(pDnode); taosWLockLatch(&pDnode->data.latch); - if (pMgmt->dnodeEps != NULL) { - taosArrayDestroy(pMgmt->dnodeEps); - pMgmt->dnodeEps = NULL; + if (pDnode->data.dnodeEps != NULL) { + taosArrayDestroy(pDnode->data.dnodeEps); + pDnode->data.dnodeEps = NULL; } - if (pMgmt->dnodeHash != NULL) { - taosHashCleanup(pMgmt->dnodeHash); - pMgmt->dnodeHash = NULL; + if (pDnode->data.dnodeHash != NULL) { + taosHashCleanup(pDnode->data.dnodeHash); + pDnode->data.dnodeHash = NULL; } taosWUnLockLatch(&pDnode->data.latch); - dndCleanupTrans(pDnode); + dmCleanupTrans(pDnode); dInfo("dnode-data is cleaned up"); } -static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) { +static int32_t dmRequireMgmt(SMgmtWrapper *pWrapper, bool *required) { *required = true; return 0; } void dmSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; - mgmtFp.openFp = dmInit; - mgmtFp.closeFp = dmCleanup; - mgmtFp.startFp = dmStart; - mgmtFp.stopFp = dmStop; - mgmtFp.requiredFp = dmRequire; + mgmtFp.openFp = dmInitMgmt; + mgmtFp.closeFp = dmCleanupMgmt; + mgmtFp.startFp = dmStartMgmt; + mgmtFp.stopFp = dmStopMgmt; + mgmtFp.requiredFp = dmRequireMgmt; - dmSetMsgHandle(pWrapper); + dmSetMgmtMsgHandle(pWrapper); pWrapper->name = "dnode"; pWrapper->fp = mgmtFp; } diff --git a/source/dnode/mgmt/implement/src/dmMonitor.c b/source/dnode/mgmt/implement/src/dmMonitor.c index 467aab112b..00eefc01d1 100644 --- a/source/dnode/mgmt/implement/src/dmMonitor.c +++ b/source/dnode/mgmt/implement/src/dmMonitor.c @@ -37,7 +37,7 @@ static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { static void dmGetMonitorInfo(SDnode *pDnode, SMonDmInfo *pInfo) { dmGetMonitorBasicInfo(pDnode, &pInfo->basic); - dndGetMonitorSysInfo(&pInfo->sys); + dmGetMonitorSysInfo(&pInfo->sys); dmGetMonitorDnodeInfo(pDnode, &pInfo->dnode); } @@ -64,14 +64,14 @@ void dmSendMonitorReport(SDnode *pDnode) { bool getFromAPI = !tsMultiProcess; pWrapper = &pDnode->wrappers[MNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) == 0) { + if (dmMarkWrapper(pWrapper) == 0) { mmGetMonitorInfo(pWrapper, &mmInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_MM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo); } @@ -81,14 +81,14 @@ void dmSendMonitorReport(SDnode *pDnode) { pWrapper = &pDnode->wrappers[VNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) == 0) { + if (dmMarkWrapper(pWrapper) == 0) { vmGetMonitorInfo(pWrapper, &vmInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_VM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo); } @@ -98,14 +98,14 @@ void dmSendMonitorReport(SDnode *pDnode) { pWrapper = &pDnode->wrappers[QNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) == 0) { + if (dmMarkWrapper(pWrapper) == 0) { qmGetMonitorInfo(pWrapper, &qmInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_QM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo); } @@ -115,14 +115,14 @@ void dmSendMonitorReport(SDnode *pDnode) { pWrapper = &pDnode->wrappers[SNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) == 0) { + if (dmMarkWrapper(pWrapper) == 0) { smGetMonitorInfo(pWrapper, &smInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_SM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo); } @@ -132,14 +132,14 @@ void dmSendMonitorReport(SDnode *pDnode) { pWrapper = &pDnode->wrappers[BNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) == 0) { + if (dmMarkWrapper(pWrapper) == 0) { bmGetMonitorInfo(pWrapper, &bmInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_BM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo); } @@ -161,7 +161,10 @@ void dmSendMonitorReport(SDnode *pDnode) { monSendReport(); } -void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { +void dmGetVnodeLoads(SDnode *pDnode, SMonVloadInfo *pInfo) { + SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, VNODE); + if (pWrapper == NULL) return; + bool getFromAPI = !tsMultiProcess; if (getFromAPI) { vmGetVnodeLoads(pWrapper, pInfo); @@ -172,10 +175,11 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); epset.eps[0].port = tsServerPort; - dndSendRecv(pWrapper->pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonVloadInfo(rsp.pCont, rsp.contLen, pInfo); } rpcFreeCont(rsp.pCont); } + dmReleaseWrapper(pWrapper); } diff --git a/source/dnode/mgmt/implement/src/dmObj.c b/source/dnode/mgmt/implement/src/dmObj.c index 3e9877292f..eec061b26d 100644 --- a/source/dnode/mgmt/implement/src/dmObj.c +++ b/source/dnode/mgmt/implement/src/dmObj.c @@ -16,12 +16,10 @@ #define _DEFAULT_SOURCE #include "dmImp.h" - -static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { +static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->data.dnodeId = 0; pDnode->data.dropped = 0; pDnode->data.clusterId = 0; - pDnode->data.supportVnodes = pOption->numOfSupportVnodes; pDnode->data.serverPort = pOption->serverPort; pDnode->data.dataDir = strdup(pOption->dataDir); @@ -34,24 +32,25 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->ntype = pOption->ntype; pDnode->data.rebootTime = taosGetTimestampMs(); - if (pDnode->data.dataDir == NULL || pDnode->data.localEp == NULL || pDnode->data.localFqdn == NULL || pDnode->data.firstEp == NULL || - pDnode->data.secondEp == NULL) { + if (pDnode->data.dataDir == NULL || pDnode->data.localEp == NULL || pDnode->data.localFqdn == NULL || + pDnode->data.firstEp == NULL || pDnode->data.secondEp == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } if (!tsMultiProcess || pDnode->ntype == NODE_BEGIN || pDnode->ntype == NODE_END) { - pDnode->data.lockfile = dndCheckRunning(pDnode->data.dataDir); + pDnode->data.lockfile = dmCheckRunning(pDnode->data.dataDir); if (pDnode->data.lockfile == NULL) { return -1; } } taosInitRWLatch(&pDnode->data.latch); + taosInitRWLatch(&pDnode->wrapperLock); return 0; } -static void dndClearVars(SDnode *pDnode) { +static void dmClearVars(SDnode *pDnode) { for (EDndNodeType n = 0; n < NODE_END; ++n) { SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; taosMemoryFreeClear(pMgmt->path); @@ -70,7 +69,7 @@ static void dndClearVars(SDnode *pDnode) { dDebug("dnode memory is cleared, data:%p", pDnode); } -SDnode *dndCreate(const SDnodeOpt *pOption) { +SDnode *dmCreate(const SDnodeOpt *pOption) { dDebug("start to create dnode object"); int32_t code = -1; char path[PATH_MAX] = {0}; @@ -82,12 +81,12 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { goto _OVER; } - if (dndInitVars(pDnode, pOption) != 0) { + if (dmInitVars(pDnode, pOption) != 0) { dError("failed to init variables since %s", terrstr()); goto _OVER; } - dndSetStatus(pDnode, DND_STAT_INIT); + dmSetStatus(pDnode, DND_STAT_INIT); dmSetMgmtFp(&pDnode->wrappers[NODE_BEGIN]); mmSetMgmtFp(&pDnode->wrappers[MNODE]); vmSetMgmtFp(&pDnode->wrappers[VNODE]); @@ -111,12 +110,12 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { taosInitRWLatch(&pWrapper->latch); } - if (dndInitMsgHandle(pDnode) != 0) { + if (dmInitMsgHandle(pDnode) != 0) { dError("failed to init msg handles since %s", terrstr()); goto _OVER; } - if (dndReadShmFile(pDnode) != 0) { + if (dmReadShmFile(pDnode) != 0) { dError("failed to read shm file since %s", terrstr()); goto _OVER; } @@ -129,7 +128,7 @@ SDnode *dndCreate(const SDnodeOpt *pOption) { _OVER: if (code != 0 && pDnode) { - dndClearVars(pDnode); + dmClearVars(pDnode); pDnode = NULL; dError("failed to create dnode since %s", terrstr()); } @@ -137,20 +136,14 @@ _OVER: return pDnode; } -void dndClose(SDnode *pDnode) { +void dmClose(SDnode *pDnode) { if (pDnode == NULL) return; for (EDndNodeType n = 0; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - dndCloseNode(pWrapper); + dmCloseNode(pWrapper); } - dndClearVars(pDnode); + dmClearVars(pDnode); dInfo("dnode is closed, data:%p", pDnode); } - -void dndHandleEvent(SDnode *pDnode, EDndEvent event) { - if (event == DND_EVENT_STOP) { - pDnode->event = event; - } -} diff --git a/source/dnode/mgmt/implement/src/dmTransport.c b/source/dnode/mgmt/implement/src/dmTransport.c index a0251a69f5..3db856b5fa 100644 --- a/source/dnode/mgmt/implement/src/dmTransport.c +++ b/source/dnode/mgmt/implement/src/dmTransport.c @@ -20,17 +20,17 @@ #define INTERNAL_CKEY "_key" #define INTERNAL_SECRET "_pwd" -static void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { +static void dmGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { taosRLockLatch(&pDnode->data.latch); - *pEpSet = pDnode->data.mnodeEpSet; + *pEpSet = pDnode->data.mnodeEps; taosRUnLockLatch(&pDnode->data.latch); } -static void dndSetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { +static void dmSetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); taosWLockLatch(&pDnode->data.latch); - pDnode->data.mnodeEpSet = *pEpSet; + pDnode->data.mnodeEps = *pEpSet; for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); } @@ -38,7 +38,7 @@ static void dndSetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { taosWUnLockLatch(&pDnode->data.latch); } -static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { +static inline NodeMsgFp dmGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; if (msgFp == NULL) { terrno = TSDB_CODE_MSG_NOT_PROCESSED; @@ -47,7 +47,7 @@ static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { return msgFp; } -static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { +static inline int32_t dmBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { SRpcConnInfo connInfo = {0}; if ((pRpc->msgType & 1U) && rpcGetConnInfo(pRpc->handle, &connInfo) != 0) { terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; @@ -62,20 +62,20 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { return 0; } -static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { +static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { int32_t code = -1; SNodeMsg *pMsg = NULL; NodeMsgFp msgFp = NULL; uint16_t msgType = pRpc->msgType; if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) { - dndSetMnodeEpSet(pWrapper->pDnode, pEpSet); + dmSetMnodeEpSet(pWrapper->pDnode, pEpSet); } - if (dndMarkWrapper(pWrapper) != 0) goto _OVER; - if ((msgFp = dndGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER; + if (dmMarkWrapper(pWrapper) != 0) goto _OVER; + if ((msgFp = dmGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER; if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER; - if (dndBuildMsg(pMsg, pRpc) != 0) goto _OVER; + if (dmBuildMsg(pMsg, pRpc) != 0) goto _OVER; if (pWrapper->procType == DND_PROC_SINGLE) { dTrace("msg:%p, is created, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); @@ -114,10 +114,10 @@ _OVER: rpcFreeCont(pRpc->pCont); } - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } -static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { +static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { SDnodeTrans *pTrans = &pDnode->trans; tmsg_t msgType = pMsg->msgType; bool isReq = msgType & 1u; @@ -126,11 +126,11 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { if (msgType == TDMT_DND_NETWORK_TEST) { dTrace("network test req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle); - dndProcessStartupReq(pDnode, pMsg); + dmProcessStartupReq(pDnode, pMsg); return; } - if (dndGetStatus(pDnode) != DND_STAT_RUNNING) { + if (pDnode->status != DND_STAT_RUNNING) { dError("msg:%s ignored since dnode not running, handle:%p app:%p", TMSG_INFO(msgType), pMsg->handle, pMsg->ahandle); if (isReq) { SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY, .ahandle = pMsg->ahandle}; @@ -168,10 +168,10 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { } dTrace("msg:%s will be processed by %s, app:%p", TMSG_INFO(msgType), pWrapper->name, pMsg->ahandle); - dndProcessRpcMsg(pWrapper, pMsg, pEpSet); + dmProcessRpcMsg(pWrapper, pMsg, pEpSet); } -int32_t dndInitMsgHandle(SDnode *pDnode) { +int32_t dmInitMsgHandle(SDnode *pDnode) { SDnodeTrans *pTrans = &pDnode->trans; for (EDndNodeType n = NODE_BEGIN + 1; n < NODE_END; ++n) { @@ -208,7 +208,7 @@ int32_t dndInitMsgHandle(SDnode *pDnode) { return 0; } -static inline int32_t dndSendRpcReq(SDnode *pDnode, const SEpSet *pEpSet, SRpcMsg *pReq) { +static inline int32_t dmSendRpcReq(SDnode *pDnode, const SEpSet *pEpSet, SRpcMsg *pReq) { if (pDnode->trans.clientRpc == NULL) { terrno = TSDB_CODE_NODE_OFFLINE; return -1; @@ -218,9 +218,9 @@ static inline int32_t dndSendRpcReq(SDnode *pDnode, const SEpSet *pEpSet, SRpcMs return 0; } -static void dndSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) { +static void dmSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) { SEpSet epSet = {0}; - dndGetMnodeEpSet(pDnode, &epSet); + dmGetMnodeEpSet(pDnode, &epSet); dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse); for (int32_t i = 0; i < epSet.numOfEps; ++i) { @@ -235,39 +235,33 @@ static void dndSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) { rpcSendRedirectRsp(pReq->handle, &epSet); } -static inline void dndSendRpcRsp(SDnode *pDnode, const SRpcMsg *pRsp) { +static inline void dmSendRpcRsp(SDnode *pDnode, const SRpcMsg *pRsp) { if (pRsp->code == TSDB_CODE_NODE_REDIRECT) { - dndSendRpcRedirectRsp(pDnode, pRsp); + dmSendRpcRedirectRsp(pDnode, pRsp); } else { rpcSendResponse(pRsp); } } -void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) { +void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) { rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp); } -int32_t dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pReq) { - SEpSet epSet = {0}; - dndGetMnodeEpSet(pDnode, &epSet); - return dndSendRpcReq(pDnode, &epSet, pReq); -} - void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) { SEpSet epSet = {0}; - dndGetMnodeEpSet(pDnode, &epSet); + dmGetMnodeEpSet(pDnode, &epSet); rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp); } -static inline int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { - if (dndGetStatus(pWrapper->pDnode) != DND_STAT_RUNNING) { +static inline int32_t dmSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { + if (pWrapper->pDnode->status != DND_STAT_RUNNING) { terrno = TSDB_CODE_NODE_OFFLINE; dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle); return -1; } if (pWrapper->procType != DND_PROC_CHILD) { - return dndSendRpcReq(pWrapper->pDnode, pEpSet, pReq); + return dmSendRpcReq(pWrapper->pDnode, pEpSet, pReq); } else { char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet)); if (pHead == NULL) { @@ -284,15 +278,15 @@ static inline int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, S } } -static inline void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { +static inline void dmSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { if (pWrapper->procType != DND_PROC_CHILD) { - dndSendRpcRsp(pWrapper->pDnode, pRsp); + dmSendRpcRsp(pWrapper->pDnode, pRsp); } else { taosProcPutToParentQ(pWrapper->procObj, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_FUNC_RSP); } } -static inline void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { +static inline void dmRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { if (pWrapper->procType != DND_PROC_CHILD) { rpcRegisterBrokenLinkArg(pMsg); } else { @@ -300,7 +294,7 @@ static inline void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMs } } -static inline void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) { +static inline void dmReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) { if (pWrapper->procType != DND_PROC_CHILD) { rpcReleaseHandle(handle, type); } else { @@ -309,8 +303,8 @@ static inline void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t } } -static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, - EProcFuncType ftype) { +static void dmConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + EProcFuncType ftype) { SRpcMsg *pRpc = &pMsg->rpcMsg; pRpc->pCont = pCont; dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle); @@ -322,7 +316,7 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); if (pRpc->msgType & 1U) { SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; - dndSendRsp(pWrapper, &rsp); + dmSendRsp(pWrapper, &rsp); } dTrace("msg:%p, is freed", pMsg); @@ -331,8 +325,8 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t } } -static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, - EProcFuncType ftype) { +static void dmConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + EProcFuncType ftype) { pMsg->pCont = pCont; dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle, pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle); @@ -347,11 +341,11 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t rpcFreeCont(pCont); break; case PROC_FUNC_REQ: - dndSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); + dmSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); break; case PROC_FUNC_RSP: taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); - dndSendRpcRsp(pWrapper->pDnode, pMsg); + dmSendRpcRsp(pWrapper->pDnode, pMsg); break; default: break; @@ -359,13 +353,13 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t taosMemoryFree(pMsg); } -SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) { - SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, +SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper) { + SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dmConsumeChildQueue, .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, .childFreeHeadFp = (ProcFreeFp)taosFreeQitem, .childMallocBodyFp = (ProcMallocFp)rpcMallocCont, .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, + .parentConsumeFp = (ProcConsumeFp)dmConsumeParentQueue, .parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, @@ -376,13 +370,13 @@ SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) { return cfg; } -static int32_t dndInitClient(SDnode *pDnode) { +static int32_t dmInitClient(SDnode *pDnode) { SDnodeTrans *pTrans = &pDnode->trans; SRpcInit rpcInit = {0}; rpcInit.label = "DND"; rpcInit.numOfThreads = 1; - rpcInit.cfp = (RpcCfp)dndProcessMsg; + rpcInit.cfp = (RpcCfp)dmProcessMsg; rpcInit.sessions = 1024; rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.idleTime = tsShellActivityTimer * 1000; @@ -405,7 +399,7 @@ static int32_t dndInitClient(SDnode *pDnode) { return 0; } -static void dndCleanupClient(SDnode *pDnode) { +static void dmCleanupClient(SDnode *pDnode) { SDnodeTrans *pTrans = &pDnode->trans; if (pTrans->clientRpc) { rpcClose(pTrans->clientRpc); @@ -414,8 +408,8 @@ static void dndCleanupClient(SDnode *pDnode) { } } -static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, - char *ckey) { +static inline int32_t dmGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, + char *ckey) { int32_t code = 0; char pass[TSDB_PASSWORD_LEN + 1] = {0}; @@ -437,9 +431,9 @@ static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi, return code; } -static inline int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, - char *ckey) { - if (dndGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) { +static inline int32_t dmRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, + char *ckey) { + if (dmGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) { dTrace("user:%s, get auth from mnode, spi:%d encrypt:%d", user, *spi, *encrypt); return 0; } @@ -473,18 +467,18 @@ static inline int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char * return rpcRsp.code; } -static int32_t dndInitServer(SDnode *pDnode) { +static int32_t dmInitServer(SDnode *pDnode) { SDnodeTrans *pTrans = &pDnode->trans; SRpcInit rpcInit = {0}; rpcInit.localPort = pDnode->data.serverPort; rpcInit.label = "DND"; rpcInit.numOfThreads = tsNumOfRpcThreads; - rpcInit.cfp = (RpcCfp)dndProcessMsg; + rpcInit.cfp = (RpcCfp)dmProcessMsg; rpcInit.sessions = tsMaxShellConns; rpcInit.connType = TAOS_CONN_SERVER; rpcInit.idleTime = tsShellActivityTimer * 1000; - rpcInit.afp = (RpcAfp)dndRetrieveUserAuthInfo; + rpcInit.afp = (RpcAfp)dmRetrieveUserAuthInfo; rpcInit.parent = pDnode; pTrans->serverRpc = rpcOpen(&rpcInit); @@ -497,7 +491,7 @@ static int32_t dndInitServer(SDnode *pDnode) { return 0; } -static void dndCleanupServer(SDnode *pDnode) { +static void dmCleanupServer(SDnode *pDnode) { SDnodeTrans *pTrans = &pDnode->trans; if (pTrans->serverRpc) { rpcClose(pTrans->serverRpc); @@ -507,21 +501,21 @@ static void dndCleanupServer(SDnode *pDnode) { } int32_t dmInitTrans(SDnode *pDnode) { - if (dndInitServer(pDnode) != 0) return -1; - if (dndInitClient(pDnode) != 0) return -1; + if (dmInitServer(pDnode) != 0) return -1; + if (dmInitClient(pDnode) != 0) return -1; SMsgCb msgCb = { - .sendReqFp = dndSendReq, - .sendRspFp = dndSendRsp, - .registerBrokenLinkArgFp = dndRegisterBrokenLinkArg, - .releaseHandleFp = dndReleaseHandle, + .sendReqFp = dmSendReq, + .sendRspFp = dmSendRsp, + .registerBrokenLinkArgFp = dmRegisterBrokenLinkArg, + .releaseHandleFp = dmReleaseHandle, }; pDnode->data.msgCb = msgCb; return 0; } -void dndCleanupTrans(SDnode *pDnode) { - dndCleanupServer(pDnode); - dndCleanupClient(pDnode); +void dmCleanupTrans(SDnode *pDnode) { + dmCleanupServer(pDnode); + dmCleanupClient(pDnode); } diff --git a/source/dnode/mgmt/implement/src/dmWorker.c b/source/dnode/mgmt/implement/src/dmWorker.c index 9c32d0bda6..6ffb8e1a23 100644 --- a/source/dnode/mgmt/implement/src/dmWorker.c +++ b/source/dnode/mgmt/implement/src/dmWorker.c @@ -33,7 +33,7 @@ static void *dmStatusThreadFp(void *param) { int64_t curTime = taosGetTimestampMs(); float interval = (curTime - lastTime) / 1000.0f; if (interval >= tsStatusInterval) { - dmSendStatusReq(pMgmt); + dmSendStatusReq(pDnode); lastTime = curTime; } } @@ -67,8 +67,8 @@ static void *dmMonitorThreadFp(void *param) { } int32_t dmStartStatusThread(SDnode *pDnode) { - pDnode->statusThreadId = taosCreateThread(dmStatusThreadFp, pDnode); - if (pDnode->statusThreadId == NULL) { + pDnode->data.statusThreadId = taosCreateThread(dmStatusThreadFp, pDnode); + if (pDnode->data.statusThreadId == NULL) { dError("failed to init dnode status thread"); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -78,15 +78,15 @@ int32_t dmStartStatusThread(SDnode *pDnode) { } void dmStopStatusThread(SDnode *pDnode) { - if (pDnode->statusThreadId != NULL) { - taosDestoryThread(pDnode->statusThreadId); - pDnode->statusThreadId = NULL; + if (pDnode->data.statusThreadId != NULL) { + taosDestoryThread(pDnode->data.statusThreadId); + pDnode->data.statusThreadId = NULL; } } int32_t dmStartMonitorThread(SDnode *pDnode) { - pDnode->monitorThreadId = taosCreateThread(dmMonitorThreadFp, pDnode); - if (pDnode->monitorThreadId == NULL) { + pDnode->data.monitorThreadId = taosCreateThread(dmMonitorThreadFp, pDnode); + if (pDnode->data.monitorThreadId == NULL) { dError("failed to init dnode monitor thread"); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -96,9 +96,9 @@ int32_t dmStartMonitorThread(SDnode *pDnode) { } void dmStopMonitorThread(SDnode *pDnode) { - if (pMgmt->monitorThreadId != NULL) { - taosDestoryThread(pMgmt->monitorThreadId); - pMgmt->monitorThreadId = NULL; + if (pDnode->data.monitorThreadId != NULL) { + taosDestoryThread(pDnode->data.monitorThreadId); + pDnode->data.monitorThreadId = NULL; } } @@ -110,16 +110,39 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { switch (pRpc->msgType) { case TDMT_DND_CONFIG_DNODE: - code = dmProcessConfigReq(pMgmt, pMsg); + code = dmProcessConfigReq(pDnode, pMsg); break; case TDMT_MND_AUTH_RSP: - code = dmProcessAuthRsp(pMgmt, pMsg); + code = dmProcessAuthRsp(pDnode, pMsg); break; case TDMT_MND_GRANT_RSP: - code = dmProcessGrantRsp(pMgmt, pMsg); + code = dmProcessGrantRsp(pDnode, pMsg); + break; + case TDMT_DND_CREATE_MNODE: + code = dmProcessCreateNodeReq(pDnode, MNODE, pMsg); + break; + case TDMT_DND_DROP_MNODE: + code = dmProcessDropNodeReq(pDnode, MNODE, pMsg); + break; + case TDMT_DND_CREATE_QNODE: + code = dmProcessCreateNodeReq(pDnode, QNODE, pMsg); + break; + case TDMT_DND_DROP_QNODE: + code = dmProcessDropNodeReq(pDnode, QNODE, pMsg); + break; + case TDMT_DND_CREATE_SNODE: + code = dmProcessCreateNodeReq(pDnode, SNODE, pMsg); + break; + case TDMT_DND_DROP_SNODE: + code = dmProcessDropNodeReq(pDnode, SNODE, pMsg); + break; + case TDMT_DND_CREATE_BNODE: + code = dmProcessCreateNodeReq(pDnode, BNODE, pMsg); + break; + case TDMT_DND_DROP_BNODE: + code = dmProcessDropNodeReq(pDnode, BNODE, pMsg); break; default: - code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg); break; } @@ -134,9 +157,9 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { taosFreeQitem(pMsg); } -int32_t dmStartWorker(SDnodeData *pMgmt) { - SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessMgmtQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) { +int32_t dmStartWorker(SDnode *pDnode) { + SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessMgmtQueue, .param = pDnode}; + if (tSingleWorkerInit(&pDnode->data.mgmtWorker, &cfg) != 0) { dError("failed to start dnode-mgmt worker since %s", terrstr()); return -1; } @@ -145,24 +168,13 @@ int32_t dmStartWorker(SDnodeData *pMgmt) { return 0; } -void dmStopWorker(SDnodeData *pMgmt) { - tSingleWorkerCleanup(&pMgmt->mgmtWorker); +void dmStopWorker(SDnode *pDnode) { + tSingleWorkerCleanup(&pDnode->data.mgmtWorker); dDebug("dnode workers are closed"); } int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnodeData *pMgmt = pWrapper->pMgmt; - SSingleWorker *pWorker = &pMgmt->mgmtWorker; - - dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - taosWriteQitem(pWorker->queue, pMsg); - return 0; -} - -int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnodeData *pMgmt = pWrapper->pMgmt; - SSingleWorker *pWorker = &pMgmt->monitorWorker; - + SSingleWorker *pWorker = &pWrapper->pDnode->data.mgmtWorker; dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); taosWriteQitem(pWorker->queue, pMsg); return 0; diff --git a/source/dnode/mgmt/interface/inc/dmDef.h b/source/dnode/mgmt/interface/inc/dmDef.h index 26d7d42af9..09771af2f2 100644 --- a/source/dnode/mgmt/interface/inc/dmDef.h +++ b/source/dnode/mgmt/interface/inc/dmDef.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_DND_DEF_H_ -#define _TD_DND_DEF_H_ +#ifndef _TD_DM_DEF_H_ +#define _TD_DM_DEF_H_ #include "dmLog.h" @@ -110,9 +110,9 @@ typedef struct { int64_t updateTime; int64_t rebootTime; bool dropped; - SEpSet mnodeEpSet; - SHashObj *dnodeHash; + SEpSet mnodeEps; SArray *dnodeEps; + SHashObj *dnodeHash; TdThread *statusThreadId; TdThread *monitorThreadId; SRWLatch latch; @@ -140,6 +140,7 @@ typedef struct SDnode { SStartupReq startup; SDnodeTrans trans; SDnodeData data; + SRWLatch wrapperLock; SMgmtWrapper wrappers[NODE_END]; } SDnode; @@ -147,4 +148,4 @@ typedef struct SDnode { } #endif -#endif /*_TD_DND_DEF_H_*/ \ No newline at end of file +#endif /*_TD_DM_DEF_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dmInt.h b/source/dnode/mgmt/interface/inc/dmInt.h index 7b633671f8..9e8ac82195 100644 --- a/source/dnode/mgmt/interface/inc/dmInt.h +++ b/source/dnode/mgmt/interface/inc/dmInt.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_DND_INT_H_ -#define _TD_DND_INT_H_ +#ifndef _TD_DM_INT_H_ +#define _TD_DM_INT_H_ #include "dmDef.h" @@ -22,32 +22,32 @@ extern "C" { #endif -// dndInt.c -const char *dndStatName(EDndRunStatus stat); -const char *dndLogName(EDndNodeType ntype); -const char *dndProcName(EDndNodeType ntype); -const char *dndEventName(EDndEvent ev); -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType nType); -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); -void dndReleaseWrapper(SMgmtWrapper *pWrapper); -EDndRunStatus dndGetStatus(SDnode *pDnode); -void dndSetStatus(SDnode *pDnode, EDndRunStatus stat); -void dndSetEvent(SDnode *pDnode, EDndEvent event); -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); -void dndGetMonitorSysInfo(SMonSysInfo *pInfo); -SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper); +// dmInt.c +SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType); +int32_t dmMarkWrapper(SMgmtWrapper *pWrapper); +void dmReleaseWrapper(SMgmtWrapper *pWrapper); +const char *dmStatName(EDndRunStatus stat); +const char *dmLogName(EDndNodeType ntype); +const char *dmProcName(EDndNodeType ntype); +const char *dmEventName(EDndEvent ev); -// dndFile.c -int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); -int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed); -TdFilePtr dndCheckRunning(const char *dataDir); -int32_t dndReadShmFile(SDnode *pDnode); -int32_t dndWriteShmFile(SDnode *pDnode); +void dmSetStatus(SDnode *pDnode, EDndRunStatus stat); +void dmSetEvent(SDnode *pDnode, EDndEvent event); +void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); +void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); +void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); +void dmGetMonitorSysInfo(SMonSysInfo *pInfo); +SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper); + +// dmFile.c +int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); +int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed); +TdFilePtr dmCheckRunning(const char *dataDir); +int32_t dmReadShmFile(SDnode *pDnode); +int32_t dmWriteShmFile(SDnode *pDnode); #ifdef __cplusplus } #endif -#endif /*_TD_DND_INT_H_*/ \ No newline at end of file +#endif /*_TD_DM_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dmLog.h b/source/dnode/mgmt/interface/inc/dmLog.h index 78d24e0ef5..c21933fc01 100644 --- a/source/dnode/mgmt/interface/inc/dmLog.h +++ b/source/dnode/mgmt/interface/inc/dmLog.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_DND_LOG_H_ -#define _TD_DND_LOG_H_ +#ifndef _TD_DM_LOG_H_ +#define _TD_DM_LOG_H_ #include "tlog.h" @@ -33,4 +33,4 @@ extern "C" { } #endif -#endif /*_TD_DND_LOG_H_*/ \ No newline at end of file +#endif /*_TD_DM_LOG_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/src/dmEnv.c b/source/dnode/mgmt/interface/src/dmEnv.c index e7dc0e3e77..b6f309ec6f 100644 --- a/source/dnode/mgmt/interface/src/dmEnv.c +++ b/source/dnode/mgmt/interface/src/dmEnv.c @@ -19,7 +19,7 @@ static int8_t once = DND_ENV_INIT; -int32_t dndInit() { +int32_t dmInit() { dDebug("start to init dnode env"); if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) { terrno = TSDB_CODE_REPEAT_INIT; @@ -45,7 +45,7 @@ int32_t dndInit() { return 0; } -void dndCleanup() { +void dmCleanup() { dDebug("start to cleanup dnode env"); if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) { dError("dnode env is already cleaned up"); diff --git a/source/dnode/mgmt/interface/src/dmFile.c b/source/dnode/mgmt/interface/src/dmFile.c index 70dbcc009f..2bf5acc800 100644 --- a/source/dnode/mgmt/interface/src/dmFile.c +++ b/source/dnode/mgmt/interface/src/dmFile.c @@ -18,7 +18,7 @@ #define MAXLEN 1024 -int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { +int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int64_t len = 0; char content[MAXLEN + 1] = {0}; @@ -64,7 +64,7 @@ _OVER: return code; } -int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { +int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed) { int32_t code = -1; int32_t len = 0; char content[MAXLEN + 1] = {0}; @@ -117,7 +117,7 @@ _OVER: return code; } -TdFilePtr dndCheckRunning(const char *dataDir) { +TdFilePtr dmCheckRunning(const char *dataDir) { char filepath[PATH_MAX] = {0}; snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP); @@ -140,7 +140,7 @@ TdFilePtr dndCheckRunning(const char *dataDir) { return pFile; } -int32_t dndReadShmFile(SDnode *pDnode) { +int32_t dmReadShmFile(SDnode *pDnode) { int32_t code = -1; char itemName[24] = {0}; char content[MAXLEN + 1] = {0}; @@ -165,13 +165,13 @@ int32_t dndReadShmFile(SDnode *pDnode) { } for (EDndNodeType ntype = NODE_BEGIN + 1; ntype < NODE_END; ++ntype) { - snprintf(itemName, sizeof(itemName), "%s_shmid", dndProcName(ntype)); + snprintf(itemName, sizeof(itemName), "%s_shmid", dmProcName(ntype)); cJSON *shmid = cJSON_GetObjectItem(root, itemName); if (shmid && shmid->type == cJSON_Number) { pDnode->wrappers[ntype].procShm.id = shmid->valueint; } - snprintf(itemName, sizeof(itemName), "%s_shmsize", dndProcName(ntype)); + snprintf(itemName, sizeof(itemName), "%s_shmsize", dmProcName(ntype)); cJSON *shmsize = cJSON_GetObjectItem(root, itemName); if (shmsize && shmsize->type == cJSON_Number) { pDnode->wrappers[ntype].procShm.size = shmsize->valueint; @@ -207,7 +207,7 @@ _OVER: return code; } -int32_t dndWriteShmFile(SDnode *pDnode) { +int32_t dmWriteShmFile(SDnode *pDnode) { int32_t code = -1; int32_t len = 0; char content[MAXLEN + 1] = {0}; @@ -228,12 +228,11 @@ int32_t dndWriteShmFile(SDnode *pDnode) { len += snprintf(content + len, MAXLEN - len, "{\n"); for (EDndNodeType ntype = NODE_BEGIN + 1; ntype < NODE_END; ++ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndProcName(ntype), pWrapper->procShm.id); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dmProcName(ntype), pWrapper->procShm.id); if (ntype == NODE_END - 1) { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndProcName(ntype), pWrapper->procShm.size); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dmProcName(ntype), pWrapper->procShm.size); } else { - len += - snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndProcName(ntype), pWrapper->procShm.size); + len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dmProcName(ntype), pWrapper->procShm.size); } } len += snprintf(content + len, MAXLEN - len, "}\n"); diff --git a/source/dnode/mgmt/interface/src/dmInt.c b/source/dnode/mgmt/interface/src/dmInt.c index eab6c074b6..ad5b35a3f8 100644 --- a/source/dnode/mgmt/interface/src/dmInt.c +++ b/source/dnode/mgmt/interface/src/dmInt.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "dmInt.h" -const char *dndStatName(EDndRunStatus status) { +const char *dmStatName(EDndRunStatus status) { switch (status) { case DND_STAT_INIT: return "init"; @@ -29,7 +29,7 @@ const char *dndStatName(EDndRunStatus status) { } } -const char *dndLogName(EDndNodeType ntype) { +const char *dmLogName(EDndNodeType ntype) { switch (ntype) { case VNODE: return "vnode"; @@ -46,7 +46,7 @@ const char *dndLogName(EDndNodeType ntype) { } } -const char *dndProcName(EDndNodeType ntype) { +const char *dmProcName(EDndNodeType ntype) { switch (ntype) { case VNODE: return "taosv"; @@ -63,7 +63,7 @@ const char *dndProcName(EDndNodeType ntype) { } } -const char *dndEventName(EDndEvent ev) { +const char *dmEventName(EDndEvent ev) { switch (ev) { case DND_EVENT_START: return "start"; @@ -76,27 +76,25 @@ const char *dndEventName(EDndEvent ev) { } } -EDndRunStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; } - -void dndSetStatus(SDnode *pDnode, EDndRunStatus status) { +void dmSetStatus(SDnode *pDnode, EDndRunStatus status) { if (pDnode->status != status) { - dDebug("dnode status set from %s to %s", dndStatName(pDnode->status), dndStatName(status)); + dDebug("dnode status set from %s to %s", dmStatName(pDnode->status), dmStatName(status)); pDnode->status = status; } } -void dndSetEvent(SDnode *pDnode, EDndEvent event) { +void dmSetEvent(SDnode *pDnode, EDndEvent event) { if (event == DND_EVENT_STOP) { pDnode->event = event; } } -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { +void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp; pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId; } -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { +SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; SMgmtWrapper *pRetWrapper = pWrapper; @@ -113,7 +111,7 @@ SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { return pRetWrapper; } -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { +int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) { int32_t code = 0; taosRLockLatch(&pWrapper->latch); @@ -129,7 +127,7 @@ int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { return code; } -void dndReleaseWrapper(SMgmtWrapper *pWrapper) { +void dmReleaseWrapper(SMgmtWrapper *pWrapper) { if (pWrapper == NULL) return; taosRLockLatch(&pWrapper->latch); @@ -138,22 +136,22 @@ void dndReleaseWrapper(SMgmtWrapper *pWrapper) { dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount); } -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { +void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { SStartupReq *pStartup = &pDnode->startup; tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); pStartup->finished = 0; } -static void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { +static void dmGetStartup(SDnode *pDnode, SStartupReq *pStartup) { memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq)); - pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); + pStartup->finished = (pDnode->status == DND_STAT_RUNNING); } -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { +void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { dDebug("startup req is received"); SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); - dndGetStartup(pDnode, pStartup); + dmGetStartup(pDnode, pStartup); dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); SRpcMsg rpcRsp = { @@ -161,7 +159,7 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { rpcSendResponse(&rpcRsp); } -void dndGetMonitorSysInfo(SMonSysInfo *pInfo) { +void dmGetMonitorSysInfo(SMonSysInfo *pInfo) { taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system); taosGetCpuCores(&pInfo->cpu_cores); taosGetProcMemory(&pInfo->mem_engine); diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c index fef5670aa8..ac96a5fd91 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c @@ -21,7 +21,7 @@ void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo) {} int32_t bmProcessGetMonBmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonBmInfo bmInfo = {0}; bmGetMonitorInfo(pWrapper, &bmInfo); - dndGetMonitorSysInfo(&bmInfo.sys); + dmGetMonitorSysInfo(&bmInfo.sys); monGetLogs(&bmInfo.log); int32_t rspLen = tSerializeSMonBmInfo(NULL, 0, &bmInfo); @@ -58,7 +58,7 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->data.dnodeId); return -1; } else { - // return dndOpenNode(pWrapper); + // return dmOpenNode(pWrapper); return 0; } } @@ -78,11 +78,11 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to drop bnode since %s", terrstr()); return -1; } else { - // dndCloseNode(pWrapper); + // dmCloseNode(pWrapper); return bmDrop(pWrapper); } } void bmInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c index bca6e0432a..ec261d654c 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "bmInt.h" -static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } +static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); @@ -39,7 +39,7 @@ static int32_t bmOpenImp(SBnodeMgmt *pMgmt) { } bool deployed = true; - if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) { + if (dmWriteFile(pMgmt->pWrapper, deployed) != 0) { dError("failed to write bnode file since %s", terrstr()); return -1; } @@ -61,7 +61,7 @@ int32_t bmDrop(SMgmtWrapper *pWrapper) { dInfo("bnode-mgmt start to drop"); bool deployed = false; - if (dndWriteFile(pWrapper, deployed) != 0) { + if (dmWriteFile(pWrapper, deployed) != 0) { dError("failed to drop bnode since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index d98cadb295..5e277b6ed2 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -24,7 +24,7 @@ void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonMmInfo mmInfo = {0}; mmGetMonitorInfo(pWrapper, &mmInfo); - dndGetMonitorSysInfo(&mmInfo.sys); + dmGetMonitorSysInfo(&mmInfo.sys); monGetLogs(&mmInfo.log); int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); @@ -80,7 +80,7 @@ int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to drop mnode since %s", terrstr()); return -1; } else { - // dndCloseNode(pWrapper); + // dmCloseNode(pWrapper); return mmDrop(pWrapper); } } @@ -105,96 +105,96 @@ int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { } void mmInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE); // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SHOW, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SHOW_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_INDEX, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SHOW, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SHOW_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_INDEX, mmProcessReadMsg, DEFAULT_HANDLE); // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE); } diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c index 935c6b2093..209c0b3f6c 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c @@ -21,7 +21,7 @@ void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo) {} int32_t qmProcessGetMonQmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonQmInfo qmInfo = {0}; qmGetMonitorInfo(pWrapper, &qmInfo); - dndGetMonitorSysInfo(&qmInfo.sys); + dmGetMonitorSysInfo(&qmInfo.sys); monGetLogs(&qmInfo.log); int32_t rspLen = tSerializeSMonQmInfo(NULL, 0, &qmInfo); @@ -58,7 +58,7 @@ int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to create qnode since %s", terrstr()); return -1; } else { - // return dndOpenNode(pWrapper); + // return dmOpenNode(pWrapper); return 0; } } @@ -78,23 +78,23 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to drop qnode since %s", terrstr()); return -1; } else { - // dndCloseNode(pWrapper); + // dmCloseNode(pWrapper); return qmDrop(pWrapper); } } void qmInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE); // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, qmProcessFetchMsg, QNODE_HANDLE); } diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c index d211faaa35..76c4f2af0d 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "qmInt.h" -static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } +static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); @@ -42,7 +42,7 @@ static int32_t qmOpenImp(SQnodeMgmt *pMgmt) { } bool deployed = true; - if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) { + if (dmWriteFile(pMgmt->pWrapper, deployed) != 0) { dError("failed to write qnode file since %s", terrstr()); return -1; } @@ -64,7 +64,7 @@ int32_t qmDrop(SMgmtWrapper *pWrapper) { dInfo("qnode-mgmt start to drop"); bool deployed = false; - if (dndWriteFile(pWrapper, deployed) != 0) { + if (dmWriteFile(pWrapper, deployed) != 0) { dError("failed to drop qnode since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c index cd8153fd60..4c0e0aef8d 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -21,7 +21,7 @@ void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo) {} int32_t smProcessGetMonSmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonSmInfo smInfo = {0}; smGetMonitorInfo(pWrapper, &smInfo); - dndGetMonitorSysInfo(&smInfo.sys); + dmGetMonitorSysInfo(&smInfo.sys); monGetLogs(&smInfo.log); int32_t rspLen = tSerializeSMonSmInfo(NULL, 0, &smInfo); @@ -58,7 +58,7 @@ int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { dError("failed to create snode since %s", terrstr()); return -1; } else { - // return dndOpenNode(pWrapper); + // return dmOpenNode(pWrapper); return 0; } } @@ -79,14 +79,14 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } else { return smDrop(pWrapper); - // return dndCloseNode(pWrapper); + // return dmCloseNode(pWrapper); } } void smInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, smProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, smProcessMonitorMsg, DEFAULT_HANDLE); // Requests handled by SNODE - dndSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/mgmt_snode/src/smInt.c b/source/dnode/mgmt/mgmt_snode/src/smInt.c index 7d3bfd6ab2..911c1b6f70 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smInt.c +++ b/source/dnode/mgmt/mgmt_snode/src/smInt.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "smInt.h" -static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } +static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); @@ -39,7 +39,7 @@ static int32_t smOpenImp(SSnodeMgmt *pMgmt) { } bool deployed = true; - if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) { + if (dmWriteFile(pMgmt->pWrapper, deployed) != 0) { dError("failed to write snode file since %s", terrstr()); return -1; } @@ -61,7 +61,7 @@ int32_t smDrop(SMgmtWrapper *pWrapper) { dInfo("snode-mgmt start to drop"); bool deployed = false; - if (dndWriteFile(pWrapper, deployed) != 0) { + if (dmWriteFile(pWrapper, deployed) != 0) { dError("failed to drop snode since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 813bc9c5f7..dfe79c2dde 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -36,7 +36,7 @@ void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo) { int32_t vmProcessGetMonVmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonVmInfo vmInfo = {0}; vmGetMonitorInfo(pWrapper, &vmInfo); - dndGetMonitorSysInfo(&vmInfo.sys); + dmGetMonitorSysInfo(&vmInfo.sys); monGetLogs(&vmInfo.log); int32_t rspLen = tSerializeSMonVmInfo(NULL, 0, &vmInfo); @@ -304,54 +304,54 @@ int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { } void vmInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, vmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, vmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, vmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, vmProcessMonitorMsg, DEFAULT_HANDLE); // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 94a6910ba3..d70377e9ad 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -126,7 +126,7 @@ static void *vmOpenVnodeFunc(void *param) { char stepDesc[TSDB_STEP_DESC_LEN] = {0}; snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", pCfg->vgId, pMgmt->state.openVnodes, pMgmt->state.totalVnodes); - dndReportStartup(pDnode, "open-vnodes", stepDesc); + dmReportStartup(pDnode, "open-vnodes", stepDesc); SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); msgCb.pWrapper = pMgmt->pWrapper; diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp index 332dc9327c..91db59757b 100644 --- a/source/dnode/mgmt/test/sut/src/server.cpp +++ b/source/dnode/mgmt/test/sut/src/server.cpp @@ -17,7 +17,7 @@ void* serverLoop(void* param) { SDnode* pDnode = (SDnode*)param; - dndRun(pDnode); + dmRun(pDnode); return NULL; } @@ -36,7 +36,7 @@ bool TestServer::DoStart() { SDnodeOpt option = BuildOption(path, fqdn, port, firstEp); taosMkDir(path); - pDnode = dndCreate(&option); + pDnode = dmCreate(&option); if (pDnode == NULL) { return false; } @@ -68,11 +68,11 @@ bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const } void TestServer::Stop() { - dndSetEvent(pDnode, DND_EVENT_STOP); + dmSetEvent(pDnode, DND_EVENT_STOP); taosThreadJoin(threadId, NULL); if (pDnode != NULL) { - dndClose(pDnode); + dmClose(pDnode); pDnode = NULL; } } diff --git a/source/dnode/mgmt/test/sut/src/sut.cpp b/source/dnode/mgmt/test/sut/src/sut.cpp index 14197153b4..8427df3e79 100644 --- a/source/dnode/mgmt/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/test/sut/src/sut.cpp @@ -40,7 +40,7 @@ void Testbase::InitLog(const char* path) { } void Testbase::Init(const char* path, int16_t port) { - dndInit(); + dmInit(); char fqdn[] = "localhost"; char firstEp[TSDB_EP_LEN] = {0}; @@ -62,7 +62,7 @@ void Testbase::Cleanup() { client.Cleanup(); taosMsleep(10); server.Stop(); - dndCleanup(); + dmCleanup(); } void Testbase::Restart() { From e558d519becaf9870e0d52bda8740977b77aabba Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Apr 2022 14:48:27 +0800 Subject: [PATCH 10/19] refact(cluster): node mgmt --- cmake/cmake.define | 10 + example/CMakeLists.txt | 17 + example/src/demoapi.c | 197 + example/src/tmq.c | 5 +- include/common/tcommon.h | 2 +- include/common/tdatablock.h | 11 +- include/common/tglobal.h | 2 + include/common/tmsg.h | 5 + include/common/ttime.h | 1 + include/common/ttokendef.h | 165 +- include/common/ttypes.h | 37 + include/libs/function/functionMgt.h | 13 +- include/libs/nodes/nodes.h | 1 + include/libs/nodes/plannodes.h | 14 +- include/libs/scalar/filter.h | 16 +- include/libs/scalar/scalar.h | 8 + include/os/osDir.h | 1 + include/util/taoserror.h | 2 + include/util/tdef.h | 5 + packaging/install.sh | 4 +- source/client/inc/clientInt.h | 105 +- source/client/src/clientEnv.c | 1 + source/client/src/clientImpl.c | 89 +- source/client/src/clientMain.c | 216 +- source/client/src/tmq.c | 55 +- source/common/src/tglobal.c | 4 +- source/common/src/tmsg.c | 19 +- source/common/src/ttime.c | 26 +- source/common/src/tvariant.c | 11 +- source/dnode/mgmt/exe/dmMain.c | 6 +- source/dnode/mgmt/implement/CMakeLists.txt | 10 +- source/dnode/mnode/impl/src/mndGrant.c | 31 + source/dnode/vnode/CMakeLists.txt | 3 + source/dnode/vnode/src/meta/metaTDBImpl.c | 64 +- source/dnode/vnode/src/tsdb/tsdbRead.c | 1154 +++-- source/libs/executor/inc/executorimpl.h | 18 +- source/libs/executor/src/dataDispatcher.c | 4 +- source/libs/executor/src/executorimpl.c | 188 +- source/libs/executor/src/groupoperator.c | 23 +- source/libs/executor/src/scanoperator.c | 17 +- source/libs/function/inc/builtins.h | 4 +- source/libs/function/inc/builtinsimpl.h | 2 + source/libs/function/src/builtins.c | 55 +- source/libs/function/src/builtinsimpl.c | 8 + source/libs/function/src/functionMgt.c | 17 + source/libs/function/src/tfill.c | 2 +- source/libs/nodes/src/nodesCloneFuncs.c | 24 +- source/libs/nodes/src/nodesCodeFuncs.c | 22 + source/libs/nodes/src/nodesUtilFuncs.c | 21 + source/libs/parser/inc/sql.y | 7 +- source/libs/parser/src/parAstCreater.c | 11 +- source/libs/parser/src/parCalcConst.c | 2 +- source/libs/parser/src/parTokenizer.c | 14 +- source/libs/parser/src/parTranslater.c | 90 +- source/libs/parser/src/parUtil.c | 30 +- source/libs/parser/src/sql.c | 4593 ++++++++--------- source/libs/parser/test/parserAstTest.cpp | 10 + source/libs/planner/src/planLogicCreater.c | 1 + source/libs/planner/src/planOptimizer.c | 226 +- source/libs/planner/src/planPhysiCreater.c | 61 +- source/libs/planner/src/planSpliter.c | 70 +- source/libs/planner/test/plannerTest.cpp | 51 +- source/libs/scalar/inc/sclInt.h | 5 +- source/libs/scalar/src/sclfunc.c | 456 ++ source/os/src/osDir.c | 41 + tests/script/tmp/back.sim | 6 + tests/script/tmp/data.sim | 14 + tests/script/tsim/query/complex_group.sim | 150 +- tests/script/tsim/query/complex_having.sim | 386 ++ tests/script/tsim/query/complex_where.sim | 80 +- tests/script/tsim/query/diff.sim | 45 +- tests/script/tsim/tmq/insertDataV1.sim | 11 +- tests/script/tsim/tmq/insertDataV4.sim | 11 +- .../tsim/tmq/mainConsumerInMultiTopic.sim | 234 + ...merMain.sim => mainConsumerInOneTopic.sim} | 29 +- tests/tsim/src/simSystem.c | 26 +- tools/shell/src/shellEngine.c | 6 + tools/taos-tools | 2 +- 78 files changed, 5482 insertions(+), 3901 deletions(-) create mode 100644 example/src/demoapi.c create mode 100644 source/dnode/mnode/impl/src/mndGrant.c create mode 100644 tests/script/tmp/back.sim create mode 100644 tests/script/tmp/data.sim create mode 100644 tests/script/tsim/query/complex_having.sim create mode 100644 tests/script/tsim/tmq/mainConsumerInMultiTopic.sim rename tests/script/tsim/tmq/{consumerMain.sim => mainConsumerInOneTopic.sim} (94%) diff --git a/cmake/cmake.define b/cmake/cmake.define index 639ae9ca3f..b89860e29f 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -1,5 +1,15 @@ cmake_minimum_required(VERSION 3.16) +if (NOT DEFINED TD_GRANT) + SET(TD_GRANT FALSE) +endif() +if (NOT DEFINED TD_USB_DONGLE) + SET(TD_USB_DONGLE FALSE) +endif() +IF (TD_GRANT) + ADD_DEFINITIONS(-D_GRANT) +ENDIF () + IF ("${BUILD_TOOLS}" STREQUAL "") IF (TD_LINUX) IF (TD_ARM_32) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index acb99caffc..54bb83d244 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(tmq "") add_executable(tstream "") +add_executable(demoapi "") target_sources(tmq PRIVATE @@ -10,6 +11,12 @@ target_sources(tstream PRIVATE "src/tstream.c" ) + +target_sources(demoapi + PRIVATE + "src/demoapi.c" +) + target_link_libraries(tmq taos ) @@ -18,6 +25,10 @@ target_link_libraries(tstream taos ) +target_link_libraries(demoapi + taos +) + target_include_directories(tmq PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) @@ -26,5 +37,11 @@ target_include_directories(tstream PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) +target_include_directories(demoapi + PUBLIC "${TD_SOURCE_DIR}/include/client" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + SET_TARGET_PROPERTIES(tmq PROPERTIES OUTPUT_NAME tmq) SET_TARGET_PROPERTIES(tstream PROPERTIES OUTPUT_NAME tstream) +SET_TARGET_PROPERTIES(demoapi PROPERTIES OUTPUT_NAME demoapi) diff --git a/example/src/demoapi.c b/example/src/demoapi.c new file mode 100644 index 0000000000..ede13b4bb8 --- /dev/null +++ b/example/src/demoapi.c @@ -0,0 +1,197 @@ +// C api call sequence demo +// to compile: gcc -o apidemo apidemo.c -ltaos + +#include +#include +#include +#include +#include +#include + +#include "taos.h" + +#define debugPrint(fmt, ...) \ + do { if (g_args.debug_print || g_args.verbose_print) \ + fprintf(stdout, "DEBG: "fmt, __VA_ARGS__); } while(0) + +#define warnPrint(fmt, ...) \ + do { fprintf(stderr, "\033[33m"); \ + fprintf(stderr, "WARN: "fmt, __VA_ARGS__); \ + fprintf(stderr, "\033[0m"); } while(0) + +#define errorPrint(fmt, ...) \ + do { fprintf(stderr, "\033[31m"); \ + fprintf(stderr, "ERROR: "fmt, __VA_ARGS__); \ + fprintf(stderr, "\033[0m"); } while(0) + +#define okPrint(fmt, ...) \ + do { fprintf(stderr, "\033[32m"); \ + fprintf(stderr, "OK: "fmt, __VA_ARGS__); \ + fprintf(stderr, "\033[0m"); } while(0) + +int64_t g_num_of_tb = 2; +int64_t g_num_of_rec = 2; + +static struct argp_option options[] = { + {"tables", 't', "NUMBER", 0, "Number of child tables, default is 10000."}, + {"records", 'n', "NUMBER", 0, + "Number of records for each table, default is 10000."}, + {0}}; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) { + switch (key) { + case 't': + g_num_of_tb = atoll(arg); + break; + + case 'n': + g_num_of_rec = atoll(arg); + break; + } + + return 0; +} + +static struct argp argp = {options, parse_opt, "", ""}; + +static void prepare_data(TAOS* taos) { + TAOS_RES *res; + res = taos_query(taos, "drop database if exists test;"); + taos_free_result(res); + usleep(100000); + + res = taos_query(taos, "create database test;"); + taos_free_result(res); + usleep(100000); + taos_select_db(taos, "test"); + + res = taos_query(taos, "create table meters(ts timestamp, f float, n int, b binary(20)) tags(area int, localtion binary(20));"); + taos_free_result(res); + + char command[1024] = {0}; + for (int64_t i = 0; i < g_num_of_tb; i ++) { + sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s');", + i, i, (i%2)?"beijing":"shanghai"); + res = taos_query(taos, command); + taos_free_result(res); + + int64_t j = 0; + int64_t total = 0; + int64_t affected; + for (; j < g_num_of_rec -1; j ++) { + sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", %f, %"PRId64", '%c%d')", + i, 1650000000000+j, (float)j, j, 'a'+(int)j%10, rand()); + res = taos_query(taos, command); + if ((res) && (0 == taos_errno(res))) { + affected = taos_affected_rows(res); + total += affected; + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + taos_free_result(res); + } + sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", NULL, NULL, NULL)", + i, 1650000000000+j+1); + res = taos_query(taos, command); + if ((res) && (0 == taos_errno(res))) { + affected = taos_affected_rows(res); + total += affected; + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + taos_free_result(res); + + printf("insert %"PRId64" records into t%"PRId64", total affected rows: %"PRId64"\n", j, i, total); + } +} + +static int print_result(TAOS_RES* res, int block) { + int64_t num_rows = 0; + TAOS_ROW row = NULL; + int num_fields = taos_num_fields(res); + TAOS_FIELD* fields = taos_fetch_fields(res); + + if (block) { + warnPrint("%s() LN%d, call taos_fetch_block()\n", __func__, __LINE__); + int rows = 0; + while ((rows = taos_fetch_block(res, &row))) { + num_rows += rows; + } + } else { + warnPrint("%s() LN%d, call taos_fetch_rows()\n", __func__, __LINE__); + while ((row = taos_fetch_row(res))) { + char temp[256] = {0}; + taos_print_row(temp, row, fields, num_fields); + puts(temp); + num_rows ++; + } + } + + return num_rows; +} + +static void verify_query(TAOS* taos) { + // TODO: select count(tbname) from stable once stable query work + char command[1024] = {0}; + + for (int64_t i = 0; i < g_num_of_tb; i++) { + sprintf(command, "select * from t%"PRId64"", i); + TAOS_RES* res = taos_query(taos, command); + + if (res) { + if (0 == taos_errno(res)) { + int field_count = taos_field_count(res); + printf("field_count: %d\n", field_count); + int* lengths = taos_fetch_lengths(res); + if (lengths) { + for (int c = 0; c < field_count; c++) { + printf("length of column %d is %d\n", c, lengths[c]); + } + } else { + errorPrint("%s() LN%d: t%"PRId64"'s lengths is NULL\n", + __func__, __LINE__, i); + } + + int64_t rows = print_result(res, i % 2); + printf("rows is: %"PRId64"\n", rows); + + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + } +} + +int main(int argc, char *argv[]) { + const char* host = "127.0.0.1"; + const char* user = "root"; + const char* passwd = "taosdata"; + + argp_parse(&argp, argc, argv, 0, 0, NULL); + TAOS* taos = taos_connect(host, user, passwd, "", 0); + if (taos == NULL) { + printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos)); + exit(1); + } + + const char* info = taos_get_server_info(taos); + printf("server info: %s\n", info); + info = taos_get_client_info(taos); + printf("client info: %s\n", info); + + prepare_data(taos); + + verify_query(taos); + + taos_close(taos); + printf("done\n"); + + return 0; +} + diff --git a/example/src/tmq.c b/example/src/tmq.c index efb4d1830e..ca80c8fe5a 100644 --- a/example/src/tmq.c +++ b/example/src/tmq.c @@ -163,12 +163,13 @@ void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { printf("subscribe err\n"); return; } - /*int32_t cnt = 0;*/ + int32_t cnt = 0; /*clock_t startTime = clock();*/ while (running) { tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 500); if (tmqmessage) { - /*cnt++;*/ + cnt++; + printf("get data\n"); msg_process(tmqmessage); tmq_message_destroy(tmqmessage); /*} else {*/ diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 1040130f76..7c308f9354 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -222,7 +222,7 @@ typedef struct SFunctParam { // the structure for sql function in select clause typedef struct SResSchame { int8_t type; - int32_t colId; + int32_t slotId; int32_t bytes; int32_t precision; int32_t scale; diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index b2b8cff19a..5e5a8826e5 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -136,7 +136,8 @@ static FORCE_INLINE void colDataAppendInt8(SColumnInfoData* pColumnInfoData, uin } static FORCE_INLINE void colDataAppendInt16(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int16_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || + pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(int16_t*)p = *(int16_t*)v; } @@ -210,15 +211,19 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock); void blockDebugShowData(const SArray* dataBlocks); +static FORCE_INLINE int32_t blockEstimateEncodeSize(const SSDataBlock* pBlock) { + return blockDataGetSerialMetaSize(pBlock) + (int32_t)ceil(blockDataGetSerialRowSize(pBlock) * pBlock->info.rows); +} + static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data, - int8_t compressed) { + int8_t compressed) { int32_t colSize = colDataGetLength(pColRes, numOfRows); return (*(tDataTypes[pColRes->info.type].compFunc))(pColRes->pData, colSize, numOfRows, data, colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0); } static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, - int8_t needCompress) { + int8_t needCompress) { int32_t* colSizes = (int32_t*)data; data += numOfCols * sizeof(int32_t); diff --git a/include/common/tglobal.h b/include/common/tglobal.h index f03943e105..5022cb7be8 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -18,6 +18,7 @@ #include "tarray.h" #include "tdef.h" +#include "tconfig.h" #ifdef __cplusplus extern "C" { @@ -129,6 +130,7 @@ void taosCfgDynamicOptions(const char *option, const char *value); void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary); struct SConfig *taosGetCfg(); +int32_t taosAddClientLogCfg(SConfig *pCfg); #ifdef __cplusplus } diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 7a4625289b..6244515b1d 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -260,6 +260,7 @@ typedef struct { typedef struct SSchema { int8_t type; + int8_t index; // default is 0, not index created col_id_t colId; int32_t bytes; char name[TSDB_COL_NAME_LEN]; @@ -2016,6 +2017,7 @@ typedef struct { static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) { int32_t tlen = 0; tlen += taosEncodeFixedI8(buf, pSchema->type); + tlen += taosEncodeFixedI8(buf, pSchema->index); tlen += taosEncodeFixedI32(buf, pSchema->bytes); tlen += taosEncodeFixedI16(buf, pSchema->colId); tlen += taosEncodeString(buf, pSchema->name); @@ -2024,6 +2026,7 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) { buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosDecodeFixedI8(buf, &pSchema->index); buf = taosDecodeFixedI32(buf, &pSchema->bytes); buf = taosDecodeFixedI16(buf, &pSchema->colId); buf = taosDecodeStringTo(buf, pSchema->name); @@ -2032,6 +2035,7 @@ static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) { static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) { if (tEncodeI8(pEncoder, pSchema->type) < 0) return -1; + if (tEncodeI8(pEncoder, pSchema->index) < 0) return -1; if (tEncodeI32(pEncoder, pSchema->bytes) < 0) return -1; if (tEncodeI16(pEncoder, pSchema->colId) < 0) return -1; if (tEncodeCStr(pEncoder, pSchema->name) < 0) return -1; @@ -2040,6 +2044,7 @@ static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSch static FORCE_INLINE int32_t tDecodeSSchema(SCoder* pDecoder, SSchema* pSchema) { if (tDecodeI8(pDecoder, &pSchema->type) < 0) return -1; + if (tDecodeI8(pDecoder, &pSchema->index) < 0) return -1; if (tDecodeI32(pDecoder, &pSchema->bytes) < 0) return -1; if (tDecodeI16(pDecoder, &pSchema->colId) < 0) return -1; if (tDecodeCStrTo(pDecoder, pSchema->name) < 0) return -1; diff --git a/include/common/ttime.h b/include/common/ttime.h index 306f54bedb..15450c31ca 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -64,6 +64,7 @@ char getPrecisionUnit(int32_t precision); int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision); int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit); +int32_t convertStringToTimestamp(int16_t type, char *inputData, int64_t timePrec, int64_t *timeVal); void taosFormatUtcTime(char *buf, int32_t bufLen, int64_t time, int32_t precision); diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 3eb43c35e1..f5b9c23ee6 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -140,88 +140,89 @@ #define TK_APPS 122 #define TK_CONNECTIONS 123 #define TK_LICENCE 124 -#define TK_QUERIES 125 -#define TK_SCORES 126 -#define TK_TOPICS 127 -#define TK_VARIABLES 128 -#define TK_BNODES 129 -#define TK_SNODES 130 -#define TK_LIKE 131 -#define TK_INDEX 132 -#define TK_FULLTEXT 133 -#define TK_FUNCTION 134 -#define TK_INTERVAL 135 -#define TK_TOPIC 136 -#define TK_AS 137 -#define TK_DESC 138 -#define TK_DESCRIBE 139 -#define TK_RESET 140 -#define TK_QUERY 141 -#define TK_EXPLAIN 142 -#define TK_ANALYZE 143 -#define TK_VERBOSE 144 -#define TK_NK_BOOL 145 -#define TK_RATIO 146 -#define TK_COMPACT 147 -#define TK_VNODES 148 -#define TK_IN 149 -#define TK_OUTPUTTYPE 150 -#define TK_AGGREGATE 151 -#define TK_BUFSIZE 152 -#define TK_STREAM 153 -#define TK_INTO 154 -#define TK_KILL 155 -#define TK_CONNECTION 156 -#define TK_MERGE 157 -#define TK_VGROUP 158 -#define TK_REDISTRIBUTE 159 -#define TK_SPLIT 160 -#define TK_SYNCDB 161 -#define TK_NULL 162 -#define TK_FIRST 163 -#define TK_LAST 164 -#define TK_NOW 165 -#define TK_ROWTS 166 -#define TK_TBNAME 167 -#define TK_QSTARTTS 168 -#define TK_QENDTS 169 -#define TK_WSTARTTS 170 -#define TK_WENDTS 171 -#define TK_WDURATION 172 -#define TK_BETWEEN 173 -#define TK_IS 174 -#define TK_NK_LT 175 -#define TK_NK_GT 176 -#define TK_NK_LE 177 -#define TK_NK_GE 178 -#define TK_NK_NE 179 -#define TK_MATCH 180 -#define TK_NMATCH 181 -#define TK_JOIN 182 -#define TK_INNER 183 -#define TK_SELECT 184 -#define TK_DISTINCT 185 -#define TK_WHERE 186 -#define TK_PARTITION 187 -#define TK_BY 188 -#define TK_SESSION 189 -#define TK_STATE_WINDOW 190 -#define TK_SLIDING 191 -#define TK_FILL 192 -#define TK_VALUE 193 -#define TK_NONE 194 -#define TK_PREV 195 -#define TK_LINEAR 196 -#define TK_NEXT 197 -#define TK_GROUP 198 -#define TK_HAVING 199 -#define TK_ORDER 200 -#define TK_SLIMIT 201 -#define TK_SOFFSET 202 -#define TK_LIMIT 203 -#define TK_OFFSET 204 -#define TK_ASC 205 -#define TK_NULLS 206 +#define TK_GRANTS 125 +#define TK_QUERIES 126 +#define TK_SCORES 127 +#define TK_TOPICS 128 +#define TK_VARIABLES 129 +#define TK_BNODES 130 +#define TK_SNODES 131 +#define TK_LIKE 132 +#define TK_INDEX 133 +#define TK_FULLTEXT 134 +#define TK_FUNCTION 135 +#define TK_INTERVAL 136 +#define TK_TOPIC 137 +#define TK_AS 138 +#define TK_DESC 139 +#define TK_DESCRIBE 140 +#define TK_RESET 141 +#define TK_QUERY 142 +#define TK_EXPLAIN 143 +#define TK_ANALYZE 144 +#define TK_VERBOSE 145 +#define TK_NK_BOOL 146 +#define TK_RATIO 147 +#define TK_COMPACT 148 +#define TK_VNODES 149 +#define TK_IN 150 +#define TK_OUTPUTTYPE 151 +#define TK_AGGREGATE 152 +#define TK_BUFSIZE 153 +#define TK_STREAM 154 +#define TK_INTO 155 +#define TK_KILL 156 +#define TK_CONNECTION 157 +#define TK_MERGE 158 +#define TK_VGROUP 159 +#define TK_REDISTRIBUTE 160 +#define TK_SPLIT 161 +#define TK_SYNCDB 162 +#define TK_NULL 163 +#define TK_FIRST 164 +#define TK_LAST 165 +#define TK_NOW 166 +#define TK_ROWTS 167 +#define TK_TBNAME 168 +#define TK_QSTARTTS 169 +#define TK_QENDTS 170 +#define TK_WSTARTTS 171 +#define TK_WENDTS 172 +#define TK_WDURATION 173 +#define TK_BETWEEN 174 +#define TK_IS 175 +#define TK_NK_LT 176 +#define TK_NK_GT 177 +#define TK_NK_LE 178 +#define TK_NK_GE 179 +#define TK_NK_NE 180 +#define TK_MATCH 181 +#define TK_NMATCH 182 +#define TK_JOIN 183 +#define TK_INNER 184 +#define TK_SELECT 185 +#define TK_DISTINCT 186 +#define TK_WHERE 187 +#define TK_PARTITION 188 +#define TK_BY 189 +#define TK_SESSION 190 +#define TK_STATE_WINDOW 191 +#define TK_SLIDING 192 +#define TK_FILL 193 +#define TK_VALUE 194 +#define TK_NONE 195 +#define TK_PREV 196 +#define TK_LINEAR 197 +#define TK_NEXT 198 +#define TK_GROUP 199 +#define TK_HAVING 200 +#define TK_ORDER 201 +#define TK_SLIMIT 202 +#define TK_SOFFSET 203 +#define TK_LIMIT 204 +#define TK_OFFSET 205 +#define TK_ASC 206 +#define TK_NULLS 207 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 5f1cfc030a..032cb44122 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -142,6 +142,43 @@ typedef struct { } \ } while (0) +#define NUM_TO_STRING(_inputType, _input, _outputBytes, _output) \ + do { \ + switch (_inputType) { \ + case TSDB_DATA_TYPE_TINYINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(int8_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_UTINYINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint8_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_SMALLINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(int16_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_USMALLINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint16_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_TIMESTAMP: \ + case TSDB_DATA_TYPE_BIGINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%" PRId64, *(int64_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_UBIGINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_FLOAT: \ + snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_DOUBLE: \ + snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_UINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \ + break; \ + default: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(int32_t *)(_input)); \ + break; \ + } \ + } while (0) + #define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT) #define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT) #define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE) diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 57a3862a9a..148a9f77d6 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -85,8 +85,8 @@ typedef enum EFunctionType { // conversion function FUNCTION_TYPE_CAST = 2000, FUNCTION_TYPE_TO_ISO8601, + FUNCTION_TYPE_TO_UNIXTIMESTAMP, FUNCTION_TYPE_TO_JSON, - FUNCTION_TYPE_UNIXTIMESTAMP, // date and time function FUNCTION_TYPE_NOW = 2500, @@ -135,8 +135,17 @@ bool fmIsTimeorderFunc(int32_t funcId); bool fmIsPseudoColumnFunc(int32_t funcId); bool fmIsWindowPseudoColumnFunc(int32_t funcId); bool fmIsWindowClauseFunc(int32_t funcId); +bool fmIsSpecialDataRequiredFunc(int32_t funcId); +bool fmIsDynamicScanOptimizedFunc(int32_t funcId); -int32_t fmFuncScanType(int32_t funcId); +typedef enum EFuncDataRequired { + FUNC_DATA_REQUIRED_ALL_NEEDED = 1, + FUNC_DATA_REQUIRED_STATIS_NEEDED, + FUNC_DATA_REQUIRED_NO_NEEDED, + FUNC_DATA_REQUIRED_DISCARD +} EFuncDataRequired; + +EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow); int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet); int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet); diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index c91779ba8b..3a1d7954a7 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -216,6 +216,7 @@ SNodeList* nodesMakeList(); int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode); int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode); int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode); +int32_t nodesListMakeStrictAppend(SNodeList** pList, SNodeptr pNode); int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc); int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc); int32_t nodesListPushFront(SNodeList* pList, SNodeptr pNode); diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 3931be7da5..3b5f9abe81 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -30,6 +30,7 @@ typedef struct SLogicNode { SNode* pConditions; SNodeList* pChildren; struct SLogicNode* pParent; + int32_t optimizedFlag; } SLogicNode; typedef enum EScanType { @@ -50,6 +51,8 @@ typedef struct SScanLogicNode { SName tableName; bool showRewrite; double ratio; + SNodeList* pDynamicScanFuncs; + int32_t dataRequired; } SScanLogicNode; typedef struct SJoinLogicNode { @@ -196,20 +199,13 @@ typedef struct SSystemTableScanPhysiNode { int32_t accountId; } SSystemTableScanPhysiNode; -typedef enum EScanRequired { - SCAN_REQUIRED_DATA_NO_NEEDED = 1, - SCAN_REQUIRED_DATA_STATIS_NEEDED, - SCAN_REQUIRED_DATA_ALL_NEEDED, - SCAN_REQUIRED_DATA_DISCARD, -} EScanRequired; - typedef struct STableScanPhysiNode { SScanPhysiNode scan; uint8_t scanFlag; // denotes reversed scan of data or not STimeWindow scanRange; double ratio; - EScanRequired scanRequired; - SNodeList* pScanReferFuncs; + int32_t dataRequired; + SNodeList* pDynamicScanFuncs; } STableScanPhysiNode; typedef STableScanPhysiNode STableSeqScanPhysiNode; diff --git a/include/libs/scalar/filter.h b/include/libs/scalar/filter.h index c81cb49b64..f1cd99f04a 100644 --- a/include/libs/scalar/filter.h +++ b/include/libs/scalar/filter.h @@ -19,8 +19,8 @@ extern "C" { #endif -#include "tcommon.h" #include "nodes.h" +#include "tcommon.h" typedef struct SFilterInfo SFilterInfo; typedef int32_t (*filer_get_col_from_id)(void *, int32_t, void **); @@ -31,20 +31,20 @@ enum { FLT_OPTION_NEED_UNIQE = 4, }; -typedef struct SFilterColumnParam{ +typedef struct SFilterColumnParam { int32_t numOfCols; - SArray* pDataBlock; + SArray *pDataBlock; } SFilterColumnParam; extern int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pinfo, uint32_t options); -extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols); +extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t **p, SColumnDataAgg *statis, int16_t numOfCols); extern int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param); extern int32_t filterSetDataFromColId(SFilterInfo *info, void *param); extern int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict); -extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar); -extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo); -extern void filterFreeInfo(SFilterInfo *info); -extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows); +extern int32_t filterConverNcharColumns(SFilterInfo *pFilterInfo, int32_t rows, bool *gotNchar); +extern int32_t filterFreeNcharColumns(SFilterInfo *pFilterInfo); +extern void filterFreeInfo(SFilterInfo *info); +extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows); #ifdef __cplusplus } diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index b5acc64f0b..caea52a5ef 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -70,6 +70,14 @@ int32_t ltrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut int32_t rtrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +/* Conversion functions */ +int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); + +/* Time related functions */ +int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); + bool getTimePseudoFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); diff --git a/include/os/osDir.h b/include/os/osDir.h index d3597cab36..e7da54bf54 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -38,6 +38,7 @@ typedef struct TdDirEntry *TdDirEntryPtr; void taosRemoveDir(const char *dirname); bool taosDirExist(char *dirname); int32_t taosMkDir(const char *dirname); +int32_t taosMulMkDir(const char *dirname); void taosRemoveOldFiles(const char *dirname, int32_t keepDays); int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen); int32_t taosRealPath(char *dirname, int32_t maxlen); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 04baa3c09d..60535e2f49 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -597,6 +597,8 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INVALID_ROLLUP_OPTION TAOS_DEF_ERROR_CODE(0, 0x2622) #define TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION TAOS_DEF_ERROR_CODE(0, 0x2623) #define TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST TAOS_DEF_ERROR_CODE(0, 0x2624) +#define TSDB_CODE_PAR_INVALID_OPTION_UNIT TAOS_DEF_ERROR_CODE(0, 0x2625) +#define TSDB_CODE_PAR_INVALID_KEEP_UNIT TAOS_DEF_ERROR_CODE(0, 0x2626) //planner #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) diff --git a/include/util/tdef.h b/include/util/tdef.h index 263c90c0f8..f276a1a812 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -94,6 +94,11 @@ extern const int32_t TYPE_BYTES[15]; #define TSDB_TIME_PRECISION_MICRO_STR "us" #define TSDB_TIME_PRECISION_NANO_STR "ns" +#define TSDB_TIME_PRECISION_SEC_DIGITS 10 +#define TSDB_TIME_PRECISION_MILLI_DIGITS 13 +#define TSDB_TIME_PRECISION_MICRO_DIGITS 16 +#define TSDB_TIME_PRECISION_NANO_DIGITS 19 + #define TSDB_INFORMATION_SCHEMA_DB "information_schema" #define TSDB_INS_TABLE_DNODES "dnodes" #define TSDB_INS_TABLE_MNODES "mnodes" diff --git a/packaging/install.sh b/packaging/install.sh index 3aae074af5..bfd5fcd3a9 100755 --- a/packaging/install.sh +++ b/packaging/install.sh @@ -157,7 +157,7 @@ function install_main_path() { ${csudo} mkdir -p ${install_main_dir}/cfg ${csudo} mkdir -p ${install_main_dir}/bin ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver + ${csudo} mkdir -p ${install_main_dir}/lib ${csudo} mkdir -p ${install_main_dir}/examples ${csudo} mkdir -p ${install_main_dir}/include ${csudo} mkdir -p ${install_main_dir}/init.d @@ -199,6 +199,8 @@ function install_lib() { ${csudo} rm -f ${lib_link_dir}/libtaos.* || : ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo} cp -rf ${script_dir}/lib/* ${install_main_dir}/lib && ${csudo} chmod 777 ${install_main_dir}/lib/* + ${csudo} ln -s ${install_main_dir}/lib/libtaos.* ${lib_link_dir}/libtaos.so.1 ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index f244059b7c..185b5824d9 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -75,12 +75,12 @@ typedef int32_t (*FHbReqHandle)(SClientHbKey* connKey, void* param, SClientHbReq typedef struct { int8_t inited; // ctl - int8_t threadStop; - TdThread thread; + int8_t threadStop; + TdThread thread; TdThreadMutex lock; // used when app init and cleanup - SArray* appHbMgrs; // SArray one for each cluster - FHbReqHandle reqHandle[HEARTBEAT_TYPE_MAX]; - FHbRspHandle rspHandle[HEARTBEAT_TYPE_MAX]; + SArray* appHbMgrs; // SArray one for each cluster + FHbReqHandle reqHandle[HEARTBEAT_TYPE_MAX]; + FHbRspHandle rspHandle[HEARTBEAT_TYPE_MAX]; } SClientHbMgr; typedef struct SQueryExecMetric { @@ -118,42 +118,42 @@ struct SAppInstInfo { }; typedef struct SAppInfo { - int64_t startTime; - char appName[TSDB_APP_NAME_LEN]; - char* ep; - int32_t pid; - int32_t numOfThreads; - SHashObj* pInstMap; + int64_t startTime; + char appName[TSDB_APP_NAME_LEN]; + char* ep; + int32_t pid; + int32_t numOfThreads; + SHashObj* pInstMap; TdThreadMutex mutex; } SAppInfo; typedef struct STscObj { - char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; - char db[TSDB_DB_FNAME_LEN]; - char ver[128]; - int32_t acctId; - uint32_t connId; - int32_t connType; - uint64_t id; // ref ID returned by taosAddRef - TdThreadMutex mutex; // used to protect the operation on db - int32_t numOfReqs; // number of sqlObj bound to this connection - SAppInstInfo* pAppInfo; + char user[TSDB_USER_LEN]; + char pass[TSDB_PASSWORD_LEN]; + char db[TSDB_DB_FNAME_LEN]; + char ver[128]; + int32_t acctId; + uint32_t connId; + int32_t connType; + uint64_t id; // ref ID returned by taosAddRef + TdThreadMutex mutex; // used to protect the operation on db + int32_t numOfReqs; // number of sqlObj bound to this connection + SAppInstInfo* pAppInfo; } STscObj; typedef struct SResultColumn { union { - char* nullbitmap; // bitmap, one bit for each item in the list - int32_t* offset; + char* nullbitmap; // bitmap, one bit for each item in the list + int32_t* offset; }; - char* pData; + char* pData; } SResultColumn; typedef struct SReqResultInfo { const char* pRspMsg; const char* pData; - TAOS_FIELD* fields; // todo, column names are not needed. - TAOS_FIELD* userFields; // the fields info that return to user + TAOS_FIELD* fields; // todo, column names are not needed. + TAOS_FIELD* userFields; // the fields info that return to user uint32_t numOfCols; int32_t* length; char** convertBuf; @@ -180,13 +180,30 @@ typedef struct SRequestSendRecvBody { SShowReqInfo showInfo; // todo this attribute will be removed after the query framework being completed. SDataBuf requestMsg; int64_t queryJob; // query job, created according to sql query DAG. - struct SQueryPlan* pDag; // the query dag, generated according to the sql statement. + struct SQueryPlan* pDag; // the query dag, generated according to the sql statement. SReqResultInfo resInfo; } SRequestSendRecvBody; #define ERROR_MSG_BUF_DEFAULT_SIZE 512 +enum { + RES_TYPE__QUERY = 1, + RES_TYPE__TMQ, +}; + +#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY) +#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ) + +typedef struct SMqRspObj { + int8_t resType; + char* topic; + void* vg; + SArray* res; // SArray + int32_t resIter; +} SMqRspObj; + typedef struct SRequestObj { + int8_t resType; // query or tmq uint64_t requestId; int32_t type; // request type STscObj* pTscObj; @@ -203,6 +220,25 @@ typedef struct SRequestObj { SRequestSendRecvBody body; } SRequestObj; +static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) { + SMqRspObj* msg = (SMqRspObj*)res; + int32_t resIter = msg->resIter == -1 ? 0 : msg->resIter; + return (SReqResultInfo*)taosArrayGet(msg->res, resIter); +} + +static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res) { + SMqRspObj* msg = (SMqRspObj*)res; + if (++msg->resIter < taosArrayGetSize(msg->res)) { + return (SReqResultInfo*)taosArrayGet(msg->res, msg->resIter); + } + return NULL; +} + +static FORCE_INLINE SReqResultInfo* tscGetCurResInfo(TAOS_RES* res) { + if (TD_RES_QUERY(res)) return &(((SRequestObj*)res)->body.resInfo); + return tmqGetCurResInfo(res); +} + extern SAppInfo appInfo; extern int32_t clientReqRefPool; extern int32_t clientConnRefPool; @@ -238,14 +274,17 @@ void initMsgHandleFp(); TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, uint16_t port); -void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); - -int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, bool convertUcs4); +int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery); +int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest); -int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery); -int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); +void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); +void doSetOneRowPtr(SReqResultInfo* pResultInfo); +int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, + bool convertUcs4); +void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); +int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4); // --- heartbeat // global, called by mgmt diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 359649884f..fec6c8e5db 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -149,6 +149,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty return NULL; } + pRequest->resType = RES_TYPE__QUERY; pRequest->pDb = getDbOfConnection(pObj); pRequest->requestId = generateRequestId(); pRequest->metric.start = taosGetTimestampUs(); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index c396ab40ac..63bb3637cf 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -13,7 +13,6 @@ static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet); static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest); static void destroySendMsgInfo(SMsgSendInfo* pMsgBody); -static int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4); static bool stringLengthCheck(const char* str, size_t maxsize) { if (str == NULL) { @@ -42,7 +41,6 @@ static char* getClusterKey(const char* user, const char* auth, const char* ip, i static STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param, SAppInstInfo* pAppInfo); -static void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, uint16_t port) { @@ -174,7 +172,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery) { int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { SRetrieveTableRsp* pRsp = NULL; - int32_t code = qExecCommand(pQuery->pRoot, &pRsp); + int32_t code = qExecCommand(pQuery->pRoot, &pRsp); if (TSDB_CODE_SUCCESS == code && NULL != pRsp) { code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false); } @@ -190,7 +188,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg; pRequest->type = pMsgInfo->msgType; pRequest->body.requestMsg = (SDataBuf){.pData = pMsgInfo->pMsg, .len = pMsgInfo->msgLen, .handle = NULL}; - pMsgInfo->pMsg = NULL; // pMsg transferred to SMsgSendInfo management + pMsgInfo->pMsg = NULL; // pMsg transferred to SMsgSendInfo management STscObj* pTscObj = pRequest->pTscObj; SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest); @@ -211,14 +209,12 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) { pRequest->type = pQuery->msgType; - SPlanContext cxt = { - .queryId = pRequest->requestId, - .acctId = pRequest->pTscObj->acctId, - .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), - .pAstRoot = pQuery->pRoot, - .showRewrite = pQuery->showRewrite - }; - int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList); + SPlanContext cxt = {.queryId = pRequest->requestId, + .acctId = pRequest->pTscObj->acctId, + .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), + .pAstRoot = pQuery->pRoot, + .showRewrite = pQuery->showRewrite}; + int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList); if (code != 0) { return code; } @@ -234,10 +230,10 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t for (int32_t i = 0; i < pResInfo->numOfCols; ++i) { pResInfo->fields[i].bytes = pSchema[i].bytes; - pResInfo->fields[i].type = pSchema[i].type; + pResInfo->fields[i].type = pSchema[i].type; pResInfo->userFields[i].bytes = pSchema[i].bytes; - pResInfo->userFields[i].type = pSchema[i].type; + pResInfo->userFields[i].type = pSchema[i].type; if (pSchema[i].type == TSDB_DATA_TYPE_VARCHAR) { pResInfo->userFields[i].bytes -= VARSTR_HEADER_SIZE; @@ -254,7 +250,8 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter; SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf}; - int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, pRequest->metric.start, &res); + int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, + pRequest->metric.start, &res); if (code != TSDB_CODE_SUCCESS) { if (pRequest->body.queryJob != 0) { schedulerFreeJob(pRequest->body.queryJob); @@ -274,14 +271,14 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList } pRequest->code = res.code; - terrno = res.code; + terrno = res.code; return pRequest->code; } SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { SRequestObj* pRequest = NULL; - SQuery* pQuery = NULL; - SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); + SQuery* pQuery = NULL; + SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); if (TSDB_CODE_SUCCESS == code) { @@ -320,15 +317,15 @@ SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { } int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { - SCatalog *pCatalog = NULL; - int32_t code = 0; - int32_t dbNum = taosArrayGetSize(pRequest->dbList); - int32_t tblNum = taosArrayGetSize(pRequest->tableList); + SCatalog* pCatalog = NULL; + int32_t code = 0; + int32_t dbNum = taosArrayGetSize(pRequest->dbList); + int32_t tblNum = taosArrayGetSize(pRequest->tableList); if (dbNum <= 0 && tblNum <= 0) { return TSDB_CODE_QRY_APP_ERROR; } - + code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog); if (code != TSDB_CODE_SUCCESS) { return code; @@ -337,8 +334,8 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { SEpSet epset = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); for (int32_t i = 0; i < dbNum; ++i) { - char *dbFName = taosArrayGet(pRequest->dbList, i); - + char* dbFName = taosArrayGet(pRequest->dbList, i); + code = catalogRefreshDBVgInfo(pCatalog, pTscObj->pAppInfo->pTransporter, &epset, dbFName); if (code != TSDB_CODE_SUCCESS) { return code; @@ -346,7 +343,7 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { } for (int32_t i = 0; i < tblNum; ++i) { - SName *tableName = taosArrayGet(pRequest->tableList, i); + SName* tableName = taosArrayGet(pRequest->tableList, i); code = catalogRefreshTableMeta(pCatalog, pTscObj->pAppInfo->pTransporter, &epset, tableName, -1); if (code != TSDB_CODE_SUCCESS) { @@ -357,11 +354,10 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { return code; } - SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) { SRequestObj* pRequest = NULL; - int32_t retryNum = 0; - int32_t code = 0; + int32_t retryNum = 0; + int32_t code = 0; while (retryNum++ < REQUEST_MAX_TRY_TIMES) { pRequest = execQueryImpl(pTscObj, sql, sqlLen); @@ -377,7 +373,7 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) { destroyRequest(pRequest); } - + return pRequest; } @@ -509,7 +505,8 @@ static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { } bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType) { - return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP || msgType == TDMT_VND_QUERY_HEARTBEAT_RSP; + return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP || + msgType == TDMT_VND_QUERY_HEARTBEAT_RSP; } void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { @@ -536,10 +533,10 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start; if (pMsg->code == TSDB_CODE_SUCCESS) { tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%" PRIx64, pRequest->self, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed/1000, pRequest->requestId); + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed / 1000, pRequest->requestId); } else { tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%" PRIx64, pRequest->self, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed/1000, pRequest->requestId); + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed / 1000, pRequest->requestId); } taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); @@ -590,7 +587,7 @@ TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, c return taos_connect(ipStr, userStr, passStr, dbStr, port); } -static void doSetOneRowPtr(SReqResultInfo* pResultInfo) { +void doSetOneRowPtr(SReqResultInfo* pResultInfo) { for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { SResultColumn* pCol = &pResultInfo->pCol[i]; @@ -722,8 +719,8 @@ _return: static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { if (pResInfo->row == NULL) { - pResInfo->row = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); - pResInfo->pCol = taosMemoryCalloc(pResInfo->numOfCols, sizeof(SResultColumn)); + pResInfo->row = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); + pResInfo->pCol = taosMemoryCalloc(pResInfo->numOfCols, sizeof(SResultColumn)); pResInfo->length = taosMemoryCalloc(pResInfo->numOfCols, sizeof(int32_t)); pResInfo->convertBuf = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); @@ -740,7 +737,7 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int int32_t type = pResultInfo->fields[i].type; int32_t bytes = pResultInfo->fields[i].bytes; - if (type == TSDB_DATA_TYPE_NCHAR) { + if (type == TSDB_DATA_TYPE_NCHAR && colLength[i] > 0) { char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -770,7 +767,8 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int return TSDB_CODE_SUCCESS; } -int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, bool convertUcs4) { +int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, + bool convertUcs4) { assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL); if (numOfRows == 0) { return TSDB_CODE_SUCCESS; @@ -841,15 +839,16 @@ void resetConnectDB(STscObj* pTscObj) { int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4) { assert(pResultInfo != NULL && pRsp != NULL); - pResultInfo->pRspMsg = (const char*)pRsp; - pResultInfo->pData = (void*)pRsp->data; - pResultInfo->numOfRows = htonl(pRsp->numOfRows); - pResultInfo->current = 0; - pResultInfo->completed = (pRsp->completed == 1); + pResultInfo->pRspMsg = (const char*)pRsp; + pResultInfo->pData = (void*)pRsp->data; + pResultInfo->numOfRows = htonl(pRsp->numOfRows); + pResultInfo->current = 0; + pResultInfo->completed = (pRsp->completed == 1); pResultInfo->payloadLen = htonl(pRsp->compLen); - pResultInfo->precision = pRsp->precision; + pResultInfo->precision = pRsp->precision; // TODO handle the compressed case pResultInfo->totalRows += pResultInfo->numOfRows; - return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows, convertUcs4); + return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows, + convertUcs4); } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 51629510d0..040ddde630 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -71,7 +71,7 @@ void taos_cleanup(void) { tscInfo("all local resources released"); } -setConfRet taos_set_config(const char *config) { +setConfRet taos_set_config(const char *config) { // TODO setConfRet ret = {SET_CONF_RET_SUCC, {0}}; return ret; @@ -133,8 +133,7 @@ int taos_field_count(TAOS_RES *res) { return 0; } - SRequestObj *pRequest = (SRequestObj *)res; - SReqResultInfo *pResInfo = &pRequest->body.resInfo; + SReqResultInfo *pResInfo = tscGetCurResInfo(res); return pResInfo->numOfCols; } @@ -145,7 +144,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { return NULL; } - SReqResultInfo *pResInfo = &(((SRequestObj *)res)->body.resInfo); + SReqResultInfo *pResInfo = tscGetCurResInfo(res); return pResInfo->userFields; } @@ -162,13 +161,36 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return NULL; } - SRequestObj *pRequest = (SRequestObj *)res; - if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || - pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { - return NULL; - } + if (TD_RES_QUERY(res)) { + SRequestObj *pRequest = (SRequestObj *)res; + if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { + return NULL; + } - return doFetchRow(pRequest, true, true); + return doFetchRow(pRequest, true, true); + + } else if (TD_RES_TMQ(res)) { + SMqRspObj *msg = ((SMqRspObj *)res); + SReqResultInfo *pResultInfo = taosArrayGet(msg->res, msg->resIter); + + doSetOneRowPtr(pResultInfo); + pResultInfo->current += 1; + + if (pResultInfo->row == NULL) { + msg->resIter++; + pResultInfo = taosArrayGet(msg->res, msg->resIter); + doSetOneRowPtr(pResultInfo); + pResultInfo->current += 1; + } + + return pResultInfo->row; + + } else { + // assert to avoid uninitialization error + ASSERT(0); + } + return NULL; } int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) { @@ -260,12 +282,12 @@ int *taos_fetch_lengths(TAOS_RES *res) { return NULL; } - return ((SRequestObj *)res)->body.resInfo.length; + SReqResultInfo *pResInfo = tscGetCurResInfo(res); + return pResInfo->length; } TAOS_ROW *taos_result_block(TAOS_RES *res) { - SRequestObj* pRequest = (SRequestObj*) res; - if (pRequest == NULL) { + if (res == NULL) { terrno = TSDB_CODE_INVALID_PARA; return NULL; } @@ -274,7 +296,8 @@ TAOS_ROW *taos_result_block(TAOS_RES *res) { return NULL; } - return &pRequest->body.resInfo.row; + SReqResultInfo *pResInfo = tscGetCurResInfo(res); + return &pResInfo->row; } // todo intergrate with tDataTypes @@ -313,7 +336,7 @@ const char *taos_data_type(int type) { const char *taos_get_client_info() { return version; } int taos_affected_rows(TAOS_RES *res) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ(res)) { return 0; } @@ -323,12 +346,17 @@ int taos_affected_rows(TAOS_RES *res) { } int taos_result_precision(TAOS_RES *res) { - SRequestObj* pRequest = (SRequestObj*) res; - if (pRequest == NULL) { + if (res == NULL) { return TSDB_TIME_PRECISION_MILLI; } - - return pRequest->body.resInfo.precision; + if (TD_RES_QUERY(res)) { + SRequestObj *pRequest = (SRequestObj *)res; + return pRequest->body.resInfo.precision; + } else if (TD_RES_TMQ(res)) { + SReqResultInfo *info = tmqGetCurResInfo(res); + return info->precision; + } + return TSDB_TIME_PRECISION_MILLI; } int taos_select_db(TAOS *taos, const char *db) { @@ -370,90 +398,115 @@ void taos_stop_query(TAOS_RES *res) { } bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { - SRequestObj *pRequestObj = res; - SReqResultInfo *pResultInfo = &pRequestObj->body.resInfo; + SReqResultInfo *pResultInfo = tscGetCurResInfo(res); if (col >= pResultInfo->numOfCols || col < 0 || row >= pResultInfo->numOfRows || row < 0) { return true; } - SResultColumn *pCol = &pRequestObj->body.resInfo.pCol[col]; + SResultColumn *pCol = &pResultInfo->pCol[col]; return colDataIsNull_f(pCol->nullbitmap, row); } -bool taos_is_update_query(TAOS_RES *res) { - return taos_num_fields(res) == 0; -} +bool taos_is_update_query(TAOS_RES *res) { return taos_num_fields(res) == 0; } int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int32_t numOfRows = 0; - /*int32_t code = */taos_fetch_block_s(res, &numOfRows, rows); + /*int32_t code = */ taos_fetch_block_s(res, &numOfRows, rows); return numOfRows; } -int taos_fetch_block_s(TAOS_RES *res, int* numOfRows, TAOS_ROW *rows) { - SRequestObj *pRequest = (SRequestObj *)res; - if (pRequest == NULL) { +int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { + if (res == NULL) { return 0; } + if (TD_RES_QUERY(res)) { + SRequestObj *pRequest = (SRequestObj *)res; - (*rows) = NULL; - (*numOfRows) = 0; + (*rows) = NULL; + (*numOfRows) = 0; - if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || - pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { + if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { + return 0; + } + + doFetchRow(pRequest, false, true); + + // TODO refactor + SReqResultInfo *pResultInfo = &pRequest->body.resInfo; + pResultInfo->current = pResultInfo->numOfRows; + + (*rows) = pResultInfo->row; + (*numOfRows) = pResultInfo->numOfRows; + return pRequest->code; + } else if (TD_RES_TMQ(res)) { + SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); + if (pResultInfo == NULL) return -1; + + pResultInfo->current = pResultInfo->numOfRows; + (*rows) = pResultInfo->row; + (*numOfRows) = pResultInfo->numOfRows; return 0; + } else { + ASSERT(0); + return -1; } - - doFetchRow(pRequest, false, true); - - // TODO refactor - SReqResultInfo *pResultInfo = &pRequest->body.resInfo; - pResultInfo->current = pResultInfo->numOfRows; - - (*rows) = pResultInfo->row; - (*numOfRows) = pResultInfo->numOfRows; - return pRequest->code; } -int taos_fetch_raw_block(TAOS_RES *res, int* numOfRows, void** pData) { - SRequestObj *pRequest = (SRequestObj *)res; - if (pRequest == NULL) { +int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { + if (res == NULL) { return 0; } + if (TD_RES_QUERY(res)) { + SRequestObj *pRequest = (SRequestObj *)res; + + if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { + return 0; + } + + doFetchRow(pRequest, false, false); + + SReqResultInfo *pResultInfo = &pRequest->body.resInfo; + + pResultInfo->current = pResultInfo->numOfRows; + (*numOfRows) = pResultInfo->numOfRows; + (*pData) = (void *)pResultInfo->pData; - if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || - pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { return 0; + + } else if (TD_RES_TMQ(res)) { + SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); + if (pResultInfo == NULL) return -1; + + pResultInfo->current = pResultInfo->numOfRows; + (*numOfRows) = pResultInfo->numOfRows; + (*pData) = (void *)pResultInfo->pData; + return 0; + + } else { + ASSERT(0); + return -1; } - - doFetchRow(pRequest, false, false); - - SReqResultInfo *pResultInfo = &pRequest->body.resInfo; - - pResultInfo->current = pResultInfo->numOfRows; - (*numOfRows) = pResultInfo->numOfRows; - (*pData) = (void*) pResultInfo->pData; - - return 0; } int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { - SRequestObj *pRequest = (SRequestObj *)res; - if (pRequest == NULL) { + if (res == NULL) { return 0; } - int32_t numOfFields = taos_num_fields(pRequest); + int32_t numOfFields = taos_num_fields(res); if (columnIndex < 0 || columnIndex >= numOfFields || numOfFields == 0) { return 0; } - TAOS_FIELD* pField = &pRequest->body.resInfo.userFields[columnIndex]; + SReqResultInfo *pResInfo = tscGetCurResInfo(res); + TAOS_FIELD *pField = &pResInfo->userFields[columnIndex]; if (!IS_VAR_DATA_TYPE(pField->type)) { return 0; } - return pRequest->body.resInfo.pCol[columnIndex].offset; + return pResInfo->pCol[columnIndex].offset; } int taos_validate_sql(TAOS *taos, const char *sql) { return true; } @@ -483,18 +536,19 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { // TODO } -TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) { - // TODO - return NULL; +TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, + void *param, int interval) { + // TODO + return NULL; } TAOS_RES *taos_consume(TAOS_SUB *tsub) { - // TODO - return NULL; + // TODO + return NULL; } void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { - // TODO + // TODO } int taos_load_table_info(TAOS *taos, const char *tableNameList) { @@ -553,26 +607,26 @@ int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) { } int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) { - // TODO - return -1; + // TODO + return -1; } int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) { - // TODO - return -1; + // TODO + return -1; } -int taos_stmt_add_batch(TAOS_STMT* stmt) { - // TODO - return -1; +int taos_stmt_add_batch(TAOS_STMT *stmt) { + // TODO + return -1; } TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) { - // TODO - return NULL; + // TODO + return NULL; } -int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) { - // TODO - return -1; +int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { + // TODO + return -1; } diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 955e25fd71..dbe78782f5 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -17,25 +17,19 @@ #include "clientLog.h" #include "parser.h" #include "planner.h" -#include "scheduler.h" #include "tdatablock.h" #include "tdef.h" #include "tglobal.h" #include "tmsgtype.h" -#include "tpagedbuf.h" #include "tqueue.h" #include "tref.h" -typedef struct { - int32_t curBlock; - int32_t curRow; - void** uData; -} SMqRowIter; - struct tmq_message_t { SMqPollRsp msg; + char* topic; void* vg; - SMqRowIter iter; + SArray* res; // SArray + int32_t resIter; }; struct tmq_list_t { @@ -849,7 +843,8 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { if (msgEpoch < tmqEpoch) { /*printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch);*/ /*tsem_post(&tmq->rspSem);*/ - tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", pParam->vgId, msgEpoch, tmqEpoch); + tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", pParam->vgId, msgEpoch, + tmqEpoch); return 0; } @@ -886,8 +881,8 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { } memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead)); tDecodeSMqPollRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->msg); - pRsp->iter.curBlock = 0; - pRsp->iter.curRow = 0; + /*pRsp->iter.curBlock = 0;*/ + /*pRsp->iter.curRow = 0;*/ // TODO: alloc mem /*pRsp->*/ /*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/ @@ -899,8 +894,8 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { } #endif - tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pParam->pVg->vgId, pRsp->msg.reqOffset, - pRsp->msg.rspOffset); + tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pParam->pVg->vgId, + pRsp->msg.reqOffset, pRsp->msg.rspOffset); pRsp->vg = pParam->pVg; taosWriteQitem(tmq->mqueue, pRsp); @@ -921,7 +916,8 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { bool set = false; int32_t topicNumGet = taosArrayGetSize(pRsp->topics); char vgKey[TSDB_TOPIC_FNAME_LEN + 22]; - tscDebug("consumer %ld update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch, topicNumGet); + tscDebug("consumer %ld update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch, + topicNumGet); SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic)); if (newTopics == NULL) { return false; @@ -1289,7 +1285,8 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { int64_t transporterId = 0; /*printf("send poll\n");*/ atomic_add_fetch_32(&tmq->waitingRequest, 1); - tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId, pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId); + tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId, + pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId); /*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/ asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo); pVg->pollCnt++; @@ -1566,30 +1563,4 @@ const char* tmq_err2str(tmq_resp_err_t err) { return "fail"; } -TAOS_ROW tmq_get_row(tmq_message_t* message) { - SMqPollRsp* rsp = &message->msg; - while (1) { - if (message->iter.curBlock < taosArrayGetSize(rsp->pBlockData)) { - SSDataBlock* pBlock = taosArrayGet(rsp->pBlockData, message->iter.curBlock); - if (message->iter.curRow < pBlock->info.rows) { - for (int i = 0; i < pBlock->info.numOfCols; i++) { - SColumnInfoData* pData = taosArrayGet(pBlock->pDataBlock, i); - if (colDataIsNull_s(pData, message->iter.curRow)) - message->iter.uData[i] = NULL; - else { - message->iter.uData[i] = colDataGetData(pData, message->iter.curRow); - } - } - message->iter.curRow++; - return message->iter.uData; - } else { - message->iter.curBlock++; - message->iter.curRow = 0; - continue; - } - } - return NULL; - } -} - char* tmq_get_topic_name(tmq_message_t* message) { return "not implemented yet"; } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 0bc1fa09f5..58bc7235a1 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -256,7 +256,7 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e return 0; } -static int32_t taosAddClientLogCfg(SConfig *pCfg) { +int32_t taosAddClientLogCfg(SConfig *pCfg) { if (cfgAddDir(pCfg, "configDir", configDir, 1) != 0) return -1; if (cfgAddDir(pCfg, "scriptDir", configDir, 1) != 0) return -1; if (cfgAddDir(pCfg, "logDir", tsLogDir, 1) != 0) return -1; @@ -616,7 +616,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32); - if (taosMkDir(tsLogDir) != 0) { + if (taosMulMkDir(tsLogDir) != 0) { uError("failed to create dir:%s since %s", tsLogDir, terrstr()); cfgCleanup(pCfg); return -1; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 83f8646364..0e0ed0fd15 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -308,6 +308,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nTagCols); for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) { tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type); + tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].index); tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pTagSchema[i].colId); tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes); tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name); @@ -378,6 +379,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { pReq->stbCfg.pTagSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nTagCols * sizeof(SSchema)); for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) { buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type)); + buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].index)); buf = taosDecodeFixedI16(buf, &pReq->stbCfg.pTagSchema[i].colId); buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name); @@ -1991,7 +1993,7 @@ void tFreeSUseDbBatchRsp(SUseDbBatchRsp *pRsp) { taosArrayDestroy(pRsp->pArray); } -int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { +int32_t tSerializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2004,7 +2006,7 @@ int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { return tlen; } -int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { +int32_t tDeserializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2016,7 +2018,7 @@ int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { return 0; } -int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp) { +int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2047,7 +2049,7 @@ int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp) { return tlen; } -int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp) { +int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2078,7 +2080,7 @@ int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp) { return 0; } -int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq) { +int32_t tSerializeSUserIndexReq(void *buf, int32_t bufLen, SUserIndexReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2091,7 +2093,7 @@ int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq) return tlen; } -int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq) { +int32_t tDeserializeSUserIndexReq(void *buf, int32_t bufLen, SUserIndexReq *pReq) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2103,7 +2105,7 @@ int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq return 0; } -int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp) { +int32_t tSerializeSUserIndexRsp(void *buf, int32_t bufLen, const SUserIndexRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2120,7 +2122,7 @@ int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* return tlen; } -int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp) { +int32_t tDeserializeSUserIndexRsp(void *buf, int32_t bufLen, SUserIndexRsp *pRsp) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2136,7 +2138,6 @@ int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp return 0; } - int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index a65352f2b9..1baf393e9a 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -406,7 +406,31 @@ int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char default: { return -1; } - } + } +} + +int32_t convertStringToTimestamp(int16_t type, char *inputData, int64_t timePrec, int64_t *timeVal) { + int32_t charLen = varDataLen(inputData); + char *newColData; + if (type == TSDB_DATA_TYPE_BINARY) { + newColData = taosMemoryCalloc(1, charLen + 1); + memcpy(newColData, varDataVal(inputData), charLen); + taosParseTime(newColData, timeVal, charLen, (int32_t)timePrec, 0); + taosMemoryFree(newColData); + } else if (type == TSDB_DATA_TYPE_NCHAR) { + newColData = taosMemoryCalloc(1, charLen / TSDB_NCHAR_SIZE + 1); + int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inputData), charLen, newColData); + if (len < 0){ + taosMemoryFree(newColData); + return TSDB_CODE_FAILED; + } + newColData[len] = 0; + taosParseTime(newColData, timeVal, len + 1, (int32_t)timePrec, 0); + taosMemoryFree(newColData); + } else { + return TSDB_CODE_FAILED; + } + return TSDB_CODE_SUCCESS; } static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) { diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c index 8c5010e577..a0503e43a1 100644 --- a/source/common/src/tvariant.c +++ b/source/common/src/tvariant.c @@ -1028,13 +1028,18 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type) { char * taosVariantGet(SVariant *pVar, int32_t type) { switch (type) { - case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_TIMESTAMP: return (char *)&pVar->i; + case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_USMALLINT: + case TSDB_DATA_TYPE_UINT: + case TSDB_DATA_TYPE_UBIGINT: + return (char *)&pVar->u; case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_FLOAT: return (char *)&pVar->d; @@ -1042,7 +1047,7 @@ char * taosVariantGet(SVariant *pVar, int32_t type) { return (char *)pVar->pz; case TSDB_DATA_TYPE_NCHAR: return (char *)pVar->ucs4; - default: + default: return NULL; } diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 12de4103a4..e67c54aa85 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "dmImp.h" #include "tconfig.h" +#include "tgrant.h" static struct { bool dumpConfig; @@ -89,10 +90,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { return 0; } -static void dmGenerateGrant() { - // grantParseParameter(); - printf("this feature is not implemented yet\n"); -} +static void dmGenerateGrant() { grantParseParameter(); } static void dmPrintVersion() { #ifdef TD_ENTERPRISE diff --git a/source/dnode/mgmt/implement/CMakeLists.txt b/source/dnode/mgmt/implement/CMakeLists.txt index fbe7530395..26c14edc77 100644 --- a/source/dnode/mgmt/implement/CMakeLists.txt +++ b/source/dnode/mgmt/implement/CMakeLists.txt @@ -6,4 +6,12 @@ target_link_libraries( target_include_directories( dnode PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" -) \ No newline at end of file +) + +IF (TD_GRANT) + TARGET_LINK_LIBRARIES(dnode grant) +ENDIF () +IF (TD_USB_DONGLE) + TARGET_LINK_LIBRARIES(dnode usb_dongle) +else() +ENDIF () \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndGrant.c b/source/dnode/mnode/impl/src/mndGrant.c new file mode 100644 index 0000000000..cdf3271789 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndGrant.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#ifndef _GRANT +#include "os.h" +#include "taoserror.h" +#include "tgrant.h" +#include "mndInt.h" + +int32_t grantInit() { return TSDB_CODE_SUCCESS; } +void grantCleanUp() {} +void grantParseParameter() { mError("can't parsed parameter k"); } +int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; } +void grantReset(EGrantType grant, uint64_t value) {} +void grantAdd(EGrantType grant, uint64_t value) {} +void grantRestore(EGrantType grant, uint64_t value) {} + +#endif \ No newline at end of file diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index b5fe7d460f..bd2e4213d5 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -55,6 +55,8 @@ target_include_directories( vnode PUBLIC "inc" PRIVATE "src/inc" + PUBLIC "${TD_SOURCE_DIR}/include/libs/scalar" + ) target_link_libraries( vnode @@ -69,6 +71,7 @@ target_link_libraries( PUBLIC scheduler PUBLIC tdb #PUBLIC bdb + #PUBLIC scalar PUBLIC transport PUBLIC stream ) diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index c78691e7c2..e3acba7eb6 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -25,18 +25,18 @@ typedef struct SPoolMem { static SPoolMem *openPool(); static void clearPool(SPoolMem *pPool); static void closePool(SPoolMem *pPool); -static void *poolMalloc(void *arg, size_t size); +static void * poolMalloc(void *arg, size_t size); static void poolFree(void *arg, void *ptr); struct SMetaDB { TXN txn; - TENV *pEnv; - TDB *pTbDB; - TDB *pSchemaDB; - TDB *pNameIdx; - TDB *pStbIdx; - TDB *pNtbIdx; - TDB *pCtbIdx; + TENV * pEnv; + TDB * pTbDB; + TDB * pSchemaDB; + TDB * pNameIdx; + TDB * pStbIdx; + TDB * pNtbIdx; + TDB * pCtbIdx; SPoolMem *pPool; }; @@ -46,7 +46,7 @@ typedef struct __attribute__((__packed__)) { } SSchemaDbKey; typedef struct { - char *name; + char * name; tb_uid_t uid; } SNameIdxKey; @@ -205,14 +205,14 @@ void metaCloseDB(SMeta *pMeta) { int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { tb_uid_t uid; - SMetaDB *pMetaDb; - void *pKey; - void *pVal; + SMetaDB * pMetaDb; + void * pKey; + void * pVal; int kLen; int vLen; int ret; char buf[512]; - void *pBuf; + void * pBuf; SCtbIdxKey ctbIdxKey; SSchemaDbKey schemaDbKey; SSchemaWrapper schemaWrapper; @@ -329,11 +329,11 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) { STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { int ret; SMetaDB *pMetaDb = pMeta->pDB; - void *pKey; - void *pVal; + void * pKey; + void * pVal; int kLen; int vLen; - STbCfg *pTbCfg; + STbCfg * pTbCfg; // Fetch pKey = &uid; @@ -385,14 +385,14 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo } static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx) { - void *pKey; - void *pVal; + void * pKey; + void * pVal; int kLen; int vLen; int ret; SSchemaDbKey schemaDbKey; SSchemaWrapper *pSchemaWrapper; - void *pBuf; + void * pBuf; // fetch schemaDbKey.uid = uid; @@ -419,9 +419,9 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { tb_uid_t quid; SSchemaWrapper *pSW; STSchemaBuilder sb; - SSchemaEx *pSchema; - STSchema *pTSchema; - STbCfg *pTbCfg; + SSchemaEx * pSchema; + STSchema * pTSchema; + STbCfg * pTbCfg; pTbCfg = metaGetTbInfoByUid(pMeta, uid); if (pTbCfg->type == META_CHILD_TABLE) { @@ -452,7 +452,7 @@ struct SMTbCursor { SMTbCursor *metaOpenTbCursor(SMeta *pMeta) { SMTbCursor *pTbCur = NULL; - SMetaDB *pDB = pMeta->pDB; + SMetaDB * pDB = pMeta->pDB; pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur)); if (pTbCur == NULL) { @@ -474,12 +474,12 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) { } char *metaTbCursorNext(SMTbCursor *pTbCur) { - void *pKey = NULL; - void *pVal = NULL; + void * pKey = NULL; + void * pVal = NULL; int kLen; int vLen; int ret; - void *pBuf; + void * pBuf; STbCfg tbCfg; for (;;) { @@ -503,17 +503,17 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) { } struct SMCtbCursor { - TDBC *pCur; + TDBC * pCur; tb_uid_t suid; - void *pKey; - void *pVal; + void * pKey; + void * pVal; int kLen; int vLen; }; SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { SMCtbCursor *pCtbCur = NULL; - SMetaDB *pDB = pMeta->pDB; + SMetaDB * pDB = pMeta->pDB; int ret; pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur)); @@ -621,6 +621,7 @@ static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) { for (int i = 0; i < pSW->nCols; i++) { pSchema = pSW->pSchema + i; tlen += taosEncodeFixedI8(buf, pSchema->type); + tlen += taosEncodeFixedI8(buf, pSchema->index); tlen += taosEncodeFixedI16(buf, pSchema->colId); tlen += taosEncodeFixedI32(buf, pSchema->bytes); tlen += taosEncodeString(buf, pSchema->name); @@ -637,6 +638,7 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { for (int i = 0; i < pSW->nCols; i++) { pSchema = pSW->pSchema + i; buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosSkipFixedLen(buf, sizeof(int8_t)); buf = taosDecodeFixedI16(buf, &pSchema->colId); buf = taosDecodeFixedI32(buf, &pSchema->bytes); buf = taosDecodeStringTo(buf, pSchema->name); @@ -781,7 +783,7 @@ static void closePool(SPoolMem *pPool) { } static void *poolMalloc(void *arg, size_t size) { - void *ptr = NULL; + void * ptr = NULL; SPoolMem *pPool = (SPoolMem *)arg; SPoolMem *pMem; diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index e308c9c2b9..550e7cd183 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -13,21 +13,22 @@ * along with this program. If not, see . */ -#include "vnodeInt.h" -#include "tdatablock.h" #include "os.h" #include "talgo.h" #include "tcompare.h" +#include "tdatablock.h" #include "tdataformat.h" #include "texception.h" +#include "vnodeInt.h" +#include "filter.h" #include "taosdef.h" #include "tlosertree.h" -#include "vnodeInt.h" #include "tmsg.h" +#include "vnodeInt.h" -#define EXTRA_BYTES 2 -#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) +#define EXTRA_BYTES 2 +#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) #define QH_GET_NUM_OF_COLS(handle) ((size_t)(taosArrayGetSize((handle)->pColumns))) #define GET_FILE_DATA_BLOCK_INFO(_checkInfo, _block) \ @@ -37,32 +38,32 @@ .uid = (_checkInfo)->tableId}) enum { - TSDB_QUERY_TYPE_ALL = 1, - TSDB_QUERY_TYPE_LAST = 2, + TSDB_QUERY_TYPE_ALL = 1, + TSDB_QUERY_TYPE_LAST = 2, }; enum { - TSDB_CACHED_TYPE_NONE = 0, + TSDB_CACHED_TYPE_NONE = 0, TSDB_CACHED_TYPE_LASTROW = 1, - TSDB_CACHED_TYPE_LAST = 2, + TSDB_CACHED_TYPE_LAST = 2, }; typedef struct SQueryFilePos { - int32_t fid; - int32_t slot; - int32_t pos; - int64_t lastKey; - int32_t rows; - bool mixBlock; - bool blockCompleted; + int32_t fid; + int32_t slot; + int32_t pos; + int64_t lastKey; + int32_t rows; + bool mixBlock; + bool blockCompleted; STimeWindow win; } SQueryFilePos; typedef struct SDataBlockLoadInfo { - SDFileSet* fileGroup; - int32_t slot; - uint64_t uid; - SArray* pLoadedCols; + SDFileSet* fileGroup; + int32_t slot; + uint64_t uid; + SArray* pLoadedCols; } SDataBlockLoadInfo; typedef struct SLoadCompBlockInfo { @@ -71,33 +72,33 @@ typedef struct SLoadCompBlockInfo { } SLoadCompBlockInfo; enum { - CHECKINFO_CHOSEN_MEM = 0, + CHECKINFO_CHOSEN_MEM = 0, CHECKINFO_CHOSEN_IMEM = 1, - CHECKINFO_CHOSEN_BOTH = 2 //for update=2(merge case) + CHECKINFO_CHOSEN_BOTH = 2 // for update=2(merge case) }; typedef struct STableCheckInfo { - uint64_t tableId; - TSKEY lastKey; - SBlockInfo* pCompInfo; - int32_t compSize; - int32_t numOfBlocks:29; // number of qualified data blocks not the original blocks - uint8_t chosen:2; // indicate which iterator should move forward - bool initBuf:1; // whether to initialize the in-memory skip list iterator or not - SSkipListIterator* iter; // mem buffer skip list iterator - SSkipListIterator* iiter; // imem buffer skip list iterator + uint64_t tableId; + TSKEY lastKey; + SBlockInfo* pCompInfo; + int32_t compSize; + int32_t numOfBlocks : 29; // number of qualified data blocks not the original blocks + uint8_t chosen : 2; // indicate which iterator should move forward + bool initBuf : 1; // whether to initialize the in-memory skip list iterator or not + SSkipListIterator* iter; // mem buffer skip list iterator + SSkipListIterator* iiter; // imem buffer skip list iterator } STableCheckInfo; typedef struct STableBlockInfo { - SBlock *compBlock; - STableCheckInfo *pTableCheckInfo; + SBlock* compBlock; + STableCheckInfo* pTableCheckInfo; } STableBlockInfo; typedef struct SBlockOrderSupporter { - int32_t numOfTables; - STableBlockInfo** pDataBlockInfo; - int32_t* blockIndexArray; - int32_t* numOfBlocksPerTable; + int32_t numOfTables; + STableBlockInfo** pDataBlockInfo; + int32_t* blockIndexArray; + int32_t* numOfBlocksPerTable; } SBlockOrderSupporter; typedef struct SIOCostSummary { @@ -109,37 +110,37 @@ typedef struct SIOCostSummary { } SIOCostSummary; typedef struct STsdbReadHandle { - STsdb* pTsdb; - SQueryFilePos cur; // current position - int16_t order; - STimeWindow window; // the primary query time window that applies to all queries - SDataStatis* statis; // query level statistics, only one table block statistics info exists at any time - int32_t numOfBlocks; - SArray* pColumns; // column list, SColumnInfoData array list - bool locateStart; - int32_t outputCapacity; - int32_t realNumOfRows; - SArray* pTableCheckInfo; // SArray - int32_t activeIndex; - bool checkFiles; // check file stage - int8_t cachelastrow; // check if last row cached - bool loadExternalRow; // load time window external data rows - bool currentLoadExternalRows; // current load external rows - int32_t loadType; // block load type - char *idStr; // query info handle, for debug purpose - int32_t type; // query type: retrieve all data blocks, 2. retrieve only last row, 3. retrieve direct prev|next rows - SDFileSet* pFileGroup; - SFSIter fileIter; - SReadH rhelper; - STableBlockInfo* pDataBlockInfo; - SDataCols *pDataCols; // in order to hold current file data block - int32_t allocSize; // allocated data block size - SArray *defaultLoadColumn;// default load column - SDataBlockLoadInfo dataBlockLoadInfo; /* record current block load information */ - SLoadCompBlockInfo compBlockLoadInfo; /* record current compblock information in SQueryAttr */ + STsdb* pTsdb; + SQueryFilePos cur; // current position + int16_t order; + STimeWindow window; // the primary query time window that applies to all queries + SDataStatis* statis; // query level statistics, only one table block statistics info exists at any time + int32_t numOfBlocks; + SArray* pColumns; // column list, SColumnInfoData array list + bool locateStart; + int32_t outputCapacity; + int32_t realNumOfRows; + SArray* pTableCheckInfo; // SArray + int32_t activeIndex; + bool checkFiles; // check file stage + int8_t cachelastrow; // check if last row cached + bool loadExternalRow; // load time window external data rows + bool currentLoadExternalRows; // current load external rows + int32_t loadType; // block load type + char* idStr; // query info handle, for debug purpose + int32_t type; // query type: retrieve all data blocks, 2. retrieve only last row, 3. retrieve direct prev|next rows + SDFileSet* pFileGroup; + SFSIter fileIter; + SReadH rhelper; + STableBlockInfo* pDataBlockInfo; + SDataCols* pDataCols; // in order to hold current file data block + int32_t allocSize; // allocated data block size + SArray* defaultLoadColumn; // default load column + SDataBlockLoadInfo dataBlockLoadInfo; /* record current block load information */ + SLoadCompBlockInfo compBlockLoadInfo; /* record current compblock information in SQueryAttr */ - SArray *prev; // previous row which is before than time window - SArray *next; // next row which is after the query time window + SArray* prev; // previous row which is before than time window + SArray* next; // next row which is after the query time window SIOCostSummary cost; } STsdbReadHandle; @@ -149,24 +150,27 @@ typedef struct STableGroupSupporter { SSchema* pTagSchema; } STableGroupSupporter; -static STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList); -static int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo *groupList); -static int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle); +int32_t tsdbQueryTableList(void* pMeta, SArray* pRes, void* filterInfo); + +static STimeWindow updateLastrowForEachGroup(STableGroupInfo* groupList); +static int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo* groupList); +static int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle); // static int32_t tsdbGetCachedLastRow(STable* pTable, STSRow** pRes, TSKEY* lastKey); static void changeQueryHandleForInterpQuery(tsdbReaderT pHandle); static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock); static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); -static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, STsdbReadHandle* pTsdbReadHandle); +static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, + STsdbReadHandle* pTsdbReadHandle); static int32_t tsdbCheckInfoCompar(const void* key1, const void* key2); -//static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, void* pMemRef); -//static void* doFreeColumnInfoData(SArray* pColumnInfoData); -//static void* destroyTableCheckInfo(SArray* pTableCheckInfo); -static bool tsdbGetExternalRow(tsdbReaderT pHandle); +// static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, void* pMemRef); +// static void* doFreeColumnInfoData(SArray* pColumnInfoData); +// static void* destroyTableCheckInfo(SArray* pTableCheckInfo); +static bool tsdbGetExternalRow(tsdbReaderT pHandle); static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) { pBlockLoadInfo->slot = -1; - pBlockLoadInfo->uid = 0; + pBlockLoadInfo->uid = 0; pBlockLoadInfo->fileGroup = NULL; } @@ -204,30 +208,32 @@ static SArray* getDefaultLoadColumns(STsdbReadHandle* pTsdbReadHandle, bool load } int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - int64_t rows = 0; - STsdbMemTable* pMemTable = NULL;//pTsdbReadHandle->pMemTable; - if (pMemTable == NULL) { return rows; } + int64_t rows = 0; + STsdbMemTable* pMemTable = NULL; // pTsdbReadHandle->pMemTable; + if (pMemTable == NULL) { + return rows; + } -// STableData* pMem = NULL; -// STableData* pIMem = NULL; + // STableData* pMem = NULL; + // STableData* pIMem = NULL; -// SMemTable* pMemT = pMemRef->snapshot.mem; -// SMemTable* pIMemT = pMemRef->snapshot.imem; + // SMemTable* pMemT = pMemRef->snapshot.mem; + // SMemTable* pIMemT = pMemRef->snapshot.imem; size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); for (int32_t i = 0; i < size; ++i) { STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); -// if (pMemT && pCheckInfo->tableId < pMemT->maxTables) { -// pMem = pMemT->tData[pCheckInfo->tableId]; -// rows += (pMem && pMem->uid == pCheckInfo->tableId) ? pMem->numOfRows : 0; -// } -// if (pIMemT && pCheckInfo->tableId < pIMemT->maxTables) { -// pIMem = pIMemT->tData[pCheckInfo->tableId]; -// rows += (pIMem && pIMem->uid == pCheckInfo->tableId) ? pIMem->numOfRows : 0; -// } + // if (pMemT && pCheckInfo->tableId < pMemT->maxTables) { + // pMem = pMemT->tData[pCheckInfo->tableId]; + // rows += (pMem && pMem->uid == pCheckInfo->tableId) ? pMem->numOfRows : 0; + // } + // if (pIMemT && pCheckInfo->tableId < pIMemT->maxTables) { + // pIMem = pIMemT->tData[pCheckInfo->tableId]; + // rows += (pIMem && pIMem->uid == pCheckInfo->tableId) ? pIMem->numOfRows : 0; + // } } return rows; } @@ -244,15 +250,15 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S // todo apply the lastkey of table check to avoid to load header file for (int32_t i = 0; i < numOfGroup; ++i) { - SArray* group = *(SArray**) taosArrayGet(pGroupList->pGroupList, i); + SArray* group = *(SArray**)taosArrayGet(pGroupList->pGroupList, i); size_t gsize = taosArrayGetSize(group); assert(gsize > 0); for (int32_t j = 0; j < gsize; ++j) { - STableKeyInfo* pKeyInfo = (STableKeyInfo*) taosArrayGet(group, j); + STableKeyInfo* pKeyInfo = (STableKeyInfo*)taosArrayGet(group, j); - STableCheckInfo info = { .lastKey = pKeyInfo->lastKey, .tableId = pKeyInfo->uid}; + STableCheckInfo info = {.lastKey = pKeyInfo->lastKey, .tableId = pKeyInfo->uid}; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { if (info.lastKey == INT64_MIN || info.lastKey < pTsdbReadHandle->window.skey) { info.lastKey = pTsdbReadHandle->window.skey; @@ -264,7 +270,8 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S } taosArrayPush(pTableCheckInfo, &info); - tsdbDebug("%p check table uid:%"PRId64" from lastKey:%"PRId64" %s", pTsdbReadHandle, info.tableId, info.lastKey, pTsdbReadHandle->idStr); + tsdbDebug("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReadHandle, info.tableId, + info.lastKey, pTsdbReadHandle->idStr); } } @@ -279,10 +286,10 @@ static void resetCheckInfo(STsdbReadHandle* pTsdbReadHandle) { // todo apply the lastkey of table check to avoid to load header file for (int32_t i = 0; i < numOfTables; ++i) { - STableCheckInfo* pCheckInfo = (STableCheckInfo*) taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); + STableCheckInfo* pCheckInfo = (STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); pCheckInfo->lastKey = pTsdbReadHandle->window.skey; - pCheckInfo->iter = tSkipListDestroyIter(pCheckInfo->iter); - pCheckInfo->iiter = tSkipListDestroyIter(pCheckInfo->iiter); + pCheckInfo->iter = tSkipListDestroyIter(pCheckInfo->iter); + pCheckInfo->iiter = tSkipListDestroyIter(pCheckInfo->iiter); pCheckInfo->initBuf = false; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { @@ -297,7 +304,7 @@ static void resetCheckInfo(STsdbReadHandle* pTsdbReadHandle) { static SArray* createCheckInfoFromCheckInfo(STableCheckInfo* pCheckInfo, TSKEY skey, SArray** psTable) { SArray* pNew = taosArrayInit(1, sizeof(STableCheckInfo)); - STableCheckInfo info = { .lastKey = skey}; + STableCheckInfo info = {.lastKey = skey}; info.tableId = pCheckInfo->tableId; taosArrayPush(pNew, &info); @@ -308,7 +315,7 @@ static bool emptyQueryTimewindow(STsdbReadHandle* pTsdbReadHandle) { assert(pTsdbReadHandle != NULL); STimeWindow* w = &pTsdbReadHandle->window; - bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); return ((asc && w->skey > w->ekey) || (!asc && w->ekey > w->skey)); } @@ -354,23 +361,23 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, goto _end; } - pReadHandle->order = pCond->order; - pReadHandle->pTsdb = tsdb; - pReadHandle->type = TSDB_QUERY_TYPE_ALL; - pReadHandle->cur.fid = INT32_MIN; - pReadHandle->cur.win = TSWINDOW_INITIALIZER; - pReadHandle->checkFiles = true; - pReadHandle->activeIndex = 0; // current active table index - pReadHandle->allocSize = 0; + pReadHandle->order = pCond->order; + pReadHandle->pTsdb = tsdb; + pReadHandle->type = TSDB_QUERY_TYPE_ALL; + pReadHandle->cur.fid = INT32_MIN; + pReadHandle->cur.win = TSWINDOW_INITIALIZER; + pReadHandle->checkFiles = true; + pReadHandle->activeIndex = 0; // current active table index + pReadHandle->allocSize = 0; pReadHandle->locateStart = false; - pReadHandle->loadType = pCond->type; + pReadHandle->loadType = pCond->type; - pReadHandle->outputCapacity = 4096;//((STsdb*)tsdb)->config.maxRowsPerFileBlock; + pReadHandle->outputCapacity = 4096; //((STsdb*)tsdb)->config.maxRowsPerFileBlock; pReadHandle->loadExternalRow = pCond->loadExternalRows; pReadHandle->currentLoadExternalRows = pCond->loadExternalRows; char buf[128] = {0}; - snprintf(buf, tListLen(buf), "TID:0x%"PRIx64" QID:0x%"PRIx64, taskId, qId); + snprintf(buf, tListLen(buf), "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, qId); pReadHandle->idStr = strdup(buf); if (tsdbInitReadH(&pReadHandle->rhelper, (STsdb*)tsdb) != 0) { @@ -421,37 +428,39 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, return (tsdbReaderT)pReadHandle; - _end: +_end: tsdbCleanupReadHandle(pReadHandle); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; } -tsdbReaderT* tsdbQueryTables(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, uint64_t taskId) { +tsdbReaderT* tsdbQueryTables(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, + uint64_t taskId) { STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(tsdb, pCond, qId, taskId); if (pTsdbReadHandle == NULL) { return NULL; } if (emptyQueryTimewindow(pTsdbReadHandle)) { - return (tsdbReaderT*) pTsdbReadHandle; + return (tsdbReaderT*)pTsdbReadHandle; } // todo apply the lastkey of table check to avoid to load header file pTsdbReadHandle->pTableCheckInfo = createCheckInfoFromTableGroup(pTsdbReadHandle, groupList); if (pTsdbReadHandle->pTableCheckInfo == NULL) { -// tsdbCleanupReadHandle(pTsdbReadHandle); + // tsdbCleanupReadHandle(pTsdbReadHandle); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; } - tsdbDebug("%p total numOfTable:%" PRIzu " in this query, group %"PRIzu" %s", pTsdbReadHandle, taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo), - taosArrayGetSize(groupList->pGroupList), pTsdbReadHandle->idStr); + tsdbDebug("%p total numOfTable:%" PRIzu " in this query, group %" PRIzu " %s", pTsdbReadHandle, + taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo), taosArrayGetSize(groupList->pGroupList), + pTsdbReadHandle->idStr); - return (tsdbReaderT) pTsdbReadHandle; + return (tsdbReaderT)pTsdbReadHandle; } -void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond *pCond) { +void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) { STsdbReadHandle* pTsdbReadHandle = queryHandle; if (emptyQueryTimewindow(pTsdbReadHandle)) { @@ -463,13 +472,13 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond *pCond) { return; } - pTsdbReadHandle->order = pCond->order; - pTsdbReadHandle->window = pCond->twindow; - pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; - pTsdbReadHandle->cur.fid = -1; - pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->activeIndex = 0; // current active table index + pTsdbReadHandle->order = pCond->order; + pTsdbReadHandle->window = pCond->twindow; + pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; + pTsdbReadHandle->cur.fid = -1; + pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; + pTsdbReadHandle->checkFiles = true; + pTsdbReadHandle->activeIndex = 0; // current active table index pTsdbReadHandle->locateStart = false; pTsdbReadHandle->loadExternalRow = pCond->loadExternalRows; @@ -488,16 +497,16 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond *pCond) { resetCheckInfo(pTsdbReadHandle); } -void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond *pCond, STableGroupInfo* groupList) { +void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond* pCond, STableGroupInfo* groupList) { STsdbReadHandle* pTsdbReadHandle = queryHandle; - pTsdbReadHandle->order = pCond->order; - pTsdbReadHandle->window = pCond->twindow; - pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; - pTsdbReadHandle->cur.fid = -1; - pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->activeIndex = 0; // current active table index + pTsdbReadHandle->order = pCond->order; + pTsdbReadHandle->window = pCond->twindow; + pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; + pTsdbReadHandle->cur.fid = -1; + pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; + pTsdbReadHandle->checkFiles = true; + pTsdbReadHandle->activeIndex = 0; // current active table index pTsdbReadHandle->locateStart = false; pTsdbReadHandle->loadExternalRow = pCond->loadExternalRows; @@ -514,21 +523,23 @@ void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond *pC tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo); SArray* pTable = NULL; -// STsdbMeta* pMeta = tsdbGetMeta(pTsdbReadHandle->pTsdb); + // STsdbMeta* pMeta = tsdbGetMeta(pTsdbReadHandle->pTsdb); -// pTsdbReadHandle->pTableCheckInfo = destroyTableCheckInfo(pTsdbReadHandle->pTableCheckInfo); + // pTsdbReadHandle->pTableCheckInfo = destroyTableCheckInfo(pTsdbReadHandle->pTableCheckInfo); - pTsdbReadHandle->pTableCheckInfo = NULL;//createCheckInfoFromTableGroup(pTsdbReadHandle, groupList, pMeta, &pTable); + pTsdbReadHandle->pTableCheckInfo = NULL; // createCheckInfoFromTableGroup(pTsdbReadHandle, groupList, pMeta, + // &pTable); if (pTsdbReadHandle->pTableCheckInfo == NULL) { -// tsdbCleanupReadHandle(pTsdbReadHandle); + // tsdbCleanupReadHandle(pTsdbReadHandle); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; } -// pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); -// pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); + // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); + // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); } -tsdbReaderT tsdbQueryLastRow(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, uint64_t taskId) { +tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, + uint64_t taskId) { pCond->twindow = updateLastrowForEachGroup(groupList); // no qualified table @@ -536,13 +547,13 @@ tsdbReaderT tsdbQueryLastRow(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo return NULL; } - STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, taskId); + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(tsdb, pCond, groupList, qId, taskId); if (pTsdbReadHandle == NULL) { return NULL; } int32_t code = checkForCachedLastRow(pTsdbReadHandle, groupList); - if (code != TSDB_CODE_SUCCESS) { // set the numOfTables to be 0 + if (code != TSDB_CODE_SUCCESS) { // set the numOfTables to be 0 terrno = code; return NULL; } @@ -551,7 +562,7 @@ tsdbReaderT tsdbQueryLastRow(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo if (pTsdbReadHandle->cachelastrow) { pTsdbReadHandle->type = TSDB_QUERY_TYPE_LAST; } - + return pTsdbReadHandle; } @@ -576,12 +587,12 @@ tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupIn } #endif -SArray* tsdbGetQueriedTableList(tsdbReaderT *pHandle) { +SArray* tsdbGetQueriedTableList(tsdbReaderT* pHandle) { assert(pHandle != NULL); - STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) pHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); + size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); SArray* res = taosArrayInit(size, POINTER_BYTES); return res; } @@ -594,18 +605,18 @@ static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGr STableGroupInfo* pNew = taosMemoryCalloc(1, sizeof(STableGroupInfo)); pNew->pGroupList = taosArrayInit(numOfGroup, POINTER_BYTES); - for(int32_t i = 0; i < numOfGroup; ++i) { + for (int32_t i = 0; i < numOfGroup; ++i) { SArray* oneGroup = taosArrayGetP(pGroupList->pGroupList, i); - size_t numOfTables = taosArrayGetSize(oneGroup); + size_t numOfTables = taosArrayGetSize(oneGroup); SArray* px = taosArrayInit(4, sizeof(STableKeyInfo)); for (int32_t j = 0; j < numOfTables; ++j) { STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(oneGroup, j); -// if (window->skey <= pInfo->lastKey && ((STable*)pInfo->pTable)->lastKey != TSKEY_INITIAL_VAL) { -// taosArrayPush(px, pInfo); -// pNew->numOfTables += 1; -// break; -// } + // if (window->skey <= pInfo->lastKey && ((STable*)pInfo->pTable)->lastKey != TSKEY_INITIAL_VAL) { + // taosArrayPush(px, pInfo); + // pNew->numOfTables += 1; + // break; + // } } // there are no data in this group @@ -619,7 +630,8 @@ static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGr return pNew; } -tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, uint64_t qId, uint64_t taskId) { +tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, + uint64_t taskId) { STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList); if (pNew->numOfTables == 0) { @@ -634,7 +646,7 @@ tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb *tsdb, STsdbQueryCond* pCond, ST } } - STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTables(tsdb, pCond, pNew, qId, taskId); + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(tsdb, pCond, pNew, qId, taskId); pTsdbReadHandle->loadExternalRow = true; pTsdbReadHandle->currentLoadExternalRows = true; @@ -674,9 +686,9 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe return false; } - bool memEmpty = (pCheckInfo->iter == NULL) || (pCheckInfo->iter != NULL && !tSkipListIterNext(pCheckInfo->iter)); + bool memEmpty = (pCheckInfo->iter == NULL) || (pCheckInfo->iter != NULL && !tSkipListIterNext(pCheckInfo->iter)); bool imemEmpty = (pCheckInfo->iiter == NULL) || (pCheckInfo->iiter != NULL && !tSkipListIterNext(pCheckInfo->iiter)); - if (memEmpty && imemEmpty) { // buffer is empty + if (memEmpty && imemEmpty) { // buffer is empty return false; } @@ -687,8 +699,9 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe STSRow* row = (STSRow*)SL_GET_NODE_DATA(node); TSKEY key = TD_ROW_KEY(row); // first timestamp in buffer tsdbDebug("%p uid:%" PRId64 ", check data in mem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 - "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%"PRId64", %s", - pHandle, pCheckInfo->tableId, key, order, (*pMem)->keyMin, (*pMem)->keyMax, pCheckInfo->lastKey, (*pMem)->nrows, pHandle->idStr); + "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%" PRId64 ", %s", + pHandle, pCheckInfo->tableId, key, order, (*pMem)->keyMin, (*pMem)->keyMax, pCheckInfo->lastKey, + (*pMem)->nrows, pHandle->idStr); if (ASCENDING_TRAVERSE(order)) { assert(pCheckInfo->lastKey <= key); @@ -697,7 +710,7 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe } } else { - tsdbDebug("%p uid:%"PRId64", no data in mem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); + tsdbDebug("%p uid:%" PRId64 ", no data in mem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); } if (!imemEmpty) { @@ -707,8 +720,9 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe STSRow* row = (STSRow*)SL_GET_NODE_DATA(node); TSKEY key = TD_ROW_KEY(row); // first timestamp in buffer tsdbDebug("%p uid:%" PRId64 ", check data in imem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 - "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%"PRId64", %s", - pHandle, pCheckInfo->tableId, key, order, (*pIMem)->keyMin, (*pIMem)->keyMax, pCheckInfo->lastKey, (*pIMem)->nrows, pHandle->idStr); + "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%" PRId64 ", %s", + pHandle, pCheckInfo->tableId, key, order, (*pIMem)->keyMin, (*pIMem)->keyMax, pCheckInfo->lastKey, + (*pIMem)->nrows, pHandle->idStr); if (ASCENDING_TRAVERSE(order)) { assert(pCheckInfo->lastKey <= key); @@ -716,7 +730,7 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe assert(pCheckInfo->lastKey >= key); } } else { - tsdbDebug("%p uid:%"PRId64", no data in imem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); + tsdbDebug("%p uid:%" PRId64 ", no data in imem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); } return true; @@ -761,30 +775,20 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, TSKEY r2 = TD_ROW_KEY(rimem); if (r1 == r2) { -#if 0 - if(update == TD_ROW_DISCARD_UPDATE){ + if (update == TD_ROW_DISCARD_UPDATE) { pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; tSkipListIterNext(pCheckInfo->iter); - } - else if(update == TD_ROW_OVERWRITE_UPDATE) { + } else if (update == TD_ROW_OVERWRITE_UPDATE) { pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; tSkipListIterNext(pCheckInfo->iiter); } else { pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; } -#endif - if (TD_SUPPORT_UPDATE(update)) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_BOTH; - } else { - pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; - tSkipListIterNext(pCheckInfo->iter); - } return r1; } else if (r1 < r2 && ASCENDING_TRAVERSE(order)) { pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; return r1; - } - else { + } else { pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; return r2; } @@ -828,7 +832,7 @@ static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int tSkipListIterNext(pCheckInfo->iter); pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; return rimem; - } else if(update == TD_ROW_OVERWRITE_UPDATE){ + } else if (update == TD_ROW_OVERWRITE_UPDATE) { tSkipListIterNext(pCheckInfo->iiter); pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; return rmem; @@ -872,7 +876,7 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { if (pCheckInfo->iiter != NULL) { return tSkipListIterGet(pCheckInfo->iiter) != NULL; } - } else if (pCheckInfo->chosen == CHECKINFO_CHOSEN_IMEM){ + } else if (pCheckInfo->chosen == CHECKINFO_CHOSEN_IMEM) { if (pCheckInfo->iiter != NULL) { hasNext = tSkipListIterNext(pCheckInfo->iiter); } @@ -897,8 +901,8 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { } static bool hasMoreDataInCache(STsdbReadHandle* pHandle) { - STsdbCfg *pCfg = &pHandle->pTsdb->config; - size_t size = taosArrayGetSize(pHandle->pTableCheckInfo); + STsdbCfg* pCfg = &pHandle->pTsdb->config; + size_t size = taosArrayGetSize(pHandle->pTableCheckInfo); assert(pHandle->activeIndex < size && pHandle->activeIndex >= 0 && size >= 1); pHandle->cur.fid = INT32_MIN; @@ -913,8 +917,8 @@ static bool hasMoreDataInCache(STsdbReadHandle* pHandle) { } pCheckInfo->lastKey = TD_ROW_KEY(row); // first timestamp in buffer - tsdbDebug("%p uid:%" PRId64", check data in buffer from skey:%" PRId64 ", order:%d, %s", pHandle, - pCheckInfo->tableId, pCheckInfo->lastKey, pHandle->order, pHandle->idStr); + tsdbDebug("%p uid:%" PRId64 ", check data in buffer from skey:%" PRId64 ", order:%d, %s", pHandle, + pCheckInfo->tableId, pCheckInfo->lastKey, pHandle->order, pHandle->idStr); // all data in mem are checked already. if ((pCheckInfo->lastKey > pHandle->window.ekey && ASCENDING_TRAVERSE(pHandle->order)) || @@ -922,7 +926,7 @@ static bool hasMoreDataInCache(STsdbReadHandle* pHandle) { return false; } - int32_t step = ASCENDING_TRAVERSE(pHandle->order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(pHandle->order) ? 1 : -1; STimeWindow* win = &pHandle->cur.win; pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo, pHandle->window.ekey, pHandle->outputCapacity, win, pHandle); @@ -947,9 +951,9 @@ static int32_t getFileIdFromKey(TSKEY key, int32_t daysPerFile, int32_t precisio if (key < 0) { key -= (daysPerFile * tsTickPerDay[precision]); } - + int64_t fid = (int64_t)(key / (daysPerFile * tsTickPerDay[precision])); // set the starting fileId - if (fid < 0L && llabs(fid) > INT32_MAX) { // data value overflow for INT32 + if (fid < 0L && llabs(fid) > INT32_MAX) { // data value overflow for INT32 fid = INT32_MIN; } @@ -987,7 +991,7 @@ static int32_t binarySearchForBlock(SBlock* pBlock, int32_t numOfBlocks, TSKEY s return midSlot; } -static int32_t loadBlockInfo(STsdbReadHandle * pTsdbReadHandle, int32_t index, int32_t* numOfBlocks) { +static int32_t loadBlockInfo(STsdbReadHandle* pTsdbReadHandle, int32_t index, int32_t* numOfBlocks) { int32_t code = 0; STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, index); @@ -1030,9 +1034,11 @@ static int32_t loadBlockInfo(STsdbReadHandle * pTsdbReadHandle, int32_t index, i TSKEY s = TSKEY_INITIAL_VAL, e = TSKEY_INITIAL_VAL; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - assert(pCheckInfo->lastKey <= pTsdbReadHandle->window.ekey && pTsdbReadHandle->window.skey <= pTsdbReadHandle->window.ekey); + assert(pCheckInfo->lastKey <= pTsdbReadHandle->window.ekey && + pTsdbReadHandle->window.skey <= pTsdbReadHandle->window.ekey); } else { - assert(pCheckInfo->lastKey >= pTsdbReadHandle->window.ekey && pTsdbReadHandle->window.skey >= pTsdbReadHandle->window.ekey); + assert(pCheckInfo->lastKey >= pTsdbReadHandle->window.ekey && + pTsdbReadHandle->window.skey >= pTsdbReadHandle->window.ekey); } s = TMIN(pCheckInfo->lastKey, pTsdbReadHandle->window.ekey); @@ -1093,10 +1099,11 @@ static int32_t getFileCompInfo(STsdbReadHandle* pTsdbReadHandle, int32_t* numOfB return code; } -static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, int32_t slotIndex) { +static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, + int32_t slotIndex) { int64_t st = taosGetTimestampUs(); - STSchema *pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0); + STSchema* pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0); int32_t code = tdInitDataCols(pTsdbReadHandle->pDataCols, pSchema); if (code != TSDB_CODE_SUCCESS) { tsdbError("%p failed to malloc buf for pDataCols, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); @@ -1120,7 +1127,8 @@ static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBl int16_t* colIds = pTsdbReadHandle->defaultLoadColumn->pData; - int32_t ret = tsdbLoadBlockDataCols(&(pTsdbReadHandle->rhelper), pBlock, pCheckInfo->pCompInfo, colIds, (int)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)), true); + int32_t ret = tsdbLoadBlockDataCols(&(pTsdbReadHandle->rhelper), pBlock, pCheckInfo->pCompInfo, colIds, + (int)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)), true); if (ret != TSDB_CODE_SUCCESS) { int32_t c = terrno; assert(c != TSDB_CODE_SUCCESS); @@ -1139,9 +1147,9 @@ static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBl pBlock->numOfRows = pCols->numOfRows; // Convert from TKEY to TSKEY for primary timestamp column if current block has timestamp before 1970-01-01T00:00:00Z - if(pBlock->keyFirst < 0 && colIds[0] == PRIMARYKEY_TIMESTAMP_COL_ID) { + if (pBlock->keyFirst < 0 && colIds[0] == PRIMARYKEY_TIMESTAMP_COL_ID) { int64_t* src = pCols->cols[0].pData; - for(int32_t i = 0; i < pBlock->numOfRows; ++i) { + for (int32_t i = 0; i < pBlock->numOfRows; ++i) { src[i] = tdGetKey(src[i]); } } @@ -1149,30 +1157,34 @@ static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBl int64_t elapsedTime = (taosGetTimestampUs() - st); pTsdbReadHandle->cost.blockLoadTime += elapsedTime; - tsdbDebug("%p load file block into buffer, index:%d, brange:%"PRId64"-%"PRId64", rows:%d, elapsed time:%"PRId64 " us, %s", - pTsdbReadHandle, slotIndex, pBlock->keyFirst, pBlock->keyLast, pBlock->numOfRows, elapsedTime, pTsdbReadHandle->idStr); + tsdbDebug("%p load file block into buffer, index:%d, brange:%" PRId64 "-%" PRId64 ", rows:%d, elapsed time:%" PRId64 + " us, %s", + pTsdbReadHandle, slotIndex, pBlock->keyFirst, pBlock->keyLast, pBlock->numOfRows, elapsedTime, + pTsdbReadHandle->idStr); return TSDB_CODE_SUCCESS; _error: pBlock->numOfRows = 0; - tsdbError("%p error occurs in loading file block, index:%d, brange:%"PRId64"-%"PRId64", rows:%d, %s", + tsdbError("%p error occurs in loading file block, index:%d, brange:%" PRId64 "-%" PRId64 ", rows:%d, %s", pTsdbReadHandle, slotIndex, pBlock->keyFirst, pBlock->keyLast, pBlock->numOfRows, pTsdbReadHandle->idStr); return terrno; } static int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* pBlockInfo); -static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, int32_t start, int32_t end); -static void moveDataToFront(STsdbReadHandle* pTsdbReadHandle, int32_t numOfRows, int32_t numOfCols); -static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle); -static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SDataBlockInfo* pBlockInfo, int32_t endPos); +static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, + int32_t start, int32_t end); +static void moveDataToFront(STsdbReadHandle* pTsdbReadHandle, int32_t numOfRows, int32_t numOfCols); +static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle); +static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, + SDataBlockInfo* pBlockInfo, int32_t endPos); -static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo){ +static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo) { SQueryFilePos* cur = &pTsdbReadHandle->cur; STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; SDataBlockInfo binfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); TSKEY key; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; /*bool hasData = */ initTableMemIterator(pTsdbReadHandle, pCheckInfo); assert(cur->pos >= 0 && cur->pos <= binfo.rows); @@ -1180,22 +1192,22 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* key = extractFirstTraverseKey(pCheckInfo, pTsdbReadHandle->order, pCfg->update); if (key != TSKEY_INITIAL_VAL) { - tsdbDebug("%p key in mem:%"PRId64", %s", pTsdbReadHandle, key, pTsdbReadHandle->idStr); + tsdbDebug("%p key in mem:%" PRId64 ", %s", pTsdbReadHandle, key, pTsdbReadHandle->idStr); } else { tsdbDebug("%p no data in mem, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); } if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) || (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) { - if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) || (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey))) { - // do not load file block into buffer int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; - TSKEY maxKey = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? (binfo.window.skey - step):(binfo.window.ekey - step); - cur->rows = tsdbReadRowsFromCache(pCheckInfo, maxKey, pTsdbReadHandle->outputCapacity, &cur->win, pTsdbReadHandle); + TSKEY maxKey = + ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? (binfo.window.skey - step) : (binfo.window.ekey - step); + cur->rows = + tsdbReadRowsFromCache(pCheckInfo, maxKey, pTsdbReadHandle->outputCapacity, &cur->win, pTsdbReadHandle); pTsdbReadHandle->realNumOfRows = cur->rows; // update the last key value @@ -1209,7 +1221,6 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* return code; } - // return error, add test cases if ((code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot)) != TSDB_CODE_SUCCESS) { return code; @@ -1226,12 +1237,12 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* assert(pTsdbReadHandle->outputCapacity >= binfo.rows); int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &binfo); - if ((cur->pos == 0 && endPos == binfo.rows -1 && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || + if ((cur->pos == 0 && endPos == binfo.rows - 1 && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || (cur->pos == (binfo.rows - 1) && endPos == 0 && (!ASCENDING_TRAVERSE(pTsdbReadHandle->order)))) { pTsdbReadHandle->realNumOfRows = binfo.rows; cur->rows = binfo.rows; - cur->win = binfo.window; + cur->win = binfo.window; cur->mixBlock = false; cur->blockCompleted = true; @@ -1242,29 +1253,31 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* cur->lastKey = binfo.window.skey - 1; cur->pos = -1; } - } else { // partially copy to dest buffer + } else { // partially copy to dest buffer copyAllRemainRowsFromFileBlock(pTsdbReadHandle, pCheckInfo, &binfo, endPos); cur->mixBlock = true; } assert(cur->blockCompleted); if (cur->rows == binfo.rows) { - tsdbDebug("%p whole file block qualified, brange:%"PRId64"-%"PRId64", rows:%d, lastKey:%"PRId64", %s", + tsdbDebug("%p whole file block qualified, brange:%" PRId64 "-%" PRId64 ", rows:%d, lastKey:%" PRId64 ", %s", pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, cur->lastKey, pTsdbReadHandle->idStr); } else { - tsdbDebug("%p create data block from remain file block, brange:%"PRId64"-%"PRId64", rows:%d, total:%d, lastKey:%"PRId64", %s", - pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, binfo.rows, cur->lastKey, pTsdbReadHandle->idStr); + tsdbDebug("%p create data block from remain file block, brange:%" PRId64 "-%" PRId64 + ", rows:%d, total:%d, lastKey:%" PRId64 ", %s", + pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, binfo.rows, cur->lastKey, + pTsdbReadHandle->idStr); } - } return code; } -static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, bool* exists) { +static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, + bool* exists) { SQueryFilePos* cur = &pTsdbReadHandle->cur; - int32_t code = TSDB_CODE_SUCCESS; - bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + int32_t code = TSDB_CODE_SUCCESS; + bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); if (asc) { // query ended in/started from current block @@ -1287,10 +1300,10 @@ static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBloc assert(pCheckInfo->lastKey <= pBlock->keyLast); doMergeTwoLevelData(pTsdbReadHandle, pCheckInfo, pBlock); } else { // the whole block is loaded in to buffer - cur->pos = asc? 0:(pBlock->numOfRows - 1); + cur->pos = asc ? 0 : (pBlock->numOfRows - 1); code = handleDataMergeIfNeeded(pTsdbReadHandle, pBlock, pCheckInfo); } - } else { //desc order, query ended in current block + } else { // desc order, query ended in current block if (pTsdbReadHandle->window.ekey > pBlock->keyFirst || pCheckInfo->lastKey < pBlock->keyLast) { if ((code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot)) != TSDB_CODE_SUCCESS) { *exists = false; @@ -1299,7 +1312,8 @@ static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBloc SDataCols* pTsCol = pTsdbReadHandle->rhelper.pDCols[0]; if (pCheckInfo->lastKey < pBlock->keyLast) { - cur->pos = binarySearchForKey(pTsCol->cols[0].pData, pBlock->numOfRows, pCheckInfo->lastKey, pTsdbReadHandle->order); + cur->pos = + binarySearchForKey(pTsCol->cols[0].pData, pBlock->numOfRows, pCheckInfo->lastKey, pTsdbReadHandle->order); } else { cur->pos = pBlock->numOfRows - 1; } @@ -1307,7 +1321,7 @@ static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBloc assert(pCheckInfo->lastKey >= pBlock->keyFirst); doMergeTwoLevelData(pTsdbReadHandle, pCheckInfo, pBlock); } else { - cur->pos = asc? 0:(pBlock->numOfRows-1); + cur->pos = asc ? 0 : (pBlock->numOfRows - 1); code = handleDataMergeIfNeeded(pTsdbReadHandle, pBlock, pCheckInfo); } } @@ -1378,11 +1392,12 @@ static int doBinarySearchKey(char* pValue, int num, TSKEY key, int order) { return midPos; } -static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, int32_t start, int32_t end) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1 : -1; +static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, + int32_t start, int32_t end) { + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - TSKEY* tsArray = pCols->cols[0].pData; + TSKEY* tsArray = pCols->cols[0].pData; int32_t num = end - start + 1; assert(num >= 0); @@ -1393,9 +1408,9 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t int32_t requiredNumOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); - //data in buffer has greater timestamp, copy data in file block + // data in buffer has greater timestamp, copy data in file block int32_t i = 0, j = 0; - while(i < requiredNumOfCols && j < pCols->numOfCols) { + while (i < requiredNumOfCols && j < pCols->numOfCols) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); SDataCol* src = &pCols->cols[j]; @@ -1406,15 +1421,15 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t if (!isAllRowsNull(src) && pColInfo->info.colId == src->colId) { if (!IS_VAR_DATA_TYPE(pColInfo->info.type)) { // todo opt performance -// memmove(pData, (char*)src->pData + bytes * start, bytes * num); - for(int32_t k = start; k < num + start; ++k) { + // memmove(pData, (char*)src->pData + bytes * start, bytes * num); + for (int32_t k = start; k < num + start; ++k) { SCellVal sVal = {0}; if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) { TASSERT(0); } if (sVal.valType == TD_VTYPE_NULL) { - colDataAppend(pColInfo, k, NULL, true); + colDataAppendNULL(pColInfo, k); } else { colDataAppend(pColInfo, k, sVal.val, false); } @@ -1423,28 +1438,32 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t // todo refactor, only copy one-by-one for (int32_t k = start; k < num + start; ++k) { SCellVal sVal = {0}; - if(tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0){ + if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) { TASSERT(0); } - colDataAppend(pColInfo, k, sVal.val, false); + if (sVal.valType == TD_VTYPE_NULL) { + colDataAppendNULL(pColInfo, k); + } else { + colDataAppend(pColInfo, k, sVal.val, false); + } } } j++; i++; - } else { // pColInfo->info.colId < src->colId, it is a NULL data - for(int32_t k = start; k < num + start; ++k) { // TODO opt performance + } else { // pColInfo->info.colId < src->colId, it is a NULL data + for (int32_t k = start; k < num + start; ++k) { // TODO opt performance colDataAppend(pColInfo, k, NULL, true); } i++; } } - while (i < requiredNumOfCols) { // the remain columns are all null data + while (i < requiredNumOfCols) { // the remain columns are all null data SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - for(int32_t k = start; k < num + start; ++k) { - colDataAppend(pColInfo, k, NULL, true); // TODO add a fast version to set a number of consecutive NULL value. + for (int32_t k = start; k < num + start; ++k) { + colDataAppend(pColInfo, k, NULL, true); // TODO add a fast version to set a number of consecutive NULL value. } i++; } @@ -1461,15 +1480,15 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2, bool forceSetNull) { #if 1 - STSchema* pSchema; - STSRow* row; - int16_t colId; - int16_t offset; + STSchema* pSchema; + STSRow* row; + int16_t colId; + int16_t offset; - bool isRow1DataRow = TD_IS_TP_ROW(row1); - bool isRow2DataRow; - bool isChosenRowDataRow; - int32_t chosen_itr; + bool isRow1DataRow = TD_IS_TP_ROW(row1); + bool isRow2DataRow; + bool isChosenRowDataRow; + int32_t chosen_itr; SCellVal sVal = {0}; // the schema version info is embeded in STSRow @@ -1479,19 +1498,19 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit pSchema1 = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, uid, TD_ROW_SVER(row1)); } - if(isRow1DataRow) { + if (isRow1DataRow) { numOfColsOfRow1 = schemaNCols(pSchema1); } else { numOfColsOfRow1 = tdRowGetNCols(row1); } int32_t numOfColsOfRow2 = 0; - if(row2) { + if (row2) { isRow2DataRow = TD_IS_TP_ROW(row2); if (pSchema2 == NULL) { pSchema2 = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, uid, TD_ROW_SVER(row2)); } - if(isRow2DataRow) { + if (isRow2DataRow) { numOfColsOfRow2 = schemaNCols(pSchema2); } else { numOfColsOfRow2 = tdRowGetNCols(row2); @@ -1499,31 +1518,31 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit } int32_t i = 0, j = 0, k = 0; - while(i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { + while (i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); int32_t colIdOfRow1; - if(j >= numOfColsOfRow1) { + if (j >= numOfColsOfRow1) { colIdOfRow1 = INT32_MAX; - } else if(isRow1DataRow) { + } else if (isRow1DataRow) { colIdOfRow1 = pSchema1->columns[j].colId; } else { - SKvRowIdx *pColIdx = tdKvRowColIdxAt(row1, j); + SKvRowIdx* pColIdx = tdKvRowColIdxAt(row1, j); colIdOfRow1 = pColIdx->colId; } int32_t colIdOfRow2; - if(k >= numOfColsOfRow2) { + if (k >= numOfColsOfRow2) { colIdOfRow2 = INT32_MAX; - } else if(isRow2DataRow) { + } else if (isRow2DataRow) { colIdOfRow2 = pSchema2->columns[k].colId; } else { - SKvRowIdx *pColIdx = tdKvRowColIdxAt(row2, k); + SKvRowIdx* pColIdx = tdKvRowColIdxAt(row2, k); colIdOfRow2 = pColIdx->colId; } - if(colIdOfRow1 == colIdOfRow2) { - if(colIdOfRow1 < pColInfo->info.colId) { + if (colIdOfRow1 == colIdOfRow2) { + if (colIdOfRow1 < pColInfo->info.colId) { j++; k++; continue; @@ -1532,8 +1551,8 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit pSchema = pSchema1; isChosenRowDataRow = isRow1DataRow; chosen_itr = j; - } else if(colIdOfRow1 < colIdOfRow2) { - if(colIdOfRow1 < pColInfo->info.colId) { + } else if (colIdOfRow1 < colIdOfRow2) { + if (colIdOfRow1 < pColInfo->info.colId) { j++; continue; } @@ -1542,7 +1561,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit isChosenRowDataRow = isRow1DataRow; chosen_itr = j; } else { - if(colIdOfRow2 < pColInfo->info.colId) { + if (colIdOfRow2 < pColInfo->info.colId) { k++; continue; } @@ -1551,12 +1570,12 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit chosen_itr = k; isChosenRowDataRow = isRow2DataRow; } - if(isChosenRowDataRow) { + if (isChosenRowDataRow) { colId = pSchema->columns[chosen_itr].colId; offset = pSchema->columns[chosen_itr].offset; tdSTpRowGetVal(row, colId, pSchema->columns[chosen_itr].type, pSchema->flen, offset, chosen_itr, &sVal); } else { - SKvRowIdx *pColIdx = tdKvRowColIdxAt(row, chosen_itr); + SKvRowIdx* pColIdx = tdKvRowColIdxAt(row, chosen_itr); colId = pColIdx->colId; offset = pColIdx->offset; tdSKvRowGetVal(row, colId, offset, chosen_itr, &sVal); @@ -1571,21 +1590,21 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit i++; - if(row == row1) { + if (row == row1) { j++; } else { k++; } } else { - if(forceSetNull) { + if (forceSetNull) { colDataAppend(pColInfo, numOfRows, NULL, true); } i++; } } - if(forceSetNull) { - while (i < numOfCols) { // the remain columns are all null data + if (forceSetNull) { + while (i < numOfCols) { // the remain columns are all null data SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); colDataAppend(pColInfo, numOfRows, NULL, true); i++; @@ -1602,15 +1621,16 @@ static void moveDataToFront(STsdbReadHandle* pTsdbReadHandle, int32_t numOfRows, // if the buffer is not full in case of descending order query, move the data in the front of the buffer if (numOfRows < pTsdbReadHandle->outputCapacity) { int32_t emptySize = pTsdbReadHandle->outputCapacity - numOfRows; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, numOfRows * pColInfo->info.bytes); + memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, + numOfRows * pColInfo->info.bytes); } } } -static void getQualifiedRowsPos(STsdbReadHandle* pTsdbReadHandle, int32_t startPos, int32_t endPos, int32_t numOfExisted, - int32_t* start, int32_t* end) { +static void getQualifiedRowsPos(STsdbReadHandle* pTsdbReadHandle, int32_t startPos, int32_t endPos, + int32_t numOfExisted, int32_t* start, int32_t* end) { *start = -1; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { @@ -1635,7 +1655,8 @@ static void getQualifiedRowsPos(STsdbReadHandle* pTsdbReadHandle, int32_t startP } } -static void updateInfoAfterMerge(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, int32_t numOfRows, int32_t endPos) { +static void updateInfoAfterMerge(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, int32_t numOfRows, + int32_t endPos) { SQueryFilePos* cur = &pTsdbReadHandle->cur; pCheckInfo->lastKey = cur->lastKey; @@ -1655,22 +1676,24 @@ static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle) { } SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, 0); - assert(cur->win.skey == ((TSKEY*)pColInfoData->pData)[0] && cur->win.ekey == ((TSKEY*)pColInfoData->pData)[cur->rows-1]); + assert(cur->win.skey == ((TSKEY*)pColInfoData->pData)[0] && + cur->win.ekey == ((TSKEY*)pColInfoData->pData)[cur->rows - 1]); } else { cur->win = pTsdbReadHandle->window; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; cur->lastKey = pTsdbReadHandle->window.ekey + step; } } -static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SDataBlockInfo* pBlockInfo, int32_t endPos) { +static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, + SDataBlockInfo* pBlockInfo, int32_t endPos) { SQueryFilePos* cur = &pTsdbReadHandle->cur; SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - TSKEY* tsArray = pCols->cols[0].pData; + TSKEY* tsArray = pCols->cols[0].pData; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); int32_t pos = cur->pos; @@ -1686,7 +1709,7 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa int32_t numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, start, end); // the time window should always be ascending order: skey <= ekey - cur->win = (STimeWindow) {.skey = tsArray[start], .ekey = tsArray[end]}; + cur->win = (STimeWindow){.skey = tsArray[start], .ekey = tsArray[end]}; cur->mixBlock = (numOfRows != pBlockInfo->rows); cur->lastKey = tsArray[endPos] + step; cur->blockCompleted = true; @@ -1699,17 +1722,18 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos); doCheckGeneratedBlockRange(pTsdbReadHandle); - tsdbDebug("%p uid:%" PRIu64", data block created, mixblock:%d, brange:%"PRIu64"-%"PRIu64" rows:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, pTsdbReadHandle->idStr); + tsdbDebug("%p uid:%" PRIu64 ", data block created, mixblock:%d, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", + pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, + pTsdbReadHandle->idStr); } int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* pBlockInfo) { // NOTE: reverse the order to find the end position in data block int32_t endPos = -1; - int32_t order = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? TSDB_ORDER_DESC : TSDB_ORDER_ASC; + int32_t order = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; SQueryFilePos* cur = &pTsdbReadHandle->cur; - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; + SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order) && pTsdbReadHandle->window.ekey >= pBlockInfo->window.ekey) { endPos = pBlockInfo->rows - 1; @@ -1730,37 +1754,39 @@ int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* p // be included in the query time window will be discarded static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock) { SQueryFilePos* cur = &pTsdbReadHandle->cur; - SDataBlockInfo blockInfo = {0};//GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); + SDataBlockInfo blockInfo = {0}; // GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; initTableMemIterator(pTsdbReadHandle, pCheckInfo); SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; assert(pCols->cols[0].type == TSDB_DATA_TYPE_TIMESTAMP && pCols->cols[0].colId == PRIMARYKEY_TIMESTAMP_COL_ID && - cur->pos >= 0 && cur->pos < pBlock->numOfRows); + cur->pos >= 0 && cur->pos < pBlock->numOfRows); TSKEY* tsArray = pCols->cols[0].pData; - assert(pCols->numOfRows == pBlock->numOfRows && tsArray[0] == pBlock->keyFirst && tsArray[pBlock->numOfRows-1] == pBlock->keyLast); + assert(pCols->numOfRows == pBlock->numOfRows && tsArray[0] == pBlock->keyFirst && + tsArray[pBlock->numOfRows - 1] == pBlock->keyLast); // for search the endPos, so the order needs to reverse - int32_t order = (pTsdbReadHandle->order == TSDB_ORDER_ASC)? TSDB_ORDER_DESC:TSDB_ORDER_ASC; + int32_t order = (pTsdbReadHandle->order == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); STable* pTable = NULL; int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &blockInfo); - tsdbDebug("%p uid:%" PRIu64" start merge data block, file block range:%"PRIu64"-%"PRIu64" rows:%d, start:%d," + tsdbDebug("%p uid:%" PRIu64 " start merge data block, file block range:%" PRIu64 "-%" PRIu64 + " rows:%d, start:%d," "end:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, blockInfo.window.skey, blockInfo.window.ekey, - blockInfo.rows, cur->pos, endPos, pTsdbReadHandle->idStr); + pTsdbReadHandle, pCheckInfo->tableId, blockInfo.window.skey, blockInfo.window.ekey, blockInfo.rows, + cur->pos, endPos, pTsdbReadHandle->idStr); // compared with the data from in-memory buffer, to generate the correct timestamp array list int32_t numOfRows = 0; - int16_t rv1 = -1; - int16_t rv2 = -1; + int16_t rv1 = -1; + int16_t rv2 = -1; STSchema* pSchema1 = NULL; STSchema* pSchema2 = NULL; @@ -1786,49 +1812,53 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf break; } - if (((pos > endPos || tsArray[pos] > pTsdbReadHandle->window.ekey) && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || - ((pos < endPos || tsArray[pos] < pTsdbReadHandle->window.ekey) && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { + if (((pos > endPos || tsArray[pos] > pTsdbReadHandle->window.ekey) && + ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || + ((pos < endPos || tsArray[pos] < pTsdbReadHandle->window.ekey) && + !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { break; } if ((key < tsArray[pos] && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || (key > tsArray[pos] && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { if (rv1 != TD_ROW_SVER(row1)) { -// pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); + // pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); rv1 = TD_ROW_SVER(row1); } - if(row2 && rv2 != TD_ROW_SVER(row2)) { -// pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); + if (row2 && rv2 != TD_ROW_SVER(row2)) { + // pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); rv2 = TD_ROW_SVER(row2); } - - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, pCheckInfo->tableId, pSchema1, pSchema2, true); + + mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, + pCheckInfo->tableId, pSchema1, pSchema2, true); numOfRows += 1; if (cur->win.skey == TSKEY_INITIAL_VAL) { cur->win.skey = key; } cur->win.ekey = key; - cur->lastKey = key + step; + cur->lastKey = key + step; cur->mixBlock = true; moveToNextRowInMem(pCheckInfo); } else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it if (pCfg->update) { - if(pCfg->update == TD_ROW_PARTIAL_UPDATE) { + if (pCfg->update == TD_ROW_PARTIAL_UPDATE) { doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, pos, pos); } if (rv1 != TD_ROW_SVER(row1)) { -// pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); + // pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); rv1 = TD_ROW_SVER(row1); } - if(row2 && rv2 != TD_ROW_SVER(row2)) { -// pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); + if (row2 && rv2 != TD_ROW_SVER(row2)) { + // pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); rv2 = TD_ROW_SVER(row2); } - + bool forceSetNull = pCfg->update != TD_ROW_PARTIAL_UPDATE; - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, pCheckInfo->tableId, pSchema1, pSchema2, forceSetNull); + mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, + pCheckInfo->tableId, pSchema1, pSchema2, forceSetNull); numOfRows += 1; if (cur->win.skey == TSKEY_INITIAL_VAL) { cur->win.skey = key; @@ -1844,7 +1874,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf moveToNextRowInMem(pCheckInfo); } } else if ((key > tsArray[pos] && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || - (key < tsArray[pos] && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { + (key < tsArray[pos] && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { if (cur->win.skey == TSKEY_INITIAL_VAL) { cur->win.skey = tsArray[pos]; } @@ -1852,7 +1882,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf int32_t end = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, key, order); assert(end != -1); - if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it + if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it if (pCfg->update == TD_ROW_DISCARD_UPDATE) { moveToNextRowInMem(pCheckInfo); } else { @@ -1866,8 +1896,8 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, qstart, qend); pos += (qend - qstart + 1) * step; - cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? tsArray[qend]:tsArray[qstart]; - cur->lastKey = cur->win.ekey + step; + cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? tsArray[qend] : tsArray[qstart]; + cur->lastKey = cur->win.ekey + step; } } while (numOfRows < pTsdbReadHandle->outputCapacity); @@ -1892,8 +1922,8 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, start, end); pos += (end - start + 1) * step; - cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? tsArray[end]:tsArray[start]; - cur->lastKey = cur->win.ekey + step; + cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? tsArray[end] : tsArray[start]; + cur->lastKey = cur->win.ekey + step; cur->mixBlock = true; } } @@ -1911,8 +1941,9 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos); doCheckGeneratedBlockRange(pTsdbReadHandle); - tsdbDebug("%p uid:%" PRIu64", data block created, mixblock:%d, brange:%"PRIu64"-%"PRIu64" rows:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, pTsdbReadHandle->idStr); + tsdbDebug("%p uid:%" PRIu64 ", data block created, mixblock:%d, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", + pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, + pTsdbReadHandle->idStr); } int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) { @@ -2008,7 +2039,7 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* STableBlockInfo* pRightBlockInfoEx = &pSupporter->pDataBlockInfo[rightTableIndex][rightTableBlockIndex]; // assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset); -#if 0 // TODO: temporarily comment off requested by Dr. Liao +#if 0 // TODO: temporarily comment off requested by Dr. Liao if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset && pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) { tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset); @@ -2028,7 +2059,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu return TSDB_CODE_TDB_OUT_OF_MEMORY; } - pTsdbReadHandle->pDataBlockInfo = (STableBlockInfo*) tmp; + pTsdbReadHandle->pDataBlockInfo = (STableBlockInfo*)tmp; } memset(pTsdbReadHandle->pDataBlockInfo, 0, size); @@ -2087,18 +2118,18 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu cleanBlockOrderSupporter(&sup, numOfQualTables); tsdbDebug("%p create data blocks info struct completed for 1 table, %d blocks not sorted %s", pTsdbReadHandle, cnt, - pTsdbReadHandle->idStr); + pTsdbReadHandle->idStr); return TSDB_CODE_SUCCESS; } tsdbDebug("%p create data blocks info struct completed, %d blocks in %d tables %s", pTsdbReadHandle, cnt, - numOfQualTables, pTsdbReadHandle->idStr); + numOfQualTables, pTsdbReadHandle->idStr); assert(cnt <= numOfBlocks && numOfQualTables <= numOfTables); // the pTableQueryInfo[j]->numOfBlocks may be 0 sup.numOfTables = numOfQualTables; SMultiwayMergeTreeInfo* pTree = NULL; - uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar); + uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar); if (ret != TSDB_CODE_SUCCESS) { cleanBlockOrderSupporter(&sup, numOfTables); return TSDB_CODE_TDB_OUT_OF_MEMORY; @@ -2137,11 +2168,11 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exists); -static int32_t getDataBlockRv(STsdbReadHandle* pTsdbReadHandle, STableBlockInfo* pNext, bool *exists) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1 : -1; +static int32_t getDataBlockRv(STsdbReadHandle* pTsdbReadHandle, STableBlockInfo* pNext, bool* exists) { + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; SQueryFilePos* cur = &pTsdbReadHandle->cur; - while(1) { + while (1) { int32_t code = loadFileDataBlock(pTsdbReadHandle, pNext->compBlock, pNext->pTableCheckInfo, exists); if (code != TSDB_CODE_SUCCESS || *exists) { return code; @@ -2169,7 +2200,7 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi int32_t numOfBlocks = 0; int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; + STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; STimeWindow win = TSWINDOW_INITIALIZER; while (true) { @@ -2219,7 +2250,8 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi } // todo return error code to query engine - if ((code = createDataBlocksInfo(pTsdbReadHandle, numOfBlocks, &pTsdbReadHandle->numOfBlocks)) != TSDB_CODE_SUCCESS) { + if ((code = createDataBlocksInfo(pTsdbReadHandle, numOfBlocks, &pTsdbReadHandle->numOfBlocks)) != + TSDB_CODE_SUCCESS) { break; } @@ -2241,7 +2273,7 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi } assert(pTsdbReadHandle->pFileGroup != NULL && pTsdbReadHandle->numOfBlocks > 0); - cur->slot = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 0:pTsdbReadHandle->numOfBlocks-1; + cur->slot = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 0 : pTsdbReadHandle->numOfBlocks - 1; cur->fid = pTsdbReadHandle->pFileGroup->fid; STableBlockInfo* pBlockInfo = &pTsdbReadHandle->pDataBlockInfo[cur->slot]; @@ -2254,18 +2286,18 @@ static bool isEndFileDataBlock(SQueryFilePos* cur, int32_t numOfBlocks, bool asc } static void moveToNextDataBlockInCurrentFile(STsdbReadHandle* pTsdbReadHandle) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1 : -1; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; SQueryFilePos* cur = &pTsdbReadHandle->cur; assert(cur->slot < pTsdbReadHandle->numOfBlocks && cur->slot >= 0); cur->slot += step; - cur->mixBlock = false; + cur->mixBlock = false; cur->blockCompleted = false; } int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* pTableBlockInfo) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) queryHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)queryHandle; pTableBlockInfo->totalSize = 0; pTableBlockInfo->totalRows = 0; @@ -2287,7 +2319,7 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* int32_t code = TSDB_CODE_SUCCESS; int32_t numOfBlocks = 0; int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - int defaultRows = 4096;//TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); + int defaultRows = 4096; // TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); STimeWindow win = TSWINDOW_INITIALIZER; bool ascTraverse = ASCENDING_TRAVERSE(pTsdbReadHandle->order); @@ -2304,7 +2336,8 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* tsdbGetFidKeyRange(pCfg->daysPerFile, pCfg->precision, pTsdbReadHandle->pFileGroup->fid, &win.skey, &win.ekey); // current file are not overlapped with query time window, ignore remain files - if ((ascTraverse && win.skey > pTsdbReadHandle->window.ekey) || (!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)) { + if ((ascTraverse && win.skey > pTsdbReadHandle->window.ekey) || + (!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)) { tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pTsdbReadHandle, pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr); @@ -2357,9 +2390,9 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* if (numOfRows < defaultRows) { pTableBlockInfo->numOfSmallBlocks += 1; } -// int32_t stepIndex = (numOfRows-1)/TSDB_BLOCK_DIST_STEP_ROWS; -// SFileBlockInfo *blockInfo = (SFileBlockInfo*)taosArrayGet(pTableBlockInfo->dataBlockInfos, stepIndex); -// blockInfo->numBlocksOfStep++; + // int32_t stepIndex = (numOfRows-1)/TSDB_BLOCK_DIST_STEP_ROWS; + // SFileBlockInfo *blockInfo = (SFileBlockInfo*)taosArrayGet(pTableBlockInfo->dataBlockInfos, stepIndex); + // blockInfo->numBlocksOfStep++; } } } @@ -2416,7 +2449,7 @@ static int32_t getDataBlocksInFiles(STsdbReadHandle* pTsdbReadHandle, bool* exis static bool doHasDataInBuffer(STsdbReadHandle* pTsdbReadHandle) { size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - + while (pTsdbReadHandle->activeIndex < numOfTables) { if (hasMoreDataInCache(pTsdbReadHandle)) { return true; @@ -2428,23 +2461,23 @@ static bool doHasDataInBuffer(STsdbReadHandle* pTsdbReadHandle) { return false; } -//todo not unref yet, since it is not support multi-group interpolation query +// todo not unref yet, since it is not support multi-group interpolation query static UNUSED_FUNC void changeQueryHandleForInterpQuery(tsdbReaderT pHandle) { // filter the queried time stamp in the first place - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; // starts from the buffer in case of descending timestamp order check data blocks size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); int32_t i = 0; - while(i < numOfTables) { + while (i < numOfTables) { STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); // the first qualified table for interpolation query -// if ((pTsdbReadHandle->window.skey <= pCheckInfo->pTableObj->lastKey) && -// (pCheckInfo->pTableObj->lastKey != TSKEY_INITIAL_VAL)) { -// break; -// } + // if ((pTsdbReadHandle->window.skey <= pCheckInfo->pTableObj->lastKey) && + // (pCheckInfo->pTableObj->lastKey != TSKEY_INITIAL_VAL)) { + // break; + // } i++; } @@ -2454,7 +2487,7 @@ static UNUSED_FUNC void changeQueryHandleForInterpQuery(tsdbReaderT pHandle) { return; } - STableCheckInfo info = *(STableCheckInfo*) taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); + STableCheckInfo info = *(STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); taosArrayClear(pTsdbReadHandle->pTableCheckInfo); info.lastKey = pTsdbReadHandle->window.skey; @@ -2463,13 +2496,13 @@ static UNUSED_FUNC void changeQueryHandleForInterpQuery(tsdbReaderT pHandle) { static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, STsdbReadHandle* pTsdbReadHandle) { - int numOfRows = 0; - int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); + int numOfRows = 0; + int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; win->skey = TSKEY_INITIAL_VAL; - int64_t st = taosGetTimestampUs(); - int16_t rv = -1; + int64_t st = taosGetTimestampUs(); + int16_t rv = -1; STSchema* pSchema = NULL; do { @@ -2479,9 +2512,10 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int } TSKEY key = TD_ROW_KEY(row); - if ((key > maxKey && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || (key < maxKey && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { - tsdbDebug("%p key:%"PRIu64" beyond qrange:%"PRId64" - %"PRId64", no more data in buffer", pTsdbReadHandle, key, pTsdbReadHandle->window.skey, - pTsdbReadHandle->window.ekey); + if ((key > maxKey && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || + (key < maxKey && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { + tsdbDebug("%p key:%" PRIu64 " beyond qrange:%" PRId64 " - %" PRId64 ", no more data in buffer", pTsdbReadHandle, + key, pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey); break; } @@ -2495,14 +2529,15 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0); rv = TD_ROW_SVER(row); } - mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, numOfRows, row, NULL, numOfCols, pCheckInfo->tableId, pSchema, NULL, true); + mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, numOfRows, row, NULL, numOfCols, pCheckInfo->tableId, pSchema, + NULL, true); if (++numOfRows >= maxRowsToRead) { moveToNextRowInMem(pCheckInfo); break; } - } while(moveToNextRowInMem(pCheckInfo)); + } while (moveToNextRowInMem(pCheckInfo)); assert(numOfRows <= maxRowsToRead); @@ -2510,15 +2545,16 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int if (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && numOfRows < maxRowsToRead) { int32_t emptySize = maxRowsToRead - numOfRows; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, numOfRows * pColInfo->info.bytes); + memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, + numOfRows * pColInfo->info.bytes); } } int64_t elapsedTime = taosGetTimestampUs() - st; - tsdbDebug("%p build data block from cache completed, elapsed time:%"PRId64" us, numOfRows:%d, numOfCols:%d, %s", pTsdbReadHandle, - elapsedTime, numOfRows, numOfCols, pTsdbReadHandle->idStr); + tsdbDebug("%p build data block from cache completed, elapsed time:%" PRId64 " us, numOfRows:%d, numOfCols:%d, %s", + pTsdbReadHandle, elapsedTime, numOfRows, numOfCols, pTsdbReadHandle->idStr); return numOfRows; } @@ -2545,20 +2581,20 @@ static void destroyHelper(void* param) { return; } -// tQueryInfo* pInfo = (tQueryInfo*)param; -// if (pInfo->optr != TSDB_RELATION_IN) { -// taosMemoryFreeClear(pInfo->q); -// } else { -// taosHashCleanup((SHashObj *)(pInfo->q)); -// } + // tQueryInfo* pInfo = (tQueryInfo*)param; + // if (pInfo->optr != TSDB_RELATION_IN) { + // taosMemoryFreeClear(pInfo->q); + // } else { + // taosHashCleanup((SHashObj *)(pInfo->q)); + // } taosMemoryFree(param); } -#define TSDB_PREV_ROW 0x1 -#define TSDB_NEXT_ROW 0x2 +#define TSDB_PREV_ROW 0x1 +#define TSDB_NEXT_ROW 0x2 -static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { +static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { if (pTsdbReadHandle->checkFiles) { // check if the query range overlaps with the file data block bool exists = true; @@ -2570,13 +2606,13 @@ static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { } if (exists) { - tsdbRetrieveDataBlock((tsdbReaderT*) pTsdbReadHandle, NULL); + tsdbRetrieveDataBlock((tsdbReaderT*)pTsdbReadHandle, NULL); if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, 0); assert(*(int64_t*)pColInfo->pData == pTsdbReadHandle->window.skey); } - pTsdbReadHandle->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found. + pTsdbReadHandle->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found. return exists; } @@ -2589,16 +2625,17 @@ static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { } // current result is empty - if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey && pTsdbReadHandle->cur.rows == 0) { -// STsdbMemTable* pMemRef = pTsdbReadHandle->pMemTable; + if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey && + pTsdbReadHandle->cur.rows == 0) { + // STsdbMemTable* pMemRef = pTsdbReadHandle->pMemTable; -// doGetExternalRow(pTsdbReadHandle, TSDB_PREV_ROW, pMemRef); -// doGetExternalRow(pTsdbReadHandle, TSDB_NEXT_ROW, pMemRef); + // doGetExternalRow(pTsdbReadHandle, TSDB_PREV_ROW, pMemRef); + // doGetExternalRow(pTsdbReadHandle, TSDB_NEXT_ROW, pMemRef); bool result = tsdbGetExternalRow(pTsdbReadHandle); -// pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); -// pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); + // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); + // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); pTsdbReadHandle->currentLoadExternalRows = false; return result; @@ -2610,30 +2647,31 @@ static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // the last row is cached in buffer, return it directly. // here note that the pTsdbReadHandle->window must be the TS_INITIALIZER - int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); + int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); assert(numOfTables > 0 && numOfCols > 0); SQueryFilePos* cur = &pTsdbReadHandle->cur; - STSRow* pRow = NULL; - TSKEY key = TSKEY_INITIAL_VAL; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1:-1; + STSRow* pRow = NULL; + TSKEY key = TSKEY_INITIAL_VAL; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; if (++pTsdbReadHandle->activeIndex < numOfTables) { STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); -// int32_t ret = tsdbGetCachedLastRow(pCheckInfo->pTableObj, &pRow, &key); -// if (ret != TSDB_CODE_SUCCESS) { -// return false; -// } - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, pRow, NULL, numOfCols, pCheckInfo->tableId, NULL, NULL, true); + // int32_t ret = tsdbGetCachedLastRow(pCheckInfo->pTableObj, &pRow, &key); + // if (ret != TSDB_CODE_SUCCESS) { + // return false; + // } + mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, pRow, NULL, numOfCols, pCheckInfo->tableId, + NULL, NULL, true); taosMemoryFreeClear(pRow); // update the last key value pCheckInfo->lastKey = key + step; - cur->rows = 1; // only one row - cur->lastKey = key + step; + cur->rows = 1; // only one row + cur->lastKey = key + step; cur->mixBlock = true; cur->win.skey = key; cur->win.ekey = key; @@ -2644,9 +2682,7 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { return false; } - - -//static bool loadCachedLast(STsdbReadHandle* pTsdbReadHandle) { +// static bool loadCachedLast(STsdbReadHandle* pTsdbReadHandle) { // // the last row is cached in buffer, return it directly. // // here note that the pTsdbReadHandle->window must be the TS_INITIALIZER // int32_t tgNumOfCols = (int32_t)QH_GET_NUM_OF_COLS(pTsdbReadHandle); @@ -2666,8 +2702,8 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // int32_t numOfCols = pTable->maxColNum; // // if (pTable->lastCols == NULL || pTable->maxColNum <= 0) { -// tsdbWarn("no last cached for table %s, uid:%" PRIu64 ",tid:%d", pTable->name->data, pTable->uid, pTable->tableId); -// continue; +// tsdbWarn("no last cached for table %s, uid:%" PRIu64 ",tid:%d", pTable->name->data, pTable->uid, +// pTable->tableId); continue; // } // // int32_t i = 0, j = 0; @@ -2802,7 +2838,7 @@ static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { int64_t stime = taosGetTimestampUs(); - while(pTsdbReadHandle->activeIndex < numOfTables) { + while (pTsdbReadHandle->activeIndex < numOfTables) { if (loadBlockOfActiveTable(pTsdbReadHandle)) { return true; } @@ -2812,8 +2848,8 @@ static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { pTsdbReadHandle->activeIndex += 1; pTsdbReadHandle->locateStart = false; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->cur.rows = 0; + pTsdbReadHandle->checkFiles = true; + pTsdbReadHandle->cur.rows = 0; pTsdbReadHandle->currentLoadExternalRows = pTsdbReadHandle->loadExternalRow; terrno = TSDB_CODE_SUCCESS; @@ -2827,15 +2863,16 @@ static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { // handle data in cache situation bool tsdbNextDataBlock(tsdbReaderT pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - for(int32_t i = 0; i < taosArrayGetSize(pTsdbReadHandle->pColumns); ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pTsdbReadHandle->pColumns); ++i) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); colInfoDataCleanup(pColInfo, pTsdbReadHandle->outputCapacity); } if (emptyQueryTimewindow(pTsdbReadHandle)) { - tsdbDebug("%p query window not overlaps with the data set, no result returned, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); + tsdbDebug("%p query window not overlaps with the data set, no result returned, %s", pTsdbReadHandle, + pTsdbReadHandle->idStr); return false; } @@ -2845,15 +2882,15 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // TODO refactor: remove "type" if (pTsdbReadHandle->type == TSDB_QUERY_TYPE_LAST) { if (pTsdbReadHandle->cachelastrow == TSDB_CACHED_TYPE_LASTROW) { -// return loadCachedLastRow(pTsdbReadHandle); + // return loadCachedLastRow(pTsdbReadHandle); } else if (pTsdbReadHandle->cachelastrow == TSDB_CACHED_TYPE_LAST) { -// return loadCachedLast(pTsdbReadHandle); + // return loadCachedLast(pTsdbReadHandle); } } if (pTsdbReadHandle->loadType == BLOCK_LOAD_TABLE_SEQ_ORDER) { return loadDataBlockFromTableSeq(pTsdbReadHandle); - } else { // loadType == RR and Offset Order + } else { // loadType == RR and Offset Order if (pTsdbReadHandle->checkFiles) { // check if the query range overlaps with the file data block bool exists = true; @@ -2885,7 +2922,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { } } -//static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, STsdbMemTable* pMemRef) { +// static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, STsdbMemTable* pMemRef) { // STsdbReadHandle* pSecQueryHandle = NULL; // // if (type == TSDB_PREV_ROW && pTsdbReadHandle->prev) { @@ -2990,14 +3027,14 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // memcpy((char*)pCol->pData, (char*)s->pData + s->info.bytes * pos, pCol->info.bytes); // } // -//out_of_memory: +// out_of_memory: // tsdbCleanupReadHandle(pSecQueryHandle); // return terrno; //} bool tsdbGetExternalRow(tsdbReaderT pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; - SQueryFilePos* cur = &pTsdbReadHandle->cur; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; + SQueryFilePos* cur = &pTsdbReadHandle->cur; cur->fid = INT32_MIN; cur->mixBlock = true; @@ -3006,7 +3043,7 @@ bool tsdbGetExternalRow(tsdbReaderT pHandle) { return false; } - int32_t numOfCols = (int32_t) QH_GET_NUM_OF_COLS(pTsdbReadHandle); + int32_t numOfCols = (int32_t)QH_GET_NUM_OF_COLS(pTsdbReadHandle); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, i); SColumnInfoData* first = taosArrayGet(pTsdbReadHandle->prev, i); @@ -3053,36 +3090,36 @@ bool tsdbGetExternalRow(tsdbReaderT pHandle) { //} bool isTsdbCacheLastRow(tsdbReaderT* pReader) { - return ((STsdbReadHandle *)pReader)->cachelastrow > TSDB_CACHED_TYPE_NONE; + return ((STsdbReadHandle*)pReader)->cachelastrow > TSDB_CACHED_TYPE_NONE; } -int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo *groupList) { +int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo* groupList) { assert(pTsdbReadHandle != NULL && groupList != NULL); -// TSKEY key = TSKEY_INITIAL_VAL; -// -// SArray* group = taosArrayGetP(groupList->pGroupList, 0); -// assert(group != NULL); -// -// STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(group, 0); -// -// int32_t code = 0; -// -// if (((STable*)pInfo->pTable)->lastRow) { -// code = tsdbGetCachedLastRow(pInfo->pTable, NULL, &key); -// if (code != TSDB_CODE_SUCCESS) { -// pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_NONE; -// } else { -// pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LASTROW; -// } -// } -// -// // update the tsdb query time range -// if (pTsdbReadHandle->cachelastrow != TSDB_CACHED_TYPE_NONE) { -// pTsdbReadHandle->window = TSWINDOW_INITIALIZER; -// pTsdbReadHandle->checkFiles = false; -// pTsdbReadHandle->activeIndex = -1; // start from -1 -// } + // TSKEY key = TSKEY_INITIAL_VAL; + // + // SArray* group = taosArrayGetP(groupList->pGroupList, 0); + // assert(group != NULL); + // + // STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(group, 0); + // + // int32_t code = 0; + // + // if (((STable*)pInfo->pTable)->lastRow) { + // code = tsdbGetCachedLastRow(pInfo->pTable, NULL, &key); + // if (code != TSDB_CODE_SUCCESS) { + // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_NONE; + // } else { + // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LASTROW; + // } + // } + // + // // update the tsdb query time range + // if (pTsdbReadHandle->cachelastrow != TSDB_CACHED_TYPE_NONE) { + // pTsdbReadHandle->window = TSWINDOW_INITIALIZER; + // pTsdbReadHandle->checkFiles = false; + // pTsdbReadHandle->activeIndex = -1; // start from -1 + // } return TSDB_CODE_SUCCESS; } @@ -3091,21 +3128,20 @@ int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle) { assert(pTsdbReadHandle != NULL); int32_t code = 0; -// if (pTsdbReadHandle->pTsdb && atomic_load_8(&pTsdbReadHandle->pTsdb->hasCachedLastColumn)){ -// pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LAST; -// } + // if (pTsdbReadHandle->pTsdb && atomic_load_8(&pTsdbReadHandle->pTsdb->hasCachedLastColumn)){ + // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LAST; + // } // update the tsdb query time range if (pTsdbReadHandle->cachelastrow) { - pTsdbReadHandle->checkFiles = false; + pTsdbReadHandle->checkFiles = false; pTsdbReadHandle->activeIndex = -1; // start from -1 } return code; } - -STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { +STimeWindow updateLastrowForEachGroup(STableGroupInfo* groupList) { STimeWindow window = {INT64_MAX, INT64_MIN}; int32_t totalNumOfTable = 0; @@ -3113,24 +3149,24 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { // NOTE: starts from the buffer in case of descending timestamp order check data blocks size_t numOfGroups = taosArrayGetSize(groupList->pGroupList); - for(int32_t j = 0; j < numOfGroups; ++j) { + for (int32_t j = 0; j < numOfGroups; ++j) { SArray* pGroup = taosArrayGetP(groupList->pGroupList, j); TSKEY key = TSKEY_INITIAL_VAL; STableKeyInfo keyInfo = {0}; size_t numOfTables = taosArrayGetSize(pGroup); - for(int32_t i = 0; i < numOfTables; ++i) { - STableKeyInfo* pInfo = (STableKeyInfo*) taosArrayGet(pGroup, i); + for (int32_t i = 0; i < numOfTables; ++i) { + STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(pGroup, i); // if the lastKey equals to INT64_MIN, there is no data in this table - TSKEY lastKey = 0;//((STable*)(pInfo->pTable))->lastKey; + TSKEY lastKey = 0; //((STable*)(pInfo->pTable))->lastKey; if (key < lastKey) { key = lastKey; -// keyInfo.pTable = pInfo->pTable; + // keyInfo.pTable = pInfo->pTable; keyInfo.lastKey = key; - pInfo->lastKey = key; + pInfo->lastKey = key; if (key < window.skey) { window.skey = key; @@ -3143,18 +3179,18 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { } // more than one table in each group, only one table left for each group -// if (keyInfo.pTable != NULL) { -// totalNumOfTable++; -// if (taosArrayGetSize(pGroup) == 1) { -// // do nothing -// } else { -// taosArrayClear(pGroup); -// taosArrayPush(pGroup, &keyInfo); -// } -// } else { // mark all the empty groups, and remove it later -// taosArrayDestroy(pGroup); -// taosArrayPush(emptyGroup, &j); -// } + // if (keyInfo.pTable != NULL) { + // totalNumOfTable++; + // if (taosArrayGetSize(pGroup) == 1) { + // // do nothing + // } else { + // taosArrayClear(pGroup); + // taosArrayPush(pGroup, &keyInfo); + // } + // } else { // mark all the empty groups, and remove it later + // taosArrayDestroy(pGroup); + // taosArrayPush(emptyGroup, &j); + // } } // window does not being updated, so set the original @@ -3163,7 +3199,7 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { assert(totalNumOfTable == 0 && taosArrayGetSize(groupList->pGroupList) == numOfGroups); } - taosArrayRemoveBatch(groupList->pGroupList, TARRAY_GET_START(emptyGroup), (int32_t) taosArrayGetSize(emptyGroup)); + taosArrayRemoveBatch(groupList->pGroupList, TARRAY_GET_START(emptyGroup), (int32_t)taosArrayGetSize(emptyGroup)); taosArrayDestroy(emptyGroup); groupList->numOfTables = totalNumOfTable; @@ -3172,7 +3208,7 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDataBlockInfo) { STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; - SQueryFilePos* cur = &pHandle->cur; + SQueryFilePos* cur = &pHandle->cur; uint64_t uid = 0; @@ -3185,11 +3221,12 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa uid = pCheckInfo->tableId; } - tsdbDebug("data block generated, uid:%"PRIu64" numOfRows:%d, tsrange:%"PRId64" - %"PRId64" %s", uid, cur->rows, cur->win.skey, - cur->win.ekey, pHandle->idStr); + tsdbDebug("data block generated, uid:%" PRIu64 " numOfRows:%d, tsrange:%" PRId64 " - %" PRId64 " %s", uid, cur->rows, + cur->win.skey, cur->win.ekey, pHandle->idStr); -// pDataBlockInfo->uid = uid; // block Id may be over write by assigning uid fro this data block. Do NOT assign the table uid - pDataBlockInfo->rows = cur->rows; + // pDataBlockInfo->uid = uid; // block Id may be over write by assigning uid fro this data block. Do NOT assign + // the table uid + pDataBlockInfo->rows = cur->rows; pDataBlockInfo->window = cur->win; pDataBlockInfo->numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pHandle)); } @@ -3198,7 +3235,7 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa * return null for mixed data block, if not a complete file data block, the statistics value will always return NULL */ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStatis** pBlockStatis) { - STsdbReadHandle* pHandle = (STsdbReadHandle*) pTsdbReadHandle; + STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; SQueryFilePos* c = &pHandle->cur; if (c->mixBlock) { @@ -3228,7 +3265,7 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStati size_t numOfCols = QH_GET_NUM_OF_COLS(pHandle); memset(pHandle->statis, 0, numOfCols * sizeof(SDataStatis)); - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { pHandle->statis[i].colId = colIds[i]; } @@ -3242,9 +3279,9 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStati pPrimaryColStatis->min = pBlockInfo->compBlock->keyFirst; pPrimaryColStatis->max = pBlockInfo->compBlock->keyLast; - //update the number of NULL data rows - for(int32_t i = 1; i < numOfCols; ++i) { - if (pHandle->statis[i].numOfNull == -1) { // set the column data are all NULL + // update the number of NULL data rows + for (int32_t i = 1; i < numOfCols; ++i) { + if (pHandle->statis[i].numOfNull == -1) { // set the column data are all NULL pHandle->statis[i].numOfNull = pBlockInfo->compBlock->numOfRows; } } @@ -3294,9 +3331,10 @@ SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) { int32_t emptySize = pHandle->outputCapacity - numOfRows; int32_t reqNumOfCols = (int32_t)taosArrayGetSize(pHandle->pColumns); - for(int32_t i = 0; i < reqNumOfCols; ++i) { + for (int32_t i = 0; i < reqNumOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pHandle->pColumns, i); - memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, numOfRows * pColInfo->info.bytes); + memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, + numOfRows * pColInfo->info.bytes); } } @@ -3352,7 +3390,7 @@ void filterPrepare(void* expr, void* param) { #endif -static int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { +static int32_t tableGroupComparFn(const void* p1, const void* p2, const void* param) { #if 0 STableGroupSupporter* pTableGroupSupp = (STableGroupSupporter*) param; STable* pTable1 = ((STableKeyInfo*) p1)->uid; @@ -3449,7 +3487,8 @@ void createTableGroupImpl(SArray* pGroups, SArray* pTableList, size_t numOfTable taosArrayPush(pGroups, &g); } -SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColIndex* pCols, int32_t numOfOrderCols, TSKEY skey) { +SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColIndex* pCols, int32_t numOfOrderCols, + TSKEY skey) { assert(pTableList != NULL); SArray* pTableGroup = taosArrayInit(1, POINTER_BYTES); @@ -3459,7 +3498,7 @@ SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColInd return pTableGroup; } - if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table + if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table SArray* sa = taosArrayDup(pTableList); if (sa == NULL) { taosArrayDestroy(pTableGroup); @@ -3481,7 +3520,7 @@ SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColInd return pTableGroup; } -//static bool tableFilterFp(const void* pNode, void* param) { +// static bool tableFilterFp(const void* pNode, void* param) { // tQueryInfo* pInfo = (tQueryInfo*) param; // // STable* pTable = (STable*)(SL_GET_NODE_DATA((SSkipListNode*)pNode)); @@ -3566,15 +3605,16 @@ SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColInd // return true; //} -//static void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param); +// static void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp +// *param); -//static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) { -// // query according to the expression tree +// static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) { +// // // query according to the expression tree // SExprTraverseSupp supp = { -// .nodeFilterFn = (__result_filter_fn_t) tableFilterFp, +// .nodeFilterFn = (__result_filter_fn_t)tableFilterFp, // .setupInfoFn = filterPrepare, // .pExtInfo = pSTable->tagSchema, -// }; +// }; // // getTableListfromSkipList(pExpr, pSTable->pIndex, pRes, &supp); // tExprTreeDestroy(pExpr, destroyHelper); @@ -3586,19 +3626,20 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch SColIndex* pColIndex, int32_t numOfCols, uint64_t reqId, uint64_t taskId) { STbCfg* pTbCfg = metaGetTbInfoByUid(pMeta, uid); if (pTbCfg == NULL) { - tsdbError("%p failed to get stable, uid:%"PRIu64", TID:0x%"PRIx64" QID:0x%"PRIx64, pMeta, uid, taskId, reqId); + tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId); terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; goto _error; } if (pTbCfg->type != META_SUPER_TABLE) { - tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", TID:0x%"PRIx64" QID:0x%"PRIx64, pMeta, uid, taskId, reqId); - terrno = TSDB_CODE_OPS_NOT_SUPPORT; //basically, this error is caused by invalid sql issued by client + tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, + reqId); + terrno = TSDB_CODE_OPS_NOT_SUPPORT; // basically, this error is caused by invalid sql issued by client goto _error; } - //NOTE: not add ref count for super table - SArray* res = taosArrayInit(8, sizeof(STableKeyInfo)); + // NOTE: not add ref count for super table + SArray* res = taosArrayInit(8, sizeof(STableKeyInfo)); SSchemaWrapper* pTagSchema = metaGetTableSchema(pMeta, uid, 0, true); // no tags and tbname condition, all child tables of this stable are involved @@ -3608,66 +3649,44 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch goto _error; } - pGroupInfo->numOfTables = (uint32_t) taosArrayGetSize(res); - pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); + pGroupInfo->numOfTables = (uint32_t)taosArrayGetSize(res); + pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); - tsdbDebug("%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu, TID:0x%"PRIx64" QID:0x%"PRIx64, pMeta, - pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList), taskId, reqId); + tsdbDebug("%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu, TID:0x%" PRIx64 + " QID:0x%" PRIx64, + pMeta, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList), taskId, reqId); taosArrayDestroy(res); return ret; } int32_t ret = TSDB_CODE_SUCCESS; -// tExprNode* expr = NULL; -// -// TRY(TSDB_MAX_TAG_CONDITIONS) { -// expr = exprTreeFromTableName(tbnameCond); -// if (expr == NULL) { -// expr = exprTreeFromBinary(pTagCond, len); -// } else { -// CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, expr, NULL); -// tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len); -// if (tagExpr != NULL) { -// CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, tagExpr, NULL); -// tExprNode* tbnameExpr = expr; -// expr = taosMemoryCalloc(1, sizeof(tExprNode)); -// if (expr == NULL) { -// THROW( TSDB_CODE_TDB_OUT_OF_MEMORY ); -// } -// expr->nodeType = TSQL_NODE_EXPR; -// expr->_node.optr = (uint8_t)tagNameRelType; -// expr->_node.pLeft = tagExpr; -// expr->_node.pRight = tbnameExpr; -// } -// } -// CLEANUP_EXECUTE(); -// -// } CATCH( code ) { -// CLEANUP_EXECUTE(); -// terrno = code; -// tsdbUnlockRepoMeta(tsdb); // unlock tsdb in any cases -// -// goto _error; -// // TODO: more error handling -// } END_TRY -// -// doQueryTableList(pTable, res, expr); -// pGroupInfo->numOfTables = (uint32_t)taosArrayGetSize(res); -// pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); -// -// tsdbDebug("%p stable tid:%d, uid:%"PRIu64" query, numOfTables:%u, belong to %" PRIzu " groups", tsdb, pTable->tableId, -// pTable->uid, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList)); -// -// taosArrayDestroy(res); -// -// if (tsdbUnlockRepoMeta(tsdb) < 0) goto _error; -// return ret; - _error: + SFilterInfo* filterInfo = NULL; + ret = filterInitFromNode((SNode*)pTagCond, &filterInfo, 0); + if (ret != TSDB_CODE_SUCCESS) { + terrno = ret; + return ret; + } + ret = tsdbQueryTableList(pMeta, res, filterInfo); + pGroupInfo->numOfTables = (uint32_t)taosArrayGetSize(res); + pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); + + // tsdbDebug("%p stable tid:%d, uid:%" PRIu64 " query, numOfTables:%u, belong to %" PRIzu " groups", tsdb, + // pTable->tableId, pTable->uid, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList)); + + taosArrayDestroy(res); + return ret; + +_error: return terrno; } +int32_t tsdbQueryTableList(void* pMeta, SArray* pRes, void* filterInfo) { + // impl later + + return TSDB_CODE_SUCCESS; +} int32_t tsdbGetOneTableGroup(void* pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo* pGroupInfo) { STbCfg* pTbCfg = metaGetTbInfoByUid(pMeta, uid); if (pTbCfg == NULL) { @@ -3686,7 +3705,7 @@ int32_t tsdbGetOneTableGroup(void* pMeta, uint64_t uid, TSKEY startKey, STableGr taosArrayPush(pGroupInfo->pGroupList, &group); return TSDB_CODE_SUCCESS; - _error: +_error: return terrno; } @@ -3765,7 +3784,6 @@ static void* destroyTableCheckInfo(SArray* pTableCheckInfo) { return NULL; } - void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)queryHandle; if (pTsdbReadHandle == NULL) { @@ -3779,7 +3797,7 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { taosMemoryFreeClear(pTsdbReadHandle->statis); if (!emptyQueryTimewindow(pTsdbReadHandle)) { -// tsdbMayUnTakeMemSnapshot(pTsdbReadHandle); + // tsdbMayUnTakeMemSnapshot(pTsdbReadHandle); } else { assert(pTsdbReadHandle->pTableCheckInfo == NULL); } @@ -3798,8 +3816,10 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { SIOCostSummary* pCost = &pTsdbReadHandle->cost; - tsdbDebug("%p :io-cost summary: head-file read cnt:%"PRIu64", head-file time:%"PRIu64" us, statis-info:%"PRId64" us, datablock:%" PRId64" us, check data:%"PRId64" us, %s", - pTsdbReadHandle, pCost->headFileLoad, pCost->headFileLoadTime, pCost->statisInfoLoadTime, pCost->blockLoadTime, pCost->checkForNextTime, pTsdbReadHandle->idStr); + tsdbDebug("%p :io-cost summary: head-file read cnt:%" PRIu64 ", head-file time:%" PRIu64 " us, statis-info:%" PRId64 + " us, datablock:%" PRId64 " us, check data:%" PRId64 " us, %s", + pTsdbReadHandle, pCost->headFileLoad, pCost->headFileLoadTime, pCost->statisInfoLoadTime, + pCost->blockLoadTime, pCost->checkForNextTime, pTsdbReadHandle->idStr); taosMemoryFreeClear(pTsdbReadHandle); } @@ -4053,37 +4073,37 @@ static void queryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, S } // Apply the filter expression to each node in the skiplist to acquire the qualified nodes in skip list -void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param) { - if (pExpr == NULL) { - return; - } - - tExprNode *pLeft = pExpr->_node.pLeft; - tExprNode *pRight = pExpr->_node.pRight; - - // column project - if (pLeft->nodeType != TSQL_NODE_EXPR && pRight->nodeType != TSQL_NODE_EXPR) { - assert(pLeft->nodeType == TSQL_NODE_COL && (pRight->nodeType == TSQL_NODE_VALUE || pRight->nodeType == TSQL_NODE_DUMMY)); - - param->setupInfoFn(pExpr, param->pExtInfo); - - tQueryInfo *pQueryInfo = pExpr->_node.info; - if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE - && pQueryInfo->optr != TSDB_RELATION_MATCH && pQueryInfo->optr != TSDB_RELATION_NMATCH - && pQueryInfo->optr != TSDB_RELATION_IN)) { - queryIndexedColumn(pSkipList, pQueryInfo, result); - } else { - queryIndexlessColumn(pSkipList, pQueryInfo, result, param->nodeFilterFn); - } - - return; - } - - // The value of hasPK is always 0. - uint8_t weight = pLeft->_node.hasPK + pRight->_node.hasPK; - assert(weight == 0 && pSkipList != NULL && taosArrayGetSize(result) == 0); - - //apply the hierarchical filter expression to every node in skiplist to find the qualified nodes - applyFilterToSkipListNode(pSkipList, pExpr, result, param); -} +//void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param) { +// if (pExpr == NULL) { +// return; +// } +// +// tExprNode *pLeft = pExpr->_node.pLeft; +// tExprNode *pRight = pExpr->_node.pRight; +// +// // column project +// if (pLeft->nodeType != TSQL_NODE_EXPR && pRight->nodeType != TSQL_NODE_EXPR) { +// assert(pLeft->nodeType == TSQL_NODE_COL && (pRight->nodeType == TSQL_NODE_VALUE || pRight->nodeType == TSQL_NODE_DUMMY)); +// +// param->setupInfoFn(pExpr, param->pExtInfo); +// +// tQueryInfo *pQueryInfo = pExpr->_node.info; +// if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE +// && pQueryInfo->optr != TSDB_RELATION_MATCH && pQueryInfo->optr != TSDB_RELATION_NMATCH +// && pQueryInfo->optr != TSDB_RELATION_IN)) { +// queryIndexedColumn(pSkipList, pQueryInfo, result); +// } else { +// queryIndexlessColumn(pSkipList, pQueryInfo, result, param->nodeFilterFn); +// } +// +// return; +// } +// +// // The value of hasPK is always 0. +// uint8_t weight = pLeft->_node.hasPK + pRight->_node.hasPK; +// assert(weight == 0 && pSkipList != NULL && taosArrayGetSize(result) == 0); +// +// //apply the hierarchical filter expression to every node in skiplist to find the qualified nodes +// applyFilterToSkipListNode(pSkipList, pExpr, result, param); +//} #endif diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 9fee599a5d..37bc4b771f 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -411,7 +411,7 @@ typedef struct STableScanInfo { SResultRowInfo* pResultRowInfo; int32_t* rowCellInfoOffset; SExprInfo* pExpr; - SSDataBlock block; + SSDataBlock* pResBlock; SArray* pColMatchInfo; int32_t numOfOutput; int64_t elapsedTime; @@ -569,6 +569,9 @@ typedef struct SGroupbyOperatorInfo { int32_t groupKeyLen; // total group by column width SGroupResInfo groupResInfo; SAggSupporter aggSup; + SExprInfo* pScalarExprInfo; + int32_t numOfScalarExpr;// the number of scalar expression in group operator + SqlFunctionCtx*pScalarFuncCtx; } SGroupbyOperatorInfo; typedef struct SDataGroupInfo { @@ -674,7 +677,7 @@ void operatorDummyCloseFn(void* param, int32_t numOfCols); int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num); int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey); -void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); +void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, int32_t* rowCellOffset); void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset); void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order); int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, @@ -685,12 +688,11 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI uint64_t* total, SArray* pColList); void doSetOperatorCompleted(SOperatorInfo* pOperator); void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock); -SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity); -SSDataBlock* loadNextDataBlock(void* param); +SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset); SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t repeatTime, - int32_t reverseTime, SArray* pColMatchInfo, SNode* pCondition, SExecTaskInfo* pTaskInfo); + int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SExecTaskInfo* pTaskInfo); SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); @@ -704,8 +706,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlot, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, int64_t gap, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, - SArray* pGroupColList, SNode* pCondition, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); +SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, + SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo); SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo); @@ -729,6 +731,8 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOf int32_t numOfOutput); #endif +void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList); + void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order); void finalizeQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput); diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 1edebcd7db..626cb1b5f0 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -92,9 +92,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, return false; } - // NOTE: there are four bytes of an integer more than the required buffer space. - // struct size + data payload + length for each column + bitmap length - pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockDataGetSerialMetaSize(pInput->pData) + blockDataGetSize(pInput->pData); + pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockEstimateEncodeSize(pInput->pData); pBuf->pData = taosMemoryMalloc(pBuf->allocSize); if (pBuf->pData == NULL) { diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index b86d75cc7b..0eac507822 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -234,9 +234,8 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator) { void operatorDummyCloseFn(void* param, int32_t numOfCols) {} -static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, - SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); - +static int32_t doCopyToSDataBlock(SSDataBlock* pBlock, int32_t rowCapacity, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, + int32_t orderType, int32_t* rowCellOffset); static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size); static void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow* win); @@ -1068,9 +1067,9 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, pCtx[i].size = pBlock->info.rows; pCtx[i].currentStage = MAIN_SCAN; - SExprInfo expr = pOperator->pExpr[i]; - for (int32_t j = 0; j < expr.base.numOfParams; ++j) { - SFunctParam *pFuncParam = &expr.base.pParam[j]; + SExprInfo* pOneExpr = &pOperator->pExpr[i]; + for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) { + SFunctParam *pFuncParam = &pOneExpr->base.pParam[j]; if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) { int32_t slotId = pFuncParam->pCol->slotId; pCtx[i].input.pData[j] = taosArrayGet(pBlock->pDataBlock, slotId); @@ -1145,19 +1144,21 @@ static void setPseudoOutputColInfo(SSDataBlock* pResult, SqlFunctionCtx* pCtx, S } } -static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, - int32_t numOfOutput, SArray* pPseudoList) { +void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList) { setPseudoOutputColInfo(pResult, pCtx, pPseudoList); pResult->info.groupId = pSrcBlock->info.groupId; for (int32_t k = 0; k < numOfOutput; ++k) { + int32_t outputSlotId = pExpr[k].base.resSchema.slotId; + SqlFunctionCtx* pfCtx = &pCtx[k]; + if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query - SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k); - colDataAssign(pColInfoData, pCtx[k].input.pData[0], pCtx[k].input.numOfRows); + SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId); + colDataAssign(pColInfoData, pfCtx->input.pData[0], pfCtx->input.numOfRows); pResult->info.rows = pSrcBlock->info.rows; } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_VALUE) { - SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k); + SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId); for (int32_t i = 0; i < pSrcBlock->info.rows; ++i) { colDataAppend(pColInfoData, i, taosVariantGet(&pExpr[k].base.pParam[0].param, pExpr[k].base.pParam[0].param.nType), TSDB_DATA_TYPE_NULL == pExpr[k].base.pParam[0].param.nType); } @@ -1167,40 +1168,40 @@ static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSData taosArrayPush(pBlockList, &pSrcBlock); SScalarParam dest = {0}; - dest.columnData = taosArrayGet(pResult->pDataBlock, k); + dest.columnData = taosArrayGet(pResult->pDataBlock, outputSlotId); scalarCalculate(pExpr[k].pExpr->_optrRoot.pRootNode, pBlockList, &dest); pResult->info.rows = dest.numOfRows; taosArrayDestroy(pBlockList); } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_FUNCTION) { - ASSERT(!fmIsAggFunc(pCtx[k].functionId)); + ASSERT(!fmIsAggFunc(pfCtx->functionId)); - if (fmIsPseudoColumnFunc(pCtx[k].functionId)) { + if (fmIsPseudoColumnFunc(pfCtx->functionId)) { // do nothing - } else if (fmIsNonstandardSQLFunc(pCtx[k].functionId)) { + } else if (fmIsNonstandardSQLFunc(pfCtx->functionId)) { // todo set the correct timestamp column - pCtx[k].input.pPTS = taosArrayGet(pSrcBlock->pDataBlock, 1); + pfCtx->input.pPTS = taosArrayGet(pSrcBlock->pDataBlock, 1); SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[k]); - pCtx[k].fpSet.init(&pCtx[k], pResInfo); + pfCtx->fpSet.init(&pCtx[k], pResInfo); - pCtx[k].pOutput = taosArrayGet(pResult->pDataBlock, k); - pCtx[k].offset = pResult->info.rows; // set the start offset + pfCtx->pOutput = taosArrayGet(pResult->pDataBlock, outputSlotId); + pfCtx->offset = pResult->info.rows; // set the start offset if (taosArrayGetSize(pPseudoList) > 0) { int32_t* outputColIndex = taosArrayGet(pPseudoList, 0); - pCtx[k].pTsOutput = (SColumnInfoData*)pCtx[*outputColIndex].pOutput; + pfCtx->pTsOutput = (SColumnInfoData*)pCtx[*outputColIndex].pOutput; } - int32_t numOfRows = pCtx[k].fpSet.process(&pCtx[k]); + int32_t numOfRows = pfCtx->fpSet.process(pfCtx); pResult->info.rows += numOfRows; } else { SArray* pBlockList = taosArrayInit(4, POINTER_BYTES); taosArrayPush(pBlockList, &pSrcBlock); SScalarParam dest = {0}; - dest.columnData = taosArrayGet(pResult->pDataBlock, k); + dest.columnData = taosArrayGet(pResult->pDataBlock, outputSlotId); scalarCalculate((SNode*)pExpr[k].pExpr->_function.pFunctNode, pBlockList, &dest); pResult->info.rows = dest.numOfRows; @@ -1810,7 +1811,7 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx* pCtx, int32_t numOfOutput) { return TSDB_CODE_SUCCESS; } -static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) { +SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) { SqlFunctionCtx* pFuncCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx)); if (pFuncCtx == NULL) { return NULL; @@ -1851,12 +1852,12 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num pCtx->input.pData = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES); pCtx->input.pColumnDataAgg = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES); - pCtx->pTsOutput = NULL;//taosArrayInit(4, POINTER_BYTES); + pCtx->pTsOutput = NULL; pCtx->resDataInfo.bytes = pFunct->resSchema.bytes; pCtx->resDataInfo.type = pFunct->resSchema.type; pCtx->order = TSDB_ORDER_ASC; - pCtx->start.key = INT64_MIN; - pCtx->end.key = INT64_MIN; + pCtx->start.key = INT64_MIN; + pCtx->end.key = INT64_MIN; #if 0 for (int32_t j = 0; j < pCtx->numOfParams; ++j) { // int16_t type = pFunct->param[j].nType; @@ -3330,8 +3331,7 @@ void setIntervalQueryRange(STaskRuntimeEnv* pRuntimeEnv, TSKEY key) { * @param pQInfo * @param result */ -static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, - SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset) { +int32_t doCopyToSDataBlock(SSDataBlock* pBlock, int32_t rowCapacity, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, int32_t* rowCellOffset) { int32_t numOfRows = getNumOfTotalRes(pGroupResInfo); int32_t numOfResult = pBlock->info.rows; // there are already exists result rows @@ -3370,7 +3370,9 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResI pGroupResInfo->index += 1; for (int32_t j = 0; j < pBlock->info.numOfCols; ++j) { - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, j); + int32_t slotId = pExprInfo[j].base.resSchema.slotId; + + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId); SResultRowEntryInfo* pEntryInfo = getResultCell(pRow, j, rowCellOffset); char* in = GET_ROWCELL_INTERBUF(pEntryInfo); @@ -3391,8 +3393,8 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResI return 0; } -void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, - int32_t* rowCellOffset) { +void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, + int32_t* rowCellOffset) { assert(pGroupResInfo->currentGroup <= pGroupResInfo->totalGroup); blockDataCleanup(pBlock); @@ -3401,7 +3403,7 @@ void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock } int32_t orderType = TSDB_ORDER_ASC; - doCopyToSDataBlock(pBuf, pGroupResInfo, orderType, pBlock, rowCapacity, rowCellOffset); + doCopyToSDataBlock(pBlock, rowCapacity, pExprInfo, pBuf, pGroupResInfo, orderType, rowCellOffset); // add condition (pBlock->info.rows >= 1) just to runtime happy blockDataUpdateTsWindow(pBlock); @@ -4438,32 +4440,6 @@ _error: return NULL; } -SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { - SSDataBlock* pResBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - if (pResBlock == NULL) { - return NULL; - } - - size_t numOfCols = taosArrayGetSize(pExprInfo); - pResBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); - - SArray* pResult = pResBlock->pDataBlock; - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData colInfoData = {0}; - SExprInfo* p = taosArrayGetP(pExprInfo, i); - - SResSchema* pSchema = &p->base.resSchema; - colInfoData.info.type = pSchema->type; - colInfoData.info.colId = pSchema->colId; - colInfoData.info.bytes = pSchema->bytes; - colInfoData.info.scale = pSchema->scale; - colInfoData.info.precision = pSchema->precision; - taosArrayPush(pResult, &colInfoData); - } - - return pResBlock; -} - static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey); static void cleanupAggSup(SAggSupporter* pAggSup); @@ -4777,7 +4753,7 @@ static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGr SColumn* pCol = taosArrayGet(pGroupInfo, i); for (int32_t j = 0; j < numOfCols; ++j) { SExprInfo* pe = &pExprInfo[j]; - if (pe->base.resSchema.colId == pCol->colId) { + if (pe->base.resSchema.slotId == pCol->colId) { taosArrayPush(plist, pCol); taosArrayPush(pInfo->groupInfo, &j); len += pCol->bytes; @@ -4816,7 +4792,7 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t goto _error; } - pInfo->binfo.pCtx = createSqlFunctionCtx_rv(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset); + pInfo->binfo.pCtx = createSqlFunctionCtx(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset); initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1); if (pInfo->binfo.pCtx == NULL || pInfo->binfo.pRes == NULL) { @@ -5137,9 +5113,7 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo* pOperator, bool* newgro SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity, - pAggInfo->binfo.rowCellInfoOffset); - + toSDatablock(pInfo->pRes, pAggInfo->binfo.capacity, &pAggInfo->groupResInfo, pOperator->pExpr, pAggInfo->pResultBuf, pAggInfo->binfo.rowCellInfoOffset); if (pInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pAggInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -5188,8 +5162,7 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo* pOperator, bool* newgro updateNumOfRowsInResultRows(pInfo->pCtx, pOperator->numOfOutput, &pInfo->resultRowInfo, pInfo->rowCellInfoOffset); initGroupResInfo(&pAggInfo->groupResInfo, &pInfo->resultRowInfo); - toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity, - pAggInfo->binfo.rowCellInfoOffset); + toSDatablock(pInfo->pRes, pAggInfo->binfo.capacity, &pAggInfo->groupResInfo, pOperator->pExpr, pAggInfo->pResultBuf, pAggInfo->binfo.rowCellInfoOffset); if (pInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pAggInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); @@ -5204,6 +5177,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); + #if 0 if (pProjectInfo->existDataBlock) { // TODO refactor SSDataBlock* pBlock = pProjectInfo->existDataBlock; @@ -5392,8 +5366,7 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro } blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, - pInfo->binfo.rowCellInfoOffset); + toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); @@ -5411,8 +5384,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup } if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, - pInfo->binfo.rowCellInfoOffset); + toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -5447,8 +5419,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated); blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, - pInfo->binfo.rowCellInfoOffset); + toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); ASSERT(pInfo->binfo.pRes->info.rows > 0); pOperator->status = OP_RES_TO_RETURN; @@ -5693,7 +5664,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) { SOptrBasicInfo* pBInfo = &pInfo->binfo; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); + toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); return NULL; @@ -5725,7 +5696,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) { initGroupResInfo(&pInfo->groupResInfo, &pBInfo->resultRowInfo); blockDataEnsureCapacity(pBInfo->pRes, pBInfo->capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); + toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } @@ -5742,7 +5713,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup) SOptrBasicInfo* pBInfo = &pInfo->binfo; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); + toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); return NULL; @@ -5774,7 +5745,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup) initGroupResInfo(&pInfo->groupResInfo, &pBInfo->resultRowInfo); blockDataEnsureCapacity(pBInfo->pRes, pBInfo->capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); + toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } @@ -5953,7 +5924,7 @@ static void cleanupAggSup(SAggSupporter* pAggSup) { int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey) { - pBasicInfo->pCtx = createSqlFunctionCtx_rv(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset); + pBasicInfo->pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset); pBasicInfo->pRes = pResultBlock; pBasicInfo->capacity = numOfRows; @@ -6382,8 +6353,6 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim SExprInfo* pExpr, int32_t numOfOutput) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); - // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); @@ -6406,8 +6375,6 @@ SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRun SExprInfo* pExpr, int32_t numOfOutput) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); - // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); @@ -6682,45 +6649,13 @@ bool validateExprColumnInfo(SQueriedTableInfo* pTableInfo, SExprBasicInfo* pExpr return j != INT32_MIN; } -static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t numOfFilters, char** pMsg) { - for (int32_t f = 0; f < numOfFilters; ++f) { - SColumnFilterInfo* pFilterMsg = (SColumnFilterInfo*)(*pMsg); - - SColumnFilterInfo* pColFilter = &pColFilters[f]; - pColFilter->filterstr = htons(pFilterMsg->filterstr); - - (*pMsg) += sizeof(SColumnFilterInfo); - - if (pColFilter->filterstr) { - pColFilter->len = htobe64(pFilterMsg->len); - - pColFilter->pz = - (int64_t)taosMemoryCalloc(1, (size_t)(pColFilter->len + 1 * TSDB_NCHAR_SIZE)); // note: null-terminator - if (pColFilter->pz == 0) { - return TSDB_CODE_QRY_OUT_OF_MEMORY; - } - - memcpy((void*)pColFilter->pz, (*pMsg), (size_t)pColFilter->len); - (*pMsg) += (pColFilter->len + 1); - } else { - pColFilter->lowerBndi = htobe64(pFilterMsg->lowerBndi); - pColFilter->upperBndi = htobe64(pFilterMsg->upperBndi); - } - - pColFilter->lowerRelOptr = htons(pFilterMsg->lowerRelOptr); - pColFilter->upperRelOptr = htons(pFilterMsg->upperRelOptr); - } - - return TSDB_CODE_SUCCESS; -} - static SResSchema createResSchema(int32_t type, int32_t bytes, int32_t slotId, int32_t scale, int32_t precision, const char* name) { SResSchema s = {0}; - s.scale = scale; - s.type = type; - s.bytes = bytes; - s.colId = slotId; + s.scale = scale; + s.type = type; + s.bytes = bytes; + s.slotId = slotId; s.precision = precision; strncpy(s.name, name, tListLen(s.name)); @@ -6762,7 +6697,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* pTargetNode = (STargetNode*)nodesListGetNode(pGroupKeys, i - numOfFuncs); } - SExprInfo* pExp = &pExprs[pTargetNode->slotId]; + SExprInfo* pExp = &pExprs[i]; pExp->pExpr = taosMemoryCalloc(1, sizeof(tExprNode)); pExp->pExpr->_function.num = 1; @@ -6882,8 +6817,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo int32_t numOfCols = 0; tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId); SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); + SSDataBlock* pResBlock = createOutputBuf_rv1(pScanPhyNode->node.pOutputDataBlockDesc); + return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, - pScanPhyNode->reverse, pColList, pScanPhyNode->node.pConditions, pTaskInfo); + pScanPhyNode->reverse, pColList, pResBlock, pScanPhyNode->node.pConditions, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) { SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode; SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc); @@ -6938,9 +6875,15 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num); SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); + SExprInfo* pScalarExprInfo = NULL; + int32_t numOfScalarExpr = 0; if (pAggNode->pGroupKeys != NULL) { SArray* pColList = extractColumnInfo(pAggNode->pGroupKeys); - return createGroupOperatorInfo(op, pExprInfo, num, pResBlock, pColList, pAggNode->node.pConditions, pTaskInfo, NULL); + if (pAggNode->pExprs != NULL) { + pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr); + } + + return createGroupOperatorInfo(op, pExprInfo, num, pResBlock, pColList, pAggNode->node.pConditions, pScalarExprInfo, numOfScalarExpr, pTaskInfo, NULL); } else { return createAggregateOperatorInfo(op, pExprInfo, num, pResBlock, pTaskInfo, pTableGroupInfo); } @@ -7187,10 +7130,15 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod } *numOfOutputCols = 0; - int32_t num = LIST_LENGTH(pOutputNodeList->pSlots); for (int32_t i = 0; i < num; ++i) { SSlotDescNode* pNode = (SSlotDescNode*)nodesListGetNode(pOutputNodeList->pSlots, i); + // todo: add reserve flag check + if (pNode->slotId >= numOfCols) { // it is a column reserved for the arithmetic expression calculation + (*numOfOutputCols) += 1; + continue; + } + SColMatchInfo* info = taosArrayGet(pList, pNode->slotId); if (pNode->output) { (*numOfOutputCols) += 1; diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 8a10170fcd..c8a6697d4e 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -265,7 +265,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou SSDataBlock* pRes = pInfo->binfo.pRes; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset); + toSDatablock(pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); if (pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -285,6 +285,12 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); + + // there is an scalar expression that needs to be calculated before apply the group aggregation. + if (pInfo->pScalarExprInfo != NULL) { + projectApplyFunctions(pInfo->pScalarExprInfo, pBlock, pBlock, pInfo->pScalarFuncCtx, pInfo->numOfScalarExpr, NULL); + } + // setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput); doHashGroupbyAgg(pOperator, pBlock); } @@ -305,7 +311,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou initGroupResInfo(&pInfo->groupResInfo, &pInfo->binfo.resultRowInfo); while(1) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset); + toSDatablock(pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); doFilter(pInfo->pCondition, pRes); bool hasRemain = hasRemainDataInCurrentGroup(&pInfo->groupResInfo); @@ -322,16 +328,21 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou return (pRes->info.rows == 0)? NULL:pRes; } -SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition, SExecTaskInfo* pTaskInfo, - const STableGroupInfo* pTableGroupInfo) { +SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, + SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - pInfo->pGroupCols = pGroupColList; - pInfo->pCondition = pCondition; + pInfo->pGroupCols = pGroupColList; + pInfo->pCondition = pCondition; + + pInfo->pScalarExprInfo = pScalarExprInfo; + pInfo->numOfScalarExpr = numOfScalarExpr; + pInfo->pScalarFuncCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pInfo->binfo.rowCellInfoOffset); + int32_t code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList); if (code != TSDB_CODE_SUCCESS) { diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 4179999c4b..f1502df743 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -113,7 +113,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) { STableScanInfo* pTableScanInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - SSDataBlock* pBlock = &pTableScanInfo->block; + SSDataBlock* pBlock = pTableScanInfo->pResBlock; STableGroupInfo* pTableGroupInfo = &pOperator->pTaskInfo->tableqinfoGroupInfo; *newgroup = false; @@ -218,7 +218,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { } SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, - int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, + int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SExecTaskInfo* pTaskInfo) { assert(repeatTime > 0); @@ -232,12 +232,7 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, return NULL; } - pInfo->block.pDataBlock = taosArrayInit(numOfOutput, sizeof(SColumnInfoData)); - for (int32_t i = 0; i < numOfOutput; ++i) { - SColumnInfoData idata = {0}; - taosArrayPush(pInfo->block.pDataBlock, &idata); - } - + pInfo->pResBlock = pResBlock; pInfo->pFilterNode = pCondition; pInfo->dataReader = pTsdbReadHandle; pInfo->times = repeatTime; @@ -312,7 +307,7 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator, bool* newgroup) { tsdbGetFileBlocksDistInfo(pTableScanInfo->dataReader, &tableBlockDist); tableBlockDist.numOfRowsInMemTable = (int32_t) tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader); - SSDataBlock* pBlock = &pTableScanInfo->block; + SSDataBlock* pBlock = pTableScanInfo->pResBlock; pBlock->info.rows = 1; pBlock->info.numOfCols = 1; @@ -343,13 +338,13 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* } pInfo->dataReader = dataReader; - pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); +// pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); SColumnInfoData infoData = {0}; infoData.info.type = TSDB_DATA_TYPE_BINARY; infoData.info.bytes = 1024; infoData.info.colId = 0; - taosArrayPush(pInfo->block.pDataBlock, &infoData); +// taosArrayPush(pInfo->block.pDataBlock, &infoData); pOperator->name = "DataBlockInfoScanOperator"; // pOperator->operatorType = OP_TableBlockInfoScan; diff --git a/source/libs/function/inc/builtins.h b/source/libs/function/inc/builtins.h index f0349c55b9..624a2953c9 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -22,7 +22,7 @@ extern "C" { #include "functionMgt.h" -#define FUNCTION_NAME_MAX_LENGTH 16 +#define FUNCTION_NAME_MAX_LENGTH 32 #define FUNC_MGT_FUNC_CLASSIFICATION_MASK(n) (1 << n) @@ -41,12 +41,14 @@ extern "C" { #define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) typedef int32_t (*FCheckAndGetResultType)(SFunctionNode* pFunc); +typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow); typedef struct SBuiltinFuncDefinition { char name[FUNCTION_NAME_MAX_LENGTH]; EFunctionType type; uint64_t classification; FCheckAndGetResultType checkFunc; + FFuncDataRequired dataRequiredFunc; FExecGetEnv getEnvFunc; FExecInit initFunc; FExecProcess processFunc; diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 607bd279c1..09c468b610 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -21,10 +21,12 @@ extern "C" { #endif #include "function.h" +#include "functionMgt.h" bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); void functionFinalize(SqlFunctionCtx *pCtx); +EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow); bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t countFunction(SqlFunctionCtx *pCtx); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index b4d886dcdf..36de0d1149 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -25,8 +25,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "count", .type = FUNCTION_TYPE_COUNT, - .classification = FUNC_MGT_AGG_FUNC, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, .checkFunc = checkAndGetResultType, + .dataRequiredFunc = countDataRequired, .getEnvFunc = getCountFuncEnv, .initFunc = functionSetup, .processFunc = countFunction, @@ -389,7 +390,37 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .checkFunc = checkAndGetResultType, .getEnvFunc = NULL, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = castFunction, + .finalizeFunc = NULL + }, + { + .name = "to_iso8601", + .type = FUNCTION_TYPE_TO_ISO8601, + .classification = FUNC_MGT_SCALAR_FUNC, + .checkFunc = checkAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toISO8601Function, + .finalizeFunc = NULL + }, + { + .name = "to_unixtimestamp", + .type = FUNCTION_TYPE_TO_UNIXTIMESTAMP, + .classification = FUNC_MGT_SCALAR_FUNC, + .checkFunc = checkAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toUnixtimestampFunction, + .finalizeFunc = NULL + }, + { + .name = "timetruncate", + .type = FUNCTION_TYPE_TIMETRUNCATE, + .classification = FUNC_MGT_SCALAR_FUNC, + .checkFunc = checkAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeTruncateFunction, .finalizeFunc = NULL }, { @@ -599,7 +630,25 @@ int32_t checkAndGetResultType(SFunctionNode* pFunc) { break; } case FUNCTION_TYPE_CAST: { - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT }; + //type + SValueNode* pParam = nodesListGetNode(pFunc->pParameterList, 1); + int32_t paraType = pParam->datum.i; + //bytes + pParam = nodesListGetNode(pFunc->pParameterList, 2); + int32_t paraBytes = pParam->datum.i; + pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType}; + break; + } + case FUNCTION_TYPE_TO_ISO8601: { + pFunc->node.resType = (SDataType) { .bytes = 64, .type = TSDB_DATA_TYPE_BINARY}; + break; + } + case FUNCTION_TYPE_TO_UNIXTIMESTAMP: { + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + break; + } + case FUNCTION_TYPE_TIMETRUNCATE: { + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; break; } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 133e8f9c93..50c65439c0 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -55,6 +55,14 @@ void functionFinalize(SqlFunctionCtx *pCtx) { pResInfo->isNullRes = (pResInfo->numOfRes == 0)? 1:0; } +EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { + SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); + if (QUERY_NODE_COLUMN == nodeType(pParam) && PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pParam)->colId) { + return FUNC_DATA_REQUIRED_NO_NEEDED; + } + return FUNC_DATA_REQUIRED_STATIS_NEEDED; +} + bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(int64_t); return true; diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index c50dea5a9d..ea9b3bdf18 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -76,6 +76,16 @@ int32_t fmGetFuncResultType(SFunctionNode* pFunc) { return funcMgtBuiltins[pFunc->funcId].checkFunc(pFunc); } +EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { + if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) { + return FUNC_DATA_REQUIRED_ALL_NEEDED; + } + if (NULL == funcMgtBuiltins[pFunc->funcId].dataRequiredFunc) { + return FUNC_DATA_REQUIRED_ALL_NEEDED; + } + return funcMgtBuiltins[pFunc->funcId].dataRequiredFunc(pFunc, pTimeWindow); +} + int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) { if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { return TSDB_CODE_FAILED; @@ -120,6 +130,13 @@ bool fmIsNonstandardSQLFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_NONSTANDARD_SQL_FUNC); } +bool fmIsSpecialDataRequiredFunc(int32_t funcId) { + return isSpecificClassifyFunc(funcId, FUNC_MGT_SPECIAL_DATA_REQUIRED); +} + +bool fmIsDynamicScanOptimizedFunc(int32_t funcId) { + return isSpecificClassifyFunc(funcId, FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED); +} void fmFuncMgtDestroy() { void* m = gFunMgtService.pFuncNameHashTable; diff --git a/source/libs/function/src/tfill.c b/source/libs/function/src/tfill.c index 1f7e83286b..b6b5362187 100644 --- a/source/libs/function/src/tfill.c +++ b/source/libs/function/src/tfill.c @@ -541,7 +541,7 @@ struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, co pFillCol[i].col.bytes = pExprInfo->base.resSchema.bytes; pFillCol[i].col.type = (int8_t)pExprInfo->base.resSchema.type; pFillCol[i].col.offset = offset; - pFillCol[i].col.colId = pExprInfo->base.resSchema.colId; + pFillCol[i].col.colId = pExprInfo->base.resSchema.slotId; pFillCol[i].tagIndex = -2; pFillCol[i].flag = pExprInfo->base.pParam[0].pCol->flag; // always be the normal column for table query // pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId; diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index fe3b7cb8a0..975036575d 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -95,7 +95,6 @@ static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) { static void exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) { dataTypeCopy(&pSrc->resType, &pDst->resType); COPY_CHAR_ARRAY_FIELD(aliasName); - // CLONE_NODE_LIST_FIELD(pAssociationList); } static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) { @@ -222,15 +221,19 @@ static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) { } static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) { + COPY_ALL_SCALAR_FIELDS; COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pScanCols); CLONE_OBJECT_FIELD(pMeta, tableMetaClone); CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone); - COPY_SCALAR_FIELD(scanType); - COPY_SCALAR_FIELD(scanFlag); - COPY_SCALAR_FIELD(scanRange); - COPY_SCALAR_FIELD(tableName); - COPY_SCALAR_FIELD(showRewrite); + CLONE_NODE_LIST_FIELD(pDynamicScanFuncs); + return (SNode*)pDst; +} + +static SNode* logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) { + COPY_ALL_SCALAR_FIELDS; + COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); + CLONE_NODE_FIELD(pOnConditions); return (SNode*)pDst; } @@ -263,15 +266,8 @@ static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNo static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pDst) { COPY_ALL_SCALAR_FIELDS; COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); - // COPY_SCALAR_FIELD(winType); CLONE_NODE_LIST_FIELD(pFuncs); - // COPY_SCALAR_FIELD(interval); - // COPY_SCALAR_FIELD(offset); - // COPY_SCALAR_FIELD(sliding); - // COPY_SCALAR_FIELD(intervalUnit); - // COPY_SCALAR_FIELD(slidingUnit); CLONE_NODE_FIELD(pFill); - // COPY_SCALAR_FIELD(sessionGap); CLONE_NODE_FIELD(pTspk); return (SNode*)pDst; } @@ -360,6 +356,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) { return downstreamSourceCopy((const SDownstreamSourceNode*)pNode, (SDownstreamSourceNode*)pDst); case QUERY_NODE_LOGIC_PLAN_SCAN: return logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst); + case QUERY_NODE_LOGIC_PLAN_JOIN: + return logicJoinCopy((const SJoinLogicNode*)pNode, (SJoinLogicNode*)pDst); case QUERY_NODE_LOGIC_PLAN_AGG: return logicAggCopy((const SAggLogicNode*)pNode, (SAggLogicNode*)pDst); case QUERY_NODE_LOGIC_PLAN_PROJECT: diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 13093d63ac..8ab76f5714 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -723,6 +723,9 @@ static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) { static const char* jkTableScanPhysiPlanScanFlag = "ScanFlag"; static const char* jkTableScanPhysiPlanStartKey = "StartKey"; static const char* jkTableScanPhysiPlanEndKey = "EndKey"; +static const char* jkTableScanPhysiPlanRatio = "Ratio"; +static const char* jkTableScanPhysiPlanDataRequired = "DataRequired"; +static const char* jkTableScanPhysiPlanDynamicScanFuncs = "DynamicScanFuncs"; static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) { const STableScanPhysiNode* pNode = (const STableScanPhysiNode*)pObj; @@ -737,6 +740,15 @@ static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanEndKey, pNode->scanRange.ekey); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddDoubleToObject(pJson, jkTableScanPhysiPlanRatio, pNode->ratio); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired); + } + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkTableScanPhysiPlanDynamicScanFuncs, pNode->pDynamicScanFuncs); + } return code; } @@ -754,6 +766,15 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanEndKey, &pNode->scanRange.ekey); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetDoubleValue(pJson, jkTableScanPhysiPlanRatio, &pNode->ratio); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetNumberValue(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkTableScanPhysiPlanDynamicScanFuncs, &pNode->pDynamicScanFuncs); + } return code; } @@ -2767,6 +2788,7 @@ int32_t nodesStringToList(const char* pStr, SNodeList** pList) { return TSDB_CODE_FAILED; } int32_t code = jsonToNodeListImpl(pJson, pList); + tjsonDelete(pJson); if (TSDB_CODE_SUCCESS != code) { nodesDestroyList(*pList); terrno = code; diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 9f81b34274..1c565ddd37 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -158,6 +158,16 @@ SNodeptr nodesMakeNode(ENodeType type) { case QUERY_NODE_SHOW_FUNCTIONS_STMT: case QUERY_NODE_SHOW_INDEXES_STMT: case QUERY_NODE_SHOW_STREAMS_STMT: + case QUERY_NODE_SHOW_APPS_STMT: + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_LICENCE_STMT: + case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: + case QUERY_NODE_SHOW_CREATE_TABLE_STMT: + case QUERY_NODE_SHOW_CREATE_STABLE_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: + case QUERY_NODE_SHOW_SCORES_STMT: + case QUERY_NODE_SHOW_TOPICS_STMT: + case QUERY_NODE_SHOW_VARIABLE_STMT: case QUERY_NODE_SHOW_BNODES_STMT: case QUERY_NODE_SHOW_SNODES_STMT: return makeNode(type, sizeof(SShowStmt)); @@ -694,6 +704,17 @@ int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode) { return nodesListAppend(*pList, pNode); } +int32_t nodesListMakeStrictAppend(SNodeList** pList, SNodeptr pNode) { + if (NULL == *pList) { + *pList = nodesMakeList(); + if (NULL == *pList) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; + } + } + return nodesListStrictAppend(*pList, pNode); +} + int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) { if (NULL == pTarget || NULL == pSrc) { return TSDB_CODE_FAILED; diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 18bea4736c..94aec0e744 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -79,13 +79,13 @@ alter_account_option ::= USERS literal. alter_account_option ::= CONNS literal. { } alter_account_option ::= STATE literal. { } -/************************************************ create/alter/drop/show user *****************************************/ +/************************************************ create/alter/drop user **********************************************/ cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); } cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); } cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B); } cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); } -/************************************************ create/drop/alter/show dnode ****************************************/ +/************************************************ create/drop/alter dnode *********************************************/ cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); } cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); } cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); } @@ -124,7 +124,7 @@ cmd ::= DROP SNODE ON DNODE NK_INTEGER(A). cmd ::= CREATE MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_MNODE_STMT, &A); } cmd ::= DROP MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &A); } -/************************************************ create/drop/show/use database ***************************************/ +/************************************************ create/drop/use database ********************************************/ cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C); } cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); } cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); } @@ -332,6 +332,7 @@ cmd ::= SHOW ACCOUNTS. cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } +cmd ::= SHOW GRANTS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } cmd ::= SHOW CREATE DATABASE db_name(A). { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &A); } cmd ::= SHOW CREATE TABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, A); } cmd ::= SHOW CREATE STABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, A); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 318f7ca5f7..a14053ada7 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -257,13 +257,20 @@ SNodeList* addValueNodeFromTypeToList(SAstCreateContext* pCxt, SDataType dataTyp char buf[64] = {0}; //add value node for type snprintf(buf, sizeof(buf), "%u", dataType.type); - SToken token = {.type = TSDB_DATA_TYPE_TINYINT, .n = strlen(buf), .z = buf}; + SToken token = {.type = TSDB_DATA_TYPE_SMALLINT, .n = strlen(buf), .z = buf}; SNode* pNode = createValueNode(pCxt, token.type, &token); addNodeToList(pCxt, pList, pNode); //add value node for bytes memset(buf, 0, sizeof(buf)); - snprintf(buf, sizeof(buf), "%u", dataType.bytes); + int32_t bytes; + if (IS_VAR_DATA_TYPE(dataType.type)) { + bytes = (dataType.type == TSDB_DATA_TYPE_NCHAR) ? dataType.bytes * TSDB_NCHAR_SIZE : dataType.bytes; + bytes += VARSTR_HEADER_SIZE; + } else { + bytes = dataType.bytes; + } + snprintf(buf, sizeof(buf), "%d", bytes); token.type = TSDB_DATA_TYPE_BIGINT; token.n = strlen(buf); token.z = buf; diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index c31ec92bde..ead3ec90ad 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -143,7 +143,7 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab if (TSDB_CODE_SUCCESS == pCxt->code) { pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pRight); } - if (TSDB_CODE_SUCCESS == pCxt->code) { + if (TSDB_CODE_SUCCESS == pCxt->code && NULL != pJoin->pOnCond) { pCxt->code = rewriteCondition(pCxt, &pJoin->pOnCond); } } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index daeb98b3e6..5c2f10f810 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -80,6 +80,7 @@ static SKeyword keywordTable[] = { {"FSYNC", TK_FSYNC}, {"FUNCTION", TK_FUNCTION}, {"FUNCTIONS", TK_FUNCTIONS}, + {"GRANTS", TK_GRANTS}, {"GROUP", TK_GROUP}, {"HAVING", TK_HAVING}, {"IF", TK_IF}, @@ -131,10 +132,10 @@ static SKeyword keywordTable[] = { {"PRECISION", TK_PRECISION}, {"PRIVILEGE", TK_PRIVILEGE}, {"PREV", TK_PREV}, - {"_QENDTS", TK_QENDTS}, + {"_QENDTS", TK_QENDTS}, {"QNODE", TK_QNODE}, {"QNODES", TK_QNODES}, - {"_QSTARTTS", TK_QSTARTTS}, + {"_QSTARTTS", TK_QSTARTTS}, {"QTIME", TK_QTIME}, {"QUERIES", TK_QUERIES}, {"QUERY", TK_QUERY}, @@ -144,7 +145,7 @@ static SKeyword keywordTable[] = { {"RESET", TK_RESET}, {"RETENTIONS", TK_RETENTIONS}, {"ROLLUP", TK_ROLLUP}, - {"_ROWTS", TK_ROWTS}, + {"_ROWTS", TK_ROWTS}, {"SCORES", TK_SCORES}, {"SELECT", TK_SELECT}, {"SESSION", TK_SESSION}, @@ -163,7 +164,7 @@ static SKeyword keywordTable[] = { {"STATE", TK_STATE}, {"STATE_WINDOW", TK_STATE_WINDOW}, {"STORAGE", TK_STORAGE}, - {"STREAM", TK_STREAM}, + {"STREAM", TK_STREAM}, {"STREAMS", TK_STREAMS}, {"STREAM_MODE", TK_STREAM_MODE}, {"SYNCDB", TK_SYNCDB}, @@ -192,8 +193,8 @@ static SKeyword keywordTable[] = { {"VGROUPS", TK_VGROUPS}, {"VNODES", TK_VNODES}, {"WAL", TK_WAL}, - {"_WDURATION", TK_WDURATION}, - {"_WENDTS", TK_WENDTS}, + {"_WDURATION", TK_WDURATION}, + {"_WENDTS", TK_WENDTS}, {"WHERE", TK_WHERE}, {"_WSTARTTS", TK_WSTARTTS}, // {"ID", TK_ID}, @@ -221,7 +222,6 @@ static SKeyword keywordTable[] = { // {"UMINUS", TK_UMINUS}, // {"UPLUS", TK_UPLUS}, // {"BITNOT", TK_BITNOT}, - // {"GRANTS", TK_GRANTS}, // {"DOT", TK_DOT}, // {"CTIME", TK_CTIME}, // {"LP", TK_LP}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 8885373b2b..b3947b872e 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -21,7 +21,7 @@ #include "parUtil.h" #include "ttime.h" -#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : ((SValueNode*)(pVal))->datum.i) +#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : getBigintFromValueNode((SValueNode*)(pVal))) typedef struct STranslateContext { SParseContext* pParseCxt; @@ -380,6 +380,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) { static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { uint8_t precision = (NULL != pCxt->pCurrStmt ? pCxt->pCurrStmt->precision : pVal->node.resType.precision); + pVal->node.resType.precision = precision; if (pVal->isDuration) { if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, precision) != TSDB_CODE_SUCCESS) { @@ -452,6 +453,9 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { } pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; + } else { + pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; } return DEAL_RES_CONTINUE; } @@ -758,7 +762,7 @@ static int32_t createAllColumns(STranslateContext* pCxt, SNodeList** pCols) { size_t nums = taosArrayGetSize(pTables); for (size_t i = 0; i < nums; ++i) { STableNode* pTable = taosArrayGetP(pTables, i); - int32_t code = createColumnNodeByTable(pCxt, pTable, *pCols); + int32_t code = createColumnNodeByTable(pCxt, pTable, *pCols); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -825,11 +829,39 @@ static int32_t createFirstLastAllCols(STranslateContext* pCxt, SFunctionNode* pS return TSDB_CODE_SUCCESS; } +static bool isTableStar(SNode* pNode) { + return (QUERY_NODE_COLUMN == nodeType(pNode)) && (0 == strcmp(((SColumnNode*)pNode)->colName, "*")); +} + +static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SNodeList** pOutput) { + *pOutput = nodesMakeList(); + if (NULL == *pOutput) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY); + } + bool foundTable = false; + SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); + size_t nums = taosArrayGetSize(pTables); + for (size_t i = 0; i < nums; ++i) { + STableNode* pTable = taosArrayGetP(pTables, i); + if (0 == strcmp(pTable->tableAlias, pCol->tableAlias)) { + int32_t code = createColumnNodeByTable(pCxt, pTable, *pOutput); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + foundTable = true; + break; + } + } + if (!foundTable) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_TABLE_NOT_EXIST, pCol->tableAlias); + } + return TSDB_CODE_SUCCESS; +} + static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) { if (NULL == pSelect->pProjectionList) { // select * ... return createAllColumns(pCxt, &pSelect->pProjectionList); } else { - // todo : t.* SNode* pNode = NULL; WHERE_EACH(pNode, pSelect->pProjectionList) { if (isFirstLastStar(pNode)) { @@ -840,6 +872,14 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) { INSERT_LIST(pSelect->pProjectionList, pFuncs); ERASE_NODE(pSelect->pProjectionList); continue; + } else if (isTableStar(pNode)) { + SNodeList* pCols = NULL; + if (TSDB_CODE_SUCCESS != createTableAllCols(pCxt, (SColumnNode*)pNode, &pCols)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + INSERT_LIST(pSelect->pProjectionList, pCols); + ERASE_NODE(pSelect->pProjectionList); + continue; } WHERE_NEXT; } @@ -1041,6 +1081,27 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } +static int64_t getUnitPerMinute(uint8_t precision) { + switch (precision) { + case TSDB_TIME_PRECISION_MILLI: + return MILLISECOND_PER_MINUTE; + case TSDB_TIME_PRECISION_MICRO: + return MILLISECOND_PER_MINUTE * 1000L; + case TSDB_TIME_PRECISION_NANO: + return NANOSECOND_PER_MINUTE; + default: + break; + } + return MILLISECOND_PER_MINUTE; +} + +static int64_t getBigintFromValueNode(SValueNode* pVal) { + if (pVal->isDuration) { + return pVal->datum.i / getUnitPerMinute(pVal->node.resType.precision); + } + return pVal->datum.i; +} + static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbReq* pReq) { if (NULL != pRetentions) { pReq->pRetensions = taosArrayInit(LIST_LENGTH(pRetentions), sizeof(SRetention)); @@ -1098,7 +1159,10 @@ static int32_t checkRangeOption(STranslateContext* pCxt, const char* pName, SVal if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { return pCxt->errCode; } - int64_t val = pVal->datum.i; + if (pVal->isDuration && (TIME_UNIT_MINUTE != pVal->unit && TIME_UNIT_HOUR != pVal->unit && TIME_UNIT_DAY != pVal->unit)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_OPTION_UNIT, pName, pVal->unit); + } + int64_t val = getBigintFromValueNode(pVal); if (val < minVal || val > maxVal) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_RANGE_OPTION, pName, val, minVal, maxVal); } @@ -1187,9 +1251,18 @@ static int32_t checkKeepOption(STranslateContext* pCxt, SNodeList* pKeep) { } } - int32_t daysToKeep0 = ((SValueNode*)nodesListGetNode(pKeep, 0))->datum.i; - int32_t daysToKeep1 = ((SValueNode*)nodesListGetNode(pKeep, 1))->datum.i; - int32_t daysToKeep2 = ((SValueNode*)nodesListGetNode(pKeep, 2))->datum.i; + SValueNode* pKeep0 = (SValueNode*)nodesListGetNode(pKeep, 0); + SValueNode* pKeep1 = (SValueNode*)nodesListGetNode(pKeep, 1); + SValueNode* pKeep2 = (SValueNode*)nodesListGetNode(pKeep, 2); + if ((pKeep0->isDuration && (TIME_UNIT_MINUTE != pKeep0->unit && TIME_UNIT_HOUR != pKeep0->unit && TIME_UNIT_DAY != pKeep0->unit)) || + (pKeep1->isDuration && (TIME_UNIT_MINUTE != pKeep1->unit && TIME_UNIT_HOUR != pKeep1->unit && TIME_UNIT_DAY != pKeep1->unit)) || + (pKeep2->isDuration && (TIME_UNIT_MINUTE != pKeep2->unit && TIME_UNIT_HOUR != pKeep2->unit && TIME_UNIT_DAY != pKeep2->unit))) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_KEEP_UNIT, pKeep0->unit, pKeep1->unit, pKeep2->unit); + } + + int32_t daysToKeep0 = getBigintFromValueNode(pKeep0); + int32_t daysToKeep1 = getBigintFromValueNode(pKeep1); + int32_t daysToKeep2 = getBigintFromValueNode(pKeep2); if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP || daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_KEEP_VALUE, daysToKeep0, daysToKeep1, daysToKeep2, @@ -1240,8 +1313,7 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, SDatabaseOptions* p code = checkRangeOption(pCxt, "compression", pOptions->pCompressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); } if (TSDB_CODE_SUCCESS == code) { - code = - checkRangeOption(pCxt, "daysPerFile", pOptions->pDaysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); + code = checkRangeOption(pCxt, "daysPerFile", pOptions->pDaysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); } if (TSDB_CODE_SUCCESS == code) { code = checkRangeOption(pCxt, "fsyncPeriod", pOptions->pFsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 171324aa99..85d574d9e7 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -62,35 +62,39 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL: return "This interval value is too small : %s"; case TSDB_CODE_PAR_DB_NOT_SPECIFIED: - return "db not specified"; + return "Database not specified"; case TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME: return "Invalid identifier name : %s"; case TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR: - return "corresponding super table not in this db"; + return "Corresponding super table not in this db"; case TSDB_CODE_PAR_INVALID_RANGE_OPTION: - return "invalid option %s: %"PRId64" valid range: [%d, %d]"; + return "Invalid option %s: %"PRId64" valid range: [%d, %d]"; case TSDB_CODE_PAR_INVALID_STR_OPTION: - return "invalid option %s: %s"; + return "Invalid option %s: %s"; case TSDB_CODE_PAR_INVALID_ENUM_OPTION: - return "invalid option %s: %"PRId64", only %d, %d allowed"; + return "Invalid option %s: %"PRId64", only %d, %d allowed"; case TSDB_CODE_PAR_INVALID_TTL_OPTION: - return "invalid option ttl: %"PRId64", should be greater than or equal to %d"; + return "Invalid option ttl: %"PRId64", should be greater than or equal to %d"; case TSDB_CODE_PAR_INVALID_KEEP_NUM: - return "invalid number of keep options"; + return "Invalid number of keep options"; case TSDB_CODE_PAR_INVALID_KEEP_ORDER: - return "invalid keep value, should be keep0 <= keep1 <= keep2"; + return "Invalid keep value, should be keep0 <= keep1 <= keep2"; case TSDB_CODE_PAR_INVALID_KEEP_VALUE: - return "invalid option keep: %d, %d, %d valid range: [%d, %d]"; + return "Invalid option keep: %d, %d, %d valid range: [%d, %d]"; case TSDB_CODE_PAR_INVALID_COMMENT_OPTION: - return "invalid option comment, length cannot exceed %d"; + return "Invalid option comment, length cannot exceed %d"; case TSDB_CODE_PAR_INVALID_F_RANGE_OPTION: - return "invalid option %s: %f valid range: [%d, %d]"; + return "Invalid option %s: %f valid range: [%d, %d]"; case TSDB_CODE_PAR_INVALID_ROLLUP_OPTION: - return "invalid option rollup: only one function is allowed"; + return "Invalid option rollup: only one function is allowed"; case TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION: - return "invalid option retentions"; + return "Invalid option retentions"; case TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST: return "GROUP BY and WINDOW-clause can't be used together"; + case TSDB_CODE_PAR_INVALID_OPTION_UNIT: + return "Invalid option %s unit: %c, only m, h, d allowed"; + case TSDB_CODE_PAR_INVALID_KEEP_UNIT: + return "Invalid option keep unit: %c, %c, %c, only m, h, d allowed"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index a8f764f0e1..610f6b9263 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -100,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 313 +#define YYNOCODE 314 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SToken yy21; - bool yy173; - EOrder yy256; - EFillMode yy268; - SDataType yy288; - SAlterOption yy289; - EJoinType yy440; - EOperatorType yy468; - SNodeList* yy476; - ENullOrder yy525; - SNode* yy564; - int32_t yy620; + ENullOrder yy69; + SNode* yy140; + EFillMode yy174; + SAlterOption yy181; + SNodeList* yy220; + EJoinType yy224; + EOrder yy238; + SToken yy253; + bool yy273; + SDataType yy368; + EOperatorType yy480; + int32_t yy528; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -132,18 +132,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 547 -#define YYNRULE 409 -#define YYNRULE_WITH_ACTION 409 -#define YYNTOKEN 207 -#define YY_MAX_SHIFT 546 -#define YY_MIN_SHIFTREDUCE 806 -#define YY_MAX_SHIFTREDUCE 1214 -#define YY_ERROR_ACTION 1215 -#define YY_ACCEPT_ACTION 1216 -#define YY_NO_ACTION 1217 -#define YY_MIN_REDUCE 1218 -#define YY_MAX_REDUCE 1626 +#define YYNSTATE 548 +#define YYNRULE 410 +#define YYNTOKEN 208 +#define YY_MAX_SHIFT 547 +#define YY_MIN_SHIFTREDUCE 807 +#define YY_MAX_SHIFTREDUCE 1216 +#define YY_ERROR_ACTION 1217 +#define YY_ACCEPT_ACTION 1218 +#define YY_NO_ACTION 1219 +#define YY_MIN_REDUCE 1220 +#define YY_MAX_REDUCE 1629 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -210,481 +209,483 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1529) +#define YY_ACTTAB_COUNT (1533) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 25, 194, 1478, 1327, 257, 449, 1494, 462, 269, 312, - /* 10 */ 277, 1427, 30, 28, 1474, 1481, 310, 1418, 1420, 1454, - /* 20 */ 266, 1478, 1050, 274, 429, 32, 31, 29, 27, 26, - /* 30 */ 1511, 21, 1338, 1474, 1480, 306, 461, 445, 1048, 238, - /* 40 */ 1478, 32, 31, 29, 27, 26, 1072, 448, 23, 100, - /* 50 */ 11, 1465, 1474, 1480, 1494, 289, 433, 1055, 32, 31, - /* 60 */ 29, 27, 26, 30, 28, 1157, 1605, 228, 1495, 1496, - /* 70 */ 1500, 266, 216, 1050, 1, 1368, 30, 28, 1511, 131, - /* 80 */ 1558, 137, 98, 1603, 266, 445, 1050, 1605, 1171, 1048, - /* 90 */ 52, 431, 127, 1551, 1552, 448, 1556, 543, 1555, 1465, - /* 100 */ 131, 11, 1048, 96, 1603, 1073, 1216, 50, 1055, 1049, - /* 110 */ 49, 1333, 380, 379, 11, 70, 1495, 1496, 1500, 1544, - /* 120 */ 461, 1055, 347, 1543, 1540, 1, 1219, 932, 485, 484, - /* 130 */ 483, 936, 482, 938, 939, 481, 941, 478, 1, 947, - /* 140 */ 475, 949, 950, 472, 469, 1051, 488, 84, 543, 1329, - /* 150 */ 83, 82, 81, 80, 79, 78, 77, 76, 75, 282, - /* 160 */ 1049, 543, 1054, 1074, 1075, 1101, 1102, 1103, 1104, 1105, - /* 170 */ 1106, 1107, 1108, 1049, 12, 1050, 462, 1070, 164, 30, - /* 180 */ 28, 117, 371, 1230, 132, 311, 382, 266, 376, 1050, - /* 190 */ 1605, 1048, 381, 405, 1465, 97, 1051, 377, 375, 157, - /* 200 */ 378, 1338, 155, 131, 373, 1048, 305, 1603, 304, 1051, - /* 210 */ 1055, 396, 461, 1054, 1074, 1075, 1101, 1102, 1103, 1104, - /* 220 */ 1105, 1106, 1107, 1108, 1055, 419, 1054, 1074, 1075, 1101, - /* 230 */ 1102, 1103, 1104, 1105, 1106, 1107, 1108, 406, 462, 1181, - /* 240 */ 132, 7, 1605, 30, 28, 447, 132, 72, 1074, 1075, - /* 250 */ 543, 266, 462, 1050, 368, 131, 894, 30, 28, 1603, - /* 260 */ 1076, 319, 1049, 1338, 543, 266, 12, 1050, 1605, 1048, - /* 270 */ 416, 1179, 1180, 1182, 1183, 896, 1049, 1338, 52, 424, - /* 280 */ 420, 131, 1494, 1048, 132, 1603, 84, 1605, 1055, 83, - /* 290 */ 82, 81, 80, 79, 78, 77, 76, 75, 1051, 1334, - /* 300 */ 1604, 333, 1055, 65, 1603, 7, 1511, 32, 31, 29, - /* 310 */ 27, 26, 1051, 445, 1511, 1054, 118, 101, 1241, 7, - /* 320 */ 1296, 445, 423, 448, 1330, 1494, 1316, 1465, 543, 1054, - /* 330 */ 1074, 1075, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, - /* 340 */ 1049, 132, 543, 119, 1495, 1496, 1500, 141, 140, 1511, - /* 350 */ 237, 132, 1070, 422, 1049, 462, 445, 122, 497, 326, - /* 360 */ 462, 1558, 338, 1465, 320, 1071, 448, 429, 1378, 346, - /* 370 */ 1465, 339, 1385, 265, 1240, 347, 1051, 189, 256, 1554, - /* 380 */ 1338, 434, 1618, 1383, 59, 1338, 229, 1495, 1496, 1500, - /* 390 */ 1051, 499, 100, 1054, 1074, 1075, 1101, 1102, 1103, 1104, - /* 400 */ 1105, 1106, 1107, 1108, 843, 1331, 842, 1054, 1074, 1075, - /* 410 */ 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 462, 1465, - /* 420 */ 30, 28, 1385, 1385, 844, 98, 1239, 1335, 266, 271, - /* 430 */ 1050, 1267, 114, 1419, 1383, 128, 1551, 1552, 1415, 1556, - /* 440 */ 29, 27, 26, 1338, 337, 139, 1048, 332, 331, 330, - /* 450 */ 329, 328, 1485, 325, 324, 323, 322, 318, 317, 316, - /* 460 */ 315, 314, 313, 462, 1483, 1055, 32, 31, 29, 27, - /* 470 */ 26, 1465, 459, 539, 538, 32, 31, 29, 27, 26, - /* 480 */ 250, 1323, 1, 519, 518, 517, 516, 281, 1338, 515, - /* 490 */ 514, 513, 102, 508, 507, 506, 505, 504, 503, 502, - /* 500 */ 501, 108, 1494, 462, 241, 543, 164, 511, 115, 462, - /* 510 */ 371, 300, 72, 241, 449, 270, 1341, 1049, 460, 374, - /* 520 */ 1428, 1325, 251, 115, 249, 248, 1511, 370, 1338, 1089, - /* 530 */ 1218, 1340, 373, 445, 1338, 842, 276, 1120, 32, 31, - /* 540 */ 29, 27, 26, 448, 115, 404, 1120, 1465, 9, 8, - /* 550 */ 1558, 366, 1340, 1051, 93, 92, 91, 90, 89, 88, - /* 560 */ 87, 86, 85, 225, 1495, 1496, 1500, 1314, 1553, 1122, - /* 570 */ 1054, 1074, 1075, 1101, 1102, 1103, 1104, 1105, 1106, 1107, - /* 580 */ 1108, 387, 1164, 279, 462, 1121, 1385, 1126, 1072, 462, - /* 590 */ 116, 115, 278, 208, 1121, 222, 395, 1383, 280, 1340, - /* 600 */ 1238, 1089, 868, 1125, 1237, 6, 1236, 220, 1270, 1338, - /* 610 */ 166, 22, 1125, 390, 1338, 1385, 497, 500, 384, 1310, - /* 620 */ 142, 869, 1133, 1494, 165, 1235, 1384, 24, 264, 1115, - /* 630 */ 1116, 1117, 1118, 1119, 1123, 1124, 24, 264, 1115, 1116, - /* 640 */ 1117, 1118, 1119, 1123, 1124, 1465, 1077, 1511, 1156, 1465, - /* 650 */ 42, 1465, 1234, 41, 445, 32, 31, 29, 27, 26, - /* 660 */ 382, 1233, 376, 106, 448, 1321, 381, 408, 1465, 97, - /* 670 */ 1465, 377, 375, 433, 378, 512, 510, 1494, 1232, 1229, - /* 680 */ 1228, 1227, 436, 67, 68, 1495, 1496, 1500, 1544, 1226, - /* 690 */ 273, 272, 240, 1540, 394, 9, 8, 1465, 1225, 1224, - /* 700 */ 1063, 1511, 1563, 1152, 1605, 1223, 1465, 392, 432, 1222, - /* 710 */ 48, 47, 309, 1221, 136, 297, 1056, 131, 448, 303, - /* 720 */ 437, 1603, 1465, 1465, 1465, 1465, 1465, 246, 1494, 295, - /* 730 */ 299, 291, 287, 133, 1465, 1055, 440, 444, 69, 1495, - /* 740 */ 1496, 1500, 1544, 1465, 1465, 1152, 259, 1540, 126, 169, - /* 750 */ 1465, 546, 1511, 44, 1465, 1231, 132, 1178, 1465, 432, - /* 760 */ 190, 159, 446, 175, 158, 213, 412, 1571, 95, 448, - /* 770 */ 64, 1494, 1257, 1465, 535, 463, 531, 527, 523, 212, - /* 780 */ 61, 161, 163, 1494, 160, 162, 487, 1059, 1252, 69, - /* 790 */ 1495, 1496, 1500, 1544, 383, 1511, 1494, 259, 1540, 126, - /* 800 */ 1250, 1297, 445, 1213, 1214, 66, 417, 1511, 206, 191, - /* 810 */ 385, 342, 448, 178, 445, 33, 1465, 180, 1572, 1127, - /* 820 */ 1511, 403, 388, 1064, 448, 1379, 33, 445, 1465, 1155, - /* 830 */ 1085, 1494, 231, 1495, 1496, 1500, 184, 448, 458, 1058, - /* 840 */ 1067, 1465, 365, 1494, 69, 1495, 1496, 1500, 1544, 1112, - /* 850 */ 1574, 438, 259, 1540, 1617, 1511, 1512, 70, 1495, 1496, - /* 860 */ 1500, 1544, 445, 1578, 430, 411, 1541, 1511, 171, 441, - /* 870 */ 1057, 193, 448, 1070, 445, 2, 1465, 33, 284, 435, - /* 880 */ 245, 1017, 197, 1034, 448, 168, 199, 94, 1465, 894, - /* 890 */ 247, 454, 69, 1495, 1496, 1500, 1544, 1026, 214, 288, - /* 900 */ 259, 1540, 1617, 1494, 69, 1495, 1496, 1500, 1544, 138, - /* 910 */ 1061, 1601, 259, 1540, 1617, 104, 321, 152, 429, 205, - /* 920 */ 125, 106, 1417, 1562, 327, 925, 364, 1511, 360, 356, - /* 930 */ 352, 151, 44, 467, 445, 335, 920, 953, 104, 1494, - /* 940 */ 340, 1060, 957, 100, 448, 334, 336, 1081, 1465, 341, - /* 950 */ 1494, 1080, 32, 31, 29, 27, 26, 53, 344, 144, - /* 960 */ 149, 1079, 433, 1511, 70, 1495, 1496, 1500, 1544, 343, - /* 970 */ 445, 345, 443, 1540, 1511, 105, 98, 147, 51, 963, - /* 980 */ 448, 445, 348, 429, 1465, 106, 187, 1551, 428, 962, - /* 990 */ 427, 448, 104, 1605, 150, 1465, 107, 1078, 413, 367, - /* 1000 */ 232, 1495, 1496, 1500, 1494, 369, 131, 1328, 100, 1494, - /* 1010 */ 1603, 233, 1495, 1496, 1500, 154, 148, 1324, 121, 156, - /* 1020 */ 145, 74, 372, 397, 109, 110, 1326, 1322, 1511, 111, - /* 1030 */ 112, 255, 425, 1511, 398, 445, 407, 143, 1494, 399, - /* 1040 */ 445, 98, 400, 1077, 170, 448, 173, 418, 409, 1465, - /* 1050 */ 448, 129, 1551, 1552, 1465, 1556, 1575, 263, 1585, 452, - /* 1060 */ 410, 1055, 1511, 1584, 1494, 119, 1495, 1496, 1500, 445, - /* 1070 */ 233, 1495, 1496, 1500, 176, 415, 5, 179, 1211, 448, - /* 1080 */ 258, 421, 1565, 1465, 426, 414, 267, 99, 1511, 4, - /* 1090 */ 1076, 1152, 1559, 124, 183, 445, 34, 185, 260, 233, - /* 1100 */ 1495, 1496, 1500, 442, 1619, 448, 1494, 439, 17, 1465, - /* 1110 */ 456, 1494, 186, 1526, 1426, 450, 192, 1494, 455, 1602, - /* 1120 */ 451, 1620, 1425, 201, 268, 234, 1495, 1496, 1500, 215, - /* 1130 */ 1511, 457, 203, 58, 1339, 1511, 60, 445, 217, 465, - /* 1140 */ 494, 1511, 445, 1311, 211, 1210, 542, 448, 445, 1315, - /* 1150 */ 40, 1465, 448, 223, 224, 219, 1465, 1459, 448, 1494, - /* 1160 */ 221, 1458, 1465, 283, 1455, 285, 286, 226, 1495, 1496, - /* 1170 */ 1500, 1494, 235, 1495, 1496, 1500, 1044, 1045, 227, 1495, - /* 1180 */ 1496, 1500, 134, 1511, 1494, 290, 1453, 1452, 292, 293, - /* 1190 */ 445, 294, 296, 1451, 298, 1511, 1442, 135, 301, 302, - /* 1200 */ 448, 1313, 445, 1029, 1465, 1028, 1436, 1435, 1511, 308, - /* 1210 */ 209, 307, 448, 1494, 493, 445, 1465, 1434, 1433, 1000, - /* 1220 */ 236, 1495, 1496, 1500, 1410, 448, 1409, 1408, 1407, 1465, - /* 1230 */ 1406, 1405, 1508, 1495, 1496, 1500, 495, 1511, 1404, 1494, - /* 1240 */ 1403, 1402, 1401, 1400, 445, 1507, 1495, 1496, 1500, 1399, - /* 1250 */ 1398, 1397, 1396, 1395, 448, 492, 491, 490, 1465, 489, - /* 1260 */ 103, 1394, 209, 1511, 1393, 1494, 493, 1392, 1391, 1390, - /* 1270 */ 445, 1389, 1388, 1494, 243, 1495, 1496, 1500, 1002, 1387, - /* 1280 */ 448, 1386, 1269, 1450, 1465, 1444, 1432, 1423, 495, 1511, - /* 1290 */ 146, 1317, 1268, 1266, 350, 861, 445, 1511, 349, 1494, - /* 1300 */ 1506, 1495, 1496, 1500, 445, 351, 448, 492, 491, 490, - /* 1310 */ 1465, 489, 1264, 353, 448, 1262, 354, 355, 1465, 359, - /* 1320 */ 1260, 363, 357, 1511, 358, 362, 244, 1495, 1496, 1500, - /* 1330 */ 445, 1249, 361, 1248, 242, 1495, 1496, 1500, 1245, 1319, - /* 1340 */ 448, 1494, 73, 970, 1465, 968, 153, 1318, 511, 893, - /* 1350 */ 1258, 892, 891, 1253, 890, 887, 886, 252, 253, 1251, - /* 1360 */ 239, 1495, 1496, 1500, 386, 1511, 509, 254, 389, 1244, - /* 1370 */ 391, 1243, 445, 393, 71, 1449, 43, 167, 1036, 1443, - /* 1380 */ 401, 1431, 448, 113, 1430, 402, 1465, 1422, 123, 172, - /* 1390 */ 14, 15, 37, 54, 1483, 174, 177, 3, 33, 38, - /* 1400 */ 182, 35, 230, 1495, 1496, 1500, 56, 1177, 120, 10, - /* 1410 */ 188, 181, 1199, 8, 20, 19, 1198, 1170, 55, 1113, - /* 1420 */ 261, 1203, 1421, 1202, 1149, 453, 36, 1148, 262, 202, - /* 1430 */ 204, 16, 1204, 466, 1065, 275, 470, 1087, 1086, 13, - /* 1440 */ 18, 198, 130, 196, 473, 1175, 200, 195, 61, 931, - /* 1450 */ 45, 57, 476, 479, 965, 959, 875, 540, 961, 1482, - /* 1460 */ 541, 544, 39, 882, 881, 468, 207, 954, 951, 948, - /* 1470 */ 471, 1265, 859, 474, 464, 942, 940, 477, 480, 496, - /* 1480 */ 900, 880, 879, 878, 877, 876, 895, 62, 897, 872, - /* 1490 */ 871, 870, 46, 63, 867, 866, 498, 486, 865, 210, - /* 1500 */ 1263, 864, 520, 521, 946, 525, 945, 944, 943, 522, - /* 1510 */ 524, 526, 1261, 528, 529, 1259, 530, 532, 533, 534, - /* 1520 */ 1247, 536, 537, 1246, 1242, 1052, 964, 218, 545, + /* 0 */ 463, 25, 194, 52, 257, 306, 1497, 9, 8, 72, + /* 10 */ 277, 388, 30, 28, 463, 274, 369, 1421, 1423, 270, + /* 20 */ 266, 1481, 1052, 310, 1336, 1340, 396, 115, 1072, 1481, + /* 30 */ 1514, 1497, 1481, 1477, 1483, 1342, 1608, 446, 1050, 1340, + /* 40 */ 166, 1477, 1484, 391, 1477, 1483, 462, 449, 385, 131, + /* 50 */ 11, 1468, 406, 1606, 165, 1514, 312, 1057, 29, 27, + /* 60 */ 26, 348, 446, 30, 28, 1159, 463, 119, 1498, 1499, + /* 70 */ 1503, 266, 449, 1052, 1, 72, 1468, 30, 28, 265, + /* 80 */ 42, 1135, 375, 41, 462, 266, 238, 1052, 1497, 1050, + /* 90 */ 1331, 1340, 229, 1498, 1499, 1503, 407, 544, 540, 539, + /* 100 */ 1075, 11, 462, 1050, 450, 435, 1621, 269, 1057, 1051, + /* 110 */ 1430, 463, 1514, 381, 380, 11, 30, 28, 430, 446, + /* 120 */ 311, 117, 1057, 1232, 266, 1, 1052, 1608, 1608, 449, + /* 130 */ 513, 511, 1243, 1468, 430, 1468, 1340, 1124, 12, 1, + /* 140 */ 131, 1607, 1050, 100, 1606, 1606, 1053, 1318, 544, 70, + /* 150 */ 1498, 1499, 1503, 1547, 420, 1128, 12, 1546, 1543, 100, + /* 160 */ 1051, 1057, 544, 1056, 1076, 1077, 1103, 1104, 1105, 1106, + /* 170 */ 1107, 1108, 1109, 1110, 1051, 463, 98, 1468, 7, 22, + /* 180 */ 1242, 30, 28, 448, 319, 132, 128, 1554, 1555, 266, + /* 190 */ 1559, 1052, 98, 132, 118, 132, 348, 1053, 1298, 1387, + /* 200 */ 1340, 544, 129, 1554, 1555, 256, 1559, 1050, 425, 421, + /* 210 */ 1385, 1053, 1074, 1051, 1056, 1076, 1077, 1103, 1104, 1105, + /* 220 */ 1106, 1107, 1108, 1109, 1110, 1468, 1057, 1221, 1056, 1076, + /* 230 */ 1077, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 305, + /* 240 */ 844, 304, 843, 7, 1076, 1077, 9, 8, 84, 132, + /* 250 */ 1053, 83, 82, 81, 80, 79, 78, 77, 76, 75, + /* 260 */ 845, 32, 31, 29, 27, 26, 544, 1056, 1076, 1077, + /* 270 */ 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1051, 132, + /* 280 */ 424, 1418, 52, 30, 28, 237, 65, 1072, 139, 132, + /* 290 */ 383, 266, 377, 1052, 327, 96, 382, 339, 1241, 97, + /* 300 */ 101, 378, 376, 1335, 379, 216, 340, 1332, 1370, 1050, + /* 310 */ 32, 31, 29, 27, 26, 1053, 84, 1566, 1154, 83, + /* 320 */ 82, 81, 80, 79, 78, 77, 76, 75, 1057, 1220, + /* 330 */ 334, 1183, 1056, 1076, 1077, 1103, 1104, 1105, 1106, 1107, + /* 340 */ 1108, 1109, 1110, 1468, 1078, 7, 164, 445, 241, 137, + /* 350 */ 372, 895, 498, 93, 92, 91, 90, 89, 88, 87, + /* 360 */ 86, 85, 417, 1181, 1182, 1184, 1185, 501, 544, 1312, + /* 370 */ 897, 1079, 374, 1091, 250, 50, 141, 140, 49, 338, + /* 380 */ 1051, 1122, 333, 332, 331, 330, 329, 430, 326, 325, + /* 390 */ 324, 323, 322, 318, 317, 316, 315, 314, 313, 463, + /* 400 */ 164, 30, 28, 489, 372, 1561, 463, 450, 320, 266, + /* 410 */ 1561, 1052, 100, 1431, 1387, 347, 251, 1053, 249, 248, + /* 420 */ 271, 371, 1514, 1558, 1340, 1385, 374, 1050, 1557, 446, + /* 430 */ 1123, 1340, 1215, 1216, 1056, 1076, 1077, 1103, 1104, 1105, + /* 440 */ 1106, 1107, 1108, 1109, 1110, 98, 1057, 1269, 1127, 32, + /* 450 */ 31, 29, 27, 26, 432, 127, 1554, 1555, 1317, 1559, + /* 460 */ 1114, 423, 189, 1, 1073, 32, 31, 29, 27, 26, + /* 470 */ 1561, 59, 24, 264, 1117, 1118, 1119, 1120, 1121, 1125, + /* 480 */ 1126, 32, 31, 29, 27, 26, 544, 241, 1556, 175, + /* 490 */ 1166, 157, 1333, 122, 155, 1158, 1074, 1240, 1051, 520, + /* 500 */ 519, 518, 517, 281, 1380, 516, 515, 514, 102, 509, + /* 510 */ 508, 507, 506, 505, 504, 503, 502, 108, 159, 209, + /* 520 */ 1122, 158, 500, 494, 933, 486, 485, 484, 937, 483, + /* 530 */ 939, 940, 482, 942, 479, 1053, 948, 476, 950, 951, + /* 540 */ 473, 470, 1468, 1239, 1173, 496, 116, 1329, 1218, 1316, + /* 550 */ 6, 222, 1056, 1076, 1077, 1103, 1104, 1105, 1106, 1107, + /* 560 */ 1108, 1109, 1110, 220, 493, 492, 491, 21, 490, 1123, + /* 570 */ 161, 437, 23, 160, 843, 1238, 142, 32, 31, 29, + /* 580 */ 27, 26, 32, 31, 29, 27, 26, 1127, 1468, 115, + /* 590 */ 367, 1325, 1213, 152, 1272, 1327, 125, 1343, 498, 463, + /* 600 */ 463, 282, 365, 397, 361, 357, 353, 151, 1337, 460, + /* 610 */ 1387, 24, 264, 1117, 1118, 1119, 1120, 1121, 1125, 1126, + /* 620 */ 1468, 1422, 1323, 169, 1340, 1340, 297, 276, 447, 463, + /* 630 */ 273, 272, 1608, 53, 1608, 115, 149, 1237, 461, 67, + /* 640 */ 1065, 299, 1497, 1342, 1457, 131, 383, 131, 377, 1606, + /* 650 */ 163, 1606, 382, 162, 1340, 97, 1058, 378, 376, 1212, + /* 660 */ 379, 32, 31, 29, 27, 26, 1514, 48, 47, 309, + /* 670 */ 1387, 136, 405, 446, 512, 1057, 303, 1157, 300, 1259, + /* 680 */ 289, 1386, 1468, 449, 246, 1497, 295, 1468, 291, 287, + /* 690 */ 133, 1154, 434, 148, 279, 121, 106, 145, 1497, 1236, + /* 700 */ 409, 384, 115, 68, 1498, 1499, 1503, 1547, 488, 1514, + /* 710 */ 1342, 240, 1543, 132, 143, 464, 433, 32, 31, 29, + /* 720 */ 27, 26, 1514, 1608, 1091, 395, 449, 1061, 463, 446, + /* 730 */ 1468, 1235, 1234, 1299, 441, 438, 131, 208, 393, 449, + /* 740 */ 1606, 1497, 463, 1468, 1468, 1231, 69, 1498, 1499, 1503, + /* 750 */ 1547, 280, 1387, 1340, 259, 1543, 126, 1254, 278, 119, + /* 760 */ 1498, 1499, 1503, 1385, 1066, 1514, 547, 1340, 190, 436, + /* 770 */ 430, 1233, 433, 1230, 413, 1574, 1468, 1468, 1060, 386, + /* 780 */ 213, 1069, 449, 95, 1052, 1252, 1468, 1229, 1228, 536, + /* 790 */ 1468, 532, 528, 524, 212, 100, 1227, 44, 1622, 1226, + /* 800 */ 1050, 1180, 69, 1498, 1499, 1503, 1547, 389, 191, 178, + /* 810 */ 259, 1543, 126, 180, 434, 1225, 1224, 418, 1468, 1057, + /* 820 */ 66, 1223, 33, 206, 1497, 33, 1129, 1059, 98, 1087, + /* 830 */ 343, 1575, 1468, 1468, 1488, 1381, 404, 64, 187, 1554, + /* 840 */ 429, 1468, 428, 114, 1468, 1608, 1486, 61, 1514, 1063, + /* 850 */ 44, 1497, 33, 459, 921, 446, 1019, 366, 131, 544, + /* 860 */ 1468, 1468, 1606, 184, 1577, 449, 1468, 439, 442, 1468, + /* 870 */ 197, 1051, 94, 104, 199, 1514, 455, 205, 1497, 106, + /* 880 */ 1515, 412, 446, 926, 171, 69, 1498, 1499, 1503, 1547, + /* 890 */ 431, 2, 449, 259, 1543, 1620, 1468, 193, 1062, 1036, + /* 900 */ 1072, 168, 1514, 468, 1581, 869, 104, 954, 1053, 446, + /* 910 */ 958, 284, 69, 1498, 1499, 1503, 1547, 288, 245, 449, + /* 920 */ 259, 1543, 1620, 1468, 870, 1056, 105, 895, 1497, 247, + /* 930 */ 964, 1604, 106, 104, 1028, 214, 963, 107, 321, 69, + /* 940 */ 1498, 1499, 1503, 1547, 1420, 138, 328, 259, 1543, 1620, + /* 950 */ 336, 335, 1514, 1497, 337, 1083, 341, 342, 1565, 446, + /* 960 */ 1082, 344, 144, 1081, 345, 346, 1080, 147, 51, 449, + /* 970 */ 349, 150, 368, 1468, 398, 399, 370, 1514, 434, 1330, + /* 980 */ 1497, 154, 411, 400, 446, 1326, 255, 74, 401, 228, + /* 990 */ 1498, 1499, 1503, 156, 449, 373, 109, 408, 1468, 110, + /* 1000 */ 1328, 1324, 111, 112, 1514, 1079, 1497, 170, 173, 1608, + /* 1010 */ 419, 446, 1588, 410, 70, 1498, 1499, 1503, 1547, 453, + /* 1020 */ 1057, 449, 131, 1544, 5, 1468, 1606, 1578, 183, 176, + /* 1030 */ 1514, 416, 1497, 1587, 179, 1568, 258, 446, 422, 427, + /* 1040 */ 1497, 70, 1498, 1499, 1503, 1547, 415, 449, 1154, 444, + /* 1050 */ 1543, 1468, 4, 99, 414, 1078, 1514, 1562, 34, 260, + /* 1060 */ 443, 186, 440, 446, 1514, 17, 1429, 233, 1498, 1499, + /* 1070 */ 1503, 446, 124, 449, 1497, 1529, 451, 1468, 185, 452, + /* 1080 */ 456, 449, 203, 1428, 268, 1468, 201, 1497, 263, 58, + /* 1090 */ 457, 458, 1341, 232, 1498, 1499, 1503, 1623, 1514, 1497, + /* 1100 */ 192, 233, 1498, 1499, 1503, 446, 1605, 466, 215, 1313, + /* 1110 */ 60, 1514, 495, 217, 211, 449, 543, 40, 446, 1468, + /* 1120 */ 219, 223, 267, 1514, 224, 426, 221, 1462, 449, 1461, + /* 1130 */ 446, 283, 1468, 1497, 1458, 233, 1498, 1499, 1503, 285, + /* 1140 */ 449, 286, 1046, 1047, 1468, 134, 290, 1456, 225, 1498, + /* 1150 */ 1499, 1503, 292, 293, 294, 1455, 296, 1514, 1454, 1497, + /* 1160 */ 231, 1498, 1499, 1503, 446, 1445, 298, 135, 301, 302, + /* 1170 */ 1031, 1030, 1439, 1438, 449, 307, 308, 1437, 1468, 103, + /* 1180 */ 1002, 1413, 1412, 1514, 1436, 1497, 1411, 1410, 1409, 1408, + /* 1190 */ 446, 1407, 1406, 1405, 234, 1498, 1499, 1503, 1404, 1403, + /* 1200 */ 449, 1402, 1401, 1400, 1468, 1004, 1391, 1390, 1389, 1514, + /* 1210 */ 1497, 1399, 1398, 1397, 1396, 1395, 446, 1394, 1393, 1392, + /* 1220 */ 226, 1498, 1499, 1503, 1388, 1271, 449, 1453, 1447, 1435, + /* 1230 */ 1468, 1426, 1319, 146, 1514, 1497, 862, 1270, 1268, 352, + /* 1240 */ 1266, 446, 350, 356, 1497, 351, 235, 1498, 1499, 1503, + /* 1250 */ 1264, 449, 1262, 360, 354, 1468, 355, 359, 1251, 1514, + /* 1260 */ 358, 362, 363, 1250, 1247, 1321, 446, 969, 1514, 1320, + /* 1270 */ 1260, 227, 1498, 1499, 1503, 446, 449, 364, 73, 1497, + /* 1280 */ 1468, 971, 894, 252, 893, 449, 892, 891, 1255, 1468, + /* 1290 */ 253, 888, 887, 1253, 387, 254, 236, 1498, 1499, 1503, + /* 1300 */ 390, 1246, 392, 1514, 512, 1511, 1498, 1499, 1503, 1245, + /* 1310 */ 446, 153, 510, 1497, 394, 71, 1452, 167, 43, 1038, + /* 1320 */ 449, 1446, 113, 1434, 1468, 402, 1433, 1425, 172, 14, + /* 1330 */ 54, 3, 403, 1486, 177, 37, 35, 1514, 33, 15, + /* 1340 */ 1510, 1498, 1499, 1503, 446, 38, 1179, 1497, 10, 120, + /* 1350 */ 181, 19, 188, 1172, 449, 182, 1497, 55, 1468, 56, + /* 1360 */ 20, 1151, 1497, 1201, 8, 1150, 1206, 36, 130, 174, + /* 1370 */ 123, 1514, 1200, 16, 243, 1498, 1499, 1503, 446, 261, + /* 1380 */ 1514, 1315, 1205, 1204, 262, 195, 1514, 446, 449, 1089, + /* 1390 */ 1497, 13, 1468, 446, 1088, 196, 18, 449, 1424, 1177, + /* 1400 */ 202, 1468, 1115, 449, 198, 200, 45, 1468, 1509, 1498, + /* 1410 */ 1499, 1503, 57, 61, 1514, 454, 1497, 244, 1498, 1499, + /* 1420 */ 1503, 446, 1485, 242, 1498, 1499, 1503, 204, 207, 1067, + /* 1430 */ 39, 449, 465, 955, 467, 1468, 952, 275, 469, 471, + /* 1440 */ 1514, 472, 209, 949, 474, 475, 494, 446, 943, 477, + /* 1450 */ 478, 239, 1498, 1499, 1503, 941, 480, 449, 481, 947, + /* 1460 */ 932, 1468, 946, 62, 945, 944, 487, 966, 496, 46, + /* 1470 */ 962, 63, 960, 860, 497, 499, 901, 230, 1498, 1499, + /* 1480 */ 1503, 965, 883, 210, 882, 881, 880, 493, 492, 491, + /* 1490 */ 879, 490, 878, 877, 876, 896, 898, 873, 872, 871, + /* 1500 */ 868, 867, 866, 865, 1267, 521, 522, 1265, 1263, 523, + /* 1510 */ 526, 525, 527, 529, 530, 1261, 534, 533, 1249, 531, + /* 1520 */ 535, 537, 538, 1248, 1244, 541, 542, 1219, 1054, 1219, + /* 1530 */ 546, 218, 545, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 276, 277, 255, 235, 238, 251, 210, 216, 254, 216, - /* 10 */ 243, 257, 12, 13, 267, 268, 225, 250, 251, 0, - /* 20 */ 20, 255, 22, 238, 216, 12, 13, 14, 15, 16, - /* 30 */ 234, 2, 241, 267, 268, 260, 20, 241, 38, 246, - /* 40 */ 255, 12, 13, 14, 15, 16, 20, 251, 2, 241, - /* 50 */ 50, 255, 267, 268, 210, 36, 260, 57, 12, 13, - /* 60 */ 14, 15, 16, 12, 13, 14, 291, 271, 272, 273, - /* 70 */ 274, 20, 227, 22, 74, 230, 12, 13, 234, 304, - /* 80 */ 269, 47, 274, 308, 20, 241, 22, 291, 75, 38, - /* 90 */ 218, 283, 284, 285, 286, 251, 288, 97, 287, 255, - /* 100 */ 304, 50, 38, 231, 308, 20, 207, 73, 57, 109, - /* 110 */ 76, 239, 220, 221, 50, 271, 272, 273, 274, 275, - /* 120 */ 20, 57, 49, 279, 280, 74, 0, 88, 89, 90, - /* 130 */ 91, 92, 93, 94, 95, 96, 97, 98, 74, 100, - /* 140 */ 101, 102, 103, 104, 105, 145, 85, 21, 97, 210, - /* 150 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 260, - /* 160 */ 109, 97, 162, 163, 164, 165, 166, 167, 168, 169, - /* 170 */ 170, 171, 172, 109, 74, 22, 216, 20, 61, 12, - /* 180 */ 13, 209, 65, 211, 184, 225, 52, 20, 54, 22, - /* 190 */ 291, 38, 58, 216, 255, 61, 145, 63, 64, 78, - /* 200 */ 66, 241, 81, 304, 87, 38, 144, 308, 146, 145, - /* 210 */ 57, 260, 20, 162, 163, 164, 165, 166, 167, 168, - /* 220 */ 169, 170, 171, 172, 57, 135, 162, 163, 164, 165, - /* 230 */ 166, 167, 168, 169, 170, 171, 172, 260, 216, 162, - /* 240 */ 184, 74, 291, 12, 13, 14, 184, 225, 163, 164, - /* 250 */ 97, 20, 216, 22, 232, 304, 38, 12, 13, 308, - /* 260 */ 20, 225, 109, 241, 97, 20, 74, 22, 291, 38, - /* 270 */ 193, 194, 195, 196, 197, 57, 109, 241, 218, 189, - /* 280 */ 190, 304, 210, 38, 184, 308, 21, 291, 57, 24, - /* 290 */ 25, 26, 27, 28, 29, 30, 31, 32, 145, 239, - /* 300 */ 304, 67, 57, 215, 308, 74, 234, 12, 13, 14, - /* 310 */ 15, 16, 145, 241, 234, 162, 219, 229, 210, 74, - /* 320 */ 223, 241, 20, 251, 236, 210, 0, 255, 97, 162, - /* 330 */ 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, - /* 340 */ 109, 184, 97, 271, 272, 273, 274, 113, 114, 234, - /* 350 */ 18, 184, 20, 273, 109, 216, 241, 233, 49, 27, - /* 360 */ 216, 269, 30, 255, 225, 20, 251, 216, 244, 225, - /* 370 */ 255, 39, 234, 258, 210, 49, 145, 137, 240, 287, - /* 380 */ 241, 309, 310, 245, 215, 241, 271, 272, 273, 274, - /* 390 */ 145, 57, 241, 162, 163, 164, 165, 166, 167, 168, - /* 400 */ 169, 170, 171, 172, 20, 236, 22, 162, 163, 164, - /* 410 */ 165, 166, 167, 168, 169, 170, 171, 172, 216, 255, - /* 420 */ 12, 13, 234, 234, 40, 274, 210, 225, 20, 240, - /* 430 */ 22, 0, 137, 245, 245, 284, 285, 286, 241, 288, - /* 440 */ 14, 15, 16, 241, 112, 248, 38, 115, 116, 117, - /* 450 */ 118, 119, 74, 121, 122, 123, 124, 125, 126, 127, - /* 460 */ 128, 129, 130, 216, 86, 57, 12, 13, 14, 15, - /* 470 */ 16, 255, 225, 213, 214, 12, 13, 14, 15, 16, - /* 480 */ 35, 235, 74, 52, 53, 54, 55, 56, 241, 58, - /* 490 */ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - /* 500 */ 69, 70, 210, 216, 50, 97, 61, 71, 234, 216, - /* 510 */ 65, 75, 225, 50, 251, 226, 242, 109, 225, 232, - /* 520 */ 257, 235, 77, 234, 79, 80, 234, 82, 241, 75, - /* 530 */ 0, 242, 87, 241, 241, 22, 226, 83, 12, 13, - /* 540 */ 14, 15, 16, 251, 234, 263, 83, 255, 1, 2, - /* 550 */ 269, 38, 242, 145, 24, 25, 26, 27, 28, 29, - /* 560 */ 30, 31, 32, 271, 272, 273, 274, 0, 287, 131, - /* 570 */ 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, - /* 580 */ 172, 4, 14, 226, 216, 131, 234, 149, 20, 216, - /* 590 */ 18, 234, 240, 225, 131, 23, 19, 245, 225, 242, - /* 600 */ 210, 75, 38, 149, 210, 43, 210, 35, 0, 241, - /* 610 */ 33, 173, 149, 36, 241, 234, 49, 222, 41, 224, - /* 620 */ 48, 57, 75, 210, 47, 210, 245, 173, 174, 175, - /* 630 */ 176, 177, 178, 179, 180, 181, 173, 174, 175, 176, - /* 640 */ 177, 178, 179, 180, 181, 255, 20, 234, 4, 255, - /* 650 */ 73, 255, 210, 76, 241, 12, 13, 14, 15, 16, - /* 660 */ 52, 210, 54, 71, 251, 235, 58, 75, 255, 61, - /* 670 */ 255, 63, 64, 260, 66, 220, 221, 210, 210, 210, - /* 680 */ 210, 210, 3, 111, 271, 272, 273, 274, 275, 210, - /* 690 */ 12, 13, 279, 280, 21, 1, 2, 255, 210, 210, - /* 700 */ 22, 234, 182, 183, 291, 210, 255, 34, 241, 210, - /* 710 */ 138, 139, 140, 210, 142, 141, 38, 304, 251, 147, - /* 720 */ 71, 308, 255, 255, 255, 255, 255, 155, 210, 157, - /* 730 */ 156, 159, 160, 161, 255, 57, 71, 50, 271, 272, - /* 740 */ 273, 274, 275, 255, 255, 183, 279, 280, 281, 235, - /* 750 */ 255, 19, 234, 71, 255, 211, 184, 75, 255, 241, - /* 760 */ 293, 78, 235, 137, 81, 33, 299, 300, 36, 251, - /* 770 */ 74, 210, 0, 255, 42, 97, 44, 45, 46, 47, - /* 780 */ 84, 78, 78, 210, 81, 81, 235, 109, 0, 271, - /* 790 */ 272, 273, 274, 275, 22, 234, 210, 279, 280, 281, - /* 800 */ 0, 223, 241, 163, 164, 73, 302, 234, 76, 311, - /* 810 */ 22, 251, 251, 71, 241, 71, 255, 75, 300, 75, - /* 820 */ 234, 251, 22, 145, 251, 244, 71, 241, 255, 185, - /* 830 */ 75, 210, 271, 272, 273, 274, 296, 251, 106, 38, - /* 840 */ 162, 255, 213, 210, 271, 272, 273, 274, 275, 162, - /* 850 */ 270, 202, 279, 280, 281, 234, 234, 271, 272, 273, - /* 860 */ 274, 275, 241, 290, 289, 133, 280, 234, 136, 204, - /* 870 */ 38, 305, 251, 20, 241, 292, 255, 71, 216, 200, - /* 880 */ 266, 75, 71, 151, 251, 153, 75, 71, 255, 38, - /* 890 */ 220, 75, 271, 272, 273, 274, 275, 143, 261, 36, - /* 900 */ 279, 280, 281, 210, 271, 272, 273, 274, 275, 120, - /* 910 */ 109, 290, 279, 280, 281, 71, 216, 33, 216, 75, - /* 920 */ 36, 71, 216, 290, 249, 75, 42, 234, 44, 45, - /* 930 */ 46, 47, 71, 71, 241, 131, 75, 75, 71, 210, - /* 940 */ 216, 109, 75, 241, 251, 247, 247, 20, 255, 265, - /* 950 */ 210, 20, 12, 13, 14, 15, 16, 73, 241, 218, - /* 960 */ 76, 20, 260, 234, 271, 272, 273, 274, 275, 259, - /* 970 */ 241, 252, 279, 280, 234, 71, 274, 218, 218, 75, - /* 980 */ 251, 241, 216, 216, 255, 71, 284, 285, 286, 75, - /* 990 */ 288, 251, 71, 291, 218, 255, 75, 20, 258, 212, - /* 1000 */ 271, 272, 273, 274, 210, 234, 304, 234, 241, 210, - /* 1010 */ 308, 271, 272, 273, 274, 234, 132, 234, 134, 234, - /* 1020 */ 136, 216, 220, 241, 234, 234, 234, 234, 234, 234, - /* 1030 */ 234, 212, 303, 234, 265, 241, 259, 153, 210, 152, - /* 1040 */ 241, 274, 264, 20, 215, 251, 215, 192, 241, 255, - /* 1050 */ 251, 284, 285, 286, 255, 288, 270, 258, 301, 191, - /* 1060 */ 252, 57, 234, 301, 210, 271, 272, 273, 274, 241, - /* 1070 */ 271, 272, 273, 274, 256, 255, 199, 256, 138, 251, - /* 1080 */ 255, 255, 298, 255, 198, 187, 258, 241, 234, 186, - /* 1090 */ 20, 183, 269, 295, 297, 241, 120, 294, 206, 271, - /* 1100 */ 272, 273, 274, 203, 310, 251, 210, 201, 74, 255, - /* 1110 */ 253, 210, 282, 278, 256, 255, 306, 210, 134, 307, - /* 1120 */ 255, 312, 256, 241, 255, 271, 272, 273, 274, 230, - /* 1130 */ 234, 252, 215, 215, 241, 234, 74, 241, 216, 237, - /* 1140 */ 220, 234, 241, 224, 215, 205, 212, 251, 241, 0, - /* 1150 */ 262, 255, 251, 228, 228, 217, 255, 0, 251, 210, - /* 1160 */ 208, 0, 255, 64, 0, 38, 158, 271, 272, 273, - /* 1170 */ 274, 210, 271, 272, 273, 274, 38, 38, 271, 272, - /* 1180 */ 273, 274, 38, 234, 210, 158, 0, 0, 38, 38, - /* 1190 */ 241, 158, 38, 0, 38, 234, 0, 74, 149, 148, - /* 1200 */ 251, 0, 241, 109, 255, 145, 0, 0, 234, 141, - /* 1210 */ 61, 53, 251, 210, 65, 241, 255, 0, 0, 86, - /* 1220 */ 271, 272, 273, 274, 0, 251, 0, 0, 0, 255, - /* 1230 */ 0, 0, 271, 272, 273, 274, 87, 234, 0, 210, - /* 1240 */ 0, 0, 0, 0, 241, 271, 272, 273, 274, 0, - /* 1250 */ 0, 0, 0, 0, 251, 106, 107, 108, 255, 110, - /* 1260 */ 120, 0, 61, 234, 0, 210, 65, 0, 0, 0, - /* 1270 */ 241, 0, 0, 210, 271, 272, 273, 274, 22, 0, - /* 1280 */ 251, 0, 0, 0, 255, 0, 0, 0, 87, 234, - /* 1290 */ 43, 0, 0, 0, 36, 51, 241, 234, 38, 210, - /* 1300 */ 271, 272, 273, 274, 241, 43, 251, 106, 107, 108, - /* 1310 */ 255, 110, 0, 38, 251, 0, 36, 43, 255, 43, - /* 1320 */ 0, 43, 38, 234, 36, 36, 271, 272, 273, 274, - /* 1330 */ 241, 0, 38, 0, 271, 272, 273, 274, 0, 0, - /* 1340 */ 251, 210, 83, 38, 255, 22, 81, 0, 71, 38, - /* 1350 */ 0, 38, 38, 0, 38, 38, 38, 22, 22, 0, - /* 1360 */ 271, 272, 273, 274, 39, 234, 71, 22, 38, 0, - /* 1370 */ 22, 0, 241, 22, 20, 0, 137, 154, 38, 0, - /* 1380 */ 22, 0, 251, 150, 0, 137, 255, 0, 134, 43, - /* 1390 */ 188, 188, 137, 74, 86, 132, 75, 71, 71, 71, - /* 1400 */ 71, 182, 271, 272, 273, 274, 4, 75, 74, 188, - /* 1410 */ 86, 74, 38, 2, 71, 74, 38, 75, 74, 162, - /* 1420 */ 38, 38, 0, 38, 75, 135, 71, 75, 38, 43, - /* 1430 */ 132, 71, 75, 38, 22, 38, 38, 75, 75, 74, - /* 1440 */ 74, 74, 86, 75, 38, 75, 74, 86, 84, 22, - /* 1450 */ 74, 74, 38, 38, 38, 22, 22, 22, 38, 86, - /* 1460 */ 21, 21, 74, 38, 38, 74, 86, 75, 75, 75, - /* 1470 */ 74, 0, 51, 74, 85, 75, 75, 74, 74, 50, - /* 1480 */ 57, 38, 38, 38, 38, 38, 38, 74, 57, 38, - /* 1490 */ 38, 38, 74, 74, 38, 38, 72, 87, 38, 71, - /* 1500 */ 0, 38, 38, 36, 99, 36, 99, 99, 99, 43, - /* 1510 */ 38, 43, 0, 38, 36, 0, 43, 38, 36, 43, - /* 1520 */ 0, 38, 37, 0, 0, 22, 109, 22, 20, 313, - /* 1530 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1540 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1550 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1560 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1570 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1580 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1590 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1600 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1610 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1620 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1630 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1640 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1650 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1660 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1670 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1680 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1690 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1700 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1710 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1720 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1730 */ 313, 313, 313, 313, 313, 313, + /* 0 */ 217, 277, 278, 219, 239, 261, 211, 1, 2, 226, + /* 10 */ 244, 4, 12, 13, 217, 239, 233, 251, 252, 227, + /* 20 */ 20, 256, 22, 226, 240, 242, 19, 235, 20, 256, + /* 30 */ 235, 211, 256, 268, 269, 243, 292, 242, 38, 242, + /* 40 */ 33, 268, 269, 36, 268, 269, 20, 252, 41, 305, + /* 50 */ 50, 256, 217, 309, 47, 235, 217, 57, 14, 15, + /* 60 */ 16, 49, 242, 12, 13, 14, 217, 272, 273, 274, + /* 70 */ 275, 20, 252, 22, 74, 226, 256, 12, 13, 259, + /* 80 */ 73, 75, 233, 76, 20, 20, 247, 22, 211, 38, + /* 90 */ 211, 242, 272, 273, 274, 275, 261, 97, 214, 215, + /* 100 */ 20, 50, 20, 38, 252, 310, 311, 255, 57, 109, + /* 110 */ 258, 217, 235, 221, 222, 50, 12, 13, 217, 242, + /* 120 */ 226, 210, 57, 212, 20, 74, 22, 292, 292, 252, + /* 130 */ 221, 222, 211, 256, 217, 256, 242, 132, 74, 74, + /* 140 */ 305, 305, 38, 242, 309, 309, 146, 0, 97, 272, + /* 150 */ 273, 274, 275, 276, 136, 150, 74, 280, 281, 242, + /* 160 */ 109, 57, 97, 163, 164, 165, 166, 167, 168, 169, + /* 170 */ 170, 171, 172, 173, 109, 217, 275, 256, 74, 174, + /* 180 */ 211, 12, 13, 14, 226, 185, 285, 286, 287, 20, + /* 190 */ 289, 22, 275, 185, 220, 185, 49, 146, 224, 235, + /* 200 */ 242, 97, 285, 286, 287, 241, 289, 38, 190, 191, + /* 210 */ 246, 146, 20, 109, 163, 164, 165, 166, 167, 168, + /* 220 */ 169, 170, 171, 172, 173, 256, 57, 0, 163, 164, + /* 230 */ 165, 166, 167, 168, 169, 170, 171, 172, 173, 145, + /* 240 */ 20, 147, 22, 74, 164, 165, 1, 2, 21, 185, + /* 250 */ 146, 24, 25, 26, 27, 28, 29, 30, 31, 32, + /* 260 */ 40, 12, 13, 14, 15, 16, 97, 163, 164, 165, + /* 270 */ 166, 167, 168, 169, 170, 171, 172, 173, 109, 185, + /* 280 */ 20, 242, 219, 12, 13, 18, 216, 20, 249, 185, + /* 290 */ 52, 20, 54, 22, 27, 232, 58, 30, 211, 61, + /* 300 */ 230, 63, 64, 240, 66, 228, 39, 237, 231, 38, + /* 310 */ 12, 13, 14, 15, 16, 146, 21, 183, 184, 24, + /* 320 */ 25, 26, 27, 28, 29, 30, 31, 32, 57, 0, + /* 330 */ 67, 163, 163, 164, 165, 166, 167, 168, 169, 170, + /* 340 */ 171, 172, 173, 256, 20, 74, 61, 50, 50, 47, + /* 350 */ 65, 38, 49, 24, 25, 26, 27, 28, 29, 30, + /* 360 */ 31, 32, 194, 195, 196, 197, 198, 223, 97, 225, + /* 370 */ 57, 20, 87, 75, 35, 73, 113, 114, 76, 112, + /* 380 */ 109, 83, 115, 116, 117, 118, 119, 217, 121, 122, + /* 390 */ 123, 124, 125, 126, 127, 128, 129, 130, 131, 217, + /* 400 */ 61, 12, 13, 85, 65, 270, 217, 252, 226, 20, + /* 410 */ 270, 22, 242, 258, 235, 226, 77, 146, 79, 80, + /* 420 */ 241, 82, 235, 288, 242, 246, 87, 38, 288, 242, + /* 430 */ 132, 242, 164, 165, 163, 164, 165, 166, 167, 168, + /* 440 */ 169, 170, 171, 172, 173, 275, 57, 0, 150, 12, + /* 450 */ 13, 14, 15, 16, 284, 285, 286, 287, 0, 289, + /* 460 */ 163, 274, 138, 74, 20, 12, 13, 14, 15, 16, + /* 470 */ 270, 216, 174, 175, 176, 177, 178, 179, 180, 181, + /* 480 */ 182, 12, 13, 14, 15, 16, 97, 50, 288, 138, + /* 490 */ 14, 78, 237, 234, 81, 4, 20, 211, 109, 52, + /* 500 */ 53, 54, 55, 56, 245, 58, 59, 60, 61, 62, + /* 510 */ 63, 64, 65, 66, 67, 68, 69, 70, 78, 61, + /* 520 */ 83, 81, 57, 65, 88, 89, 90, 91, 92, 93, + /* 530 */ 94, 95, 96, 97, 98, 146, 100, 101, 102, 103, + /* 540 */ 104, 105, 256, 211, 75, 87, 18, 236, 208, 0, + /* 550 */ 43, 23, 163, 164, 165, 166, 167, 168, 169, 170, + /* 560 */ 171, 172, 173, 35, 106, 107, 108, 2, 110, 132, + /* 570 */ 78, 3, 2, 81, 22, 211, 48, 12, 13, 14, + /* 580 */ 15, 16, 12, 13, 14, 15, 16, 150, 256, 235, + /* 590 */ 38, 236, 139, 33, 0, 236, 36, 243, 49, 217, + /* 600 */ 217, 261, 42, 261, 44, 45, 46, 47, 226, 226, + /* 610 */ 235, 174, 175, 176, 177, 178, 179, 180, 181, 182, + /* 620 */ 256, 246, 236, 236, 242, 242, 142, 227, 236, 217, + /* 630 */ 12, 13, 292, 73, 292, 235, 76, 211, 226, 111, + /* 640 */ 22, 157, 211, 243, 0, 305, 52, 305, 54, 309, + /* 650 */ 78, 309, 58, 81, 242, 61, 38, 63, 64, 206, + /* 660 */ 66, 12, 13, 14, 15, 16, 235, 139, 140, 141, + /* 670 */ 235, 143, 264, 242, 71, 57, 148, 186, 75, 0, + /* 680 */ 36, 246, 256, 252, 156, 211, 158, 256, 160, 161, + /* 690 */ 162, 184, 261, 133, 227, 135, 71, 137, 211, 211, + /* 700 */ 75, 22, 235, 272, 273, 274, 275, 276, 236, 235, + /* 710 */ 243, 280, 281, 185, 154, 97, 242, 12, 13, 14, + /* 720 */ 15, 16, 235, 292, 75, 21, 252, 109, 217, 242, + /* 730 */ 256, 211, 211, 224, 71, 71, 305, 226, 34, 252, + /* 740 */ 309, 211, 217, 256, 256, 211, 272, 273, 274, 275, + /* 750 */ 276, 226, 235, 242, 280, 281, 282, 0, 241, 272, + /* 760 */ 273, 274, 275, 246, 146, 235, 19, 242, 294, 201, + /* 770 */ 217, 212, 242, 211, 300, 301, 256, 256, 38, 22, + /* 780 */ 33, 163, 252, 36, 22, 0, 256, 211, 211, 42, + /* 790 */ 256, 44, 45, 46, 47, 242, 211, 71, 311, 211, + /* 800 */ 38, 75, 272, 273, 274, 275, 276, 22, 312, 71, + /* 810 */ 280, 281, 282, 75, 261, 211, 211, 303, 256, 57, + /* 820 */ 73, 211, 71, 76, 211, 71, 75, 38, 275, 75, + /* 830 */ 252, 301, 256, 256, 74, 245, 252, 74, 285, 286, + /* 840 */ 287, 256, 289, 138, 256, 292, 86, 84, 235, 109, + /* 850 */ 71, 211, 71, 106, 75, 242, 75, 214, 305, 97, + /* 860 */ 256, 256, 309, 297, 271, 252, 256, 203, 205, 256, + /* 870 */ 71, 109, 71, 71, 75, 235, 75, 75, 211, 71, + /* 880 */ 235, 134, 242, 75, 137, 272, 273, 274, 275, 276, + /* 890 */ 290, 293, 252, 280, 281, 282, 256, 306, 109, 152, + /* 900 */ 20, 154, 235, 71, 291, 38, 71, 75, 146, 242, + /* 910 */ 75, 217, 272, 273, 274, 275, 276, 36, 267, 252, + /* 920 */ 280, 281, 282, 256, 57, 163, 71, 38, 211, 221, + /* 930 */ 75, 291, 71, 71, 144, 262, 75, 75, 217, 272, + /* 940 */ 273, 274, 275, 276, 217, 120, 250, 280, 281, 282, + /* 950 */ 132, 248, 235, 211, 248, 20, 217, 266, 291, 242, + /* 960 */ 20, 260, 219, 20, 242, 253, 20, 219, 219, 252, + /* 970 */ 217, 219, 213, 256, 242, 266, 235, 235, 261, 235, + /* 980 */ 211, 235, 253, 153, 242, 235, 213, 217, 265, 272, + /* 990 */ 273, 274, 275, 235, 252, 221, 235, 260, 256, 235, + /* 1000 */ 235, 235, 235, 235, 235, 20, 211, 216, 216, 292, + /* 1010 */ 193, 242, 302, 242, 272, 273, 274, 275, 276, 192, + /* 1020 */ 57, 252, 305, 281, 200, 256, 309, 271, 298, 257, + /* 1030 */ 235, 256, 211, 302, 257, 299, 256, 242, 256, 199, + /* 1040 */ 211, 272, 273, 274, 275, 276, 188, 252, 184, 280, + /* 1050 */ 281, 256, 187, 242, 259, 20, 235, 270, 120, 207, + /* 1060 */ 204, 283, 202, 242, 235, 74, 257, 272, 273, 274, + /* 1070 */ 275, 242, 296, 252, 211, 279, 256, 256, 295, 256, + /* 1080 */ 135, 252, 216, 257, 256, 256, 242, 211, 259, 216, + /* 1090 */ 254, 253, 242, 272, 273, 274, 275, 313, 235, 211, + /* 1100 */ 307, 272, 273, 274, 275, 242, 308, 238, 231, 225, + /* 1110 */ 74, 235, 221, 217, 216, 252, 213, 263, 242, 256, + /* 1120 */ 218, 229, 259, 235, 229, 304, 209, 0, 252, 0, + /* 1130 */ 242, 64, 256, 211, 0, 272, 273, 274, 275, 38, + /* 1140 */ 252, 159, 38, 38, 256, 38, 159, 0, 272, 273, + /* 1150 */ 274, 275, 38, 38, 159, 0, 38, 235, 0, 211, + /* 1160 */ 272, 273, 274, 275, 242, 0, 38, 74, 150, 149, + /* 1170 */ 109, 146, 0, 0, 252, 53, 142, 0, 256, 120, + /* 1180 */ 86, 0, 0, 235, 0, 211, 0, 0, 0, 0, + /* 1190 */ 242, 0, 0, 0, 272, 273, 274, 275, 0, 0, + /* 1200 */ 252, 0, 0, 0, 256, 22, 0, 0, 0, 235, + /* 1210 */ 211, 0, 0, 0, 0, 0, 242, 0, 0, 0, + /* 1220 */ 272, 273, 274, 275, 0, 0, 252, 0, 0, 0, + /* 1230 */ 256, 0, 0, 43, 235, 211, 51, 0, 0, 43, + /* 1240 */ 0, 242, 38, 43, 211, 36, 272, 273, 274, 275, + /* 1250 */ 0, 252, 0, 43, 38, 256, 36, 36, 0, 235, + /* 1260 */ 38, 38, 36, 0, 0, 0, 242, 22, 235, 0, + /* 1270 */ 0, 272, 273, 274, 275, 242, 252, 43, 83, 211, + /* 1280 */ 256, 38, 38, 22, 38, 252, 38, 38, 0, 256, + /* 1290 */ 22, 38, 38, 0, 39, 22, 272, 273, 274, 275, + /* 1300 */ 38, 0, 22, 235, 71, 272, 273, 274, 275, 0, + /* 1310 */ 242, 81, 71, 211, 22, 20, 0, 155, 138, 38, + /* 1320 */ 252, 0, 151, 0, 256, 22, 0, 0, 43, 189, + /* 1330 */ 74, 71, 138, 86, 75, 138, 183, 235, 71, 189, + /* 1340 */ 272, 273, 274, 275, 242, 71, 75, 211, 189, 74, + /* 1350 */ 74, 74, 86, 75, 252, 71, 211, 74, 256, 4, + /* 1360 */ 71, 75, 211, 38, 2, 75, 75, 71, 86, 133, + /* 1370 */ 135, 235, 38, 71, 272, 273, 274, 275, 242, 38, + /* 1380 */ 235, 0, 38, 38, 38, 86, 235, 242, 252, 75, + /* 1390 */ 211, 74, 256, 242, 75, 75, 74, 252, 0, 75, + /* 1400 */ 43, 256, 163, 252, 74, 74, 74, 256, 272, 273, + /* 1410 */ 274, 275, 74, 84, 235, 136, 211, 272, 273, 274, + /* 1420 */ 275, 242, 86, 272, 273, 274, 275, 133, 86, 22, + /* 1430 */ 74, 252, 85, 75, 38, 256, 75, 38, 74, 38, + /* 1440 */ 235, 74, 61, 75, 38, 74, 65, 242, 75, 38, + /* 1450 */ 74, 272, 273, 274, 275, 75, 38, 252, 74, 99, + /* 1460 */ 22, 256, 99, 74, 99, 99, 87, 38, 87, 74, + /* 1470 */ 38, 74, 22, 51, 50, 72, 57, 272, 273, 274, + /* 1480 */ 275, 109, 38, 71, 38, 38, 38, 106, 107, 108, + /* 1490 */ 38, 110, 38, 38, 22, 38, 57, 38, 38, 38, + /* 1500 */ 38, 38, 38, 38, 0, 38, 36, 0, 0, 43, + /* 1510 */ 36, 38, 43, 38, 36, 0, 36, 38, 0, 43, + /* 1520 */ 43, 38, 37, 0, 0, 22, 21, 314, 22, 314, + /* 1530 */ 20, 22, 21, 314, 314, 314, 314, 314, 314, 314, + /* 1540 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1550 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1560 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1570 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1580 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1590 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1600 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1610 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1620 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1630 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1640 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1650 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1660 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1670 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1680 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1690 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1700 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1710 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1720 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1730 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, + /* 1740 */ 314, }; -#define YY_SHIFT_COUNT (546) +#define YY_SHIFT_COUNT (547) #define YY_SHIFT_MIN (0) #define YY_SHIFT_MAX (1524) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 572, 0, 51, 64, 64, 64, 64, 167, 64, 64, - /* 10 */ 245, 408, 100, 231, 245, 245, 245, 245, 245, 245, - /* 20 */ 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, - /* 30 */ 245, 245, 245, 245, 192, 192, 192, 157, 678, 678, - /* 40 */ 62, 16, 16, 56, 678, 85, 85, 16, 16, 16, - /* 50 */ 16, 16, 16, 73, 26, 302, 56, 26, 16, 16, - /* 60 */ 26, 16, 26, 26, 26, 16, 309, 332, 454, 463, - /* 70 */ 463, 265, 445, 153, 134, 153, 153, 153, 153, 153, - /* 80 */ 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, - /* 90 */ 153, 153, 153, 153, 85, 384, 326, 218, 240, 240, - /* 100 */ 240, 567, 218, 345, 26, 26, 26, 61, 334, 39, - /* 110 */ 39, 39, 39, 39, 39, 39, 732, 126, 608, 940, - /* 120 */ 77, 85, 117, 85, 90, 513, 626, 520, 562, 520, - /* 130 */ 568, 679, 644, 853, 863, 851, 754, 853, 853, 789, - /* 140 */ 804, 804, 853, 927, 931, 73, 345, 941, 73, 73, - /* 150 */ 853, 73, 977, 26, 26, 26, 26, 26, 26, 26, - /* 160 */ 26, 26, 26, 26, 851, 853, 977, 345, 927, 887, - /* 170 */ 931, 309, 345, 941, 309, 1023, 855, 868, 1004, 855, - /* 180 */ 868, 1004, 1004, 877, 886, 898, 903, 908, 345, 1070, - /* 190 */ 976, 892, 900, 906, 1034, 26, 868, 1004, 1004, 868, - /* 200 */ 1004, 984, 345, 941, 309, 61, 309, 345, 1062, 851, - /* 210 */ 334, 853, 309, 977, 1529, 1529, 1529, 1529, 1529, 431, - /* 220 */ 884, 530, 577, 1149, 1201, 13, 29, 46, 526, 295, - /* 230 */ 643, 643, 643, 643, 643, 643, 643, 34, 234, 426, - /* 240 */ 547, 438, 426, 426, 426, 19, 574, 436, 121, 683, - /* 250 */ 703, 704, 772, 788, 800, 673, 592, 682, 742, 694, - /* 260 */ 640, 649, 665, 744, 687, 755, 378, 806, 811, 816, - /* 270 */ 844, 850, 801, 832, 861, 862, 867, 904, 914, 921, - /* 280 */ 696, 564, 1157, 1161, 1099, 1164, 1127, 1008, 1138, 1139, - /* 290 */ 1144, 1027, 1186, 1150, 1151, 1033, 1187, 1154, 1193, 1156, - /* 300 */ 1196, 1123, 1049, 1051, 1094, 1060, 1206, 1207, 1158, 1068, - /* 310 */ 1217, 1218, 1133, 1224, 1226, 1227, 1228, 1230, 1231, 1238, - /* 320 */ 1240, 1241, 1242, 1243, 1249, 1250, 1251, 1252, 1140, 1253, - /* 330 */ 1261, 1264, 1267, 1268, 1269, 1256, 1271, 1272, 1279, 1281, - /* 340 */ 1282, 1283, 1285, 1286, 1287, 1247, 1291, 1244, 1292, 1293, - /* 350 */ 1260, 1258, 1262, 1312, 1275, 1280, 1274, 1315, 1284, 1288, - /* 360 */ 1276, 1320, 1294, 1289, 1278, 1331, 1333, 1338, 1339, 1259, - /* 370 */ 1265, 1305, 1277, 1323, 1347, 1311, 1313, 1314, 1316, 1295, - /* 380 */ 1277, 1317, 1318, 1350, 1335, 1353, 1336, 1325, 1359, 1345, - /* 390 */ 1330, 1369, 1348, 1371, 1351, 1354, 1375, 1239, 1223, 1340, - /* 400 */ 1379, 1233, 1358, 1248, 1254, 1381, 1384, 1255, 1387, 1319, - /* 410 */ 1346, 1263, 1326, 1327, 1202, 1321, 1328, 1332, 1334, 1337, - /* 420 */ 1341, 1342, 1329, 1308, 1344, 1343, 1203, 1349, 1352, 1324, - /* 430 */ 1219, 1355, 1356, 1357, 1360, 1221, 1402, 1374, 1378, 1382, - /* 440 */ 1383, 1385, 1390, 1411, 1257, 1361, 1362, 1363, 1365, 1366, - /* 450 */ 1368, 1370, 1367, 1372, 1290, 1376, 1422, 1386, 1298, 1377, - /* 460 */ 1364, 1373, 1380, 1412, 1388, 1389, 1392, 1395, 1397, 1391, - /* 470 */ 1393, 1398, 1396, 1394, 1406, 1399, 1400, 1414, 1403, 1401, - /* 480 */ 1415, 1404, 1405, 1407, 1408, 1409, 1427, 1410, 1413, 1416, - /* 490 */ 1417, 1418, 1419, 1420, 1277, 1433, 1421, 1429, 1423, 1424, - /* 500 */ 1428, 1425, 1426, 1443, 1444, 1445, 1446, 1447, 1434, 1431, - /* 510 */ 1295, 1448, 1277, 1451, 1452, 1453, 1456, 1457, 1460, 1463, - /* 520 */ 1471, 1464, 1467, 1466, 1500, 1472, 1469, 1468, 1512, 1475, - /* 530 */ 1478, 1473, 1515, 1479, 1482, 1476, 1520, 1483, 1485, 1523, - /* 540 */ 1524, 1435, 1439, 1503, 1505, 1440, 1508, + /* 0 */ 528, 0, 51, 65, 65, 65, 65, 104, 65, 65, + /* 10 */ 271, 389, 64, 169, 271, 271, 271, 271, 271, 271, + /* 20 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, + /* 30 */ 271, 271, 271, 271, 82, 82, 82, 8, 618, 618, + /* 40 */ 94, 26, 26, 10, 618, 80, 80, 26, 26, 26, + /* 50 */ 26, 26, 26, 12, 192, 260, 10, 192, 26, 26, + /* 60 */ 192, 26, 192, 192, 192, 26, 303, 267, 298, 437, + /* 70 */ 437, 295, 339, 762, 238, 762, 762, 762, 762, 762, + /* 80 */ 762, 762, 762, 762, 762, 762, 762, 762, 762, 762, + /* 90 */ 762, 762, 762, 762, 80, 220, 147, 313, 324, 324, + /* 100 */ 324, 549, 313, 444, 192, 192, 192, 318, 465, 436, + /* 110 */ 436, 436, 436, 436, 436, 436, 747, 227, 594, 453, + /* 120 */ 168, 80, 285, 80, 18, 552, 351, 134, 507, 134, + /* 130 */ 476, 568, 491, 880, 881, 889, 790, 880, 880, 825, + /* 140 */ 818, 818, 880, 935, 940, 12, 444, 943, 12, 12, + /* 150 */ 880, 12, 946, 192, 192, 192, 192, 192, 192, 192, + /* 160 */ 192, 192, 192, 192, 889, 880, 946, 444, 935, 830, + /* 170 */ 940, 303, 444, 943, 303, 985, 817, 827, 963, 817, + /* 180 */ 827, 963, 963, 824, 840, 858, 865, 864, 444, 1035, + /* 190 */ 938, 852, 856, 860, 991, 192, 827, 963, 963, 827, + /* 200 */ 963, 945, 444, 943, 303, 318, 303, 444, 1036, 889, + /* 210 */ 465, 880, 303, 946, 1533, 1533, 1533, 1533, 1533, 447, + /* 220 */ 560, 329, 7, 458, 1381, 469, 565, 570, 649, 705, + /* 230 */ 249, 249, 249, 249, 249, 249, 249, 302, 263, 44, + /* 240 */ 6, 5, 44, 44, 44, 644, 484, 603, 413, 440, + /* 250 */ 492, 572, 679, 757, 785, 704, 625, 726, 738, 245, + /* 260 */ 268, 664, 663, 751, 297, 754, 760, 781, 799, 801, + /* 270 */ 802, 808, 740, 789, 779, 832, 835, 855, 861, 862, + /* 280 */ 763, 867, 1127, 1129, 1067, 1134, 1101, 982, 1104, 1105, + /* 290 */ 1107, 987, 1147, 1114, 1115, 995, 1155, 1118, 1158, 1128, + /* 300 */ 1165, 1093, 1018, 1020, 1061, 1025, 1172, 1173, 1122, 1034, + /* 310 */ 1177, 1184, 1094, 1181, 1182, 1186, 1187, 1188, 1189, 1191, + /* 320 */ 1192, 1193, 1198, 1199, 1201, 1202, 1203, 1211, 1212, 1059, + /* 330 */ 1213, 1214, 1215, 1217, 1218, 1219, 1183, 1206, 1207, 1208, + /* 340 */ 1224, 1225, 1227, 1228, 1229, 1231, 1190, 1232, 1185, 1237, + /* 350 */ 1238, 1204, 1209, 1196, 1240, 1216, 1220, 1200, 1250, 1222, + /* 360 */ 1221, 1210, 1252, 1223, 1226, 1234, 1258, 1263, 1264, 1265, + /* 370 */ 1195, 1230, 1243, 1233, 1245, 1269, 1244, 1246, 1248, 1249, + /* 380 */ 1241, 1233, 1253, 1254, 1270, 1261, 1288, 1268, 1255, 1293, + /* 390 */ 1273, 1262, 1301, 1280, 1309, 1292, 1295, 1316, 1180, 1162, + /* 400 */ 1281, 1321, 1171, 1303, 1194, 1235, 1323, 1326, 1197, 1327, + /* 410 */ 1256, 1285, 1236, 1260, 1267, 1140, 1259, 1274, 1271, 1275, + /* 420 */ 1276, 1277, 1278, 1284, 1247, 1283, 1289, 1150, 1286, 1290, + /* 430 */ 1266, 1153, 1296, 1282, 1291, 1302, 1159, 1355, 1325, 1334, + /* 440 */ 1341, 1344, 1345, 1346, 1362, 1239, 1299, 1314, 1319, 1317, + /* 450 */ 1322, 1320, 1324, 1330, 1331, 1279, 1332, 1398, 1357, 1294, + /* 460 */ 1338, 1329, 1336, 1342, 1407, 1356, 1347, 1358, 1396, 1399, + /* 470 */ 1364, 1361, 1401, 1367, 1368, 1406, 1371, 1373, 1411, 1376, + /* 480 */ 1380, 1418, 1384, 1360, 1363, 1365, 1366, 1438, 1379, 1389, + /* 490 */ 1429, 1372, 1395, 1397, 1432, 1233, 1450, 1422, 1424, 1419, + /* 500 */ 1403, 1412, 1444, 1446, 1447, 1448, 1452, 1454, 1455, 1472, + /* 510 */ 1439, 1241, 1457, 1233, 1459, 1460, 1461, 1462, 1463, 1464, + /* 520 */ 1465, 1504, 1467, 1470, 1466, 1507, 1473, 1474, 1469, 1508, + /* 530 */ 1475, 1478, 1476, 1515, 1479, 1480, 1477, 1518, 1483, 1485, + /* 540 */ 1523, 1524, 1503, 1505, 1506, 1509, 1511, 1510, }; #define YY_REDUCE_COUNT (218) #define YY_REDUCE_MIN (-276) -#define YY_REDUCE_MAX (1131) +#define YY_REDUCE_MAX (1205) static const short yy_reduce_ofst[] = { - /* 0 */ -101, 413, 467, 518, 573, 621, 633, -204, -156, 693, - /* 10 */ 72, 586, 702, 115, 740, 729, 794, 799, 828, 292, - /* 20 */ 561, 854, 896, 901, 907, 949, 961, 974, 1003, 1029, - /* 30 */ 1055, 1063, 1089, 1131, -192, 151, 767, -23, -234, -215, - /* 40 */ -225, 22, 287, -49, -253, -246, -233, -209, -40, 36, - /* 50 */ 139, 144, 202, -128, 138, 80, -4, 289, 247, 293, - /* 60 */ 189, 368, 310, 352, 357, 373, 88, -207, -276, -276, - /* 70 */ -276, -28, 124, -61, 97, 108, 164, 216, 390, 394, - /* 80 */ 396, 415, 442, 451, 468, 469, 470, 471, 479, 488, - /* 90 */ 489, 495, 499, 503, 263, 260, 60, -108, -189, 92, - /* 100 */ 281, 169, 455, 197, 274, 188, 381, -155, 395, -232, - /* 110 */ 246, 286, 430, 514, 527, 551, 282, 544, 578, 498, - /* 120 */ 504, 560, 581, 570, 540, 629, 580, 575, 575, 575, - /* 130 */ 622, 566, 583, 662, 614, 670, 637, 700, 706, 675, - /* 140 */ 698, 699, 724, 684, 710, 741, 717, 719, 759, 760, - /* 150 */ 766, 776, 787, 771, 773, 781, 783, 785, 790, 791, - /* 160 */ 792, 793, 795, 796, 802, 805, 819, 782, 769, 778, - /* 170 */ 777, 829, 807, 808, 831, 786, 757, 818, 820, 762, - /* 180 */ 821, 825, 826, 784, 797, 798, 803, 575, 846, 823, - /* 190 */ 830, 809, 812, 810, 835, 622, 858, 860, 865, 866, - /* 200 */ 869, 857, 882, 879, 917, 899, 918, 893, 902, 920, - /* 210 */ 919, 922, 929, 934, 888, 925, 926, 938, 952, + /* 0 */ 340, 431, 474, 530, 613, 640, 667, 717, -123, 769, + /* 10 */ -205, 742, 553, -180, 795, 821, 487, 829, 863, 876, + /* 20 */ 888, 922, 948, 974, 999, 1024, 1033, 1068, 1102, 1136, + /* 30 */ 1145, 1151, 1179, 1205, 170, -99, -83, -165, -235, -224, + /* 40 */ -256, -217, -151, 342, -227, -148, -234, -203, -106, -42, + /* 50 */ 182, 189, 382, 63, -36, 187, -164, -208, 383, 412, + /* 60 */ 179, 511, 400, 517, 467, 525, 70, -161, -276, -276, + /* 70 */ -276, -89, 259, -121, -26, -79, -31, 87, 286, 332, + /* 80 */ 364, 426, 488, 520, 521, 534, 562, 576, 577, 585, + /* 90 */ 588, 604, 605, 610, 155, -116, -216, -108, 135, 140, + /* 100 */ 200, 255, -91, 39, 354, 375, 435, 77, 144, 311, + /* 110 */ 355, 359, 386, 387, 392, 472, 408, 559, 509, 496, + /* 120 */ 514, 578, 590, 584, 566, 643, 593, 600, 600, 600, + /* 130 */ 645, 591, 598, 694, 651, 708, 673, 721, 727, 696, + /* 140 */ 703, 706, 739, 691, 701, 743, 722, 712, 748, 749, + /* 150 */ 753, 752, 759, 741, 744, 746, 750, 758, 761, 764, + /* 160 */ 765, 766, 767, 768, 774, 770, 773, 732, 709, 723, + /* 170 */ 737, 791, 771, 729, 792, 756, 710, 772, 775, 731, + /* 180 */ 777, 780, 782, 736, 730, 776, 783, 600, 811, 787, + /* 190 */ 778, 784, 798, 793, 796, 645, 809, 820, 823, 826, + /* 200 */ 828, 836, 844, 838, 866, 877, 873, 850, 869, 891, + /* 210 */ 884, 896, 898, 903, 854, 892, 895, 902, 917, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 10 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 20 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 30 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 40 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 50 */ 1215, 1215, 1215, 1274, 1215, 1215, 1215, 1215, 1215, 1215, - /* 60 */ 1215, 1215, 1215, 1215, 1215, 1215, 1272, 1411, 1215, 1546, - /* 70 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 80 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 90 */ 1215, 1215, 1215, 1215, 1215, 1215, 1274, 1215, 1557, 1557, - /* 100 */ 1557, 1272, 1215, 1215, 1215, 1215, 1215, 1367, 1215, 1215, - /* 110 */ 1215, 1215, 1215, 1215, 1215, 1215, 1445, 1215, 1215, 1621, - /* 120 */ 1215, 1215, 1320, 1215, 1581, 1215, 1573, 1549, 1563, 1550, - /* 130 */ 1215, 1606, 1566, 1215, 1215, 1215, 1437, 1215, 1215, 1416, - /* 140 */ 1413, 1413, 1215, 1215, 1215, 1274, 1215, 1215, 1274, 1274, - /* 150 */ 1215, 1274, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 160 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1447, - /* 170 */ 1215, 1272, 1215, 1215, 1272, 1215, 1588, 1586, 1215, 1588, - /* 180 */ 1586, 1215, 1215, 1600, 1596, 1579, 1577, 1563, 1215, 1215, - /* 190 */ 1215, 1624, 1612, 1608, 1215, 1215, 1586, 1215, 1215, 1586, - /* 200 */ 1215, 1424, 1215, 1215, 1272, 1215, 1272, 1215, 1336, 1215, - /* 210 */ 1215, 1215, 1272, 1215, 1439, 1370, 1370, 1275, 1220, 1215, - /* 220 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1509, - /* 230 */ 1510, 1599, 1598, 1509, 1523, 1522, 1521, 1215, 1215, 1504, - /* 240 */ 1215, 1215, 1505, 1503, 1502, 1215, 1215, 1215, 1215, 1215, - /* 250 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1547, - /* 260 */ 1215, 1609, 1613, 1215, 1215, 1215, 1484, 1215, 1215, 1215, - /* 270 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 280 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 290 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 300 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 310 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 320 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 330 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 340 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 350 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 360 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 370 */ 1215, 1215, 1381, 1215, 1215, 1215, 1215, 1215, 1215, 1301, - /* 380 */ 1300, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 390 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 400 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 410 */ 1215, 1215, 1570, 1580, 1215, 1215, 1215, 1215, 1215, 1215, - /* 420 */ 1215, 1215, 1215, 1484, 1215, 1597, 1215, 1556, 1552, 1215, - /* 430 */ 1215, 1548, 1215, 1215, 1607, 1215, 1215, 1215, 1215, 1215, - /* 440 */ 1215, 1215, 1215, 1542, 1215, 1215, 1215, 1215, 1215, 1215, - /* 450 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 460 */ 1215, 1483, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1364, - /* 470 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 480 */ 1215, 1215, 1349, 1347, 1346, 1345, 1215, 1342, 1215, 1215, - /* 490 */ 1215, 1215, 1215, 1215, 1372, 1215, 1215, 1215, 1215, 1215, - /* 500 */ 1295, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 510 */ 1286, 1215, 1285, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 520 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 530 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 540 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, + /* 0 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 10 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 20 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 30 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 40 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 50 */ 1217, 1217, 1217, 1276, 1217, 1217, 1217, 1217, 1217, 1217, + /* 60 */ 1217, 1217, 1217, 1217, 1217, 1217, 1274, 1414, 1217, 1549, + /* 70 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 80 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 90 */ 1217, 1217, 1217, 1217, 1217, 1217, 1276, 1217, 1560, 1560, + /* 100 */ 1560, 1274, 1217, 1217, 1217, 1217, 1217, 1369, 1217, 1217, + /* 110 */ 1217, 1217, 1217, 1217, 1217, 1217, 1448, 1217, 1217, 1624, + /* 120 */ 1217, 1217, 1322, 1217, 1584, 1217, 1576, 1552, 1566, 1553, + /* 130 */ 1217, 1609, 1569, 1217, 1217, 1217, 1440, 1217, 1217, 1419, + /* 140 */ 1416, 1416, 1217, 1217, 1217, 1276, 1217, 1217, 1276, 1276, + /* 150 */ 1217, 1276, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 160 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1450, + /* 170 */ 1217, 1274, 1217, 1217, 1274, 1217, 1591, 1589, 1217, 1591, + /* 180 */ 1589, 1217, 1217, 1603, 1599, 1582, 1580, 1566, 1217, 1217, + /* 190 */ 1217, 1627, 1615, 1611, 1217, 1217, 1589, 1217, 1217, 1589, + /* 200 */ 1217, 1427, 1217, 1217, 1274, 1217, 1274, 1217, 1338, 1217, + /* 210 */ 1217, 1217, 1274, 1217, 1442, 1372, 1372, 1277, 1222, 1217, + /* 220 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1512, + /* 230 */ 1513, 1602, 1601, 1512, 1526, 1525, 1524, 1217, 1217, 1507, + /* 240 */ 1217, 1217, 1508, 1506, 1505, 1217, 1217, 1217, 1217, 1217, + /* 250 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1550, + /* 260 */ 1217, 1612, 1616, 1217, 1217, 1217, 1487, 1217, 1217, 1217, + /* 270 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 280 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 290 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 300 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 310 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 320 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 330 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 340 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 350 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 360 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 370 */ 1217, 1217, 1217, 1383, 1217, 1217, 1217, 1217, 1217, 1217, + /* 380 */ 1303, 1302, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 390 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 400 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 410 */ 1217, 1217, 1217, 1573, 1583, 1217, 1217, 1217, 1217, 1217, + /* 420 */ 1217, 1217, 1217, 1217, 1487, 1217, 1600, 1217, 1559, 1555, + /* 430 */ 1217, 1217, 1551, 1217, 1217, 1610, 1217, 1217, 1217, 1217, + /* 440 */ 1217, 1217, 1217, 1217, 1545, 1217, 1217, 1217, 1217, 1217, + /* 450 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 460 */ 1217, 1217, 1486, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 470 */ 1366, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 480 */ 1217, 1217, 1217, 1351, 1349, 1348, 1347, 1217, 1344, 1217, + /* 490 */ 1217, 1217, 1217, 1217, 1217, 1374, 1217, 1217, 1217, 1217, + /* 500 */ 1217, 1297, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 510 */ 1217, 1288, 1217, 1287, 1217, 1217, 1217, 1217, 1217, 1217, + /* 520 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 530 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 540 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, }; /********** End of lemon-generated parsing tables *****************************/ @@ -916,194 +917,195 @@ static const char *const yyTokenName[] = { /* 122 */ "APPS", /* 123 */ "CONNECTIONS", /* 124 */ "LICENCE", - /* 125 */ "QUERIES", - /* 126 */ "SCORES", - /* 127 */ "TOPICS", - /* 128 */ "VARIABLES", - /* 129 */ "BNODES", - /* 130 */ "SNODES", - /* 131 */ "LIKE", - /* 132 */ "INDEX", - /* 133 */ "FULLTEXT", - /* 134 */ "FUNCTION", - /* 135 */ "INTERVAL", - /* 136 */ "TOPIC", - /* 137 */ "AS", - /* 138 */ "DESC", - /* 139 */ "DESCRIBE", - /* 140 */ "RESET", - /* 141 */ "QUERY", - /* 142 */ "EXPLAIN", - /* 143 */ "ANALYZE", - /* 144 */ "VERBOSE", - /* 145 */ "NK_BOOL", - /* 146 */ "RATIO", - /* 147 */ "COMPACT", - /* 148 */ "VNODES", - /* 149 */ "IN", - /* 150 */ "OUTPUTTYPE", - /* 151 */ "AGGREGATE", - /* 152 */ "BUFSIZE", - /* 153 */ "STREAM", - /* 154 */ "INTO", - /* 155 */ "KILL", - /* 156 */ "CONNECTION", - /* 157 */ "MERGE", - /* 158 */ "VGROUP", - /* 159 */ "REDISTRIBUTE", - /* 160 */ "SPLIT", - /* 161 */ "SYNCDB", - /* 162 */ "NULL", - /* 163 */ "FIRST", - /* 164 */ "LAST", - /* 165 */ "NOW", - /* 166 */ "ROWTS", - /* 167 */ "TBNAME", - /* 168 */ "QSTARTTS", - /* 169 */ "QENDTS", - /* 170 */ "WSTARTTS", - /* 171 */ "WENDTS", - /* 172 */ "WDURATION", - /* 173 */ "BETWEEN", - /* 174 */ "IS", - /* 175 */ "NK_LT", - /* 176 */ "NK_GT", - /* 177 */ "NK_LE", - /* 178 */ "NK_GE", - /* 179 */ "NK_NE", - /* 180 */ "MATCH", - /* 181 */ "NMATCH", - /* 182 */ "JOIN", - /* 183 */ "INNER", - /* 184 */ "SELECT", - /* 185 */ "DISTINCT", - /* 186 */ "WHERE", - /* 187 */ "PARTITION", - /* 188 */ "BY", - /* 189 */ "SESSION", - /* 190 */ "STATE_WINDOW", - /* 191 */ "SLIDING", - /* 192 */ "FILL", - /* 193 */ "VALUE", - /* 194 */ "NONE", - /* 195 */ "PREV", - /* 196 */ "LINEAR", - /* 197 */ "NEXT", - /* 198 */ "GROUP", - /* 199 */ "HAVING", - /* 200 */ "ORDER", - /* 201 */ "SLIMIT", - /* 202 */ "SOFFSET", - /* 203 */ "LIMIT", - /* 204 */ "OFFSET", - /* 205 */ "ASC", - /* 206 */ "NULLS", - /* 207 */ "cmd", - /* 208 */ "account_options", - /* 209 */ "alter_account_options", - /* 210 */ "literal", - /* 211 */ "alter_account_option", - /* 212 */ "user_name", - /* 213 */ "dnode_endpoint", - /* 214 */ "dnode_host_name", - /* 215 */ "not_exists_opt", - /* 216 */ "db_name", - /* 217 */ "db_options", - /* 218 */ "exists_opt", - /* 219 */ "alter_db_options", - /* 220 */ "integer_list", - /* 221 */ "variable_list", - /* 222 */ "retention_list", - /* 223 */ "alter_db_option", - /* 224 */ "retention", - /* 225 */ "full_table_name", - /* 226 */ "column_def_list", - /* 227 */ "tags_def_opt", - /* 228 */ "table_options", - /* 229 */ "multi_create_clause", - /* 230 */ "tags_def", - /* 231 */ "multi_drop_clause", - /* 232 */ "alter_table_clause", - /* 233 */ "alter_table_options", - /* 234 */ "column_name", - /* 235 */ "type_name", - /* 236 */ "create_subtable_clause", - /* 237 */ "specific_tags_opt", - /* 238 */ "literal_list", - /* 239 */ "drop_table_clause", - /* 240 */ "col_name_list", - /* 241 */ "table_name", - /* 242 */ "column_def", - /* 243 */ "func_name_list", - /* 244 */ "alter_table_option", - /* 245 */ "col_name", - /* 246 */ "db_name_cond_opt", - /* 247 */ "like_pattern_opt", - /* 248 */ "table_name_cond", - /* 249 */ "from_db_opt", - /* 250 */ "func_name", - /* 251 */ "function_name", - /* 252 */ "index_name", - /* 253 */ "index_options", - /* 254 */ "func_list", - /* 255 */ "duration_literal", - /* 256 */ "sliding_opt", - /* 257 */ "func", - /* 258 */ "expression_list", - /* 259 */ "topic_name", - /* 260 */ "query_expression", - /* 261 */ "analyze_opt", - /* 262 */ "explain_options", - /* 263 */ "agg_func_opt", - /* 264 */ "bufsize_opt", - /* 265 */ "stream_name", - /* 266 */ "dnode_list", - /* 267 */ "signed", - /* 268 */ "signed_literal", - /* 269 */ "table_alias", - /* 270 */ "column_alias", - /* 271 */ "expression", - /* 272 */ "pseudo_column", - /* 273 */ "column_reference", - /* 274 */ "subquery", - /* 275 */ "predicate", - /* 276 */ "compare_op", - /* 277 */ "in_op", - /* 278 */ "in_predicate_value", - /* 279 */ "boolean_value_expression", - /* 280 */ "boolean_primary", - /* 281 */ "common_expression", - /* 282 */ "from_clause", - /* 283 */ "table_reference_list", - /* 284 */ "table_reference", - /* 285 */ "table_primary", - /* 286 */ "joined_table", - /* 287 */ "alias_opt", - /* 288 */ "parenthesized_joined_table", - /* 289 */ "join_type", - /* 290 */ "search_condition", - /* 291 */ "query_specification", - /* 292 */ "set_quantifier_opt", - /* 293 */ "select_list", - /* 294 */ "where_clause_opt", - /* 295 */ "partition_by_clause_opt", - /* 296 */ "twindow_clause_opt", - /* 297 */ "group_by_clause_opt", - /* 298 */ "having_clause_opt", - /* 299 */ "select_sublist", - /* 300 */ "select_item", - /* 301 */ "fill_opt", - /* 302 */ "fill_mode", - /* 303 */ "group_by_list", - /* 304 */ "query_expression_body", - /* 305 */ "order_by_clause_opt", - /* 306 */ "slimit_clause_opt", - /* 307 */ "limit_clause_opt", - /* 308 */ "query_primary", - /* 309 */ "sort_specification_list", - /* 310 */ "sort_specification", - /* 311 */ "ordering_specification_opt", - /* 312 */ "null_ordering_opt", + /* 125 */ "GRANTS", + /* 126 */ "QUERIES", + /* 127 */ "SCORES", + /* 128 */ "TOPICS", + /* 129 */ "VARIABLES", + /* 130 */ "BNODES", + /* 131 */ "SNODES", + /* 132 */ "LIKE", + /* 133 */ "INDEX", + /* 134 */ "FULLTEXT", + /* 135 */ "FUNCTION", + /* 136 */ "INTERVAL", + /* 137 */ "TOPIC", + /* 138 */ "AS", + /* 139 */ "DESC", + /* 140 */ "DESCRIBE", + /* 141 */ "RESET", + /* 142 */ "QUERY", + /* 143 */ "EXPLAIN", + /* 144 */ "ANALYZE", + /* 145 */ "VERBOSE", + /* 146 */ "NK_BOOL", + /* 147 */ "RATIO", + /* 148 */ "COMPACT", + /* 149 */ "VNODES", + /* 150 */ "IN", + /* 151 */ "OUTPUTTYPE", + /* 152 */ "AGGREGATE", + /* 153 */ "BUFSIZE", + /* 154 */ "STREAM", + /* 155 */ "INTO", + /* 156 */ "KILL", + /* 157 */ "CONNECTION", + /* 158 */ "MERGE", + /* 159 */ "VGROUP", + /* 160 */ "REDISTRIBUTE", + /* 161 */ "SPLIT", + /* 162 */ "SYNCDB", + /* 163 */ "NULL", + /* 164 */ "FIRST", + /* 165 */ "LAST", + /* 166 */ "NOW", + /* 167 */ "ROWTS", + /* 168 */ "TBNAME", + /* 169 */ "QSTARTTS", + /* 170 */ "QENDTS", + /* 171 */ "WSTARTTS", + /* 172 */ "WENDTS", + /* 173 */ "WDURATION", + /* 174 */ "BETWEEN", + /* 175 */ "IS", + /* 176 */ "NK_LT", + /* 177 */ "NK_GT", + /* 178 */ "NK_LE", + /* 179 */ "NK_GE", + /* 180 */ "NK_NE", + /* 181 */ "MATCH", + /* 182 */ "NMATCH", + /* 183 */ "JOIN", + /* 184 */ "INNER", + /* 185 */ "SELECT", + /* 186 */ "DISTINCT", + /* 187 */ "WHERE", + /* 188 */ "PARTITION", + /* 189 */ "BY", + /* 190 */ "SESSION", + /* 191 */ "STATE_WINDOW", + /* 192 */ "SLIDING", + /* 193 */ "FILL", + /* 194 */ "VALUE", + /* 195 */ "NONE", + /* 196 */ "PREV", + /* 197 */ "LINEAR", + /* 198 */ "NEXT", + /* 199 */ "GROUP", + /* 200 */ "HAVING", + /* 201 */ "ORDER", + /* 202 */ "SLIMIT", + /* 203 */ "SOFFSET", + /* 204 */ "LIMIT", + /* 205 */ "OFFSET", + /* 206 */ "ASC", + /* 207 */ "NULLS", + /* 208 */ "cmd", + /* 209 */ "account_options", + /* 210 */ "alter_account_options", + /* 211 */ "literal", + /* 212 */ "alter_account_option", + /* 213 */ "user_name", + /* 214 */ "dnode_endpoint", + /* 215 */ "dnode_host_name", + /* 216 */ "not_exists_opt", + /* 217 */ "db_name", + /* 218 */ "db_options", + /* 219 */ "exists_opt", + /* 220 */ "alter_db_options", + /* 221 */ "integer_list", + /* 222 */ "variable_list", + /* 223 */ "retention_list", + /* 224 */ "alter_db_option", + /* 225 */ "retention", + /* 226 */ "full_table_name", + /* 227 */ "column_def_list", + /* 228 */ "tags_def_opt", + /* 229 */ "table_options", + /* 230 */ "multi_create_clause", + /* 231 */ "tags_def", + /* 232 */ "multi_drop_clause", + /* 233 */ "alter_table_clause", + /* 234 */ "alter_table_options", + /* 235 */ "column_name", + /* 236 */ "type_name", + /* 237 */ "create_subtable_clause", + /* 238 */ "specific_tags_opt", + /* 239 */ "literal_list", + /* 240 */ "drop_table_clause", + /* 241 */ "col_name_list", + /* 242 */ "table_name", + /* 243 */ "column_def", + /* 244 */ "func_name_list", + /* 245 */ "alter_table_option", + /* 246 */ "col_name", + /* 247 */ "db_name_cond_opt", + /* 248 */ "like_pattern_opt", + /* 249 */ "table_name_cond", + /* 250 */ "from_db_opt", + /* 251 */ "func_name", + /* 252 */ "function_name", + /* 253 */ "index_name", + /* 254 */ "index_options", + /* 255 */ "func_list", + /* 256 */ "duration_literal", + /* 257 */ "sliding_opt", + /* 258 */ "func", + /* 259 */ "expression_list", + /* 260 */ "topic_name", + /* 261 */ "query_expression", + /* 262 */ "analyze_opt", + /* 263 */ "explain_options", + /* 264 */ "agg_func_opt", + /* 265 */ "bufsize_opt", + /* 266 */ "stream_name", + /* 267 */ "dnode_list", + /* 268 */ "signed", + /* 269 */ "signed_literal", + /* 270 */ "table_alias", + /* 271 */ "column_alias", + /* 272 */ "expression", + /* 273 */ "pseudo_column", + /* 274 */ "column_reference", + /* 275 */ "subquery", + /* 276 */ "predicate", + /* 277 */ "compare_op", + /* 278 */ "in_op", + /* 279 */ "in_predicate_value", + /* 280 */ "boolean_value_expression", + /* 281 */ "boolean_primary", + /* 282 */ "common_expression", + /* 283 */ "from_clause", + /* 284 */ "table_reference_list", + /* 285 */ "table_reference", + /* 286 */ "table_primary", + /* 287 */ "joined_table", + /* 288 */ "alias_opt", + /* 289 */ "parenthesized_joined_table", + /* 290 */ "join_type", + /* 291 */ "search_condition", + /* 292 */ "query_specification", + /* 293 */ "set_quantifier_opt", + /* 294 */ "select_list", + /* 295 */ "where_clause_opt", + /* 296 */ "partition_by_clause_opt", + /* 297 */ "twindow_clause_opt", + /* 298 */ "group_by_clause_opt", + /* 299 */ "having_clause_opt", + /* 300 */ "select_sublist", + /* 301 */ "select_item", + /* 302 */ "fill_opt", + /* 303 */ "fill_mode", + /* 304 */ "group_by_list", + /* 305 */ "query_expression_body", + /* 306 */ "order_by_clause_opt", + /* 307 */ "slimit_clause_opt", + /* 308 */ "limit_clause_opt", + /* 309 */ "query_primary", + /* 310 */ "sort_specification_list", + /* 311 */ "sort_specification", + /* 312 */ "ordering_specification_opt", + /* 313 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1295,231 +1297,232 @@ static const char *const yyRuleName[] = { /* 181 */ "cmd ::= SHOW APPS", /* 182 */ "cmd ::= SHOW CONNECTIONS", /* 183 */ "cmd ::= SHOW LICENCE", - /* 184 */ "cmd ::= SHOW CREATE DATABASE db_name", - /* 185 */ "cmd ::= SHOW CREATE TABLE full_table_name", - /* 186 */ "cmd ::= SHOW CREATE STABLE full_table_name", - /* 187 */ "cmd ::= SHOW QUERIES", - /* 188 */ "cmd ::= SHOW SCORES", - /* 189 */ "cmd ::= SHOW TOPICS", - /* 190 */ "cmd ::= SHOW VARIABLES", - /* 191 */ "cmd ::= SHOW BNODES", - /* 192 */ "cmd ::= SHOW SNODES", - /* 193 */ "db_name_cond_opt ::=", - /* 194 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 195 */ "like_pattern_opt ::=", - /* 196 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 197 */ "table_name_cond ::= table_name", - /* 198 */ "from_db_opt ::=", - /* 199 */ "from_db_opt ::= FROM db_name", - /* 200 */ "func_name_list ::= func_name", - /* 201 */ "func_name_list ::= func_name_list NK_COMMA col_name", - /* 202 */ "func_name ::= function_name", - /* 203 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 204 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 205 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 206 */ "index_options ::=", - /* 207 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 208 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 209 */ "func_list ::= func", - /* 210 */ "func_list ::= func_list NK_COMMA func", - /* 211 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 212 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 213 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", - /* 214 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 215 */ "cmd ::= DESC full_table_name", - /* 216 */ "cmd ::= DESCRIBE full_table_name", - /* 217 */ "cmd ::= RESET QUERY CACHE", - /* 218 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 219 */ "analyze_opt ::=", - /* 220 */ "analyze_opt ::= ANALYZE", - /* 221 */ "explain_options ::=", - /* 222 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 223 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 224 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", - /* 225 */ "cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 226 */ "cmd ::= DROP FUNCTION function_name", - /* 227 */ "agg_func_opt ::=", - /* 228 */ "agg_func_opt ::= AGGREGATE", - /* 229 */ "bufsize_opt ::=", - /* 230 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 231 */ "cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression", - /* 232 */ "cmd ::= DROP STREAM stream_name", - /* 233 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 234 */ "cmd ::= KILL QUERY NK_INTEGER", - /* 235 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 236 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 237 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 238 */ "dnode_list ::= DNODE NK_INTEGER", - /* 239 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 240 */ "cmd ::= SYNCDB db_name REPLICA", - /* 241 */ "cmd ::= query_expression", - /* 242 */ "literal ::= NK_INTEGER", - /* 243 */ "literal ::= NK_FLOAT", - /* 244 */ "literal ::= NK_STRING", - /* 245 */ "literal ::= NK_BOOL", - /* 246 */ "literal ::= TIMESTAMP NK_STRING", - /* 247 */ "literal ::= duration_literal", - /* 248 */ "literal ::= NULL", - /* 249 */ "duration_literal ::= NK_VARIABLE", - /* 250 */ "signed ::= NK_INTEGER", - /* 251 */ "signed ::= NK_PLUS NK_INTEGER", - /* 252 */ "signed ::= NK_MINUS NK_INTEGER", - /* 253 */ "signed ::= NK_FLOAT", - /* 254 */ "signed ::= NK_PLUS NK_FLOAT", - /* 255 */ "signed ::= NK_MINUS NK_FLOAT", - /* 256 */ "signed_literal ::= signed", - /* 257 */ "signed_literal ::= NK_STRING", - /* 258 */ "signed_literal ::= NK_BOOL", - /* 259 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 260 */ "signed_literal ::= duration_literal", - /* 261 */ "signed_literal ::= NULL", - /* 262 */ "literal_list ::= signed_literal", - /* 263 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 264 */ "db_name ::= NK_ID", - /* 265 */ "table_name ::= NK_ID", - /* 266 */ "column_name ::= NK_ID", - /* 267 */ "function_name ::= NK_ID", - /* 268 */ "function_name ::= FIRST", - /* 269 */ "function_name ::= LAST", - /* 270 */ "table_alias ::= NK_ID", - /* 271 */ "column_alias ::= NK_ID", - /* 272 */ "user_name ::= NK_ID", - /* 273 */ "index_name ::= NK_ID", - /* 274 */ "topic_name ::= NK_ID", - /* 275 */ "stream_name ::= NK_ID", - /* 276 */ "expression ::= literal", - /* 277 */ "expression ::= pseudo_column", - /* 278 */ "expression ::= column_reference", - /* 279 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 280 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 281 */ "expression ::= function_name NK_LP expression AS type_name NK_RP", - /* 282 */ "expression ::= subquery", - /* 283 */ "expression ::= NK_LP expression NK_RP", - /* 284 */ "expression ::= NK_PLUS expression", - /* 285 */ "expression ::= NK_MINUS expression", - /* 286 */ "expression ::= expression NK_PLUS expression", - /* 287 */ "expression ::= expression NK_MINUS expression", - /* 288 */ "expression ::= expression NK_STAR expression", - /* 289 */ "expression ::= expression NK_SLASH expression", - /* 290 */ "expression ::= expression NK_REM expression", - /* 291 */ "expression_list ::= expression", - /* 292 */ "expression_list ::= expression_list NK_COMMA expression", - /* 293 */ "column_reference ::= column_name", - /* 294 */ "column_reference ::= table_name NK_DOT column_name", - /* 295 */ "pseudo_column ::= NOW", - /* 296 */ "pseudo_column ::= ROWTS", - /* 297 */ "pseudo_column ::= TBNAME", - /* 298 */ "pseudo_column ::= QSTARTTS", - /* 299 */ "pseudo_column ::= QENDTS", - /* 300 */ "pseudo_column ::= WSTARTTS", - /* 301 */ "pseudo_column ::= WENDTS", - /* 302 */ "pseudo_column ::= WDURATION", - /* 303 */ "predicate ::= expression compare_op expression", - /* 304 */ "predicate ::= expression BETWEEN expression AND expression", - /* 305 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 306 */ "predicate ::= expression IS NULL", - /* 307 */ "predicate ::= expression IS NOT NULL", - /* 308 */ "predicate ::= expression in_op in_predicate_value", - /* 309 */ "compare_op ::= NK_LT", - /* 310 */ "compare_op ::= NK_GT", - /* 311 */ "compare_op ::= NK_LE", - /* 312 */ "compare_op ::= NK_GE", - /* 313 */ "compare_op ::= NK_NE", - /* 314 */ "compare_op ::= NK_EQ", - /* 315 */ "compare_op ::= LIKE", - /* 316 */ "compare_op ::= NOT LIKE", - /* 317 */ "compare_op ::= MATCH", - /* 318 */ "compare_op ::= NMATCH", - /* 319 */ "in_op ::= IN", - /* 320 */ "in_op ::= NOT IN", - /* 321 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 322 */ "boolean_value_expression ::= boolean_primary", - /* 323 */ "boolean_value_expression ::= NOT boolean_primary", - /* 324 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 325 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 326 */ "boolean_primary ::= predicate", - /* 327 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 328 */ "common_expression ::= expression", - /* 329 */ "common_expression ::= boolean_value_expression", - /* 330 */ "from_clause ::= FROM table_reference_list", - /* 331 */ "table_reference_list ::= table_reference", - /* 332 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 333 */ "table_reference ::= table_primary", - /* 334 */ "table_reference ::= joined_table", - /* 335 */ "table_primary ::= table_name alias_opt", - /* 336 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 337 */ "table_primary ::= subquery alias_opt", - /* 338 */ "table_primary ::= parenthesized_joined_table", - /* 339 */ "alias_opt ::=", - /* 340 */ "alias_opt ::= table_alias", - /* 341 */ "alias_opt ::= AS table_alias", - /* 342 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 343 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 344 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 345 */ "join_type ::=", - /* 346 */ "join_type ::= INNER", - /* 347 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 348 */ "set_quantifier_opt ::=", - /* 349 */ "set_quantifier_opt ::= DISTINCT", - /* 350 */ "set_quantifier_opt ::= ALL", - /* 351 */ "select_list ::= NK_STAR", - /* 352 */ "select_list ::= select_sublist", - /* 353 */ "select_sublist ::= select_item", - /* 354 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 355 */ "select_item ::= common_expression", - /* 356 */ "select_item ::= common_expression column_alias", - /* 357 */ "select_item ::= common_expression AS column_alias", - /* 358 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 359 */ "where_clause_opt ::=", - /* 360 */ "where_clause_opt ::= WHERE search_condition", - /* 361 */ "partition_by_clause_opt ::=", - /* 362 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 363 */ "twindow_clause_opt ::=", - /* 364 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 365 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 366 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 367 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 368 */ "sliding_opt ::=", - /* 369 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 370 */ "fill_opt ::=", - /* 371 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 372 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 373 */ "fill_mode ::= NONE", - /* 374 */ "fill_mode ::= PREV", - /* 375 */ "fill_mode ::= NULL", - /* 376 */ "fill_mode ::= LINEAR", - /* 377 */ "fill_mode ::= NEXT", - /* 378 */ "group_by_clause_opt ::=", - /* 379 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 380 */ "group_by_list ::= expression", - /* 381 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 382 */ "having_clause_opt ::=", - /* 383 */ "having_clause_opt ::= HAVING search_condition", - /* 384 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 385 */ "query_expression_body ::= query_primary", - /* 386 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 387 */ "query_primary ::= query_specification", - /* 388 */ "order_by_clause_opt ::=", - /* 389 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 390 */ "slimit_clause_opt ::=", - /* 391 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 392 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 393 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 394 */ "limit_clause_opt ::=", - /* 395 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 396 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 397 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 398 */ "subquery ::= NK_LP query_expression NK_RP", - /* 399 */ "search_condition ::= common_expression", - /* 400 */ "sort_specification_list ::= sort_specification", - /* 401 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 402 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 403 */ "ordering_specification_opt ::=", - /* 404 */ "ordering_specification_opt ::= ASC", - /* 405 */ "ordering_specification_opt ::= DESC", - /* 406 */ "null_ordering_opt ::=", - /* 407 */ "null_ordering_opt ::= NULLS FIRST", - /* 408 */ "null_ordering_opt ::= NULLS LAST", + /* 184 */ "cmd ::= SHOW GRANTS", + /* 185 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 186 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 187 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 188 */ "cmd ::= SHOW QUERIES", + /* 189 */ "cmd ::= SHOW SCORES", + /* 190 */ "cmd ::= SHOW TOPICS", + /* 191 */ "cmd ::= SHOW VARIABLES", + /* 192 */ "cmd ::= SHOW BNODES", + /* 193 */ "cmd ::= SHOW SNODES", + /* 194 */ "db_name_cond_opt ::=", + /* 195 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 196 */ "like_pattern_opt ::=", + /* 197 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 198 */ "table_name_cond ::= table_name", + /* 199 */ "from_db_opt ::=", + /* 200 */ "from_db_opt ::= FROM db_name", + /* 201 */ "func_name_list ::= func_name", + /* 202 */ "func_name_list ::= func_name_list NK_COMMA col_name", + /* 203 */ "func_name ::= function_name", + /* 204 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 205 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", + /* 206 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", + /* 207 */ "index_options ::=", + /* 208 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 209 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 210 */ "func_list ::= func", + /* 211 */ "func_list ::= func_list NK_COMMA func", + /* 212 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 213 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 214 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", + /* 215 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 216 */ "cmd ::= DESC full_table_name", + /* 217 */ "cmd ::= DESCRIBE full_table_name", + /* 218 */ "cmd ::= RESET QUERY CACHE", + /* 219 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 220 */ "analyze_opt ::=", + /* 221 */ "analyze_opt ::= ANALYZE", + /* 222 */ "explain_options ::=", + /* 223 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 224 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 225 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 226 */ "cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 227 */ "cmd ::= DROP FUNCTION function_name", + /* 228 */ "agg_func_opt ::=", + /* 229 */ "agg_func_opt ::= AGGREGATE", + /* 230 */ "bufsize_opt ::=", + /* 231 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 232 */ "cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression", + /* 233 */ "cmd ::= DROP STREAM stream_name", + /* 234 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 235 */ "cmd ::= KILL QUERY NK_INTEGER", + /* 236 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 237 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 238 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 239 */ "dnode_list ::= DNODE NK_INTEGER", + /* 240 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 241 */ "cmd ::= SYNCDB db_name REPLICA", + /* 242 */ "cmd ::= query_expression", + /* 243 */ "literal ::= NK_INTEGER", + /* 244 */ "literal ::= NK_FLOAT", + /* 245 */ "literal ::= NK_STRING", + /* 246 */ "literal ::= NK_BOOL", + /* 247 */ "literal ::= TIMESTAMP NK_STRING", + /* 248 */ "literal ::= duration_literal", + /* 249 */ "literal ::= NULL", + /* 250 */ "duration_literal ::= NK_VARIABLE", + /* 251 */ "signed ::= NK_INTEGER", + /* 252 */ "signed ::= NK_PLUS NK_INTEGER", + /* 253 */ "signed ::= NK_MINUS NK_INTEGER", + /* 254 */ "signed ::= NK_FLOAT", + /* 255 */ "signed ::= NK_PLUS NK_FLOAT", + /* 256 */ "signed ::= NK_MINUS NK_FLOAT", + /* 257 */ "signed_literal ::= signed", + /* 258 */ "signed_literal ::= NK_STRING", + /* 259 */ "signed_literal ::= NK_BOOL", + /* 260 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 261 */ "signed_literal ::= duration_literal", + /* 262 */ "signed_literal ::= NULL", + /* 263 */ "literal_list ::= signed_literal", + /* 264 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 265 */ "db_name ::= NK_ID", + /* 266 */ "table_name ::= NK_ID", + /* 267 */ "column_name ::= NK_ID", + /* 268 */ "function_name ::= NK_ID", + /* 269 */ "function_name ::= FIRST", + /* 270 */ "function_name ::= LAST", + /* 271 */ "table_alias ::= NK_ID", + /* 272 */ "column_alias ::= NK_ID", + /* 273 */ "user_name ::= NK_ID", + /* 274 */ "index_name ::= NK_ID", + /* 275 */ "topic_name ::= NK_ID", + /* 276 */ "stream_name ::= NK_ID", + /* 277 */ "expression ::= literal", + /* 278 */ "expression ::= pseudo_column", + /* 279 */ "expression ::= column_reference", + /* 280 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 281 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 282 */ "expression ::= function_name NK_LP expression AS type_name NK_RP", + /* 283 */ "expression ::= subquery", + /* 284 */ "expression ::= NK_LP expression NK_RP", + /* 285 */ "expression ::= NK_PLUS expression", + /* 286 */ "expression ::= NK_MINUS expression", + /* 287 */ "expression ::= expression NK_PLUS expression", + /* 288 */ "expression ::= expression NK_MINUS expression", + /* 289 */ "expression ::= expression NK_STAR expression", + /* 290 */ "expression ::= expression NK_SLASH expression", + /* 291 */ "expression ::= expression NK_REM expression", + /* 292 */ "expression_list ::= expression", + /* 293 */ "expression_list ::= expression_list NK_COMMA expression", + /* 294 */ "column_reference ::= column_name", + /* 295 */ "column_reference ::= table_name NK_DOT column_name", + /* 296 */ "pseudo_column ::= NOW", + /* 297 */ "pseudo_column ::= ROWTS", + /* 298 */ "pseudo_column ::= TBNAME", + /* 299 */ "pseudo_column ::= QSTARTTS", + /* 300 */ "pseudo_column ::= QENDTS", + /* 301 */ "pseudo_column ::= WSTARTTS", + /* 302 */ "pseudo_column ::= WENDTS", + /* 303 */ "pseudo_column ::= WDURATION", + /* 304 */ "predicate ::= expression compare_op expression", + /* 305 */ "predicate ::= expression BETWEEN expression AND expression", + /* 306 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 307 */ "predicate ::= expression IS NULL", + /* 308 */ "predicate ::= expression IS NOT NULL", + /* 309 */ "predicate ::= expression in_op in_predicate_value", + /* 310 */ "compare_op ::= NK_LT", + /* 311 */ "compare_op ::= NK_GT", + /* 312 */ "compare_op ::= NK_LE", + /* 313 */ "compare_op ::= NK_GE", + /* 314 */ "compare_op ::= NK_NE", + /* 315 */ "compare_op ::= NK_EQ", + /* 316 */ "compare_op ::= LIKE", + /* 317 */ "compare_op ::= NOT LIKE", + /* 318 */ "compare_op ::= MATCH", + /* 319 */ "compare_op ::= NMATCH", + /* 320 */ "in_op ::= IN", + /* 321 */ "in_op ::= NOT IN", + /* 322 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 323 */ "boolean_value_expression ::= boolean_primary", + /* 324 */ "boolean_value_expression ::= NOT boolean_primary", + /* 325 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 326 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 327 */ "boolean_primary ::= predicate", + /* 328 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 329 */ "common_expression ::= expression", + /* 330 */ "common_expression ::= boolean_value_expression", + /* 331 */ "from_clause ::= FROM table_reference_list", + /* 332 */ "table_reference_list ::= table_reference", + /* 333 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 334 */ "table_reference ::= table_primary", + /* 335 */ "table_reference ::= joined_table", + /* 336 */ "table_primary ::= table_name alias_opt", + /* 337 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 338 */ "table_primary ::= subquery alias_opt", + /* 339 */ "table_primary ::= parenthesized_joined_table", + /* 340 */ "alias_opt ::=", + /* 341 */ "alias_opt ::= table_alias", + /* 342 */ "alias_opt ::= AS table_alias", + /* 343 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 344 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 345 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 346 */ "join_type ::=", + /* 347 */ "join_type ::= INNER", + /* 348 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 349 */ "set_quantifier_opt ::=", + /* 350 */ "set_quantifier_opt ::= DISTINCT", + /* 351 */ "set_quantifier_opt ::= ALL", + /* 352 */ "select_list ::= NK_STAR", + /* 353 */ "select_list ::= select_sublist", + /* 354 */ "select_sublist ::= select_item", + /* 355 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 356 */ "select_item ::= common_expression", + /* 357 */ "select_item ::= common_expression column_alias", + /* 358 */ "select_item ::= common_expression AS column_alias", + /* 359 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 360 */ "where_clause_opt ::=", + /* 361 */ "where_clause_opt ::= WHERE search_condition", + /* 362 */ "partition_by_clause_opt ::=", + /* 363 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 364 */ "twindow_clause_opt ::=", + /* 365 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 366 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 367 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 368 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 369 */ "sliding_opt ::=", + /* 370 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 371 */ "fill_opt ::=", + /* 372 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 373 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 374 */ "fill_mode ::= NONE", + /* 375 */ "fill_mode ::= PREV", + /* 376 */ "fill_mode ::= NULL", + /* 377 */ "fill_mode ::= LINEAR", + /* 378 */ "fill_mode ::= NEXT", + /* 379 */ "group_by_clause_opt ::=", + /* 380 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 381 */ "group_by_list ::= expression", + /* 382 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 383 */ "having_clause_opt ::=", + /* 384 */ "having_clause_opt ::= HAVING search_condition", + /* 385 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 386 */ "query_expression_body ::= query_primary", + /* 387 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 388 */ "query_primary ::= query_specification", + /* 389 */ "order_by_clause_opt ::=", + /* 390 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 391 */ "slimit_clause_opt ::=", + /* 392 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 393 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 394 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 395 */ "limit_clause_opt ::=", + /* 396 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 397 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 398 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 399 */ "subquery ::= NK_LP query_expression NK_RP", + /* 400 */ "search_condition ::= common_expression", + /* 401 */ "sort_specification_list ::= sort_specification", + /* 402 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 403 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 404 */ "ordering_specification_opt ::=", + /* 405 */ "ordering_specification_opt ::= ASC", + /* 406 */ "ordering_specification_opt ::= DESC", + /* 407 */ "null_ordering_opt ::=", + /* 408 */ "null_ordering_opt ::= NULLS FIRST", + /* 409 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1646,156 +1649,156 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 207: /* cmd */ - case 210: /* literal */ - case 217: /* db_options */ - case 219: /* alter_db_options */ - case 224: /* retention */ - case 225: /* full_table_name */ - case 228: /* table_options */ - case 232: /* alter_table_clause */ - case 233: /* alter_table_options */ - case 236: /* create_subtable_clause */ - case 239: /* drop_table_clause */ - case 242: /* column_def */ - case 245: /* col_name */ - case 246: /* db_name_cond_opt */ - case 247: /* like_pattern_opt */ - case 248: /* table_name_cond */ - case 249: /* from_db_opt */ - case 250: /* func_name */ - case 253: /* index_options */ - case 255: /* duration_literal */ - case 256: /* sliding_opt */ - case 257: /* func */ - case 260: /* query_expression */ - case 262: /* explain_options */ - case 267: /* signed */ - case 268: /* signed_literal */ - case 271: /* expression */ - case 272: /* pseudo_column */ - case 273: /* column_reference */ - case 274: /* subquery */ - case 275: /* predicate */ - case 278: /* in_predicate_value */ - case 279: /* boolean_value_expression */ - case 280: /* boolean_primary */ - case 281: /* common_expression */ - case 282: /* from_clause */ - case 283: /* table_reference_list */ - case 284: /* table_reference */ - case 285: /* table_primary */ - case 286: /* joined_table */ - case 288: /* parenthesized_joined_table */ - case 290: /* search_condition */ - case 291: /* query_specification */ - case 294: /* where_clause_opt */ - case 296: /* twindow_clause_opt */ - case 298: /* having_clause_opt */ - case 300: /* select_item */ - case 301: /* fill_opt */ - case 304: /* query_expression_body */ - case 306: /* slimit_clause_opt */ - case 307: /* limit_clause_opt */ - case 308: /* query_primary */ - case 310: /* sort_specification */ + case 208: /* cmd */ + case 211: /* literal */ + case 218: /* db_options */ + case 220: /* alter_db_options */ + case 225: /* retention */ + case 226: /* full_table_name */ + case 229: /* table_options */ + case 233: /* alter_table_clause */ + case 234: /* alter_table_options */ + case 237: /* create_subtable_clause */ + case 240: /* drop_table_clause */ + case 243: /* column_def */ + case 246: /* col_name */ + case 247: /* db_name_cond_opt */ + case 248: /* like_pattern_opt */ + case 249: /* table_name_cond */ + case 250: /* from_db_opt */ + case 251: /* func_name */ + case 254: /* index_options */ + case 256: /* duration_literal */ + case 257: /* sliding_opt */ + case 258: /* func */ + case 261: /* query_expression */ + case 263: /* explain_options */ + case 268: /* signed */ + case 269: /* signed_literal */ + case 272: /* expression */ + case 273: /* pseudo_column */ + case 274: /* column_reference */ + case 275: /* subquery */ + case 276: /* predicate */ + case 279: /* in_predicate_value */ + case 280: /* boolean_value_expression */ + case 281: /* boolean_primary */ + case 282: /* common_expression */ + case 283: /* from_clause */ + case 284: /* table_reference_list */ + case 285: /* table_reference */ + case 286: /* table_primary */ + case 287: /* joined_table */ + case 289: /* parenthesized_joined_table */ + case 291: /* search_condition */ + case 292: /* query_specification */ + case 295: /* where_clause_opt */ + case 297: /* twindow_clause_opt */ + case 299: /* having_clause_opt */ + case 301: /* select_item */ + case 302: /* fill_opt */ + case 305: /* query_expression_body */ + case 307: /* slimit_clause_opt */ + case 308: /* limit_clause_opt */ + case 309: /* query_primary */ + case 311: /* sort_specification */ { - nodesDestroyNode((yypminor->yy564)); + nodesDestroyNode((yypminor->yy140)); } break; - case 208: /* account_options */ - case 209: /* alter_account_options */ - case 211: /* alter_account_option */ - case 264: /* bufsize_opt */ + case 209: /* account_options */ + case 210: /* alter_account_options */ + case 212: /* alter_account_option */ + case 265: /* bufsize_opt */ { } break; - case 212: /* user_name */ - case 213: /* dnode_endpoint */ - case 214: /* dnode_host_name */ - case 216: /* db_name */ - case 234: /* column_name */ - case 241: /* table_name */ - case 251: /* function_name */ - case 252: /* index_name */ - case 259: /* topic_name */ - case 265: /* stream_name */ - case 269: /* table_alias */ - case 270: /* column_alias */ - case 287: /* alias_opt */ + case 213: /* user_name */ + case 214: /* dnode_endpoint */ + case 215: /* dnode_host_name */ + case 217: /* db_name */ + case 235: /* column_name */ + case 242: /* table_name */ + case 252: /* function_name */ + case 253: /* index_name */ + case 260: /* topic_name */ + case 266: /* stream_name */ + case 270: /* table_alias */ + case 271: /* column_alias */ + case 288: /* alias_opt */ { } break; - case 215: /* not_exists_opt */ - case 218: /* exists_opt */ - case 261: /* analyze_opt */ - case 263: /* agg_func_opt */ - case 292: /* set_quantifier_opt */ + case 216: /* not_exists_opt */ + case 219: /* exists_opt */ + case 262: /* analyze_opt */ + case 264: /* agg_func_opt */ + case 293: /* set_quantifier_opt */ { } break; - case 220: /* integer_list */ - case 221: /* variable_list */ - case 222: /* retention_list */ - case 226: /* column_def_list */ - case 227: /* tags_def_opt */ - case 229: /* multi_create_clause */ - case 230: /* tags_def */ - case 231: /* multi_drop_clause */ - case 237: /* specific_tags_opt */ - case 238: /* literal_list */ - case 240: /* col_name_list */ - case 243: /* func_name_list */ - case 254: /* func_list */ - case 258: /* expression_list */ - case 266: /* dnode_list */ - case 293: /* select_list */ - case 295: /* partition_by_clause_opt */ - case 297: /* group_by_clause_opt */ - case 299: /* select_sublist */ - case 303: /* group_by_list */ - case 305: /* order_by_clause_opt */ - case 309: /* sort_specification_list */ + case 221: /* integer_list */ + case 222: /* variable_list */ + case 223: /* retention_list */ + case 227: /* column_def_list */ + case 228: /* tags_def_opt */ + case 230: /* multi_create_clause */ + case 231: /* tags_def */ + case 232: /* multi_drop_clause */ + case 238: /* specific_tags_opt */ + case 239: /* literal_list */ + case 241: /* col_name_list */ + case 244: /* func_name_list */ + case 255: /* func_list */ + case 259: /* expression_list */ + case 267: /* dnode_list */ + case 294: /* select_list */ + case 296: /* partition_by_clause_opt */ + case 298: /* group_by_clause_opt */ + case 300: /* select_sublist */ + case 304: /* group_by_list */ + case 306: /* order_by_clause_opt */ + case 310: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy476)); + nodesDestroyList((yypminor->yy220)); } break; - case 223: /* alter_db_option */ - case 244: /* alter_table_option */ + case 224: /* alter_db_option */ + case 245: /* alter_table_option */ { } break; - case 235: /* type_name */ + case 236: /* type_name */ { } break; - case 276: /* compare_op */ - case 277: /* in_op */ + case 277: /* compare_op */ + case 278: /* in_op */ { } break; - case 289: /* join_type */ + case 290: /* join_type */ { } break; - case 302: /* fill_mode */ + case 303: /* fill_mode */ { } break; - case 311: /* ordering_specification_opt */ + case 312: /* ordering_specification_opt */ { } break; - case 312: /* null_ordering_opt */ + case 313: /* null_ordering_opt */ { } @@ -1923,18 +1926,15 @@ static YYACTIONTYPE yy_find_shift_action( do{ i = yy_shift_ofst[stateno]; assert( i>=0 ); - assert( i<=YY_ACTTAB_COUNT ); - assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); + /* assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); */ assert( iLookAhead!=YYNOCODE ); assert( iLookAhead < YYNTOKEN ); i += iLookAhead; - assert( i<(int)YY_NLOOKAHEAD ); - if( yy_lookahead[i]!=iLookAhead ){ + if( i>=YY_NLOOKAHEAD || yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ - assert( iLookAhead %s\n", @@ -1949,8 +1949,16 @@ static YYACTIONTYPE yy_find_shift_action( #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; - assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); - if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ + if( +#if YY_SHIFT_MIN+YYWILDCARD<0 + j>=0 && +#endif +#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT + j0 + ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", @@ -1964,7 +1972,6 @@ static YYACTIONTYPE yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ - assert( i>=0 && iyytos; #ifndef NDEBUG if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - yysize = yyRuleInfoNRhs[yyruleno]; + yysize = yyRuleInfo[yyruleno].nrhs; if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", + fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", yyTracePrompt, - yyruleno, yyRuleName[yyruleno], - yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; @@ -3000,11 +2595,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,208,&yymsp[0].minor); + yy_destructor(yypParser,209,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,209,&yymsp[0].minor); + yy_destructor(yypParser,210,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -3018,20 +2613,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,208,&yymsp[-2].minor); +{ yy_destructor(yypParser,209,&yymsp[-2].minor); { } - yy_destructor(yypParser,210,&yymsp[0].minor); + yy_destructor(yypParser,211,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,211,&yymsp[0].minor); +{ yy_destructor(yypParser,212,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,209,&yymsp[-1].minor); +{ yy_destructor(yypParser,210,&yymsp[-1].minor); { } - yy_destructor(yypParser,211,&yymsp[0].minor); + yy_destructor(yypParser,212,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -3045,31 +2640,31 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,210,&yymsp[0].minor); + yy_destructor(yypParser,211,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy21, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy253, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy21, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy253, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy21); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy253); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy21, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy253, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy0); } break; case 30: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 31: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy21); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy253); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -3086,20 +2681,20 @@ static YYACTIONTYPE yy_reduce( case 36: /* dnode_endpoint ::= NK_STRING */ case 37: /* dnode_host_name ::= NK_ID */ yytestcase(yyruleno==37); case 38: /* dnode_host_name ::= NK_IPTOKEN */ yytestcase(yyruleno==38); - case 264: /* db_name ::= NK_ID */ yytestcase(yyruleno==264); - case 265: /* table_name ::= NK_ID */ yytestcase(yyruleno==265); - case 266: /* column_name ::= NK_ID */ yytestcase(yyruleno==266); - case 267: /* function_name ::= NK_ID */ yytestcase(yyruleno==267); - case 268: /* function_name ::= FIRST */ yytestcase(yyruleno==268); - case 269: /* function_name ::= LAST */ yytestcase(yyruleno==269); - case 270: /* table_alias ::= NK_ID */ yytestcase(yyruleno==270); - case 271: /* column_alias ::= NK_ID */ yytestcase(yyruleno==271); - case 272: /* user_name ::= NK_ID */ yytestcase(yyruleno==272); - case 273: /* index_name ::= NK_ID */ yytestcase(yyruleno==273); - case 274: /* topic_name ::= NK_ID */ yytestcase(yyruleno==274); - case 275: /* stream_name ::= NK_ID */ yytestcase(yyruleno==275); -{ yylhsminor.yy21 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy21 = yylhsminor.yy21; + case 265: /* db_name ::= NK_ID */ yytestcase(yyruleno==265); + case 266: /* table_name ::= NK_ID */ yytestcase(yyruleno==266); + case 267: /* column_name ::= NK_ID */ yytestcase(yyruleno==267); + case 268: /* function_name ::= NK_ID */ yytestcase(yyruleno==268); + case 269: /* function_name ::= FIRST */ yytestcase(yyruleno==269); + case 270: /* function_name ::= LAST */ yytestcase(yyruleno==270); + case 271: /* table_alias ::= NK_ID */ yytestcase(yyruleno==271); + case 272: /* column_alias ::= NK_ID */ yytestcase(yyruleno==272); + case 273: /* user_name ::= NK_ID */ yytestcase(yyruleno==273); + case 274: /* index_name ::= NK_ID */ yytestcase(yyruleno==274); + case 275: /* topic_name ::= NK_ID */ yytestcase(yyruleno==275); + case 276: /* stream_name ::= NK_ID */ yytestcase(yyruleno==276); +{ yylhsminor.yy253 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy253 = yylhsminor.yy253; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -3132,408 +2727,408 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } break; case 49: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy173, &yymsp[-1].minor.yy21, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy273, &yymsp[-1].minor.yy253, yymsp[0].minor.yy140); } break; case 50: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy21); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy273, &yymsp[0].minor.yy253); } break; case 51: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy21); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy253); } break; case 52: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy21, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy253, yymsp[0].minor.yy140); } break; case 53: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy173 = true; } +{ yymsp[-2].minor.yy273 = true; } break; case 54: /* not_exists_opt ::= */ case 56: /* exists_opt ::= */ yytestcase(yyruleno==56); - case 219: /* analyze_opt ::= */ yytestcase(yyruleno==219); - case 227: /* agg_func_opt ::= */ yytestcase(yyruleno==227); - case 348: /* set_quantifier_opt ::= */ yytestcase(yyruleno==348); -{ yymsp[1].minor.yy173 = false; } + case 220: /* analyze_opt ::= */ yytestcase(yyruleno==220); + case 228: /* agg_func_opt ::= */ yytestcase(yyruleno==228); + case 349: /* set_quantifier_opt ::= */ yytestcase(yyruleno==349); +{ yymsp[1].minor.yy273 = false; } break; case 55: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy173 = true; } +{ yymsp[-1].minor.yy273 = true; } break; case 57: /* db_options ::= */ -{ yymsp[1].minor.yy564 = createDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy140 = createDatabaseOptions(pCxt); } break; case 58: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 59: /* db_options ::= db_options CACHE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 60: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 61: /* db_options ::= db_options COMP NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 62: /* db_options ::= db_options DAYS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 63: /* db_options ::= db_options DAYS NK_VARIABLE */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 64: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 65: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 66: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 67: /* db_options ::= db_options KEEP integer_list */ case 68: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==68); -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pKeep = yymsp[0].minor.yy476; yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pKeep = yymsp[0].minor.yy220; yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 69: /* db_options ::= db_options PRECISION NK_STRING */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 70: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 71: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 72: /* db_options ::= db_options TTL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 73: /* db_options ::= db_options WAL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 74: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 75: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 76: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 77: /* db_options ::= db_options RETENTIONS retention_list */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pRetentions = yymsp[0].minor.yy476; yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pRetentions = yymsp[0].minor.yy220; yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 78: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy564 = createDatabaseOptions(pCxt); yylhsminor.yy564 = setDatabaseAlterOption(pCxt, yylhsminor.yy564, &yymsp[0].minor.yy289); } - yymsp[0].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createDatabaseOptions(pCxt); yylhsminor.yy140 = setDatabaseAlterOption(pCxt, yylhsminor.yy140, &yymsp[0].minor.yy181); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; case 79: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy564 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy564, &yymsp[0].minor.yy289); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy140, &yymsp[0].minor.yy181); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; case 80: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy181.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 81: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy181.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 82: /* alter_db_option ::= KEEP integer_list */ case 83: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==83); -{ yymsp[-1].minor.yy289.type = DB_OPTION_KEEP; yymsp[-1].minor.yy289.pList = yymsp[0].minor.yy476; } +{ yymsp[-1].minor.yy181.type = DB_OPTION_KEEP; yymsp[-1].minor.yy181.pList = yymsp[0].minor.yy220; } break; case 84: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_WAL; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy181.type = DB_OPTION_WAL; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 85: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy181.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 86: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy181.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 87: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy181.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 88: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy476 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy476 = yylhsminor.yy476; +{ yylhsminor.yy220 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy220 = yylhsminor.yy220; break; case 89: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 239: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==239); -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; + case 240: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==240); +{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy220 = yylhsminor.yy220; break; case 90: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy476 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy476 = yylhsminor.yy476; +{ yylhsminor.yy220 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy220 = yylhsminor.yy220; break; case 91: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; +{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy220 = yylhsminor.yy220; break; case 92: /* retention_list ::= retention */ case 112: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==112); case 115: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==115); case 122: /* column_def_list ::= column_def */ yytestcase(yyruleno==122); case 165: /* col_name_list ::= col_name */ yytestcase(yyruleno==165); - case 200: /* func_name_list ::= func_name */ yytestcase(yyruleno==200); - case 209: /* func_list ::= func */ yytestcase(yyruleno==209); - case 262: /* literal_list ::= signed_literal */ yytestcase(yyruleno==262); - case 353: /* select_sublist ::= select_item */ yytestcase(yyruleno==353); - case 400: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==400); -{ yylhsminor.yy476 = createNodeList(pCxt, yymsp[0].minor.yy564); } - yymsp[0].minor.yy476 = yylhsminor.yy476; + case 201: /* func_name_list ::= func_name */ yytestcase(yyruleno==201); + case 210: /* func_list ::= func */ yytestcase(yyruleno==210); + case 263: /* literal_list ::= signed_literal */ yytestcase(yyruleno==263); + case 354: /* select_sublist ::= select_item */ yytestcase(yyruleno==354); + case 401: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==401); +{ yylhsminor.yy220 = createNodeList(pCxt, yymsp[0].minor.yy140); } + yymsp[0].minor.yy220 = yylhsminor.yy220; break; case 93: /* retention_list ::= retention_list NK_COMMA retention */ case 123: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==123); case 166: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==166); - case 201: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==201); - case 210: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==210); - case 263: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==263); - case 354: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==354); - case 401: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==401); -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, yymsp[0].minor.yy564); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; + case 202: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==202); + case 211: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==211); + case 264: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==264); + case 355: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==355); + case 402: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==402); +{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, yymsp[0].minor.yy140); } + yymsp[-2].minor.yy220 = yylhsminor.yy220; break; case 94: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy564 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 95: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 97: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==97); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy173, yymsp[-5].minor.yy564, yymsp[-3].minor.yy476, yymsp[-1].minor.yy476, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy273, yymsp[-5].minor.yy140, yymsp[-3].minor.yy220, yymsp[-1].minor.yy220, yymsp[0].minor.yy140); } break; case 96: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy476); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy220); } break; case 98: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy476); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy220); } break; case 99: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy173, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy273, yymsp[0].minor.yy140); } break; case 100: /* cmd ::= ALTER TABLE alter_table_clause */ case 101: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==101); - case 241: /* cmd ::= query_expression */ yytestcase(yyruleno==241); -{ pCxt->pRootNode = yymsp[0].minor.yy564; } + case 242: /* cmd ::= query_expression */ yytestcase(yyruleno==242); +{ pCxt->pRootNode = yymsp[0].minor.yy140; } break; case 102: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy564 = createAlterTableOption(pCxt, yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableOption(pCxt, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; case 103: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy564 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368); } + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; case 104: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy564 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy564, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy21); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy140, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy253); } + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; case 105: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy564 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368); } + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; case 106: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy564 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy21, &yymsp[0].minor.yy21); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy253, &yymsp[0].minor.yy253); } + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; case 107: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy564 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368); } + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; case 108: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy564 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy564, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy21); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy140, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy253); } + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; case 109: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy564 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368); } + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; case 110: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy564 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy21, &yymsp[0].minor.yy21); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy253, &yymsp[0].minor.yy253); } + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; case 111: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy564 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy564, &yymsp[-2].minor.yy21, yymsp[0].minor.yy564); } - yymsp[-5].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy140, &yymsp[-2].minor.yy253, yymsp[0].minor.yy140); } + yymsp[-5].minor.yy140 = yylhsminor.yy140; break; case 113: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ case 116: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==116); -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-1].minor.yy476, yymsp[0].minor.yy564); } - yymsp[-1].minor.yy476 = yylhsminor.yy476; +{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-1].minor.yy220, yymsp[0].minor.yy140); } + yymsp[-1].minor.yy220 = yylhsminor.yy220; break; case 114: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy564 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy173, yymsp[-7].minor.yy564, yymsp[-5].minor.yy564, yymsp[-4].minor.yy476, yymsp[-1].minor.yy476); } - yymsp[-8].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy273, yymsp[-7].minor.yy140, yymsp[-5].minor.yy140, yymsp[-4].minor.yy220, yymsp[-1].minor.yy220); } + yymsp[-8].minor.yy140 = yylhsminor.yy140; break; case 117: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy564 = createDropTableClause(pCxt, yymsp[-1].minor.yy173, yymsp[0].minor.yy564); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createDropTableClause(pCxt, yymsp[-1].minor.yy273, yymsp[0].minor.yy140); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; case 118: /* specific_tags_opt ::= */ case 149: /* tags_def_opt ::= */ yytestcase(yyruleno==149); - case 361: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==361); - case 378: /* group_by_clause_opt ::= */ yytestcase(yyruleno==378); - case 388: /* order_by_clause_opt ::= */ yytestcase(yyruleno==388); -{ yymsp[1].minor.yy476 = NULL; } + case 362: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==362); + case 379: /* group_by_clause_opt ::= */ yytestcase(yyruleno==379); + case 389: /* order_by_clause_opt ::= */ yytestcase(yyruleno==389); +{ yymsp[1].minor.yy220 = NULL; } break; case 119: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy476 = yymsp[-1].minor.yy476; } +{ yymsp[-2].minor.yy220 = yymsp[-1].minor.yy220; } break; case 120: /* full_table_name ::= table_name */ -{ yylhsminor.yy564 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy21, NULL); } - yymsp[0].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy253, NULL); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; case 121: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy564 = createRealTableNode(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy21, NULL); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createRealTableNode(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy253, NULL); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 124: /* column_def ::= column_name type_name */ -{ yylhsminor.yy564 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288, NULL); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368, NULL); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; case 125: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy564 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy21, yymsp[-2].minor.yy288, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy253, yymsp[-2].minor.yy368, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; case 126: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 127: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 128: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 129: /* type_name ::= INT */ case 130: /* type_name ::= INTEGER */ yytestcase(yyruleno==130); -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_INT); } break; case 131: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 132: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 133: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 134: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy368 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 135: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 136: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy368 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 137: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy288 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy368 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 138: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy288 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy368 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 139: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy288 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy368 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 140: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy288 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy368 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 141: /* type_name ::= JSON */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 142: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy368 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 143: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 144: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 145: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy368 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 146: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 147: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy368 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 148: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy288 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy368 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 150: /* tags_def_opt ::= tags_def */ - case 352: /* select_list ::= select_sublist */ yytestcase(yyruleno==352); -{ yylhsminor.yy476 = yymsp[0].minor.yy476; } - yymsp[0].minor.yy476 = yylhsminor.yy476; + case 353: /* select_list ::= select_sublist */ yytestcase(yyruleno==353); +{ yylhsminor.yy220 = yymsp[0].minor.yy220; } + yymsp[0].minor.yy220 = yylhsminor.yy220; break; case 151: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy476 = yymsp[-1].minor.yy476; } +{ yymsp[-3].minor.yy220 = yymsp[-1].minor.yy220; } break; case 152: /* table_options ::= */ -{ yymsp[1].minor.yy564 = createTableOptions(pCxt); } +{ yymsp[1].minor.yy140 = createTableOptions(pCxt); } break; case 153: /* table_options ::= table_options COMMENT NK_STRING */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy140)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 154: /* table_options ::= table_options KEEP integer_list */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pKeep = yymsp[0].minor.yy476; yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy140)->pKeep = yymsp[0].minor.yy220; yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 155: /* table_options ::= table_options TTL NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy140)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 156: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy564)->pSma = yymsp[-1].minor.yy476; yylhsminor.yy564 = yymsp[-4].minor.yy564; } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-4].minor.yy140)->pSma = yymsp[-1].minor.yy220; yylhsminor.yy140 = yymsp[-4].minor.yy140; } + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; case 157: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy564)->pFuncs = yymsp[-1].minor.yy476; yylhsminor.yy564 = yymsp[-4].minor.yy564; } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-4].minor.yy140)->pFuncs = yymsp[-1].minor.yy220; yylhsminor.yy140 = yymsp[-4].minor.yy140; } + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; case 158: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy140)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 159: /* table_options ::= table_options DELAY NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy140)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; case 160: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy564 = createTableOptions(pCxt); yylhsminor.yy564 = setTableAlterOption(pCxt, yylhsminor.yy564, &yymsp[0].minor.yy289); } - yymsp[0].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createTableOptions(pCxt); yylhsminor.yy140 = setTableAlterOption(pCxt, yylhsminor.yy140, &yymsp[0].minor.yy181); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; case 161: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy564 = setTableAlterOption(pCxt, yymsp[-1].minor.yy564, &yymsp[0].minor.yy289); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = setTableAlterOption(pCxt, yymsp[-1].minor.yy140, &yymsp[0].minor.yy181); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; case 162: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy289.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy181.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 163: /* alter_table_option ::= KEEP integer_list */ -{ yymsp[-1].minor.yy289.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy289.pList = yymsp[0].minor.yy476; } +{ yymsp[-1].minor.yy181.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy181.pList = yymsp[0].minor.yy220; } break; case 164: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy181.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 167: /* col_name ::= column_name */ -{ yylhsminor.yy564 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy21); } - yymsp[0].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy140 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy253); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; case 168: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } @@ -3545,13 +3140,13 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; case 171: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy564, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } break; case 172: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy564, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } break; case 173: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy564, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy140, NULL); } break; case 174: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } @@ -3566,7 +3161,7 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; case 178: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } break; case 179: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } @@ -3581,644 +3176,645 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } break; case 183: /* cmd ::= SHOW LICENCE */ + case 184: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==184); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } break; - case 184: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy21); } + case 185: /* cmd ::= SHOW CREATE DATABASE db_name */ +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy253); } break; - case 185: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy564); } + case 186: /* cmd ::= SHOW CREATE TABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy140); } break; - case 186: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy564); } + case 187: /* cmd ::= SHOW CREATE STABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy140); } break; - case 187: /* cmd ::= SHOW QUERIES */ + case 188: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } break; - case 188: /* cmd ::= SHOW SCORES */ + case 189: /* cmd ::= SHOW SCORES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } break; - case 189: /* cmd ::= SHOW TOPICS */ + case 190: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } break; - case 190: /* cmd ::= SHOW VARIABLES */ + case 191: /* cmd ::= SHOW VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } break; - case 191: /* cmd ::= SHOW BNODES */ + case 192: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT, NULL, NULL); } break; - case 192: /* cmd ::= SHOW SNODES */ + case 193: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT, NULL, NULL); } break; - case 193: /* db_name_cond_opt ::= */ - case 198: /* from_db_opt ::= */ yytestcase(yyruleno==198); -{ yymsp[1].minor.yy564 = createDefaultDatabaseCondValue(pCxt); } + case 194: /* db_name_cond_opt ::= */ + case 199: /* from_db_opt ::= */ yytestcase(yyruleno==199); +{ yymsp[1].minor.yy140 = createDefaultDatabaseCondValue(pCxt); } break; - case 194: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy21); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 195: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy253); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 195: /* like_pattern_opt ::= */ - case 206: /* index_options ::= */ yytestcase(yyruleno==206); - case 359: /* where_clause_opt ::= */ yytestcase(yyruleno==359); - case 363: /* twindow_clause_opt ::= */ yytestcase(yyruleno==363); - case 368: /* sliding_opt ::= */ yytestcase(yyruleno==368); - case 370: /* fill_opt ::= */ yytestcase(yyruleno==370); - case 382: /* having_clause_opt ::= */ yytestcase(yyruleno==382); - case 390: /* slimit_clause_opt ::= */ yytestcase(yyruleno==390); - case 394: /* limit_clause_opt ::= */ yytestcase(yyruleno==394); -{ yymsp[1].minor.yy564 = NULL; } + case 196: /* like_pattern_opt ::= */ + case 207: /* index_options ::= */ yytestcase(yyruleno==207); + case 360: /* where_clause_opt ::= */ yytestcase(yyruleno==360); + case 364: /* twindow_clause_opt ::= */ yytestcase(yyruleno==364); + case 369: /* sliding_opt ::= */ yytestcase(yyruleno==369); + case 371: /* fill_opt ::= */ yytestcase(yyruleno==371); + case 383: /* having_clause_opt ::= */ yytestcase(yyruleno==383); + case 391: /* slimit_clause_opt ::= */ yytestcase(yyruleno==391); + case 395: /* limit_clause_opt ::= */ yytestcase(yyruleno==395); +{ yymsp[1].minor.yy140 = NULL; } break; - case 196: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 197: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 197: /* table_name_cond ::= table_name */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy21); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 198: /* table_name_cond ::= table_name */ +{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy253); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 199: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy21); } + case 200: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy253); } break; - case 202: /* func_name ::= function_name */ -{ yylhsminor.yy564 = createFunctionNode(pCxt, &yymsp[0].minor.yy21, NULL); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 203: /* func_name ::= function_name */ +{ yylhsminor.yy140 = createFunctionNode(pCxt, &yymsp[0].minor.yy253, NULL); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 203: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy173, &yymsp[-3].minor.yy21, &yymsp[-1].minor.yy21, NULL, yymsp[0].minor.yy564); } + case 204: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy273, &yymsp[-3].minor.yy253, &yymsp[-1].minor.yy253, NULL, yymsp[0].minor.yy140); } break; - case 204: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy173, &yymsp[-5].minor.yy21, &yymsp[-3].minor.yy21, yymsp[-1].minor.yy476, NULL); } + case 205: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy273, &yymsp[-5].minor.yy253, &yymsp[-3].minor.yy253, yymsp[-1].minor.yy220, NULL); } break; - case 205: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy173, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy21); } + case 206: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy273, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy253); } break; - case 207: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy564 = createIndexOption(pCxt, yymsp[-6].minor.yy476, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), NULL, yymsp[0].minor.yy564); } + case 208: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ +{ yymsp[-8].minor.yy140 = createIndexOption(pCxt, yymsp[-6].minor.yy220, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), NULL, yymsp[0].minor.yy140); } break; - case 208: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy564 = createIndexOption(pCxt, yymsp[-8].minor.yy476, releaseRawExprNode(pCxt, yymsp[-4].minor.yy564), releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), yymsp[0].minor.yy564); } + case 209: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ +{ yymsp[-10].minor.yy140 = createIndexOption(pCxt, yymsp[-8].minor.yy220, releaseRawExprNode(pCxt, yymsp[-4].minor.yy140), releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), yymsp[0].minor.yy140); } break; - case 211: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy564 = createFunctionNode(pCxt, &yymsp[-3].minor.yy21, yymsp[-1].minor.yy476); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 212: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy140 = createFunctionNode(pCxt, &yymsp[-3].minor.yy253, yymsp[-1].minor.yy220); } + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; - case 212: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy173, &yymsp[-2].minor.yy21, yymsp[0].minor.yy564, NULL); } + case 213: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy273, &yymsp[-2].minor.yy253, yymsp[0].minor.yy140, NULL); } break; - case 213: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy173, &yymsp[-2].minor.yy21, NULL, &yymsp[0].minor.yy21); } + case 214: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy273, &yymsp[-2].minor.yy253, NULL, &yymsp[0].minor.yy253); } break; - case 214: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy21); } + case 215: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy273, &yymsp[0].minor.yy253); } break; - case 215: /* cmd ::= DESC full_table_name */ - case 216: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==216); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy564); } + case 216: /* cmd ::= DESC full_table_name */ + case 217: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==217); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy140); } break; - case 217: /* cmd ::= RESET QUERY CACHE */ + case 218: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 218: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy173, yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } + case 219: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy273, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } break; - case 220: /* analyze_opt ::= ANALYZE */ - case 228: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==228); - case 349: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==349); -{ yymsp[0].minor.yy173 = true; } + case 221: /* analyze_opt ::= ANALYZE */ + case 229: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==229); + case 350: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==350); +{ yymsp[0].minor.yy273 = true; } break; - case 221: /* explain_options ::= */ -{ yymsp[1].minor.yy564 = createDefaultExplainOptions(pCxt); } + case 222: /* explain_options ::= */ +{ yymsp[1].minor.yy140 = createDefaultExplainOptions(pCxt); } break; - case 222: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy564 = setExplainVerbose(pCxt, yymsp[-2].minor.yy564, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 223: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy140 = setExplainVerbose(pCxt, yymsp[-2].minor.yy140, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 223: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy564 = setExplainRatio(pCxt, yymsp[-2].minor.yy564, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 224: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy140 = setExplainRatio(pCxt, yymsp[-2].minor.yy140, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 224: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy476); } + case 225: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy220); } break; - case 225: /* cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy173, &yymsp[-5].minor.yy21, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy288, yymsp[0].minor.yy620); } + case 226: /* cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy273, &yymsp[-5].minor.yy253, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy368, yymsp[0].minor.yy528); } break; - case 226: /* cmd ::= DROP FUNCTION function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy21); } + case 227: /* cmd ::= DROP FUNCTION function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy253); } break; - case 229: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy620 = 0; } + case 230: /* bufsize_opt ::= */ +{ yymsp[1].minor.yy528 = 0; } break; - case 230: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy620 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 231: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy528 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 231: /* cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, &yymsp[-4].minor.yy21, &yymsp[-2].minor.yy21, yymsp[0].minor.yy564); } + case 232: /* cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, &yymsp[-4].minor.yy253, &yymsp[-2].minor.yy253, yymsp[0].minor.yy140); } break; - case 232: /* cmd ::= DROP STREAM stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy21); } + case 233: /* cmd ::= DROP STREAM stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy253); } break; - case 233: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 234: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 234: /* cmd ::= KILL QUERY NK_INTEGER */ + case 235: /* cmd ::= KILL QUERY NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_QUERY_STMT, &yymsp[0].minor.yy0); } break; - case 235: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 236: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 236: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy476); } + case 237: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy220); } break; - case 237: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 238: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 238: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy476 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + case 239: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy220 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; - case 240: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy21); } + case 241: /* cmd ::= SYNCDB db_name REPLICA */ +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy253); } break; - case 242: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 243: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 243: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 244: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 244: /* literal ::= NK_STRING */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 245: /* literal ::= NK_STRING */ +{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 245: /* literal ::= NK_BOOL */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 246: /* literal ::= NK_BOOL */ +{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 246: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 247: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 247: /* literal ::= duration_literal */ - case 256: /* signed_literal ::= signed */ yytestcase(yyruleno==256); - case 276: /* expression ::= literal */ yytestcase(yyruleno==276); - case 277: /* expression ::= pseudo_column */ yytestcase(yyruleno==277); - case 278: /* expression ::= column_reference */ yytestcase(yyruleno==278); - case 282: /* expression ::= subquery */ yytestcase(yyruleno==282); - case 322: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==322); - case 326: /* boolean_primary ::= predicate */ yytestcase(yyruleno==326); - case 328: /* common_expression ::= expression */ yytestcase(yyruleno==328); - case 329: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==329); - case 331: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==331); - case 333: /* table_reference ::= table_primary */ yytestcase(yyruleno==333); - case 334: /* table_reference ::= joined_table */ yytestcase(yyruleno==334); - case 338: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==338); - case 385: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==385); - case 387: /* query_primary ::= query_specification */ yytestcase(yyruleno==387); -{ yylhsminor.yy564 = yymsp[0].minor.yy564; } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 248: /* literal ::= duration_literal */ + case 257: /* signed_literal ::= signed */ yytestcase(yyruleno==257); + case 277: /* expression ::= literal */ yytestcase(yyruleno==277); + case 278: /* expression ::= pseudo_column */ yytestcase(yyruleno==278); + case 279: /* expression ::= column_reference */ yytestcase(yyruleno==279); + case 283: /* expression ::= subquery */ yytestcase(yyruleno==283); + case 323: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==323); + case 327: /* boolean_primary ::= predicate */ yytestcase(yyruleno==327); + case 329: /* common_expression ::= expression */ yytestcase(yyruleno==329); + case 330: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==330); + case 332: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==332); + case 334: /* table_reference ::= table_primary */ yytestcase(yyruleno==334); + case 335: /* table_reference ::= joined_table */ yytestcase(yyruleno==335); + case 339: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==339); + case 386: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==386); + case 388: /* query_primary ::= query_specification */ yytestcase(yyruleno==388); +{ yylhsminor.yy140 = yymsp[0].minor.yy140; } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 248: /* literal ::= NULL */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 249: /* literal ::= NULL */ +{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 249: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 250: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 250: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 251: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 251: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 252: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; - case 252: /* signed ::= NK_MINUS NK_INTEGER */ + case 253: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 253: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 254: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 254: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 255: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 255: /* signed ::= NK_MINUS NK_FLOAT */ + case 256: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 257: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 258: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 258: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 259: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 259: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 260: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 260: /* signed_literal ::= duration_literal */ - case 355: /* select_item ::= common_expression */ yytestcase(yyruleno==355); - case 399: /* search_condition ::= common_expression */ yytestcase(yyruleno==399); -{ yylhsminor.yy564 = releaseRawExprNode(pCxt, yymsp[0].minor.yy564); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 261: /* signed_literal ::= duration_literal */ + case 356: /* select_item ::= common_expression */ yytestcase(yyruleno==356); + case 400: /* search_condition ::= common_expression */ yytestcase(yyruleno==400); +{ yylhsminor.yy140 = releaseRawExprNode(pCxt, yymsp[0].minor.yy140); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 261: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } + case 262: /* signed_literal ::= NULL */ +{ yymsp[0].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; - case 279: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy21, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy21, yymsp[-1].minor.yy476)); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 280: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy253, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy253, yymsp[-1].minor.yy220)); } + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; - case 280: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy21, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy21, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 281: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy253, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy253, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; - case 281: /* expression ::= function_name NK_LP expression AS type_name NK_RP */ + case 282: /* expression ::= function_name NK_LP expression AS type_name NK_RP */ { - SNodeList *p = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy564)); - p = addValueNodeFromTypeToList(pCxt, yymsp[-1].minor.yy288, p); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy21, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-5].minor.yy21, p)); + SNodeList *p = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140)); + p = addValueNodeFromTypeToList(pCxt, yymsp[-1].minor.yy368, p); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy253, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-5].minor.yy253, p)); } - yymsp[-5].minor.yy564 = yylhsminor.yy564; + yymsp[-5].minor.yy140 = yylhsminor.yy140; break; - case 283: /* expression ::= NK_LP expression NK_RP */ - case 327: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==327); -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy564)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 284: /* expression ::= NK_LP expression NK_RP */ + case 328: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==328); +{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 284: /* expression ::= NK_PLUS expression */ + case 285: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy564)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 285: /* expression ::= NK_MINUS expression */ + case 286: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy564), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), NULL)); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 286: /* expression ::= expression NK_PLUS expression */ + case 287: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 287: /* expression ::= expression NK_MINUS expression */ + case 288: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 288: /* expression ::= expression NK_STAR expression */ + case 289: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 289: /* expression ::= expression NK_SLASH expression */ + case 290: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 290: /* expression ::= expression NK_REM expression */ + case 291: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 291: /* expression_list ::= expression */ -{ yylhsminor.yy476 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy564)); } - yymsp[0].minor.yy476 = yylhsminor.yy476; + case 292: /* expression_list ::= expression */ +{ yylhsminor.yy220 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } + yymsp[0].minor.yy220 = yylhsminor.yy220; break; - case 292: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, releaseRawExprNode(pCxt, yymsp[0].minor.yy564)); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; + case 293: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } + yymsp[-2].minor.yy220 = yylhsminor.yy220; break; - case 293: /* column_reference ::= column_name */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy21, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy21)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 294: /* column_reference ::= column_name */ +{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy253, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy253)); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 294: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy21, createColumnNode(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy21)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 295: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy253, createColumnNode(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy253)); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 295: /* pseudo_column ::= NOW */ - case 296: /* pseudo_column ::= ROWTS */ yytestcase(yyruleno==296); - case 297: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==297); - case 298: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==298); - case 299: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==299); - case 300: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==300); - case 301: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==301); - case 302: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==302); -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 296: /* pseudo_column ::= NOW */ + case 297: /* pseudo_column ::= ROWTS */ yytestcase(yyruleno==297); + case 298: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==298); + case 299: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==299); + case 300: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==300); + case 301: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==301); + case 302: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==302); + case 303: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==303); +{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy140 = yylhsminor.yy140; break; - case 303: /* predicate ::= expression compare_op expression */ - case 308: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==308); + case 304: /* predicate ::= expression compare_op expression */ + case 309: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==309); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy468, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy480, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 304: /* predicate ::= expression BETWEEN expression AND expression */ + case 305: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy564), releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy140), releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; + yymsp[-4].minor.yy140 = yylhsminor.yy140; break; - case 305: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 306: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[-5].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[-5].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-5].minor.yy564 = yylhsminor.yy564; + yymsp[-5].minor.yy140 = yylhsminor.yy140; break; - case 306: /* predicate ::= expression IS NULL */ + case 307: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), NULL)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 307: /* predicate ::= expression IS NOT NULL */ + case 308: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy564), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), NULL)); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; - case 309: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy468 = OP_TYPE_LOWER_THAN; } + case 310: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy480 = OP_TYPE_LOWER_THAN; } break; - case 310: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy468 = OP_TYPE_GREATER_THAN; } + case 311: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy480 = OP_TYPE_GREATER_THAN; } break; - case 311: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy468 = OP_TYPE_LOWER_EQUAL; } + case 312: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy480 = OP_TYPE_LOWER_EQUAL; } break; - case 312: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy468 = OP_TYPE_GREATER_EQUAL; } + case 313: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy480 = OP_TYPE_GREATER_EQUAL; } break; - case 313: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy468 = OP_TYPE_NOT_EQUAL; } + case 314: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy480 = OP_TYPE_NOT_EQUAL; } break; - case 314: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy468 = OP_TYPE_EQUAL; } + case 315: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy480 = OP_TYPE_EQUAL; } break; - case 315: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy468 = OP_TYPE_LIKE; } + case 316: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy480 = OP_TYPE_LIKE; } break; - case 316: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy468 = OP_TYPE_NOT_LIKE; } + case 317: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy480 = OP_TYPE_NOT_LIKE; } break; - case 317: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy468 = OP_TYPE_MATCH; } + case 318: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy480 = OP_TYPE_MATCH; } break; - case 318: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy468 = OP_TYPE_NMATCH; } + case 319: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy480 = OP_TYPE_NMATCH; } break; - case 319: /* in_op ::= IN */ -{ yymsp[0].minor.yy468 = OP_TYPE_IN; } + case 320: /* in_op ::= IN */ +{ yymsp[0].minor.yy480 = OP_TYPE_IN; } break; - case 320: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy468 = OP_TYPE_NOT_IN; } + case 321: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy480 = OP_TYPE_NOT_IN; } break; - case 321: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy476)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 322: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy220)); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 323: /* boolean_value_expression ::= NOT boolean_primary */ + case 324: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy564), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), NULL)); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 324: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 325: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 325: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 326: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); + yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 330: /* from_clause ::= FROM table_reference_list */ - case 360: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==360); - case 383: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==383); -{ yymsp[-1].minor.yy564 = yymsp[0].minor.yy564; } + case 331: /* from_clause ::= FROM table_reference_list */ + case 361: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==361); + case 384: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==384); +{ yymsp[-1].minor.yy140 = yymsp[0].minor.yy140; } break; - case 332: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy564 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy564, yymsp[0].minor.yy564, NULL); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 333: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy140 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy140, yymsp[0].minor.yy140, NULL); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 335: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy564 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy21, &yymsp[0].minor.yy21); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 336: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy140 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy253, &yymsp[0].minor.yy253); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 336: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy564 = createRealTableNode(pCxt, &yymsp[-3].minor.yy21, &yymsp[-1].minor.yy21, &yymsp[0].minor.yy21); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 337: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy140 = createRealTableNode(pCxt, &yymsp[-3].minor.yy253, &yymsp[-1].minor.yy253, &yymsp[0].minor.yy253); } + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; - case 337: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy564 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy564), &yymsp[0].minor.yy21); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 338: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy140 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140), &yymsp[0].minor.yy253); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 339: /* alias_opt ::= */ -{ yymsp[1].minor.yy21 = nil_token; } + case 340: /* alias_opt ::= */ +{ yymsp[1].minor.yy253 = nil_token; } break; - case 340: /* alias_opt ::= table_alias */ -{ yylhsminor.yy21 = yymsp[0].minor.yy21; } - yymsp[0].minor.yy21 = yylhsminor.yy21; + case 341: /* alias_opt ::= table_alias */ +{ yylhsminor.yy253 = yymsp[0].minor.yy253; } + yymsp[0].minor.yy253 = yylhsminor.yy253; break; - case 341: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy21 = yymsp[0].minor.yy21; } + case 342: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy253 = yymsp[0].minor.yy253; } break; - case 342: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 343: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==343); -{ yymsp[-2].minor.yy564 = yymsp[-1].minor.yy564; } + case 343: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 344: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==344); +{ yymsp[-2].minor.yy140 = yymsp[-1].minor.yy140; } break; - case 344: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy564 = createJoinTableNode(pCxt, yymsp[-4].minor.yy440, yymsp[-5].minor.yy564, yymsp[-2].minor.yy564, yymsp[0].minor.yy564); } - yymsp[-5].minor.yy564 = yylhsminor.yy564; + case 345: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy140 = createJoinTableNode(pCxt, yymsp[-4].minor.yy224, yymsp[-5].minor.yy140, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } + yymsp[-5].minor.yy140 = yylhsminor.yy140; break; - case 345: /* join_type ::= */ -{ yymsp[1].minor.yy440 = JOIN_TYPE_INNER; } + case 346: /* join_type ::= */ +{ yymsp[1].minor.yy224 = JOIN_TYPE_INNER; } break; - case 346: /* join_type ::= INNER */ -{ yymsp[0].minor.yy440 = JOIN_TYPE_INNER; } + case 347: /* join_type ::= INNER */ +{ yymsp[0].minor.yy224 = JOIN_TYPE_INNER; } break; - case 347: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 348: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy564 = createSelectStmt(pCxt, yymsp[-7].minor.yy173, yymsp[-6].minor.yy476, yymsp[-5].minor.yy564); - yymsp[-8].minor.yy564 = addWhereClause(pCxt, yymsp[-8].minor.yy564, yymsp[-4].minor.yy564); - yymsp[-8].minor.yy564 = addPartitionByClause(pCxt, yymsp[-8].minor.yy564, yymsp[-3].minor.yy476); - yymsp[-8].minor.yy564 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy564, yymsp[-2].minor.yy564); - yymsp[-8].minor.yy564 = addGroupByClause(pCxt, yymsp[-8].minor.yy564, yymsp[-1].minor.yy476); - yymsp[-8].minor.yy564 = addHavingClause(pCxt, yymsp[-8].minor.yy564, yymsp[0].minor.yy564); + yymsp[-8].minor.yy140 = createSelectStmt(pCxt, yymsp[-7].minor.yy273, yymsp[-6].minor.yy220, yymsp[-5].minor.yy140); + yymsp[-8].minor.yy140 = addWhereClause(pCxt, yymsp[-8].minor.yy140, yymsp[-4].minor.yy140); + yymsp[-8].minor.yy140 = addPartitionByClause(pCxt, yymsp[-8].minor.yy140, yymsp[-3].minor.yy220); + yymsp[-8].minor.yy140 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy140, yymsp[-2].minor.yy140); + yymsp[-8].minor.yy140 = addGroupByClause(pCxt, yymsp[-8].minor.yy140, yymsp[-1].minor.yy220); + yymsp[-8].minor.yy140 = addHavingClause(pCxt, yymsp[-8].minor.yy140, yymsp[0].minor.yy140); } break; - case 350: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy173 = false; } + case 351: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy273 = false; } break; - case 351: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy476 = NULL; } + case 352: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy220 = NULL; } break; - case 356: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy564 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy564), &yymsp[0].minor.yy21); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 357: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140), &yymsp[0].minor.yy253); } + yymsp[-1].minor.yy140 = yylhsminor.yy140; break; - case 357: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy564 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), &yymsp[0].minor.yy21); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 358: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), &yymsp[0].minor.yy253); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 358: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy564 = createColumnNode(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 359: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy140 = createColumnNode(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 362: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 379: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==379); - case 389: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==389); -{ yymsp[-2].minor.yy476 = yymsp[0].minor.yy476; } + case 363: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 380: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==380); + case 390: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==390); +{ yymsp[-2].minor.yy220 = yymsp[0].minor.yy220; } break; - case 364: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy564 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy564), releaseRawExprNode(pCxt, yymsp[-1].minor.yy564)); } + case 365: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy140 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } break; - case 365: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy564 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy564)); } + case 366: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy140 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } break; - case 366: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy564 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy564), NULL, yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } + case 367: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy140 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), NULL, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } break; - case 367: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy564 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy564), releaseRawExprNode(pCxt, yymsp[-3].minor.yy564), yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } + case 368: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy140 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy140), releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } break; - case 369: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy564 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy564); } + case 370: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy140 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy140); } break; - case 371: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy564 = createFillNode(pCxt, yymsp[-1].minor.yy268, NULL); } + case 372: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy140 = createFillNode(pCxt, yymsp[-1].minor.yy174, NULL); } break; - case 372: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy564 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy476)); } + case 373: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy140 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy220)); } break; - case 373: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy268 = FILL_MODE_NONE; } + case 374: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy174 = FILL_MODE_NONE; } break; - case 374: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy268 = FILL_MODE_PREV; } + case 375: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy174 = FILL_MODE_PREV; } break; - case 375: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy268 = FILL_MODE_NULL; } + case 376: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy174 = FILL_MODE_NULL; } break; - case 376: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy268 = FILL_MODE_LINEAR; } + case 377: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy174 = FILL_MODE_LINEAR; } break; - case 377: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy268 = FILL_MODE_NEXT; } + case 378: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy174 = FILL_MODE_NEXT; } break; - case 380: /* group_by_list ::= expression */ -{ yylhsminor.yy476 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); } - yymsp[0].minor.yy476 = yylhsminor.yy476; + case 381: /* group_by_list ::= expression */ +{ yylhsminor.yy220 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } + yymsp[0].minor.yy220 = yylhsminor.yy220; break; - case 381: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; + case 382: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } + yymsp[-2].minor.yy220 = yylhsminor.yy220; break; - case 384: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 385: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy564 = addOrderByClause(pCxt, yymsp[-3].minor.yy564, yymsp[-2].minor.yy476); - yylhsminor.yy564 = addSlimitClause(pCxt, yylhsminor.yy564, yymsp[-1].minor.yy564); - yylhsminor.yy564 = addLimitClause(pCxt, yylhsminor.yy564, yymsp[0].minor.yy564); + yylhsminor.yy140 = addOrderByClause(pCxt, yymsp[-3].minor.yy140, yymsp[-2].minor.yy220); + yylhsminor.yy140 = addSlimitClause(pCxt, yylhsminor.yy140, yymsp[-1].minor.yy140); + yylhsminor.yy140 = addLimitClause(pCxt, yylhsminor.yy140, yymsp[0].minor.yy140); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; - case 386: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy564 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy564, yymsp[0].minor.yy564); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 387: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy140 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy140, yymsp[0].minor.yy140); } + yymsp[-3].minor.yy140 = yylhsminor.yy140; break; - case 391: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 395: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==395); -{ yymsp[-1].minor.yy564 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 392: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 396: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==396); +{ yymsp[-1].minor.yy140 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 392: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 396: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==396); -{ yymsp[-3].minor.yy564 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 393: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 397: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==397); +{ yymsp[-3].minor.yy140 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 393: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 397: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==397); -{ yymsp[-3].minor.yy564 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 394: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 398: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==398); +{ yymsp[-3].minor.yy140 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 398: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy564); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 399: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy140); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 402: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy564 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), yymsp[-1].minor.yy256, yymsp[0].minor.yy525); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 403: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy140 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), yymsp[-1].minor.yy238, yymsp[0].minor.yy69); } + yymsp[-2].minor.yy140 = yylhsminor.yy140; break; - case 403: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy256 = ORDER_ASC; } + case 404: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy238 = ORDER_ASC; } break; - case 404: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy256 = ORDER_ASC; } + case 405: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy238 = ORDER_ASC; } break; - case 405: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy256 = ORDER_DESC; } + case 406: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy238 = ORDER_DESC; } break; - case 406: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy525 = NULL_ORDER_DEFAULT; } + case 407: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy69 = NULL_ORDER_DEFAULT; } break; - case 407: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy525 = NULL_ORDER_FIRST; } + case 408: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy69 = NULL_ORDER_FIRST; } break; - case 408: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy525 = NULL_ORDER_LAST; } + case 409: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy69 = NULL_ORDER_LAST; } break; default: break; /********** End reduce actions ************************************************/ }; - assert( yyruleno 10 and c1 is not null"); + ASSERT_TRUE(run()); +} + TEST_F(ParserTest, selectPseudoColumn) { setDatabase("root", "test"); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index bd5ce0f494..1d8400e1eb 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -200,6 +200,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect strcpy(pScan->tableName.tname, pRealTable->table.tableName); pScan->showRewrite = pCxt->pPlanCxt->showRewrite; pScan->ratio = pRealTable->ratio; + pScan->dataRequired = FUNC_DATA_REQUIRED_ALL_NEEDED; // set columns to scan SNodeList* pCols = NULL; diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 2a36e38ce1..c56e113d40 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -14,7 +14,231 @@ */ #include "planInt.h" +#include "functionMgt.h" -int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { +#define OPTIMIZE_FLAG_MASK(n) (1 << n) + +#define OPTIMIZE_FLAG_OSD OPTIMIZE_FLAG_MASK(0) + +#define OPTIMIZE_FLAG_SET_MASK(val, mask) (val) |= (mask) +#define OPTIMIZE_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) + +typedef struct SOptimizeContext { + bool optimized; +} SOptimizeContext; + +typedef int32_t (*FMatch)(SOptimizeContext* pCxt, SLogicNode* pLogicNode); +typedef int32_t (*FOptimize)(SOptimizeContext* pCxt, SLogicNode* pLogicNode); + +typedef struct SOptimizeRule { + char* pName; + FOptimize optimizeFunc; +} SOptimizeRule; + +typedef struct SOsdInfo { + SScanLogicNode* pScan; + SNodeList* pSdrFuncs; + SNodeList* pDsoFuncs; +} SOsdInfo; + +static bool osdMayBeOptimized(SLogicNode* pNode) { + if (OPTIMIZE_FLAG_TEST_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_OSD)) { + return false; + } + if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode)) { + return false; + } + if (NULL == pNode->pParent || + (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode->pParent))) { + return false; + } + return true; +} + +static SLogicNode* osdFindPossibleScanNode(SLogicNode* pNode) { + if (osdMayBeOptimized(pNode)) { + return pNode; + } + SNode* pChild; + FOREACH(pChild, pNode->pChildren) { + SLogicNode* pScanNode = osdFindPossibleScanNode((SLogicNode*)pChild); + if (NULL != pScanNode) { + return pScanNode; + } + } + return NULL; +} + +static SNodeList* osdGetAllFuncs(SLogicNode* pNode) { + switch (nodeType(pNode)) { + case QUERY_NODE_LOGIC_PLAN_WINDOW: + return ((SWindowLogicNode*)pNode)->pFuncs; + case QUERY_NODE_LOGIC_PLAN_AGG: + return ((SAggLogicNode*)pNode)->pAggFuncs; + default: + break; + } + return NULL; +} + +static int32_t osdGetRelatedFuncs(SScanLogicNode* pScan, SNodeList** pSdrFuncs, SNodeList** pDsoFuncs) { + SNodeList* pAllFuncs = osdGetAllFuncs(pScan->node.pParent); + SNode* pFunc = NULL; + FOREACH(pFunc, pAllFuncs) { + int32_t code = TSDB_CODE_SUCCESS; + if (fmIsSpecialDataRequiredFunc(((SFunctionNode*)pFunc)->funcId)) { + code = nodesListMakeStrictAppend(pSdrFuncs, nodesCloneNode(pFunc)); + } else if (fmIsDynamicScanOptimizedFunc(((SFunctionNode*)pFunc)->funcId)) { + code = nodesListMakeStrictAppend(pDsoFuncs, nodesCloneNode(pFunc)); + } + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyList(*pSdrFuncs); + nodesDestroyList(*pDsoFuncs); + return code; + } + } return TSDB_CODE_SUCCESS; } + +static int32_t osdMatch(SOptimizeContext* pCxt, SLogicNode* pLogicNode, SOsdInfo* pInfo) { + pInfo->pScan = (SScanLogicNode*)osdFindPossibleScanNode(pLogicNode); + if (NULL == pInfo->pScan) { + return TSDB_CODE_SUCCESS; + } + return osdGetRelatedFuncs(pInfo->pScan, &pInfo->pSdrFuncs, &pInfo->pDsoFuncs); +} + +static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l , EFuncDataRequired r) { + switch (l) { + case FUNC_DATA_REQUIRED_ALL_NEEDED: + return l; + case FUNC_DATA_REQUIRED_STATIS_NEEDED: + return FUNC_DATA_REQUIRED_ALL_NEEDED == r ? r : l; + case FUNC_DATA_REQUIRED_NO_NEEDED: + return FUNC_DATA_REQUIRED_DISCARD == r ? l : r; + default: + break; + } + return r; +} + +static int32_t osdGetDataRequired(SNodeList* pFuncs) { + if (NULL == pFuncs) { + return FUNC_DATA_REQUIRED_ALL_NEEDED; + } + EFuncDataRequired dataRequired = FUNC_DATA_REQUIRED_DISCARD; + SNode* pFunc = NULL; + FOREACH(pFunc, pFuncs) { + dataRequired = osdPromoteDataRequired(dataRequired, fmFuncDataRequired((SFunctionNode*)pFunc, NULL)); + } + return dataRequired; +} + +static int32_t osdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { + SOsdInfo info = {0}; + int32_t code = osdMatch(pCxt, pLogicNode, &info); + if (TSDB_CODE_SUCCESS == code && (NULL != info.pDsoFuncs || NULL != info.pSdrFuncs)) { + info.pScan->dataRequired = osdGetDataRequired(info.pSdrFuncs); + info.pScan->pDynamicScanFuncs = info.pDsoFuncs; + OPTIMIZE_FLAG_SET_MASK(info.pScan->node.optimizedFlag, OPTIMIZE_FLAG_OSD); + pCxt->optimized = true; + } + nodesDestroyList(info.pSdrFuncs); + return code; +} + +static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode* pScan) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t cpdPartitionCondition(SJoinLogicNode* pJoin, SNodeList** pMultiTableCond, SNodeList** pSingleTableCond) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t cpdPushJoinCondToOnCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin, SNodeList* pMultiTableCond) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t cpdPushJoinCondToChildren(SOptimizeContext* pCxt, SJoinLogicNode* pJoin, SNodeList* pSingleTableCond) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t cpdPushJoinCondition(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) { + if (NULL != pJoin->node.pConditions) { + SNodeList* pMultiTableCond = NULL; + SNodeList* pSingleTableCond = NULL; + int32_t code = cpdPartitionCondition(pJoin, &pMultiTableCond, &pSingleTableCond); + if (TSDB_CODE_SUCCESS == code && NULL != pMultiTableCond) { + code = cpdPushJoinCondToOnCond(pCxt, pJoin, pMultiTableCond); + } + if (TSDB_CODE_SUCCESS == code && NULL != pSingleTableCond) { + code = cpdPushJoinCondToChildren(pCxt, pJoin, pSingleTableCond); + } + } + return TSDB_CODE_SUCCESS; +} + +static int32_t cpdPushAggCondition(SOptimizeContext* pCxt, SAggLogicNode* pAgg) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t cpdPushCondition(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { + int32_t code = TSDB_CODE_SUCCESS; + switch (nodeType(pLogicNode)) { + case QUERY_NODE_LOGIC_PLAN_SCAN: + code = cpdOptimizeScanCondition(pCxt, (SScanLogicNode*)pLogicNode); + break; + case QUERY_NODE_LOGIC_PLAN_JOIN: + code = cpdPushJoinCondition(pCxt, (SJoinLogicNode*)pLogicNode); + break; + case QUERY_NODE_LOGIC_PLAN_AGG: + code = cpdPushAggCondition(pCxt, (SAggLogicNode*)pLogicNode); + break; + default: + break; + } + if (TSDB_CODE_SUCCESS == code) { + SNode* pChild = NULL; + FOREACH(pChild, pLogicNode->pChildren) { + code = cpdPushCondition(pCxt, (SLogicNode*)pChild); + if (TSDB_CODE_SUCCESS != code) { + break; + } + } + } + return code; +} + +static int32_t cpdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { + return cpdPushCondition(pCxt, pLogicNode); +} + +static const SOptimizeRule optimizeRuleSet[] = { + { .pName = "OptimizeScanData", .optimizeFunc = osdOptimize }, + { .pName = "ConditionPushDown", .optimizeFunc = cpdOptimize } +}; + +static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimizeRule)); + +static int32_t applyOptimizeRule(SLogicNode* pLogicNode) { + SOptimizeContext cxt = { .optimized = false }; + do { + cxt.optimized = false; + for (int32_t i = 0; i < optimizeRuleNum; ++i) { + int32_t code = optimizeRuleSet[i].optimizeFunc(&cxt, pLogicNode); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + } + } while (cxt.optimized); + return TSDB_CODE_SUCCESS; +} + +int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { + return applyOptimizeRule(pLogicNode); +} diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index f34452f84a..8459f4beba 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -437,6 +437,12 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode); pSubplan->execNodeStat.tableNum = pScanLogicNode->pVgroupList->vgroups[0].numOfTable; tNameGetFullDbName(&pScanLogicNode->tableName, pSubplan->dbFName); + pTableScan->dataRequired = pScanLogicNode->dataRequired; + pTableScan->pDynamicScanFuncs = nodesCloneList(pScanLogicNode->pDynamicScanFuncs); + if (NULL != pScanLogicNode->pDynamicScanFuncs && NULL == pTableScan->pDynamicScanFuncs) { + nodesDestroyNode(pTableScan); + return TSDB_CODE_OUT_OF_MEMORY; + } return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode); } @@ -486,58 +492,25 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, return TSDB_CODE_FAILED; } -static int32_t createColFromDataBlockDesc(SDataBlockDescNode* pDesc, SNodeList* pCols) { - SNode* pNode; - FOREACH(pNode, pDesc->pSlots) { - SSlotDescNode* pSlot = (SSlotDescNode*)pNode; - SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); - if (NULL == pCol) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCol->node.resType = pSlot->dataType; - pCol->dataBlockId = pDesc->dataBlockId; - pCol->slotId = pSlot->slotId; - pCol->colId = -1; - int32_t code = nodesListStrictAppend(pCols, pCol); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - } - return TSDB_CODE_SUCCESS; -} - -static int32_t createJoinOutputCols(SPhysiPlanContext* pCxt, SDataBlockDescNode* pLeftDesc, SDataBlockDescNode* pRightDesc, SNodeList** pList) { - SNodeList* pCols = nodesMakeList(); - if (NULL == pCols) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - int32_t code = createColFromDataBlockDesc(pLeftDesc, pCols); - if (TSDB_CODE_SUCCESS == code) { - code = createColFromDataBlockDesc(pRightDesc, pCols); - } - - if (TSDB_CODE_SUCCESS == code) { - *pList = pCols; - } else { - nodesDestroyList(pCols); - } - - return code; -} - static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) { SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN); if (NULL == pJoin) { return TSDB_CODE_OUT_OF_MEMORY; } - SDataBlockDescNode* pLeftDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc; - SDataBlockDescNode* pRightDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc; + int32_t code = TSDB_CODE_SUCCESS; - int32_t code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions); + pJoin->joinType = pJoinLogicNode->joinType; + if (NULL != pJoinLogicNode->pOnConditions) { + SDataBlockDescNode* pLeftDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc; + SDataBlockDescNode* pRightDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc; + code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions); + } if (TSDB_CODE_SUCCESS == code) { - code = createJoinOutputCols(pCxt, pLeftDesc, pRightDesc, &pJoin->pTargets); + pJoin->pTargets = nodesCloneList(pJoinLogicNode->node.pTargets); + if (NULL == pJoin->pTargets) { + code = TSDB_CODE_OUT_OF_MEMORY; + } } if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc); diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index aadbaf6fd8..0b21052955 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -23,18 +23,14 @@ #define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) typedef struct SSplitContext { - int32_t errCode; int32_t groupId; - bool match; - void* pInfo; + bool split; } SSplitContext; -typedef int32_t (*FMatch)(SSplitContext* pCxt, SLogicSubplan* pSubplan); -typedef int32_t (*FSplit)(SSplitContext* pCxt); +typedef int32_t (*FSplit)(SSplitContext* pCxt, SLogicSubplan* pSubplan); typedef struct SSplitRule { char* pName; - FMatch matchFunc; FSplit splitFunc; } SSplitRule; @@ -58,30 +54,25 @@ static SLogicNode* stsMatchByNode(SLogicNode* pNode) { return NULL; } -static int32_t stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan) { - if (SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS)) { - return TSDB_CODE_SUCCESS; - } +static void stsFindSplitNode(SLogicSubplan* pSubplan, SStsInfo* pInfo) { SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode); if (NULL != pSplitNode) { - SStsInfo* pInfo = taosMemoryCalloc(1, sizeof(SStsInfo)); - if (NULL == pInfo) { - return TSDB_CODE_OUT_OF_MEMORY; - } pInfo->pScan = (SScanLogicNode*)pSplitNode; pInfo->pSubplan = pSubplan; - pCxt->pInfo = pInfo; - pCxt->match = true; - return TSDB_CODE_SUCCESS; + } +} +static void stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, SStsInfo* pInfo) { + if (!SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS)) { + stsFindSplitNode(pSubplan, pInfo); } SNode* pChild; FOREACH(pChild, pSubplan->pChildren) { - int32_t code = stsMatch(pCxt, (SLogicSubplan*)pChild); - if (TSDB_CODE_SUCCESS != code || pCxt->match) { - return code; + stsMatch(pCxt, (SLogicSubplan*)pChild, pInfo); + if (NULL != pInfo->pScan) { + break; } } - return TSDB_CODE_SUCCESS; + return; } static SLogicSubplan* stsCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* pScan) { @@ -128,46 +119,44 @@ static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla return TSDB_CODE_FAILED; } -static int32_t stsSplit(SSplitContext* pCxt) { - SStsInfo* pInfo = pCxt->pInfo; - if (NULL == pInfo->pSubplan->pChildren) { - pInfo->pSubplan->pChildren = nodesMakeList(); - if (NULL == pInfo->pSubplan->pChildren) { +static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { + SStsInfo info = {0}; + stsMatch(pCxt, pSubplan, &info); + if (NULL == info.pScan) { + return TSDB_CODE_SUCCESS; + } + if (NULL == info.pSubplan->pChildren) { + info.pSubplan->pChildren = nodesMakeList(); + if (NULL == info.pSubplan->pChildren) { return TSDB_CODE_OUT_OF_MEMORY; } } - int32_t code = nodesListStrictAppend(pInfo->pSubplan->pChildren, stsCreateScanSubplan(pCxt, pInfo->pScan)); + int32_t code = nodesListStrictAppend(info.pSubplan->pChildren, stsCreateScanSubplan(pCxt, info.pScan)); if (TSDB_CODE_SUCCESS == code) { - code = stsCreateExchangeNode(pCxt, pInfo->pSubplan, pInfo->pScan); + code = stsCreateExchangeNode(pCxt, info.pSubplan, info.pScan); } ++(pCxt->groupId); - taosMemoryFreeClear(pCxt->pInfo); + pCxt->split = true; return code; } static const SSplitRule splitRuleSet[] = { - { .pName = "SuperTableScan", .matchFunc = stsMatch, .splitFunc = stsSplit } + { .pName = "SuperTableScan", .splitFunc = stsSplit } }; static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule)); static int32_t applySplitRule(SLogicSubplan* pSubplan) { - SSplitContext cxt = { .errCode = TSDB_CODE_SUCCESS, .groupId = pSubplan->id.groupId + 1, .match = false, .pInfo = NULL }; - bool split = false; + SSplitContext cxt = { .groupId = pSubplan->id.groupId + 1, .split = false }; do { - split = false; + cxt.split = false; for (int32_t i = 0; i < splitRuleNum; ++i) { - cxt.match = false; - int32_t code = splitRuleSet[i].matchFunc(&cxt, pSubplan); - if (TSDB_CODE_SUCCESS == code && cxt.match) { - code = splitRuleSet[i].splitFunc(&cxt); - split = true; - } + int32_t code = splitRuleSet[i].splitFunc(&cxt, pSubplan); if (TSDB_CODE_SUCCESS != code) { return code; } } - } while (split); + } while (cxt.split); return TSDB_CODE_SUCCESS; } @@ -201,6 +190,7 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan pSubplan->subplanType = SUBPLAN_TYPE_SCAN; } pSubplan->id.queryId = pCxt->queryId; + pSubplan->id.groupId = 1; setLogicNodeParent(pSubplan->pNode); int32_t code = applySplitRule(pSubplan); diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index 697c562b1e..fd0084c01e 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -150,7 +150,7 @@ private: SQuery* query_; }; -TEST_F(PlannerTest, simple) { +TEST_F(PlannerTest, selectBasic) { setDatabase("root", "test"); bind("SELECT * FROM t1"); @@ -164,37 +164,50 @@ TEST_F(PlannerTest, selectConstant) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, stSimple) { +TEST_F(PlannerTest, selectStableBasic) { setDatabase("root", "test"); bind("SELECT * FROM st1"); ASSERT_TRUE(run()); } -TEST_F(PlannerTest, groupBy) { +TEST_F(PlannerTest, selectJoin) { + setDatabase("root", "test"); + + bind("SELECT * FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + ASSERT_TRUE(run()); + + bind("SELECT * FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1"); + ASSERT_TRUE(run()); + + bind("SELECT t1.* FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1"); + ASSERT_TRUE(run()); +} + +TEST_F(PlannerTest, selectGroupBy) { setDatabase("root", "test"); bind("SELECT count(*) FROM t1"); ASSERT_TRUE(run()); - bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1"); - ASSERT_TRUE(run()); + // bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1"); + // ASSERT_TRUE(run()); - bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3"); - ASSERT_TRUE(run()); + // bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3"); + // ASSERT_TRUE(run()); - bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3"); - ASSERT_TRUE(run()); + // bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3"); + // ASSERT_TRUE(run()); } -TEST_F(PlannerTest, subquery) { +TEST_F(PlannerTest, selectSubquery) { setDatabase("root", "test"); bind("SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 group by b"); ASSERT_TRUE(run()); } -TEST_F(PlannerTest, interval) { +TEST_F(PlannerTest, selectInterval) { setDatabase("root", "test"); bind("SELECT count(*) FROM t1 interval(10s)"); @@ -210,14 +223,14 @@ TEST_F(PlannerTest, interval) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, sessionWindow) { +TEST_F(PlannerTest, selectSessionWindow) { setDatabase("root", "test"); bind("SELECT count(*) FROM t1 session(ts, 10s)"); ASSERT_TRUE(run()); } -TEST_F(PlannerTest, stateWindow) { +TEST_F(PlannerTest, selectStateWindow) { setDatabase("root", "test"); bind("SELECT count(*) FROM t1 state_window(c1)"); @@ -227,7 +240,7 @@ TEST_F(PlannerTest, stateWindow) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, partitionBy) { +TEST_F(PlannerTest, selectPartitionBy) { setDatabase("root", "test"); bind("SELECT * FROM t1 partition by c1"); @@ -243,7 +256,7 @@ TEST_F(PlannerTest, partitionBy) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, orderBy) { +TEST_F(PlannerTest, selectOrderBy) { setDatabase("root", "test"); bind("SELECT c1 FROM t1 order by c1"); @@ -259,7 +272,7 @@ TEST_F(PlannerTest, orderBy) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, groupByOrderBy) { +TEST_F(PlannerTest, selectGroupByOrderBy) { setDatabase("root", "test"); bind("select count(*), sum(c1) from t1 order by sum(c1)"); @@ -269,7 +282,7 @@ TEST_F(PlannerTest, groupByOrderBy) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, distinct) { +TEST_F(PlannerTest, selectDistinct) { setDatabase("root", "test"); bind("SELECT distinct c1 FROM t1"); @@ -282,7 +295,7 @@ TEST_F(PlannerTest, distinct) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, limit) { +TEST_F(PlannerTest, selectLimit) { setDatabase("root", "test"); bind("SELECT * FROM t1 limit 2"); @@ -295,7 +308,7 @@ TEST_F(PlannerTest, limit) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, slimit) { +TEST_F(PlannerTest, selectSlimit) { setDatabase("root", "test"); bind("SELECT * FROM t1 partition by c1 slimit 2"); diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index 58b62bb05e..3d59ffd93d 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -46,8 +46,9 @@ typedef struct SScalarCtx { int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out); SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows); -#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type) -#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes) +#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type) +#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes) +#define GET_PARAM_PRECISON(_c) ((_c)->columnData->info.precision) void sclFreeParam(SScalarParam *param); diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 0956c2add5..b53dc955de 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1,6 +1,7 @@ #include "function.h" #include "scalar.h" #include "tdatablock.h" +#include "ttime.h" #include "sclInt.h" #include "sclvector.h" @@ -647,6 +648,461 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu return TSDB_CODE_SUCCESS; } +int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + if (inputNum!= 3) { + return TSDB_CODE_FAILED; + } + + int16_t inputType = pInput[0].columnData->info.type; + int16_t outputType = *(int16_t *)pInput[1].columnData->pData; + if (outputType != TSDB_DATA_TYPE_BIGINT && outputType != TSDB_DATA_TYPE_UBIGINT && + outputType != TSDB_DATA_TYPE_VARCHAR && outputType != TSDB_DATA_TYPE_NCHAR && + outputType != TSDB_DATA_TYPE_TIMESTAMP) { + return TSDB_CODE_FAILED; + } + int64_t outputLen = *(int64_t *)pInput[2].columnData->pData; + + char *input = NULL; + char *outputBuf = taosMemoryCalloc(outputLen * pInput[0].numOfRows, 1); + char *output = outputBuf; + if (IS_VAR_DATA_TYPE(inputType)) { + input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0]; + } else { + input = pInput[0].columnData->pData; + } + + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + switch(outputType) { + case TSDB_DATA_TYPE_BIGINT: { + if (inputType == TSDB_DATA_TYPE_BINARY) { + memcpy(output, varDataVal(input), varDataLen(input)); + *(int64_t *)output = strtoll(output, NULL, 10); + } else if (inputType == TSDB_DATA_TYPE_NCHAR) { + char *newBuf = taosMemoryCalloc(1, outputLen * TSDB_NCHAR_SIZE + 1); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf); + if (len < 0) { + taosMemoryFree(newBuf); + return TSDB_CODE_FAILED; + } + newBuf[len] = 0; + *(int64_t *)output = strtoll(newBuf, NULL, 10); + taosMemoryFree(newBuf); + } else { + GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input); + } + break; + } + case TSDB_DATA_TYPE_UBIGINT: { + if (inputType == TSDB_DATA_TYPE_BINARY) { + memcpy(output, varDataVal(input), varDataLen(input)); + *(uint64_t *)output = strtoull(output, NULL, 10); + } else if (inputType == TSDB_DATA_TYPE_NCHAR) { + char *newBuf = taosMemoryCalloc(1, outputLen * TSDB_NCHAR_SIZE + 1); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf); + if (len < 0) { + taosMemoryFree(newBuf); + return TSDB_CODE_FAILED; + } + newBuf[len] = 0; + *(uint64_t *)output = strtoull(newBuf, NULL, 10); + taosMemoryFree(newBuf); + } else { + GET_TYPED_DATA(*(uint64_t *)output, uint64_t, inputType, input); + } + break; + } + case TSDB_DATA_TYPE_TIMESTAMP: { + if (inputType == TSDB_DATA_TYPE_BINARY || inputType == TSDB_DATA_TYPE_NCHAR) { + //not support + return TSDB_CODE_FAILED; + } else { + GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input); + } + break; + } + case TSDB_DATA_TYPE_BINARY: { + if (inputType == TSDB_DATA_TYPE_BOOL) { + int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), *(int8_t *)input ? "true" : "false"); + varDataSetLen(output, len); + } else if (inputType == TSDB_DATA_TYPE_BINARY) { + int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), varDataVal(input)); + varDataSetLen(output, len); + } else if (inputType == TSDB_DATA_TYPE_BINARY || inputType == TSDB_DATA_TYPE_NCHAR) { + //not support + return TSDB_CODE_FAILED; + } else { + char tmp[400] = {0}; + NUM_TO_STRING(inputType, input, sizeof(tmp), tmp); + int32_t len = (int32_t)strlen(tmp); + len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE); + memcpy(varDataVal(output), tmp, len); + varDataSetLen(output, len); + } + break; + } + case TSDB_DATA_TYPE_NCHAR: { + int32_t outputCharLen = (outputLen - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; + if (inputType == TSDB_DATA_TYPE_BOOL) { + char tmp[8] = {0}; + int32_t len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false" ); + bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); + if (!ret) { + return TSDB_CODE_FAILED; + } + varDataSetLen(output, len); + } else if (inputType == TSDB_DATA_TYPE_BINARY) { + int32_t len = outputCharLen > varDataLen(input) ? varDataLen(input) : outputCharLen; + bool ret = taosMbsToUcs4(input + VARSTR_HEADER_SIZE, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); + if (!ret) { + return TSDB_CODE_FAILED; + } + varDataSetLen(output, len); + } else if (inputType == TSDB_DATA_TYPE_NCHAR) { + int32_t len = MIN(outputLen, varDataLen(input) + VARSTR_HEADER_SIZE); + memcpy(output, input, len); + varDataSetLen(output, len - VARSTR_HEADER_SIZE); + } else { + char tmp[400] = {0}; + NUM_TO_STRING(inputType, input, sizeof(tmp), tmp); + int32_t len = (int32_t)strlen(tmp); + len = outputCharLen > len ? len : outputCharLen; + bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); + if (!ret) { + return TSDB_CODE_FAILED; + } + varDataSetLen(output, len); + } + break; + } + default: { + return TSDB_CODE_FAILED; + } + } + + colDataAppend(pOutput->columnData, i, output, false); + if (IS_VAR_DATA_TYPE(inputType)) { + input += varDataTLen(input); + } else { + input += tDataTypes[inputType].bytes; + } + if (IS_VAR_DATA_TYPE(outputType)) { + output += varDataTLen(output); + } else { + output += tDataTypes[outputType].bytes; + } + } + + pOutput->numOfRows = pInput->numOfRows; + taosMemoryFree(outputBuf); + return TSDB_CODE_SUCCESS; +} + +int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + int32_t type = GET_PARAM_TYPE(pInput); + if (type != TSDB_DATA_TYPE_BIGINT && type != TSDB_DATA_TYPE_TIMESTAMP) { + return TSDB_CODE_FAILED; + } + + if (inputNum != 1) { + return TSDB_CODE_FAILED; + } + + char *input = pInput[0].columnData->pData; + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + char fraction[20] = {0}; + bool hasFraction = false; + NUM_TO_STRING(type, input, sizeof(fraction), fraction); + int32_t tsDigits = (int32_t)strlen(fraction); + + char buf[64] = {0}; + int64_t timeVal; + GET_TYPED_DATA(timeVal, int64_t, type, input); + if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) { + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / (1000 * 1000); + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / (1000 * 1000 * 1000); + } else { + assert(0); + } + hasFraction = true; + memmove(fraction, fraction + TSDB_TIME_PRECISION_SEC_DIGITS, TSDB_TIME_PRECISION_SEC_DIGITS); + } + + struct tm *tmInfo = localtime((const time_t *)&timeVal); + strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", tmInfo); + int32_t len = (int32_t)strlen(buf); + + if (hasFraction) { + int32_t fracLen = (int32_t)strlen(fraction) + 1; + char *tzInfo = strchr(buf, '+'); + if (tzInfo) { + memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + } else { + tzInfo = strchr(buf, '-'); + memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + } + + char tmp[32]; + sprintf(tmp, ".%s", fraction); + memcpy(tzInfo, tmp, fracLen); + len += fracLen; + } + + memmove(buf + VARSTR_HEADER_SIZE, buf, len); + varDataSetLen(buf, len); + + colDataAppend(pOutput->columnData, i, buf, false); + input += tDataTypes[type].bytes; + } + + pOutput->numOfRows = pInput->numOfRows; + + return TSDB_CODE_SUCCESS; +} + +int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + int32_t type = GET_PARAM_TYPE(pInput); + int32_t timePrec = GET_PARAM_PRECISON(pInput); + if (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR) { + return TSDB_CODE_FAILED; + } + + if (inputNum != 1) { + return TSDB_CODE_FAILED; + } + + char *input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0]; + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + int64_t timeVal = 0; + convertStringToTimestamp(type, input, timePrec, &timeVal); + + colDataAppend(pOutput->columnData, i, (char *)&timeVal, false); + input += varDataTLen(input); + } + + pOutput->numOfRows = pInput->numOfRows; + + return TSDB_CODE_SUCCESS; +} + +int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + int32_t type = GET_PARAM_TYPE(&pInput[0]); + int32_t timePrec = GET_PARAM_PRECISON(&pInput[0]); + if (inputNum != 2) { + return TSDB_CODE_FAILED; + } + + if (type != TSDB_DATA_TYPE_BIGINT && type != TSDB_DATA_TYPE_TIMESTAMP && + type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR) { + return TSDB_CODE_FAILED; + } + + if (GET_PARAM_TYPE(&pInput[1]) != TSDB_DATA_TYPE_BIGINT) { //time_unit + return TSDB_CODE_FAILED; + } + + int64_t timeUnit, timeVal = 0; + GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData); + + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); + + char *input = NULL; + if (IS_VAR_DATA_TYPE(type)) { + input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0]; + } else { + input = pInput[0].columnData->pData; + } + + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + if (IS_VAR_DATA_TYPE(type)) { /* datetime format strings */ + convertStringToTimestamp(type, input, TSDB_TIME_PRECISION_NANO, &timeVal); + //If converted value is less than 10digits in second, use value in second instead + int64_t timeValSec = timeVal / 1000000000; + if (timeValSec < 1000000000) { + timeVal = timeValSec; + } + } else if (type == TSDB_DATA_TYPE_BIGINT) { /* unix timestamp */ + GET_TYPED_DATA(timeVal, int64_t, type, input); + } else if (type == TSDB_DATA_TYPE_TIMESTAMP) { /* timestamp column*/ + GET_TYPED_DATA(timeVal, int64_t, type, input); + int64_t timeValSec = timeVal / factor; + if (timeValSec < 1000000000) { + timeVal = timeValSec; + } + } + + char buf[20] = {0}; + NUM_TO_STRING(TSDB_DATA_TYPE_BIGINT, &timeVal, sizeof(buf), buf); + int32_t tsDigits = (int32_t)strlen(buf); + timeUnit = timeUnit * 1000 / factor; + + switch (timeUnit) { + case 0: { /* 1u */ + if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000 * 1000; + //} else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + // //timeVal = timeVal / 1000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor; + } else { + timeVal = timeVal * 1; + } + break; + } + case 1: { /* 1a */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal * 1; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000 * 1000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS){ + timeVal = timeVal * factor; + } else { + assert(0); + } + break; + } + case 1000: { /* 1s */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor; + } else { + assert(0); + } + break; + } + case 60000: { /* 1m */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 / 60 * 60 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 / 60 * 60 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 / 60 * 60 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor / factor / 60 * 60 * factor; + } else { + assert(0); + } + break; + } + case 3600000: { /* 1h */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 / 3600 * 3600 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 / 3600 * 3600 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 / 3600 * 3600 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor / factor / 3600 * 3600 * factor; + } else { + assert(0); + } + break; + } + case 86400000: { /* 1d */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 / 86400 * 86400 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 / 86400 * 86400 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 / 86400 * 86400 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor / factor / 86400* 86400 * factor; + } else { + assert(0); + } + break; + } + case 604800000: { /* 1w */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 / 604800 * 604800 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 / 604800 * 604800 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 / 604800 * 604800 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor / factor / 604800 * 604800* factor; + } else { + assert(0); + } + break; + } + default: { + timeVal = timeVal * 1; + break; + } + } + + //truncate the timestamp to db precision + switch (timePrec) { + case TSDB_TIME_PRECISION_MILLI: { + if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000; + } + break; + } + case TSDB_TIME_PRECISION_MICRO: { + if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal * 1000; + } + break; + } + case TSDB_TIME_PRECISION_NANO: { + if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal * 1000000; + } + break; + } + } + + colDataAppend(pOutput->columnData, i, (char *)&timeVal, false); + if (IS_VAR_DATA_TYPE(type)) { + input += varDataTLen(input); + } else { + input += tDataTypes[type].bytes; + } + } + + pOutput->numOfRows = pInput->numOfRows; + + return TSDB_CODE_SUCCESS; +} int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { return doScalarFunctionUnique(pInput, inputNum, pOutput, atan); diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index b4058b3c0e..a955fb3b0a 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -76,6 +76,47 @@ int32_t taosMkDir(const char *dirname) { return code; } +int32_t taosMulMkDir(const char *dirname) { + if (dirname == NULL) return -1; + char *temp = strdup(dirname); + char *pos = temp; + int32_t code = 0; + + if (strncmp(temp, "/", 1) == 0) { + pos += 1; + } else if (strncmp(temp, "./", 2) == 0) { + pos += 2; + } + + for ( ; *pos != '\0'; pos++) { + if (*pos == '/') { + *pos = '\0'; + code = mkdir(temp, 0755); + if (code < 0 && errno != EEXIST) { + free(temp); + return code; + } + *pos = '/'; + } + } + + if (*(pos - 1) != '/') { + code = mkdir(temp, 0755); + if (code < 0 && errno != EEXIST) { + free(temp); + return code; + } + } + free(temp); + + // int32_t code = mkdir(dirname, 0755); + if (code < 0 && errno == EEXIST) { + return 0; + } + + return code; +} + void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { DIR *dir = opendir(dirname); if (dir == NULL) return; diff --git a/tests/script/tmp/back.sim b/tests/script/tmp/back.sim new file mode 100644 index 0000000000..9202e90594 --- /dev/null +++ b/tests/script/tmp/back.sim @@ -0,0 +1,6 @@ +sql connect +$x = 1 +begin: + sql insert into db.tb values(now, $x ) -x begin + $x = $x + 1 +goto begin diff --git a/tests/script/tmp/data.sim b/tests/script/tmp/data.sim new file mode 100644 index 0000000000..faac5b2828 --- /dev/null +++ b/tests/script/tmp/data.sim @@ -0,0 +1,14 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +sql create database db +sql create table db.tb (ts timestamp, i int) +sql insert into db.tb values(now, 1) + +print ======== start back +run_back tmp/back.sim + +sleep 2000 +return -1 diff --git a/tests/script/tsim/query/complex_group.sim b/tests/script/tsim/query/complex_group.sim index 3a1ec523fe..d6ce26b69a 100644 --- a/tests/script/tsim/query/complex_group.sim +++ b/tests/script/tsim/query/complex_group.sim @@ -97,167 +97,167 @@ print ================ query 1 group by filter sql select count(*) from ct3 group by c1 print ====> sql : select count(*) from ct3 group by c1 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c2 print ====> sql : select count(*) from ct3 group by c2 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c3 print ====> sql : select count(*) from ct3 group by c3 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c4 print ====> sql : select count(*) from ct3 group by c4 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c5 print ====> sql : select count(*) from ct3 group by c5 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c6 print ====> sql : select count(*) from ct3 group by c6 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c7 print ====> sql : select count(*) from ct3 group by c7 print ====> rows: $rows -if $rows != 2 then +if $rows != 3 then return -1 endi sql select count(*) from ct3 group by c8 print ====> sql : select count(*) from ct3 group by c8 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c9 print ====> sql : select count(*) from ct3 group by c9 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c10 print ====> sql : select count(*) from ct3 group by c10 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi print ================ query 2 complex with group by sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 @@ -307,170 +307,170 @@ print ================ query 1 group by filter sql select count(*) from ct3 group by c1 print ====> sql : select count(*) from ct3 group by c1 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c2 print ====> sql : select count(*) from ct3 group by c2 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c3 print ====> sql : select count(*) from ct3 group by c3 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c4 print ====> sql : select count(*) from ct3 group by c4 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c5 print ====> sql : select count(*) from ct3 group by c5 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c6 print ====> sql : select count(*) from ct3 group by c6 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c7 print ====> sql : select count(*) from ct3 group by c7 print ====> rows: $rows -if $rows != 2 then +if $rows != 3 then return -1 endi sql select count(*) from ct3 group by c8 print ====> sql : select count(*) from ct3 group by c8 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c9 print ====> sql : select count(*) from ct3 group by c9 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi sql select count(*) from ct3 group by c10 print ====> sql : select count(*) from ct3 group by c10 print ====> rows: $rows -if $rows != 8 then +if $rows != 9 then return -1 endi print ================ query 2 complex with group by sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 -print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +sql select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_having.sim b/tests/script/tsim/query/complex_having.sim new file mode 100644 index 0000000000..10283153d8 --- /dev/null +++ b/tests/script/tsim/query/complex_having.sim @@ -0,0 +1,386 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 2 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2019-01-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct4 values ( '2019-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2019-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2020-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2020-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2020-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2020-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct4 values ( '2021-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2021-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2021-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-02-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) +sql insert into ct4 values ( '2022-05-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + + +print ================ start query ====================== + +print ================ query 1 having condition +sql select c1 from ct1 group by c1 having count(c1) +sql select c1 from ct4 group by c1 having count(c1) +sql select count(c1) from ct1 group by c1 having count(c1) + +sql select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> sql : select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select sum(c1) ,count(c7) from ct4 group by c7 having count(c1) < sum(c1) ; +print ====> sql : select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 2 and sum(c1) > 2 ; +print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 2 and sum(c1) > 2 ; +print ====> rows: $rows +if $rows != 7 then + return -1 +endi + +sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; +print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; +print ====> rows: $rows +if $rows != 7 then + return -1 +endi + + +print ================ query 1 complex with having condition + +sql select count(c1) from ct4 where c1 > 2 group by c7 having count(c1) > 1 limit 1 offset 0 +print ====> sql : select count(c1) from ct4 where c1 > 2 group by c7 having count(c1) > 1 limit 1 offset 0 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select round(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 20 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 20 then + return -1 +endi + +print ================ query 1 having condition +sql select c1 from ct1 group by c1 having count(c1) +sql select c1 from ct4 group by c1 having count(c1) +sql select count(c1) from ct1 group by c1 having count(c1) + +sql select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> sql : select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select sum(c1) ,count(c7) from ct4 group by c7 having count(c1) < sum(c1) ; +print ====> sql : select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 2 and sum(c1) > 2 ; +print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 2 and sum(c1) > 2 ; +print ====> rows: $rows +if $rows != 7 then + return -1 +endi + +sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; +print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; +print ====> rows: $rows +if $rows != 7 then + return -1 +endi + + +print ================ query 1 complex with having condition + +sql select count(c1) from ct4 where c1 > 2 group by c7 having count(c1) > 1 limit 1 offset 0 +print ====> sql : select count(c1) from ct4 where c1 > 2 group by c7 having count(c1) > 1 limit 1 offset 0 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select round(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_where.sim b/tests/script/tsim/query/complex_where.sim index 7a5de85a3c..312c1d98ed 100644 --- a/tests/script/tsim/query/complex_where.sim +++ b/tests/script/tsim/query/complex_where.sim @@ -192,14 +192,14 @@ if $data01 != 1 then return -1 endi -sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +sql select c1 from stb1 where c1 > 5 and c1 <= 6 print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 print ====> rows: $rows print ====> rows0: $data00 -if $rows != 4 then +if $rows != 3 then return -1 endi -if $data01 != 6 then +if $data00 != 6 then return -1 endi @@ -210,7 +210,7 @@ print ====> rows0: $data00 if $rows != 32 then return -1 endi -if $data01 != 1 then +if $data00 != 1 then return -1 endi @@ -221,7 +221,7 @@ print ====> rows0: $data00 if $rows != 17 then return -1 endi -if $data01 != 5 then +if $data00 != 5 then return -1 endi @@ -240,7 +240,7 @@ if $rows != 12 then return -1 endi -sql_error select c1 from stb1 where c7 between false and true +sql select c1 from stb1 where c7 between false and true sql select c1 from stb1 where c1 in (1,2,3) print ====> sql : select c1 from stb1 where c1 in (1,2,3) @@ -272,98 +272,98 @@ endi print ================ query 2 complex with where -sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select count(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then @@ -510,14 +510,14 @@ if $data01 != 1 then return -1 endi -sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +sql select c1 from stb1 where c1 > 5 and c1 <= 6 print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 print ====> rows: $rows print ====> rows0: $data00 -if $rows != 4 then +if $rows != 3 then return -1 endi -if $data01 != 6 then +if $data00 != 6 then return -1 endi @@ -528,7 +528,7 @@ print ====> rows0: $data00 if $rows != 32 then return -1 endi -if $data01 != 1 then +if $data00 != 1 then return -1 endi @@ -539,7 +539,7 @@ print ====> rows0: $data00 if $rows != 17 then return -1 endi -if $data01 != 5 then +if $data00 != 5 then return -1 endi @@ -558,7 +558,7 @@ if $rows != 12 then return -1 endi -sql_error select c1 from stb1 where c7 between false and true +sql select c1 from stb1 where c7 between false and true sql select c1 from stb1 where c1 in (1,2,3) print ====> sql : select c1 from stb1 where c1 in (1,2,3) @@ -590,98 +590,98 @@ endi print ================ query 2 complex with where -sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select count(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then return -1 endi -sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +sql select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 print ====> rows: $rows if $rows != 1 then diff --git a/tests/script/tsim/query/diff.sim b/tests/script/tsim/query/diff.sim index ebbd470944..c55b080e44 100644 --- a/tests/script/tsim/query/diff.sim +++ b/tests/script/tsim/query/diff.sim @@ -63,20 +63,21 @@ print =============== step2 $i = 1 $tb = $tbPrefix . $i -print ===> select diff(tbcol) from $tb -sql select diff(tbcol) from $tb +print ===> select _rowts, diff(tbcol) from $tb +sql select _rowts, diff(tbcol) from $tb print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 print ===> $data10 $data11 $data12 $data13 $data14 $data15 -if $data11 != 1 then +if $data11 != 1 then + print expect 1, actual: $data11 return -1 endi print =============== step3 $cc = 4 * 60000 $ms = 1601481600000 + $cc -print ===> select diff(tbcol) from $tb where ts > $ms -sql select diff(tbcol) from $tb where ts > $ms +print ===> select _rowts, diff(tbcol) from $tb where ts > $ms +sql select _rowts, diff(tbcol) from $tb where ts > $ms print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 print ===> $data10 $data11 $data12 $data13 $data14 $data15 @@ -86,8 +87,8 @@ endi $cc = 4 * 60000 $ms = 1601481600000 + $cc -print ===> select diff(tbcol) from $tb where ts <= $ms -sql select diff(tbcol) from $tb where ts <= $ms +print ===> select _rowts, diff(tbcol) from $tb where ts <= $ms +sql select _rowts, diff(tbcol) from $tb where ts <= $ms print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 print ===> $data10 $data11 $data12 $data13 $data14 $data15 @@ -96,8 +97,8 @@ if $data11 != 1 then endi print =============== step4 -print ===> select diff(tbcol) as b from $tb -sql select diff(tbcol) as b from $tb +print ===> select _rowts, diff(tbcol) as b from $tb +sql select _rowts, diff(tbcol) as b from $tb print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 print ===> $data10 $data11 $data12 $data13 $data14 $data15 @@ -105,24 +106,24 @@ if $data11 != 1 then return -1 endi -print =============== step5 -print ===> select diff(tbcol) as b from $tb interval(1m) -sql select diff(tbcol) as b from $tb interval(1m) -x step5 - return -1 -step5: - -print =============== step6 -$cc = 4 * 60000 -$ms = 1601481600000 + $cc -print ===> select diff(tbcol) as b from $tb where ts <= $ms interval(1m) -sql select diff(tbcol) as b from $tb where ts <= $ms interval(1m) -x step6 - return -1 +#print =============== step5 +#print ===> select diff(tbcol) as b from $tb interval(1m) +#sql select diff(tbcol) as b from $tb interval(1m) -x step5 +# return -1 +#step5: +# +#print =============== step6 +#$cc = 4 * 60000 +#$ms = 1601481600000 + $cc +#print ===> select diff(tbcol) as b from $tb where ts <= $ms interval(1m) +#sql select diff(tbcol) as b from $tb where ts <= $ms interval(1m) -x step6 +# return -1 step6: print =============== clear sql drop database $db sql show databases -if $rows != 0 then +if $rows != 1 then return -1 endi diff --git a/tests/script/tsim/tmq/insertDataV1.sim b/tests/script/tsim/tmq/insertDataV1.sim index e8ca028269..a349c55dbd 100644 --- a/tests/script/tsim/tmq/insertDataV1.sim +++ b/tests/script/tsim/tmq/insertDataV1.sim @@ -4,13 +4,18 @@ sql connect print ================ insert data $dbNamme = d0 $tbPrefix = ct -$tbNum = 2 +$tbNum = 10 $rowNum = 100 $tstart = 1640966400000 # 2022-01-01 00:00:00.000 sql use $dbNamme +$loop_cnt = 0 + loop_insert: +print ====> loop $loop_cnt insert +$loop_cnt = $loop_cnt + 1 + $i = 0 while $i < $tbNum $tb = $tbPrefix . $i @@ -32,9 +37,11 @@ while $i < $tbNum $tstart = $tstart + 1 $x = $x + 1 endw + + #print ====> insert rows: $rowNum into $tb and ntb $i = $i + 1 - $tstart = 1640966400000 +# $tstart = 1640966400000 endw goto loop_insert diff --git a/tests/script/tsim/tmq/insertDataV4.sim b/tests/script/tsim/tmq/insertDataV4.sim index 9727d10a69..72c1358e7f 100644 --- a/tests/script/tsim/tmq/insertDataV4.sim +++ b/tests/script/tsim/tmq/insertDataV4.sim @@ -4,13 +4,18 @@ sql connect print ================ insert data $dbNamme = d1 $tbPrefix = ct -$tbNum = 2 +$tbNum = 10 $rowNum = 100 $tstart = 1640966400000 # 2022-01-01 00:00:00.000 sql use $dbNamme +$loop_cnt = 0 + loop_insert: +print ====> loop $loop_cnt insert +$loop_cnt = $loop_cnt + 1 + $i = 0 while $i < $tbNum $tb = $tbPrefix . $i @@ -32,9 +37,11 @@ while $i < $tbNum $tstart = $tstart + 1 $x = $x + 1 endw + + #print ====> insert rows: $rowNum into $tb and ntb $i = $i + 1 - $tstart = 1640966400000 +# $tstart = 1640966400000 endw goto loop_insert diff --git a/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim b/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim new file mode 100644 index 0000000000..0df7a8ba57 --- /dev/null +++ b/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim @@ -0,0 +1,234 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=1, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=1, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene2 and scene4 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 1 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 +print $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29 + +if $loop_cnt == 0 then + if $rows != 2 then + return -1 + endi + if $data02 != 1 then # vgroups + print vgroups: $data02 + return -1 + endi +else + if $rows != 3 then + return -1 + endi + if $data00 == d1 then + if $data02 != 4 then # vgroups + print vgroups: $data02 + return -1 + endi + else + if $data12 != 4 then # vgroups + print vgroups: $data12 + return -1 + endi + endi +endi + +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create multi topics. notes: now only support: +print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. function from stb/ctb/ntb +print =============== will support: * from stb + +sql create topic topic_stb_column as select ts, c1, c3 from stb +#sql create topic topic_stb_all as select * from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +sql create topic topic_ntb_column as select ts, c1, c3 from ntb +sql create topic topic_ntb_all as select * from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== run_back insert data + +if $loop_cnt == 0 then + run_back tsim/tmq/insertDataV1.sim +else + run_back tsim/tmq/insertDataV4.sim +endi + +#sleep 1000 + +#$rowNum = 1000 +#$tstart = 1640966400000 # 2022-01-01 00:00:00.000 +# +#$i = 0 +#while $i < $tbNum +# $tb = $tbPrefix . $i +# +# $x = 0 +# while $x < $rowNum +# $c = $x / 10 +# $c = $c * 10 +# $c = $x - $c +# +# $binary = ' . binary +# $binary = $binary . $c +# $binary = $binary . ' +# +# sql insert into $tb values ($tstart , $c , $x , $binary ) +# sql insert into ntb values ($tstart , $c , $x , $binary ) +# $tstart = $tstart + 1 +# $x = $x + 1 +# endw +# +# $i = $i + 1 +# $tstart = 1640966400000 +#endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$consumeDelay = 50 +$consumeMsgCntFromTopic = 1000 +print consumeMsgCntFromTopic: $consumeMsgCntFromTopic , consumeDelay: $consumeDelay + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +$numOfTopics = 2 +$expectConsumeMsgCnt = $consumeMsgCntFromTopic * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectConsumeMsgCnt +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function, topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function, topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt +print cmd result----> $system_content +#if $system_content != @{consume success: 20000, 0}@ then +if $system_content < $expect_result then + return -1 +endi + +$numOfTopics = 3 +$expectConsumeMsgCnt = $consumeMsgCntFromTopic * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectConsumeMsgCnt +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt +print cmd result----> $system_content +#if $system_content != @{consume success: 300, 0}@ then +if $system_content < $expectConsumeMsgCnt then + return -1 +endi + +$numOfTopics = 3 +$expectConsumeMsgCnt = $consumeMsgCntFromTopic * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectConsumeMsgCnt +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_all, topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_all, topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt +print cmd result----> $system_content +#if $system_content != @{consume success: 30000, 0}@ then +if $system_content < $expectConsumeMsgCnt then + return -1 +endi + +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/consumerMain.sim b/tests/script/tsim/tmq/mainConsumerInOneTopic.sim similarity index 94% rename from tests/script/tsim/tmq/consumerMain.sim rename to tests/script/tsim/tmq/mainConsumerInOneTopic.sim index 51b90971fd..b9a867921e 100644 --- a/tests/script/tsim/tmq/consumerMain.sim +++ b/tests/script/tsim/tmq/mainConsumerInOneTopic.sim @@ -84,7 +84,7 @@ endi print =============== create child table $tbPrefix = ct -$tbNum = 2 +$tbNum = 100 $i = 0 while $i < $tbNum @@ -113,7 +113,7 @@ sql create topic topic_ntb_all as select * from ntb sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb sql show tables -if $rows != 3 then +if $rows != 101 then return -1 endi @@ -125,7 +125,7 @@ else run_back tsim/tmq/insertDataV4.sim endi -sleep 1000 +#sleep 1000 #$rowNum = 1000 #$tstart = 1640966400000 # 2022-01-01 00:00:00.000 @@ -162,9 +162,9 @@ sleep 1000 # -g showMsgFlag, default is 0 # -$consumeDelay = 5000 +$consumeDelay = 50 $expectConsumeMsgCnt = 1000 -print expectConsumeMsgCnt: $expectConsumeMsgCnt, consumeDelay: $consumeDelay +print expectConsumeMsgCnt: $expectConsumeMsgCnt , consumeDelay: $consumeDelay # supported key: # group.id: @@ -184,7 +184,7 @@ print expect_result----> $expect_result print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt print cmd result----> $system_content -if $system_content >= $expect_result then +if $system_content < $expectConsumeMsgCnt then return -1 endi @@ -192,7 +192,7 @@ endi #system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt #print cmd result----> $system_content ##if $system_content != @{consume success: 10000, 0}@ then -#if $system_content != $expect_result then +#if $system_content < $expectConsumeMsgCnt then # return -1 #endi @@ -200,7 +200,7 @@ print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/ system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt print cmd result----> $system_content #if $system_content != @{consume success: 10000, 0}@ then -if $system_content >= $expect_result then +if $system_content < $expectConsumeMsgCnt then return -1 endi @@ -212,21 +212,21 @@ print expect_result----> $expect_result print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt print cmd result----> $system_content -if $system_content >= $expect_result then +if $system_content < $expectConsumeMsgCnt then return -1 endi print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt print cmd result----> $system_content -if $system_content >= $expect_result then +if $system_content < $expectConsumeMsgCnt then return -1 endi print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt print cmd result----> $system_content -if $system_content >= $expect_result then +if $system_content < $expectConsumeMsgCnt then return -1 endi @@ -238,21 +238,21 @@ print expect_result----> $expect_result print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt print cmd result----> $system_content -if $system_content >= $expect_result then +if $system_content < $expectConsumeMsgCnt then return -1 endi print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt print cmd result----> $system_content -if $system_content >= $expect_result then +if $system_content < $expectConsumeMsgCnt then return -1 endi print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt print cmd result----> $system_content -if $system_content >= $expect_result then +if $system_content < $expectConsumeMsgCnt then return -1 endi @@ -263,5 +263,4 @@ if $loop_cnt == 0 then goto loop_vgroups endi - #system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index eb5fb68264..5bbcceada5 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -80,24 +80,24 @@ SScript *simProcessCallOver(SScript *script) { simExecSuccess = false; simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX "failed" FAILED_POSTFIX ", error:%s", script->fileName, script->error); - return NULL; } else { simExecSuccess = true; simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX "success" SUCCESS_POSTFIX, script->fileName); - simCloseTaosdConnect(script); - simScriptSucced++; - simScriptPos--; - - simFreeScript(script); - if (simScriptPos == -1) { - simInfo("----------------------------------------------------------------------"); - simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced); - return NULL; - } - - return simScriptList[simScriptPos]; } + + simCloseTaosdConnect(script); + simScriptSucced++; + simScriptPos--; + simFreeScript(script); + + if (simScriptPos == -1 && simExecSuccess) { + simInfo("----------------------------------------------------------------------"); + simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced); + return NULL; + } + + return simScriptList[simScriptPos]; } else { simDebug("script:%s, is stopped", script->fileName); simFreeScript(script); diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 0e611f3794..b89d517ad3 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -26,6 +26,7 @@ #include "tglobal.h" #include "ttypes.h" #include "tutil.h" +#include "tconfig.h" #include #include @@ -90,6 +91,11 @@ TAOS *shellInit(SShellArguments *_args) { _args->user = TSDB_DEFAULT_USER; } + SConfig *pCfg = cfgInit(); + if (NULL == pCfg) return NULL; + + if (0 != taosAddClientLogCfg(pCfg)) return NULL; + // Connect to the database. TAOS *con = NULL; if (_args->auth == NULL) { diff --git a/tools/taos-tools b/tools/taos-tools index 33cdfe4f90..bf6c766986 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit 33cdfe4f90a209f105c1b6091439798a9cde1e93 +Subproject commit bf6c766986c61ff4fc80421fdea682a8fd4b5b32 From 3663c6441db926c71a8efbc963b6af3c23890dc6 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Apr 2022 15:52:14 +0800 Subject: [PATCH 11/19] refact(cluster): node mgmt --- include/dnode/mnode/mnode.h | 1 + source/dnode/mgmt/implement/inc/dmImp.h | 1 + source/dnode/mgmt/implement/src/dmExec.c | 10 +-- source/dnode/mgmt/implement/src/dmObj.c | 22 +++--- source/dnode/mgmt/implement/src/dmTransport.c | 20 +++--- source/dnode/mgmt/interface/inc/dmInt.h | 5 +- source/dnode/mgmt/interface/src/dmFile.c | 68 +++++++------------ source/dnode/mgmt/interface/src/dmInt.c | 6 -- source/dnode/mgmt/mgmt_bnode/src/bmInt.c | 2 +- source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 9 ++- source/dnode/mgmt/mgmt_qnode/src/qmInt.c | 2 +- source/dnode/mgmt/mgmt_snode/src/smInt.c | 2 +- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 2 +- source/dnode/mgmt/mgmt_vnode/src/vmInt.c | 2 +- source/dnode/mnode/impl/src/mnode.c | 3 +- 15 files changed, 72 insertions(+), 83 deletions(-) diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 08ab63e55a..1d5ed1b6d2 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -68,6 +68,7 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); * @param pMnode The mnode object. */ int32_t mndStart(SMnode *pMnode); +void mndStop(SMnode *pMnode); /** * @brief Get mnode monitor info. diff --git a/source/dnode/mgmt/implement/inc/dmImp.h b/source/dnode/mgmt/implement/inc/dmImp.h index 61dd7800b1..52a56305fd 100644 --- a/source/dnode/mgmt/implement/inc/dmImp.h +++ b/source/dnode/mgmt/implement/inc/dmImp.h @@ -29,6 +29,7 @@ void dmCloseNode(SMgmtWrapper *pWrapper); int32_t dmInitTrans(SDnode *pDnode); void dmCleanupTrans(SDnode *pDnode); SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper); +SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper); int32_t dmInitMsgHandle(SDnode *pDnode); void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp); diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c index 376742e825..354e2372a4 100644 --- a/source/dnode/mgmt/implement/src/dmExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -124,7 +124,7 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) { return dmOpenNodeImp(pWrapper); } else if (pDnode->ptype == DND_PROC_PARENT) { if (dmInitNodeProc(pWrapper) != 0) return -1; - if (dmWriteShmFile(pDnode) != 0) return -1; + if (dmWriteShmFile(pWrapper) != 0) return -1; if (dmRunNodeProc(pWrapper) != 0) return -1; } return 0; @@ -226,11 +226,11 @@ static int32_t dmRunInParentProcess(SDnode *pDnode) { pWrapper->required = dmRequireNode(pWrapper); if (!pWrapper->required) continue; if (dmInitNodeProc(pWrapper) != 0) return -1; - } - if (dmWriteShmFile(pDnode) != 0) { - dError("failed to write runtime file since %s", terrstr()); - return -1; + if (dmWriteShmFile(pWrapper) != 0) { + dError("failed to write runtime file since %s", terrstr()); + return -1; + } } for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { diff --git a/source/dnode/mgmt/implement/src/dmObj.c b/source/dnode/mgmt/implement/src/dmObj.c index cbe3b29303..9236a1f24b 100644 --- a/source/dnode/mgmt/implement/src/dmObj.c +++ b/source/dnode/mgmt/implement/src/dmObj.c @@ -72,7 +72,7 @@ static void dmClearVars(SDnode *pDnode) { } SDnode *dmCreate(const SDnodeOpt *pOption) { - dDebug("start to create dnode object"); + dDebug("start to create dnode"); int32_t code = -1; char path[PATH_MAX] = {0}; SDnode *pDnode = NULL; @@ -96,20 +96,25 @@ SDnode *dmCreate(const SDnodeOpt *pOption) { smSetMgmtFp(&pDnode->wrappers[SNODE]); bmSetMgmtFp(&pDnode->wrappers[BNODE]); - for (EDndNodeType n = 0; n < NODE_END; ++n) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; snprintf(path, sizeof(path), "%s%s%s", pDnode->data.dataDir, TD_DIRSEP, pWrapper->name); pWrapper->path = strdup(path); pWrapper->procShm.id = -1; pWrapper->pDnode = pDnode; pWrapper->ntype = n; + pWrapper->procType = DND_PROC_SINGLE; + taosInitRWLatch(&pWrapper->latch); + if (pWrapper->path == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } - pWrapper->procType = DND_PROC_SINGLE; - taosInitRWLatch(&pWrapper->latch); + if (n != DNODE && dmReadShmFile(pWrapper) != 0) { + dError("node:%s, failed to read shm file since %s", pWrapper->name, terrstr()); + goto _OVER; + } } if (dmInitMsgHandle(pDnode) != 0) { @@ -117,13 +122,8 @@ SDnode *dmCreate(const SDnodeOpt *pOption) { goto _OVER; } - if (dmReadShmFile(pDnode) != 0) { - dError("failed to read shm file since %s", terrstr()); - goto _OVER; - } - - SMsgCb msgCb = dmGetMsgcb(&pDnode->wrappers[0]); - tmsgSetDefaultMsgCb(&msgCb); + pDnode->data.msgCb = dmGetMsgcb(&pDnode->wrappers[DNODE]); + tmsgSetDefaultMsgCb(&pDnode->data.msgCb); dInfo("dnode is created, data:%p", pDnode); code = 0; diff --git a/source/dnode/mgmt/implement/src/dmTransport.c b/source/dnode/mgmt/implement/src/dmTransport.c index d746c44262..d5328cb8f6 100644 --- a/source/dnode/mgmt/implement/src/dmTransport.c +++ b/source/dnode/mgmt/implement/src/dmTransport.c @@ -503,15 +503,6 @@ static void dmCleanupServer(SDnode *pDnode) { int32_t dmInitTrans(SDnode *pDnode) { if (dmInitServer(pDnode) != 0) return -1; if (dmInitClient(pDnode) != 0) return -1; - - SMsgCb msgCb = { - .sendReqFp = dmSendReq, - .sendRspFp = dmSendRsp, - .registerBrokenLinkArgFp = dmRegisterBrokenLinkArg, - .releaseHandleFp = dmReleaseHandle, - }; - pDnode->data.msgCb = msgCb; - return 0; } @@ -519,3 +510,14 @@ void dmCleanupTrans(SDnode *pDnode) { dmCleanupServer(pDnode); dmCleanupClient(pDnode); } + +SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) { + SMsgCb msgCb = { + .sendReqFp = dmSendReq, + .sendRspFp = dmSendRsp, + .registerBrokenLinkArgFp = dmRegisterBrokenLinkArg, + .releaseHandleFp = dmReleaseHandle, + .pWrapper = pWrapper, + }; + return msgCb; +} \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dmInt.h b/source/dnode/mgmt/interface/inc/dmInt.h index 9e8ac82195..3c8ecdc71b 100644 --- a/source/dnode/mgmt/interface/inc/dmInt.h +++ b/source/dnode/mgmt/interface/inc/dmInt.h @@ -37,14 +37,13 @@ void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgF void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); void dmGetMonitorSysInfo(SMonSysInfo *pInfo); -SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper); // dmFile.c int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed); TdFilePtr dmCheckRunning(const char *dataDir); -int32_t dmReadShmFile(SDnode *pDnode); -int32_t dmWriteShmFile(SDnode *pDnode); +int32_t dmReadShmFile(SMgmtWrapper *pWrapper); +int32_t dmWriteShmFile(SMgmtWrapper *pWrapper); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/interface/src/dmFile.c b/source/dnode/mgmt/interface/src/dmFile.c index c994357e76..3256b8b4b0 100644 --- a/source/dnode/mgmt/interface/src/dmFile.c +++ b/source/dnode/mgmt/interface/src/dmFile.c @@ -140,18 +140,17 @@ TdFilePtr dmCheckRunning(const char *dataDir) { return pFile; } -int32_t dmReadShmFile(SDnode *pDnode) { +int32_t dmReadShmFile(SMgmtWrapper *pWrapper) { int32_t code = -1; - char itemName[24] = {0}; char content[MAXLEN + 1] = {0}; char file[PATH_MAX] = {0}; cJSON *root = NULL; TdFilePtr pFile = NULL; - snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->data.dataDir, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sshmfile", pWrapper->path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("file %s not exist", file); + dDebug("node:%s, file %s not exist", pWrapper->name, file); code = 0; goto _OVER; } @@ -160,35 +159,27 @@ int32_t dmReadShmFile(SDnode *pDnode) { root = cJSON_Parse(content); if (root == NULL) { terrno = TSDB_CODE_INVALID_JSON_FORMAT; - dError("failed to read %s since invalid json format", file); + dError("node:%s, failed to read %s since invalid json format", pWrapper->name, file); goto _OVER; } - for (EDndNodeType ntype = DNODE + 1; ntype < NODE_END; ++ntype) { - snprintf(itemName, sizeof(itemName), "%s_shmid", dmProcName(ntype)); - cJSON *shmid = cJSON_GetObjectItem(root, itemName); - if (shmid && shmid->type == cJSON_Number) { - pDnode->wrappers[ntype].procShm.id = shmid->valueint; - } + cJSON *shmid = cJSON_GetObjectItem(root, "shmid"); + if (shmid && shmid->type == cJSON_Number) { + pWrapper->procShm.id = shmid->valueint; + } - snprintf(itemName, sizeof(itemName), "%s_shmsize", dmProcName(ntype)); - cJSON *shmsize = cJSON_GetObjectItem(root, itemName); - if (shmsize && shmsize->type == cJSON_Number) { - pDnode->wrappers[ntype].procShm.size = shmsize->valueint; - } + cJSON *shmsize = cJSON_GetObjectItem(root, "shmsize"); + if (shmsize && shmsize->type == cJSON_Number) { + pWrapper->procShm.size = shmsize->valueint; } } - if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_END) { - for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - if (pWrapper->procShm.id >= 0) { - dDebug("shmid:%d, is closed, size:%d", pWrapper->procShm.id, pWrapper->procShm.size); - taosDropShm(&pWrapper->procShm); - } + if (!tsMultiProcess || pWrapper->pDnode->ntype == DNODE || pWrapper->pDnode->ntype == NODE_END) { + if (pWrapper->procShm.id >= 0) { + dDebug("node:%s, shmid:%d, is closed, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size); + taosDropShm(&pWrapper->procShm); } } else { - SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; if (taosAttachShm(&pWrapper->procShm) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); dError("shmid:%d, failed to attach shm since %s", pWrapper->procShm.id, terrstr()); @@ -197,7 +188,7 @@ int32_t dmReadShmFile(SDnode *pDnode) { dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size); } - dDebug("successed to load %s", file); + dDebug("node:%s, successed to load %s", pWrapper->name, file); code = 0; _OVER: @@ -207,7 +198,7 @@ _OVER: return code; } -int32_t dmWriteShmFile(SDnode *pDnode) { +int32_t dmWriteShmFile(SMgmtWrapper *pWrapper) { int32_t code = -1; int32_t len = 0; char content[MAXLEN + 1] = {0}; @@ -215,37 +206,30 @@ int32_t dmWriteShmFile(SDnode *pDnode) { char realfile[PATH_MAX] = {0}; TdFilePtr pFile = NULL; - snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->data.dataDir, TD_DIRSEP); - snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->data.dataDir, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sshmfile.bak", pWrapper->path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%sshmfile", pWrapper->path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to open file:%s since %s", file, terrstr()); + dError("node:%s, failed to open file:%s since %s", pWrapper->name, file, terrstr()); goto _OVER; } len += snprintf(content + len, MAXLEN - len, "{\n"); - for (EDndNodeType ntype = DNODE + 1; ntype < NODE_END; ++ntype) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dmProcName(ntype), pWrapper->procShm.id); - if (ntype == NODE_END - 1) { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dmProcName(ntype), pWrapper->procShm.size); - } else { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dmProcName(ntype), pWrapper->procShm.size); - } - } + len += snprintf(content + len, MAXLEN - len, " \"shmid\":%d,\n", pWrapper->procShm.id); + len += snprintf(content + len, MAXLEN - len, " \"shmsize\":%d\n", pWrapper->procShm.size); len += snprintf(content + len, MAXLEN - len, "}\n"); if (taosWriteFile(pFile, content, len) != len) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to write file:%s since %s", file, terrstr()); + dError("node:%s, failed to write file:%s since %s", pWrapper->name, file, terrstr()); goto _OVER; } if (taosFsyncFile(pFile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to fsync file:%s since %s", file, terrstr()); + dError("node:%s, failed to fsync file:%s since %s", pWrapper->name, file, terrstr()); goto _OVER; } @@ -253,11 +237,11 @@ int32_t dmWriteShmFile(SDnode *pDnode) { if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to rename %s to %s since %s", file, realfile, terrstr()); + dError("node:%s, failed to rename %s to %s since %s", pWrapper->name, file, realfile, terrstr()); return -1; } - dInfo("successed to write %s", realfile); + dInfo("node:%s, successed to write %s", pWrapper->name, realfile); code = 0; _OVER: diff --git a/source/dnode/mgmt/interface/src/dmInt.c b/source/dnode/mgmt/interface/src/dmInt.c index ad5b35a3f8..10599c0043 100644 --- a/source/dnode/mgmt/interface/src/dmInt.c +++ b/source/dnode/mgmt/interface/src/dmInt.c @@ -171,9 +171,3 @@ void dmGetMonitorSysInfo(SMonSysInfo *pInfo) { taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); } - -SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) { - SMsgCb msgCb = pWrapper->pDnode->data.msgCb; - msgCb.pWrapper = pWrapper; - return msgCb; -} \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c index ec261d654c..72a7f2cc86 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c @@ -19,7 +19,7 @@ static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { - SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb;; pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 2d8914df25..9e83c317ea 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -39,7 +39,7 @@ static int32_t mmRequire(SMgmtWrapper *pWrapper, bool *required) { } static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { - SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue; msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue; msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue; @@ -225,11 +225,18 @@ static int32_t mmStart(SMgmtWrapper *pWrapper) { return mndStart(pMgmt->pMnode); } +static void mmStop(SMgmtWrapper *pWrapper) { + dDebug("mnode-mgmt start to stop"); + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mndStop(pMgmt->pMnode); +} + void mmSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = mmOpen; mgmtFp.closeFp = mmClose; mgmtFp.startFp = mmStart; + mgmtFp.stopFp = mmStop; mgmtFp.createFp = mmProcessCreateReq; mgmtFp.dropFp = mmProcessDropReq; mgmtFp.requiredFp = mmRequire; diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c index 76c4f2af0d..53d4cefbff 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c @@ -19,7 +19,7 @@ static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { - SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.queueFps[QUERY_QUEUE] = qmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = qmPutMsgToFetchQueue; msgCb.qsizeFp = qmGetQueueSize; diff --git a/source/dnode/mgmt/mgmt_snode/src/smInt.c b/source/dnode/mgmt/mgmt_snode/src/smInt.c index 911c1b6f70..ad7909a8f7 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smInt.c +++ b/source/dnode/mgmt/mgmt_snode/src/smInt.c @@ -19,7 +19,7 @@ static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { - SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index dfe79c2dde..73397316e0 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -143,7 +143,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return -1; } - SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index d70377e9ad..c4e05c54eb 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -128,7 +128,7 @@ static void *vmOpenVnodeFunc(void *param) { pMgmt->state.openVnodes, pMgmt->state.totalVnodes); dmReportStartup(pDnode, "open-vnodes", stepDesc); - SMsgCb msgCb = dmGetMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 5a1780530c..8b2e77c1dd 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -220,7 +220,6 @@ static int32_t mndInitSteps(SMnode *pMnode, bool deploy) { if (mndAllocStep(pMnode, "mnode-query", mndInitQuery, mndCleanupQuery) != 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; } @@ -346,6 +345,8 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { int32_t mndStart(SMnode *pMnode) { return mndInitTimer(pMnode); } +void mndStop(SMnode *pMnode) { return mndCleanupTimer(pMnode); } + int32_t mndProcessMsg(SNodeMsg *pMsg) { SMnode *pMnode = pMsg->pNode; SRpcMsg *pRpc = &pMsg->rpcMsg; From e770a6e974753f7160054697a8fe89250728ad59 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Apr 2022 16:23:03 +0800 Subject: [PATCH 12/19] refact(cluster): node mgmt --- source/common/src/tglobal.c | 8 ++++---- source/dnode/mgmt/CMakeLists.txt | 9 ++++++++- source/dnode/mgmt/exe/CMakeLists.txt | 7 ------- source/dnode/mgmt/implement/src/dmEps.c | 2 +- source/dnode/mgmt/implement/src/dmExec.c | 2 -- source/dnode/mgmt/implement/src/dmHandle.c | 8 ++++---- source/dnode/mgmt/interface/src/dmFile.c | 4 ++-- source/dnode/mgmt/mgmt_bnode/src/bmInt.c | 3 ++- source/dnode/mgmt/mgmt_mnode/src/mmFile.c | 2 +- source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 1 + source/dnode/mgmt/mgmt_qnode/src/qmInt.c | 1 + source/dnode/mgmt/mgmt_snode/src/smInt.c | 1 + 12 files changed, 25 insertions(+), 23 deletions(-) delete mode 100644 source/dnode/mgmt/exe/CMakeLists.txt diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 58bc7235a1..2ab8af31b1 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -189,7 +189,7 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) { tsDiskCfgNum = 1; taosAddDataDir(0, pItem->str, 0, 1); tstrncpy(tsDataDir, pItem->str, PATH_MAX); - if (taosMkDir(tsDataDir) != 0) { + if (taosMulMkDir(tsDataDir) != 0) { uError("failed to create dataDir:%s since %s", tsDataDir, terrstr()); return -1; } @@ -200,12 +200,12 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) { memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg)); if (pCfg->level == 0 && pCfg->primary == 1) { tstrncpy(tsDataDir, pCfg->dir, PATH_MAX); - if (taosMkDir(tsDataDir) != 0) { + if (taosMulMkDir(tsDataDir) != 0) { uError("failed to create dataDir:%s since %s", tsDataDir, terrstr()); return -1; } } - if (taosMkDir(pCfg->dir) != 0) { + if (taosMulMkDir(pCfg->dir) != 0) { uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr()); return -1; } @@ -486,7 +486,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); taosExpandDir(tsTempDir, tsTempDir, PATH_MAX); tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval; - if (taosMkDir(tsTempDir) != 0) { + if (taosMulMkDir(tsTempDir) != 0) { uError("failed to create tempDir:%s since %s", tsTempDir, terrstr()); return -1; } diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 52761ab646..49ea54e928 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,4 +1,3 @@ -add_subdirectory(exe) add_subdirectory(interface) add_subdirectory(implement) add_subdirectory(mgmt_bnode) @@ -7,3 +6,11 @@ add_subdirectory(mgmt_qnode) add_subdirectory(mgmt_snode) add_subdirectory(mgmt_vnode) add_subdirectory(test) + +aux_source_directory(exe EXEC_SRC) +add_executable(taosd ${EXEC_SRC}) +target_include_directories( + taosd + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" +) +target_link_libraries(taosd dnode) diff --git a/source/dnode/mgmt/exe/CMakeLists.txt b/source/dnode/mgmt/exe/CMakeLists.txt deleted file mode 100644 index 931a07d261..0000000000 --- a/source/dnode/mgmt/exe/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -aux_source_directory(. EXEC_SRC) -add_executable(taosd ${EXEC_SRC}) -target_include_directories( - taosd - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../implement/inc" -) -target_link_libraries(taosd dnode) diff --git a/source/dnode/mgmt/implement/src/dmEps.c b/source/dnode/mgmt/implement/src/dmEps.c index 5dcdccfa4e..e4ff536b5f 100644 --- a/source/dnode/mgmt/implement/src/dmEps.c +++ b/source/dnode/mgmt/implement/src/dmEps.c @@ -57,7 +57,7 @@ int32_t dmReadEps(SDnode *pDnode) { snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->data.path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("file %s not exist", file); + // dDebug("file %s not exist", file); code = 0; goto PRASE_DNODE_OVER; } diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c index 354e2372a4..ad8653edd6 100644 --- a/source/dnode/mgmt/implement/src/dmExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -21,8 +21,6 @@ static bool dmRequireNode(SMgmtWrapper *pWrapper) { int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required); if (!required) { dDebug("node:%s, does not require startup", pWrapper->name); - } else { - dDebug("node:%s, needs to be started", pWrapper->name); } return required; } diff --git a/source/dnode/mgmt/implement/src/dmHandle.c b/source/dnode/mgmt/implement/src/dmHandle.c index 1b0abd8c09..b5c81850ef 100644 --- a/source/dnode/mgmt/implement/src/dmHandle.c +++ b/source/dnode/mgmt/implement/src/dmHandle.c @@ -199,7 +199,7 @@ static void dmStopMgmt(SMgmtWrapper *pWrapper) { } static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) { - dInfo("dnode-data start to init"); + dInfo("dnode-mgmt start to init"); SDnode *pDnode = pWrapper->pDnode; pDnode->data.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); @@ -228,12 +228,12 @@ static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) { return -1; } - dInfo("dnode-data is initialized"); + dInfo("dnode-mgmt is initialized"); return 0; } static void dmCleanupMgmt(SMgmtWrapper *pWrapper) { - dInfo("dnode-data start to clean up"); + dInfo("dnode-mgmt start to clean up"); SDnode *pDnode = pWrapper->pDnode; dmStopWorker(pDnode); @@ -249,7 +249,7 @@ static void dmCleanupMgmt(SMgmtWrapper *pWrapper) { taosWUnLockLatch(&pDnode->data.latch); dmCleanupTrans(pDnode); - dInfo("dnode-data is cleaned up"); + dInfo("dnode-mgmt is cleaned up"); } static int32_t dmRequireMgmt(SMgmtWrapper *pWrapper, bool *required) { diff --git a/source/dnode/mgmt/interface/src/dmFile.c b/source/dnode/mgmt/interface/src/dmFile.c index 3256b8b4b0..e9117939d7 100644 --- a/source/dnode/mgmt/interface/src/dmFile.c +++ b/source/dnode/mgmt/interface/src/dmFile.c @@ -29,7 +29,7 @@ int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("file %s not exist", file); + // dDebug("file %s not exist", file); code = 0; goto _OVER; } @@ -150,7 +150,7 @@ int32_t dmReadShmFile(SMgmtWrapper *pWrapper) { snprintf(file, sizeof(file), "%s%sshmfile", pWrapper->path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("node:%s, file %s not exist", pWrapper->name, file); + // dDebug("node:%s, file %s not exist", pWrapper->name, file); code = 0; goto _OVER; } diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c index 72a7f2cc86..860c5d465c 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c @@ -19,7 +19,8 @@ static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { - SMsgCb msgCb = pMgmt->pDnode->data.msgCb;; + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; + msgCb.pWrapper = pMgmt->pWrapper; pOption->msgCb = msgCb; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 44027780de..f3d0d666bb 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -28,7 +28,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed) { snprintf(file, sizeof(file), "%s%smnode.json", pMgmt->path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("file %s not exist", file); + // dDebug("file %s not exist", file); code = 0; goto PRASE_MNODE_OVER; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 9e83c317ea..ce0459686c 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -40,6 +40,7 @@ static int32_t mmRequire(SMgmtWrapper *pWrapper, bool *required) { static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { SMsgCb msgCb = pMgmt->pDnode->data.msgCb; + msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue; msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue; msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue; diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c index 53d4cefbff..c73d337136 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c @@ -20,6 +20,7 @@ static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmRead static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { SMsgCb msgCb = pMgmt->pDnode->data.msgCb; + msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = qmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = qmPutMsgToFetchQueue; msgCb.qsizeFp = qmGetQueueSize; diff --git a/source/dnode/mgmt/mgmt_snode/src/smInt.c b/source/dnode/mgmt/mgmt_snode/src/smInt.c index ad7909a8f7..3b17d775f7 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smInt.c +++ b/source/dnode/mgmt/mgmt_snode/src/smInt.c @@ -20,6 +20,7 @@ static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dmRead static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { SMsgCb msgCb = pMgmt->pDnode->data.msgCb; + msgCb.pWrapper = pMgmt->pWrapper; pOption->msgCb = msgCb; } From 1dd4984eeb73b2450fd2aab3726ed8607787b71c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Apr 2022 20:08:39 +0800 Subject: [PATCH 13/19] refact(cluster): node mgmt --- source/dnode/mgmt/implement/src/dmEps.c | 6 +++--- source/dnode/mgmt/implement/src/dmExec.c | 6 +++++- source/dnode/mgmt/implement/src/dmObj.c | 4 ++-- source/dnode/mgmt/implement/src/dmTransport.c | 3 ++- source/dnode/mgmt/interface/inc/dmDef.h | 1 - 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/source/dnode/mgmt/implement/src/dmEps.c b/source/dnode/mgmt/implement/src/dmEps.c index e4ff536b5f..6e8ee638dc 100644 --- a/source/dnode/mgmt/implement/src/dmEps.c +++ b/source/dnode/mgmt/implement/src/dmEps.c @@ -54,7 +54,7 @@ int32_t dmReadEps(SDnode *pDnode) { goto PRASE_DNODE_OVER; } - snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->data.path, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->data.dataDir, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { // dDebug("file %s not exist", file); @@ -176,7 +176,7 @@ PRASE_DNODE_OVER: int32_t dmWriteEps(SDnode *pDnode) { char file[PATH_MAX]; - snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->data.path, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->data.dataDir, TD_DIRSEP); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -216,7 +216,7 @@ int32_t dmWriteEps(SDnode *pDnode) { taosMemoryFree(content); char realfile[PATH_MAX]; - snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->data.path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->data.dataDir, TD_DIRSEP); if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c index ad8653edd6..be7a8f0dd2 100644 --- a/source/dnode/mgmt/implement/src/dmExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -130,6 +130,10 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) { static void dmCloseNodeImp(SMgmtWrapper *pWrapper) { dDebug("node:%s, mgmt start to close", pWrapper->name); + if (pWrapper->fp.stopFp != NULL) { + (*pWrapper->fp.stopFp)(pWrapper); + } + pWrapper->required = false; taosWLockLatch(&pWrapper->latch); if (pWrapper->deployed) { @@ -185,7 +189,7 @@ static int32_t dmRunInSingleProcess(SDnode *pDnode) { dmSetStatus(pDnode, DND_STAT_RUNNING); - for (EDndNodeType n = 0; n < NODE_END; ++n) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; if (!pWrapper->required) continue; if (pWrapper->fp.startFp == NULL) continue; diff --git a/source/dnode/mgmt/implement/src/dmObj.c b/source/dnode/mgmt/implement/src/dmObj.c index 9236a1f24b..2a9ea87530 100644 --- a/source/dnode/mgmt/implement/src/dmObj.c +++ b/source/dnode/mgmt/implement/src/dmObj.c @@ -53,7 +53,7 @@ static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { } static void dmClearVars(SDnode *pDnode) { - for (EDndNodeType n = 0; n < NODE_END; ++n) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; taosMemoryFreeClear(pMgmt->path); } @@ -141,7 +141,7 @@ _OVER: void dmClose(SDnode *pDnode) { if (pDnode == NULL) return; - for (EDndNodeType n = 0; n < NODE_END; ++n) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; dmCloseNode(pWrapper); } diff --git a/source/dnode/mgmt/implement/src/dmTransport.c b/source/dnode/mgmt/implement/src/dmTransport.c index d5328cb8f6..8f583d7ea3 100644 --- a/source/dnode/mgmt/implement/src/dmTransport.c +++ b/source/dnode/mgmt/implement/src/dmTransport.c @@ -154,6 +154,7 @@ static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { rpcSendResponse(&rspMsg); } rpcFreeCont(pMsg->pCont); + return; } if (pHandle->pMndWrapper != NULL || pHandle->pQndWrapper != NULL) { @@ -174,7 +175,7 @@ static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { int32_t dmInitMsgHandle(SDnode *pDnode) { SDnodeTrans *pTrans = &pDnode->trans; - for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) { diff --git a/source/dnode/mgmt/interface/inc/dmDef.h b/source/dnode/mgmt/interface/inc/dmDef.h index 8eefb66556..594eb22195 100644 --- a/source/dnode/mgmt/interface/inc/dmDef.h +++ b/source/dnode/mgmt/interface/inc/dmDef.h @@ -119,7 +119,6 @@ typedef struct { SSingleWorker mgmtWorker; SMsgCb msgCb; SDnode *pDnode; - const char *path; TdFilePtr lockfile; char *localEp; char *localFqdn; From 3b54d90350fa5bc2838e861a087be34e347c24a9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 13 Apr 2022 21:00:43 +0800 Subject: [PATCH 14/19] refact(cluster): node mgmt --- include/dnode/mgmt/dnode.h | 2 +- source/dnode/mgmt/implement/src/dmExec.c | 361 +++++++++----------- source/dnode/mgmt/implement/src/dmHandle.c | 10 +- source/dnode/mgmt/implement/src/dmObj.c | 6 - source/dnode/mgmt/mgmt_bnode/inc/bmInt.h | 4 - source/dnode/mgmt/mgmt_bnode/src/bmHandle.c | 22 +- source/dnode/mgmt/mgmt_bnode/src/bmInt.c | 77 ++--- source/dnode/mgmt/mgmt_mnode/inc/mmInt.h | 2 +- source/dnode/mgmt/mgmt_mnode/src/mmFile.c | 35 +- source/dnode/mgmt/mgmt_mnode/src/mmHandle.c | 21 +- source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 20 +- source/dnode/mgmt/mgmt_qnode/inc/qmInt.h | 4 - source/dnode/mgmt/mgmt_qnode/src/qmHandle.c | 22 +- source/dnode/mgmt/mgmt_qnode/src/qmInt.c | 80 ++--- source/dnode/mgmt/mgmt_snode/inc/smInt.h | 4 - source/dnode/mgmt/mgmt_snode/src/smHandle.c | 22 +- source/dnode/mgmt/mgmt_snode/src/smInt.c | 77 +---- 17 files changed, 318 insertions(+), 451 deletions(-) diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index 352f6d5b53..b48fd23204 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -51,7 +51,7 @@ typedef struct { int8_t ntype; } SDnodeOpt; -typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; +typedef enum { DND_EVENT_START = 0, DND_EVENT_STOP = 1, DND_EVENT_CHILD = 2 } EDndEvent; /** * @brief Initialize and start the dnode. diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c index be7a8f0dd2..7c5d049aff 100644 --- a/source/dnode/mgmt/implement/src/dmExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -99,40 +99,78 @@ static int32_t dmRunNodeProc(SMgmtWrapper *pWrapper) { return 0; } -static int32_t dmOpenNodeImp(SMgmtWrapper *pWrapper) { +int32_t dmOpenNode(SMgmtWrapper *pWrapper) { if (taosMkDir(pWrapper->path) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr()); return -1; } - if ((*pWrapper->fp.openFp)(pWrapper) != 0) { - dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); - return -1; - } + if (pWrapper->procType == DND_PROC_SINGLE || pWrapper->procType == DND_PROC_CHILD) { + if ((*pWrapper->fp.openFp)(pWrapper) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + return -1; + } - dDebug("node:%s, has been opened", pWrapper->name); - pWrapper->deployed = true; - return 0; -} - -int32_t dmOpenNode(SMgmtWrapper *pWrapper) { - SDnode *pDnode = pWrapper->pDnode; - if (pDnode->ptype == DND_PROC_SINGLE) { - return dmOpenNodeImp(pWrapper); - } else if (pDnode->ptype == DND_PROC_PARENT) { + dDebug("node:%s, has been opened", pWrapper->name); + pWrapper->deployed = true; + } else { if (dmInitNodeProc(pWrapper) != 0) return -1; if (dmWriteShmFile(pWrapper) != 0) return -1; if (dmRunNodeProc(pWrapper) != 0) return -1; } + + if (pWrapper->procType == DND_PROC_CHILD) { + SProcCfg cfg = dmGenProcCfg(pWrapper); + cfg.isChild = true; + pWrapper->procObj = taosProcInit(&cfg); + if (pWrapper->procObj == NULL) { + dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); + return -1; + } + } + return 0; } -static void dmCloseNodeImp(SMgmtWrapper *pWrapper) { - dDebug("node:%s, mgmt start to close", pWrapper->name); +int32_t dmStartNode(SMgmtWrapper *pWrapper) { + if (pWrapper->procType == DND_PROC_PARENT) { + dInfo("node:%s, not start in parent process", pWrapper->name); + } else if (pWrapper->procType == DND_PROC_CHILD) { + dInfo("node:%s, start in child process", pWrapper->name); + if (taosProcRun(pWrapper->procObj) != 0) { + dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); + return -1; + } + } else { + if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } + + return 0; +} + +void dmStopNode(SMgmtWrapper *pWrapper) { if (pWrapper->fp.stopFp != NULL) { (*pWrapper->fp.stopFp)(pWrapper); } +} + +void dmCloseNode(SMgmtWrapper *pWrapper) { + dInfo("node:%s, start to close", pWrapper->name); + if (pWrapper->procType == DND_PROC_PARENT) { + if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { + dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); + taosKillProc(pWrapper->procId); + dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId); + taosWaitProc(pWrapper->procId); + dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId); + } + } + + dmStopNode(pWrapper); pWrapper->required = false; taosWLockLatch(&pWrapper->latch); @@ -150,20 +188,78 @@ static void dmCloseNodeImp(SMgmtWrapper *pWrapper) { taosProcCleanup(pWrapper->procObj); pWrapper->procObj = NULL; } - dDebug("node:%s, mgmt has been closed", pWrapper->name); + + dInfo("node:%s, has been closed", pWrapper->name); } -void dmCloseNode(SMgmtWrapper *pWrapper) { - if (pWrapper->pDnode->ptype == DND_PROC_PARENT) { - if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { - dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); - taosKillProc(pWrapper->procId); - dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId); - taosWaitProc(pWrapper->procId); - dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId); +static int32_t dmOpenNodes(SDnode *pDnode) { + if (pDnode->ptype == DND_PROC_CHILD) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; + pWrapper->required = dmRequireNode(pWrapper); + if (!pWrapper->required) { + dError("dnode:%s, failed to open since not required", pWrapper->name); + } + + pWrapper->procType = DND_PROC_CHILD; + + SMsgCb msgCb = pDnode->data.msgCb; + msgCb.pWrapper = pWrapper; + tmsgSetDefaultMsgCb(&msgCb); + + if (dmOpenNode(pWrapper) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + return -1; + } + } else { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + pWrapper->required = dmRequireNode(pWrapper); + if (!pWrapper->required) continue; + + if (pDnode->ptype == DND_PROC_PARENT && n != DNODE) { + pWrapper->procType = DND_PROC_PARENT; + } else { + pWrapper->procType = DND_PROC_SINGLE; + } + + if (dmOpenNode(pWrapper) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + return -1; + } } } - dmCloseNodeImp(pWrapper); + + dmSetStatus(pDnode, DND_STAT_RUNNING); + return 0; +} + +static int32_t dmStartNodes(SDnode *pDnode) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (dmStartNode(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } + + dInfo("TDengine initialized successfully"); + dmReportStartup(pDnode, "TDengine", "initialized successfully"); + return 0; +} + +static void dmStopNodes(SDnode *pDnode) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + dmStopNode(pWrapper); + } +} + +static void dmCloseNodes(SDnode *pDnode) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + dmCloseNode(pWrapper); + } } static void dmProcessProcHandle(void *handle) { @@ -172,188 +268,55 @@ static void dmProcessProcHandle(void *handle) { rpcSendResponse(&rpcMsg); } -static int32_t dmRunInSingleProcess(SDnode *pDnode) { - dInfo("dnode run in single process"); - pDnode->ptype = DND_PROC_SINGLE; +static void dmWatchNodes(SDnode *pDnode) { + if (pDnode->ptype == DND_PROC_PARENT) { + for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (pDnode->ntype == NODE_END) continue; - for (EDndNodeType n = DNODE; n < NODE_END; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dmRequireNode(pWrapper); - if (!pWrapper->required) continue; - - if (dmOpenNodeImp(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dmSetStatus(pDnode, DND_STAT_RUNNING); - - for (EDndNodeType n = DNODE; n < NODE_END; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (pWrapper->fp.startFp == NULL) continue; - if ((*pWrapper->fp.startFp)(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dInfo("TDengine initialized successfully"); - dmReportStartup(pDnode, "TDengine", "initialized successfully"); - while (1) { - if (pDnode->event == DND_EVENT_STOP) { - dInfo("dnode is about to stop"); - dmSetStatus(pDnode, DND_STAT_STOPPED); - break; - } - taosMsleep(100); - } - - return 0; -} - -static int32_t dmRunInParentProcess(SDnode *pDnode) { - dInfo("dnode run in parent process"); - pDnode->ptype = DND_PROC_PARENT; - - SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE]; - if (dmOpenNodeImp(pDWrapper) != 0) { - dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); - return -1; - } - - for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dmRequireNode(pWrapper); - if (!pWrapper->required) continue; - if (dmInitNodeProc(pWrapper) != 0) return -1; - - if (dmWriteShmFile(pWrapper) != 0) { - dError("failed to write runtime file since %s", terrstr()); - return -1; - } - } - - for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (dmRunNodeProc(pWrapper) != 0) return -1; - } - - dmSetStatus(pDnode, DND_STAT_RUNNING); - - if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) { - dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); - return -1; - } - - dInfo("TDengine initialized successfully"); - dmReportStartup(pDnode, "TDengine", "initialized successfully"); - - while (1) { - if (pDnode->event == DND_EVENT_STOP) { - dInfo("dnode is about to stop"); - dmSetStatus(pDnode, DND_STAT_STOPPED); - - for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (pDnode->ntype == NODE_END) continue; - - if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { - dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); - taosKillProc(pWrapper->procId); - dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId); - taosWaitProc(pWrapper->procId); - dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId); - } - } - break; - } else { - for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (pDnode->ntype == NODE_END) continue; - - if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { - dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); - taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle); - dmNewNodeProc(pWrapper, n); - } + if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { + dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); + taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle); + dmNewNodeProc(pWrapper, n); } } - - taosMsleep(100); } - - return 0; -} - -static int32_t dmRunInChildProcess(SDnode *pDnode) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; - dInfo("%s run in child process", pWrapper->name); - pDnode->ptype = DND_PROC_CHILD; - - pWrapper->required = dmRequireNode(pWrapper); - if (!pWrapper->required) { - dError("%s does not require startup", pWrapper->name); - return -1; - } - - SMsgCb msgCb = dmGetMsgcb(pWrapper); - tmsgSetDefaultMsgCb(&msgCb); - pWrapper->procType = DND_PROC_CHILD; - - if (dmOpenNodeImp(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - - SProcCfg cfg = dmGenProcCfg(pWrapper); - cfg.isChild = true; - pWrapper->procObj = taosProcInit(&cfg); - if (pWrapper->procObj == NULL) { - dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); - return -1; - } - - if (pWrapper->fp.startFp != NULL) { - if ((*pWrapper->fp.startFp)(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dmSetStatus(pDnode, DND_STAT_RUNNING); - - if (taosProcRun(pWrapper->procObj) != 0) { - dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); - return -1; - } - - dInfo("TDengine initialized successfully"); - dmReportStartup(pDnode, "TDengine", "initialized successfully"); - while (1) { - if (pDnode->event == DND_EVENT_STOP) { - dInfo("%s is about to stop", pWrapper->name); - dmSetStatus(pDnode, DND_STAT_STOPPED); - break; - } - taosMsleep(100); - } - - return 0; } int32_t dmRun(SDnode *pDnode) { if (!tsMultiProcess) { - return dmRunInSingleProcess(pDnode); + pDnode->ptype = DND_PROC_SINGLE; + dInfo("dnode run in single process"); } else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_END) { - return dmRunInParentProcess(pDnode); + pDnode->ptype = DND_PROC_PARENT; + dInfo("dnode run in parent process"); } else { - return dmRunInChildProcess(pDnode); + pDnode->ptype = DND_PROC_CHILD; + SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; + dInfo("%s run in child process", pWrapper->name); } - return 0; + if (dmOpenNodes(pDnode) != 0) { + dError("failed to open nodes since %s", terrstr()); + return -1; + } + + if (dmStartNodes(pDnode) != 0) { + dError("failed to start nodes since %s", terrstr()); + return -1; + } + + while (1) { + taosMsleep(100); + if (pDnode->event & DND_EVENT_STOP) { + dInfo("dnode is about to stop"); + dmSetStatus(pDnode, DND_STAT_STOPPED); + dmStopNodes(pDnode); + dmCloseNodes(pDnode); + return 0; + } else { + dmWatchNodes(pDnode); + } + } } diff --git a/source/dnode/mgmt/implement/src/dmHandle.c b/source/dnode/mgmt/implement/src/dmHandle.c index b5c81850ef..8f9a316c72 100644 --- a/source/dnode/mgmt/implement/src/dmHandle.c +++ b/source/dnode/mgmt/implement/src/dmHandle.c @@ -152,18 +152,20 @@ int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) int32_t code = (*pWrapper->fp.dropFp)(pWrapper, pMsg); if (code != 0) { dError("node:%s, failed to drop since %s", pWrapper->name, terrstr()); - pWrapper->required = true; - pWrapper->deployed = true; } else { dDebug("node:%s, has been dropped", pWrapper->name); pWrapper->required = false; pWrapper->deployed = false; - dmCloseNode(pWrapper); + taosRemoveDir(pWrapper->path); } taosWUnLockLatch(&pWrapper->latch); dmReleaseWrapper(pWrapper); - return 0; + + if (code == 0) { + dmCloseNode(pWrapper); + } + return code; } static void dmSetMgmtMsgHandle(SMgmtWrapper *pWrapper) { diff --git a/source/dnode/mgmt/implement/src/dmObj.c b/source/dnode/mgmt/implement/src/dmObj.c index 2a9ea87530..be89814d6a 100644 --- a/source/dnode/mgmt/implement/src/dmObj.c +++ b/source/dnode/mgmt/implement/src/dmObj.c @@ -140,12 +140,6 @@ _OVER: void dmClose(SDnode *pDnode) { if (pDnode == NULL) return; - - for (EDndNodeType n = DNODE; n < NODE_END; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - dmCloseNode(pWrapper); - } - dmClearVars(pDnode); dInfo("dnode is closed, data:%p", pDnode); } diff --git a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h index 8a7442efc3..3adcc1206b 100644 --- a/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h +++ b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h @@ -33,10 +33,6 @@ typedef struct SBnodeMgmt { SSingleWorker monitorWorker; } SBnodeMgmt; -// bmInt.c -int32_t bmOpen(SMgmtWrapper *pWrapper); -int32_t bmDrop(SMgmtWrapper *pWrapper); - // bmHandle.c void bmInitMsgHandle(SMgmtWrapper *pWrapper); int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c index ac96a5fd91..49bf9201e1 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c @@ -57,10 +57,15 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->data.dnodeId); return -1; - } else { - // return dmOpenNode(pWrapper); - return 0; } + + bool deployed = true; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write bnode file since %s", terrstr()); + return -1; + } + + return 0; } int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { @@ -77,10 +82,15 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop bnode since %s", terrstr()); return -1; - } else { - // dmCloseNode(pWrapper); - return bmDrop(pWrapper); } + + bool deployed = false; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write bnode file since %s", terrstr()); + return -1; + } + + return 0; } void bmInitMsgHandle(SMgmtWrapper *pWrapper) { diff --git a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c index 860c5d465c..f635df8ec7 100644 --- a/source/dnode/mgmt/mgmt_bnode/src/bmInt.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c @@ -24,63 +24,17 @@ static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { pOption->msgCb = msgCb; } -static int32_t bmOpenImp(SBnodeMgmt *pMgmt) { - SBnodeOpt option = {0}; - bmInitOption(pMgmt, &option); - - pMgmt->pBnode = bndOpen(pMgmt->path, &option); - if (pMgmt->pBnode == NULL) { - dError("failed to open bnode since %s", terrstr()); - return -1; - } - - if (bmStartWorker(pMgmt) != 0) { - dError("failed to start bnode worker since %s", terrstr()); - return -1; - } - - bool deployed = true; - if (dmWriteFile(pMgmt->pWrapper, deployed) != 0) { - dError("failed to write bnode file since %s", terrstr()); - return -1; - } - - return 0; -} - -static void bmCloseImp(SBnodeMgmt *pMgmt) { - if (pMgmt->pBnode != NULL) { - bmStopWorker(pMgmt); - bndClose(pMgmt->pBnode); - pMgmt->pBnode = NULL; - } -} - -int32_t bmDrop(SMgmtWrapper *pWrapper) { - SBnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return 0; - - dInfo("bnode-mgmt start to drop"); - bool deployed = false; - if (dmWriteFile(pWrapper, deployed) != 0) { - dError("failed to drop bnode since %s", terrstr()); - return -1; - } - - bmCloseImp(pMgmt); - taosRemoveDir(pMgmt->path); - pWrapper->pMgmt = NULL; - taosMemoryFree(pMgmt); - dInfo("bnode-mgmt is dropped"); - return 0; -} - static void bmClose(SMgmtWrapper *pWrapper) { SBnodeMgmt *pMgmt = pWrapper->pMgmt; if (pMgmt == NULL) return; dInfo("bnode-mgmt start to cleanup"); - bmCloseImp(pMgmt); + if (pMgmt->pBnode != NULL) { + bmStopWorker(pMgmt); + bndClose(pMgmt->pBnode); + pMgmt->pBnode = NULL; + } + pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("bnode-mgmt is cleaned up"); @@ -99,15 +53,22 @@ int32_t bmOpen(SMgmtWrapper *pWrapper) { pMgmt->pWrapper = pWrapper; pWrapper->pMgmt = pMgmt; - int32_t code = bmOpenImp(pMgmt); - if (code != 0) { - dError("failed to init bnode-mgmt since %s", terrstr()); + SBnodeOpt option = {0}; + bmInitOption(pMgmt, &option); + pMgmt->pBnode = bndOpen(pMgmt->path, &option); + if (pMgmt->pBnode == NULL) { + dError("failed to open bnode since %s", terrstr()); bmClose(pWrapper); - } else { - dInfo("bnode-mgmt is initialized"); + return -1; } - return code; + if (bmStartWorker(pMgmt) != 0) { + dError("failed to start bnode worker since %s", terrstr()); + bmClose(pWrapper); + return -1; + } + + return 0; } void bmSetMgmtFp(SMgmtWrapper *pWrapper) { diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index 0742d2b9f9..d76c1f6679 100644 --- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -41,7 +41,7 @@ typedef struct SMnodeMgmt { // mmFile.c int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed); -int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed); +int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed); // mmInt.c int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index f3d0d666bb..9724cc04a2 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -105,9 +105,11 @@ PRASE_MNODE_OVER: return code; } -int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { - char file[PATH_MAX]; - snprintf(file, sizeof(file), "%s%smnode.json.bak", pMgmt->path, TD_DIRSEP); +int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed) { + char file[PATH_MAX] = {0}; + char realfile[PATH_MAX] = {0}; + snprintf(file, sizeof(file), "%s%smnode.json.bak", pWrapper->path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%smnode.json", pWrapper->path, TD_DIRSEP); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -121,19 +123,21 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { char *content = taosMemoryCalloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", deployed); - len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n"); - for (int32_t i = 0; i < pMgmt->replica; ++i) { - SReplica *pReplica = &pMgmt->replicas[i]; - len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id); - len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); - len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port); - if (i < pMgmt->replica - 1) { - len += snprintf(content + len, maxLen - len, " },{\n"); - } else { - len += snprintf(content + len, maxLen - len, " }]\n"); + if (pReq != NULL) { + len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n"); + for (int32_t i = 0; i < pReq->replica; ++i) { + SReplica *pReplica = &pReq->replicas[i]; + len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id); + len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); + len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port); + if (i < pReq->replica - 1) { + len += snprintf(content + len, maxLen - len, " },{\n"); + } else { + len += snprintf(content + len, maxLen - len, " }],\n"); + } } } + len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed); len += snprintf(content + len, maxLen - len, "}\n"); taosWriteFile(pFile, content, len); @@ -141,9 +145,6 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { taosCloseFile(&pFile); taosMemoryFree(content); - char realfile[PATH_MAX]; - snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP); - if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to rename %s since %s", file, terrstr()); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 5e277b6ed2..c6149a9a7e 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -60,9 +60,15 @@ int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create mnode since %s", terrstr()); return -1; - } else { - return mmOpenFromMsg(pWrapper, &createReq); } + + bool deployed = true; + if (mmWriteFile(pWrapper, &createReq, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + + return 0; } int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { @@ -79,10 +85,15 @@ int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop mnode since %s", terrstr()); return -1; - } else { - // dmCloseNode(pWrapper); - return mmDrop(pWrapper); } + + bool deployed = false; + if (mmWriteFile(pWrapper, NULL, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + + return 0; } int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index ce0459686c..49d5d79491 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -134,12 +134,6 @@ static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) { return -1; } - bool deployed = true; - if (mmWriteFile(pMgmt, deployed) != 0) { - dError("failed to write mnode file since %s", terrstr()); - return -1; - } - return 0; } @@ -164,11 +158,11 @@ int32_t mmDrop(SMgmtWrapper *pWrapper) { if (pMgmt == NULL) return 0; dInfo("mnode-mgmt start to drop"); - bool deployed = false; - if (mmWriteFile(pMgmt, deployed) != 0) { - dError("failed to drop mnode since %s", terrstr()); - return -1; - } + // bool deployed = false; + // if (mmWriteFile(pMgmt, deployed) != 0) { + // dError("failed to drop mnode since %s", terrstr()); + // return -1; + // } mmCloseImp(pMgmt); taosRemoveDir(pMgmt->path); @@ -229,7 +223,9 @@ static int32_t mmStart(SMgmtWrapper *pWrapper) { static void mmStop(SMgmtWrapper *pWrapper) { dDebug("mnode-mgmt start to stop"); SMnodeMgmt *pMgmt = pWrapper->pMgmt; - mndStop(pMgmt->pMnode); + if (pMgmt != NULL) { + mndStop(pMgmt->pMnode); + } } void mmSetMgmtFp(SMgmtWrapper *pWrapper) { diff --git a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h index c0ed6599bd..d52fbff683 100644 --- a/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h +++ b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h @@ -34,10 +34,6 @@ typedef struct SQnodeMgmt { SSingleWorker monitorWorker; } SQnodeMgmt; -// qmInt.c -int32_t qmOpen(SMgmtWrapper *pWrapper); -int32_t qmDrop(SMgmtWrapper *pWrapper); - // qmHandle.c void qmInitMsgHandle(SMgmtWrapper *pWrapper); int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c index 209c0b3f6c..d8a54cfbd5 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c @@ -57,10 +57,15 @@ int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create qnode since %s", terrstr()); return -1; - } else { - // return dmOpenNode(pWrapper); - return 0; } + + bool deployed = true; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write qnode file since %s", terrstr()); + return -1; + } + + return 0; } int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { @@ -77,10 +82,15 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop qnode since %s", terrstr()); return -1; - } else { - // dmCloseNode(pWrapper); - return qmDrop(pWrapper); } + + bool deployed = false; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write qnode file since %s", terrstr()); + return -1; + } + + return 0; } void qmInitMsgHandle(SMgmtWrapper *pWrapper) { diff --git a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c index c73d337136..d8d02b2619 100644 --- a/source/dnode/mgmt/mgmt_qnode/src/qmInt.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c @@ -27,69 +27,23 @@ static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { pOption->msgCb = msgCb; } -static int32_t qmOpenImp(SQnodeMgmt *pMgmt) { - SQnodeOpt option = {0}; - qmInitOption(pMgmt, &option); - - pMgmt->pQnode = qndOpen(&option); - if (pMgmt->pQnode == NULL) { - dError("failed to open qnode since %s", terrstr()); - return -1; - } - - if (qmStartWorker(pMgmt) != 0) { - dError("failed to start qnode worker since %s", terrstr()); - return -1; - } - - bool deployed = true; - if (dmWriteFile(pMgmt->pWrapper, deployed) != 0) { - dError("failed to write qnode file since %s", terrstr()); - return -1; - } - - return 0; -} - -static void qmCloseImp(SQnodeMgmt *pMgmt) { - if (pMgmt->pQnode != NULL) { - qmStopWorker(pMgmt); - qndClose(pMgmt->pQnode); - pMgmt->pQnode = NULL; - } -} - -int32_t qmDrop(SMgmtWrapper *pWrapper) { - SQnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return 0; - - dInfo("qnode-mgmt start to drop"); - bool deployed = false; - if (dmWriteFile(pWrapper, deployed) != 0) { - dError("failed to drop qnode since %s", terrstr()); - return -1; - } - - qmCloseImp(pMgmt); - taosRemoveDir(pMgmt->path); - pWrapper->pMgmt = NULL; - taosMemoryFree(pMgmt); - dInfo("qnode-mgmt is dropped"); - return 0; -} - static void qmClose(SMgmtWrapper *pWrapper) { SQnodeMgmt *pMgmt = pWrapper->pMgmt; if (pMgmt == NULL) return; dInfo("qnode-mgmt start to cleanup"); - qmCloseImp(pMgmt); + if (pMgmt->pQnode != NULL) { + qmStopWorker(pMgmt); + qndClose(pMgmt->pQnode); + pMgmt->pQnode = NULL; + } + pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("qnode-mgmt is cleaned up"); } -int32_t qmOpen(SMgmtWrapper *pWrapper) { +static int32_t qmOpen(SMgmtWrapper *pWrapper) { dInfo("qnode-mgmt start to init"); SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt)); if (pMgmt == NULL) { @@ -102,15 +56,23 @@ int32_t qmOpen(SMgmtWrapper *pWrapper) { pMgmt->pWrapper = pWrapper; pWrapper->pMgmt = pMgmt; - int32_t code = qmOpenImp(pMgmt); - if (code != 0) { - dError("failed to init qnode-mgmt since %s", terrstr()); + SQnodeOpt option = {0}; + qmInitOption(pMgmt, &option); + pMgmt->pQnode = qndOpen(&option); + if (pMgmt->pQnode == NULL) { + dError("failed to open qnode since %s", terrstr()); qmClose(pWrapper); - } else { - dInfo("qnode-mgmt is initialized"); + return -1; } - return code; + if (qmStartWorker(pMgmt) != 0) { + dError("failed to start qnode worker since %s", terrstr()); + qmClose(pWrapper); + return -1; + } + + dInfo("qnode-mgmt is initialized"); + return 0; } void qmSetMgmtFp(SMgmtWrapper *pWrapper) { diff --git a/source/dnode/mgmt/mgmt_snode/inc/smInt.h b/source/dnode/mgmt/mgmt_snode/inc/smInt.h index 5045f21272..9eb48af733 100644 --- a/source/dnode/mgmt/mgmt_snode/inc/smInt.h +++ b/source/dnode/mgmt/mgmt_snode/inc/smInt.h @@ -36,10 +36,6 @@ typedef struct SSnodeMgmt { SSingleWorker monitorWorker; } SSnodeMgmt; -// smInt.c -int32_t smOpen(SMgmtWrapper *pWrapper); -int32_t smDrop(SMgmtWrapper *pWrapper); - // smHandle.c void smInitMsgHandle(SMgmtWrapper *pWrapper); int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c index 4c0e0aef8d..defc5ab136 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -57,10 +57,15 @@ int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create snode since %s", terrstr()); return -1; - } else { - // return dmOpenNode(pWrapper); - return 0; } + + bool deployed = true; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write snode file since %s", terrstr()); + return -1; + } + + return 0; } int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { @@ -77,10 +82,15 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop snode since %s", terrstr()); return -1; - } else { - return smDrop(pWrapper); - // return dmCloseNode(pWrapper); } + + bool deployed = false; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write snode file since %s", terrstr()); + return -1; + } + + return 0; } void smInitMsgHandle(SMgmtWrapper *pWrapper) { diff --git a/source/dnode/mgmt/mgmt_snode/src/smInt.c b/source/dnode/mgmt/mgmt_snode/src/smInt.c index 3b17d775f7..8adf643a2b 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smInt.c +++ b/source/dnode/mgmt/mgmt_snode/src/smInt.c @@ -24,63 +24,17 @@ static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { pOption->msgCb = msgCb; } -static int32_t smOpenImp(SSnodeMgmt *pMgmt) { - SSnodeOpt option = {0}; - smInitOption(pMgmt, &option); - - pMgmt->pSnode = sndOpen(pMgmt->path, &option); - if (pMgmt->pSnode == NULL) { - dError("failed to open snode since %s", terrstr()); - return -1; - } - - if (smStartWorker(pMgmt) != 0) { - dError("failed to start snode worker since %s", terrstr()); - return -1; - } - - bool deployed = true; - if (dmWriteFile(pMgmt->pWrapper, deployed) != 0) { - dError("failed to write snode file since %s", terrstr()); - return -1; - } - - return 0; -} - -static void smCloseImp(SSnodeMgmt *pMgmt) { - if (pMgmt->pSnode != NULL) { - smStopWorker(pMgmt); - sndClose(pMgmt->pSnode); - pMgmt->pSnode = NULL; - } -} - -int32_t smDrop(SMgmtWrapper *pWrapper) { - SSnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return 0; - - dInfo("snode-mgmt start to drop"); - bool deployed = false; - if (dmWriteFile(pWrapper, deployed) != 0) { - dError("failed to drop snode since %s", terrstr()); - return -1; - } - - smCloseImp(pMgmt); - taosRemoveDir(pMgmt->path); - pWrapper->pMgmt = NULL; - taosMemoryFree(pMgmt); - dInfo("snode-mgmt is dropped"); - return 0; -} - static void smClose(SMgmtWrapper *pWrapper) { SSnodeMgmt *pMgmt = pWrapper->pMgmt; if (pMgmt == NULL) return; dInfo("snode-mgmt start to cleanup"); - smCloseImp(pMgmt); + if (pMgmt->pSnode != NULL) { + smStopWorker(pMgmt); + sndClose(pMgmt->pSnode); + pMgmt->pSnode = NULL; + } + pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("snode-mgmt is cleaned up"); @@ -99,15 +53,20 @@ int32_t smOpen(SMgmtWrapper *pWrapper) { pMgmt->pWrapper = pWrapper; pWrapper->pMgmt = pMgmt; - int32_t code = smOpenImp(pMgmt); - if (code != 0) { - dError("failed to init snode-mgmt since %s", terrstr()); - smClose(pWrapper); - } else { - dInfo("snode-mgmt is initialized"); + SSnodeOpt option = {0}; + smInitOption(pMgmt, &option); + pMgmt->pSnode = sndOpen(pMgmt->path, &option); + if (pMgmt->pSnode == NULL) { + dError("failed to open snode since %s", terrstr()); + return -1; } - return code; + if (smStartWorker(pMgmt) != 0) { + dError("failed to start snode worker since %s", terrstr()); + return -1; + } + + return 0; } void smSetMgmtFp(SMgmtWrapper *pWrapper) { From d812206eda3013f92abd4b0c48631fd3063f25b8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 14 Apr 2022 11:33:31 +0800 Subject: [PATCH 15/19] refact(cluster): node mgmt --- source/dnode/mgmt/implement/src/dmExec.c | 48 ++++---- source/dnode/mgmt/implement/src/dmTransport.c | 7 +- source/dnode/mgmt/mgmt_mnode/inc/mmInt.h | 2 - source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 114 ++++++------------ 4 files changed, 69 insertions(+), 102 deletions(-) diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c index 7c5d049aff..bb18eb85f1 100644 --- a/source/dnode/mgmt/implement/src/dmExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -25,7 +25,7 @@ static bool dmRequireNode(SMgmtWrapper *pWrapper) { return required; } -static int32_t dmInitNodeProc(SMgmtWrapper *pWrapper) { +static int32_t dmInitParentProc(SMgmtWrapper *pWrapper) { int32_t shmsize = tsMnodeShmSize; if (pWrapper->ntype == VNODE) { shmsize = tsVnodeShmSize; @@ -82,20 +82,37 @@ static int32_t dmNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) { return 0; } -static int32_t dmRunNodeProc(SMgmtWrapper *pWrapper) { +static int32_t dmRunParentProc(SMgmtWrapper *pWrapper) { if (pWrapper->pDnode->ntype == NODE_END) { - dInfo("node:%s, should be started manually", pWrapper->name); + dInfo("node:%s, should be started manually in child process", pWrapper->name); } else { if (dmNewNodeProc(pWrapper, pWrapper->ntype) != 0) { return -1; } } - if (taosProcRun(pWrapper->procObj) != 0) { dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); return -1; } + return 0; +} +static int32_t dmInitChildProc(SMgmtWrapper *pWrapper) { + SProcCfg cfg = dmGenProcCfg(pWrapper); + cfg.isChild = true; + pWrapper->procObj = taosProcInit(&cfg); + if (pWrapper->procObj == NULL) { + dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); + return -1; + } + return 0; +} + +static int32_t dmRunChildProc(SMgmtWrapper *pWrapper) { + if (taosProcRun(pWrapper->procObj) != 0) { + dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); + return -1; + } return 0; } @@ -111,23 +128,16 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) { dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); return -1; } - + if (pWrapper->procType == DND_PROC_CHILD) { + if (dmInitChildProc(pWrapper) != 0) return -1; + if (dmRunChildProc(pWrapper) != 0) return -1; + } dDebug("node:%s, has been opened", pWrapper->name); pWrapper->deployed = true; } else { - if (dmInitNodeProc(pWrapper) != 0) return -1; + if (dmInitParentProc(pWrapper) != 0) return -1; if (dmWriteShmFile(pWrapper) != 0) return -1; - if (dmRunNodeProc(pWrapper) != 0) return -1; - } - - if (pWrapper->procType == DND_PROC_CHILD) { - SProcCfg cfg = dmGenProcCfg(pWrapper); - cfg.isChild = true; - pWrapper->procObj = taosProcInit(&cfg); - if (pWrapper->procObj == NULL) { - dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); - return -1; - } + if (dmRunParentProc(pWrapper) != 0) return -1; } return 0; @@ -138,10 +148,6 @@ int32_t dmStartNode(SMgmtWrapper *pWrapper) { dInfo("node:%s, not start in parent process", pWrapper->name); } else if (pWrapper->procType == DND_PROC_CHILD) { dInfo("node:%s, start in child process", pWrapper->name); - if (taosProcRun(pWrapper->procObj) != 0) { - dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); - return -1; - } } else { if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) { dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); diff --git a/source/dnode/mgmt/implement/src/dmTransport.c b/source/dnode/mgmt/implement/src/dmTransport.c index 8f583d7ea3..aa38c2492d 100644 --- a/source/dnode/mgmt/implement/src/dmTransport.c +++ b/source/dnode/mgmt/implement/src/dmTransport.c @@ -78,10 +78,11 @@ static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSe if (dmBuildMsg(pMsg, pRpc) != 0) goto _OVER; if (pWrapper->procType == DND_PROC_SINGLE) { - dTrace("msg:%p, is created, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); + dTrace("msg:%p, is created, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), pRpc->handle, pMsg->user); code = (*msgFp)(pWrapper, pMsg); } else if (pWrapper->procType == DND_PROC_PARENT) { - dTrace("msg:%p, is created and put into child queue, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); + dTrace("msg:%p, is created and put into child queue, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), + pRpc->handle, pMsg->user); code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle, PROC_FUNC_REQ); } else { @@ -97,7 +98,7 @@ _OVER: rpcFreeCont(pRpc->pCont); } } else { - dError("msg:%p, failed to process since 0x%04x:%s", pMsg, code & 0XFFFF, terrstr()); + dError("msg:%p, type:%s failed to process since 0x%04x:%s", pMsg, TMSG_INFO(msgType), code & 0XFFFF, terrstr()); if (msgType & 1U) { if (terrno != 0) code = terrno; if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) { diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index d76c1f6679..5f66ae230a 100644 --- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -44,8 +44,6 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed); int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed); // mmInt.c -int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq); -int32_t mmDrop(SMgmtWrapper *pWrapper); int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq); // mmHandle.c diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 49d5d79491..35ffe86735 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -98,53 +98,6 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre return 0; } -static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) { - SMnodeOpt option = {0}; - if (pReq != NULL) { - if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) { - return -1; - } - } else { - bool deployed = false; - if (mmReadFile(pMgmt, &deployed) != 0) { - dError("failed to read file since %s", terrstr()); - return -1; - } - - if (!deployed) { - dInfo("mnode start to deploy"); - if (pMgmt->pWrapper->procType == DND_PROC_CHILD) { - pMgmt->pDnode->data.dnodeId = 1; - } - mmBuildOptionForDeploy(pMgmt, &option); - } else { - dInfo("mnode start to open"); - mmBuildOptionForOpen(pMgmt, &option); - } - } - - pMgmt->pMnode = mndOpen(pMgmt->path, &option); - if (pMgmt->pMnode == NULL) { - dError("failed to open mnode since %s", terrstr()); - return -1; - } - - if (mmStartWorker(pMgmt) != 0) { - dError("failed to start mnode worker since %s", terrstr()); - return -1; - } - - return 0; -} - -static void mmCloseImp(SMnodeMgmt *pMgmt) { - if (pMgmt->pMnode != NULL) { - mmStopWorker(pMgmt); - mndClose(pMgmt->pMnode); - pMgmt->pMnode = NULL; - } -} - int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) { SMnodeOpt option = {0}; if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) { @@ -153,37 +106,23 @@ int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) { return mndAlter(pMgmt->pMnode, &option); } -int32_t mmDrop(SMgmtWrapper *pWrapper) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return 0; - - dInfo("mnode-mgmt start to drop"); - // bool deployed = false; - // if (mmWriteFile(pMgmt, deployed) != 0) { - // dError("failed to drop mnode since %s", terrstr()); - // return -1; - // } - - mmCloseImp(pMgmt); - taosRemoveDir(pMgmt->path); - pWrapper->pMgmt = NULL; - taosMemoryFree(pMgmt); - dInfo("mnode-mgmt is dropped"); - return 0; -} - static void mmClose(SMgmtWrapper *pWrapper) { SMnodeMgmt *pMgmt = pWrapper->pMgmt; if (pMgmt == NULL) return; dInfo("mnode-mgmt start to cleanup"); - mmCloseImp(pMgmt); + if (pMgmt->pMnode != NULL) { + mmStopWorker(pMgmt); + mndClose(pMgmt->pMnode); + pMgmt->pMnode = NULL; + } + pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("mnode-mgmt is cleaned up"); } -int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) { +static int32_t mmOpen(SMgmtWrapper *pWrapper) { dInfo("mnode-mgmt start to init"); if (walInit() != 0) { dError("failed to init wal since %s", terrstr()); @@ -201,18 +140,41 @@ int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) { pMgmt->pWrapper = pWrapper; pWrapper->pMgmt = pMgmt; - int32_t code = mmOpenImp(pMgmt, pReq); - if (code != 0) { - dError("failed to init mnode-mgmt since %s", terrstr()); + bool deployed = false; + if (mmReadFile(pMgmt, &deployed) != 0) { + dError("failed to read file since %s", terrstr()); mmClose(pWrapper); - } else { - dInfo("mnode-mgmt is initialized"); + return -1; } - return code; -} + SMnodeOpt option = {0}; + if (!deployed) { + dInfo("mnode start to deploy"); + if (pWrapper->procType == DND_PROC_CHILD) { + pWrapper->pDnode->data.dnodeId = 1; + } + mmBuildOptionForDeploy(pMgmt, &option); + } else { + dInfo("mnode start to open"); + mmBuildOptionForOpen(pMgmt, &option); + } -static int32_t mmOpen(SMgmtWrapper *pWrapper) { return mmOpenFromMsg(pWrapper, NULL); } + pMgmt->pMnode = mndOpen(pMgmt->path, &option); + if (pMgmt->pMnode == NULL) { + dError("failed to open mnode since %s", terrstr()); + mmClose(pWrapper); + return -1; + } + + if (mmStartWorker(pMgmt) != 0) { + dError("failed to start mnode worker since %s", terrstr()); + mmClose(pWrapper); + return -1; + } + + dInfo("mnode-mgmt is initialized"); + return 0; +} static int32_t mmStart(SMgmtWrapper *pWrapper) { dDebug("mnode-mgmt start to run"); From c57b157461b50eb50ef908ccc80442f8d7dbe629 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 14 Apr 2022 12:03:15 +0800 Subject: [PATCH 16/19] refact(cluster): node mgmt --- source/dnode/mgmt/implement/src/dmEps.c | 13 ++++++------- source/dnode/mgmt/mgmt_mnode/src/mmFile.c | 19 +++++++++++++------ source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 21 ++++++++++++++++++++- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/source/dnode/mgmt/implement/src/dmEps.c b/source/dnode/mgmt/implement/src/dmEps.c index 6e8ee638dc..ae1cd513b5 100644 --- a/source/dnode/mgmt/implement/src/dmEps.c +++ b/source/dnode/mgmt/implement/src/dmEps.c @@ -45,7 +45,7 @@ int32_t dmReadEps(SDnode *pDnode) { int32_t maxLen = 256 * 1024; char *content = taosMemoryCalloc(1, maxLen + 1); cJSON *root = NULL; - char file[PATH_MAX]; + char file[PATH_MAX] = {0}; TdFilePtr pFile = NULL; pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp)); @@ -54,7 +54,7 @@ int32_t dmReadEps(SDnode *pDnode) { goto PRASE_DNODE_OVER; } - snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->data.dataDir, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->wrappers[DNODE].path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { // dDebug("file %s not exist", file); @@ -175,8 +175,10 @@ PRASE_DNODE_OVER: } int32_t dmWriteEps(SDnode *pDnode) { - char file[PATH_MAX]; - snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->data.dataDir, TD_DIRSEP); + char file[PATH_MAX] = {0}; + char realfile[PATH_MAX]; + snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->wrappers[DNODE].path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->wrappers[DNODE].path, TD_DIRSEP); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -215,9 +217,6 @@ int32_t dmWriteEps(SDnode *pDnode) { taosCloseFile(&pFile); taosMemoryFree(content); - char realfile[PATH_MAX]; - snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->data.dataDir, TD_DIRSEP); - if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to rename %s since %s", file, terrstr()); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 9724cc04a2..baf16f591d 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -121,22 +121,29 @@ int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deploye int32_t len = 0; int32_t maxLen = 4096; char *content = taosMemoryCalloc(1, maxLen + 1); - + len += snprintf(content + len, maxLen - len, "{\n"); - if (pReq != NULL) { - len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n"); - for (int32_t i = 0; i < pReq->replica; ++i) { - SReplica *pReplica = &pReq->replicas[i]; + len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n"); + + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + if (pReq != NULL || pMgmt != NULL) { + int8_t replica = (pReq != NULL ? pReq->replica : pMgmt->replica); + for (int32_t i = 0; i < replica; ++i) { + SReplica *pReplica = &pMgmt->replicas[i]; + if (pReq != NULL) { + pReplica = &pReq->replicas[i]; + } len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id); len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port); - if (i < pReq->replica - 1) { + if (i < replica - 1) { len += snprintf(content + len, maxLen - len, " },{\n"); } else { len += snprintf(content + len, maxLen - len, " }],\n"); } } } + len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed); len += snprintf(content + len, maxLen - len, "}\n"); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 35ffe86735..69b4d50939 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -103,7 +103,18 @@ int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) { if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) { return -1; } - return mndAlter(pMgmt->pMnode, &option); + + if (mndAlter(pMgmt->pMnode, &option) != 0) { + return -1; + } + + bool deployed = true; + if (mmWriteFile(pMgmt->pWrapper, pReq, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + + return 0; } static void mmClose(SMgmtWrapper *pWrapper) { @@ -172,6 +183,14 @@ static int32_t mmOpen(SMgmtWrapper *pWrapper) { return -1; } + if (!deployed) { + deployed = true; + if (mmWriteFile(pWrapper, NULL, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + } + dInfo("mnode-mgmt is initialized"); return 0; } From 6958f3abfca79070ecc391aa55c304696e27a65b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 14 Apr 2022 13:44:40 +0800 Subject: [PATCH 17/19] refact(cluster): node mgmt --- include/dnode/mnode/mnode.h | 6 ++++++ source/dnode/mgmt/exe/dmMain.c | 3 +-- source/dnode/mgmt/interface/inc/dmDef.h | 1 + source/dnode/mnode/impl/inc/mndGrant.h | 1 - source/dnode/mnode/impl/src/mndGrant.c | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 1d5ed1b6d2..9e5f8a4ddd 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -103,6 +103,12 @@ int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, cha */ int32_t mndProcessMsg(SNodeMsg *pMsg); +/** + * @brief Generate machine code + * + */ +void mndGenerateMachineCode(); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 7e32a2f093..3f5c22dd84 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "dmImp.h" #include "tconfig.h" -#include "mndGrant.h" static struct { bool dumpConfig; @@ -90,7 +89,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { return 0; } -static void dmGenerateGrant() { parseGrantParameter(); } +static void dmGenerateGrant() { mndGenerateMachineCode(); } static void dmPrintVersion() { #ifdef TD_ENTERPRISE diff --git a/source/dnode/mgmt/interface/inc/dmDef.h b/source/dnode/mgmt/interface/inc/dmDef.h index 594eb22195..c0c33570db 100644 --- a/source/dnode/mgmt/interface/inc/dmDef.h +++ b/source/dnode/mgmt/interface/inc/dmDef.h @@ -36,6 +36,7 @@ #include "tworker.h" #include "dnode.h" +#include "mnode.h" #include "monitor.h" #ifdef __cplusplus diff --git a/source/dnode/mnode/impl/inc/mndGrant.h b/source/dnode/mnode/impl/inc/mndGrant.h index a2ff5ea6ce..ad3dc7f79d 100644 --- a/source/dnode/mnode/impl/inc/mndGrant.h +++ b/source/dnode/mnode/impl/inc/mndGrant.h @@ -44,7 +44,6 @@ void grantReset(EGrantType grant, uint64_t value); void grantAdd(EGrantType grant, uint64_t value); void grantRestore(EGrantType grant, uint64_t value); -void parseGrantParameter(); #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndGrant.c b/source/dnode/mnode/impl/src/mndGrant.c index c97d4dd807..99c25299ff 100644 --- a/source/dnode/mnode/impl/src/mndGrant.c +++ b/source/dnode/mnode/impl/src/mndGrant.c @@ -30,4 +30,4 @@ void grantRestore(EGrantType grant, uint64_t value) {} #endif -void parseGrantParameter() { parseGrantParameter(); } \ No newline at end of file +void mndGenerateMachineCode() { grantParseParameter(); } \ No newline at end of file From 8b8778652253aa99139613cf284518dfcd817932 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 14 Apr 2022 14:26:54 +0800 Subject: [PATCH 18/19] fix(cluster): create qnode in multi-process mode may crash --- source/dnode/mgmt/implement/src/dmExec.c | 7 ++++++- source/dnode/mgmt/implement/src/dmHandle.c | 15 ++++++++------- source/dnode/mgmt/implement/src/dmObj.c | 4 +++- source/dnode/mgmt/interface/inc/dmDef.h | 2 +- source/libs/transport/src/transSrv.c | 12 ++++++------ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c index bb18eb85f1..36e135b9de 100644 --- a/source/dnode/mgmt/implement/src/dmExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -275,19 +275,24 @@ static void dmProcessProcHandle(void *handle) { } static void dmWatchNodes(SDnode *pDnode) { + taosThreadMutexLock(&pDnode->mutex); if (pDnode->ptype == DND_PROC_PARENT) { for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; if (!pWrapper->required) continue; + if (pWrapper->procType != DND_PROC_PARENT) continue; if (pDnode->ntype == NODE_END) continue; if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); - taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle); + if (pWrapper->procObj) { + taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle); + } dmNewNodeProc(pWrapper, n); } } } + taosThreadMutexUnlock(&pDnode->mutex); } int32_t dmRun(SDnode *pDnode) { diff --git a/source/dnode/mgmt/implement/src/dmHandle.c b/source/dnode/mgmt/implement/src/dmHandle.c index 8f9a316c72..93b24535a9 100644 --- a/source/dnode/mgmt/implement/src/dmHandle.c +++ b/source/dnode/mgmt/implement/src/dmHandle.c @@ -116,7 +116,7 @@ int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMs return -1; } - taosWLockLatch(&pDnode->wrapperLock); + taosThreadMutexLock(&pDnode->mutex); pWrapper = &pDnode->wrappers[ntype]; if (taosMkDir(pWrapper->path) != 0) { @@ -132,10 +132,11 @@ int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMs dDebug("node:%s, has been created", pWrapper->name); pWrapper->required = true; pWrapper->deployed = true; + pWrapper->procType = pDnode->ptype; (void)dmOpenNode(pWrapper); } - taosWUnLockLatch(&pDnode->wrapperLock); + taosThreadMutexUnlock(&pDnode->mutex); return code; } @@ -147,24 +148,24 @@ int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) return -1; } - taosWLockLatch(&pWrapper->latch); + taosThreadMutexLock(&pDnode->mutex); int32_t code = (*pWrapper->fp.dropFp)(pWrapper, pMsg); if (code != 0) { dError("node:%s, failed to drop since %s", pWrapper->name, terrstr()); } else { dDebug("node:%s, has been dropped", pWrapper->name); - pWrapper->required = false; - pWrapper->deployed = false; - taosRemoveDir(pWrapper->path); } - taosWUnLockLatch(&pWrapper->latch); dmReleaseWrapper(pWrapper); if (code == 0) { dmCloseNode(pWrapper); + pWrapper->required = false; + pWrapper->deployed = false; + taosRemoveDir(pWrapper->path); } + taosThreadMutexUnlock(&pDnode->mutex); return code; } diff --git a/source/dnode/mgmt/implement/src/dmObj.c b/source/dnode/mgmt/implement/src/dmObj.c index be89814d6a..66bfb27016 100644 --- a/source/dnode/mgmt/implement/src/dmObj.c +++ b/source/dnode/mgmt/implement/src/dmObj.c @@ -48,7 +48,7 @@ static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { } taosInitRWLatch(&pDnode->data.latch); - taosInitRWLatch(&pDnode->wrapperLock); + taosThreadMutexInit(&pDnode->mutex, NULL); return 0; } @@ -67,6 +67,8 @@ static void dmClearVars(SDnode *pDnode) { taosMemoryFreeClear(pDnode->data.firstEp); taosMemoryFreeClear(pDnode->data.secondEp); taosMemoryFreeClear(pDnode->data.dataDir); + taosThreadMutexDestroy(&pDnode->mutex); + memset(&pDnode->mutex, 0, sizeof(pDnode->mutex)); taosMemoryFree(pDnode); dDebug("dnode memory is cleared, data:%p", pDnode); } diff --git a/source/dnode/mgmt/interface/inc/dmDef.h b/source/dnode/mgmt/interface/inc/dmDef.h index c0c33570db..a38349f852 100644 --- a/source/dnode/mgmt/interface/inc/dmDef.h +++ b/source/dnode/mgmt/interface/inc/dmDef.h @@ -140,7 +140,7 @@ typedef struct SDnode { SStartupReq startup; SDnodeTrans trans; SDnodeData data; - SRWLatch wrapperLock; + TdThreadMutex mutex; SMgmtWrapper wrappers[NODE_END]; } SDnode; diff --git a/source/libs/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index 79c72b3a35..c5a74d4840 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -147,8 +147,8 @@ static void (*transAsyncHandle[])(SSrvMsg* msg, SWorkThrdObj* thrd) = {uvHandleR static void uvDestroyConn(uv_handle_t* handle); // server and worker thread -static void* workerThread(void* arg); -static void* acceptThread(void* arg); +static void* transWorkerThread(void* arg); +static void* transAcceptThread(void* arg); // add handle loop static bool addHandleToWorkloop(void* arg); @@ -538,7 +538,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { } } -void* acceptThread(void* arg) { +void* transAcceptThread(void* arg) { // opt setThreadName("trans-accept"); SServerObj* srv = (SServerObj*)arg; @@ -596,7 +596,7 @@ static bool addHandleToAcceptloop(void* arg) { } return true; } -void* workerThread(void* arg) { +void* transWorkerThread(void* arg) { setThreadName("trans-worker"); SWorkThrdObj* pThrd = (SWorkThrdObj*)arg; uv_run(pThrd->loop, UV_RUN_DEFAULT); @@ -686,7 +686,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, if (false == addHandleToWorkloop(thrd)) { goto End; } - int err = taosThreadCreate(&(thrd->thread), NULL, workerThread, (void*)(thrd)); + int err = taosThreadCreate(&(thrd->thread), NULL, transWorkerThread, (void*)(thrd)); if (err == 0) { tDebug("sucess to create worker-thread %d", i); // printf("thread %d create\n", i); @@ -698,7 +698,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, if (false == addHandleToAcceptloop(srv)) { goto End; } - int err = taosThreadCreate(&srv->thread, NULL, acceptThread, (void*)srv); + int err = taosThreadCreate(&srv->thread, NULL, transAcceptThread, (void*)srv); if (err == 0) { tDebug("success to create accept-thread"); } else { From c6d2f6d2a167b702dd1c4ad38f6e10e662fcc5fe Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 14 Apr 2022 15:45:26 +0800 Subject: [PATCH 19/19] fix(cluster): mnode not start in multi-process mode --- source/dnode/mgmt/implement/src/dmExec.c | 6 ++++++ source/dnode/mgmt/mgmt_mnode/src/mmHandle.c | 1 - tests/script/jenkins/basic.txt | 3 ++- tests/script/tsim/db/error1.sim | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c index 36e135b9de..f66e7cd9d3 100644 --- a/source/dnode/mgmt/implement/src/dmExec.c +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -148,6 +148,12 @@ int32_t dmStartNode(SMgmtWrapper *pWrapper) { dInfo("node:%s, not start in parent process", pWrapper->name); } else if (pWrapper->procType == DND_PROC_CHILD) { dInfo("node:%s, start in child process", pWrapper->name); + if (pWrapper->ntype != DNODE) { + if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } } else { if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) { dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index c6149a9a7e..91c4724372 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -175,7 +175,6 @@ void mmInitMsgHandle(SMgmtWrapper *pWrapper) { dmSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_SHOW, mmProcessReadMsg, DEFAULT_HANDLE); - dmSetMsgHandle(pWrapper, TDMT_MND_SHOW_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE); diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 35476980b1..aef60fd8b7 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -81,7 +81,8 @@ # --- for multi process mode ./test.sh -f tsim/user/basic1.sim -m ./test.sh -f tsim/db/basic3.sim -m -./test.sh -f tsim/insert/backquote.sim +./test.sh -f tsim/db/error1.sim -m +./test.sh -f tsim/insert/backquote.sim -m ./test.sh -f tsim/parser/fourArithmetic-basic.sim -m ./test.sh -f tsim/query/interval-offset.sim -m ./test.sh -f tsim/tmq/basic.sim -m diff --git a/tests/script/tsim/db/error1.sim b/tests/script/tsim/db/error1.sim index 2e00143eb9..3460647bc9 100644 --- a/tests/script/tsim/db/error1.sim +++ b/tests/script/tsim/db/error1.sim @@ -62,7 +62,7 @@ print ========== stop dnode2 system sh/exec.sh -n dnode2 -s stop -x SIGKILL sleep 1000 -print =============== create database +print =============== drop database sql_error drop database d1 print ========== start dnode2