From 4cf20418cdd0d446517184077521c49ed349f562 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 26 Jul 2022 18:00:50 +0800 Subject: [PATCH 01/35] feat: support batch fetch in catalog --- include/common/tmsg.h | 22 ++ include/common/tmsgdef.h | 1 + source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 1 + source/dnode/vnode/src/inc/vnd.h | 4 +- source/dnode/vnode/src/vnd/vnodeQuery.c | 135 +++++++- source/dnode/vnode/src/vnd/vnodeSvr.c | 8 +- source/libs/catalog/inc/catalogInt.h | 18 + source/libs/catalog/inc/ctgRemote.h | 3 +- source/libs/catalog/src/ctgAsync.c | 21 +- source/libs/catalog/src/ctgRemote.c | 363 ++++++++++++++++++-- source/libs/catalog/src/ctgUtil.c | 34 +- source/libs/qcom/src/querymsg.c | 1 + 12 files changed, 559 insertions(+), 52 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 0d0eb841bc..9d23557ee7 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -3045,6 +3045,28 @@ typedef struct SDeleteRes { int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes); int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes); +typedef struct { + int32_t msgType; + int32_t msgLen; + void* msg; +} SBatchMsg; + +typedef struct { + int32_t reqType; + int32_t msgLen; + int32_t rspCode; + void* msg; +} SBatchRsp; + +static FORCE_INLINE void tFreeSBatchRsp(void *p) { + if (NULL == p) { + return; + } + + SBatchRsp* pRsp = (SBatchRsp*); + taosMemoryFree(pRsp->msg); +} + #pragma pack(pop) #ifdef __cplusplus diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 56e0935ce1..2d5a703b62 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -180,6 +180,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_TABLE_META, "vnode-table-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_TABLES_META, "vnode-tables-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_TABLE_CFG, "vnode-table-cfg", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_BATCH_META, "vnode-batch-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL) diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 0471e2b850..9ef2350b6b 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -336,6 +336,7 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_UPDATE_TAG_VAL, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_TABLE_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_TABLE_CFG, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_BATCH_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_TABLES_META, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SCH_CANCEL_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SCH_DROP_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 984b34814d..44281ea38e 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -78,8 +78,8 @@ void vnodeBufPoolReset(SVBufPool* pPool); // vnodeQuery.c int32_t vnodeQueryOpen(SVnode* pVnode); void vnodeQueryClose(SVnode* pVnode); -int32_t vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg); -int vnodeGetTableCfg(SVnode* pVnode, SRpcMsg* pMsg); +int32_t vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg, bool direct); +int vnodeGetTableCfg(SVnode* pVnode, SRpcMsg* pMsg, bool direct); // vnodeCommit.c int32_t vnodeBegin(SVnode* pVnode); diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 1c3e2f0514..bf846dba13 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -21,7 +21,7 @@ int vnodeQueryOpen(SVnode *pVnode) { void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); } -int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { +int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { STableInfoReq infoReq = {0}; STableMetaRsp metaRsp = {0}; SMetaReader mer1 = {0}; @@ -99,7 +99,12 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { goto _exit; } - pRsp = rpcMallocCont(rspLen); + if (direct) { + pRsp = rpcMallocCont(rspLen); + } else { + pRsp = taosMemoryCalloc(1, rspLen); + } + if (pRsp == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; @@ -117,15 +122,17 @@ _exit: qError("get table %s meta failed cause of %s", infoReq.tbName, tstrerror(code)); } - tmsgSendRsp(&rpcMsg); - + if (direct) { + tmsgSendRsp(&rpcMsg); + } + taosMemoryFree(metaRsp.pSchemas); metaReaderClear(&mer2); metaReaderClear(&mer1); return TSDB_CODE_SUCCESS; } -int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg) { +int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { STableCfgReq cfgReq = {0}; STableCfgRsp cfgRsp = {0}; SMetaReader mer1 = {0}; @@ -209,7 +216,12 @@ int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg) { goto _exit; } - pRsp = rpcMallocCont(rspLen); + if (direct) { + pRsp = rpcMallocCont(rspLen); + } else { + pRsp = taosMemoryCalloc(1, rspLen); + } + if (pRsp == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; @@ -227,14 +239,121 @@ _exit: qError("get table %s cfg failed cause of %s", cfgReq.tbName, tstrerror(code)); } - tmsgSendRsp(&rpcMsg); - + if (direct) { + tmsgSendRsp(&rpcMsg); + } + tFreeSTableCfgRsp(&cfgRsp); metaReaderClear(&mer2); metaReaderClear(&mer1); return TSDB_CODE_SUCCESS; } +int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { + int32_t code = 0; + int32_t offset = 0; + int32_t rspSize = 0; + int32_t msgNum = ntohl(pMsg->pCont); + offset += sizeof(msgNum); + SBatchMsg req = {0}; + SBatchRsp rsp = {0}; + SRpcMsg reqMsg = *pMsg; + SRpcMsg rspMsg = {0}; + void* pRsp = NULL; + + SArray* batchRsp = taosArrayInit(msgNum, sizeof(SBatchRsp)); + if (NULL == batchRsp) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + for (int32_t i = 0; i < msgNum; ++i) { + req.msgType = ntohl((char*)pMsg->pCont + offset); + offset += req.msgType; + + req.msgLen = ntohl((char*)pMsg->pCont + offset); + offset += req.msgLen; + + req.msg = (char*)pMsg->pCont + offset; + offset += req.msgLen; + + reqMsg.msgType = req.msgType; + reqMsg.pCont = req.msg; + reqMsg.contLen = req.msgLen; + + switch (req.msgType) { + case TDMT_VND_TABLE_META: + vnodeGetTableMeta(pVnode, &reqMsg, false); + break; + case TDMT_VND_TABLE_CFG: + vnodeGetTableCfg(pVnode, &reqMsg, false); + break; + default: + qError("invalid req msgType %d", req.msgType); + reqMsg.code = TSDB_CODE_INVALID_MSG; + reqMsg.pCont = NULL; + reqMsg.contLen = 0; + break; + } + + rsp.reqType = reqMsg.msgType; + rsp.msgLen = reqMsg.contLen; + rsp.rspCode = reqMsg.code; + rsp.msg = reqMsg.pCont; + + taosArrayPush(batchRsp, &rsp); + + rspSize += sizeof(rsp) + rsp.msgLen - POINTER_BYTES; + } + + rspSize += sizeof(int32_t); + offset = 0; + + pRsp = rpcMallocCont(rspSize); + if (pRsp == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + *(int32_t*)((char*)pRsp + offset) = htonl(msgNum); + offset += sizeof(msgNum); + for (int32_t i = 0; i < msgNum; ++i) { + SBatchRsp *p = taosArrayGet(batchRsp, i); + + *(int32_t*)((char*)pRsp + offset) = htonl(p->reqType); + offset += sizeof(p->reqType); + *(int32_t*)((char*)pRsp + offset) = htonl(p->msgLen); + offset += sizeof(p->msgLen); + *(int32_t*)((char*)pRsp + offset) = htonl(p->rspCode); + offset += sizeof(p->rspCode); + memcpy((char*)pRsp + offset, p->msg, p->msgLen); + offset += p->msgLen; + + taosMemoryFreeClear(p->msg); + } + + taosArrayDestroy(batchRsp); + batchRsp = NULL; + +_exit: + + rspMsg.info = pMsg->info; + rspMsg.pCont = pRsp; + rspMsg.contLen = rspSize; + rspMsg.code = code; + rspMsg.msgType = pMsg->msgType; + + if (code) { + qError("get batch meta failed cause of %s", tstrerror(code)); + } + + taosArrayDestroyEx(batchRsp, tFreeSBatchRsp); + + tmsgSendRsp(&rspMsg); + + return TSDB_CODE_SUCCESS; +} + int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { pLoad->vgId = TD_VID(pVnode); pLoad->syncState = syncGetMyRole(pVnode->sync); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 9d06fbffdd..830ab6e37c 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -296,7 +296,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { vTrace("message in fetch queue is processing"); if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || - pMsg->msgType == TDMT_VND_TABLE_CFG) && + pMsg->msgType == TDMT_VND_TABLE_CFG || pMsg->msgType = TDMT_VND_BATCH_META) && !vnodeIsLeader(pVnode)) { vnodeRedirectRpcMsg(pVnode, pMsg); return 0; @@ -318,9 +318,11 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { case TDMT_SCH_QUERY_HEARTBEAT: return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0); case TDMT_VND_TABLE_META: - return vnodeGetTableMeta(pVnode, pMsg); + return vnodeGetTableMeta(pVnode, pMsg, true); case TDMT_VND_TABLE_CFG: - return vnodeGetTableCfg(pVnode, pMsg); + return vnodeGetTableCfg(pVnode, pMsg, true); + case TDMT_VND_BATCH_META: + return vnodeGetBatchMeta(pVnode, pMsg); case TDMT_VND_CONSUME: return tqProcessPollReq(pVnode->pTq, pMsg); case TDMT_STREAM_TASK_RUN: diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index bf3bc1f0f4..4bd85792cd 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -31,6 +31,7 @@ extern "C" { #define CTG_DEFAULT_RENT_SECOND 10 #define CTG_DEFAULT_RENT_SLOT_SIZE 10 #define CTG_DEFAULT_MAX_RETRY_TIMES 3 +#define CTG_DEFAULT_BATCH_NUM 64 #define CTG_RENT_SLOT_SECOND 1.5 @@ -38,6 +39,8 @@ extern "C" { #define CTG_ERR_CODE_TABLE_NOT_EXIST TSDB_CODE_PAR_TABLE_NOT_EXIST +#define CTG_BATCH_FETCH 1 + enum { CTG_READ = 1, CTG_WRITE, @@ -200,8 +203,20 @@ typedef struct SCatalog { SCtgRentMgmt stbRent; } SCatalog; +typedef struct SCtgBatch { + int32_t batchId; + int32_t msgType; + int32_t msgSize; + SArray* pMsgs; + SRequestConnInfo *pConn; + char dbFName[TSDB_DB_FNAME_LEN]; + SArray* pTaskIds; +} SCtgBatch; + typedef struct SCtgJob { int64_t refId; + int32_t batchId; + SHashObj* pBatchs; SArray* pTasks; int32_t taskDone; SMetaData jobRes; @@ -258,6 +273,7 @@ typedef struct SCtgTask { SRWLatch lock; SArray* pParents; SCtgSubRes subRes; + SHashObj* pBatchs; } SCtgTask; typedef int32_t (*ctgInitTaskFp)(SCtgJob*, int32_t, void*); @@ -626,6 +642,8 @@ int32_t ctgLaunchSubTask(SCtgTask *pTask, CTG_TASK_TYPE type, ctgSubTaskCbFp fp, int32_t ctgGetTbCfgCb(SCtgTask *pTask); void ctgFreeHandle(SCatalog* pCatalog); +void ctgFreeBatch(SCtgBatch *pBatch); +void ctgFreeBatchs(SHashObj *pBatchs); int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst); int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput); int32_t ctgGenerateVgList(SCatalog *pCtg, SHashObj *vgHash, SArray** pList); diff --git a/source/libs/catalog/inc/ctgRemote.h b/source/libs/catalog/inc/ctgRemote.h index cd88863c1b..72ab43e085 100644 --- a/source/libs/catalog/inc/ctgRemote.h +++ b/source/libs/catalog/inc/ctgRemote.h @@ -23,8 +23,9 @@ extern "C" { typedef struct SCtgTaskCallbackParam { uint64_t queryId; int64_t refId; - uint64_t taskId; + SArray* taskId; int32_t reqType; + int32_t batchId; } SCtgTaskCallbackParam; diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 920acbac2e..65c6a0f76b 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -473,8 +473,15 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const pJob->tbCfgNum = tbCfgNum; pJob->svrVerNum = svrVerNum; - pJob->pTasks = taosArrayInit(taskNum, sizeof(SCtgTask)); +#if CTG_BATCH_FETCH + pJob->pBatchs = taosHashInit(CTG_DEFAULT_BATCH_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (NULL == pJob->pBatchs) { + ctgError("taosHashInit %d batch failed", CTG_DEFAULT_BATCH_NUM); + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } +#endif + pJob->pTasks = taosArrayInit(taskNum, sizeof(SCtgTask)); if (NULL == pJob->pTasks) { ctgError("taosArrayInit %d tasks failed", taskNum); CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); @@ -560,7 +567,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const _return: - taosMemoryFreeClear(*job); + ctgFreeJob(*job); CTG_RET(code); } @@ -872,7 +879,7 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf * SVgroupInfo vgInfo = {0}; CTG_ERR_JRET(ctgGetVgInfoFromHashValue(pCtg, dbCache->vgCache.vgInfo, ctx->pName, &vgInfo)); - ctgDebug("will refresh tbmeta, not supposed to be stb, tbName:%s, flag:%d", tNameGetTableName(ctx->pName), ctx->flag); + ctgDebug("will refresh tbmeta, supposed to be stb, tbName:%s, flag:%d", tNameGetTableName(ctx->pName), ctx->flag); ctx->vgId = vgInfo.vgId; CTG_ERR_JRET(ctgGetTbMetaFromVnode(pCtg, pConn, ctx->pName, &vgInfo, NULL, pTask)); @@ -890,7 +897,7 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf * return TSDB_CODE_SUCCESS; } - ctgError("no tbmeta got, tbNmae:%s", tNameGetTableName(ctx->pName)); + ctgError("no tbmeta got, tbName:%s", tNameGetTableName(ctx->pName)); ctgRemoveTbMetaFromCache(pCtg, ctx->pName, false); CTG_ERR_JRET(CTG_ERR_CODE_TABLE_NOT_EXIST); @@ -1705,13 +1712,19 @@ int32_t ctgLaunchJob(SCtgJob *pJob) { qDebug("QID:0x%" PRIx64 " ctg launch [%dth] task", pJob->queryId, pTask->taskId); CTG_ERR_RET((*gCtgAsyncFps[pTask->type].launchFp)(pTask)); + pTask->status = CTG_TASK_LAUNCHED; + pTask->pBatchs = pJob->pBatchs; } if (taskNum <= 0) { qDebug("QID:0x%" PRIx64 " ctg call user callback with rsp %s", pJob->queryId, tstrerror(pJob->jobResCode)); taosAsyncExec(ctgCallUserCb, pJob, NULL); +#if CTG_BATCH_FETCH + } else { + ctgLaunchBatchs(pJob->pCtg, pJob, pJob->pBatchs); +#endif } return TSDB_CODE_SUCCESS; diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index cc5dde9298..04ffbca629 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -21,6 +21,64 @@ #include "ctgRemote.h" #include "tref.h" +int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBuf *pMsg, int32_t rspCode) { + int32_t code = 0; + SArray* pTaskId = cbParam->taskId; + int32_t taskNum = taosArrayGetSize(pTaskId); + SDataBuf taskMsg = *pMsg; + int32_t offset = 0; + int32_t msgNum = (pMsg->pData && (pMsg->len > 0)) ? htonl(pMsg->pData) : 0; + ASSERT(taskNum == msgNum || 0 == msgNum); + + qDebug("QID:0x%" PRIx64 " ctg got batch %d rsp %s", pJob->queryId, cbParam->batchId, TMSG_INFO(cbParam->reqType + 1)); + + offset += sizeof(msgNum); + SBatchRsp rsp = {0}; + SHashObj* pBatchs = taosHashInit(taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (NULL == pBatchs) { + ctgError("taosHashInit %d batch failed", taskNum); + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + + for (int32_t i = 0; i < taskNum; ++i) { + int32_t taskId = taosArrayGet(pTaskId, i); + SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskId); + if (msgNum > 0) { + rsp.reqType = htonl(((char*)pMsg->pData) + offset); + offset += sizeof(rsp.reqType); + rsp.msgLen = htonl(((char*)pMsg->pData) + offset); + offset += sizeof(rsp.msgLen); + rsp.rspCode = htonl(((char*)pMsg->pData) + offset); + offset += sizeof(rsp.rspCode); + rsp.msg = ((char*)pMsg->pData) + offset; + offset += rsp.msgLen; + + taskMsg.msgType = rsp.reqType; + taskMsg.pData = rsp.msg; + taskMsg.len = rsp.msgLen; + } else { + rsp.reqType = -1; + taskMsg.msgType = -1; + taskMsg.pData = NULL; + taskMsg.len = 0; + } + + pTask->pBatchs = pBatchs; + + qDebug("QID:0x%" PRIx64 " ctg task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(taskMsg.msgType + 1)); + + (*gCtgAsyncFps[pTask->type].handleRspFp)(pTask, rsp.reqType, &taskMsg, (rsp.rspCode ? rsp.rspCode : rspCode)); + } + + CTG_ERR_JRET(ctgLaunchBatchs(pJob->pCtg, pJob, pBatchs)); + +_return: + + ctgFreeBatchs(pBatchs); + CTG_RET(code); +} + + int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, int32_t rspCode, char* target) { int32_t code = 0; @@ -233,6 +291,11 @@ int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, break; } default: + if (TSDB_CODE_SUCCESS != rspCode) { + qError("Got error rsp, error:%s", tstrerror(rspCode)); + CTG_ERR_RET(rspCode); + } + qError("invalid req type %s", TMSG_INFO(reqType)); return TSDB_CODE_APP_ERROR; } @@ -254,12 +317,17 @@ int32_t ctgHandleMsgCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { goto _return; } - SCtgTask *pTask = taosArrayGet(pJob->pTasks, cbParam->taskId); + if (TDMT_VND_BATCH_META == cbParam->reqType || TDMT_MND_BATCH_META == cbParam->reqType) { + CTG_ERR_JRET(ctgHandleBatchRsp(pJob, cbParam, pMsg, rspCode)); + } else { + int32_t taskId = taosArrayGet(cbParam->taskId, 0); + SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskId); - qDebug("QID:0x%" PRIx64 " ctg task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(cbParam->reqType + 1)); + qDebug("QID:0x%" PRIx64 " ctg task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(cbParam->reqType + 1)); + + CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].handleRspFp)(pTask, cbParam->reqType, pMsg, rspCode)); + } - CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].handleRspFp)(pTask, cbParam->reqType, pMsg, rspCode)); - _return: taosMemoryFree(pMsg->pData); @@ -272,7 +340,7 @@ _return: } -int32_t ctgMakeMsgSendInfo(SCtgTask* pTask, int32_t msgType, SMsgSendInfo **pMsgSendInfo) { +int32_t ctgMakeMsgSendInfo(SCtgJob* pJob, SArray* pTaskId, int32_t batchId, int32_t msgType, SMsgSendInfo **pMsgSendInfo) { int32_t code = 0; SMsgSendInfo *msgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == msgSendInfo) { @@ -287,9 +355,10 @@ int32_t ctgMakeMsgSendInfo(SCtgTask* pTask, int32_t msgType, SMsgSendInfo **pMsg } param->reqType = msgType; - param->queryId = pTask->pJob->queryId; - param->refId = pTask->pJob->refId; - param->taskId = pTask->taskId; + param->queryId = pJob->queryId; + param->refId = pJob->refId; + param->taskId = pTaskId; + param->batchId = batchId; msgSendInfo->param = param; msgSendInfo->paramFreeFp = taosMemoryFree; @@ -307,12 +376,13 @@ _return: CTG_RET(code); } -int32_t ctgAsyncSendMsg(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTask* pTask, int32_t msgType, void *msg, uint32_t msgSize) { +int32_t ctgAsyncSendMsg(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob* pJob, SArray* pTaskId, + int32_t batchId, char* dbFName, int32_t vgId, int32_t msgType, void *msg, uint32_t msgSize) { int32_t code = 0; SMsgSendInfo *pMsgSendInfo = NULL; - CTG_ERR_JRET(ctgMakeMsgSendInfo(pTask, msgType, &pMsgSendInfo)); + CTG_ERR_JRET(ctgMakeMsgSendInfo(pJob, pTaskId, batchId, msgType, &pMsgSendInfo)); - ctgUpdateSendTargetInfo(pMsgSendInfo, msgType, pTask); + ctgUpdateSendTargetInfo(pMsgSendInfo, msgType, dbFName, vgId); pMsgSendInfo->requestId = pConn->requestId; pMsgSendInfo->requestObjRefId = pConn->requestObjRefId; @@ -328,19 +398,163 @@ int32_t ctgAsyncSendMsg(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgTask* pTask CTG_ERR_JRET(code); } - ctgDebug("ctg req msg sent, reqId:0x%" PRIx64 ", msg type:%d, %s", pTask->pJob->queryId, msgType, TMSG_INFO(msgType)); + ctgDebug("ctg req msg sent, reqId:0x%" PRIx64 ", msg type:%d, %s", pJob->queryId, msgType, TMSG_INFO(msgType)); return TSDB_CODE_SUCCESS; _return: if (pMsgSendInfo) { - taosMemoryFreeClear(pMsgSendInfo->param); - taosMemoryFreeClear(pMsgSendInfo); + destroySendMsgInfo(pMsgSendInfo); } CTG_RET(code); } +int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo *pConn, SCtgTask* pTask, int32_t msgType, void *msg, uint32_t msgSize) { + int32_t code = 0; + SHashObj* pBatchs = pTask->pBatchs; + SCtgJob* pJob = pTask->pJob; + SCtgBatch* pBatch = taosHashGet(pBatchs, &vgId, sizeof(vgId)); + int32_t taskNum = taosArrayGetSize(pTask->pJob->pTasks); + SCtgBatch newBatch = {0}; + SBatchMsg req = {0}; + + if (NULL == pBatch) { + newBatch.pMsgs = taosArrayInit(taskNum, sizeof(SBatchMsg)); + newBatch.pTaskIds = taosArrayInit(taskNum, sizeof(int32_t)); + if (NULL == newBatch.pMsgs || NULL == newBatch.pTaskIds) { + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } + + newBatch.pConn = pConn; + + req.msgType = msgType; + req.msgLen = msgSize; + req.msg = msg; + if (NULL == taosArrayPush(newBatch.pMsgs, &req)) { + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } + if (NULL == taosArrayPush(newBatch.pTaskIds, &pTask->taskId)) { + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } + newBatch.msgSize = sizeof(req) + msgSize - POINTER_BYTES; + + if (vgId > 0) { + if (TDMT_VND_TABLE_CFG == msgType) { + SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx; + tNameGetFullDbName(ctx->pName, newBatch.dbFName); + } else if (TDMT_VND_TABLE_META == msgType) { + SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx; + tNameGetFullDbName(ctx->pName, newBatch.dbFName); + } else { + ctgError("invalid vnode msgType %d", msgType); + CTG_ERR_JRET(TSDB_CODE_APP_ERROR); + } + } + + newBatch.msgType = (vgId > 0) ? TDMT_VND_BATCH_META : TDMT_MND_BATCH_META; + newBatch.batchId = atomic_add_fetch_32(&pJob->batchId, 1); + + if (0 != taosHashPut(pBatchs, &vgId, sizeof(vgId), &newBatch, sizeof(newBatch))) { + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } + + ctgDebug("task %d %s req added to batch %d, target vgId %d", pTask->taskId, TMSG_INFO(msgType), newBatch->batchId, vgId); + + return TSDB_CODE_SUCCESS; + } + + req.msgType = msgType; + req.msgLen = msgSize; + req.msg = msg; + if (NULL == taosArrayPush(pBatch->pMsgs, &req)) { + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } + if (NULL == taosArrayPush(pBatch->pTaskIds, &pTask->taskId)) { + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } + pBatch->msgSize += sizeof(req) + msgSize - POINTER_BYTES; + + if (vgId > 0) { + if (TDMT_VND_TABLE_CFG == msgType) { + SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx; + tNameGetFullDbName(ctx->pName, newBatch.dbFName); + } else if (TDMT_VND_TABLE_META == msgType) { + SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx; + tNameGetFullDbName(ctx->pName, newBatch.dbFName); + } else { + ctgError("invalid vnode msgType %d", msgType); + CTG_ERR_JRET(TSDB_CODE_APP_ERROR); + } + } + + ctgDebug("task %d %s req added to batch %d, target vgId %d", pTask->taskId, TMSG_INFO(msgType), pBatch->batchId, vgId); + + return TSDB_CODE_SUCCESS; + +_return: + + ctgFreeBatch(&newBatch); + taosMemoryFree(msg); + + return code; +} + +int32_t ctgBuildBatchReqMsg(SCtgBatch* pBatch, void** msg) { + *msg = taosMemoryMalloc(pBatch->msgSize); + if (NULL == (*msg)) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + + int32_t offset = 0; + int32_t num = taosArrayGetSize(pBatch->pMsgs); + *(int32_t*)((char*)(*msg) + offset) = htonl(num); + offset += sizeof(num); + + for (int32_t i = 0; i < num; ++i) { + SBatchMsg* pReq = taosArrayGet(pBatch->pMsgs, i); + *(int32_t*)((char*)(*msg) + offset) = htonl(pReq->msgType); + offset += sizeof(pReq->msgType); + *(int32_t*)((char*)(*msg) + offset) = htonl(pReq->msgLen); + offset += sizeof(pReq->msgLen); + memcpy((char*)(*msg) + offset, pReq->msg, pReq->msgLen); + offset += pReq->msgLen; + } + + ASSERT(pBatch->msgSize == offset); + + return TSDB_CODE_SUCCESS; +} + +int32_t ctgLaunchBatchs(SCatalog* pCtg, SCtgJob *pJob, SHashObj* pBatchs) { + int32_t code = 0; + void* msg = NULL; + void* p = taosHashIterate(pBatchs, NULL); + while (NULL != p) { + size_t len = 0; + int32_t* vgId = taosHashGetKey(p, &len); + SCtgBatch* pBatch = (SCtgBatch*)p; + + CTG_ERR_JRET(ctgBuildBatchReqMsg(pBatch, &msg)); + CTG_ERR_JRET(ctgAsyncSendMsg(pCtg, pBatch->pConn, pJob, pBatch->pTaskIds, pBatch->batchId, + pBatch->dbFName, *vgId, pBatch->msgType, msg, pBatch->msgSize)); + + p = taosHashIterate(pBatchs, p); + } + + return TSDB_CODE_SUCCESS; + +_return: + + if (p) { + taosHashCancelIterate(pBatchs, p); + } + taosMemoryFree(msg); + + CTG_RET(code); +} + + int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray *out, SCtgTask* pTask) { char *msg = NULL; int32_t msgLen = 0; @@ -361,7 +575,14 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, NULL)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -396,7 +617,14 @@ int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray if (pTask) { CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, NULL, NULL)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -436,8 +664,14 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SBuildU CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, input->db)); + + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -476,8 +710,14 @@ int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)dbFName)); + + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -517,7 +757,13 @@ int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)indexName)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -560,7 +806,13 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SName *n CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)tbFName)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -600,7 +852,13 @@ int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const ch } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)funcName)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -640,7 +898,13 @@ int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)user)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -685,7 +949,13 @@ int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo *pConn, char } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, tbFName)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -744,7 +1014,21 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SNa .requestId = pConn->requestId, .requestObjRefId = pConn->requestObjRefId, .mgmtEps = vgroupInfo->epSet}; - CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask, reqType, msg, msgLen)); + +#if CTG_BATCH_FETCH + CTG_RET(ctgAddVnodeBatch(pCtg, vgroupInfo->vgId, &vConn, pTask, reqType, msg, msgLen)); +#else + SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx; + char dbFName[TSDB_DB_FNAME_LEN]; + tNameGetFullDbName(ctx->pName, dbFName); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, dbFName, ctx->vgId, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -791,7 +1075,20 @@ int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo *pConn, const S .requestId = pConn->requestId, .requestObjRefId = pConn->requestObjRefId, .mgmtEps = vgroupInfo->epSet}; - CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask, reqType, msg, msgLen)); +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, vgroupInfo->vgId, &vConn, pTask, reqType, msg, msgLen)); +#else + SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx; + char dbFName[TSDB_DB_FNAME_LEN]; + tNameGetFullDbName(ctx->pName, dbFName); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, dbFName, ctx->pVgInfo->vgId, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -833,7 +1130,13 @@ int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const S if (pTask) { CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, NULL, (char*)tbFName)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { @@ -869,7 +1172,13 @@ int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, char **ou if (pTask) { CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, NULL, NULL)); - CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask, reqType, msg, msgLen)); + SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); + if (NULL == pTaskId) { + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + taosArrayPush(pTaskId, &pTask->taskId); + + CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); } SRpcMsg rpcMsg = { diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 1f0f074a0f..8d33e5596f 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -19,6 +19,29 @@ #include "catalogInt.h" #include "systable.h" + +void ctgFreeBatch(SCtgBatch *pBatch) { + if (NULL == pBatch) { + return; + } + + taosArrayDestroy(pBatch->pMsgs); + taosArrayDestroy(pBatch->pTaskIds); +} + +void ctgFreeBatchs(SHashObj *pBatchs) { + void* p = taosHashIterate(pBatchs, NULL); + while (NULL != p) { + SCtgBatch* pBatch = (SCtgBatch*)p; + + ctgFreeBatch(pBatch); + + p = taosHashIterate(pBatchs, p); + } + + taosHashCleanup(pBatchs); +} + char *ctgTaskTypeStr(CTG_TASK_TYPE type) { switch (type) { case CTG_TASK_GET_QNODE: @@ -612,6 +635,7 @@ void ctgFreeJob(void* job) { uint64_t qid = pJob->queryId; ctgFreeTasks(pJob->pTasks); + ctgFreeBatchs(pJob->pBatchs); ctgFreeSMetaData(&pJob->jobRes); @@ -867,14 +891,10 @@ int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes) { } -int32_t ctgUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, int32_t msgType, SCtgTask* pTask) { - if (msgType == TDMT_VND_TABLE_META) { - SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx; - char dbFName[TSDB_DB_FNAME_LEN]; - tNameGetFullDbName(ctx->pName, dbFName); - +int32_t ctgUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, int32_t msgType, char* dbFName, int32_t vgId) { + if (msgType == TDMT_VND_TABLE_META || msgType == TDMT_VND_TABLE_CFG || msgType == TDMT_VND_BATCH_META) { pMsgSendInfo->target.type = TARGET_TYPE_VNODE; - pMsgSendInfo->target.vgId = ctx->vgId; + pMsgSendInfo->target.vgId = vgId; pMsgSendInfo->target.dbFName = strdup(dbFName); } else { pMsgSendInfo->target.type = TARGET_TYPE_MNODE; diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index ed8786170d..78ecde6003 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -636,6 +636,7 @@ void initQueryModuleMsgHandle() { queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_BATCH_META)] = queryProcessGetBatchMetaRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp; } From 2884b36d5fe31f46aace849f9dded53991a8a120 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 26 Jul 2022 20:07:28 +0800 Subject: [PATCH 02/35] fix(query): fix sum(null) or sum(nullexpr) result to null --- source/libs/function/src/builtinsimpl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 5ad433c9ff..18bc74e57d 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -466,7 +466,7 @@ int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0; + pResInfo->isNullRes = (pResInfo->isNullRes == 1) ? 1 : (pResInfo->numOfRes == 0) ? 1 : 0; char* in = GET_ROWCELL_INTERBUF(pResInfo); colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes); @@ -662,8 +662,9 @@ int32_t sumFunction(SqlFunctionCtx* pCtx) { } // check for overflow - if (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum))) { - numOfElem = 0; + if (numOfElem == 0 || (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum)))) { + GET_RES_INFO(pCtx)->isNullRes = 1; + numOfElem = 1; } _sum_over: From 2dc24b26922d355c5ae54e16e7566c6b4c53ccaa Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 26 Jul 2022 20:07:28 +0800 Subject: [PATCH 03/35] fix(query): fix max/min with null input --- source/libs/function/src/builtinsimpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 18bc74e57d..790f5d03a3 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -466,7 +466,7 @@ int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx); - pResInfo->isNullRes = (pResInfo->isNullRes == 1) ? 1 : (pResInfo->numOfRes == 0) ? 1 : 0; + pResInfo->isNullRes = (pResInfo->isNullRes == 1) ? 1 : (pResInfo->numOfRes == 0); char* in = GET_ROWCELL_INTERBUF(pResInfo); colDataAppend(pCol, pBlock->info.rows, in, pResInfo->isNullRes); @@ -1606,7 +1606,7 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t currentRow = pBlock->info.rows; SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); - pEntryInfo->isNullRes = (pEntryInfo->numOfRes == 0); + pEntryInfo->isNullRes = (pEntryInfo->isNullRes == 1) ? 1 : (pEntryInfo->numOfRes == 0); if (pCol->info.type == TSDB_DATA_TYPE_FLOAT) { float v = *(double*)&pRes->v; From 320525edf988c75b816da3c43de6370c8fec5c94 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 26 Jul 2022 20:07:28 +0800 Subject: [PATCH 04/35] fix(query): fix max/min with null input --- source/libs/function/src/builtinsimpl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 790f5d03a3..bc24f54b52 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1577,6 +1577,11 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { } } + if (numOfElems == 0) { + GET_RES_INFO(pCtx)->isNullRes = 1; + numOfElems = 1; + } + _min_max_over: return numOfElems; } From c0091afb018eb2cc9b67471afbb3ebf2b16ecc8c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 26 Jul 2022 20:23:13 +0800 Subject: [PATCH 05/35] Merge branch '3.0' into enh/TD-17659 --- source/libs/function/src/builtinsimpl.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 06011b2641..fb82ab206c 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -662,7 +662,7 @@ int32_t sumFunction(SqlFunctionCtx* pCtx) { } // check for overflow - if (numOfElem == 0 || (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum)))) { + if (IS_FLOAT_TYPE(type) && (isinf(pSumRes->dsum) || isnan(pSumRes->dsum))) { GET_RES_INFO(pCtx)->isNullRes = 1; numOfElem = 1; } @@ -1577,11 +1577,6 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { } } - if (numOfElems == 0) { - GET_RES_INFO(pCtx)->isNullRes = 1; - numOfElems = 1; - } - _min_max_over: return numOfElems; } From 602d2197fb599b85c0f9d26c5ef525cbfb8be26c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 27 Jul 2022 08:27:24 +0800 Subject: [PATCH 06/35] feat: support vnode meta batch fetching --- include/common/tmsg.h | 8 +++- include/common/tmsgdef.h | 1 + source/dnode/vnode/src/inc/vnd.h | 1 + source/dnode/vnode/src/vnd/vnodeQuery.c | 17 ++++--- source/dnode/vnode/src/vnd/vnodeSvr.c | 2 +- source/libs/catalog/inc/catalogInt.h | 5 +- source/libs/catalog/src/ctgAsync.c | 2 +- source/libs/catalog/src/ctgRemote.c | 62 +++++++++++++++++-------- source/libs/qcom/src/querymsg.c | 1 - 9 files changed, 67 insertions(+), 32 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 9d23557ee7..0571f8382a 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -3051,6 +3051,12 @@ typedef struct { void* msg; } SBatchMsg; +typedef struct { + SMsgHead header; + int32_t msgNum; + SBatchMsg msg[]; +} SBatchReq; + typedef struct { int32_t reqType; int32_t msgLen; @@ -3063,7 +3069,7 @@ static FORCE_INLINE void tFreeSBatchRsp(void *p) { return; } - SBatchRsp* pRsp = (SBatchRsp*); + SBatchRsp* pRsp = (SBatchRsp*)p; taosMemoryFree(pRsp->msg); } diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 2d5a703b62..20dc04631e 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -136,6 +136,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_DROP_INDEX, "drop-index", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_GET_INDEX, "get-index", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_GET_TABLE_INDEX, "get-table-index", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_BATCH_META, "batch-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TABLE_CFG, "table-cfg", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "create-topic", SMCreateTopicReq, SMCreateTopicRsp) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "alter-topic", NULL, NULL) diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 44281ea38e..dd1facb462 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -80,6 +80,7 @@ int32_t vnodeQueryOpen(SVnode* pVnode); void vnodeQueryClose(SVnode* pVnode); int32_t vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg, bool direct); int vnodeGetTableCfg(SVnode* pVnode, SRpcMsg* pMsg, bool direct); +int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg); // vnodeCommit.c int32_t vnodeBegin(SVnode* pVnode); diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index bf846dba13..6b36a66776 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -124,6 +124,8 @@ _exit: if (direct) { tmsgSendRsp(&rpcMsg); + } else { + *pMsg = rpcMsg; } taosMemoryFree(metaRsp.pSchemas); @@ -241,6 +243,8 @@ _exit: if (direct) { tmsgSendRsp(&rpcMsg); + } else { + *pMsg = rpcMsg; } tFreeSTableCfgRsp(&cfgRsp); @@ -253,8 +257,9 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { int32_t code = 0; int32_t offset = 0; int32_t rspSize = 0; - int32_t msgNum = ntohl(pMsg->pCont); - offset += sizeof(msgNum); + SBatchReq *batchReq = (SBatchReq*)pMsg->pCont; + int32_t msgNum = ntohl(batchReq->msgNum); + offset += sizeof(SBatchReq); SBatchMsg req = {0}; SBatchRsp rsp = {0}; SRpcMsg reqMsg = *pMsg; @@ -268,11 +273,11 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { } for (int32_t i = 0; i < msgNum; ++i) { - req.msgType = ntohl((char*)pMsg->pCont + offset); - offset += req.msgType; + req.msgType = ntohl(*(int32_t*)((char*)pMsg->pCont + offset)); + offset += sizeof(req.msgType); - req.msgLen = ntohl((char*)pMsg->pCont + offset); - offset += req.msgLen; + req.msgLen = ntohl(*(int32_t*)((char*)pMsg->pCont + offset)); + offset += sizeof(req.msgLen); req.msg = (char*)pMsg->pCont + offset; offset += req.msgLen; diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 830ab6e37c..f560d6a8c2 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -296,7 +296,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { vTrace("message in fetch queue is processing"); if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || - pMsg->msgType == TDMT_VND_TABLE_CFG || pMsg->msgType = TDMT_VND_BATCH_META) && + pMsg->msgType == TDMT_VND_TABLE_CFG || pMsg->msgType == TDMT_VND_BATCH_META) && !vnodeIsLeader(pVnode)) { vnodeRedirectRpcMsg(pVnode, pMsg); return 0; diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 4bd85792cd..0821a91d6b 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -208,7 +208,7 @@ typedef struct SCtgBatch { int32_t msgType; int32_t msgSize; SArray* pMsgs; - SRequestConnInfo *pConn; + SRequestConnInfo conn; char dbFName[TSDB_DB_FNAME_LEN]; SArray* pTaskIds; } SCtgBatch; @@ -634,6 +634,7 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SNa int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, SVgroupInfo *vgroupInfo, STableCfg **out, SCtgTask* pTask); int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName, STableCfg **out, SCtgTask* pTask); int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, char **out, SCtgTask* pTask); +int32_t ctgLaunchBatchs(SCatalog* pCtg, SCtgJob *pJob, SHashObj* pBatchs); int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp, void* param); int32_t ctgLaunchJob(SCtgJob *pJob); @@ -660,7 +661,7 @@ int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2); void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput); int32_t ctgUpdateMsgCtx(SCtgMsgCtx* pCtx, int32_t reqType, void* out, char* target); char * ctgTaskTypeStr(CTG_TASK_TYPE type); -int32_t ctgUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, int32_t msgType, SCtgTask* pTask); +int32_t ctgUpdateSendTargetInfo(SMsgSendInfo *pMsgSendInfo, int32_t msgType, char* dbFName, int32_t vgId); int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes); void ctgFreeSTableIndex(void *info); void ctgClearSubTaskRes(SCtgSubRes *pRes); diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 65c6a0f76b..9a666eb4ff 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -1709,12 +1709,12 @@ int32_t ctgLaunchJob(SCtgJob *pJob) { for (int32_t i = 0; i < taskNum; ++i) { SCtgTask *pTask = taosArrayGet(pJob->pTasks, i); + pTask->pBatchs = pJob->pBatchs; qDebug("QID:0x%" PRIx64 " ctg launch [%dth] task", pJob->queryId, pTask->taskId); CTG_ERR_RET((*gCtgAsyncFps[pTask->type].launchFp)(pTask)); pTask->status = CTG_TASK_LAUNCHED; - pTask->pBatchs = pJob->pBatchs; } if (taskNum <= 0) { diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index 04ffbca629..8b1d125a58 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -24,13 +24,14 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBuf *pMsg, int32_t rspCode) { int32_t code = 0; SArray* pTaskId = cbParam->taskId; + SCatalog* pCtg = pJob->pCtg; int32_t taskNum = taosArrayGetSize(pTaskId); SDataBuf taskMsg = *pMsg; int32_t offset = 0; - int32_t msgNum = (pMsg->pData && (pMsg->len > 0)) ? htonl(pMsg->pData) : 0; + int32_t msgNum = (pMsg->pData && (pMsg->len > 0)) ? ntohl(*(int32_t*)pMsg->pData) : 0; ASSERT(taskNum == msgNum || 0 == msgNum); - qDebug("QID:0x%" PRIx64 " ctg got batch %d rsp %s", pJob->queryId, cbParam->batchId, TMSG_INFO(cbParam->reqType + 1)); + ctgDebug("QID:0x%" PRIx64 " ctg got batch %d rsp %s", pJob->queryId, cbParam->batchId, TMSG_INFO(cbParam->reqType + 1)); offset += sizeof(msgNum); SBatchRsp rsp = {0}; @@ -41,14 +42,14 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu } for (int32_t i = 0; i < taskNum; ++i) { - int32_t taskId = taosArrayGet(pTaskId, i); - SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskId); + int32_t* taskId = taosArrayGet(pTaskId, i); + SCtgTask *pTask = taosArrayGet(pJob->pTasks, *taskId); if (msgNum > 0) { - rsp.reqType = htonl(((char*)pMsg->pData) + offset); + rsp.reqType = ntohl(*(int32_t*)((char*)pMsg->pData + offset)); offset += sizeof(rsp.reqType); - rsp.msgLen = htonl(((char*)pMsg->pData) + offset); + rsp.msgLen = ntohl(*(int32_t*)((char*)pMsg->pData + offset)); offset += sizeof(rsp.msgLen); - rsp.rspCode = htonl(((char*)pMsg->pData) + offset); + rsp.rspCode = ntohl(*(int32_t*)((char*)pMsg->pData + offset)); offset += sizeof(rsp.rspCode); rsp.msg = ((char*)pMsg->pData) + offset; offset += rsp.msgLen; @@ -65,7 +66,7 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu pTask->pBatchs = pBatchs; - qDebug("QID:0x%" PRIx64 " ctg task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(taskMsg.msgType + 1)); + ctgDebug("QID:0x%" PRIx64 " ctg task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(taskMsg.msgType + 1)); (*gCtgAsyncFps[pTask->type].handleRspFp)(pTask, rsp.reqType, &taskMsg, (rsp.rspCode ? rsp.rspCode : rspCode)); } @@ -317,15 +318,30 @@ int32_t ctgHandleMsgCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { goto _return; } + SCatalog* pCtg = pJob->pCtg; + if (TDMT_VND_BATCH_META == cbParam->reqType || TDMT_MND_BATCH_META == cbParam->reqType) { CTG_ERR_JRET(ctgHandleBatchRsp(pJob, cbParam, pMsg, rspCode)); } else { - int32_t taskId = taosArrayGet(cbParam->taskId, 0); - SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskId); + int32_t *taskId = taosArrayGet(cbParam->taskId, 0); + SCtgTask *pTask = taosArrayGet(pJob->pTasks, *taskId); qDebug("QID:0x%" PRIx64 " ctg task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(cbParam->reqType + 1)); - + +#if CTG_BATCH_FETCH + SHashObj* pBatchs = taosHashInit(CTG_DEFAULT_BATCH_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + if (NULL == pBatchs) { + ctgError("taosHashInit %d batch failed", CTG_DEFAULT_BATCH_NUM); + CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + pTask->pBatchs = pBatchs; +#endif + CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].handleRspFp)(pTask, cbParam->reqType, pMsg, rspCode)); + +#if CTG_BATCH_FETCH + CTG_ERR_JRET(ctgLaunchBatchs(pJob->pCtg, pJob, pBatchs)); +#endif } _return: @@ -393,6 +409,7 @@ int32_t ctgAsyncSendMsg(SCatalog* pCtg, SRequestConnInfo *pConn, SCtgJob* pJob, int64_t transporterId = 0; code = asyncSendMsgToServer(pConn->pTrans, &pConn->mgmtEps, &transporterId, pMsgSendInfo); + pMsgSendInfo = NULL; if (code) { ctgError("asyncSendMsgToSever failed, error: %s", tstrerror(code)); CTG_ERR_JRET(code); @@ -426,7 +443,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo *pConn, SCtgT CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } - newBatch.pConn = pConn; + newBatch.conn = *pConn; req.msgType = msgType; req.msgLen = msgSize; @@ -437,7 +454,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo *pConn, SCtgT if (NULL == taosArrayPush(newBatch.pTaskIds, &pTask->taskId)) { CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } - newBatch.msgSize = sizeof(req) + msgSize - POINTER_BYTES; + newBatch.msgSize = sizeof(SBatchReq) + sizeof(req) + msgSize - POINTER_BYTES; if (vgId > 0) { if (TDMT_VND_TABLE_CFG == msgType) { @@ -459,7 +476,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo *pConn, SCtgT CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } - ctgDebug("task %d %s req added to batch %d, target vgId %d", pTask->taskId, TMSG_INFO(msgType), newBatch->batchId, vgId); + ctgDebug("task %d %s req added to batch %d, target vgId %d", pTask->taskId, TMSG_INFO(msgType), newBatch.batchId, vgId); return TSDB_CODE_SUCCESS; } @@ -500,7 +517,7 @@ _return: return code; } -int32_t ctgBuildBatchReqMsg(SCtgBatch* pBatch, void** msg) { +int32_t ctgBuildBatchReqMsg(SCtgBatch* pBatch, int32_t vgId, void** msg) { *msg = taosMemoryMalloc(pBatch->msgSize); if (NULL == (*msg)) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -508,8 +525,11 @@ int32_t ctgBuildBatchReqMsg(SCtgBatch* pBatch, void** msg) { int32_t offset = 0; int32_t num = taosArrayGetSize(pBatch->pMsgs); - *(int32_t*)((char*)(*msg) + offset) = htonl(num); - offset += sizeof(num); + SBatchReq *pBatchReq = (SBatchReq*)(*msg); + + pBatchReq->header.vgId = htonl(vgId); + pBatchReq->msgNum = htonl(num); + offset += sizeof(SBatchReq); for (int32_t i = 0; i < num; ++i) { SBatchMsg* pReq = taosArrayGet(pBatch->pMsgs, i); @@ -534,9 +554,11 @@ int32_t ctgLaunchBatchs(SCatalog* pCtg, SCtgJob *pJob, SHashObj* pBatchs) { size_t len = 0; int32_t* vgId = taosHashGetKey(p, &len); SCtgBatch* pBatch = (SCtgBatch*)p; + + ctgDebug("QID:0x%" PRIx64 " ctg start to launch batch %d", pJob->queryId, pBatch->batchId); - CTG_ERR_JRET(ctgBuildBatchReqMsg(pBatch, &msg)); - CTG_ERR_JRET(ctgAsyncSendMsg(pCtg, pBatch->pConn, pJob, pBatch->pTaskIds, pBatch->batchId, + CTG_ERR_JRET(ctgBuildBatchReqMsg(pBatch, *vgId, &msg)); + CTG_ERR_JRET(ctgAsyncSendMsg(pCtg, &pBatch->conn, pJob, pBatch->pTaskIds, pBatch->batchId, pBatch->dbFName, *vgId, pBatch->msgType, msg, pBatch->msgSize)); p = taosHashIterate(pBatchs, p); @@ -1016,7 +1038,7 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo *pConn, const SNa .mgmtEps = vgroupInfo->epSet}; #if CTG_BATCH_FETCH - CTG_RET(ctgAddVnodeBatch(pCtg, vgroupInfo->vgId, &vConn, pTask, reqType, msg, msgLen)); + CTG_RET(ctgAddBatch(pCtg, vgroupInfo->vgId, &vConn, pTask, reqType, msg, msgLen)); #else SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx; char dbFName[TSDB_DB_FNAME_LEN]; diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 78ecde6003..ed8786170d 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -636,7 +636,6 @@ void initQueryModuleMsgHandle() { queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_TABLE_INDEX)] = queryProcessGetTbIndexRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_BATCH_META)] = queryProcessGetBatchMetaRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp; } From c087a8d55197cd05f2b115a30f4f61574a0f871c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 27 Jul 2022 11:19:29 +0800 Subject: [PATCH 07/35] fix test case --- tests/script/tsim/stream/session0.sim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/script/tsim/stream/session0.sim b/tests/script/tsim/stream/session0.sim index 16a53d49f3..d05a9e1814 100644 --- a/tests/script/tsim/stream/session0.sim +++ b/tests/script/tsim/stream/session0.sim @@ -83,22 +83,22 @@ if $data11 != 3 then goto loop0 endi -if $data12 != 10 then +if $data12 != NULL then print ======data12=$data12 goto loop0 endi -if $data13 != 10 then +if $data13 != NULL then print ======data13=$data13 goto loop0 endi -if $data14 != 1.100000000 then +if $data14 != NULL then print ======data14=$data14 return -1 endi -if $data15 != 0.000000000 then +if $data15 != NULL then print ======data15=$data15 return -1 endi @@ -141,22 +141,22 @@ if $data01 != 7 then goto loop1 endi -if $data02 != 18 then +if $data02 != NULL then print =====data02=$data02 goto loop1 endi -if $data03 != 4 then +if $data03 != NULL then print =====data03=$data03 goto loop1 endi -if $data04 != 1.000000000 then +if $data04 != NULL then print ======$data04 return -1 endi -if $data05 != 1.154700538 then +if $data05 != NULL then print ======$data05 return -1 endi From 648a7a12b005c0a5e5c71c4b19e6da28a481d3c3 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 27 Jul 2022 14:02:05 +0800 Subject: [PATCH 08/35] feat: support mnd meta batch fetching --- source/dnode/mgmt/mgmt_mnode/src/mmHandle.c | 1 + source/dnode/mnode/impl/src/mndQuery.c | 99 +++++++++++++++++++++ source/dnode/vnode/src/vnd/vnodeQuery.c | 4 +- source/libs/catalog/inc/catalogInt.h | 11 +++ source/libs/catalog/inc/ctgRemote.h | 7 -- source/libs/catalog/src/ctgAsync.c | 5 +- source/libs/catalog/src/ctgRemote.c | 75 ++++++++++++---- source/libs/catalog/src/ctgUtil.c | 10 +++ 8 files changed, 187 insertions(+), 25 deletions(-) diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 22a53f07f6..647af20fcf 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -184,6 +184,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_STB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_STB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_TABLE_META, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_BATCH_META, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_TABLE_CFG, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_SMA, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_SMA, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index 5a527b994e..e6e9cae100 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -63,6 +63,104 @@ int32_t mndProcessQueryMsg(SRpcMsg *pMsg) { return code; } +int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { + int32_t code = 0; + int32_t offset = 0; + int32_t rspSize = 0; + SBatchReq *batchReq = (SBatchReq*)pMsg->pCont; + int32_t msgNum = ntohl(batchReq->msgNum); + offset += sizeof(SBatchReq); + SBatchMsg req = {0}; + SBatchRsp rsp = {0}; + SRpcMsg reqMsg = *pMsg; + SRpcMsg rspMsg = {0}; + void* pRsp = NULL; + SMnode *pMnode = pMsg->info.node; + + SArray* batchRsp = taosArrayInit(msgNum, sizeof(SBatchRsp)); + if (NULL == batchRsp) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + for (int32_t i = 0; i < msgNum; ++i) { + req.msgType = ntohl(*(int32_t*)((char*)pMsg->pCont + offset)); + offset += sizeof(req.msgType); + + req.msgLen = ntohl(*(int32_t*)((char*)pMsg->pCont + offset)); + offset += sizeof(req.msgLen); + + req.msg = (char*)pMsg->pCont + offset; + offset += req.msgLen; + + reqMsg.msgType = req.msgType; + reqMsg.pCont = req.msg; + reqMsg.contLen = req.msgLen; + reqMsg.info.rsp = NULL; + reqMsg.info.rspLen = 0; + + MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(req.msgType)]; + if (fp == NULL) { + mError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType)); + terrno = TSDB_CODE_MSG_NOT_PROCESSED; + return -1; + } + + code = (*fp)(&reqMsg); + + rsp.reqType = reqMsg.msgType; + rsp.msgLen = reqMsg.info.rspLen; + rsp.rspCode = code; + rsp.msg = reqMsg.info.rsp; + + taosArrayPush(batchRsp, &rsp); + + rspSize += sizeof(rsp) + rsp.msgLen - POINTER_BYTES; + } + + rspSize += sizeof(int32_t); + offset = 0; + + pRsp = rpcMallocCont(rspSize); + if (pRsp == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + + *(int32_t*)((char*)pRsp + offset) = htonl(msgNum); + offset += sizeof(msgNum); + for (int32_t i = 0; i < msgNum; ++i) { + SBatchRsp *p = taosArrayGet(batchRsp, i); + + *(int32_t*)((char*)pRsp + offset) = htonl(p->reqType); + offset += sizeof(p->reqType); + *(int32_t*)((char*)pRsp + offset) = htonl(p->msgLen); + offset += sizeof(p->msgLen); + *(int32_t*)((char*)pRsp + offset) = htonl(p->rspCode); + offset += sizeof(p->rspCode); + memcpy((char*)pRsp + offset, p->msg, p->msgLen); + offset += p->msgLen; + + rpcFreeCont(p->msg); + } + + taosArrayDestroy(batchRsp); + batchRsp = NULL; + +_exit: + + pMsg->info.rsp = pRsp; + pMsg->info.rspLen = rspSize; + + if (code) { + mError("mnd get batch meta failed cause of %s", tstrerror(code)); + } + + taosArrayDestroyEx(batchRsp, tFreeSBatchRsp); + + return code; +} + int32_t mndInitQuery(SMnode *pMnode) { if (qWorkerInit(NODE_TYPE_MNODE, MNODE_HANDLE, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb) != 0) { mError("failed to init qworker in mnode since %s", terrstr()); @@ -76,6 +174,7 @@ int32_t mndInitQuery(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_SCH_MERGE_FETCH, mndProcessQueryMsg); mndSetMsgHandle(pMnode, TDMT_SCH_DROP_TASK, mndProcessQueryMsg); mndSetMsgHandle(pMnode, TDMT_SCH_QUERY_HEARTBEAT, mndProcessQueryMsg); + mndSetMsgHandle(pMnode, TDMT_MND_BATCH_META, mndProcessBatchMetaMsg); return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 6b36a66776..71b9d70518 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -349,14 +349,14 @@ _exit: rspMsg.msgType = pMsg->msgType; if (code) { - qError("get batch meta failed cause of %s", tstrerror(code)); + qError("vnd get batch meta failed cause of %s", tstrerror(code)); } taosArrayDestroyEx(batchRsp, tFreeSBatchRsp); tmsgSendRsp(&rspMsg); - return TSDB_CODE_SUCCESS; + return code; } int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 0821a91d6b..1aaa1ecfd7 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -251,6 +251,16 @@ typedef struct SCtgMsgCtx { char* target; } SCtgMsgCtx; + +typedef struct SCtgTaskCallbackParam { + uint64_t queryId; + int64_t refId; + SArray* taskId; + int32_t reqType; + int32_t batchId; +} SCtgTaskCallbackParam; + + typedef struct SCtgTask SCtgTask; typedef int32_t (*ctgSubTaskCbFp)(SCtgTask*); @@ -643,6 +653,7 @@ int32_t ctgLaunchSubTask(SCtgTask *pTask, CTG_TASK_TYPE type, ctgSubTaskCbFp fp, int32_t ctgGetTbCfgCb(SCtgTask *pTask); void ctgFreeHandle(SCatalog* pCatalog); +void ctgFreeMsgSendParam(void* param); void ctgFreeBatch(SCtgBatch *pBatch); void ctgFreeBatchs(SHashObj *pBatchs); int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst); diff --git a/source/libs/catalog/inc/ctgRemote.h b/source/libs/catalog/inc/ctgRemote.h index 72ab43e085..fe0762a88a 100644 --- a/source/libs/catalog/inc/ctgRemote.h +++ b/source/libs/catalog/inc/ctgRemote.h @@ -20,13 +20,6 @@ extern "C" { #endif -typedef struct SCtgTaskCallbackParam { - uint64_t queryId; - int64_t refId; - SArray* taskId; - int32_t reqType; - int32_t batchId; -} SCtgTaskCallbackParam; #ifdef __cplusplus diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 9a666eb4ff..f4cee13ec0 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -783,7 +783,8 @@ int32_t ctgCallSubCb(SCtgTask *pTask) { pParent->subRes.code = code; } } - + + pParent->pBatchs = pTask->pBatchs; CTG_ERR_JRET(pParent->subRes.fp(pParent)); } @@ -1660,6 +1661,7 @@ int32_t ctgSetSubTaskCb(SCtgTask *pSub, SCtgTask *pTask) { if (CTG_TASK_DONE == pSub->status) { pTask->subRes.code = pSub->code; CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].cloneFp)(pSub, &pTask->subRes.res)); + pTask->pBatchs = pSub->pBatchs; CTG_ERR_JRET(pTask->subRes.fp(pTask)); } else { if (NULL == pSub->pParents) { @@ -1697,6 +1699,7 @@ int32_t ctgLaunchSubTask(SCtgTask *pTask, CTG_TASK_TYPE type, ctgSubTaskCbFp fp, CTG_ERR_RET(ctgSetSubTaskCb(pSub, pTask)); if (newTask) { + pSub->pBatchs = pTask->pBatchs; CTG_ERR_RET((*gCtgAsyncFps[pSub->type].launchFp)(pSub)); pSub->status = CTG_TASK_LAUNCHED; } diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index 8b1d125a58..3ec30ac39f 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -18,7 +18,6 @@ #include "tname.h" #include "catalogInt.h" #include "systable.h" -#include "ctgRemote.h" #include "tref.h" int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBuf *pMsg, int32_t rspCode) { @@ -361,7 +360,7 @@ int32_t ctgMakeMsgSendInfo(SCtgJob* pJob, SArray* pTaskId, int32_t batchId, int3 SMsgSendInfo *msgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (NULL == msgSendInfo) { qError("calloc %d failed", (int32_t)sizeof(SMsgSendInfo)); - CTG_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + CTG_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } SCtgTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SCtgTaskCallbackParam)); @@ -377,7 +376,7 @@ int32_t ctgMakeMsgSendInfo(SCtgJob* pJob, SArray* pTaskId, int32_t batchId, int3 param->batchId = batchId; msgSendInfo->param = param; - msgSendInfo->paramFreeFp = taosMemoryFree; + msgSendInfo->paramFreeFp = ctgFreeMsgSendParam; msgSendInfo->fp = ctgHandleMsgCallback; *pMsgSendInfo = msgSendInfo; @@ -386,8 +385,8 @@ int32_t ctgMakeMsgSendInfo(SCtgJob* pJob, SArray* pTaskId, int32_t batchId, int3 _return: - taosMemoryFree(param); - taosMemoryFree(msgSendInfo); + taosArrayDestroy(pTaskId); + destroySendMsgInfo(msgSendInfo); CTG_RET(code); } @@ -543,6 +542,8 @@ int32_t ctgBuildBatchReqMsg(SCtgBatch* pBatch, int32_t vgId, void** msg) { ASSERT(pBatch->msgSize == offset); + qDebug("batch req %d to vg %d msg built with %d meta reqs", pBatch->batchId, vgId, num); + return TSDB_CODE_SUCCESS; } @@ -558,9 +559,11 @@ int32_t ctgLaunchBatchs(SCatalog* pCtg, SCtgJob *pJob, SHashObj* pBatchs) { ctgDebug("QID:0x%" PRIx64 " ctg start to launch batch %d", pJob->queryId, pBatch->batchId); CTG_ERR_JRET(ctgBuildBatchReqMsg(pBatch, *vgId, &msg)); - CTG_ERR_JRET(ctgAsyncSendMsg(pCtg, &pBatch->conn, pJob, pBatch->pTaskIds, pBatch->batchId, - pBatch->dbFName, *vgId, pBatch->msgType, msg, pBatch->msgSize)); - + code = ctgAsyncSendMsg(pCtg, &pBatch->conn, pJob, pBatch->pTaskIds, pBatch->batchId, + pBatch->dbFName, *vgId, pBatch->msgType, msg, pBatch->msgSize); + pBatch->pTaskIds = NULL; + CTG_ERR_JRET(code); + p = taosHashIterate(pBatchs, p); } @@ -598,6 +601,9 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, NULL)); +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -605,6 +611,7 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -640,6 +647,9 @@ int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray if (pTask) { CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, NULL, NULL)); +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -647,6 +657,7 @@ int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SArray taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -687,6 +698,9 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SBuildU } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, input->db)); +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -694,6 +708,7 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SBuildU taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -733,6 +748,9 @@ int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)dbFName)); +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -740,6 +758,7 @@ int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const char taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -778,7 +797,10 @@ int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)indexName)); - + +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -786,6 +808,7 @@ int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -827,7 +850,10 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SName *n } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)tbFName)); - + +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -835,6 +861,7 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, SName *n taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -873,7 +900,10 @@ int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const ch CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)funcName)); - + +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -881,6 +911,7 @@ int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const ch taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -919,7 +950,10 @@ int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)user)); - + +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -927,6 +961,7 @@ int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -970,7 +1005,9 @@ int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo *pConn, char CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, tbFName)); - +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -978,6 +1015,7 @@ int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo *pConn, char taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -1151,7 +1189,9 @@ int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const S if (pTask) { CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, NULL, (char*)tbFName)); - +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -1159,6 +1199,7 @@ int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, const S taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { @@ -1193,7 +1234,10 @@ int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, char **ou if (pTask) { CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, NULL, NULL)); - + +#if CTG_BATCH_FETCH + CTG_RET(ctgAddBatch(pCtg, 0, pConn, pTask, reqType, msg, msgLen)); +#else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); @@ -1201,6 +1245,7 @@ int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo *pConn, char **ou taosArrayPush(pTaskId, &pTask->taskId); CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, 0, reqType, msg, msgLen)); +#endif } SRpcMsg rpcMsg = { diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 8d33e5596f..e61becbe17 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -19,6 +19,16 @@ #include "catalogInt.h" #include "systable.h" +void ctgFreeMsgSendParam(void* param) { + if (NULL == param) { + return; + } + + SCtgTaskCallbackParam* pParam = (SCtgTaskCallbackParam*)param; + taosArrayDestroy(pParam->taskId); + + taosMemoryFree(param); +} void ctgFreeBatch(SCtgBatch *pBatch) { if (NULL == pBatch) { From 70067fa9393735298c309f282ded75e2fdf053b6 Mon Sep 17 00:00:00 2001 From: "slzhou@taodata.com" Date: Wed, 27 Jul 2022 14:27:59 +0800 Subject: [PATCH 09/35] fix: prepare for multirow join --- source/libs/executor/src/joinoperator.c | 100 ++++++++++++++---------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index 11e0059017..895899d068 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -116,7 +116,9 @@ void destroyMergeJoinOperator(void* param, int32_t numOfOutput) { taosMemoryFreeClear(param); } -static void doJoinOneRow(struct SOperatorInfo* pOperator, SSDataBlock* pRes, int32_t currRow) { + +static void mergeJoinJoinLeftRight(struct SOperatorInfo* pOperator, SSDataBlock* pRes, int32_t currRow, + SSDataBlock* pLeftBlock, int32_t leftPos, SSDataBlock* pRightBlock, int32_t rightPos) { SJoinOperatorInfo* pJoinInfo = pOperator->info; for (int32_t i = 0; i < pOperator->exprSupp.numOfExprs; ++i) { @@ -130,11 +132,11 @@ static void doJoinOneRow(struct SOperatorInfo* pOperator, SSDataBlock* pRes, int SColumnInfoData* pSrc = NULL; if (pJoinInfo->pLeft->info.blockId == blockId) { - pSrc = taosArrayGet(pJoinInfo->pLeft->pDataBlock, slotId); - rowIndex = pJoinInfo->leftPos; + pSrc = taosArrayGet(pLeftBlock->pDataBlock, slotId); + rowIndex = leftPos; } else { - pSrc = taosArrayGet(pJoinInfo->pRight->pDataBlock, slotId); - rowIndex = pJoinInfo->rightPos; + pSrc = taosArrayGet(pRightBlock->pDataBlock, slotId); + rowIndex = rightPos; } if (colDataIsNull_s(pSrc, rowIndex)) { @@ -146,6 +148,45 @@ static void doJoinOneRow(struct SOperatorInfo* pOperator, SSDataBlock* pRes, int } } + +static bool mergeJoinGetNextTimestamp(SOperatorInfo* pOperator, int64_t* pLeftTs, int64_t* pRightTs) { + SJoinOperatorInfo* pJoinInfo = pOperator->info; + + if (pJoinInfo->pLeft == NULL || pJoinInfo->leftPos >= pJoinInfo->pLeft->info.rows) { + SOperatorInfo* ds1 = pOperator->pDownstream[0]; + pJoinInfo->pLeft = ds1->fpSet.getNextFn(ds1); + + pJoinInfo->leftPos = 0; + if (pJoinInfo->pLeft == NULL) { + setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); + return false; + } + } + + if (pJoinInfo->pRight == NULL || pJoinInfo->rightPos >= pJoinInfo->pRight->info.rows) { + SOperatorInfo* ds2 = pOperator->pDownstream[1]; + pJoinInfo->pRight = ds2->fpSet.getNextFn(ds2); + + pJoinInfo->rightPos = 0; + if (pJoinInfo->pRight == NULL) { + setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); + return false; + } + } + // only the timestamp match support for ordinary table + SColumnInfoData* pLeftCol = taosArrayGet(pJoinInfo->pLeft->pDataBlock, pJoinInfo->leftCol.slotId); + char* pLeftVal = colDataGetData(pLeftCol, pJoinInfo->leftPos); + *pLeftTs = *(int64_t*)pLeftVal; + + SColumnInfoData* pRightCol = taosArrayGet(pJoinInfo->pRight->pDataBlock, pJoinInfo->rightCol.slotId); + char* pRightVal = colDataGetData(pRightCol, pJoinInfo->rightPos); + *pRightTs = *(int64_t*)pRightVal; + + ASSERT(pLeftCol->info.type == TSDB_DATA_TYPE_TIMESTAMP); + ASSERT(pRightCol->info.type == TSDB_DATA_TYPE_TIMESTAMP); + return true; +} + static void doMergeJoinImpl(struct SOperatorInfo* pOperator, SSDataBlock* pRes) { SJoinOperatorInfo* pJoinInfo = pOperator->info; @@ -154,52 +195,29 @@ static void doMergeJoinImpl(struct SOperatorInfo* pOperator, SSDataBlock* pRes) bool asc = (pJoinInfo->inputTsOrder == TSDB_ORDER_ASC) ? true : false; while (1) { - // todo extract method - if (pJoinInfo->pLeft == NULL || pJoinInfo->leftPos >= pJoinInfo->pLeft->info.rows) { - SOperatorInfo* ds1 = pOperator->pDownstream[0]; - pJoinInfo->pLeft = ds1->fpSet.getNextFn(ds1); - - pJoinInfo->leftPos = 0; - if (pJoinInfo->pLeft == NULL) { - setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); - break; - } + int64_t leftTs = 0; + int64_t rightTs = 0; + bool hasNextTs = mergeJoinGetNextTimestamp(pOperator, &leftTs, &rightTs); + if (!hasNextTs) { + break; } - - if (pJoinInfo->pRight == NULL || pJoinInfo->rightPos >= pJoinInfo->pRight->info.rows) { - SOperatorInfo* ds2 = pOperator->pDownstream[1]; - pJoinInfo->pRight = ds2->fpSet.getNextFn(ds2); - - pJoinInfo->rightPos = 0; - if (pJoinInfo->pRight == NULL) { - setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); - break; - } - } - - SColumnInfoData* pLeftCol = taosArrayGet(pJoinInfo->pLeft->pDataBlock, pJoinInfo->leftCol.slotId); - char* pLeftVal = colDataGetData(pLeftCol, pJoinInfo->leftPos); - - SColumnInfoData* pRightCol = taosArrayGet(pJoinInfo->pRight->pDataBlock, pJoinInfo->rightCol.slotId); - char* pRightVal = colDataGetData(pRightCol, pJoinInfo->rightPos); - - // only the timestamp match support for ordinary table - ASSERT(pLeftCol->info.type == TSDB_DATA_TYPE_TIMESTAMP); - if (*(int64_t*)pLeftVal == *(int64_t*)pRightVal) { - doJoinOneRow(pOperator, pRes, nrows); + + if (leftTs == rightTs) { + mergeJoinJoinLeftRight(pOperator, pRes, nrows, + pJoinInfo->pLeft, pJoinInfo->leftPos, pJoinInfo->pRight, pJoinInfo->rightPos); pJoinInfo->leftPos += 1; pJoinInfo->rightPos += 1; nrows += 1; - } else if (asc && *(int64_t*)pLeftVal < *(int64_t*)pRightVal || - !asc && *(int64_t*)pLeftVal > *(int64_t*)pRightVal) { + } else if (asc && leftTs < rightTs || + !asc && leftTs > rightTs) { pJoinInfo->leftPos += 1; if (pJoinInfo->leftPos >= pJoinInfo->pLeft->info.rows) { continue; } - } else if (asc && *(int64_t*)pLeftVal > *(int64_t*)pRightVal || - !asc && *(int64_t*)pLeftVal < *(int64_t*)pRightVal) { + } else if (asc && leftTs > rightTs || + !asc && leftTs < rightTs) { pJoinInfo->rightPos += 1; if (pJoinInfo->rightPos >= pJoinInfo->pRight->info.rows) { continue; From 5b96fee400e5d5f6a495e1974605211944f9bad3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 27 Jul 2022 14:41:05 +0800 Subject: [PATCH 10/35] test: recover case --- tests/script/jenkins/basic.txt | 4 +-- tests/script/tsim/parser/function.sim | 46 ++++++--------------------- 2 files changed, 12 insertions(+), 38 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 4ec3a14cc8..99beabe9ee 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -110,7 +110,7 @@ ./test.sh -f tsim/parser/fill.sim ./test.sh -f tsim/parser/first_last.sim ./test.sh -f tsim/parser/fourArithmetic-basic.sim -# TD-17659 ./test.sh -f tsim/parser/function.sim +./test.sh -f tsim/parser/function.sim ./test.sh -f tsim/parser/groupby-basic.sim ./test.sh -f tsim/parser/groupby.sim ./test.sh -f tsim/parser/having_child.sim @@ -145,7 +145,7 @@ ./test.sh -f tsim/parser/select_across_vnodes.sim ./test.sh -f tsim/parser/select_distinct_tag.sim ./test.sh -f tsim/parser/select_from_cache_disk.sim -# TD-17659 ./test.sh -f tsim/parser/select_with_tags.sim +# TD-17832 ./test.sh -f tsim/parser/select_with_tags.sim ./test.sh -f tsim/parser/selectResNum.sim ./test.sh -f tsim/parser/set_tag_vals.sim ./test.sh -f tsim/parser/single_row_in_tb.sim diff --git a/tests/script/tsim/parser/function.sim b/tests/script/tsim/parser/function.sim index 7927715988..80512b9b3e 100644 --- a/tests/script/tsim/parser/function.sim +++ b/tests/script/tsim/parser/function.sim @@ -826,7 +826,7 @@ sql select derivative(k, 200a, 0) from tm0; sql select derivative(k, 999a, 0) from tm0; sql_error select derivative(k, 20s, -12) from tm0; -sql select derivative(k, 1s, 0) from tm0 +sql select ts, derivative(k, 1s, 0) from tm0 if $rows != 5 then return -1 endi @@ -858,7 +858,7 @@ if $data31 != -0.000236111 then return -1 endi -sql select derivative(k, 6m, 0) from tm0; +sql select ts ,derivative(k, 6m, 0) from tm0; if $rows != 5 then return -1 endi @@ -888,7 +888,7 @@ if $data31 != -0.085000000 then return -1 endi -sql select derivative(k, 12m, 0) from tm0; +sql select ts, derivative(k, 12m, 0) from tm0; if $rows != 5 then return -1 endi @@ -938,44 +938,17 @@ sql insert into t1 values('2020-1-1 1:1:6', 200); sql insert into t1 values('2020-1-1 1:1:8', 2000); sql insert into t1 values('2020-1-1 1:1:10', 20000); -sql_error select derivative(k, 1s, 0) from m1; +sql select derivative(k, 1s, 0) from m1; sql_error select derivative(k, 1s, 0) from m1 group by a; sql_error select derivative(f1, 1s, 0) from (select k from t1); -sql select derivative(k, 1s, 0) from m1 group by tbname -if $rows != 12 then - return -1 -endi -if $data00 != @20-01-01 01:01:03.000@ then - return -1 -endi -if $data01 != 1.000000000 then - return -1 -endi -if $data02 != @t0@ then - return -1 -endi -if $data10 != @20-01-01 01:02:04.000@ then - return -1 -endi -if $data11 != 0.016393443 then - return -1 -endi -if $data12 != t0 then - return -1 -endi -if $data90 != @20-01-01 01:01:06.000@ then - return -1 -endi -if $data91 != 90.000000000 then - return -1 -endi -if $data92 != t1 then +sql select ts, derivative(k, 1s, 0) from m1 +if $rows != 13 then return -1 endi print =========================>TD-5190 -sql select stddev(f1) from st1 where ts>'2021-07-01 1:1:1' and ts<'2021-07-30 00:00:00' interval(1d) fill(NULL); +sql select _wstart, stddev(f1) from st1 where ts>'2021-07-01 1:1:1' and ts<'2021-07-30 00:00:00' interval(1d) fill(NULL); if $rows != 29 then return -1 endi @@ -986,7 +959,7 @@ if $data01 != NULL then return -1 endi -sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s)); +sql_error select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s)); sql create table smeters (ts timestamp, current float, voltage int) tags (t1 int); sql create table smeter1 using smeters tags (1); @@ -994,7 +967,7 @@ sql insert into smeter1 values ('2021-08-08 10:10:10', 10, 2); sql insert into smeter1 values ('2021-08-08 10:10:12', 10, 2); sql insert into smeter1 values ('2021-08-08 10:10:14', 20, 1); -sql select stddev(voltage) from smeters where ts>='2021-08-08 10:10:10.000' and ts < '2021-08-08 10:10:20.000' and current=10 interval(1000a); +sql select _wstart, stddev(voltage) from smeters where ts>='2021-08-08 10:10:10.000' and ts < '2021-08-08 10:10:20.000' and current=10 interval(1000a); if $rows != 2 then return -1 endi @@ -1019,3 +992,4 @@ if $data00 != 0.000000000 then return -1 endi +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 42b809ec3df713d31c42122405ef99bbf1e71744 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 27 Jul 2022 14:43:55 +0800 Subject: [PATCH 11/35] test: recover case --- tests/script/tsim/parser/function.sim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/script/tsim/parser/function.sim b/tests/script/tsim/parser/function.sim index 80512b9b3e..cbfb59bcab 100644 --- a/tests/script/tsim/parser/function.sim +++ b/tests/script/tsim/parser/function.sim @@ -959,7 +959,7 @@ if $data01 != NULL then return -1 endi -sql_error select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s)); +sql select derivative(test_column_alias_name, 1s, 0) from (select _wstart, avg(k) test_column_alias_name from t1 interval(1s)); sql create table smeters (ts timestamp, current float, voltage int) tags (t1 int); sql create table smeter1 using smeters tags (1); @@ -991,5 +991,3 @@ endi if $data00 != 0.000000000 then return -1 endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file From 5ed23e7912f6de340af3bdfe32aed52e68d5dacf Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 27 Jul 2022 14:52:44 +0800 Subject: [PATCH 12/35] fix read buf --- source/libs/transport/src/transCli.c | 13 +++++++++++++ source/libs/transport/src/transComm.c | 6 ++++-- source/libs/transport/src/transSvr.c | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 54ffcabc8d..064c110a9f 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -60,6 +60,7 @@ typedef struct SCliThrd { int64_t pid; // pid uv_loop_t* loop; SAsyncPool* asyncPool; + uv_idle_t* idle; uv_timer_t timer; void* pool; // conn pool @@ -116,6 +117,7 @@ static void cliSendCb(uv_write_t* req, int status); // callback after conn to server static void cliConnCb(uv_connect_t* req, int status); static void cliAsyncCb(uv_async_t* handle); +static void cliIdleCb(uv_idle_t* handle); static int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg); @@ -962,6 +964,10 @@ static void cliAsyncCb(uv_async_t* handle) { } if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd); } +static void cliIdleCb(uv_idle_t* handle) { + SCliThrd* thrd = handle->data; + tTrace("do idle work"); +} static void* cliWorkThread(void* arg) { SCliThrd* pThrd = (SCliThrd*)arg; @@ -1024,6 +1030,11 @@ static SCliThrd* createThrdObj() { uv_timer_init(pThrd->loop, &pThrd->timer); pThrd->timer.data = pThrd; + // pThrd->idle = taosMemoryCalloc(1, sizeof(uv_idle_t)); + // uv_idle_init(pThrd->loop, pThrd->idle); + // pThrd->idle->data = pThrd; + // uv_idle_start(pThrd->idle, cliIdleCb); + pThrd->pool = createConnPool(4); transDQCreate(pThrd->loop, &pThrd->delayQueue); @@ -1045,6 +1056,8 @@ static void destroyThrdObj(SCliThrd* pThrd) { transDQDestroy(pThrd->delayQueue, destroyCmsg); transDQDestroy(pThrd->timeoutQueue, NULL); + + taosMemoryFree(pThrd->idle); taosMemoryFree(pThrd->loop); taosMemoryFree(pThrd); } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index fb59aafb33..c99effb26f 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -152,16 +152,18 @@ int transDumpFromBuffer(SConnBuffer* connBuf, char** buf) { int transResetBuffer(SConnBuffer* connBuf) { SConnBuffer* p = connBuf; - if (p->total <= p->len) { + if (p->total < p->len) { int left = p->len - p->total; memmove(p->buf, p->buf + p->total, left); p->left = -1; p->total = 0; p->len = left; - } else { + } else if (p->total == p->len) { p->left = -1; p->total = 0; p->len = 0; + } else { + assert(0); } return 0; } diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index e360926b40..a97e0b53c1 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -238,7 +238,7 @@ static void uvHandleReq(SSvrConn* pConn) { transMsg.msgType = pHead->msgType; transMsg.code = pHead->code; - transClearBuffer(&pConn->readBuf); + // transClearBuffer(&pConn->readBuf); pConn->inType = pHead->msgType; if (pConn->status == ConnNormal) { From 3469117732e7bc8781b45a13968ed418545ee0c2 Mon Sep 17 00:00:00 2001 From: "slzhou@taodata.com" Date: Wed, 27 Jul 2022 15:12:23 +0800 Subject: [PATCH 13/35] fix: add input ts order to physical plan join node --- source/libs/executor/src/joinoperator.c | 10 +++------- source/libs/nodes/src/nodesCodeFuncs.c | 8 +++++++- source/libs/planner/src/planPhysiCreater.c | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index 895899d068..7b3c590f07 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -83,8 +83,6 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t } else if (pJoinNode->inputTsOrder == ORDER_DESC) { pInfo->inputTsOrder = TSDB_ORDER_DESC; } - //TODO: remove this when JoinNode inputTsOrder is ready - pInfo->inputTsOrder = TSDB_ORDER_ASC; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyMergeJoinOperator, NULL, NULL, NULL); @@ -201,7 +199,7 @@ static void doMergeJoinImpl(struct SOperatorInfo* pOperator, SSDataBlock* pRes) if (!hasNextTs) { break; } - + if (leftTs == rightTs) { mergeJoinJoinLeftRight(pOperator, pRes, nrows, pJoinInfo->pLeft, pJoinInfo->leftPos, pJoinInfo->pRight, pJoinInfo->rightPos); @@ -209,15 +207,13 @@ static void doMergeJoinImpl(struct SOperatorInfo* pOperator, SSDataBlock* pRes) pJoinInfo->rightPos += 1; nrows += 1; - } else if (asc && leftTs < rightTs || - !asc && leftTs > rightTs) { + } else if (asc && leftTs < rightTs || !asc && leftTs > rightTs) { pJoinInfo->leftPos += 1; if (pJoinInfo->leftPos >= pJoinInfo->pLeft->info.rows) { continue; } - } else if (asc && leftTs > rightTs || - !asc && leftTs < rightTs) { + } else if (asc && leftTs > rightTs || !asc && leftTs < rightTs) { pJoinInfo->rightPos += 1; if (pJoinInfo->rightPos >= pJoinInfo->pRight->info.rows) { continue; diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 186a51f000..c499d6e7cc 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -1712,6 +1712,7 @@ static int32_t jsonToPhysiProjectNode(const SJson* pJson, void* pObj) { } static const char* jkJoinPhysiPlanJoinType = "JoinType"; +static const char* jkJoinPhysiPlanInputTsOrder = "InputTsOrder"; static const char* jkJoinPhysiPlanMergeCondition = "MergeCondition"; static const char* jkJoinPhysiPlanOnConditions = "OnConditions"; static const char* jkJoinPhysiPlanTargets = "Targets"; @@ -1723,6 +1724,9 @@ static int32_t physiJoinNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkJoinPhysiPlanJoinType, pNode->joinType); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkJoinPhysiPlanInputTsOrder, pNode->inputTsOrder); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkJoinPhysiPlanMergeCondition, nodeToJson, pNode->pMergeCondition); } @@ -1742,7 +1746,9 @@ static int32_t jsonToPhysiJoinNode(const SJson* pJson, void* pObj) { int32_t code = jsonToPhysicPlanNode(pJson, pObj); if (TSDB_CODE_SUCCESS == code) { tjsonGetNumberValue(pJson, jkJoinPhysiPlanJoinType, pNode->joinType, code); - ; + } + if (TSDB_CODE_SUCCESS == code) { + tjsonGetNumberValue(pJson, jkJoinPhysiPlanInputTsOrder, pNode->inputTsOrder, code); } if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkJoinPhysiPlanOnConditions, &pNode->pOnConditions); diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 587e566939..1c57859f1a 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -632,6 +632,7 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren int32_t code = TSDB_CODE_SUCCESS; pJoin->joinType = pJoinLogicNode->joinType; + pJoin->inputTsOrder = pJoinLogicNode->inputTsOrder; setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pMergeCondition, &pJoin->pMergeCondition); if (TSDB_CODE_SUCCESS == code) { From e1c413000790ccd2cc065c129d7e478fbff2d281 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 27 Jul 2022 15:23:33 +0800 Subject: [PATCH 14/35] fix:add test case --- tests/system-test/7-tmq/tmq_taosx.py | 91 +++++ tests/system-test/fulltest.sh | 1 + tests/test/c/CMakeLists.txt | 8 + tests/test/c/tmq_taosx_ci.c | 520 +++++++++++++++++++++++++++ 4 files changed, 620 insertions(+) create mode 100644 tests/system-test/7-tmq/tmq_taosx.py create mode 100644 tests/test/c/tmq_taosx_ci.c diff --git a/tests/system-test/7-tmq/tmq_taosx.py b/tests/system-test/7-tmq/tmq_taosx.py new file mode 100644 index 0000000000..a136d0a1a2 --- /dev/null +++ b/tests/system-test/7-tmq/tmq_taosx.py @@ -0,0 +1,91 @@ + +import taos +import sys +import time +import socket +import os +import threading + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + #tdSql.init(conn.cursor(), logSql) # output sql.txt file + + def checkFileContent(self): + buildPath = tdCom.getBuildPath() + cfgPath = tdCom.getClientCfgPath() + cmdStr = '%s/build/bin/tmq_taosx_ci -c %s'%(buildPath, cfgPath) + tdLog.info(cmdStr) + os.system(cmdStr) + + srcFile = '%s/../log/tmq_taosx_tmp.source'%(cfgPath) + dstFile = '%s/../log/tmq_taosx_tmp.result'%(cfgPath) + tdLog.info("compare file: %s, %s"%(srcFile, dstFile)) + + consumeFile = open(srcFile, mode='r') + queryFile = open(dstFile, mode='r') + + while True: + dst = queryFile.readline() + src = consumeFile.readline() + + if dst: + if dst != src: + tdLog.exit("compare error: %s != %s"%src, dst) + else: + break + + tdSql.execute('use db_taosx') + tdSql.query("select * from ct3") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 51) + tdSql.checkData(0, 4, 940) + tdSql.checkData(1, 1, 23) + tdSql.checkData(1, 4, None) + + tdSql.query("select * from ct1") + tdSql.checkRows(4) + + tdSql.query("select * from ct2") + tdSql.checkRows(0) + + tdSql.query("select * from ct0") + tdSql.checkRows(2) + tdSql.checkData(0, 3, "a") + tdSql.checkData(1, 4, None) + + tdSql.query("select * from n1") + tdSql.checkRows(2) + tdSql.checkData(0, 1, "eeee") + tdSql.checkData(1, 2, 940) + + tdSql.query("select * from jt") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 11) + tdSql.checkData(0, 2, None) + tdSql.checkData(1, 1, 1) + tdSql.checkData(1, 2, '{"k1":1,"k2":"hello"}') + + return + + def run(self): + tdSql.prepare() + self.checkFileContent() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +event = threading.Event() + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 57cadb7de7..c86fb59dd7 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -227,6 +227,7 @@ python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot1.py python3 ./test.py -f 7-tmq/stbTagFilter-1ctb.py python3 ./test.py -f 7-tmq/dataFromTsdbNWal.py python3 ./test.py -f 7-tmq/dataFromTsdbNWal-multiCtb.py +python3 ./test.py -f 7-tmq/tmq_taosx.py # python3 ./test.py -f 7-tmq/stbTagFilter-multiCtb.py #------------querPolicy 2----------- diff --git a/tests/test/c/CMakeLists.txt b/tests/test/c/CMakeLists.txt index 5db97a0f0f..605eef9be3 100644 --- a/tests/test/c/CMakeLists.txt +++ b/tests/test/c/CMakeLists.txt @@ -1,6 +1,7 @@ add_executable(tmq_demo tmqDemo.c) add_executable(tmq_sim tmqSim.c) add_executable(create_table createTable.c) +add_executable(tmq_taosx_ci tmq_taosx_ci.c) target_link_libraries( create_table PUBLIC taos_static @@ -22,6 +23,13 @@ target_link_libraries( PUBLIC common PUBLIC os ) +target_link_libraries( + tmq_taosx_ci + PUBLIC taos_static + PUBLIC util + PUBLIC common + PUBLIC os +) add_executable(sdbDump sdbDump.c) target_link_libraries( diff --git a/tests/test/c/tmq_taosx_ci.c b/tests/test/c/tmq_taosx_ci.c new file mode 100644 index 0000000000..ece7ad4819 --- /dev/null +++ b/tests/test/c/tmq_taosx_ci.c @@ -0,0 +1,520 @@ +/* + * 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 . + */ + +#include +#include +#include +#include +#include +#include "taos.h" +#include "types.h" + +static int running = 1; +TdFilePtr g_fp = NULL; +char dir[64]={0}; + +static TAOS* use_db(){ + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + return NULL; + } + + TAOS_RES* pRes = taos_query(pConn, "use db_taosx"); + if (taos_errno(pRes) != 0) { + printf("error in use db_taosx, reason:%s\n", taos_errstr(pRes)); + return NULL; + } + taos_free_result(pRes); + return pConn; +} + +static void msg_process(TAOS_RES* msg) { + /*memset(buf, 0, 1024);*/ + printf("-----------topic-------------: %s\n", tmq_get_topic_name(msg)); + printf("db: %s\n", tmq_get_db_name(msg)); + printf("vg: %d\n", tmq_get_vgroup_id(msg)); + TAOS *pConn = use_db(); + if (tmq_get_res_type(msg) == TMQ_RES_TABLE_META) { + char* result = tmq_get_json_meta(msg); + if (result) { + printf("meta result: %s\n", result); + } + taosFprintfFile(g_fp, result); + taosFprintfFile(g_fp, "\n"); + tmq_free_json_meta(result); + } + + tmq_raw_data raw = {0}; + tmq_get_raw(msg, &raw); + int32_t ret = tmq_write_raw(pConn, raw); + printf("write raw data: %s\n", tmq_err2str(ret)); + +// else{ +// while(1){ +// int numOfRows = 0; +// void *pData = NULL; +// taos_fetch_raw_block(msg, &numOfRows, &pData); +// if(numOfRows == 0) break; +// printf("write data: tbname:%s, numOfRows:%d\n", tmq_get_table_name(msg), numOfRows); +// int ret = taos_write_raw_block(pConn, numOfRows, pData, tmq_get_table_name(msg)); +// printf("write raw data: %s\n", tmq_err2str(ret)); +// } +// } + + taos_close(pConn); +} + +int32_t init_env() { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + return -1; + } + + TAOS_RES* pRes = taos_query(pConn, "drop database if exists db_taosx"); + if (taos_errno(pRes) != 0) { + printf("error in drop db_taosx, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database if not exists db_taosx vgroups 1"); + if (taos_errno(pRes) != 0) { + printf("error in create db_taosx, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "drop database if exists abc1"); + if (taos_errno(pRes) != 0) { + printf("error in drop db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, + "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(16)) tags(t1 int, t3 " + "nchar(8), t4 bool)"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct0 using st1 tags(1000, \"ttt\", true)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table tu1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct0 values(1626006833600, 1, 2, 'a')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct0, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct1 using st1(t1) tags(2000)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table ct1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct2 using st1(t1) tags(NULL)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table ct2, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct1 values(1626006833600, 3, 4, 'b')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct3 using st1(t1) tags(3000)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct3 values(1626006833600, 5, 6, 'c') ct1 values(1626006833601, 2, 3, 'sds') (1626006833602, 4, 5, 'ddd') ct0 values(1626006833602, 4, 3, 'hwj') ct1 values(now+5s, 23, 32, 's21ds')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table st1 add column c4 bigint"); + if (taos_errno(pRes) != 0) { + printf("failed to alter super table st1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table st1 modify column c3 binary(64)"); + if (taos_errno(pRes) != 0) { + printf("failed to alter super table st1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct3 values(1626006833605, 53, 63, 'cffffffffffffffffffffffffffff', 8989898899999) (1626006833609, 51, 62, 'c333', 940)"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct3 select * from ct1"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table st1 add tag t2 binary(64)"); + if (taos_errno(pRes) != 0) { + printf("failed to alter super table st1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table ct3 set tag t1=5000"); + if (taos_errno(pRes) != 0) { + printf("failed to slter child table ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "delete from abc1 .ct3 where ts < 1626006833606"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists n1(ts timestamp, c1 int, c2 nchar(4))"); + if (taos_errno(pRes) != 0) { + printf("failed to create normal table n1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table n1 add column c3 bigint"); + if (taos_errno(pRes) != 0) { + printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table n1 modify column c2 nchar(8)"); + if (taos_errno(pRes) != 0) { + printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table n1 rename column c3 cc3"); + if (taos_errno(pRes) != 0) { + printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table n1 comment 'hello'"); + if (taos_errno(pRes) != 0) { + printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "alter table n1 drop column c1"); + if (taos_errno(pRes) != 0) { + printf("failed to alter normal table n1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into n1 values(now, 'eeee', 8989898899999) (now+9s, 'c333', 940)"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into n1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table jt(ts timestamp, i int) tags(t json)"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table jt, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table jt1 using jt tags('{\"k1\":1, \"k2\":\"hello\"}')"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table jt, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table jt2 using jt tags('')"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table jt2, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into jt1 values(now, 1)"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table jt1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into jt2 values(now, 11)"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table jt2, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + taos_close(pConn); + return 0; +} + +int32_t create_topic() { + printf("create topic\n"); + TAOS_RES* pRes; + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + return -1; + } + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create topic topic_ctb_column with meta as database abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + taos_close(pConn); + return 0; +} + +void tmq_commit_cb_print(tmq_t* tmq, int32_t code, void* param) { + printf("commit %d tmq %p param %p\n", code, tmq, param); +} + +tmq_t* build_consumer() { +#if 0 + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); +#endif + + tmq_conf_t* conf = tmq_conf_new(); + tmq_conf_set(conf, "group.id", "tg2"); + tmq_conf_set(conf, "client.id", "my app 1"); + tmq_conf_set(conf, "td.connect.user", "root"); + tmq_conf_set(conf, "td.connect.pass", "taosdata"); + tmq_conf_set(conf, "msg.with.table.name", "true"); + tmq_conf_set(conf, "enable.auto.commit", "true"); + tmq_conf_set(conf, "enable.heartbeat.background", "true"); + + /*tmq_conf_set(conf, "experimental.snapshot.enable", "true");*/ + + tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); + tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); + assert(tmq); + tmq_conf_destroy(conf); + return tmq; +} + +tmq_list_t* build_topic_list() { + tmq_list_t* topic_list = tmq_list_new(); + tmq_list_append(topic_list, "topic_ctb_column"); + /*tmq_list_append(topic_list, "tmq_test_db_multi_insert_topic");*/ + return topic_list; +} + +void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { + int32_t code; + + if ((code = tmq_subscribe(tmq, topics))) { + fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(code)); + printf("subscribe err\n"); + return; + } + int32_t cnt = 0; + while (running) { + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1000); + if (tmqmessage) { + cnt++; + msg_process(tmqmessage); + /*if (cnt >= 2) break;*/ + /*printf("get data\n");*/ + taos_free_result(tmqmessage); + /*} else {*/ + /*break;*/ + /*tmq_commit_sync(tmq, NULL);*/ + }else{ + break; + } + } + + code = tmq_consumer_close(tmq); + if (code) + fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(code)); + else + fprintf(stderr, "%% Consumer closed\n"); +} + +void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { + static const int MIN_COMMIT_COUNT = 1; + + int msg_count = 0; + int32_t code; + + if ((code = tmq_subscribe(tmq, topics))) { + fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(code)); + return; + } + + tmq_list_t* subList = NULL; + tmq_subscription(tmq, &subList); + char** subTopics = tmq_list_to_c_array(subList); + int32_t sz = tmq_list_get_size(subList); + printf("subscribed topics: "); + for (int32_t i = 0; i < sz; i++) { + printf("%s, ", subTopics[i]); + } + printf("\n"); + tmq_list_destroy(subList); + + while (running) { + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1000); + if (tmqmessage) { + msg_process(tmqmessage); + taos_free_result(tmqmessage); + + /*tmq_commit_sync(tmq, NULL);*/ + /*if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0);*/ + } + } + + code = tmq_consumer_close(tmq); + if (code) + fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(code)); + else + fprintf(stderr, "%% Consumer closed\n"); +} + +void initLogFile() { + char f1[256] = {0}; + char f2[256] = {0}; + + sprintf(f1, "%s/../log/tmq_taosx_tmp.source", dir); + sprintf(f2, "%s/../log/tmq_taosx_tmp.result", dir); + TdFilePtr pFile = taosOpenFile(f1, TD_FILE_TEXT | TD_FILE_TRUNC | TD_FILE_STREAM); + if (NULL == pFile) { + fprintf(stderr, "Failed to open %s for save result\n", f1); + exit(-1); + } + g_fp = pFile; + + TdFilePtr pFile2 = taosOpenFile(f2, TD_FILE_TEXT | TD_FILE_TRUNC | TD_FILE_STREAM); + if (NULL == pFile2) { + fprintf(stderr, "Failed to open %s for save result\n", f2); + exit(-1); + } + char *result[] = { + "{\"type\":\"create\",\"tableName\":\"st1\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":6},{\"name\":\"c3\",\"type\":8,\"length\":16}],\"tags\":[{\"name\":\"t1\",\"type\":4},{\"name\":\"t3\",\"type\":10,\"length\":8},{\"name\":\"t4\",\"type\":1}]}", + "{\"type\":\"create\",\"tableName\":\"ct0\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":1000},{\"name\":\"t3\",\"type\":10,\"value\":\"\\\"ttt\\\"\"},{\"name\":\"t4\",\"type\":1,\"value\":1}]}", + "{\"type\":\"create\",\"tableName\":\"ct1\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":2000}]}", + "{\"type\":\"create\",\"tableName\":\"ct2\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[]}", + "{\"type\":\"create\",\"tableName\":\"ct3\",\"tableType\":\"child\",\"using\":\"st1\",\"tagNum\":3,\"tags\":[{\"name\":\"t1\",\"type\":4,\"value\":3000}]}", + "{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":5,\"colName\":\"c4\",\"colType\":5}", + "{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":7,\"colName\":\"c3\",\"colType\":8,\"colLength\":64}", + "{\"type\":\"alter\",\"tableName\":\"st1\",\"tableType\":\"super\",\"alterType\":1,\"colName\":\"t2\",\"colType\":8,\"colLength\":64}", + "{\"type\":\"alter\",\"tableName\":\"ct3\",\"tableType\":\"child\",\"alterType\":4,\"colName\":\"t1\",\"colValue\":\"5000\",\"colValueNull\":false}", + "{\"type\":\"create\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"c1\",\"type\":4},{\"name\":\"c2\",\"type\":10,\"length\":4}],\"tags\":[]}", + "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":5,\"colName\":\"c3\",\"colType\":5}", + "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":7,\"colName\":\"c2\",\"colType\":10,\"colLength\":8}", + "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":10,\"colName\":\"c3\",\"colNewName\":\"cc3\"}", + "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":9}", + "{\"type\":\"alter\",\"tableName\":\"n1\",\"tableType\":\"normal\",\"alterType\":6,\"colName\":\"c1\"}", + "{\"type\":\"create\",\"tableName\":\"jt\",\"tableType\":\"super\",\"columns\":[{\"name\":\"ts\",\"type\":9},{\"name\":\"i\",\"type\":4}],\"tags\":[{\"name\":\"t\",\"type\":15}]}", + "{\"type\":\"create\",\"tableName\":\"jt1\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[{\"name\":\"t\",\"type\":15,\"value\":\"{\\\"k1\\\":1,\\\"k2\\\":\\\"hello\\\"}\"}]}", + "{\"type\":\"create\",\"tableName\":\"jt2\",\"tableType\":\"child\",\"using\":\"jt\",\"tagNum\":1,\"tags\":[]}" + }; + + for(int i = 0; i < sizeof(result)/sizeof(result[0]); i++){ + taosFprintfFile(pFile2, result[i]); + taosFprintfFile(pFile2, "\n"); + } + taosCloseFile(&pFile2); +} + +int main(int argc, char* argv[]) { + if(argc == 3 && strcmp(argv[1], "-c") == 0) { + strcpy(dir, argv[2]); + }else{ + strcpy(dir, "../../../sim/psim/cfg"); + } + + printf("env init\n"); + initLogFile(); + + if (init_env() < 0) { + return -1; + } + create_topic(); + + tmq_t* tmq = build_consumer(); + tmq_list_t* topic_list = build_topic_list(); + basic_consume_loop(tmq, topic_list); + /*sync_consume_loop(tmq, topic_list);*/ + taosCloseFile(&g_fp); +} From 58514862e6f30ea847e822bfded0411e440ca2eb Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Wed, 27 Jul 2022 15:25:57 +0800 Subject: [PATCH 15/35] feat: delete sink node add ts column name attribute --- include/libs/nodes/plannodes.h | 1 + source/libs/nodes/src/nodesCloneFuncs.c | 1 + source/libs/nodes/src/nodesCodeFuncs.c | 7 +++++++ source/libs/planner/src/planLogicCreater.c | 1 + source/libs/planner/src/planPhysiCreater.c | 1 + 5 files changed, 11 insertions(+) diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 1147e875f2..0e05ed7887 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -152,6 +152,7 @@ typedef struct SVnodeModifyLogicNode { uint64_t stableId; int8_t tableType; // table type char tableFName[TSDB_TABLE_FNAME_LEN]; + char tsColName[TSDB_COL_NAME_LEN]; STimeWindow deleteTimeRange; SVgroupsInfo* pVgroupList; SNodeList* pInsertCols; diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 5279d015b4..edae8ae118 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -402,6 +402,7 @@ static int32_t logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModi COPY_SCALAR_FIELD(stableId); COPY_SCALAR_FIELD(tableType); COPY_CHAR_ARRAY_FIELD(tableFName); + COPY_CHAR_ARRAY_FIELD(tsColName); COPY_OBJECT_FIELD(deleteTimeRange, sizeof(STimeWindow)); CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone); CLONE_NODE_LIST_FIELD(pInsertCols); diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 186a51f000..51bd2c644b 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -2370,6 +2370,7 @@ static int32_t jsonToPhysiQueryInsertNode(const SJson* pJson, void* pObj) { static const char* jkDeletePhysiPlanTableId = "TableId"; static const char* jkDeletePhysiPlanTableType = "TableType"; static const char* jkDeletePhysiPlanTableFName = "TableFName"; +static const char* jkDeletePhysiPlanTsColName = "TsColName"; static const char* jkDeletePhysiPlanDeleteTimeRangeStartKey = "DeleteTimeRangeStartKey"; static const char* jkDeletePhysiPlanDeleteTimeRangeEndKey = "DeleteTimeRangeEndKey"; static const char* jkDeletePhysiPlanAffectedRows = "AffectedRows"; @@ -2387,6 +2388,9 @@ static int32_t physiDeleteNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddStringToObject(pJson, jkDeletePhysiPlanTableFName, pNode->tableFName); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddStringToObject(pJson, jkDeletePhysiPlanTsColName, pNode->tsColName); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkDeletePhysiPlanDeleteTimeRangeStartKey, pNode->deleteTimeRange.skey); } @@ -2413,6 +2417,9 @@ static int32_t jsonToPhysiDeleteNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetStringValue(pJson, jkDeletePhysiPlanTableFName, pNode->tableFName); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetStringValue(pJson, jkDeletePhysiPlanTsColName, pNode->tsColName); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetBigIntValue(pJson, jkDeletePhysiPlanDeleteTimeRangeStartKey, &pNode->deleteTimeRange.skey); } diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 30e3b676df..8f8d666bd3 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -1294,6 +1294,7 @@ static int32_t createVnodeModifLogicNodeByDelete(SLogicPlanContext* pCxt, SDelet pModify->tableType = pRealTable->pMeta->tableType; snprintf(pModify->tableFName, sizeof(pModify->tableFName), "%d.%s.%s", pCxt->pPlanCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName); + strcpy(pModify->tsColName, pRealTable->pMeta->schema->name); pModify->deleteTimeRange = pDelete->timeRange; pModify->pAffectedRows = nodesCloneNode(pDelete->pCountFunc); if (NULL == pModify->pAffectedRows) { diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 587e566939..402989024c 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -1637,6 +1637,7 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pDeleter->tableId = pModify->tableId; pDeleter->tableType = pModify->tableType; strcpy(pDeleter->tableFName, pModify->tableFName); + strcpy(pDeleter->tsColName, pModify->tsColName); pDeleter->deleteTimeRange = pModify->deleteTimeRange; int32_t code = setNodeSlotId(pCxt, pRoot->pOutputDataBlockDesc->dataBlockId, -1, pModify->pAffectedRows, From 64d9562949afd7ae186008fa740a561bd60351b1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 27 Jul 2022 15:43:49 +0800 Subject: [PATCH 16/35] refactor: privilege code --- source/dnode/mnode/impl/CMakeLists.txt | 10 +- source/dnode/mnode/impl/inc/mndPrivilege.h | 1 + source/dnode/mnode/impl/src/mndPrivilege.c | 187 ++------------------- source/dnode/mnode/impl/src/mndUser.c | 36 +--- 4 files changed, 25 insertions(+), 209 deletions(-) diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index a4bd12a7f7..c740ea1397 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -1,4 +1,11 @@ aux_source_directory(src MNODE_SRC) +IF (TD_PRIVILEGE) + ADD_DEFINITIONS(-D_PRIVILEGE) +ENDIF () +IF (TD_PRIVILEGE) + LIST(APPEND MNODE_SRC ${TD_ENTERPRISE_DIR}/src/plugins/privilege/src/privilege.c) +ENDIF () + add_library(mnode STATIC ${MNODE_SRC}) target_include_directories( mnode @@ -8,11 +15,8 @@ target_include_directories( target_link_libraries( mnode scheduler sdb wal transport cjson sync monitor executor qworker stream parser ) - IF (TD_GRANT) TARGET_LINK_LIBRARIES(mnode grant) -ENDIF () -IF (TD_GRANT) ADD_DEFINITIONS(-D_GRANT) ENDIF () diff --git a/source/dnode/mnode/impl/inc/mndPrivilege.h b/source/dnode/mnode/impl/inc/mndPrivilege.h index f6002e3be8..dc88b25f51 100644 --- a/source/dnode/mnode/impl/inc/mndPrivilege.h +++ b/source/dnode/mnode/impl/inc/mndPrivilege.h @@ -30,6 +30,7 @@ int32_t mndCheckDbPrivilege(SMnode *pMnode, const char *user, EOperType operType int32_t mndCheckDbPrivilegeByName(SMnode *pMnode, const char *user, EOperType operType, const char *dbname); int32_t mndCheckShowPrivilege(SMnode *pMnode, const char *user, EShowType showType, const char *dbname); int32_t mndCheckAlterUserPrivilege(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter); +int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndPrivilege.c b/source/dnode/mnode/impl/src/mndPrivilege.c index e4422c480f..151a2a6404 100644 --- a/source/dnode/mnode/impl/src/mndPrivilege.c +++ b/source/dnode/mnode/impl/src/mndPrivilege.c @@ -18,177 +18,20 @@ #include "mndDb.h" #include "mndUser.h" +#ifndef _PRIVILEGE int32_t mndInitPrivilege(SMnode *pMnode) { return 0; } - -void mndCleanupPrivilege(SMnode *pMnode) {} - -int32_t mndCheckOperPrivilege(SMnode *pMnode, const char *user, EOperType operType) { - int32_t code = 0; - SUserObj *pUser = mndAcquireUser(pMnode, user); - - if (pUser == NULL) { - terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - code = -1; - goto _OVER; - } - - if (pUser->superUser) { - goto _OVER; - } - - if (!pUser->enable) { - terrno = TSDB_CODE_MND_USER_DISABLED; - code = -1; - goto _OVER; - } - - switch (operType) { - case MND_OPER_CONNECT: - case MND_OPER_CREATE_FUNC: - case MND_OPER_DROP_FUNC: - case MND_OPER_SHOW_VARIBALES: - break; - default: - terrno = TSDB_CODE_MND_NO_RIGHTS; - code = -1; - } - -_OVER: - mndReleaseUser(pMnode, pUser); - return code; -} - -int32_t mndCheckAlterUserPrivilege(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter) { - if (pUser->superUser && pAlter->alterType != TSDB_ALTER_USER_PASSWD) { - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; - } - - if (pOperUser->superUser) return 0; - - if (!pOperUser->enable) { - terrno = TSDB_CODE_MND_USER_DISABLED; - return -1; - } - - if (pAlter->alterType == TSDB_ALTER_USER_PASSWD) { - if (strcmp(pUser->user, pOperUser->user) == 0) { - if (pOperUser->sysInfo) return 0; - } - } - - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; -} - -int32_t mndCheckShowPrivilege(SMnode *pMnode, const char *user, EShowType showType, const char *dbname) { - int32_t code = 0; - SUserObj *pUser = mndAcquireUser(pMnode, user); - - if (pUser == NULL) { - code = -1; - goto _OVER; - } - - if (pUser->superUser) { - goto _OVER; - } - - if (!pUser->enable) { - terrno = TSDB_CODE_MND_USER_DISABLED; - code = -1; - goto _OVER; - } - - if (pUser->sysInfo) { - goto _OVER; - } - - switch (showType) { - case TSDB_MGMT_TABLE_DB: - case TSDB_MGMT_TABLE_STB: - case TSDB_MGMT_TABLE_INDEX: - case TSDB_MGMT_TABLE_STREAMS: - case TSDB_MGMT_TABLE_CONSUMERS: - case TSDB_MGMT_TABLE_TOPICS: - case TSDB_MGMT_TABLE_SUBSCRIPTIONS: - case TSDB_MGMT_TABLE_FUNC: - case TSDB_MGMT_TABLE_QUERIES: - case TSDB_MGMT_TABLE_CONNS: - case TSDB_MGMT_TABLE_APPS: - case TSDB_MGMT_TABLE_TRANS: - code = 0; - break; - default: - terrno = TSDB_CODE_MND_NO_RIGHTS; - code = -1; - goto _OVER; - } - - if (showType == TSDB_MGMT_TABLE_STB || showType == TSDB_MGMT_TABLE_VGROUP || showType == TSDB_MGMT_TABLE_INDEX) { - code = mndCheckDbPrivilegeByName(pMnode, user, MND_OPER_READ_OR_WRITE_DB, dbname); - } - -_OVER: - mndReleaseUser(pMnode, pUser); - return code; -} - -int32_t mndCheckDbPrivilege(SMnode *pMnode, const char *user, EOperType operType, SDbObj *pDb) { - int32_t code = 0; - SUserObj *pUser = mndAcquireUser(pMnode, user); - - if (pUser == NULL) { - code = -1; - goto _OVER; - } - - if (pUser->superUser) goto _OVER; - - if (!pUser->enable) { - terrno = TSDB_CODE_MND_USER_DISABLED; - code = -1; - goto _OVER; - } - - if (operType == MND_OPER_CREATE_DB) { - if (pUser->sysInfo) goto _OVER; - } - - if (operType == MND_OPER_ALTER_DB || operType == MND_OPER_DROP_DB || operType == MND_OPER_COMPACT_DB || - operType == MND_OPER_TRIM_DB) { - if (strcmp(pUser->user, pDb->createUser) == 0 && pUser->sysInfo) goto _OVER; - } - - if (operType == MND_OPER_USE_DB || operType == MND_OPER_READ_OR_WRITE_DB) { - if (strcmp(pUser->user, pDb->createUser) == 0) goto _OVER; - if (taosHashGet(pUser->readDbs, pDb->name, strlen(pDb->name) + 1) != NULL) goto _OVER; - if (taosHashGet(pUser->writeDbs, pDb->name, strlen(pDb->name) + 1) != NULL) goto _OVER; - } - - if (operType == MND_OPER_WRITE_DB) { - if (strcmp(pUser->user, pDb->createUser) == 0) goto _OVER; - if (taosHashGet(pUser->writeDbs, pDb->name, strlen(pDb->name) + 1) != NULL) goto _OVER; - } - - if (operType == MND_OPER_READ_DB) { - if (strcmp(pUser->user, pDb->createUser) == 0) goto _OVER; - if (taosHashGet(pUser->readDbs, pDb->name, strlen(pDb->name) + 1) != NULL) goto _OVER; - } - - terrno = TSDB_CODE_MND_NO_RIGHTS; - code = -1; - -_OVER: - mndReleaseUser(pMnode, pUser); - return code; -} - +void mndCleanupPrivilege(SMnode *pMnode) {} +int32_t mndCheckOperPrivilege(SMnode *pMnode, const char *user, EOperType operType) { return 0; } +int32_t mndCheckAlterUserPrivilege(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter) { return 0; } +int32_t mndCheckShowPrivilege(SMnode *pMnode, const char *user, EShowType showType, const char *dbname) { return 0; } +int32_t mndCheckDbPrivilege(SMnode *pMnode, const char *user, EOperType operType, SDbObj *pDb) { return 0; } int32_t mndCheckDbPrivilegeByName(SMnode *pMnode, const char *user, EOperType operType, const char *dbname) { - SDbObj *pDb = mndAcquireDb(pMnode, dbname); - if (pDb == NULL) return -1; - - int32_t code = mndCheckDbPrivilege(pMnode, user, operType, pDb); - mndReleaseDb(pMnode, pDb); - return code; -} \ No newline at end of file + return 0; +} +int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp) { + memcpy(pRsp->user, pUser->user, TSDB_USER_LEN); + pRsp->superAuth = 1; + pRsp->version = pUser->authVersion; + return 0; +} +#endif \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 0452659d47..5da119bb30 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -15,8 +15,8 @@ #define _DEFAULT_SOURCE #include "mndUser.h" -#include "mndPrivilege.h" #include "mndDb.h" +#include "mndPrivilege.h" #include "mndShow.h" #include "mndTrans.h" #include "tbase64.h" @@ -408,7 +408,7 @@ static int32_t mndAlterUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SRpc return 0; } -static SHashObj *mndDupDbHash(SHashObj *pOld) { +SHashObj *mndDupDbHash(SHashObj *pOld) { SHashObj *pNew = taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pNew == NULL) { @@ -662,38 +662,6 @@ _OVER: return code; } -static int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp) { - memcpy(pRsp->user, pUser->user, TSDB_USER_LEN); - pRsp->superAuth = pUser->superUser; - pRsp->version = pUser->authVersion; - taosRLockLatch(&pUser->lock); - pRsp->readDbs = mndDupDbHash(pUser->readDbs); - pRsp->writeDbs = mndDupDbHash(pUser->writeDbs); - taosRUnLockLatch(&pUser->lock); - pRsp->createdDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - if (NULL == pRsp->createdDbs) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - SSdb *pSdb = pMnode->pSdb; - void *pIter = NULL; - while (1) { - SDbObj *pDb = NULL; - pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pDb); - if (pIter == NULL) break; - - if (strcmp(pDb->createUser, pUser->user) == 0) { - int32_t len = strlen(pDb->name) + 1; - taosHashPut(pRsp->createdDbs, pDb->name, len, pDb->name, len); - } - - sdbRelease(pSdb, pDb); - } - - return 0; -} - static int32_t mndProcessGetUserAuthReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; int32_t code = -1; From 4b8c007618406005beeb4ea5cb116034531a2816 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 27 Jul 2022 16:06:00 +0800 Subject: [PATCH 17/35] fix:fix remove from cache issue --- source/util/src/tcache.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c index 0975b10d55..7cbc1cd555 100644 --- a/source/util/src/tcache.c +++ b/source/util/src/tcache.c @@ -266,6 +266,7 @@ static void pushfrontNodeInEntryList(SCacheEntry *pEntry, SCacheNode *pNode) { pNode->pNext = pEntry->next; pEntry->next = pNode; pEntry->num += 1; + ASSERT((pEntry->next && pEntry->num > 0) || (NULL == pEntry->next && pEntry->num == 0)); } static void removeNodeInEntryList(SCacheEntry *pe, SCacheNode *prev, SCacheNode *pNode) { @@ -278,6 +279,7 @@ static void removeNodeInEntryList(SCacheEntry *pe, SCacheNode *prev, SCacheNode pNode->pNext = NULL; pe->num -= 1; + ASSERT((pe->next && pe->num > 0) || (NULL == pe->next && pe->num == 0)); } static FORCE_INLINE SCacheEntry *doFindEntry(SCacheObj *pCacheObj, const void *key, size_t keyLen) { @@ -657,15 +659,18 @@ void doTraverseElems(SCacheObj *pCacheObj, bool (*fp)(void *param, SCacheNode *p taosWLockLatch(&pEntry->latch); + SCacheNode **pPre = &pEntry->next; SCacheNode *pNode = pEntry->next; while (pNode != NULL) { SCacheNode *next = pNode->pNext; if (fp(pSup, pNode)) { + pPre = &pNode->pNext; pNode = pNode->pNext; } else { - pEntry->next = next; + *pPre = next; pEntry->num -= 1; + ASSERT((pEntry->next && pEntry->num > 0) || (NULL == pEntry->next && pEntry->num == 0)); atomic_sub_fetch_ptr(&pCacheObj->numOfElems, 1); pNode = next; From 75974255c7e50c6f75b07922318d7a9f8bafb0f7 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 27 Jul 2022 16:26:41 +0800 Subject: [PATCH 18/35] fix: fix mnd meta issue --- source/dnode/mnode/impl/src/mndQuery.c | 8 +++++--- source/libs/catalog/src/ctgRemote.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index e6e9cae100..2beeb10335 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -105,12 +105,14 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { terrno = TSDB_CODE_MSG_NOT_PROCESSED; return -1; } - - code = (*fp)(&reqMsg); + if ((*fp)(&reqMsg)) { + rsp.rspCode = terrno; + } else { + rsp.rspCode = 0; + } rsp.reqType = reqMsg.msgType; rsp.msgLen = reqMsg.info.rspLen; - rsp.rspCode = code; rsp.msg = reqMsg.info.rsp; taosArrayPush(batchRsp, &rsp); diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index 3ec30ac39f..55bfc88a49 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -27,7 +27,7 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu int32_t taskNum = taosArrayGetSize(pTaskId); SDataBuf taskMsg = *pMsg; int32_t offset = 0; - int32_t msgNum = (pMsg->pData && (pMsg->len > 0)) ? ntohl(*(int32_t*)pMsg->pData) : 0; + int32_t msgNum = (TSDB_CODE_SUCCESS == rspCode && pMsg->pData && (pMsg->len > 0)) ? ntohl(*(int32_t*)pMsg->pData) : 0; ASSERT(taskNum == msgNum || 0 == msgNum); ctgDebug("QID:0x%" PRIx64 " ctg got batch %d rsp %s", pJob->queryId, cbParam->batchId, TMSG_INFO(cbParam->reqType + 1)); From 1584dd0ac0a1406b609e9ba8fc879b5ee016c3a2 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 27 Jul 2022 16:42:09 +0800 Subject: [PATCH 19/35] fix: free ovfl cells when destroying page --- source/libs/tdb/src/db/tdbPage.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index 7a70b621c6..276b06b147 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -76,14 +76,17 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) ASSERT(xFree); + for (int iOvfl = 0; iOvfl < pPage->nOverflow; iOvfl++) { + tdbOsFree(pPage->apOvfl[iOvfl]); + } + ptr = pPage->pData; xFree(arg, ptr); return 0; } -void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, - TXN *, SBTree *pBt)) { +void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, TXN *, SBTree *pBt)) { pPage->pPageHdr = pPage->pData + szAmHdr; TDB_PAGE_NCELLS_SET(pPage, 0); TDB_PAGE_CCELLS_SET(pPage, pPage->pageSize - sizeof(SPageFtr)); @@ -99,8 +102,7 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell ASSERT((u8 *)pPage->pPageFtr == pPage->pFreeEnd); } -void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, - TXN *, SBTree *pBt)) { +void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *, int, TXN *, SBTree *pBt)) { pPage->pPageHdr = pPage->pData + szAmHdr; pPage->pCellIdx = pPage->pPageHdr + TDB_PAGE_HDR_SIZE(pPage); pPage->pFreeStart = pPage->pCellIdx + TDB_PAGE_OFFSET_SIZE(pPage) * TDB_PAGE_NCELLS(pPage); @@ -124,9 +126,8 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl nFree = TDB_PAGE_NFREE(pPage); nCells = TDB_PAGE_NCELLS(pPage); - iOvfl = 0; - for (; iOvfl < pPage->nOverflow; iOvfl++) { + for (iOvfl = 0; iOvfl < pPage->nOverflow; ++iOvfl) { if (pPage->aiOvfl[iOvfl] >= idx) { break; } @@ -146,6 +147,8 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl pNewCell = (SCell *)tdbOsMalloc(szCell); memcpy(pNewCell, pCell, szCell); + tdbDebug("tdbPage/new ovfl cell: %p", pNewCell); + pPage->apOvfl[iOvfl] = pNewCell; pPage->aiOvfl[iOvfl] = idx; pPage->nOverflow++; @@ -193,6 +196,8 @@ int tdbPageDropCell(SPage *pPage, int idx, TXN *pTxn, SBTree *pBt) { for (; iOvfl < pPage->nOverflow; iOvfl++) { if (pPage->aiOvfl[iOvfl] == idx) { // remove the over flow cell + tdbOsFree(pPage->apOvfl[iOvfl]); + tdbDebug("tdbPage/free ovfl cell: %p", pPage->apOvfl[iOvfl]); for (; (++iOvfl) < pPage->nOverflow;) { pPage->aiOvfl[iOvfl - 1] = pPage->aiOvfl[iOvfl] - 1; pPage->apOvfl[iOvfl - 1] = pPage->apOvfl[iOvfl]; @@ -248,7 +253,7 @@ void tdbPageCopy(SPage *pFromPage, SPage *pToPage) { int tdbPageCapacity(int pageSize, int amHdrSize) { int szPageHdr; - int minCellIndexSize; // at least one cell in cell index + int minCellIndexSize; // at least one cell in cell index if (pageSize < 65536) { szPageHdr = pageMethods.szPageHdr; From 00acf4520c3418350afd962607fbd6715ca6758e Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 27 Jul 2022 16:49:03 +0800 Subject: [PATCH 20/35] refactor(stream): remove option --- include/libs/stream/tstream.h | 2 +- source/dnode/mgmt/mgmt_vnode/src/vmWorker.c | 2 +- source/dnode/mnode/impl/src/mndScheduler.c | 2 ++ source/dnode/vnode/src/tq/tq.c | 2 +- source/libs/stream/src/streamTask.c | 4 ++-- source/libs/wal/inc/walInt.h | 6 ++++++ 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 6199732cc8..ab1c00a694 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -270,7 +270,7 @@ typedef struct SStreamTask { int64_t startVer; int64_t checkpointVer; int64_t processedVer; - int32_t numOfVgroups; + // int32_t numOfVgroups; // children info SArray* childEpInfo; // SArray diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index 5ad13e383a..9d1142801d 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -89,7 +89,7 @@ static void vmProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo); if (code != 0) { if (terrno != 0) code = terrno; - dGError("vgId:%d, msg:%p failed to stream since %s", pVnode->vgId, pMsg, terrstr()); + dGError("vgId:%d, msg:%p failed to process stream since %s", pVnode->vgId, pMsg, terrstr()); vmSendRsp(pMsg, code); } diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 9882b0a9ae..9d7fa537bb 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -391,10 +391,12 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { // exec pInnerTask->execType = TASK_EXEC__PIPE; +#if 0 SDbObj* pSourceDb = mndAcquireDb(pMnode, pStream->sourceDb); ASSERT(pDbObj != NULL); sdbRelease(pSdb, pSourceDb); pInnerTask->numOfVgroups = pSourceDb->cfg.numOfVgroups; +#endif if (tsSchedStreamToSnode) { SSnodeObj* pSnode = mndSchedFetchOneSnode(pMnode); diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 01f2f659ff..6b0e3944e3 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -653,7 +653,7 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, char* msg, int32_t msgLen) { } else { SReadHandle mgHandle = { .vnode = NULL, - .numOfVgroups = pTask->numOfVgroups, + .numOfVgroups = (int32_t)taosArrayGetSize(pTask->childEpInfo), }; pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &mgHandle); } diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index 5921e44a9c..216e3fa761 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -64,7 +64,7 @@ int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { if (tEncodeI32(pEncoder, pTask->selfChildId) < 0) return -1; if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1; - if (tEncodeI32(pEncoder, pTask->numOfVgroups) < 0) return -1; + /*if (tEncodeI32(pEncoder, pTask->numOfVgroups) < 0) return -1;*/ int32_t epSz = taosArrayGetSize(pTask->childEpInfo); if (tEncodeI32(pEncoder, epSz) < 0) return -1; @@ -119,7 +119,7 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { if (tDecodeI32(pDecoder, &pTask->selfChildId) < 0) return -1; if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1; if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1; - if (tDecodeI32(pDecoder, &pTask->numOfVgroups) < 0) return -1; + /*if (tDecodeI32(pDecoder, &pTask->numOfVgroups) < 0) return -1;*/ int32_t epSz; if (tDecodeI32(pDecoder, &epSz) < 0) return -1; diff --git a/source/libs/wal/inc/walInt.h b/source/libs/wal/inc/walInt.h index 20667fc918..3aebb1c6ba 100644 --- a/source/libs/wal/inc/walInt.h +++ b/source/libs/wal/inc/walInt.h @@ -61,26 +61,31 @@ static inline int32_t compareWalFileInfo(const void* pLeft, const void* pRight) } static inline int64_t walGetLastFileSize(SWal* pWal) { + if (taosArrayGetSize(pWal->fileInfoSet) == 0) return 0; SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet); return pInfo->fileSize; } static inline int64_t walGetLastFileFirstVer(SWal* pWal) { + if (taosArrayGetSize(pWal->fileInfoSet) == 0) return -1; SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet); return pInfo->firstVer; } static inline int64_t walGetCurFileFirstVer(SWal* pWal) { + if (pWal->writeCur == -1) return -1; SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur); return pInfo->firstVer; } static inline int64_t walGetCurFileLastVer(SWal* pWal) { + if (pWal->writeCur == -1) return -1; SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur); return pInfo->firstVer; } static inline int64_t walGetCurFileOffset(SWal* pWal) { + if (pWal->writeCur == -1) return -1; SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur); return pInfo->fileSize; } @@ -88,6 +93,7 @@ static inline int64_t walGetCurFileOffset(SWal* pWal) { static inline bool walCurFileClosed(SWal* pWal) { return taosArrayGetSize(pWal->fileInfoSet) != pWal->writeCur; } static inline SWalFileInfo* walGetCurFileInfo(SWal* pWal) { + if (pWal->writeCur == -1) return NULL; return (SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur); } From 5e1bbe0e7e0474338b2b5a968150434ac96d8cbf Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 27 Jul 2022 16:55:23 +0800 Subject: [PATCH 21/35] refactor(sma): remove option --- include/libs/executor/executor.h | 7 +++---- source/dnode/vnode/src/sma/smaRollup.c | 10 +++++----- source/libs/executor/src/executor.c | 18 ++++++++---------- source/libs/stream/src/streamExec.c | 8 ++++---- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 65e20336cc..500418df97 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -64,8 +64,7 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers); * @param SReadHandle * @return */ -qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, - SSchemaWrapper** pSchema); +qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, SSchemaWrapper** pSchema); /** * Set the input data block for the stream scan. @@ -74,7 +73,7 @@ qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* n * @param type * @return */ -int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type, bool assignUid); +int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type); /** * Set multiple input data blocks for the stream scan. @@ -84,7 +83,7 @@ int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type, bool * @param type * @return */ -int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type, bool assignUid); +int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type); /** * Update the table id list, add or remove. diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index a6fde1e2d2..cf489d72a8 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -611,8 +611,8 @@ static int32_t tdRSmaFetchAndSubmitResult(SRSmaInfoItem *pItem, STSchema *pTSche goto _err; } - smaDebug("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " version:%"PRIi64, SMA_VID(pSma), - suid, pItem->level, output->info.version); + smaDebug("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " version:%" PRIi64, + SMA_VID(pSma), suid, pItem->level, output->info.version); taosMemoryFreeClear(pReq); taosArrayClear(pResult); @@ -644,7 +644,7 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType smaDebug("vgId:%d, execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, SMA_VID(pSma), level, pItem->taskInfo, suid); - if (qSetStreamInput(pItem->taskInfo, pMsg, inputType, true) < 0) { // INPUT__DATA_SUBMIT + if (qSetStreamInput(pItem->taskInfo, pMsg, inputType) < 0) { // INPUT__DATA_SUBMIT smaError("vgId:%d, rsma % " PRIi8 " qSetStreamInput failed since %s", SMA_VID(pSma), level, tstrerror(terrno)); return TSDB_CODE_FAILED; } @@ -1329,7 +1329,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { tdRefRSmaInfo(pSma, pRSmaInfo); SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL}; - qSetStreamInput(pItem->taskInfo, &dataBlock, STREAM_INPUT__DATA_BLOCK, false); + qSetStreamInput(pItem->taskInfo, &dataBlock, STREAM_INPUT__DATA_BLOCK); tdRSmaFetchAndSubmitResult(pItem, pRSmaInfo->pTSchema, pRSmaInfo->suid, pStat, STREAM_INPUT__DATA_BLOCK); tdUnRefRSmaInfo(pSma, pRSmaInfo); @@ -1356,4 +1356,4 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { _end: tdReleaseSmaRef(smaMgmt.rsetId, pItem->refId, __func__, __LINE__); -} \ No newline at end of file +} diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 8b1cbb5ae8..5d4e5c9e8d 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -30,8 +30,7 @@ static void cleanupRefPool() { taosCloseRef(ref); } -static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, bool assignUid, - char* id) { +static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) { ASSERT(pOperator != NULL); if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { if (pOperator->numOfDownstream == 0) { @@ -44,12 +43,12 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu return TSDB_CODE_QRY_APP_ERROR; } pOperator->status = OP_NOT_OPENED; - return doSetStreamBlock(pOperator->pDownstream[0], input, numOfBlocks, type, assignUid, id); + return doSetStreamBlock(pOperator->pDownstream[0], input, numOfBlocks, type, id); } else { pOperator->status = OP_NOT_OPENED; SStreamScanInfo* pInfo = pOperator->info; - pInfo->assignBlockUid = assignUid; + /*pInfo->assignBlockUid = assignUid;*/ // TODO: if a block was set but not consumed, // prevent setting a different type of block @@ -95,11 +94,11 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu } } -int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type, bool assignUid) { - return qSetMultiStreamInput(tinfo, input, 1, type, assignUid); +int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type) { + return qSetMultiStreamInput(tinfo, input, 1, type); } -int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type, bool assignUid) { +int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) { if (tinfo == NULL) { return TSDB_CODE_QRY_APP_ERROR; } @@ -110,8 +109,7 @@ int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numO SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; - int32_t code = - doSetStreamBlock(pTaskInfo->pRoot, (void**)pBlocks, numOfBlocks, type, assignUid, GET_TASKID(pTaskInfo)); + int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void**)pBlocks, numOfBlocks, type, GET_TASKID(pTaskInfo)); if (code != TSDB_CODE_SUCCESS) { qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo)); } else { @@ -337,7 +335,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, } code = dsCreateDataSinker(pSubplan->pDataSink, handle, pSinkParam); - if(code != TSDB_CODE_SUCCESS){ + if (code != TSDB_CODE_SUCCESS) { taosMemoryFreeClear(pSinkParam); } } diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c index f782de95b9..2b2c96472d 100644 --- a/source/libs/stream/src/streamExec.c +++ b/source/libs/stream/src/streamExec.c @@ -22,22 +22,22 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) SStreamQueueItem* pItem = (SStreamQueueItem*)data; if (pItem->type == STREAM_INPUT__GET_RES) { SStreamTrigger* pTrigger = (SStreamTrigger*)data; - qSetMultiStreamInput(exec, pTrigger->pBlock, 1, STREAM_INPUT__DATA_BLOCK, false); + qSetMultiStreamInput(exec, pTrigger->pBlock, 1, STREAM_INPUT__DATA_BLOCK); } else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) { ASSERT(pTask->isDataScan); SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data; qDebug("task %d %p set submit input %p %p %d 1", pTask->taskId, pTask, pSubmit, pSubmit->data, *pSubmit->dataRef); - qSetStreamInput(exec, pSubmit->data, STREAM_INPUT__DATA_SUBMIT, false); + qSetStreamInput(exec, pSubmit->data, STREAM_INPUT__DATA_SUBMIT); } else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) { SStreamDataBlock* pBlock = (SStreamDataBlock*)data; SArray* blocks = pBlock->blocks; qDebug("task %d %p set ssdata input", pTask->taskId, pTask); - qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__DATA_BLOCK, false); + qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__DATA_BLOCK); } else if (pItem->type == STREAM_INPUT__MERGED_SUBMIT) { SStreamMergedSubmit* pMerged = (SStreamMergedSubmit*)data; SArray* blocks = pMerged->reqs; qDebug("task %d %p set submit input (merged), batch num: %d", pTask->taskId, pTask, (int32_t)blocks->size); - qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__MERGED_SUBMIT, false); + qSetMultiStreamInput(exec, blocks->pData, blocks->size, STREAM_INPUT__MERGED_SUBMIT); } else { ASSERT(0); } From d70795f013ccf8405f3e8df2d1398732a9fc8509 Mon Sep 17 00:00:00 2001 From: gccgdb1234 Date: Wed, 27 Jul 2022 16:56:13 +0800 Subject: [PATCH 22/35] doc: reference guide to reference manual --- docs/zh/12-taos-sql/02-database.md | 6 +++--- docs/zh/12-taos-sql/22-meta.md | 4 ++-- docs/zh/14-reference/index.md | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/zh/12-taos-sql/02-database.md b/docs/zh/12-taos-sql/02-database.md index c28a833eb6..edcad98fd8 100644 --- a/docs/zh/12-taos-sql/02-database.md +++ b/docs/zh/12-taos-sql/02-database.md @@ -40,7 +40,7 @@ database_option: { ### 参数说明 -- buffer: 一个 VNODE 写入内存池大小,单位为 MB,默认为 96,最小为 3,最大为 16384。 +- BUFFER: 一个 VNODE 写入内存池大小,单位为 MB,默认为 96,最小为 3,最大为 16384。 - CACHEMODEL:表示是否在内存中缓存子表的最近数据。默认为 none。 - none:表示不缓存。 - last_row:表示缓存子表最近一行数据。这将显著改善 LAST_ROW 函数的性能表现。 @@ -52,7 +52,7 @@ database_option: { - 1:表示一阶段压缩。 - 2:表示两阶段压缩。 - DURATION:数据文件存储数据的时间跨度。可以使用加单位的表示形式,如 DURATION 100h、DURATION 10d 等,支持 m(分钟)、h(小时)和 d(天)三个单位。不加时间单位时默认单位为天,如 DURATION 50 表示 50 天。 -- FSYNC:当 WAL 参数设置为 2 时,落盘的周期。默认为 3000,单位毫秒。最小为 0,表示每次写入立即落盘;最大为 180000,即三分钟。 +- WAL_FSYNC_PERIOD:当 WAL 参数设置为 2 时,落盘的周期。默认为 3000,单位毫秒。最小为 0,表示每次写入立即落盘;最大为 180000,即三分钟。 - MAXROWS:文件块中记录的最大条数,默认为 4096 条。 - MINROWS:文件块中记录的最小条数,默认为 100 条。 - KEEP:表示数据文件保存的天数,缺省值为 3650,取值范围 [1, 365000],且必须大于或等于 DURATION 参数值。数据库会自动删除保存时间超过 KEEP 值的数据。KEEP 可以使用加单位的表示形式,如 KEEP 100h、KEEP 10d 等,支持 m(分钟)、h(小时)和 d(天)三个单位。也可以不写单位,如 KEEP 50,此时默认单位为天。 @@ -64,7 +64,7 @@ database_option: { - STRICT:表示数据同步的一致性要求,默认为 off。 - on 表示强一致,即运行标准的 raft 协议,半数提交返回成功。 - off 表示弱一致,本地提交即返回成功。 -- WAL:WAL 级别,默认为 1。 +- WAL_LEVEL:WAL 级别,默认为 1。 - 1:写 WAL,但不执行 fsync。 - 2:写 WAL,而且执行 fsync。 - VGROUPS:数据库中初始 vgroup 的数目。 diff --git a/docs/zh/12-taos-sql/22-meta.md b/docs/zh/12-taos-sql/22-meta.md index 8c262413f5..e5bc800de7 100644 --- a/docs/zh/12-taos-sql/22-meta.md +++ b/docs/zh/12-taos-sql/22-meta.md @@ -80,8 +80,8 @@ TODO | 9 | buffer | INT | 每个 vnode 写缓存的内存块大小,单位 MB | | 10 | minrows | INT | 文件块中记录的最大条数 | | 11 | maxrows | INT | 文件块中记录的最小条数 | -| 12 | wallevel | INT | WAL 级别 | -| 13 | fsync | INT | 数据落盘周期 | +| 12 | wal_level | INT | WAL 级别 | +| 13 | walfsync_period | INT | 数据落盘周期 | | 14 | comp | INT | 数据压缩方式 | | 15 | precision | BINARY(2) | 时间分辨率 | | 16 | status | BINARY(10) | 数据库状态 | diff --git a/docs/zh/14-reference/index.md b/docs/zh/14-reference/index.md index f48ce31fce..e9c0c4fe23 100644 --- a/docs/zh/14-reference/index.md +++ b/docs/zh/14-reference/index.md @@ -1,8 +1,8 @@ --- -title: 参考指南 +title: 参考手册 --- -参考指南是对 TDengine 本身、 TDengine 各语言连接器及自带的工具最详细的介绍。 +参考手册是对 TDengine 本身、 TDengine 各语言连接器及自带的工具最详细的介绍。 ```mdx-code-block import DocCardList from '@theme/DocCardList'; From 6a8c1e4fdb918ff85e108d99a5030d1adf0bf197 Mon Sep 17 00:00:00 2001 From: gccgdb1234 Date: Wed, 27 Jul 2022 16:58:39 +0800 Subject: [PATCH 23/35] doc: change the order of operation chapter --- docs/zh/{13-operation => 17-operation}/01-pkg-install.md | 0 docs/zh/{13-operation => 17-operation}/02-planning.mdx | 0 docs/zh/{13-operation => 17-operation}/03-tolerance.md | 0 docs/zh/{13-operation => 17-operation}/06-admin.md | 0 docs/zh/{13-operation => 17-operation}/07-import.md | 0 docs/zh/{13-operation => 17-operation}/08-export.md | 0 docs/zh/{13-operation => 17-operation}/09-status.md | 0 docs/zh/{13-operation => 17-operation}/10-monitor.md | 0 docs/zh/{13-operation => 17-operation}/17-diagnose.md | 0 docs/zh/{13-operation => 17-operation}/_category_.yml | 0 docs/zh/{13-operation => 17-operation}/index.md | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename docs/zh/{13-operation => 17-operation}/01-pkg-install.md (100%) rename docs/zh/{13-operation => 17-operation}/02-planning.mdx (100%) rename docs/zh/{13-operation => 17-operation}/03-tolerance.md (100%) rename docs/zh/{13-operation => 17-operation}/06-admin.md (100%) rename docs/zh/{13-operation => 17-operation}/07-import.md (100%) rename docs/zh/{13-operation => 17-operation}/08-export.md (100%) rename docs/zh/{13-operation => 17-operation}/09-status.md (100%) rename docs/zh/{13-operation => 17-operation}/10-monitor.md (100%) rename docs/zh/{13-operation => 17-operation}/17-diagnose.md (100%) rename docs/zh/{13-operation => 17-operation}/_category_.yml (100%) rename docs/zh/{13-operation => 17-operation}/index.md (100%) diff --git a/docs/zh/13-operation/01-pkg-install.md b/docs/zh/17-operation/01-pkg-install.md similarity index 100% rename from docs/zh/13-operation/01-pkg-install.md rename to docs/zh/17-operation/01-pkg-install.md diff --git a/docs/zh/13-operation/02-planning.mdx b/docs/zh/17-operation/02-planning.mdx similarity index 100% rename from docs/zh/13-operation/02-planning.mdx rename to docs/zh/17-operation/02-planning.mdx diff --git a/docs/zh/13-operation/03-tolerance.md b/docs/zh/17-operation/03-tolerance.md similarity index 100% rename from docs/zh/13-operation/03-tolerance.md rename to docs/zh/17-operation/03-tolerance.md diff --git a/docs/zh/13-operation/06-admin.md b/docs/zh/17-operation/06-admin.md similarity index 100% rename from docs/zh/13-operation/06-admin.md rename to docs/zh/17-operation/06-admin.md diff --git a/docs/zh/13-operation/07-import.md b/docs/zh/17-operation/07-import.md similarity index 100% rename from docs/zh/13-operation/07-import.md rename to docs/zh/17-operation/07-import.md diff --git a/docs/zh/13-operation/08-export.md b/docs/zh/17-operation/08-export.md similarity index 100% rename from docs/zh/13-operation/08-export.md rename to docs/zh/17-operation/08-export.md diff --git a/docs/zh/13-operation/09-status.md b/docs/zh/17-operation/09-status.md similarity index 100% rename from docs/zh/13-operation/09-status.md rename to docs/zh/17-operation/09-status.md diff --git a/docs/zh/13-operation/10-monitor.md b/docs/zh/17-operation/10-monitor.md similarity index 100% rename from docs/zh/13-operation/10-monitor.md rename to docs/zh/17-operation/10-monitor.md diff --git a/docs/zh/13-operation/17-diagnose.md b/docs/zh/17-operation/17-diagnose.md similarity index 100% rename from docs/zh/13-operation/17-diagnose.md rename to docs/zh/17-operation/17-diagnose.md diff --git a/docs/zh/13-operation/_category_.yml b/docs/zh/17-operation/_category_.yml similarity index 100% rename from docs/zh/13-operation/_category_.yml rename to docs/zh/17-operation/_category_.yml diff --git a/docs/zh/13-operation/index.md b/docs/zh/17-operation/index.md similarity index 100% rename from docs/zh/13-operation/index.md rename to docs/zh/17-operation/index.md From 0bb173a9b07f36786084b1f49ca6b394ee4927a7 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 27 Jul 2022 17:03:30 +0800 Subject: [PATCH 24/35] test: recover case --- tests/script/jenkins/basic.txt | 4 +- tests/script/tsim/parser/limit1_stb.sim | 186 +------ tests/script/tsim/parser/limit1_tb.sim | 33 +- tests/script/tsim/parser/limit_stb.sim | 662 +++--------------------- tests/script/tsim/parser/limit_tb.sim | 8 +- 5 files changed, 107 insertions(+), 786 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 99beabe9ee..f34f29fb64 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -132,8 +132,8 @@ ./test.sh -f tsim/parser/lastrow.sim ./test.sh -f tsim/parser/lastrow2.sim ./test.sh -f tsim/parser/like.sim -# TD-17464 ./test.sh -f tsim/parser/limit.sim -# TD-17464 ./test.sh -f tsim/parser/limit1.sim +./test.sh -f tsim/parser/limit.sim +./test.sh -f tsim/parser/limit1.sim # TD-17623 ./test.sh -f tsim/parser/limit2.sim ./test.sh -f tsim/parser/mixed_blocks.sim ./test.sh -f tsim/parser/nchar.sim diff --git a/tests/script/tsim/parser/limit1_stb.sim b/tests/script/tsim/parser/limit1_stb.sim index 879fd7882f..7745e2d032 100644 --- a/tests/script/tsim/parser/limit1_stb.sim +++ b/tests/script/tsim/parser/limit1_stb.sim @@ -197,37 +197,10 @@ endi if $data01 != 1 then return -1 endi -sql select ts, c1, c2, c3, c4, c5, c6, c7, c8, c9 from $stb limit 1 offset 4; +sql select ts, c1, c2, c3, c4, c5, c6, c7, c8, c9 from $stb order by ts limit 1 offset 4; if $rows != 1 then return -1 endi -if $data00 != @18-09-17 09:40:00.000@ then - return -1 -endi -if $data01 != 4 then - return -1 -endi -if $data02 != 4 then - return -1 -endi -if $data03 != 4.00000 then - return -1 -endi -if $data04 != 4.000000000 then - return -1 -endi -if $data05 != 4 then - return -1 -endi -if $data06 != 4 then - return -1 -endi -if $data08 != binary4 then - return -1 -endi -if $data09 != nchar4 then - return -1 -endi ### select from supertable + where + limit offset sql select * from $stb where ts > '2018-09-17 09:30:00.000' and ts < '2018-09-17 10:30:00.000' limit 5 offset 1 @@ -393,12 +366,12 @@ endi ## TBASE-353 $limit = $totalNum / 2 sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 asc limit $limit offset 1 -if $rows != 0 then +if $rows != 5 then return -1 endi $limit = $totalNum / 2 -sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 asc limit $limit offset 0 +sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9),t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 asc limit $limit offset 0 if $rows != 6 then print expect 6, actual:$rows return -1 @@ -447,12 +420,12 @@ endi $limit = $totalNum / 2 sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 desc limit $limit offset 1 -if $rows != 0 then +if $rows != 5 then return -1 endi $limit = $totalNum / 2 -sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 desc limit $limit offset 0 +sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9),t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 desc limit $limit offset 0 if $rows != 6 then return -1 endi @@ -505,7 +478,7 @@ endi ### supertable aggregation + where + interval + limit offset ## TBASE-355 -sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit 5 offset 1 +sql select _wstart, max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit 5 offset 1 if $rows != 5 then return -1 endi @@ -521,20 +494,11 @@ endi if $data01 != 1 then return -1 endi -if $data15 != 12 then - return -1 -endi -if $data40 != @18-09-17 09:50:00.000@ then - return -1 -endi -if $data41 != 5 then - return -1 -endi ### [TBASE-361] $offset = $rowNum / 2 $offset = $offset + 1 -sql select max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit $offset offset $offset +sql select _wstart, max(c1), min(c2), avg(c3), count(c4), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit $offset offset $offset $val = $rowNum - $offset if $rows != $val then print expect $val, actual:$rows @@ -546,31 +510,10 @@ endi if $data01 != 1 then return -1 endi -if $data05 != 6 then - return -1 -endi -if $data30 != @18-10-22 03:00:00.000@ then - return -1 -endi -if $data31 != 4 then - return -1 -endi -if $data42 != 5 then - return -1 -endi -if $data53 != 6.000000000 then - return -1 -endi -if $data54 != 3 then - return -1 -endi -if $data55 != 36 then - return -1 -endi ## supertable aggregation + where + interval + group by order by tag + limit offset -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 interval(5m) group by t1 order by t1 desc limit 2 offset 0 -if $rows != 6 then +sql select _wstart, max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9),t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 partition by t1 interval(5m) order by t1 desc limit 2 offset 0 +if $rows != 2 then return -1 endi if $data01 != 5 then @@ -579,117 +522,18 @@ endi if $data09 != 4 then return -1 endi -if $data11 != 6 then - return -1 -endi -if $data19 != 4 then - return -1 -endi -if $data22 != 5 then - return -1 -endi -if $data29 != 3 then - return -1 -endi -if $data33 != 6.000000000 then - return -1 -endi -if $data39 != 3 then - return -1 -endi -if $data44 != 5 then - return -1 -endi -if $data49 != 2 then - return -1 -endi -if $data58 != nchar6 then - return -1 -endi -if $data59 != 2 then + +sql select _wstart, max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 partition by t1 interval(5m) order by t1 desc limit 2 offset 1 +if $rows != 2 then return -1 endi -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 interval(5m) group by t1 order by t1 desc limit 2 offset 1 -if $rows != 6 then - return -1 -endi -if $data01 != 6 then - return -1 -endi -if $data09 != 4 then - return -1 -endi -if $data13 != 5.000000000 then - return -1 -endi -if $data19 != 4 then - return -1 -endi -if $data28 != nchar6 then - return -1 -endi -if $data29 != 3 then - return -1 -endi -if $data46 != 1 then - return -1 -endi -if $data59 != 2 then - return -1 -endi - -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 interval(5m) group by t1 order by t1 desc limit 1 offset 0 +sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 partition by t1 interval(5m) limit 1 offset 0 if $rows != 3 then return -1 endi -if $data01 != 5 then - return -1 -endi -if $data09 != 4 then - return -1 -endi -if $data13 != 5.000000000 then - return -1 -endi -if $data19 != 3 then - return -1 -endi -if $data28 != nchar5 then - return -1 -endi -if $data29 != 2 then - return -1 -endi -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 and c1 > 0 and c2 < 9 and c3 > 4 and c4 < 7 and c5 > 4 interval(5m) group by t1 order by t1 desc limit 2 offset 0 +sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 and c1 > 0 and c2 < 9 and c3 > 4 and c4 < 7 and c5 > 4 partition by t1 interval(5m) limit 2 offset 0 if $rows != 6 then return -1 -endi -if $data01 != 5 then - return -1 -endi -if $data09 != 4 then - return -1 -endi -if $data19 != 4 then - return -1 -endi -if $data23 != 5.000000000 then - return -1 -endi -if $data29 != 3 then - return -1 -endi -if $data39 != 3 then - return -1 -endi -if $data48 != nchar5 then - return -1 -endi -if $data49 != 2 then - return -1 -endi -if $data59 != 2 then - return -1 -endi +endi \ No newline at end of file diff --git a/tests/script/tsim/parser/limit1_tb.sim b/tests/script/tsim/parser/limit1_tb.sim index 82914f3011..1ef6a62291 100644 --- a/tests/script/tsim/parser/limit1_tb.sim +++ b/tests/script/tsim/parser/limit1_tb.sim @@ -437,7 +437,7 @@ if $rows != $res then return -1 endi -sql select diff(c1) from $tb where c1 > 5 limit 2 offset 1 +sql select ts, diff(c1) from $tb where c1 > 5 limit 2 offset 1 if $rows != 2 then return -1 endi @@ -462,7 +462,7 @@ endi $limit = $rowNum / 2 $offset = $limit + 1 $val = $limit - 2 -sql select diff(c1) from $tb where c1 >= 0 limit $limit offset $offset +sql select ts, diff(c1) from $tb where c1 >= 0 limit $limit offset $offset if $rows != $val then return -1 endi @@ -493,7 +493,8 @@ endi if $data41 != 4 then return -1 endi -sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 5 offset 1 + +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 5 offset 1 if $rows != 5 then return -1 endi @@ -529,7 +530,7 @@ if $data41 != 5 then endi ## TBASE-334 -sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 2 offset 1 +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 2 offset 1 if $rows != 2 then return -1 endi @@ -549,7 +550,7 @@ if $data21 != null then return -1 endi -sql select min(c1), min(c2), min(c3), min(c4), min(c5), min(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5), min(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 if $rows != 3 then return -1 endi @@ -563,7 +564,7 @@ if $data21 != 0 then return -1 endi -sql select sum(c1), sum(c2), sum(c3), sum(c4), sum(c5), sum(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5 +sql select _wstart, sum(c1), sum(c2), sum(c3), sum(c4), sum(c5), sum(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5 if $rows != 5 then return -1 endi @@ -582,7 +583,7 @@ endi if $data41 != 9 then return -1 endi -sql select sum(c1), sum(c2), sum(c3), sum(c4), sum(c5), sum(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5 offset 1 +sql select _wstart, sum(c1), sum(c2), sum(c3), sum(c4), sum(c5), sum(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5 offset 1 if $rows != 5 then return -1 endi @@ -602,7 +603,7 @@ if $data41 != 18 then return -1 endi -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5), avg(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 0 +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5), avg(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 0 if $rows != 3 then return -1 endi @@ -618,7 +619,7 @@ endi if $data31 != null then return -1 endi -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5), avg(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5), avg(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 if $rows != 3 then return -1 endi @@ -640,7 +641,7 @@ sql select stddev(c1), stddev(c2), stddev(c3), stddev(c4), stddev(c5), stddev(c6 if $rows != 0 then return -1 endi -sql select stddev(c1), stddev(c2), stddev(c3), stddev(c4), stddev(c5), stddev(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5 offset 1 +sql select _wstart, stddev(c1), stddev(c2), stddev(c3), stddev(c4), stddev(c5), stddev(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5 offset 1 if $rows != 5 then return -1 endi @@ -660,7 +661,7 @@ if $data21 != 4.027681991 then return -1 endi -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(27m) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(27m) if $rows != 3704 then return -1 endi @@ -676,7 +677,7 @@ endi if $data31 != 3 then return -1 endi -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(27m) limit 5 offset 1 +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(27m) limit 5 offset 1 if $rows != 5 then return -1 endi @@ -720,7 +721,7 @@ if $rows != 0 then return -1 endi -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 if $rows != 3 then return -1 endi @@ -739,7 +740,7 @@ sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb w if $rows != 0 then return -1 endi -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 if $rows != 3 then return -1 endi @@ -753,7 +754,7 @@ if $data23 != 1.00000 then return -1 endi -sql select first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 0 +sql select _wstart, first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 0 if $rows != 3 then return -1 endi @@ -788,7 +789,7 @@ if $data29 != nchar8 then return -1 endi -sql select first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 1 +sql select _wstart, first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 1 if $rows != 3 then return -1 endi diff --git a/tests/script/tsim/parser/limit_stb.sim b/tests/script/tsim/parser/limit_stb.sim index a3064d59e9..0d0e4a8ea3 100644 --- a/tests/script/tsim/parser/limit_stb.sim +++ b/tests/script/tsim/parser/limit_stb.sim @@ -125,7 +125,7 @@ endi $offset = $tbNum * $rowNum $offset = $offset - 1 -sql select * from $stb limit 2 offset $offset +sql select * from $stb order by ts limit 2 offset $offset if $rows != 1 then return -1 endi @@ -163,40 +163,40 @@ endi $offset = $tbNum * $rowNum $offset = $offset / 2 $offset = $offset - 1 -sql select * from $stb limit 2 offset $offset +sql select * from $stb order by ts limit 2 offset $offset if $rows != 2 then return -1 endi -if $data00 != @18-09-17 10:30:00.002@ then - return -1 -endi -if $data01 != 9 then - return -1 -endi -if $data02 != 9 then - return -1 -endi -if $data03 != 9.00000 then - return -1 -endi -if $data04 != 9.000000000 then - return -1 -endi -if $data05 != 9 then - return -1 -endi -if $data06 != 9 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != binary9 then - return -1 -endi -if $data09 != nchar9 then - return -1 -endi +#if $data00 != @18-09-17 10:30:00.002@ then +# return -1 +#endi +#if $data01 != 9 then +# return -1 +#endi +#if $data02 != 9 then +# return -1 +#endi +#if $data03 != 9.00000 then +# return -1 +#endi +#if $data04 != 9.000000000 then +# return -1 +#endi +#if $data05 != 9 then +# return -1 +#endi +#if $data06 != 9 then +# return -1 +#endi +#if $data07 != 1 then +# return -1 +#endi +#if $data08 != binary9 then +# return -1 +#endi +#if $data09 != nchar9 then +# return -1 +#endi #if $data10 != @18-09-17 09:00:00.000@ then # return -1 #endi @@ -249,7 +249,7 @@ endi if $data01 != 1 then return -1 endi -sql select ts, c1, c2, c3, c4, c5, c6, c7, c8, c9 from $stb limit 1 offset 4; +sql select ts, c1, c2, c3, c4, c5, c6, c7, c8, c9 from $stb order by ts limit 1 offset 40; if $rows != 1 then return -1 endi @@ -327,7 +327,7 @@ if $data41 != 3 then return -1 endi -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from lm_stb0 where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-09-17 10:30:00.009' order by ts asc limit 1 offset 0; +sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from lm_stb0 where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-09-17 10:30:00.009' limit 1 offset 0; if $rows != 1 then return -1 endi @@ -358,7 +358,7 @@ if $data07 != nchar0 then endi #sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from lm_stb0 where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-09-17 10:30:00.000' and c1 > 1 and c2 < 9 and c3 > 2 and c4 < 8 and c5 > 3 and c6 < 7 and c7 > 0 and c8 like '%5' and t1 > 3 and t1 < 6 limit 1 offset 0; -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from lm_stb0 where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-09-17 10:30:00.000' and c1 > 1 and c2 < 9 and c3 > 2 and c4 < 8 and c5 > 3 and c6 < 7 and c7 = 'true' and c8 like '%5' and t1 > 3 and t1 < 6 limit 1 offset 0; +sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from lm_stb0 where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-09-17 10:30:00.000' and c1 > 1 and c2 < 9 and c3 > 2 and c4 < 8 and c5 > 3 and c6 < 7 and c7 = true and c8 like '%5' and t1 > 3 and t1 < 6 limit 1 offset 0; if $rows != 1 then return -1 endi @@ -398,12 +398,12 @@ endi ## TBASE-345 sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 asc limit 5 offset 1 -if $rows != 0 then +if $rows != 5 then return -1 endi -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 asc limit 5 offset 0 -if $rows != 6 then +sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9), t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 asc limit 5 offset 0 +if $rows != 5 then return -1 endi if $data00 != 9 then @@ -430,17 +430,14 @@ endi if $data47 != nchar0 then return -1 endi -if $data58 != 7 then - return -1 -endi sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 desc limit 5 offset 1 -if $rows != 0 then +if $rows != 5 then return -1 endi -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 desc limit 5 offset 0 -if $rows != 6 then +sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9), t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 group by t1 order by t1 desc limit 5 offset 0 +if $rows != 5 then return -1 endi if $data00 != 9 then @@ -470,15 +467,9 @@ endi if $data24 != 9.000000000 then return -1 endi -if $data53 != 45 then - return -1 -endi -if $data58 != 2 then - return -1 -endi ### supertable aggregation + where + interval + limit offset -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit 5 offset 1 +sql select _wstart, max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit 5 offset 1 if $rows != 5 then return -1 endi @@ -496,7 +487,7 @@ if $data41 != 5 then endi $offset = $rowNum / 2 $offset = $offset + 1 -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit $offset offset $offset +sql select _wstart, max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) limit $offset offset $offset $val = $rowNum - $offset if $rows != $val then return -1 @@ -516,8 +507,8 @@ endi ### supertable aggregation + where + interval + group by order by tag + limit offset ## TBASE-345 -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 interval(5m) group by t1 order by t1 desc limit 3 offset 0 -if $rows != 6 then +sql select _wstart, max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9), t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 partition by t1 interval(5m) order by t1 desc limit 3 offset 0 +if $rows != 3 then return -1 endi if $data01 != 5 then @@ -538,26 +529,9 @@ endi if $data29 != 3 then return -1 endi -if $data33 != 6.000000000 then - return -1 -endi -if $data39 != 3 then - return -1 -endi -if $data44 != 5 then - return -1 -endi -if $data49 != 2 then - return -1 -endi -if $data58 != nchar6 then - return -1 -endi -if $data59 != 2 then - return -1 -endi -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 interval(5m) group by t1 order by t1 desc limit 3 offset 1 + +sql select _wstart, max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9), t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 partition by t1 interval(5m) order by t1 desc limit 3 offset 1 if $rows != 3 then return -1 endi @@ -567,21 +541,9 @@ endi if $data09 != 4 then return -1 endi -if $data13 != 6.000000000 then - return -1 -endi -if $data19 != 3 then - return -1 -endi -if $data28 != nchar6 then - return -1 -endi -if $data29 != 2 then - return -1 -endi -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 interval(5m) group by t1 order by t1 desc limit 1 offset 0 -if $rows != 3 then +sql select _wstart, max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9), t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 5 and c1 > 0 and c2 < 9 and c3 > 1 and c4 < 7 and c5 > 4 partition by t1 interval(5m) order by t1 desc limit 1 offset 0 +if $rows != 1 then return -1 endi if $data01 != 5 then @@ -590,21 +552,9 @@ endi if $data09 != 4 then return -1 endi -if $data13 != 5.000000000 then - return -1 -endi -if $data19 != 3 then - return -1 -endi -if $data28 != nchar5 then - return -1 -endi -if $data29 != 2 then - return -1 -endi -sql select max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 and c1 > 0 and c2 < 9 and c3 > 4 and c4 < 7 and c5 > 4 interval(5m) group by t1 order by t1 desc limit 3 offset 0 -if $rows != 6 then +sql select _wstart, max(c1), min(c2), avg(c3), sum(c5), spread(c6), first(c7), last(c8), first(c9), t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 and c1 > 0 and c2 < 9 and c3 > 4 and c4 < 7 and c5 > 4 partition by t1 interval(5m) order by t1 desc limit 3 offset 0 +if $rows != 3 then return -1 endi if $data01 != 5 then @@ -622,80 +572,12 @@ endi if $data29 != 3 then return -1 endi -if $data39 != 3 then - return -1 -endi -if $data48 != nchar5 then - return -1 -endi -if $data49 != 2 then - return -1 -endi -if $data59 != 2 then + +sql select _wstart, max(c1), min(c1), avg(c1), count(c1), sum(c1), spread(c1), first(c1), last(c1), t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 partition by t1 interval(5m) order by t1 asc limit 1 offset 0 +if $rows != 1 then return -1 endi -sql select max(c1), min(c1), avg(c1), count(c1), sum(c1), spread(c1), first(c1), last(c1) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 1 and t1 < 8 interval(5m) group by t1 order by t1 desc limit 1 offset 0 -if $rows != 6 then - return -1 -endi -if $data01 != 0 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data09 != 7 then - return -1 -endi -print $data13 -if $data13 != 0.000000000 then - return -1 -endi -if $data19 != 6 then - return -1 -endi -if $data24 != 1 then - return -1 -endi -if $data29 != 5 then - return -1 -endi -if $data31 != 0 then - return -1 -endi -if $data32 != 0 then - return -1 -endi -if $data33 != 0.000000000 then - return -1 -endi -if $data34 != 1 then - return -1 -endi -if $data35 != 0 then - return -1 -endi - -print $data36 -if $data36 != 0.000000000 then - return -1 -endi -if $data37 != 0 then - return -1 -endi -if $data38 != 0 then - return -1 -endi -if $data39 != 4 then - return -1 -endi -if $data49 != 3 then - return -1 -endi -if $data59 != 2 then - return -1 -endi #sql select max(c2), min(c2), avg(c2), count(c2), sum(c2), spread(c2), first(c2), last(c2) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 3 and t1 < 6 interval(5m) group by t1 order by t1 desc limit 3 offset 1 #if $rows != 3 then @@ -741,89 +623,8 @@ endi # return -1 #endi -sql select max(c2), min(c2), avg(c2), count(c2), spread(c2), first(c2), last(c2), count(ts) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 3 and t1 < 6 interval(5m) group by t1 order by t1 desc limit 3 offset 1 -if $rows != 6 then - return -1 -endi -if $data00 != @18-09-17 09:10:00.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -if $data02 != NULL then - return -1 -endi -if $data09 != 5 then - return -1 -endi -if $data13 != NULL then - return -1 -endi -if $data19 != 5 then - return -1 -endi -if $data20 != @18-09-17 09:30:00.000@ then - return -1 -endi -if $data24 != 0 then - return -1 -endi -if $data25 != NULL then - return -1 -endi -if $data26 != NULL then - return -1 -endi -if $data27 != NULL then - return -1 -endi -if $data28 != 1 then - return -1 -endi -if $data29 != 5 then - return -1 -endi -if $data30 != @18-09-17 09:10:00.000@ then - return -1 -endi -if $data31 != 1 then - return -1 -endi -if $data32 != 1 then - return -1 -endi -if $data33 != 1.000000000 then - return -1 -endi -if $data34 != 1 then - return -1 -endi -if $data35 != 0.000000000 then - return -1 -endi -if $data36 != 1 then - return -1 -endi -if $data37 != 1 then - return -1 -endi -if $data38 != 1 then - return -1 -endi -if $data39 != 4 then - return -1 -endi -if $data41 != 2 then - return -1 -endi -if $data49 != 4 then - return -1 -endi -if $data51 != 3 then - return -1 -endi -if $data59 != 4 then +sql select _wstart, max(c2), min(c2), avg(c2), count(c2), spread(c2), first(c2), last(c2), count(ts), t1 from $stb where ts >= $ts0 and ts <= $tsu and t1 > 3 and t1 < 6 partition by t1 interval(5m) order by t1 desc limit 3 offset 1 +if $rows != 3 then return -1 endi @@ -832,7 +633,7 @@ if $rows != 0 then return -1 endi -sql select top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1 +sql select ts, top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1 if $rows != 3 then return -1 endi @@ -840,7 +641,7 @@ if $data01 != 9 then return -1 endi -sql select top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts asc limit 3 offset 1 +sql select ts, top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts asc limit 3 offset 1 if $rows != 3 then return -1 endi @@ -848,180 +649,18 @@ if $data01 != 9 then return -1 endi -sql select top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu group by t1 order by t1 desc slimit 2 soffset 1 limit 3 offset 1 -if $rows != 6 then - return -1 -endi -if $data00 != @18-09-17 10:00:00.008@ then - return -1 -endi -if $data01 != 6 then - return -1 -endi -if $data02 != 8 then - return -1 -endi -if $data10 != @18-09-17 10:10:00.008@ then - return -1 -endi -if $data11 != 7 then - return -1 -endi -if $data12 != 8 then - return -1 -endi -if $data20 != @18-09-17 10:20:00.008@ then - return -1 -endi -if $data21 != 8 then - return -1 -endi -if $data22 != 8 then - return -1 -endi -if $data30 != @18-09-17 10:00:00.007@ then - return -1 -endi -if $data31 != 6 then - return -1 -endi -if $data32 != 7 then - return -1 -endi -if $data40 != @18-09-17 10:10:00.007@ then - return -1 -endi -if $data41 != 7 then - return -1 -endi -if $data42 != 7 then - return -1 -endi -if $data50 != @18-09-17 10:20:00.007@ then - return -1 -endi -if $data51 != 8 then - return -1 -endi -if $data52 != 7 then +sql select ts, top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu group by t1 order by t1 desc limit 3 offset 1 +if $rows != 3 then return -1 endi -sql select top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu group by t1 order by t1 asc slimit 2 soffset 1 limit 3 offset 1 -if $rows != 6 then - return -1 -endi -if $data00 != @18-09-17 10:00:00.001@ then - return -1 -endi -if $data01 != 6 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data10 != @18-09-17 10:10:00.001@ then - return -1 -endi -if $data11 != 7 then - return -1 -endi -if $data12 != 1 then - return -1 -endi -if $data20 != @18-09-17 10:20:00.001@ then - return -1 -endi -if $data21 != 8 then - return -1 -endi -if $data22 != 1 then - return -1 -endi -if $data30 != @18-09-17 10:00:00.002@ then - return -1 -endi -if $data31 != 6 then - return -1 -endi -if $data32 != 2 then - return -1 -endi -if $data40 != @18-09-17 10:10:00.002@ then - return -1 -endi -if $data41 != 7 then - return -1 -endi -if $data42 != 2 then - return -1 -endi -if $data50 != @18-09-17 10:20:00.002@ then - return -1 -endi -if $data51 != 8 then - return -1 -endi -if $data52 != 2 then +sql select ts, top(c1, 5), t1 from $stb where ts >= $ts0 and ts <= $tsu group by t1 order by t1 asc limit 3 offset 1 +if $rows != 3 then return -1 endi -sql select top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu group by t1 order by ts desc slimit 2 soffset 1 limit 3 offset 1 -if $rows != 6 then - return -1 -endi -if $data00 != @18-09-17 10:20:00.001@ then - return -1 -endi -if $data01 != 8 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data10 != @18-09-17 10:10:00.001@ then - return -1 -endi -if $data11 != 7 then - return -1 -endi -if $data12 != 1 then - return -1 -endi -if $data20 != @18-09-17 10:00:00.001@ then - return -1 -endi -if $data21 != 6 then - return -1 -endi -if $data22 != 1 then - return -1 -endi -if $data30 != @18-09-17 10:20:00.002@ then - return -1 -endi -if $data31 != 8 then - return -1 -endi -if $data32 != 2 then - return -1 -endi -if $data40 != @18-09-17 10:10:00.002@ then - return -1 -endi -if $data41 != 7 then - return -1 -endi -if $data42 != 2 then - return -1 -endi -if $data50 != @18-09-17 10:00:00.002@ then - return -1 -endi -if $data51 != 6 then - return -1 -endi -if $data52 != 2 then +sql select top(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu partition by t1 order by ts desc limit 3 offset 1 +if $rows != 3 then return -1 endi @@ -1036,7 +675,7 @@ if $rows != 0 then return -1 endi -sql select bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1 +sql select ts, bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1 if $rows != 3 then return -1 endi @@ -1047,7 +686,7 @@ if $data01 != 0 then return -1 endi -sql select bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts asc limit 3 offset 1 +sql select ts, bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts asc limit 3 offset 1 if $rows != 3 then return -1 endi @@ -1058,183 +697,20 @@ if $data01 != 0 then return -1 endi -sql select bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu group by t1 order by t1 desc,ts desc slimit 2 soffset 1 limit 3 offset 1 +sql select ts, bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu partition by t1 slimit 2 soffset 1 limit 3 offset 1 if $rows != 6 then return -1 endi -#if $data00 != @18-09-17 09:30:00.000@ then -# return -1 -#endi -if $data01 != 3 then - return -1 -endi -if $data02 != 8 then - return -1 -endi -#if $data10 != @18-09-17 09:20:00.000@ then -# return -1 -#endi -if $data11 != 2 then - return -1 -endi -if $data12 != 8 then - return -1 -endi -#if $data20 != @18-09-17 09:10:00.000@ then -# return -1 -#endi -if $data21 != 1 then - return -1 -endi -if $data22 != 8 then - return -1 -endi -#if $data30 != @18-09-17 09:30:00.000@ then -# return -1 -#endi -if $data31 != 3 then - return -1 -endi -if $data32 != 7 then - return -1 -endi -#if $data40 != @18-09-17 09:20:00.000@ then -# return -1 -#endi -if $data41 != 2 then - return -1 -endi -if $data42 != 7 then - return -1 -endi -#if $data50 != @18-09-17 09:10:00.000@ then -# return -1 -#endi -if $data51 != 1 then - return -1 -endi -if $data52 != 7 then - return -1 -endi -sql select bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu group by t1 order by t1 asc,ts desc slimit 2 soffset 1 limit 3 offset 1 +sql select bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu partition by t1 slimit 2 soffset 1 limit 3 offset 1 if $rows != 6 then return -1 endi -#if $data00 != @18-09-17 09:30:00.000@ then -# return -1 -#endi -if $data01 != 3 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -#if $data10 != @18-09-17 09:20:00.000@ then -# return -1 -#endi -if $data11 != 2 then - return -1 -endi -if $data12 != 1 then - return -1 -endi -#if $data20 != @18-09-17 09:10:00.000@ then -# return -1 -#endi -if $data21 != 1 then - return -1 -endi -if $data22 != 1 then - return -1 -endi -#if $data30 != @18-09-17 09:30:00.000@ then -# return -1 -#endi -if $data31 != 3 then - return -1 -endi -if $data32 != 2 then - return -1 -endi -#if $data40 != @18-09-17 09:20:00.000@ then -# return -1 -#endi -if $data41 != 2 then - return -1 -endi -if $data42 != 2 then - return -1 -endi -#if $data50 != @18-09-17 09:10:00.000@ then -# return -1 -#endi -if $data51 != 1 then - return -1 -endi -if $data52 != 2 then - return -1 -endi -sql select bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu group by t1 order by ts desc slimit 2 soffset 1 limit 3 offset 1 +sql select bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu partition by t1 slimit 2 soffset 1 limit 3 offset 1 if $rows != 6 then return -1 endi -#if $data00 != @18-09-17 09:30:00.000@ then -# return -1 -#endi -if $data01 != 3 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -#if $data10 != @18-09-17 09:20:00.000@ then -# return -1 -#endi -if $data11 != 2 then - return -1 -endi -if $data12 != 1 then - return -1 -endi -#if $data20 != @18-09-17 09:10:00.000@ then -# return -1 -#endi -if $data21 != 1 then - return -1 -endi -if $data22 != 1 then - return -1 -endi -#if $data30 != @18-09-17 09:30:00.000@ then -# return -1 -#endi -if $data31 != 3 then - return -1 -endi -if $data32 != 2 then - return -1 -endi -#if $data40 != @18-09-17 09:20:00.000@ then -# return -1 -#endi -if $data41 != 2 then - return -1 -endi -if $data42 != 2 then - return -1 -endi -#if $data50 != @18-09-17 09:10:00.000@ then -# return -1 -#endi -if $data51 != 1 then - return -1 -endi -if $data52 != 2 then - return -1 -endi - sql select bottom(c1, 5) from $stb where ts >= $ts0 and ts <= $tsu order by ts asc limit 3 offset 5 if $rows != 0 then return -1 diff --git a/tests/script/tsim/parser/limit_tb.sim b/tests/script/tsim/parser/limit_tb.sim index f8a1e7ac6a..6c5706778d 100644 --- a/tests/script/tsim/parser/limit_tb.sim +++ b/tests/script/tsim/parser/limit_tb.sim @@ -445,7 +445,7 @@ if $rows != 0 then return -1 endi -sql select diff(c1) from $tb where c1 > 5 limit 2 offset 1 +sql select ts, diff(c1) from $tb where c1 > 5 limit 2 offset 1 if $rows != 2 then return -1 endi @@ -728,7 +728,7 @@ sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb w if $rows != 0 then return -1 endi -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1 if $rows != 3 then return -1 endi @@ -742,7 +742,7 @@ if $data23 != 9.00000 then return -1 endi -sql select first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 0 +sql select _wstart, first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 0 if $rows != 3 then return -1 endi @@ -777,7 +777,7 @@ if $data29 != nchar8 then return -1 endi -sql select first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 1 +sql select _wstart, first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 1 if $rows != 3 then return -1 endi From d786d85d657df8ac9478cd0df1b290d2b98ed7a8 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 27 Jul 2022 17:06:58 +0800 Subject: [PATCH 25/35] fix: compiler error --- source/dnode/mnode/impl/inc/mndUser.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndUser.h b/source/dnode/mnode/impl/inc/mndUser.h index 016ec3e6e9..970d1db7db 100644 --- a/source/dnode/mnode/impl/inc/mndUser.h +++ b/source/dnode/mnode/impl/inc/mndUser.h @@ -17,6 +17,7 @@ #define _TD_MND_USER_H_ #include "mndInt.h" +#include "thash.h" #ifdef __cplusplus extern "C" { @@ -28,9 +29,10 @@ SUserObj *mndAcquireUser(SMnode *pMnode, const char *userName); void mndReleaseUser(SMnode *pMnode, SUserObj *pUser); // for trans test -SSdbRaw *mndUserActionEncode(SUserObj *pUser); -int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp, - int32_t *pRspLen); +SSdbRaw *mndUserActionEncode(SUserObj *pUser); +SHashObj *mndDupDbHash(SHashObj *pOld); +int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp, + int32_t *pRspLen); #ifdef __cplusplus } From 2ba6ac5fbafef4daa8a95c20b756e59cf9674db9 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 27 Jul 2022 17:11:57 +0800 Subject: [PATCH 26/35] feat:add ts,table name from SDeleterRes --- include/common/tmsg.h | 3 +- include/libs/executor/dataSinkMgt.h | 3 +- include/libs/nodes/plannodes.h | 6 +-- source/client/src/tmq.c | 62 +++++++++++----------- source/common/src/tmsg.c | 2 + source/libs/executor/src/dataDeleter.c | 3 +- source/libs/nodes/src/nodesCloneFuncs.c | 2 +- source/libs/nodes/src/nodesCodeFuncs.c | 4 +- source/libs/planner/src/planLogicCreater.c | 6 +-- source/libs/planner/src/planPhysiCreater.c | 4 +- source/libs/qworker/src/qworker.c | 3 +- 11 files changed, 51 insertions(+), 47 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 73238697cb..563d6c766c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -3044,7 +3044,8 @@ typedef struct SDeleteRes { int64_t skey; int64_t ekey; int64_t affectedRows; - char tableFName[TSDB_TABLE_FNAME_LEN]; + char tableFName[TSDB_TABLE_NAME_LEN]; + char tsColName[TSDB_COL_NAME_LEN]; } SDeleteRes; int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes); diff --git a/include/libs/executor/dataSinkMgt.h b/include/libs/executor/dataSinkMgt.h index 90b804b382..47177dc11b 100644 --- a/include/libs/executor/dataSinkMgt.h +++ b/include/libs/executor/dataSinkMgt.h @@ -38,7 +38,8 @@ typedef struct SDeleterRes { int64_t skey; int64_t ekey; int64_t affectedRows; - char tableFName[TSDB_TABLE_FNAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; + char tsColName[TSDB_COL_NAME_LEN]; } SDeleterRes; typedef struct SDeleterParam { diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 0e05ed7887..9fe9760bb0 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -151,7 +151,7 @@ typedef struct SVnodeModifyLogicNode { uint64_t tableId; uint64_t stableId; int8_t tableType; // table type - char tableFName[TSDB_TABLE_FNAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; char tsColName[TSDB_COL_NAME_LEN]; STimeWindow deleteTimeRange; SVgroupsInfo* pVgroupList; @@ -494,7 +494,7 @@ typedef struct SQueryInserterNode { uint64_t tableId; uint64_t stableId; int8_t tableType; // table type - char tableFName[TSDB_TABLE_FNAME_LEN]; + char tableName[TSDB_TABLE_NAME_LEN]; int32_t vgId; SEpSet epSet; } SQueryInserterNode; @@ -503,7 +503,7 @@ typedef struct SDataDeleterNode { SDataSinkNode sink; uint64_t tableId; int8_t tableType; // table type - char tableFName[TSDB_TABLE_FNAME_LEN]; + char tableFName[TSDB_TABLE_NAME_LEN]; char tsColName[TSDB_COL_NAME_LEN]; STimeWindow deleteTimeRange; SNode* pAffectedRows; diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index df9072fe1a..88ebb099e5 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -2823,35 +2823,35 @@ end: // delete from db.tabl where .. -> delete from tabl where .. // delete from db .tabl where .. -> delete from tabl where .. -static void getTbName(char *sql){ - char *ch = sql; - - bool inBackQuote = false; - int8_t dotIndex = 0; - while(*ch != '\0'){ - if(!inBackQuote && *ch == '`'){ - inBackQuote = true; - ch++; - continue; - } - - if(inBackQuote && *ch == '`'){ - inBackQuote = false; - ch++; - - continue; - } - - if(!inBackQuote && *ch == '.'){ - dotIndex ++; - if(dotIndex == 2){ - memmove(sql, ch + 1, strlen(ch + 1) + 1); - break; - } - } - ch++; - } -} +//static void getTbName(char *sql){ +// char *ch = sql; +// +// bool inBackQuote = false; +// int8_t dotIndex = 0; +// while(*ch != '\0'){ +// if(!inBackQuote && *ch == '`'){ +// inBackQuote = true; +// ch++; +// continue; +// } +// +// if(inBackQuote && *ch == '`'){ +// inBackQuote = false; +// ch++; +// +// continue; +// } +// +// if(!inBackQuote && *ch == '.'){ +// dotIndex ++; +// if(dotIndex == 2){ +// memmove(sql, ch + 1, strlen(ch + 1) + 1); +// break; +// } +// } +// ch++; +// } +//} static int32_t taosDeleteData(TAOS* taos, void* meta, int32_t metaLen) { SDeleteRes req = {0}; @@ -2867,9 +2867,9 @@ static int32_t taosDeleteData(TAOS* taos, void* meta, int32_t metaLen) { goto end; } - getTbName(req.tableFName); +// getTbName(req.tableFName); char sql[256] = {0}; - sprintf(sql, "delete from `%s` where `%s` >= %" PRId64" and `%s` <= %" PRId64, req.tableFName, "ts", req.skey, "ts", req.ekey); + sprintf(sql, "delete from `%s` where `%s` >= %" PRId64" and `%s` <= %" PRId64, req.tableFName, req.tsColName, req.skey, req.tsColName, req.ekey); printf("delete sql:%s\n", sql); TAOS_RES* res = taos_query(taos, sql); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 59d3b45e09..68d7a3d292 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5682,6 +5682,7 @@ int32_t tEncodeDeleteRes(SEncoder *pCoder, const SDeleteRes *pRes) { if (tEncodeI64v(pCoder, pRes->affectedRows) < 0) return -1; if (tEncodeCStr(pCoder, pRes->tableFName) < 0) return -1; + if (tEncodeCStr(pCoder, pRes->tsColName) < 0) return -1; return 0; } @@ -5700,6 +5701,7 @@ int32_t tDecodeDeleteRes(SDecoder *pCoder, SDeleteRes *pRes) { if (tDecodeI64v(pCoder, &pRes->affectedRows) < 0) return -1; if (tDecodeCStrTo(pCoder, pRes->tableFName) < 0) return -1; + if (tDecodeCStrTo(pCoder, pRes->tsColName) < 0) return -1; return 0; } int32_t tEncodeSMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pRsp) { diff --git a/source/libs/executor/src/dataDeleter.c b/source/libs/executor/src/dataDeleter.c index 391aef529f..06b7c13fa2 100644 --- a/source/libs/executor/src/dataDeleter.c +++ b/source/libs/executor/src/dataDeleter.c @@ -90,7 +90,8 @@ static void toDataCacheEntry(SDataDeleterHandle* pHandle, const SInputData* pInp pRes->uidList = pHandle->pParam->pUidList; pRes->skey = pHandle->pDeleter->deleteTimeRange.skey; pRes->ekey = pHandle->pDeleter->deleteTimeRange.ekey; - strcpy(pRes->tableFName, pHandle->pDeleter->tableFName); + strcpy(pRes->tableName, pHandle->pDeleter->tableFName); + strcpy(pRes->tsColName, pHandle->pDeleter->tsColName); pRes->affectedRows = *(int64_t*)pColRes->pData; pBuf->useSize += pEntry->dataLen; diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index edae8ae118..5fc94c2642 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -401,7 +401,7 @@ static int32_t logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModi COPY_SCALAR_FIELD(tableId); COPY_SCALAR_FIELD(stableId); COPY_SCALAR_FIELD(tableType); - COPY_CHAR_ARRAY_FIELD(tableFName); + COPY_CHAR_ARRAY_FIELD(tableName); COPY_CHAR_ARRAY_FIELD(tsColName); COPY_OBJECT_FIELD(deleteTimeRange, sizeof(STimeWindow)); CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone); diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 51bd2c644b..d25b2f3e25 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -2326,7 +2326,7 @@ static int32_t physiQueryInsertNodeToJson(const void* pObj, SJson* pJson) { code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanTableType, pNode->tableType); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddStringToObject(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableFName); + code = tjsonAddStringToObject(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableName); } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkQueryInsertPhysiPlanVgId, pNode->vgId); @@ -2355,7 +2355,7 @@ static int32_t jsonToPhysiQueryInsertNode(const SJson* pJson, void* pObj) { code = tjsonGetTinyIntValue(pJson, jkQueryInsertPhysiPlanTableType, &pNode->tableType); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetStringValue(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableFName); + code = tjsonGetStringValue(pJson, jkQueryInsertPhysiPlanTableFName, pNode->tableName); } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetIntValue(pJson, jkQueryInsertPhysiPlanVgId, &pNode->vgId); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 8f8d666bd3..d405b75003 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -1292,8 +1292,7 @@ static int32_t createVnodeModifLogicNodeByDelete(SLogicPlanContext* pCxt, SDelet pModify->modifyType = MODIFY_TABLE_TYPE_DELETE; pModify->tableId = pRealTable->pMeta->uid; pModify->tableType = pRealTable->pMeta->tableType; - snprintf(pModify->tableFName, sizeof(pModify->tableFName), "%d.%s.%s", pCxt->pPlanCxt->acctId, - pRealTable->table.dbName, pRealTable->table.tableName); + snprintf(pModify->tableName, sizeof(pModify->tableName), "%s", pRealTable->table.tableName); strcpy(pModify->tsColName, pRealTable->pMeta->schema->name); pModify->deleteTimeRange = pDelete->timeRange; pModify->pAffectedRows = nodesCloneNode(pDelete->pCountFunc); @@ -1343,8 +1342,7 @@ static int32_t createVnodeModifLogicNodeByInsert(SLogicPlanContext* pCxt, SInser pModify->tableId = pRealTable->pMeta->uid; pModify->stableId = pRealTable->pMeta->suid; pModify->tableType = pRealTable->pMeta->tableType; - snprintf(pModify->tableFName, sizeof(pModify->tableFName), "%d.%s.%s", pCxt->pPlanCxt->acctId, - pRealTable->table.dbName, pRealTable->table.tableName); + snprintf(pModify->tableName, sizeof(pModify->tableName), "%s", pRealTable->table.tableName); TSWAP(pModify->pVgroupList, pRealTable->pVgroupList); pModify->pInsertCols = nodesCloneList(pInsert->pCols); if (NULL == pModify->pInsertCols) { diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 402989024c..beb3dd0067 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -1586,7 +1586,7 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod pInserter->tableId = pModify->tableId; pInserter->stableId = pModify->stableId; pInserter->tableType = pModify->tableType; - strcpy(pInserter->tableFName, pModify->tableFName); + strcpy(pInserter->tableName, pModify->tableName); pInserter->vgId = pModify->pVgroupList->vgroups[0].vgId; pInserter->epSet = pModify->pVgroupList->vgroups[0].epSet; vgroupInfoToNodeAddr(pModify->pVgroupList->vgroups, &pSubplan->execNode); @@ -1636,7 +1636,7 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pDeleter->tableId = pModify->tableId; pDeleter->tableType = pModify->tableType; - strcpy(pDeleter->tableFName, pModify->tableFName); + strcpy(pDeleter->tableFName, pModify->tableName); strcpy(pDeleter->tsColName, pModify->tsColName); pDeleter->deleteTimeRange = pModify->deleteTimeRange; diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index df57d0fef1..d1f8a50dab 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -283,7 +283,8 @@ int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, SDeleteRes *pRes pRes->skey = pDelRes->skey; pRes->ekey = pDelRes->ekey; pRes->affectedRows = pDelRes->affectedRows; - strcpy(pRes->tableFName, pDelRes->tableFName); + strcpy(pRes->tableFName, pDelRes->tableName); + strcpy(pRes->tsColName, pDelRes->tsColName); taosMemoryFree(output.pData); return TSDB_CODE_SUCCESS; From 1119cf0276cbc97613343c3a5ff6e77f07c7cdb5 Mon Sep 17 00:00:00 2001 From: gccgdb1234 Date: Wed, 27 Jul 2022 17:16:02 +0800 Subject: [PATCH 27/35] doc: change sidebar_label of reference manual --- docs/zh/14-reference/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/zh/14-reference/index.md b/docs/zh/14-reference/index.md index e9c0c4fe23..a9abff8f42 100644 --- a/docs/zh/14-reference/index.md +++ b/docs/zh/14-reference/index.md @@ -1,4 +1,5 @@ --- +sidebar_label: 参考手册 title: 参考手册 --- From f4fa20e3db4036099a9a8854b619ea38a0df6c3e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 27 Jul 2022 17:44:19 +0800 Subject: [PATCH 28/35] test: valgrind case --- tests/script/tsim/valgrind/checkError6.sim | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/script/tsim/valgrind/checkError6.sim b/tests/script/tsim/valgrind/checkError6.sim index 804961e7b0..5257468d6d 100644 --- a/tests/script/tsim/valgrind/checkError6.sim +++ b/tests/script/tsim/valgrind/checkError6.sim @@ -105,6 +105,40 @@ sql select * from stb where tbcol + 3 <> null; print =============== step5: explain +print =============== check +$null= + +system_content sh/checkValgrind.sh -n dnode1 +print cmd return result ----> [ $system_content ] +if $system_content > 0 then + return -1 +endi + +if $system_content == $null then + return -1 +endi + +print =============== restart +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start -v + +sql select avg(tbcol) as c from stb +sql select avg(tbcol) as c from stb where ts <= 1601481840000 +sql select avg(tbcol) as c from stb where tgcol < 5 and ts <= 1601481840000 +sql select avg(tbcol) as c from stb interval(1m) +sql select avg(tbcol) as c from stb interval(1d) +sql select avg(tbcol) as b from stb where ts <= 1601481840000 interval(1m) +sql select avg(tbcol) as c from stb group by tgcol +sql select avg(tbcol) as b from stb where ts <= 1601481840000 partition by tgcol interval(1m) +sql show table distributed stb +sql select count(tbcol) as b from stb where ts <= 1601481840000 partition by tgcol interval(1m) +sql select diff(tbcol) from stb where ts <= 1601481840000 +sql select first(tbcol), last(tbcol) as c from stb group by tgcol +sql select first(tbcol), last(tbcol) as b from stb where ts <= 1601481840000 and tbcol2 is null partition by tgcol interval(1m) +sql select first(tbcol), last(tbcol) as b from stb where ts <= 1601481840000 partition by tgcol interval(1m) +sql select count(tbcol), avg(tbcol), max(tbcol), min(tbcol), sum(tbcol), stddev(tbcol) from stb where ts <= 1601481840000 partition by tgcol interval(1m) +sql select last_row(tbcol), stddev(tbcol) from stb where tbcol > 5 and tbcol < 20 group by tgcol + _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT print =============== check From b12fa7494e0fb6b3e7ffc6088982170a347b215c Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Wed, 27 Jul 2022 18:28:54 +0800 Subject: [PATCH 29/35] enh: add interface for dynamic control data scan --- include/libs/function/functionMgt.h | 1 + source/libs/function/inc/builtins.h | 2 ++ source/libs/function/src/functionMgt.c | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index f1f60cb8e5..60ad3ba451 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -209,6 +209,7 @@ typedef enum EFuncDataRequired { } EFuncDataRequired; EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow); +EFuncDataRequired fmFuncDynDataRequired(int32_t funcId, void* pRes, STimeWindow* pTimeWindow); int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet); int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet); diff --git a/source/libs/function/inc/builtins.h b/source/libs/function/inc/builtins.h index 256500ff8c..f5efcd5206 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -25,6 +25,7 @@ extern "C" { typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len); typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow); typedef int32_t (*FCreateMergeFuncParameters)(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters); +typedef EFuncDataRequired (*FFuncDynDataRequired)(void* pRes, STimeWindow* pTimeWindow); typedef struct SBuiltinFuncDefinition { const char* name; @@ -32,6 +33,7 @@ typedef struct SBuiltinFuncDefinition { uint64_t classification; FTranslateFunc translateFunc; FFuncDataRequired dataRequiredFunc; + FFuncDynDataRequired dynDataRequiredFunc; FExecGetEnv getEnvFunc; FExecInit initFunc; FExecProcess processFunc; diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index c173522683..020fd648e1 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -103,6 +103,13 @@ EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWin return funcMgtBuiltins[pFunc->funcId].dataRequiredFunc(pFunc, pTimeWindow); } +EFuncDataRequired fmFuncDynDataRequired(int32_t funcId, void* pRes, STimeWindow* pTimeWindow) { + if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) { + return TSDB_CODE_FAILED; + } + return funcMgtBuiltins[funcId].dynDataRequiredFunc(pRes, pTimeWindow); +} + int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) { if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) { return TSDB_CODE_FAILED; From 8d59865551259c0bd515aef76d0a6a2b1d1edb76 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 27 Jul 2022 19:15:54 +0800 Subject: [PATCH 30/35] feat: de submodule (#15464) * feat: use contrib instead of submodule for tools/taosws/taosa * feat: de-submodule, remove taostools/taosws/taosadapter from .gitmodules * ci: remove submodule taos-tools, taosadapter and taosws-rs from cache Co-authored-by: tangfangzhi --- .gitignore | 2 ++ .gitmodules | 9 --------- Jenkinsfile2 | 13 +++++++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index d7fcb019ae..80fd850cd4 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,8 @@ pysim/ *.out *DS_Store tests/script/api/batchprepare +taosadapter +taosadapter-debug # Doxygen Generated files html/ diff --git a/.gitmodules b/.gitmodules index 31c211bf89..07e4bb2b9c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,12 +13,3 @@ [submodule "examples/rust"] path = examples/rust url = https://github.com/songtianyi/tdengine-rust-bindings.git -[submodule "tools/taos-tools"] - path = tools/taos-tools - url = https://github.com/taosdata/taos-tools -[submodule "tools/taosadapter"] - path = tools/taosadapter - url = https://github.com/taosdata/taosadapter.git -[submodule "tools/taosws-rs"] - path = tools/taosws-rs - url = https://github.com/taosdata/taosws-rs diff --git a/Jenkinsfile2 b/Jenkinsfile2 index 1b04e40f2a..83fa1479dc 100644 --- a/Jenkinsfile2 +++ b/Jenkinsfile2 @@ -113,6 +113,12 @@ def pre_test(){ echo "unmatched reposiotry ${CHANGE_URL}" ''' } + sh ''' + cd ${WKC} + git rm --cached tools/taos-tools 2>/dev/null || : + git rm --cached tools/taosadapter 2>/dev/null || : + git rm --cached tools/taosws-rs 2>/dev/null || : + ''' sh ''' cd ${WKC} git submodule update --init --recursive @@ -258,6 +264,13 @@ def pre_test_win(){ git branch git log -5 ''' + bat ''' + cd %WIN_COMMUNITY_ROOT% + git rm --cached tools/taos-tools 2>nul + git rm --cached tools/taosadapter 2>nul + git rm --cached tools/taosws-rs 2>nul + exit 0 + ''' bat ''' cd %WIN_COMMUNITY_ROOT% git submodule update --init --recursive From 40e67b676cc755a4b8a7f40df9854b4125fd5937 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 27 Jul 2022 19:32:50 +0800 Subject: [PATCH 31/35] test: valgrind case --- tests/script/jenkins/basic.txt | 2 +- tests/script/tsim/stable/show.sim | 61 ------------------------------- 2 files changed, 1 insertion(+), 62 deletions(-) delete mode 100644 tests/script/tsim/stable/show.sim diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index f34f29fb64..8de606e705 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -274,7 +274,6 @@ ./test.sh -f tsim/stable/dnode3.sim ./test.sh -f tsim/stable/metrics.sim ./test.sh -f tsim/stable/refcount.sim -./test.sh -f tsim/stable/show.sim ./test.sh -f tsim/stable/tag_add.sim ./test.sh -f tsim/stable/tag_drop.sim ./test.sh -f tsim/stable/tag_filter.sim @@ -308,6 +307,7 @@ ./test.sh -f tsim/valgrind/checkError4.sim ./test.sh -f tsim/valgrind/checkError5.sim ./test.sh -f tsim/valgrind/checkError6.sim +./test.sh -f tsim/valgrind/checkError7.sim # --- vnode # unsupport ./test.sh -f tsim/vnode/replica3_basic.sim diff --git a/tests/script/tsim/stable/show.sim b/tests/script/tsim/stable/show.sim deleted file mode 100644 index d3ab75adf5..0000000000 --- a/tests/script/tsim/stable/show.sim +++ /dev/null @@ -1,61 +0,0 @@ -system sh/stop_dnodes.sh -system sh/deploy.sh -n dnode1 -i 1 -system sh/exec.sh -n dnode1 -s start -sql connect - -print ======================== create stable -sql create database d1 -sql use d1 - -$x = 0 -while $x < 128 - $tb = d1.s . $x - sql create table $tb (ts timestamp, i int) tags (j int) - $x = $x + 1 -endw - -print ======================== describe stables -# TODO : create stable error -$m = 0 -while $m < 128 - $tb = s . $m - $filter = ' . $tb - $filter = $filter . ' - sql show stables like $filter - print sql : show stables like $filter - if $rows != 1 then - print expect 1, actual: $rows - return -1 - endi - $m = $m + 1 -endw - - -print ======================== show stables - -sql show d1.stables - -print num of stables is $rows -if $rows != 128 then - return -1 -endi - -print ======================== create table - -$x = 0 -while $x < 424 - $tb = d1.t . $x - sql create table $tb using d1.s0 tags( $x ) - $x = $x + 1 -endw - -print ======================== show stables - -sql show d1.tables - -print num of tables is $rows -if $rows != 424 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT From ba0c1b368907fe798f63ee4ad7f3bba08985a8e4 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 27 Jul 2022 20:04:31 +0800 Subject: [PATCH 32/35] refactor(stream) --- include/libs/executor/executor.h | 9 --------- source/dnode/vnode/src/sma/smaRollup.c | 4 ++-- source/libs/executor/src/executor.c | 4 ---- source/libs/stream/src/streamDispatch.c | 20 ++++++++++++++++---- source/libs/stream/src/streamExec.c | 2 +- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 500418df97..a7fae403ed 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -66,15 +66,6 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers); */ qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, SSchemaWrapper** pSchema); -/** - * Set the input data block for the stream scan. - * @param tinfo - * @param input - * @param type - * @return - */ -int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type); - /** * Set multiple input data blocks for the stream scan. * @param tinfo diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index cf489d72a8..4b29b13abd 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -644,7 +644,7 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t inputType smaDebug("vgId:%d, execute rsma %" PRIi8 " task for qTaskInfo:%p suid:%" PRIu64, SMA_VID(pSma), level, pItem->taskInfo, suid); - if (qSetStreamInput(pItem->taskInfo, pMsg, inputType) < 0) { // INPUT__DATA_SUBMIT + if (qSetMultiStreamInput(pItem->taskInfo, pMsg, 1, inputType) < 0) { // INPUT__DATA_SUBMIT smaError("vgId:%d, rsma % " PRIi8 " qSetStreamInput failed since %s", SMA_VID(pSma), level, tstrerror(terrno)); return TSDB_CODE_FAILED; } @@ -1329,7 +1329,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { tdRefRSmaInfo(pSma, pRSmaInfo); SSDataBlock dataBlock = {.info.type = STREAM_GET_ALL}; - qSetStreamInput(pItem->taskInfo, &dataBlock, STREAM_INPUT__DATA_BLOCK); + qSetMultiStreamInput(pItem->taskInfo, &dataBlock, 1, STREAM_INPUT__DATA_BLOCK); tdRSmaFetchAndSubmitResult(pItem, pRSmaInfo->pTSchema, pRSmaInfo->suid, pStat, STREAM_INPUT__DATA_BLOCK); tdUnRefRSmaInfo(pSma, pRSmaInfo); diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 5d4e5c9e8d..1618bffb09 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -94,10 +94,6 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu } } -int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type) { - return qSetMultiStreamInput(tinfo, input, 1, type); -} - int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) { if (tinfo == NULL) { return TSDB_CODE_QRY_APP_ERROR; diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 2e33632f12..44f38823ee 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -227,6 +227,8 @@ int32_t streamDispatchOneReq(SStreamTask* pTask, const SStreamDispatchReq* pReq, msg.pCont = buf; msg.msgType = pTask->dispatchMsgType; + qDebug("dispatch from task %d to task %d node %d", pTask->taskId, pReq->taskId, vgId); + tmsgSendReq(pEpSet, &msg); code = 0; @@ -281,8 +283,10 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat return code; } else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) { - SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; - ASSERT(pTask->shuffleDispatcher.waitingRspCnt == 0); + int32_t rspCnt = atomic_load_32(&pTask->shuffleDispatcher.waitingRspCnt); + ASSERT(rspCnt == 0); + + SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; int32_t vgSz = taosArrayGetSize(vgInfo); SStreamDispatchReq* pReqs = taosMemoryCalloc(vgSz, sizeof(SStreamDispatchReq)); if (pReqs == NULL) { @@ -301,7 +305,10 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat if (pReqs[i].data == NULL || pReqs[i].dataLen == NULL) { goto FAIL_SHUFFLE_DISPATCH; } + SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); + pReqs[i].taskId = pVgInfo->taskId; } + for (int32_t i = 0; i < blockNum; i++) { SSDataBlock* pDataBlock = taosArrayGet(pData->blocks, i); char* ctbName = buildCtbNameByGroupId(pTask->shuffleDispatcher.stbFullName, pDataBlock->info.groupId); @@ -309,6 +316,9 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat // TODO: get hash function by hashMethod uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName)); + taosMemoryFree(ctbName); + + bool found = false; // TODO: optimize search int32_t j; for (j = 0; j < vgSz; j++) { @@ -318,12 +328,14 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat if (streamAddBlockToDispatchMsg(pDataBlock, &pReqs[j]) < 0) { goto FAIL_SHUFFLE_DISPATCH; } - pReqs[j].taskId = pVgInfo->taskId; pReqs[j].blockNum++; + found = true; break; } } + ASSERT(found); } + for (int32_t i = 0; i < vgSz; i++) { if (pReqs[i].blockNum > 0) { // send @@ -331,7 +343,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat if (streamDispatchOneReq(pTask, &pReqs[i], pVgInfo->vgId, &pVgInfo->epSet) < 0) { goto FAIL_SHUFFLE_DISPATCH; } - pTask->shuffleDispatcher.waitingRspCnt++; + atomic_add_fetch_32(&pTask->shuffleDispatcher.waitingRspCnt, 1); } } code = 0; diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c index 2b2c96472d..7c5cd6e391 100644 --- a/source/libs/stream/src/streamExec.c +++ b/source/libs/stream/src/streamExec.c @@ -27,7 +27,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) ASSERT(pTask->isDataScan); SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data; qDebug("task %d %p set submit input %p %p %d 1", pTask->taskId, pTask, pSubmit, pSubmit->data, *pSubmit->dataRef); - qSetStreamInput(exec, pSubmit->data, STREAM_INPUT__DATA_SUBMIT); + qSetMultiStreamInput(exec, pSubmit->data, 1, STREAM_INPUT__DATA_SUBMIT); } else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) { SStreamDataBlock* pBlock = (SStreamDataBlock*)data; SArray* blocks = pBlock->blocks; From e2648a7023c2a28fa447d09816146e70c00c79f1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 27 Jul 2022 20:29:25 +0800 Subject: [PATCH 33/35] test: restore case --- tests/script/jenkins/basic.txt | 16 ++++----- tests/script/tsim/parser/limit1_stb.sim | 47 +------------------------ 2 files changed, 9 insertions(+), 54 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 8de606e705..9be5f4fe59 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -1,7 +1,7 @@ #======================b1-start=============== -# ---- user +# ---- user ---- ./test.sh -f tsim/user/basic.sim ./test.sh -f tsim/user/password.sim ./test.sh -f tsim/user/privilege_db.sim @@ -58,13 +58,13 @@ # unsupport ./test.sh -f tsim/dnode/vnode_clean.sim ./test.sh -f tsim/dnode/use_dropped_dnode.sim -# ---- import +# ---- import ---- ./test.sh -f tsim/import/basic.sim ./test.sh -f tsim/import/commit.sim ./test.sh -f tsim/import/large.sim ./test.sh -f tsim/import/replica1.sim -# ---- insert +# ---- insert ---- ./test.sh -f tsim/insert/backquote.sim ./test.sh -f tsim/insert/basic.sim ./test.sh -f tsim/insert/basic0.sim @@ -164,7 +164,7 @@ # TD-17704 ./test.sh -f tsim/parser/union_sysinfo.sim # TD-17661 ./test.sh -f tsim/parser/where.sim -# ---- query +# ---- query ---- ./test.sh -f tsim/query/charScalarFunction.sim # ./test.sh -f tsim/query/explain.sim ./test.sh -f tsim/query/interval-offset.sim @@ -190,7 +190,7 @@ ./test.sh -f tsim/mnode/basic4.sim ./test.sh -f tsim/mnode/basic5.sim -# ---- show +# ---- show ---- ./test.sh -f tsim/show/basic.sim # ---- table @@ -260,7 +260,7 @@ ./test.sh -f tsim/tmq/snapshot.sim ./test.sh -f tsim/tmq/snapshot1.sim -# --- stable +# --- stable ---- ./test.sh -f tsim/stable/alter_comment.sim ./test.sh -f tsim/stable/alter_count.sim ./test.sh -f tsim/stable/alter_import.sim @@ -350,13 +350,13 @@ ./test.sh -f tsim/column/metrics.sim ./test.sh -f tsim/column/table.sim -# ---- compress +# ---- compress ---- ./test.sh -f tsim/compress/commitlog.sim ./test.sh -f tsim/compress/compress2.sim ./test.sh -f tsim/compress/compress.sim ./test.sh -f tsim/compress/uncompress.sim -# ---- compute +# ---- compute ---- ./test.sh -f tsim/compute/avg.sim ./test.sh -f tsim/compute/block_dist.sim ./test.sh -f tsim/compute/bottom.sim diff --git a/tests/script/tsim/parser/limit1_stb.sim b/tests/script/tsim/parser/limit1_stb.sim index 7745e2d032..43fa06230c 100644 --- a/tests/script/tsim/parser/limit1_stb.sim +++ b/tests/script/tsim/parser/limit1_stb.sim @@ -51,40 +51,10 @@ endi ##TBASE-352 $offset = $tbNum * $rowNum $offset = $offset - 1 -sql select * from $stb limit 2 offset $offset +sql select * from $stb order by ts limit 2 offset $offset if $rows != 1 then return -1 endi -if $data00 != @18-11-25 19:30:00.000@ then - return -1 -endi -if $data01 != 9 then - return -1 -endi -if $data02 != NULL then - return -1 -endi -if $data03 != 9.00000 then - return -1 -endi -if $data04 != NULL then - return -1 -endi -if $data05 != 9 then - return -1 -endi -if $data06 != 9 then - return -1 -endi -if $data07 != 1 then - return -1 -endi -if $data08 != binary9 then - return -1 -endi -if $data09 != nchar9 then - return -1 -endi $offset = $tbNum * $rowNum $offset = $offset / 2 @@ -207,21 +177,6 @@ sql select * from $stb where ts > '2018-09-17 09:30:00.000' and ts < '2018-09-17 if $rows != 5 then return -1 endi -if $data01 != 5 then - return -1 -endi -if $data11 != 6 then - return -1 -endi -if $data21 != 7 then - return -1 -endi -if $data31 != 8 then - return -1 -endi -if $data41 != 4 then - return -1 -endi $offset = $totalNum / 2 sql select * from $stb where ts >= $ts0 and ts <= $tsu limit 5 offset $offset From 904ec81bf96f3f65d7e99fccd577e82a3cf3ba53 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 27 Jul 2022 21:02:21 +0800 Subject: [PATCH 34/35] fix(stream): concurrency dispatch --- source/libs/stream/src/streamDispatch.c | 4 +++- tests/script/jenkins/basic.txt | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 44f38823ee..834a3af0d5 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -328,6 +328,9 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat if (streamAddBlockToDispatchMsg(pDataBlock, &pReqs[j]) < 0) { goto FAIL_SHUFFLE_DISPATCH; } + if (pReqs[j].blockNum == 0) { + atomic_add_fetch_32(&pTask->shuffleDispatcher.waitingRspCnt, 1); + } pReqs[j].blockNum++; found = true; break; @@ -343,7 +346,6 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat if (streamDispatchOneReq(pTask, &pReqs[i], pVgInfo->vgId, &pVgInfo->epSet) < 0) { goto FAIL_SHUFFLE_DISPATCH; } - atomic_add_fetch_32(&pTask->shuffleDispatcher.waitingRspCnt, 1); } } code = 0; diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 99beabe9ee..5d7aa8eda1 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -298,8 +298,9 @@ # --- sma ./test.sh -f tsim/sma/drop_sma.sim ./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim -./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim -./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim +# temp disable +#./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim +#./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim # --- valgrind ./test.sh -f tsim/valgrind/checkError1.sim From 5b12e7216eeb64d46c6ede4182f07a26450641f3 Mon Sep 17 00:00:00 2001 From: gccgdb1234 Date: Thu, 28 Jul 2022 08:58:58 +0800 Subject: [PATCH 35/35] doc: change sidebar label for reference manual --- docs/zh/14-reference/_category_.yml | 2 +- docs/zh/14-reference/index.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/zh/14-reference/_category_.yml b/docs/zh/14-reference/_category_.yml index ae861a15ff..faca32476c 100644 --- a/docs/zh/14-reference/_category_.yml +++ b/docs/zh/14-reference/_category_.yml @@ -1 +1 @@ -label: 参考指南 \ No newline at end of file +label: 参考手册 \ No newline at end of file diff --git a/docs/zh/14-reference/index.md b/docs/zh/14-reference/index.md index a9abff8f42..e9c0c4fe23 100644 --- a/docs/zh/14-reference/index.md +++ b/docs/zh/14-reference/index.md @@ -1,5 +1,4 @@ --- -sidebar_label: 参考手册 title: 参考手册 ---