From 460036a0d49194c04472ecd076dcc655856b7809 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 6 Apr 2022 17:50:03 +0800 Subject: [PATCH 01/19] feature/qnode --- source/libs/qworker/src/qworker.c | 14 ++--- source/libs/scalar/src/filter.c | 44 +++++++++++++--- .../libs/scalar/test/filter/filterTests.cpp | 52 +++++++++++++++++++ source/libs/scheduler/src/scheduler.c | 38 ++++++++++---- 4 files changed, 123 insertions(+), 25 deletions(-) diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index a83fcc26f2..f0f04a8a9b 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -977,10 +977,10 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType, int8_t ex QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } - QW_ERR_JRET(qwBuildAndSendQueryRsp(&qwMsg->connInfo, code)); - QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); + //QW_ERR_JRET(qwBuildAndSendQueryRsp(&qwMsg->connInfo, code)); + //QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); - queryRsped = true; + //queryRsped = true; atomic_store_ptr(&ctx->taskHandle, pTaskInfo); atomic_store_ptr(&ctx->sinkHandle, sinkHandle); @@ -994,10 +994,10 @@ _return: input.code = code; code = qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_QUERY, &input, NULL); - if (!queryRsped) { - qwBuildAndSendQueryRsp(&qwMsg->connInfo, code); - QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); - } + //if (!queryRsped) { + // qwBuildAndSendQueryRsp(&qwMsg->connInfo, code); + // QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); + //} QW_RET(TSDB_CODE_SUCCESS); } diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 393f143e5f..16236fc05b 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -687,11 +687,15 @@ int32_t filterGetRangeRes(void* h, SFilterRange *ra) { SFilterRangeNode* r = ctx->rs; while (r) { - FILTER_COPY_RA(ra, &r->ra); + if (num) { + ra->e = r->ra.e; + ra->eflag = r->ra.eflag; + } else { + FILTER_COPY_RA(ra, &r->ra); + } ++num; r = r->next; - ++ra; } if (num == 0) { @@ -3314,8 +3318,7 @@ bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t -int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) { - SFilterInfo *info = NULL; +int32_t filterGetTimeRangeImpl(SFilterInfo *info, STimeWindow *win, bool *isStrict) { SFilterRange ra = {0}; SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP); SFilterRangeCtx *tmpc = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FLT_OPTION_TIMESTAMP); @@ -3369,13 +3372,14 @@ int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) { *win = TSWINDOW_INITIALIZER; } else { filterGetRangeNum(prev, &num); - if (num > 1) { - qError("only one time range accepted, num:%d", num); - FLT_ERR_JRET(TSDB_CODE_QRY_INVALID_TIME_CONDITION); - } FLT_CHK_JMP(num < 1); + if (num > 1) { + *isStrict = false; + qDebug("more than one time range, num:%d", num); + } + SFilterRange tra; filterGetRangeRes(prev, &tra); win->skey = tra.s; @@ -3401,6 +3405,30 @@ _return: } +int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict) { + SFilterInfo *info = NULL; + int32_t code = 0; + + *isStrict = true; + + FLT_ERR_RET(filterInitFromNode(pNode, &info, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP)); + + if (info->scalarMode) { + *win = TSWINDOW_INITIALIZER; + *isStrict = false; + goto _return; + } + + FLT_ERR_JRET(filterGetTimeRangeImpl(info, win, isStrict)); + +_return: + + filterFreeInfo(info); + + FLT_RET(code); +} + + int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar) { if (FILTER_EMPTY_RES(info) || FILTER_ALL_RES(info)) { return TSDB_CODE_SUCCESS; diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp index 1e6978d889..26ef5dbd44 100644 --- a/source/libs/scalar/test/filter/filterTests.cpp +++ b/source/libs/scalar/test/filter/filterTests.cpp @@ -241,6 +241,7 @@ TEST(timerangeTest, greater) { bool isStrict = false; int32_t code = filterGetTimeRange(opNode1, &win, &isStrict); ASSERT_EQ(code, 0); + ASSERT_EQ(isStrict, true); ASSERT_EQ(win.skey, tsmall); ASSERT_EQ(win.ekey, INT64_MAX); //filterFreeInfo(filter); @@ -270,6 +271,7 @@ TEST(timerangeTest, greater_and_lower) { STimeWindow win = {0}; bool isStrict = false; int32_t code = filterGetTimeRange(logicNode, &win, &isStrict); + ASSERT_EQ(isStrict, true); ASSERT_EQ(code, 0); ASSERT_EQ(win.skey, tsmall); ASSERT_EQ(win.ekey, tbig); @@ -277,6 +279,56 @@ TEST(timerangeTest, greater_and_lower) { nodesDestroyNode(logicNode); } +TEST(timerangeTest, greater_and_lower_not_strict) { + SNode *pcol = NULL, *pval = NULL, *opNode1 = NULL, *opNode2 = NULL, *logicNode1 = NULL, *logicNode2 = NULL; + bool eRes[5] = {false, false, true, true, true}; + SScalarParam res = {0}; + int64_t tsmall1 = 222, tbig1 = 333; + int64_t tsmall2 = 444, tbig2 = 555; + SNode *list[2] = {0}; + + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall1); + flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig1); + flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); + list[0] = opNode1; + list[1] = opNode2; + + flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_AND, list, 2); + + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tsmall2); + flttMakeOpNode(&opNode1, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); + flttMakeColumnNode(&pcol, NULL, TSDB_DATA_TYPE_TIMESTAMP, sizeof(int64_t), 0, NULL); + flttMakeValueNode(&pval, TSDB_DATA_TYPE_TIMESTAMP, &tbig2); + flttMakeOpNode(&opNode2, OP_TYPE_LOWER_THAN, TSDB_DATA_TYPE_BOOL, pcol, pval); + list[0] = opNode1; + list[1] = opNode2; + + flttMakeLogicNode(&logicNode2, LOGIC_COND_TYPE_AND, list, 2); + + list[0] = logicNode1; + list[1] = logicNode2; + flttMakeLogicNode(&logicNode1, LOGIC_COND_TYPE_OR, list, 2); + + //SFilterInfo *filter = NULL; + //int32_t code = filterInitFromNode(logicNode, &filter, FLT_OPTION_NO_REWRITE|FLT_OPTION_TIMESTAMP); + //ASSERT_EQ(code, 0); + STimeWindow win = {0}; + bool isStrict = false; + int32_t code = filterGetTimeRange(logicNode1, &win, &isStrict); + ASSERT_EQ(isStrict, false); + ASSERT_EQ(code, 0); + ASSERT_EQ(win.skey, tsmall1); + ASSERT_EQ(win.ekey, tbig2); + //filterFreeInfo(filter); + nodesDestroyNode(logicNode1); +} + + + TEST(columnTest, smallint_column_greater_double_value) { SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL; int16_t leftv[5]= {1, 2, 3, 4, 5}; diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 1675f91330..a2c767ac6c 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -1235,6 +1235,22 @@ _return: SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); } +int32_t schGetTaskFromTaskList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask) { + int32_t s = taosHashGetSize(pTaskList); + if (s <= 0) { + return TSDB_CODE_SUCCESS; + } + + SSchTask **task = taosHashGet(pTaskList, &taskId, sizeof(taskId)); + if (NULL == task || NULL == (*task)) { + return TSDB_CODE_SUCCESS; + } + + *pTask = *task; + + return TSDB_CODE_SUCCESS; +} + int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, int32_t rspCode) { int32_t code = 0; SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; @@ -1247,19 +1263,21 @@ int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, in SCH_ERR_JRET(TSDB_CODE_QRY_JOB_FREED); } - int32_t s = taosHashGetSize(pJob->execTasks); - if (s <= 0) { - SCH_JOB_ELOG("empty execTask list, refId:%" PRIx64 ", taskId:%" PRIx64, pParam->refId, pParam->taskId); + schGetTaskFromTaskList(pJob->execTasks, pParam->taskId, &pTask); + if (NULL == pTask) { + if (TDMT_VND_EXPLAIN_RSP == msgType) { + schGetTaskFromTaskList(pJob->succTasks, pParam->taskId, &pTask); + } else { + SCH_JOB_ELOG("task not found in execTask list, refId:%" PRIx64 ", taskId:%" PRIx64, pParam->refId, pParam->taskId); + SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); + } + } + + if (NULL == pTask) { + SCH_JOB_ELOG("task not found in execList & succList, refId:%" PRIx64 ", taskId:%" PRIx64, pParam->refId, pParam->taskId); SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); } - SSchTask **task = taosHashGet(pJob->execTasks, &pParam->taskId, sizeof(pParam->taskId)); - if (NULL == task || NULL == (*task)) { - SCH_JOB_ELOG("task not found in execTask list, refId:%" PRIx64 ", taskId:%" PRIx64, pParam->refId, pParam->taskId); - SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); - } - - pTask = *task; SCH_TASK_DLOG("rsp msg received, type:%s, handle:%p, code:%s", TMSG_INFO(msgType), pMsg->handle, tstrerror(rspCode)); SCH_SET_TASK_HANDLE(pTask, pMsg->handle); From c6722c0f6ffd4e2e13beaaca736f50b154340ea2 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 6 Apr 2022 18:15:55 +0800 Subject: [PATCH 02/19] handle except --- source/libs/transport/src/transCli.c | 45 ++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d9c288a39b..d633284e13 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -130,9 +130,9 @@ static SCliThrdObj* createThrdObj(); static void destroyThrdObj(SCliThrdObj* pThrd); #define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1) -#define CONN_PERSIST_TIME(para) (para * 1000 * 10) -#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL) -#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrdObj*)(conn)->hostThrd)->pTransInst))->label) +#define CONN_PERSIST_TIME(para) (para * 1000 * 10) +#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL) +#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrdObj*)(conn)->hostThrd)->pTransInst))->label) #define CONN_SHOULD_RELEASE(conn, head) \ do { \ if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \ @@ -154,20 +154,20 @@ static void destroyThrdObj(SCliThrdObj* pThrd); } \ } while (0) -#define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ - do { \ - int i = 0, sz = transQueueSize(&conn->cliMsgs); \ - for (; i < sz; i++) { \ - pMsg = transQueueGet(&conn->cliMsgs, i); \ +#define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ + do { \ + int i = 0, sz = transQueueSize(&conn->cliMsgs); \ + for (; i < sz; i++) { \ + pMsg = transQueueGet(&conn->cliMsgs, i); \ if (pMsg != NULL && pMsg->ctx != NULL && (uint64_t)pMsg->ctx->ahandle == ahandle) { \ - break; \ - } \ - } \ - if (i == sz) { \ - pMsg = NULL; \ - } else { \ - pMsg = transQueueRm(&conn->cliMsgs, i); \ - } \ + break; \ + } \ + } \ + if (i == sz) { \ + pMsg = NULL; \ + } else { \ + pMsg = transQueueRm(&conn->cliMsgs, i); \ + } \ } while (0) #define CONN_GET_NEXT_SENDMSG(conn) \ do { \ @@ -209,8 +209,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd); (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) #define CONN_RELEASE_BY_SERVER(conn) \ (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) -#define REQUEST_NO_RESP(msg) ((msg)->noResp == 1) -#define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1) +#define REQUEST_NO_RESP(msg) ((msg)->noResp == 1) +#define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1) #define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release) static void* cliWorkThread(void* arg); @@ -722,10 +722,11 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) { conn->hThrdIdx = pCtx->hThrdIdx; transCtxMerge(&conn->ctx, &pCtx->appCtx); - if (!transQueuePush(&conn->cliMsgs, pMsg)) { - return; - } - transDestroyBuffer(&conn->readBuf); + transQueuePush(&conn->cliMsgs, pMsg); + // tTrace("%s cli conn %p queue msg size %d", ((STrans*)pThrd->pTransInst)->label, conn, 2); + // return; + //} + // transDestroyBuffer(&conn->readBuf); cliSend(conn); } else { conn = cliCreateConn(pThrd); From 27240a7dcf96c2541afeeec9c0c3b371948aa26f Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 6 Apr 2022 18:22:41 +0800 Subject: [PATCH 03/19] feature/qnode --- source/libs/scheduler/src/scheduler.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index a2c767ac6c..86fbd51253 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -1251,6 +1251,18 @@ int32_t schGetTaskFromTaskList(SHashObj *pTaskList, uint64_t taskId, SSchTask ** return TSDB_CODE_SUCCESS; } +int32_t schUpdateTaskExecNodeHandle(SSchTask *pTask, void *handle) { + if (NULL == pTask->execNodes || taosArrayGetSize(pTask->execNodes) > 1) { + return TSDB_CODE_SUCCESS; + } + + SSchNodeInfo *nodeInfo = taosArrayGet(pTask->execNodes, 0); + nodeInfo->handle = handle; + + return TSDB_CODE_SUCCESS; +} + + int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, int32_t rspCode) { int32_t code = 0; SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; @@ -1281,6 +1293,7 @@ int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, in SCH_TASK_DLOG("rsp msg received, type:%s, handle:%p, code:%s", TMSG_INFO(msgType), pMsg->handle, tstrerror(rspCode)); SCH_SET_TASK_HANDLE(pTask, pMsg->handle); + schUpdateTaskExecNodeHandle(pTask, pMsg->handle); SCH_ERR_JRET(schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode)); _return: From cc2726debec0edb5b2c98d2d89d283328b3cbb19 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 7 Apr 2022 09:35:00 +0000 Subject: [PATCH 04/19] start vnode refact --- source/dnode/CMakeLists.txt | 3 +- source/dnode/vnode2/CMakeLists.txt | 20 ++++++++ source/dnode/vnode2/inc/vnode.h | 35 ++++++++++++++ source/dnode/vnode2/src/inc/vnodeInt.h | 58 +++++++++++++++++++++++ source/dnode/vnode2/src/inc/vnodeMeta.h | 27 +++++++++++ source/dnode/vnode2/src/inc/vnodeTq.h | 27 +++++++++++ source/dnode/vnode2/src/inc/vnodeTsdb.h | 27 +++++++++++ source/dnode/vnode2/src/vnode/vnodeMain.c | 25 ++++++++++ 8 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 source/dnode/vnode2/CMakeLists.txt create mode 100644 source/dnode/vnode2/inc/vnode.h create mode 100644 source/dnode/vnode2/src/inc/vnodeInt.h create mode 100644 source/dnode/vnode2/src/inc/vnodeMeta.h create mode 100644 source/dnode/vnode2/src/inc/vnodeTq.h create mode 100644 source/dnode/vnode2/src/inc/vnodeTsdb.h create mode 100644 source/dnode/vnode2/src/vnode/vnodeMain.c diff --git a/source/dnode/CMakeLists.txt b/source/dnode/CMakeLists.txt index 87e4c5fc46..3670f259af 100644 --- a/source/dnode/CMakeLists.txt +++ b/source/dnode/CMakeLists.txt @@ -3,4 +3,5 @@ add_subdirectory(vnode) add_subdirectory(qnode) add_subdirectory(snode) add_subdirectory(bnode) -add_subdirectory(mgmt) \ No newline at end of file +add_subdirectory(mgmt) +add_subdirectory(vnode2) \ No newline at end of file diff --git a/source/dnode/vnode2/CMakeLists.txt b/source/dnode/vnode2/CMakeLists.txt new file mode 100644 index 0000000000..1fd3c4e158 --- /dev/null +++ b/source/dnode/vnode2/CMakeLists.txt @@ -0,0 +1,20 @@ +# vnode +add_library(vnode2 "") +target_sources( + vnode2 + PRIVATE + # vnode + "src/vnode/vnodeMain.c" +) + +target_include_directories( + vnode2 + PUBLIC "inc" + PRIVATE "src/inc" +) + +target_link_libraries( + vnode2 + os +) + diff --git a/source/dnode/vnode2/inc/vnode.h b/source/dnode/vnode2/inc/vnode.h new file mode 100644 index 0000000000..a30979a202 --- /dev/null +++ b/source/dnode/vnode2/inc/vnode.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VNODE_H_ +#define _TD_VNODE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct SVnode SVnode; + +typedef struct { +} SVnodeCfg; + +int vnodeOpen(const char *path, const SVnodeCfg *pCfg, SVnode **ppVnode); +int vnodeClose(SVnode *pVnode); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/inc/vnodeInt.h b/source/dnode/vnode2/src/inc/vnodeInt.h new file mode 100644 index 0000000000..ae2b65b3c9 --- /dev/null +++ b/source/dnode/vnode2/src/inc/vnodeInt.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VNODE_INT_H_ +#define _TD_VNODE_INT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "os.h" + +#include "vnode.h" + +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +typedef struct SMeta SMeta; +typedef struct STsdb STsdb; +typedef struct STQ STQ; + +struct SVnode { + i32 vid; + char *path; + SMeta *pMeta; + STsdb *pTsdb; + STQ *pTq; +}; + +#include "vnodeMeta.h" + +#include "vnodeTsdb.h" + +#include "vnodeTq.h" + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/inc/vnodeMeta.h b/source/dnode/vnode2/src/inc/vnodeMeta.h new file mode 100644 index 0000000000..18952e9a43 --- /dev/null +++ b/source/dnode/vnode2/src/inc/vnodeMeta.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VNODE_META_H_ +#define _TD_VNODE_META_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_META_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/inc/vnodeTq.h b/source/dnode/vnode2/src/inc/vnodeTq.h new file mode 100644 index 0000000000..573fc78df0 --- /dev/null +++ b/source/dnode/vnode2/src/inc/vnodeTq.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VNODE_TQ_H_ +#define _TD_VNODE_TQ_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_TQ_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/inc/vnodeTsdb.h b/source/dnode/vnode2/src/inc/vnodeTsdb.h new file mode 100644 index 0000000000..0ed2a6dc11 --- /dev/null +++ b/source/dnode/vnode2/src/inc/vnodeTsdb.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VNODE_TSDB_H_ +#define _TD_VNODE_TSDB_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_TSDB_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/vnode/vnodeMain.c b/source/dnode/vnode2/src/vnode/vnodeMain.c new file mode 100644 index 0000000000..c3da3fd6e4 --- /dev/null +++ b/source/dnode/vnode2/src/vnode/vnodeMain.c @@ -0,0 +1,25 @@ +/* + * 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 "vnodeInt.h" + +int vnodeOpen(const char *path, const SVnodeCfg *pCfg, SVnode **ppVnode) { + return 0; + } + +int vnodeClose(SVnode *pVnode) { + // TODO + return 0; +} \ No newline at end of file From f266d593ef26c255d4f492de2800ced051fbaa37 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 7 Apr 2022 20:34:12 +0800 Subject: [PATCH 05/19] restore current add .smad/.smal --- source/dnode/vnode/src/tsdb/tsdbFS.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index aa235f88de..51d6efe077 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -1111,7 +1111,7 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) { char bname[TSDB_FILENAME_LEN]; STfsDir * tdir = NULL; const STfsFile *pf = NULL; - const char * pattern = "^v[0-9]+f[0-9]+\\.(head|data|last)(-ver[0-9]+)?$"; + const char * pattern = "^v[0-9]+f[0-9]+\\.(head|data|last|smad|smal)(-ver[0-9]+)?$"; SArray * fArray = NULL; regex_t regex; STsdbFS * pfs = REPO_FS(pRepo); From 451a65f53f4d3f6a5d5684bd9f21a73d28a44d22 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 7 Apr 2022 20:49:18 +0800 Subject: [PATCH 06/19] add dstVgId --- source/dnode/mnode/impl/src/mndSma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 94114a96bf..b402a27a41 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -416,8 +416,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre streamObj.version = 1; streamObj.sql = pCreate->sql; streamObj.createdBy = STREAM_CREATED_BY__SMA; - // TODO - streamObj.fixedSinkVgId = 0; + streamObj.fixedSinkVgId = smaObj.dstVgId; streamObj.smaId = smaObj.uid; /*streamObj.physicalPlan = "";*/ streamObj.logicalPlan = "not implemented"; From 29138ae0c7229aeac1c0ae7c6ad386a97a8f9af0 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 8 Apr 2022 06:48:01 +0800 Subject: [PATCH 07/19] trigger CI From b0184c201f581ecd181c4926bdcf8bd9557bb785 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 8 Apr 2022 10:27:27 +0800 Subject: [PATCH 08/19] feature/qnode --- source/libs/command/src/explain.c | 1 - source/libs/executor/src/dataDispatcher.c | 2 ++ source/libs/executor/src/executorimpl.c | 3 +-- source/libs/executor/src/scanoperator.c | 5 +++++ source/libs/nodes/src/nodesToSQLFuncs.c | 2 +- source/libs/parser/src/parCalcConst.c | 4 ++++ source/libs/scheduler/src/scheduler.c | 2 +- 7 files changed, 14 insertions(+), 5 deletions(-) diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 2a36113749..605d8f41da 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -618,7 +618,6 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pSortNode->pSortKeys->length); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pSortNode->node.pOutputDataBlockDesc->totalRowSize); - EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 34894c235b..74ec4e55a6 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -209,6 +209,8 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) { assert(pDispatcher->queryEnd); pOutput->useconds = pDispatcher->useconds; pOutput->precision = pDispatcher->pSchema->precision; + pOutput->bufStatus = DS_BUF_EMPTY; + pOutput->queryEnd = pDispatcher->queryEnd; return TSDB_CODE_SUCCESS; } SDataCacheEntry* pEntry = (SDataCacheEntry*)(pDispatcher->nextOutput.pData); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 953c87bf7e..9c5f901353 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -7289,8 +7289,7 @@ SArray* createSortInfo(SNodeList* pNodeList) { } for (int32_t i = 0; i < numOfCols; ++i) { - STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i); - SOrderByExprNode* pSortKey = (SOrderByExprNode*)pNode->pExpr; + SOrderByExprNode* pSortKey = (SOrderByExprNode*)nodesListGetNode(pNodeList, i); SBlockOrderInfo bi = {0}; bi.order = (pSortKey->order == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; bi.nullFirst = (pSortKey->nullOrder == NULL_ORDER_FIRST); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index f39a18da68..53fe723671 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -255,6 +255,11 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, pOperator->getNextFn = doTableScan; pOperator->pTaskInfo = pTaskInfo; + static int32_t cost = 0; + pOperator->cost.openCost = ++cost; + pOperator->cost.totalCost = ++cost; + pOperator->resultInfo.totalRows = ++cost; + return pOperator; } diff --git a/source/libs/nodes/src/nodesToSQLFuncs.c b/source/libs/nodes/src/nodesToSQLFuncs.c index 68f38bb6a7..b8e071ec0d 100644 --- a/source/libs/nodes/src/nodesToSQLFuncs.c +++ b/source/libs/nodes/src/nodesToSQLFuncs.c @@ -21,7 +21,7 @@ #include "taoserror.h" #include "thash.h" -char *gOperatorStr[] = {NULL, "+", "-", "*", "/", "%", "&", "|", ">", ">=", "<", "<=", "=", "<>", +char *gOperatorStr[] = {NULL, "+", "-", "*", "/", "%", "-", "&", "|", ">", ">=", "<", "<=", "=", "<>", "IN", "NOT IN", "LIKE", "NOT LIKE", "MATCH", "NMATCH", "IS NULL", "IS NOT NULL", "IS TRUE", "IS FALSE", "IS UNKNOWN", "IS NOT TRUE", "IS NOT FALSE", "IS NOT UNKNOWN"}; char *gLogicConditionStr[] = {"AND", "OR", "NOT"}; diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index d21628956a..0b4f79d3ff 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -104,6 +104,8 @@ static int32_t rewriteIsTrue(SNode* pSrc, SNode** pIsTrue) { } pOp->opType = OP_TYPE_IS_TRUE; pOp->pLeft = pSrc; + pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; *pIsTrue = (SNode*)pOp; return TSDB_CODE_SUCCESS; } @@ -198,6 +200,8 @@ static int32_t calcConstQuery(SNode* pStmt) { switch (nodeType(pStmt)) { case QUERY_NODE_SELECT_STMT: return calcConstSelect((SSelectStmt*)pStmt); + case QUERY_NODE_EXPLAIN_STMT: + return calcConstQuery(((SExplainStmt*)pStmt)->pQuery); default: break; } diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 86fbd51253..d1352bac24 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -1252,7 +1252,7 @@ int32_t schGetTaskFromTaskList(SHashObj *pTaskList, uint64_t taskId, SSchTask ** } int32_t schUpdateTaskExecNodeHandle(SSchTask *pTask, void *handle) { - if (NULL == pTask->execNodes || taosArrayGetSize(pTask->execNodes) > 1) { + if (NULL == pTask->execNodes || taosArrayGetSize(pTask->execNodes) > 1 || taosArrayGetSize(pTask->execNodes) <= 0) { return TSDB_CODE_SUCCESS; } From 57c574e38aa4c380b53824a2be096653ca54adf5 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 8 Apr 2022 10:40:55 +0800 Subject: [PATCH 09/19] [TD-14575]: fix rtrim result not correct for nchar columns --- source/libs/scalar/src/sclfunc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 1a6abb7100..df9e1bf36d 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -267,7 +267,7 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) { numOfSpaces++; } } else { //NCHAR - for (int32_t i = charLen - 1; i < charLen; ++i) { + for (int32_t i = charLen - 1; i >= 0; --i) { if (!iswspace(*((uint32_t *)varDataVal(input) + i))) { break; } From afea903a9826c6ffd04a544b594e669b82bd7fe0 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 03:30:11 +0000 Subject: [PATCH 10/19] refact vnode --- source/dnode/vnode2/CMakeLists.txt | 20 -------- source/dnode/vnode2/inc/vnode.h | 35 -------------- source/dnode/vnode2/src/inc/vnodeInt.h | 58 ----------------------- source/dnode/vnode2/src/inc/vnodeMeta.h | 27 ----------- source/dnode/vnode2/src/inc/vnodeTq.h | 27 ----------- source/dnode/vnode2/src/inc/vnodeTsdb.h | 27 ----------- source/dnode/vnode2/src/vnode/vnodeMain.c | 25 ---------- 7 files changed, 219 deletions(-) delete mode 100644 source/dnode/vnode2/CMakeLists.txt delete mode 100644 source/dnode/vnode2/inc/vnode.h delete mode 100644 source/dnode/vnode2/src/inc/vnodeInt.h delete mode 100644 source/dnode/vnode2/src/inc/vnodeMeta.h delete mode 100644 source/dnode/vnode2/src/inc/vnodeTq.h delete mode 100644 source/dnode/vnode2/src/inc/vnodeTsdb.h delete mode 100644 source/dnode/vnode2/src/vnode/vnodeMain.c diff --git a/source/dnode/vnode2/CMakeLists.txt b/source/dnode/vnode2/CMakeLists.txt deleted file mode 100644 index 1fd3c4e158..0000000000 --- a/source/dnode/vnode2/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# vnode -add_library(vnode2 "") -target_sources( - vnode2 - PRIVATE - # vnode - "src/vnode/vnodeMain.c" -) - -target_include_directories( - vnode2 - PUBLIC "inc" - PRIVATE "src/inc" -) - -target_link_libraries( - vnode2 - os -) - diff --git a/source/dnode/vnode2/inc/vnode.h b/source/dnode/vnode2/inc/vnode.h deleted file mode 100644 index a30979a202..0000000000 --- a/source/dnode/vnode2/inc/vnode.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_H_ -#define _TD_VNODE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct SVnode SVnode; - -typedef struct { -} SVnodeCfg; - -int vnodeOpen(const char *path, const SVnodeCfg *pCfg, SVnode **ppVnode); -int vnodeClose(SVnode *pVnode); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/inc/vnodeInt.h b/source/dnode/vnode2/src/inc/vnodeInt.h deleted file mode 100644 index ae2b65b3c9..0000000000 --- a/source/dnode/vnode2/src/inc/vnodeInt.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_INT_H_ -#define _TD_VNODE_INT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "os.h" - -#include "vnode.h" - -typedef int8_t i8; -typedef int16_t i16; -typedef int32_t i32; -typedef int64_t i64; -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; - -typedef struct SMeta SMeta; -typedef struct STsdb STsdb; -typedef struct STQ STQ; - -struct SVnode { - i32 vid; - char *path; - SMeta *pMeta; - STsdb *pTsdb; - STQ *pTq; -}; - -#include "vnodeMeta.h" - -#include "vnodeTsdb.h" - -#include "vnodeTq.h" - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/inc/vnodeMeta.h b/source/dnode/vnode2/src/inc/vnodeMeta.h deleted file mode 100644 index 18952e9a43..0000000000 --- a/source/dnode/vnode2/src/inc/vnodeMeta.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_META_H_ -#define _TD_VNODE_META_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_META_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/inc/vnodeTq.h b/source/dnode/vnode2/src/inc/vnodeTq.h deleted file mode 100644 index 573fc78df0..0000000000 --- a/source/dnode/vnode2/src/inc/vnodeTq.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_TQ_H_ -#define _TD_VNODE_TQ_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_TQ_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/inc/vnodeTsdb.h b/source/dnode/vnode2/src/inc/vnodeTsdb.h deleted file mode 100644 index 0ed2a6dc11..0000000000 --- a/source/dnode/vnode2/src/inc/vnodeTsdb.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_TSDB_H_ -#define _TD_VNODE_TSDB_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_TSDB_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode2/src/vnode/vnodeMain.c b/source/dnode/vnode2/src/vnode/vnodeMain.c deleted file mode 100644 index c3da3fd6e4..0000000000 --- a/source/dnode/vnode2/src/vnode/vnodeMain.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "vnodeInt.h" - -int vnodeOpen(const char *path, const SVnodeCfg *pCfg, SVnode **ppVnode) { - return 0; - } - -int vnodeClose(SVnode *pVnode) { - // TODO - return 0; -} \ No newline at end of file From e41abf99163ceb4f824147dfbd3dafbee446fb3a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 03:56:30 +0000 Subject: [PATCH 11/19] refact vnode code --- source/dnode/CMakeLists.txt | 3 +- source/dnode/vnode/CMakeLists.txt | 90 +++++++++++++++++++------------ 2 files changed, 57 insertions(+), 36 deletions(-) diff --git a/source/dnode/CMakeLists.txt b/source/dnode/CMakeLists.txt index 3670f259af..87e4c5fc46 100644 --- a/source/dnode/CMakeLists.txt +++ b/source/dnode/CMakeLists.txt @@ -3,5 +3,4 @@ add_subdirectory(vnode) add_subdirectory(qnode) add_subdirectory(snode) add_subdirectory(bnode) -add_subdirectory(mgmt) -add_subdirectory(vnode2) \ No newline at end of file +add_subdirectory(mgmt) \ No newline at end of file diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 6b21f935c4..152a9e2945 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -1,54 +1,76 @@ -set(META_DB_IMPL_LIST "BDB" "TDB") -set(META_DB_IMPL "TDB" CACHE STRING "Use BDB as the default META implementation") -set_property(CACHE META_DB_IMPL PROPERTY STRINGS ${META_DB_IMPL_LIST}) +# vnode +add_library(vnode STATIC "") +target_sources( + vnode + PRIVATE + # vnode + "src/vnd/vnodeArenaMAImpl.c" + "src/vnd/vnodeBufferPool.c" + "src/vnd/vnodeCfg.c" + "src/vnd/vnodeCommit.c" + "src/vnd/vnodeInt.c" + "src/vnd/vnodeMain.c" + "src/vnd/vnodeMgr.c" + "src/vnd/vnodeQuery.c" + "src/vnd/vnodeStateMgr.c" + "src/vnd/vnodeWrite.c" -if(META_DB_IMPL IN_LIST META_DB_IMPL_LIST) - message(STATUS "META DB Impl: ${META_DB_IMPL}==============") -else() - message(FATAL_ERROR "Invalid META DB IMPL: ${META_DB_IMPL}==============") -endif() + # meta + # "src/meta/metaBDBImpl.c" + "src/meta/metaCache.c" + "src/meta/metaCfg.c" + "src/meta/metaIdx.c" + "src/meta/metaMain.c" + "src/meta/metaQuery.c" + "src/meta/metaTable.c" + "src/meta/metaTbCfg.c" + "src/meta/metaTbTag.c" + "src/meta/metaTbUid.c" + "src/meta/metaTDBImpl.c" -aux_source_directory(src/meta META_SRC) -if(${META_DB_IMPL} STREQUAL "BDB") - list(REMOVE_ITEM META_SRC "src/meta/metaTDBImpl.c") -elseif(${META_DB_IMPL} STREQUAL "TDB") - list(REMOVE_ITEM META_SRC "src/meta/metaBDBImpl.c") -endif() + # tsdb + "src/tsdb/tsdbBDBImpl.c" + "src/tsdb/tsdbCommit.c" + "src/tsdb/tsdbCompact.c" + "src/tsdb/tsdbFile.c" + "src/tsdb/tsdbFS.c" + "src/tsdb/tsdbMain.c" + "src/tsdb/tsdbMemTable.c" + "src/tsdb/tsdbOptions.c" + "src/tsdb/tsdbRead.c" + "src/tsdb/tsdbReadImpl.c" + "src/tsdb/tsdbScan.c" + "src/tsdb/tsdbSma.c" + "src/tsdb/tsdbWrite.c" -aux_source_directory(src/tq TQ_SRC) -aux_source_directory(src/tsdb TSDB_SRC) -aux_source_directory(src/vnd VND_SRC) - -list(APPEND - VNODE_SRC - ${META_SRC} - ${TQ_SRC} - ${TSDB_SRC} - ${VND_SRC} + # tq + "src/tq/tq.c" + "src/tq/tqCommit.c" + "src/tq/tqMetaStore.c" + "src/tq/tqOffset.c" + "src/tq/tqPush.c" + "src/tq/tqRead.c" ) - -add_library(vnode STATIC ${VNODE_SRC}) target_include_directories( vnode - PUBLIC inc - PRIVATE src/inc + PUBLIC "inc" + PRIVATE "src/inc" ) target_link_libraries( vnode PUBLIC os PUBLIC util PUBLIC common - PUBLIC transport PUBLIC tfs PUBLIC wal - PUBLIC scheduler - PUBLIC executor - PUBLIC stream PUBLIC qworker PUBLIC sync - # TODO: get rid of BDB - PUBLIC bdb + PUBLIC executor + PUBLIC scheduler PUBLIC tdb + PUBLIC bdb + PUBLIC transport + PUBLIC stream ) if(${BUILD_TEST}) From e87e7c3335592bf27a71ae60bebcf8359962cc1d Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Fri, 8 Apr 2022 13:59:32 +0800 Subject: [PATCH 12/19] TD-14457 TD-14537 TD-14571 bugfix --- include/libs/nodes/querynodes.h | 2 ++ include/util/taoserror.h | 21 +++++++------- source/libs/nodes/src/nodesCodeFuncs.c | 2 +- source/libs/parser/src/parTranslater.c | 40 ++++++++++++++++++++------ source/libs/parser/src/parUtil.c | 2 ++ 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index f987afd878..6b6d11c2fe 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -124,6 +124,7 @@ typedef struct STableNode { char dbName[TSDB_DB_NAME_LEN]; char tableName[TSDB_TABLE_NAME_LEN]; char tableAlias[TSDB_TABLE_NAME_LEN]; + uint8_t precision; } STableNode; struct STableMeta; @@ -236,6 +237,7 @@ typedef struct SSelectStmt { SNode* pLimit; SNode* pSlimit; char stmtName[TSDB_TABLE_NAME_LEN]; + uint8_t precision; } SSelectStmt; typedef enum ESetOperatorType { diff --git a/include/util/taoserror.h b/include/util/taoserror.h index ed90628bda..37e05bf3d3 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -483,16 +483,17 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME TAOS_DEF_ERROR_CODE(0, 0x2617) #define TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR TAOS_DEF_ERROR_CODE(0, 0x2618) #define TSDB_CODE_PAR_INVALID_RANGE_OPTION TAOS_DEF_ERROR_CODE(0, 0x2619) -#define TSDB_CODE_PAR_INVALID_STR_OPTION TAOS_DEF_ERROR_CODE(0, 0x2620) -#define TSDB_CODE_PAR_INVALID_ENUM_OPTION TAOS_DEF_ERROR_CODE(0, 0x2621) -#define TSDB_CODE_PAR_INVALID_TTL_OPTION TAOS_DEF_ERROR_CODE(0, 0x2622) -#define TSDB_CODE_PAR_INVALID_KEEP_NUM TAOS_DEF_ERROR_CODE(0, 0x2623) -#define TSDB_CODE_PAR_INVALID_KEEP_ORDER TAOS_DEF_ERROR_CODE(0, 0x2624) -#define TSDB_CODE_PAR_INVALID_KEEP_VALUE TAOS_DEF_ERROR_CODE(0, 0x2625) -#define TSDB_CODE_PAR_INVALID_COMMENT_OPTION TAOS_DEF_ERROR_CODE(0, 0x2626) -#define TSDB_CODE_PAR_INVALID_F_RANGE_OPTION TAOS_DEF_ERROR_CODE(0, 0x2627) -#define TSDB_CODE_PAR_INVALID_ROLLUP_OPTION TAOS_DEF_ERROR_CODE(0, 0x2628) -#define TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION TAOS_DEF_ERROR_CODE(0, 0x2629) +#define TSDB_CODE_PAR_INVALID_STR_OPTION TAOS_DEF_ERROR_CODE(0, 0x261A) +#define TSDB_CODE_PAR_INVALID_ENUM_OPTION TAOS_DEF_ERROR_CODE(0, 0x261B) +#define TSDB_CODE_PAR_INVALID_TTL_OPTION TAOS_DEF_ERROR_CODE(0, 0x261C) +#define TSDB_CODE_PAR_INVALID_KEEP_NUM TAOS_DEF_ERROR_CODE(0, 0x261D) +#define TSDB_CODE_PAR_INVALID_KEEP_ORDER TAOS_DEF_ERROR_CODE(0, 0x261E) +#define TSDB_CODE_PAR_INVALID_KEEP_VALUE TAOS_DEF_ERROR_CODE(0, 0x261F) +#define TSDB_CODE_PAR_INVALID_COMMENT_OPTION TAOS_DEF_ERROR_CODE(0, 0x2620) +#define TSDB_CODE_PAR_INVALID_F_RANGE_OPTION TAOS_DEF_ERROR_CODE(0, 0x2621) +#define TSDB_CODE_PAR_INVALID_ROLLUP_OPTION TAOS_DEF_ERROR_CODE(0, 0x2622) +#define TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION TAOS_DEF_ERROR_CODE(0, 0x2623) +#define TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST TAOS_DEF_ERROR_CODE(0, 0x2624) //planner #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index c3bc696a53..8f90670d13 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -1578,7 +1578,7 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) { case TSDB_DATA_TYPE_NULL: break; case TSDB_DATA_TYPE_BOOL: - code = tjsonAddIntegerToObject(pJson, jkValueDatum, pNode->datum.b); + code = tjsonAddBoolToObject(pJson, jkValueDatum, pNode->datum.b); break; case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 3491974eab..88c3d5b549 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -376,8 +376,9 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) { } static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { + uint8_t precision = (NULL != pCxt->pCurrStmt ? pCxt->pCurrStmt->precision : pVal->node.resType.precision); if (pVal->isDuration) { - if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, pVal->node.resType.precision) != TSDB_CODE_SUCCESS) { + if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, precision) != TSDB_CODE_SUCCESS) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); } } else { @@ -421,7 +422,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { break; } case TSDB_DATA_TYPE_TIMESTAMP: { - if (taosParseTime(pVal->literal, &pVal->datum.i, pVal->node.resType.bytes, pVal->node.resType.precision, tsDaylight) != TSDB_CODE_SUCCESS) { + if (taosParseTime(pVal->literal, &pVal->datum.i, pVal->node.resType.bytes, precision, tsDaylight) != TSDB_CODE_SUCCESS) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); } break; @@ -683,6 +684,19 @@ static int32_t setTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTa return code; } +static uint8_t getStmtPrecision(SNode* pStmt) { + if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) { + return ((SSelectStmt*)pStmt)->precision; + } + return 0; +} + +static uint8_t getJoinTablePrecision(SJoinTableNode* pJoinTable) { + uint8_t lp = ((STableNode*)pJoinTable->pLeft)->precision; + uint8_t rp = ((STableNode*)pJoinTable->pRight)->precision; + return (lp > rp ? rp : lp); +} + static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pTable)) { @@ -695,6 +709,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { if (TSDB_CODE_SUCCESS != code) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, pRealTable->table.tableName); } + pRealTable->table.precision = pRealTable->pMeta->tableInfo.precision; code = setTableVgroupList(pCxt, &name, pRealTable); if (TSDB_CODE_SUCCESS == code) { code = addNamespace(pCxt, pRealTable); @@ -705,6 +720,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { STempTableNode* pTempTable = (STempTableNode*)pTable; code = translateSubquery(pCxt, pTempTable->pSubquery); if (TSDB_CODE_SUCCESS == code) { + pTempTable->table.precision = getStmtPrecision(pTempTable->pSubquery); code = addNamespace(pCxt, pTempTable); } break; @@ -716,6 +732,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { code = translateTable(pCxt, pJoinTable->pRight); } if (TSDB_CODE_SUCCESS == code) { + pJoinTable->table.precision = getJoinTablePrecision(pJoinTable); code = translateExpr(pCxt, pJoinTable->pOnCond); } break; @@ -852,9 +869,12 @@ static int32_t translateHaving(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } -static int32_t translateGroupBy(STranslateContext* pCxt, SNodeList* pGroupByList) { +static int32_t translateGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) { + if (NULL != pSelect->pGroupByList && NULL != pSelect->pWindow) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST); + } pCxt->currClause = SQL_CLAUSE_GROUP_BY; - return translateExprList(pCxt, pGroupByList); + return translateExprList(pCxt, pSelect->pGroupByList); } static int32_t translateIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* pInterval) { @@ -899,14 +919,18 @@ static int32_t translateWhere(STranslateContext* pCxt, SNode* pWhere) { return translateExpr(pCxt, pWhere); } -static int32_t translateFrom(STranslateContext* pCxt, SNode* pTable) { +static int32_t translateFrom(STranslateContext* pCxt, SSelectStmt* pSelect) { pCxt->currClause = SQL_CLAUSE_FROM; - return translateTable(pCxt, pTable); + int32_t code = translateTable(pCxt, pSelect->pFromTable); + if (TSDB_CODE_SUCCESS == code) { + pSelect->precision = ((STableNode*)pSelect->pFromTable)->precision; + } + return code; } static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { pCxt->pCurrStmt = pSelect; - int32_t code = translateFrom(pCxt, pSelect->pFromTable); + int32_t code = translateFrom(pCxt, pSelect); if (TSDB_CODE_SUCCESS == code) { code = translateWhere(pCxt, pSelect->pWhere); } @@ -917,7 +941,7 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { code = translateWindow(pCxt, pSelect->pWindow); } if (TSDB_CODE_SUCCESS == code) { - code = translateGroupBy(pCxt, pSelect->pGroupByList); + code = translateGroupBy(pCxt, pSelect); } if (TSDB_CODE_SUCCESS == code) { code = translateHaving(pCxt, pSelect); diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 5206e0f8a5..171324aa99 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -89,6 +89,8 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "invalid option rollup: only one function is allowed"; case TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION: return "invalid option retentions"; + case TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST: + return "GROUP BY and WINDOW-clause can't be used together"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: From 544f012066b41ffad6558338d9e177c21055f791 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 06:01:01 +0000 Subject: [PATCH 13/19] rename file --- source/dnode/vnode/src/inc/tqInt.h | 2 +- source/dnode/vnode/src/inc/{vnd.h => vnodeInt.h} | 0 source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c | 2 +- source/dnode/vnode/src/vnd/vnodeBufferPool.c | 2 +- source/dnode/vnode/src/vnd/vnodeCfg.c | 2 +- source/dnode/vnode/src/vnd/vnodeCommit.c | 2 +- source/dnode/vnode/src/vnd/vnodeInt.c | 2 +- source/dnode/vnode/src/vnd/vnodeMain.c | 2 +- source/dnode/vnode/src/vnd/vnodeMgr.c | 2 +- source/dnode/vnode/src/vnd/vnodeQuery.c | 2 +- source/dnode/vnode/src/vnd/vnodeWrite.c | 2 +- 11 files changed, 10 insertions(+), 10 deletions(-) rename source/dnode/vnode/src/inc/{vnd.h => vnodeInt.h} (100%) diff --git a/source/dnode/vnode/src/inc/tqInt.h b/source/dnode/vnode/src/inc/tqInt.h index 6c4825e0f2..c858ebd6e4 100644 --- a/source/dnode/vnode/src/inc/tqInt.h +++ b/source/dnode/vnode/src/inc/tqInt.h @@ -19,7 +19,7 @@ #include "meta.h" #include "tlog.h" #include "tqPush.h" -#include "vnd.h" +#include "vnodeInt.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnodeInt.h similarity index 100% rename from source/dnode/vnode/src/inc/vnd.h rename to source/dnode/vnode/src/inc/vnodeInt.h diff --git a/source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c b/source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c index ab0da1451d..7b7f6c9157 100644 --- a/source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c +++ b/source/dnode/vnode/src/vnd/vnodeArenaMAImpl.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "vnd.h" +#include "vnodeInt.h" static SVArenaNode *vArenaNodeNew(uint64_t capacity); static void vArenaNodeFree(SVArenaNode *pNode); diff --git a/source/dnode/vnode/src/vnd/vnodeBufferPool.c b/source/dnode/vnode/src/vnd/vnodeBufferPool.c index 5be88cdc2e..8764950f27 100644 --- a/source/dnode/vnode/src/vnd/vnodeBufferPool.c +++ b/source/dnode/vnode/src/vnd/vnodeBufferPool.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "vnd.h" +#include "vnodeInt.h" /* ------------------------ STRUCTURES ------------------------ */ #define VNODE_BUF_POOL_SHARDS 3 diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index 3b7206e64d..4a70738e86 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "vnd.h" +#include "vnodeInt.h" const SVnodeCfg defaultVnodeOptions = { .wsize = 96 * 1024 * 1024, .ssize = 1 * 1024 * 1024, .lsize = 1024, .walCfg = {.level = TAOS_WAL_WRITE}}; /* TODO */ diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 1717721bb2..1235637e19 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "vnd.h" +#include "vnodeInt.h" static int vnodeStartCommit(SVnode *pVnode); static int vnodeEndCommit(SVnode *pVnode); diff --git a/source/dnode/vnode/src/vnd/vnodeInt.c b/source/dnode/vnode/src/vnd/vnodeInt.c index 333da7a2e5..24294c4b58 100644 --- a/source/dnode/vnode/src/vnd/vnodeInt.c +++ b/source/dnode/vnode/src/vnd/vnodeInt.c @@ -15,7 +15,7 @@ #define _DEFAULT_SOURCE #include "sync.h" -#include "vnd.h" +#include "vnodeInt.h" // #include "vnodeInt.h" int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeMain.c b/source/dnode/vnode/src/vnd/vnodeMain.c index 91c6e4d263..2fd848a39d 100644 --- a/source/dnode/vnode/src/vnd/vnodeMain.c +++ b/source/dnode/vnode/src/vnd/vnodeMain.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "vnd.h" +#include "vnodeInt.h" static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg); static void vnodeFree(SVnode *pVnode); diff --git a/source/dnode/vnode/src/vnd/vnodeMgr.c b/source/dnode/vnode/src/vnd/vnodeMgr.c index 8f7d5713ab..40f43bcd12 100644 --- a/source/dnode/vnode/src/vnd/vnodeMgr.c +++ b/source/dnode/vnode/src/vnd/vnodeMgr.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "vnd.h" +#include "vnodeInt.h" #include "tglobal.h" SVnodeMgr vnodeMgr = {.vnodeInitFlag = TD_MOD_UNINITIALIZED}; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 30c2fe84bf..0590bd4321 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -15,7 +15,7 @@ #include "vnodeQuery.h" #include "executor.h" -#include "vnd.h" +#include "vnodeInt.h" static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg); static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg); diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index e841eb6761..fb0340046e 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "vnd.h" +#include "vnodeInt.h" void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { // TODO From 6faaafb7a2f4a19377a2dfe5a6e121e489e0980b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 06:09:15 +0000 Subject: [PATCH 14/19] remove tsdb.h and meta.h --- source/dnode/vnode/inc/meta.h | 86 ------ source/dnode/vnode/inc/tsdb.h | 288 ------------------- source/dnode/vnode/inc/vnode.h | 320 +++++++++++++++++++++- source/dnode/vnode/src/inc/metaDef.h | 3 +- source/dnode/vnode/src/inc/tqInt.h | 2 +- source/dnode/vnode/src/inc/tsdbCommit.h | 2 + source/dnode/vnode/src/inc/tsdbDef.h | 2 - source/dnode/vnode/src/inc/tsdbMemTable.h | 2 +- source/dnode/vnode/src/inc/tsdbReadImpl.h | 2 +- source/dnode/vnode/src/meta/metaCache.c | 2 +- source/dnode/vnode/src/meta/metaTbUid.c | 2 +- source/dnode/vnode/src/tsdb/tsdbRead.c | 2 +- source/libs/executor/src/executorMain.c | 2 +- source/libs/executor/src/executorimpl.c | 2 +- source/libs/executor/src/scanoperator.c | 2 +- 15 files changed, 330 insertions(+), 389 deletions(-) delete mode 100644 source/dnode/vnode/inc/meta.h delete mode 100644 source/dnode/vnode/inc/tsdb.h diff --git a/source/dnode/vnode/inc/meta.h b/source/dnode/vnode/inc/meta.h deleted file mode 100644 index 149aac1206..0000000000 --- a/source/dnode/vnode/inc/meta.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_META_H_ -#define _TD_META_H_ - -#include "tmallocator.h" -#include "tmsg.h" -#include "trow.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define META_SUPER_TABLE TD_SUPER_TABLE -#define META_CHILD_TABLE TD_CHILD_TABLE -#define META_NORMAL_TABLE TD_NORMAL_TABLE - -// Types exported -typedef struct SMeta SMeta; - -typedef struct SMetaCfg { - /// LRU cache size - uint64_t lruSize; -} SMetaCfg; - -typedef struct SMTbCursor SMTbCursor; -typedef struct SMCtbCursor SMCtbCursor; -typedef struct SMSmaCursor SMSmaCursor; - -typedef SVCreateTbReq STbCfg; -typedef SVCreateTSmaReq SSmaCfg; - -// SMeta operations -SMeta * metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF); -void metaClose(SMeta *pMeta); -void metaRemove(const char *path); -int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); -int metaDropTable(SMeta *pMeta, tb_uid_t uid); -int metaCommit(SMeta *pMeta); -int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg); -int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid); - -// For Query -STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid); -STbCfg * metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid); -SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline); -STSchema * metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver); -STSma * metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid); -STSmaWrapper * metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid); -SArray * metaGetSmaTbUids(SMeta *pMeta, bool isDup); -int metaGetTbNum(SMeta *pMeta); - -SMTbCursor *metaOpenTbCursor(SMeta *pMeta); -void metaCloseTbCursor(SMTbCursor *pTbCur); -char * metaTbCursorNext(SMTbCursor *pTbCur); - -SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid); -void metaCloseCtbCurosr(SMCtbCursor *pCtbCur); -tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur); - -SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid); -void metaCloseSmaCurosr(SMSmaCursor *pSmaCur); -const char * metaSmaCursorNext(SMSmaCursor *pSmaCur); - -// Options -void metaOptionsInit(SMetaCfg *pMetaCfg); -void metaOptionsClear(SMetaCfg *pMetaCfg); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_META_H_*/ diff --git a/source/dnode/vnode/inc/tsdb.h b/source/dnode/vnode/inc/tsdb.h deleted file mode 100644 index 9e391a1b7c..0000000000 --- a/source/dnode/vnode/inc/tsdb.h +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_H_ -#define _TD_TSDB_H_ - -#include "tmallocator.h" -#include "meta.h" -#include "tcommon.h" -#include "tfs.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct SDataStatis { - int16_t colId; - int16_t maxIndex; - int16_t minIndex; - int16_t numOfNull; - int64_t sum; - int64_t max; - int64_t min; -} SDataStatis; - -typedef struct STable { - uint64_t tid; - uint64_t uid; - STSchema *pSchema; -} STable; - -#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1 -#define BLOCK_LOAD_TABLE_SEQ_ORDER 2 -#define BLOCK_LOAD_TABLE_RR_ORDER 3 - -#define TABLE_TID(t) (t)->tid -#define TABLE_UID(t) (t)->uid - -// TYPES EXPOSED -typedef struct STsdb STsdb; - -typedef struct STsdbCfg { - int8_t precision; - int8_t update; - int8_t compression; - int32_t daysPerFile; - int32_t minRowsPerFileBlock; - int32_t maxRowsPerFileBlock; - int32_t keep; - int32_t keep1; - int32_t keep2; - uint64_t lruCacheSize; - SArray *retentions; -} STsdbCfg; - -// query condition to build multi-table data block iterator -typedef struct STsdbQueryCond { - STimeWindow twindow; - int32_t order; // desc|asc order to iterate the data block - int32_t numOfCols; - SColumnInfo *colList; - bool loadExternalRows; // load external rows or not - int32_t type; // data block load type: -} STsdbQueryCond; - -typedef struct { - TSKEY lastKey; - uint64_t uid; -} STableKeyInfo; - -// STsdb -STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta, STfs *pTfs); -void tsdbClose(STsdb *); -void tsdbRemove(const char *path); -int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp); -int tsdbPrepareCommit(STsdb *pTsdb); -int tsdbCommit(STsdb *pTsdb); - - -int32_t tsdbInitSma(STsdb *pTsdb); -int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg); -int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg); -/** - * @brief When submit msg received, update the relative expired window synchronously. - * - * @param pTsdb - * @param msg - * @return int32_t - */ -int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, SSubmitReq *pMsg); - -/** - * @brief Insert tSma(Time-range-wise SMA) data from stream computing engine - * - * @param pTsdb - * @param indexUid - * @param msg - * @return int32_t - */ -int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg); - -/** - * @brief Drop tSma data and local cache. - * - * @param pTsdb - * @param indexUid - * @return int32_t - */ -int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid); - -/** - * @brief Insert RSma(Rollup SMA) data. - * - * @param pTsdb - * @param msg - * @return int32_t - */ -int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); - -// TODO: This is the basic params, and should wrap the params to a queryHandle. -/** - * @brief Get tSma(Time-range-wise SMA) data. - * - * @param pTsdb - * @param pData - * @param indexUid - * @param querySKey - * @param nMaxResult - * @return int32_t - */ -int32_t tsdbGetTSmaData(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult); - -// STsdbCfg -int tsdbOptionsInit(STsdbCfg *); -void tsdbOptionsClear(STsdbCfg *); - -typedef void* tsdbReaderT; - -/** - * Get the data block iterator, starting from position according to the query condition - * - * @param tsdb tsdb handle - * @param pCond query condition, including time window, result set order, and basic required columns for each block - * @param tableInfoGroup table object list in the form of set, grouped into different sets according to the - * group by condition - * @param qinfo query info handle from query processor - * @return - */ -tsdbReaderT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, uint64_t taskId); - -/** - * Get the last row of the given query time window for all the tables in STableGroupInfo object. - * Note that only one data block with only row will be returned while invoking retrieve data block function for - * all tables in this group. - * - * @param tsdb tsdb handle - * @param pCond query condition, including time window, result set order, and basic required columns for each block - * @param tableInfo table list. - * @return - */ -//tsdbReaderT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfo, uint64_t qId, -// SMemRef *pRef); - - -tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, void* pMemRef); - -int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* pReader, STableBlockDistInfo* pTableBlockInfo); - -bool isTsdbCacheLastRow(tsdbReaderT* pReader); - -/** - * - * @param tsdb - * @param uid - * @param skey - * @param pTagCond - * @param len - * @param tagNameRelType - * @param tbnameCond - * @param pGroupInfo - * @param pColIndex - * @param numOfCols - * @param reqId - * @return - */ -int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const char* pTagCond, size_t len, - int16_t tagNameRelType, const char* tbnameCond, STableGroupInfo* pGroupInfo, - SColIndex* pColIndex, int32_t numOfCols, uint64_t reqId, uint64_t taskId); -/** - * get num of rows in mem table - * - * @param pHandle - * @return row size - */ - -int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle); - -/** - * move to next block if exists - * - * @param pTsdbReadHandle - * @return - */ -bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle); - -/** - * Get current data block information - * - * @param pTsdbReadHandle - * @param pBlockInfo - * @return - */ -void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo); - -/** - * - * Get the pre-calculated information w.r.t. current data block. - * - * In case of data block in cache, the pBlockStatis will always be NULL. - * If a block is not completed loaded from disk, the pBlockStatis will be NULL. - - * @pBlockStatis the pre-calculated value for current data blocks. if the block is a cache block, always return 0 - * @return - */ -int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SDataStatis **pBlockStatis); - -/** - * - * The query condition with primary timestamp is passed to iterator during its constructor function, - * the returned data block must be satisfied with the time window condition in any cases, - * which means the SData data block is not actually the completed disk data blocks. - * - * @param pTsdbReadHandle query handle - * @param pColumnIdList required data columns id list - * @return - */ -SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList); - -/** - * destroy the created table group list, which is generated by tag query - * @param pGroupList - */ -void tsdbDestroyTableGroup(STableGroupInfo *pGroupList); - -/** - * create the table group result including only one table, used to handle the normal table query - * - * @param tsdb tsdbHandle - * @param uid table uid - * @param pGroupInfo the generated result - * @return - */ -int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo); - -/** - * - * @param tsdb - * @param pTableIdList - * @param pGroupInfo - * @return - */ -int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo); - -/** - * clean up the query handle - * @param queryHandle - */ -void tsdbCleanupReadHandle(tsdbReaderT queryHandle); - -int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TSDB_H_*/ diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index c1c000295a..113501a26b 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -21,12 +21,17 @@ #include "tqueue.h" #include "trpc.h" -#include "meta.h" #include "tarray.h" #include "tfs.h" -#include "tsdb.h" #include "wal.h" +#include "tmallocator.h" +#include "tmsg.h" +#include "trow.h" +#include "tmallocator.h" +#include "tcommon.h" +#include "tfs.h" + #ifdef __cplusplus extern "C" { #endif @@ -34,6 +39,82 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SMgmtWrapper SMgmtWrapper; typedef struct SVnode SVnode; + +#define META_SUPER_TABLE TD_SUPER_TABLE +#define META_CHILD_TABLE TD_CHILD_TABLE +#define META_NORMAL_TABLE TD_NORMAL_TABLE + +// Types exported +typedef struct SMeta SMeta; + +typedef struct SMetaCfg { + /// LRU cache size + uint64_t lruSize; +} SMetaCfg; + +typedef struct SMTbCursor SMTbCursor; +typedef struct SMCtbCursor SMCtbCursor; +typedef struct SMSmaCursor SMSmaCursor; + +typedef SVCreateTbReq STbCfg; +typedef SVCreateTSmaReq SSmaCfg; + +typedef struct SDataStatis { + int16_t colId; + int16_t maxIndex; + int16_t minIndex; + int16_t numOfNull; + int64_t sum; + int64_t max; + int64_t min; +} SDataStatis; + +typedef struct STsdbQueryCond { + STimeWindow twindow; + int32_t order; // desc|asc order to iterate the data block + int32_t numOfCols; + SColumnInfo *colList; + bool loadExternalRows; // load external rows or not + int32_t type; // data block load type: +} STsdbQueryCond; + +typedef struct { + TSKEY lastKey; + uint64_t uid; +} STableKeyInfo; + + +typedef struct STable { + uint64_t tid; + uint64_t uid; + STSchema *pSchema; +} STable; + +#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1 +#define BLOCK_LOAD_TABLE_SEQ_ORDER 2 +#define BLOCK_LOAD_TABLE_RR_ORDER 3 + +#define TABLE_TID(t) (t)->tid +#define TABLE_UID(t) (t)->uid + +// TYPES EXPOSED +typedef struct STsdb STsdb; + +typedef struct STsdbCfg { + int8_t precision; + int8_t update; + int8_t compression; + int32_t daysPerFile; + int32_t minRowsPerFileBlock; + int32_t maxRowsPerFileBlock; + int32_t keep; + int32_t keep1; + int32_t keep2; + uint64_t lruCacheSize; + SArray *retentions; +} STsdbCfg; + + typedef struct { // TODO int32_t reserved; @@ -263,6 +344,241 @@ int tqRetrieveDataBlockInfo(STqReadHandle *pHandle, SDataBlockInfo *pBlockIn // return SArray SArray *tqRetrieveDataBlock(STqReadHandle *pHandle); +// meta.h +SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF); +void metaClose(SMeta *pMeta); +void metaRemove(const char *path); +int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); +int metaDropTable(SMeta *pMeta, tb_uid_t uid); +int metaCommit(SMeta *pMeta); +int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg); +int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid); +STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid); +STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid); +SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline); +STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver); +STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid); +STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid); +SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup); +int metaGetTbNum(SMeta *pMeta); +SMTbCursor *metaOpenTbCursor(SMeta *pMeta); +void metaCloseTbCursor(SMTbCursor *pTbCur); +char *metaTbCursorNext(SMTbCursor *pTbCur); +SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid); +void metaCloseCtbCurosr(SMCtbCursor *pCtbCur); +tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur); + +SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid); +void metaCloseSmaCurosr(SMSmaCursor *pSmaCur); +const char *metaSmaCursorNext(SMSmaCursor *pSmaCur); + +// Options +void metaOptionsInit(SMetaCfg *pMetaCfg); +void metaOptionsClear(SMetaCfg *pMetaCfg); + +// query condition to build multi-table data block iterator +// STsdb +STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta, STfs *pTfs); +void tsdbClose(STsdb *); +void tsdbRemove(const char *path); +int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp); +int tsdbPrepareCommit(STsdb *pTsdb); +int tsdbCommit(STsdb *pTsdb); + + +int32_t tsdbInitSma(STsdb *pTsdb); +int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg); +int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg); +/** + * @brief When submit msg received, update the relative expired window synchronously. + * + * @param pTsdb + * @param msg + * @return int32_t + */ +int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, SSubmitReq *pMsg); + +/** + * @brief Insert tSma(Time-range-wise SMA) data from stream computing engine + * + * @param pTsdb + * @param indexUid + * @param msg + * @return int32_t + */ +int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg); + +/** + * @brief Drop tSma data and local cache. + * + * @param pTsdb + * @param indexUid + * @return int32_t + */ +int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid); + +/** + * @brief Insert RSma(Rollup SMA) data. + * + * @param pTsdb + * @param msg + * @return int32_t + */ +int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); + +// TODO: This is the basic params, and should wrap the params to a queryHandle. +/** + * @brief Get tSma(Time-range-wise SMA) data. + * + * @param pTsdb + * @param pData + * @param indexUid + * @param querySKey + * @param nMaxResult + * @return int32_t + */ +int32_t tsdbGetTSmaData(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult); + +// STsdbCfg +int tsdbOptionsInit(STsdbCfg *); +void tsdbOptionsClear(STsdbCfg *); + +typedef void* tsdbReaderT; + +/** + * Get the data block iterator, starting from position according to the query condition + * + * @param tsdb tsdb handle + * @param pCond query condition, including time window, result set order, and basic required columns for each block + * @param tableInfoGroup table object list in the form of set, grouped into different sets according to the + * group by condition + * @param qinfo query info handle from query processor + * @return + */ +tsdbReaderT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, uint64_t taskId); + +/** + * Get the last row of the given query time window for all the tables in STableGroupInfo object. + * Note that only one data block with only row will be returned while invoking retrieve data block function for + * all tables in this group. + * + * @param tsdb tsdb handle + * @param pCond query condition, including time window, result set order, and basic required columns for each block + * @param tableInfo table list. + * @return + */ +//tsdbReaderT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfo, uint64_t qId, +// SMemRef *pRef); + + +tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, void* pMemRef); + +int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* pReader, STableBlockDistInfo* pTableBlockInfo); + +bool isTsdbCacheLastRow(tsdbReaderT* pReader); + +/** + * + * @param tsdb + * @param uid + * @param skey + * @param pTagCond + * @param len + * @param tagNameRelType + * @param tbnameCond + * @param pGroupInfo + * @param pColIndex + * @param numOfCols + * @param reqId + * @return + */ +int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const char* pTagCond, size_t len, + int16_t tagNameRelType, const char* tbnameCond, STableGroupInfo* pGroupInfo, + SColIndex* pColIndex, int32_t numOfCols, uint64_t reqId, uint64_t taskId); +/** + * get num of rows in mem table + * + * @param pHandle + * @return row size + */ + +int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle); + +/** + * move to next block if exists + * + * @param pTsdbReadHandle + * @return + */ +bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle); + +/** + * Get current data block information + * + * @param pTsdbReadHandle + * @param pBlockInfo + * @return + */ +void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo); + +/** + * + * Get the pre-calculated information w.r.t. current data block. + * + * In case of data block in cache, the pBlockStatis will always be NULL. + * If a block is not completed loaded from disk, the pBlockStatis will be NULL. + + * @pBlockStatis the pre-calculated value for current data blocks. if the block is a cache block, always return 0 + * @return + */ +int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SDataStatis **pBlockStatis); + +/** + * + * The query condition with primary timestamp is passed to iterator during its constructor function, + * the returned data block must be satisfied with the time window condition in any cases, + * which means the SData data block is not actually the completed disk data blocks. + * + * @param pTsdbReadHandle query handle + * @param pColumnIdList required data columns id list + * @return + */ +SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList); + +/** + * destroy the created table group list, which is generated by tag query + * @param pGroupList + */ +void tsdbDestroyTableGroup(STableGroupInfo *pGroupList); + +/** + * create the table group result including only one table, used to handle the normal table query + * + * @param tsdb tsdbHandle + * @param uid table uid + * @param pGroupInfo the generated result + * @return + */ +int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo); + +/** + * + * @param tsdb + * @param pTableIdList + * @param pGroupInfo + * @return + */ +int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo); + +/** + * clean up the query handle + * @param queryHandle + */ +void tsdbCleanupReadHandle(tsdbReaderT queryHandle); + +int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg); + + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/inc/metaDef.h b/source/dnode/vnode/src/inc/metaDef.h index bc1017f0c7..8d624945b2 100644 --- a/source/dnode/vnode/src/inc/metaDef.h +++ b/source/dnode/vnode/src/inc/metaDef.h @@ -17,8 +17,7 @@ #define _TD_META_DEF_H_ #include "tmallocator.h" - -#include "meta.h" +#include "vnode.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/vnode/src/inc/tqInt.h b/source/dnode/vnode/src/inc/tqInt.h index c858ebd6e4..c71c102b06 100644 --- a/source/dnode/vnode/src/inc/tqInt.h +++ b/source/dnode/vnode/src/inc/tqInt.h @@ -16,7 +16,7 @@ #ifndef _TD_TQ_INT_H_ #define _TD_TQ_INT_H_ -#include "meta.h" +#include "vnode.h" #include "tlog.h" #include "tqPush.h" #include "vnodeInt.h" diff --git a/source/dnode/vnode/src/inc/tsdbCommit.h b/source/dnode/vnode/src/inc/tsdbCommit.h index 2c6dd75e03..6e31621384 100644 --- a/source/dnode/vnode/src/inc/tsdbCommit.h +++ b/source/dnode/vnode/src/inc/tsdbCommit.h @@ -16,6 +16,8 @@ #ifndef _TD_TSDB_COMMIT_H_ #define _TD_TSDB_COMMIT_H_ +#include "vnode.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/source/dnode/vnode/src/inc/tsdbDef.h b/source/dnode/vnode/src/inc/tsdbDef.h index 7e79b4a30c..5b9f183252 100644 --- a/source/dnode/vnode/src/inc/tsdbDef.h +++ b/source/dnode/vnode/src/inc/tsdbDef.h @@ -18,7 +18,6 @@ #include "tsdbDBDef.h" #include "tmallocator.h" -#include "meta.h" #include "tcompression.h" #include "tglobal.h" #include "thash.h" @@ -27,7 +26,6 @@ #include "tskiplist.h" #include "ttime.h" -#include "tsdb.h" #include "tsdbCommit.h" #include "tsdbFS.h" #include "tsdbFile.h" diff --git a/source/dnode/vnode/src/inc/tsdbMemTable.h b/source/dnode/vnode/src/inc/tsdbMemTable.h index 0b9d153239..d67402864e 100644 --- a/source/dnode/vnode/src/inc/tsdbMemTable.h +++ b/source/dnode/vnode/src/inc/tsdbMemTable.h @@ -16,7 +16,7 @@ #ifndef _TD_TSDB_MEM_TABLE_H_ #define _TD_TSDB_MEM_TABLE_H_ -#include "tsdb.h" +#include "vnode.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/vnode/src/inc/tsdbReadImpl.h b/source/dnode/vnode/src/inc/tsdbReadImpl.h index 682306221d..6c383063e3 100644 --- a/source/dnode/vnode/src/inc/tsdbReadImpl.h +++ b/source/dnode/vnode/src/inc/tsdbReadImpl.h @@ -19,7 +19,7 @@ #include "os.h" #include "tcommon.h" #include "tfs.h" -#include "tsdb.h" +#include "vnode.h" #include "tsdbFile.h" #include "tsdbMemory.h" #include "tskiplist.h" diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c index 266305cbab..aeb7dfc039 100644 --- a/source/dnode/vnode/src/meta/metaCache.c +++ b/source/dnode/vnode/src/meta/metaCache.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "meta.h" +#include "vnode.h" #include "metaDef.h" struct SMetaCache { diff --git a/source/dnode/vnode/src/meta/metaTbUid.c b/source/dnode/vnode/src/meta/metaTbUid.c index b488630024..e4ab36ec03 100644 --- a/source/dnode/vnode/src/meta/metaTbUid.c +++ b/source/dnode/vnode/src/meta/metaTbUid.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "meta.h" +#include "vnode.h" #include "metaDef.h" int metaOpenUidGnrt(SMeta *pMeta) { diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 144aa7fcdc..1e2687d46f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -20,7 +20,7 @@ #include "tcompare.h" #include "tdataformat.h" #include "texception.h" -#include "tsdb.h" +#include "vnode.h" #include "tsdbFS.h" #include "tsdbLog.h" #include "tsdbReadImpl.h" diff --git a/source/libs/executor/src/executorMain.c b/source/libs/executor/src/executorMain.c index d7c99d54df..5cbda90733 100644 --- a/source/libs/executor/src/executorMain.c +++ b/source/libs/executor/src/executorMain.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include +#include #include "dataSinkMgt.h" #include "texception.h" #include "os.h" diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 953c87bf7e..54e8e6ae8b 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -34,7 +34,7 @@ #include "tcompare.h" #include "tcompression.h" #include "thash.h" -#include "tsdb.h" +#include "vnode.h" #include "ttypes.h" #include "vnode.h" diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index f39a18da68..7181fd0991 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -28,7 +28,7 @@ #include "query.h" #include "tcompare.h" #include "thash.h" -#include "tsdb.h" +#include "vnode.h" #include "ttypes.h" #define SET_REVERSE_SCAN_FLAG(_info) ((_info)->scanFlag = REVERSE_SCAN) From 0e1a27c750b842d686e905fb16a4b0d6917e393b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 06:19:58 +0000 Subject: [PATCH 15/19] more refact --- .../dnode/vnode/src/inc/{metaDef.h => meta.h} | 9 +++---- .../dnode/vnode/src/inc/{tqCommit.h => tq.h} | 13 +++++++++ source/dnode/vnode/src/inc/tsdb.h | 27 +++++++++++++++++++ source/dnode/vnode/src/inc/vnodeInt.h | 6 +++++ source/dnode/vnode/src/meta/metaCache.c | 3 +-- source/dnode/vnode/src/meta/metaCfg.c | 2 +- source/dnode/vnode/src/meta/metaIdx.c | 2 +- source/dnode/vnode/src/meta/metaMain.c | 2 +- source/dnode/vnode/src/meta/metaTDBImpl.c | 2 +- source/dnode/vnode/src/meta/metaTable.c | 2 +- source/dnode/vnode/src/meta/metaTbCfg.c | 2 +- source/dnode/vnode/src/meta/metaTbUid.c | 3 +-- source/dnode/vnode/test/tsdbSmaTest.cpp | 2 +- 13 files changed, 58 insertions(+), 17 deletions(-) rename source/dnode/vnode/src/inc/{metaDef.h => meta.h} (94%) rename source/dnode/vnode/src/inc/{tqCommit.h => tq.h} (81%) create mode 100644 source/dnode/vnode/src/inc/tsdb.h diff --git a/source/dnode/vnode/src/inc/metaDef.h b/source/dnode/vnode/src/inc/meta.h similarity index 94% rename from source/dnode/vnode/src/inc/metaDef.h rename to source/dnode/vnode/src/inc/meta.h index 8d624945b2..b04364daf8 100644 --- a/source/dnode/vnode/src/inc/metaDef.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -13,11 +13,8 @@ * along with this program. If not, see . */ -#ifndef _TD_META_DEF_H_ -#define _TD_META_DEF_H_ - -#include "tmallocator.h" -#include "vnode.h" +#ifndef _TD_VNODE_META_H_ +#define _TD_VNODE_META_H_ #ifdef __cplusplus extern "C" { @@ -77,4 +74,4 @@ struct SMeta { } #endif -#endif /*_TD_META_DEF_H_*/ +#endif /*_TD_VNODE_META_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tqCommit.h b/source/dnode/vnode/src/inc/tq.h similarity index 81% rename from source/dnode/vnode/src/inc/tqCommit.h rename to source/dnode/vnode/src/inc/tq.h index f2f48bbc8a..573fc78df0 100644 --- a/source/dnode/vnode/src/inc/tqCommit.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -12,3 +12,16 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + +#ifndef _TD_VNODE_TQ_H_ +#define _TD_VNODE_TQ_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_TQ_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h new file mode 100644 index 0000000000..0ed2a6dc11 --- /dev/null +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VNODE_TSDB_H_ +#define _TD_VNODE_TSDB_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VNODE_TSDB_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 598c8c07bc..8b9f0d9a8a 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -205,6 +205,12 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t wo // sma void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data); +#include "meta.h" + +#include "tsdb.h" + +#include "tq.h" + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c index aeb7dfc039..e1507a3757 100644 --- a/source/dnode/vnode/src/meta/metaCache.c +++ b/source/dnode/vnode/src/meta/metaCache.c @@ -13,8 +13,7 @@ * along with this program. If not, see . */ -#include "vnode.h" -#include "metaDef.h" +#include "vnodeInt.h" struct SMetaCache { // TODO diff --git a/source/dnode/vnode/src/meta/metaCfg.c b/source/dnode/vnode/src/meta/metaCfg.c index cbaac1c409..a5fcb32698 100644 --- a/source/dnode/vnode/src/meta/metaCfg.c +++ b/source/dnode/vnode/src/meta/metaCfg.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "metaDef.h" +#include "vnodeInt.h" const SMetaCfg defaultMetaOptions = {.lruSize = 0}; diff --git a/source/dnode/vnode/src/meta/metaIdx.c b/source/dnode/vnode/src/meta/metaIdx.c index 818da14738..9a566f788c 100644 --- a/source/dnode/vnode/src/meta/metaIdx.c +++ b/source/dnode/vnode/src/meta/metaIdx.c @@ -16,7 +16,7 @@ #ifdef USE_INVERTED_INDEX #include "index.h" #endif -#include "metaDef.h" +#include "vnodeInt.h" struct SMetaIdx { #ifdef USE_INVERTED_INDEX diff --git a/source/dnode/vnode/src/meta/metaMain.c b/source/dnode/vnode/src/meta/metaMain.c index 690b96bbb0..ac47c32cbf 100644 --- a/source/dnode/vnode/src/meta/metaMain.c +++ b/source/dnode/vnode/src/meta/metaMain.c @@ -15,7 +15,7 @@ #include "tcoding.h" -#include "metaDef.h" +#include "vnodeInt.h" static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF); static void metaFree(SMeta *pMeta); diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index 36b3b53ccd..c78691e7c2 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "metaDef.h" +#include "vnodeInt.h" #include "tdbInt.h" typedef struct SPoolMem { diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 5977ad832c..7f06ba8855 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "metaDef.h" +#include "vnodeInt.h" int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) { // Validate the tbOptions diff --git a/source/dnode/vnode/src/meta/metaTbCfg.c b/source/dnode/vnode/src/meta/metaTbCfg.c index d71d319a79..8ecc808786 100644 --- a/source/dnode/vnode/src/meta/metaTbCfg.c +++ b/source/dnode/vnode/src/meta/metaTbCfg.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "metaDef.h" +#include "vnodeInt.h" #include "tcoding.h" int metaValidateTbCfg(SMeta *pMeta, const STbCfg *pTbOptions) { diff --git a/source/dnode/vnode/src/meta/metaTbUid.c b/source/dnode/vnode/src/meta/metaTbUid.c index e4ab36ec03..27a2ecfb19 100644 --- a/source/dnode/vnode/src/meta/metaTbUid.c +++ b/source/dnode/vnode/src/meta/metaTbUid.c @@ -13,8 +13,7 @@ * along with this program. If not, see . */ -#include "vnode.h" -#include "metaDef.h" +#include "vnodeInt.h" int metaOpenUidGnrt(SMeta *pMeta) { // Init a generator diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 37e2f188cd..208493bdf6 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #pragma GCC diagnostic push From 94bcbf6bacc70a54e7711ef6b82bd4f4c30c3c7b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 06:41:42 +0000 Subject: [PATCH 16/19] refact more --- source/dnode/vnode/CMakeLists.txt | 4 +- source/dnode/vnode/src/inc/tsdb.h | 909 +++++++++++++++++++++ source/dnode/vnode/src/inc/tsdbCommit.h | 79 -- source/dnode/vnode/src/inc/tsdbCompact.h | 32 - source/dnode/vnode/src/inc/tsdbDBDef.h | 45 - source/dnode/vnode/src/inc/tsdbDef.h | 82 -- source/dnode/vnode/src/inc/tsdbFS.h | 141 ---- source/dnode/vnode/src/inc/tsdbFile.h | 435 ---------- source/dnode/vnode/src/inc/tsdbLog.h | 38 - source/dnode/vnode/src/inc/tsdbMemTable.h | 81 -- source/dnode/vnode/src/inc/tsdbMemory.h | 81 -- source/dnode/vnode/src/inc/tsdbOptions.h | 32 - source/dnode/vnode/src/inc/tsdbReadImpl.h | 256 ------ source/dnode/vnode/src/inc/tsdbSma.h | 89 -- source/dnode/vnode/src/inc/vnodeInt.h | 6 +- source/dnode/vnode/src/tq/tq.c | 6 +- source/dnode/vnode/src/tsdb/tsdbBDBImpl.c | 2 - source/dnode/vnode/src/tsdb/tsdbCommit.c | 2 +- source/dnode/vnode/src/tsdb/tsdbFS.c | 2 +- source/dnode/vnode/src/tsdb/tsdbFile.c | 2 +- source/dnode/vnode/src/tsdb/tsdbMain.c | 8 +- source/dnode/vnode/src/tsdb/tsdbMemTable.c | 2 +- source/dnode/vnode/src/tsdb/tsdbOptions.c | 2 +- source/dnode/vnode/src/tsdb/tsdbRead.c | 11 +- source/dnode/vnode/src/tsdb/tsdbReadImpl.c | 2 +- source/dnode/vnode/src/tsdb/tsdbSma.c | 2 +- source/dnode/vnode/src/tsdb/tsdbWrite.c | 2 +- source/dnode/vnode/src/vnd/vnodeWrite.c | 24 +- source/dnode/vnode/test/CMakeLists.txt | 22 +- source/dnode/vnode/test/tsdbSmaTest.cpp | 2 +- 30 files changed, 957 insertions(+), 1444 deletions(-) delete mode 100644 source/dnode/vnode/src/inc/tsdbCommit.h delete mode 100644 source/dnode/vnode/src/inc/tsdbCompact.h delete mode 100644 source/dnode/vnode/src/inc/tsdbDBDef.h delete mode 100644 source/dnode/vnode/src/inc/tsdbDef.h delete mode 100644 source/dnode/vnode/src/inc/tsdbFS.h delete mode 100644 source/dnode/vnode/src/inc/tsdbFile.h delete mode 100644 source/dnode/vnode/src/inc/tsdbLog.h delete mode 100644 source/dnode/vnode/src/inc/tsdbMemTable.h delete mode 100644 source/dnode/vnode/src/inc/tsdbMemory.h delete mode 100644 source/dnode/vnode/src/inc/tsdbOptions.h delete mode 100644 source/dnode/vnode/src/inc/tsdbReadImpl.h delete mode 100644 source/dnode/vnode/src/inc/tsdbSma.h diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 152a9e2945..28e19dc017 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -29,7 +29,7 @@ target_sources( "src/meta/metaTDBImpl.c" # tsdb - "src/tsdb/tsdbBDBImpl.c" + # "src/tsdb/tsdbBDBImpl.c" "src/tsdb/tsdbCommit.c" "src/tsdb/tsdbCompact.c" "src/tsdb/tsdbFile.c" @@ -40,7 +40,7 @@ target_sources( "src/tsdb/tsdbRead.c" "src/tsdb/tsdbReadImpl.c" "src/tsdb/tsdbScan.c" - "src/tsdb/tsdbSma.c" + # "src/tsdb/tsdbSma.c" "src/tsdb/tsdbWrite.c" # tq diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 0ed2a6dc11..97a0832b9c 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -20,8 +20,917 @@ extern "C" { #endif +typedef struct SSmaStat SSmaStat; +typedef struct SSmaEnv SSmaEnv; +typedef struct SSmaEnvs SSmaEnvs; + +typedef enum { + TSDB_FILE_HEAD = 0, // .head + TSDB_FILE_DATA, // .data + TSDB_FILE_LAST, // .last + TSDB_FILE_SMAD, // .smad(Block-wise SMA) + TSDB_FILE_SMAL, // .smal(Block-wise SMA) + TSDB_FILE_MAX, // + TSDB_FILE_META, // meta + TSDB_FILE_TSMA, // v2t100.${sma_index_name}, Time-range-wise SMA + TSDB_FILE_RSMA, // v2r100.${sma_index_name}, Time-range-wise Rollup SMA +} E_TSDB_FILE_T; + +typedef struct { + uint32_t magic; + uint32_t fver; + uint32_t len; + uint32_t totalBlocks; + uint32_t totalSubBlocks; + uint32_t offset; + uint64_t size; + uint64_t tombSize; +} SDFInfo; + +typedef struct { + SDFInfo info; + STfsFile f; + TdFilePtr pFile; + uint8_t state; +} SDFile; + +struct SSmaEnvs { + int16_t nTSma; + int16_t nRSma; + SSmaEnv *pTSmaEnv; + SSmaEnv *pRSmaEnv; +}; + +typedef struct { + int fid; + int8_t state; // -128~127 + uint8_t ver; // 0~255, DFileSet version + uint16_t reserve; + SDFile files[TSDB_FILE_MAX]; +} SDFileSet; + +typedef struct { + int minFid; + int midFid; + int maxFid; + TSKEY minKey; +} SRtn; + +typedef struct STbData { + tb_uid_t uid; + TSKEY keyMin; + TSKEY keyMax; + int64_t nrows; + SSkipList *pData; +} STbData; + +typedef struct STsdbMemTable { + T_REF_DECLARE() + SRWLatch latch; + TSKEY keyMin; + TSKEY keyMax; + uint64_t nRow; + SMemAllocator *pMA; + // Container + SSkipList *pSlIdx; // SSkiplist + SHashObj * pHashIdx; +} STsdbMemTable; + +typedef struct { + uint32_t version; // Commit version from 0 to increase + int64_t totalPoints; // total points + int64_t totalStorage; // Uncompressed total storage +} STsdbFSMeta; + +// ================== +typedef struct { + STsdbFSMeta meta; // FS meta + SArray * df; // data file array + SArray * sf; // sma data file array v2f1900.index_name_1 +} SFSStatus; + +typedef struct { + TdThreadRwlock lock; + + SFSStatus *cstatus; // current status + SHashObj * metaCache; // meta cache + SHashObj * metaCacheComp; // meta cache for compact + bool intxn; + SFSStatus *nstatus; // new status +} STsdbFS; + +struct STsdb { + int32_t vgId; + bool repoLocked; + TdThreadMutex mutex; + char * path; + STsdbCfg config; + STsdbMemTable * mem; + STsdbMemTable * imem; + SRtn rtn; + SMemAllocatorFactory *pmaf; + STsdbFS * fs; + SMeta * pMeta; + STfs * pTfs; + SSmaEnvs smaEnvs; +}; + +#define REPO_ID(r) ((r)->vgId) +#define REPO_CFG(r) (&(r)->config) +#define REPO_FS(r) ((r)->fs) +#define REPO_META(r) ((r)->pMeta) +#define REPO_TFS(r) ((r)->pTfs) +#define IS_REPO_LOCKED(r) ((r)->repoLocked) +#define REPO_TSMA_NUM(r) ((r)->smaEnvs.nTSma) +#define REPO_RSMA_NUM(r) ((r)->smaEnvs.nRSma) +#define REPO_TSMA_ENV(r) ((r)->smaEnvs.pTSmaEnv) +#define REPO_RSMA_ENV(r) ((r)->smaEnvs.pRSmaEnv) + +int tsdbLockRepo(STsdb *pTsdb); +int tsdbUnlockRepo(STsdb *pTsdb); + +static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STable *pTable, bool lock, bool copy, int32_t version) { + return pTable->pSchema; +} + +// tsdbLog +extern int32_t tsdbDebugFlag; + +#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) + +// tsdbMemTable.h +typedef struct { + int rowsInserted; + int rowsUpdated; + int rowsDeleteSucceed; + int rowsDeleteFailed; + int nOperations; + TSKEY keyFirst; + TSKEY keyLast; +} SMergeInfo; + +static void * taosTMalloc(size_t size); +static void * taosTCalloc(size_t nmemb, size_t size); +static void * taosTRealloc(void *ptr, size_t size); +static void * taosTZfree(void *ptr); +static size_t taosTSizeof(void *ptr); +static void taosTMemset(void *ptr, int c); + +STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb); +void tsdbFreeMemTable(STsdb *pTsdb, STsdbMemTable *pMemTable); +int tsdbMemTableInsert(STsdb *pTsdb, STsdbMemTable *pMemTable, SSubmitReq *pMsg, SSubmitRsp *pRsp); +int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols, + TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo); + +static FORCE_INLINE STSRow *tsdbNextIterRow(SSkipListIterator *pIter) { + if (pIter == NULL) return NULL; + + SSkipListNode *node = tSkipListIterGet(pIter); + if (node == NULL) return NULL; + + return (STSRow *)SL_GET_NODE_DATA(node); +} + +static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator *pIter) { + STSRow *row = tsdbNextIterRow(pIter); + if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL; + + return TD_ROW_KEY(row); +} + +// tsdbOptions +extern const STsdbCfg defautlTsdbOptions; + +int tsdbValidateOptions(const STsdbCfg *); +void tsdbOptionsCopy(STsdbCfg *pDest, const STsdbCfg *pSrc); + +// tsdbReadImpl +typedef struct SReadH SReadH; + +typedef struct { + uint32_t len; + uint32_t offset; + uint32_t hasLast : 2; + uint32_t numOfBlocks : 30; + uint64_t uid; + TSKEY maxKey; +} SBlockIdx; + +#ifdef TD_REFACTOR_3 +typedef struct { + int64_t last : 1; + int64_t offset : 63; + int32_t algorithm : 8; + int32_t numOfRows : 24; + int32_t len; + int32_t keyLen; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols + int16_t numOfSubBlocks; + int16_t numOfCols; // not including timestamp column + TSKEY keyFirst; + TSKEY keyLast; +} SBlock; + +#else + +typedef enum { + TSDB_SBLK_VER_0 = 0, + TSDB_SBLK_VER_MAX, +} ESBlockVer; + +#define SBlockVerLatest TSDB_SBLK_VER_0 + +typedef struct { + uint8_t last : 1; + uint8_t blkVer : 7; + uint8_t numOfSubBlocks; + col_id_t numOfCols; // not including timestamp column + uint32_t len; // data block length + uint32_t keyLen : 20; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols + uint32_t algorithm : 4; + uint32_t reserve : 8; + col_id_t numOfBSma; + uint16_t numOfRows; + int64_t offset; + uint64_t aggrStat : 1; + uint64_t aggrOffset : 63; + TSKEY keyFirst; + TSKEY keyLast; +} SBlockV0; + +#define SBlock SBlockV0 // latest SBlock definition + +#endif + +typedef struct { + int32_t delimiter; // For recovery usage + int32_t tid; + uint64_t uid; + SBlock blocks[]; +} SBlockInfo; + +#ifdef TD_REFACTOR_3 +typedef struct { + int16_t colId; + uint16_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM + uint16_t reserve : 15; + int32_t len; + uint32_t type : 8; + uint32_t offset : 24; + int64_t sum; + int64_t max; + int64_t min; + int16_t maxIndex; + int16_t minIndex; + int16_t numOfNull; + uint8_t offsetH; + char padding[1]; +} SBlockCol; +#else +typedef struct { + int16_t colId; + uint16_t type : 6; + uint16_t blen : 10; // bitmap length(TODO: full UT for the bitmap compress of various data input) + uint32_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM + uint32_t len : 31; // data length + bitmap length + uint32_t offset; +} SBlockColV0; + +#define SBlockCol SBlockColV0 // latest SBlockCol definition + +typedef struct { + int16_t colId; + int16_t maxIndex; + int16_t minIndex; + int16_t numOfNull; + int64_t sum; + int64_t max; + int64_t min; +} SAggrBlkColV0; + +#define SAggrBlkCol SAggrBlkColV0 // latest SAggrBlkCol definition + +#endif + +// Code here just for back-ward compatibility +static FORCE_INLINE void tsdbSetBlockColOffset(SBlockCol *pBlockCol, uint32_t offset) { +#ifdef TD_REFACTOR_3 + pBlockCol->offset = offset & ((((uint32_t)1) << 24) - 1); + pBlockCol->offsetH = (uint8_t)(offset >> 24); +#else + pBlockCol->offset = offset; +#endif +} + +static FORCE_INLINE uint32_t tsdbGetBlockColOffset(SBlockCol *pBlockCol) { +#ifdef TD_REFACTOR_3 + uint32_t offset1 = pBlockCol->offset; + uint32_t offset2 = pBlockCol->offsetH; + return (offset1 | (offset2 << 24)); +#else + return pBlockCol->offset; +#endif +} + +typedef struct { + int32_t delimiter; // For recovery usage + int32_t numOfCols; // For recovery usage + uint64_t uid; // For recovery usage + SBlockCol cols[]; +} SBlockData; + +typedef void SAggrBlkData; // SBlockCol cols[]; + +struct SReadH { + STsdb *pRepo; + SDFileSet rSet; // FSET to read + SArray *aBlkIdx; // SBlockIdx array + STable *pTable; // table to read + SBlockIdx *pBlkIdx; // current reading table SBlockIdx + int cidx; + SBlockInfo *pBlkInfo; + SBlockData *pBlkData; // Block info + SAggrBlkData *pAggrBlkData; // Aggregate Block info + SDataCols *pDCols[2]; + void *pBuf; // buffer + void *pCBuf; // compression buffer + void *pExBuf; // extra buffer +}; + +#define TSDB_READ_REPO(rh) ((rh)->pRepo) +#define TSDB_READ_REPO_ID(rh) REPO_ID(TSDB_READ_REPO(rh)) +#define TSDB_READ_FSET(rh) (&((rh)->rSet)) +#define TSDB_READ_TABLE(rh) ((rh)->pTable) +#define TSDB_READ_HEAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_HEAD) +#define TSDB_READ_DATA_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_DATA) +#define TSDB_READ_LAST_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_LAST) +#define TSDB_READ_SMAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_SMAD) +#define TSDB_READ_SMAL_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_SMAL) +#define TSDB_READ_BUF(rh) ((rh)->pBuf) +#define TSDB_READ_COMP_BUF(rh) ((rh)->pCBuf) +#define TSDB_READ_EXBUF(rh) ((rh)->pExBuf) + +#define TSDB_BLOCK_STATIS_SIZE(ncols, blkVer) \ + (sizeof(SBlockData) + sizeof(SBlockColV##blkVer) * (ncols) + sizeof(TSCKSUM)) + +static FORCE_INLINE size_t tsdbBlockStatisSize(int nCols, uint32_t blkVer) { + switch (blkVer) { + case TSDB_SBLK_VER_0: + default: + return TSDB_BLOCK_STATIS_SIZE(nCols, 0); + } +} + +#define TSDB_BLOCK_AGGR_SIZE(ncols, blkVer) (sizeof(SAggrBlkColV##blkVer) * (ncols) + sizeof(TSCKSUM)) + +static FORCE_INLINE size_t tsdbBlockAggrSize(int nCols, uint32_t blkVer) { + switch (blkVer) { + case TSDB_SBLK_VER_0: + default: + return TSDB_BLOCK_AGGR_SIZE(nCols, 0); + } +} + +int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo); +void tsdbDestroyReadH(SReadH *pReadh); +int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet); +void tsdbCloseAndUnsetFSet(SReadH *pReadh); +int tsdbLoadBlockIdx(SReadH *pReadh); +int tsdbSetReadTable(SReadH *pReadh, STable *pTable); +int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget); +int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlockInfo); +int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, + int numOfColsIds); +int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock); +int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx); +void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx); +void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBlock *pBlock); + +static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) { + void *pBuf = *ppBuf; + size_t tsize = taosTSizeof(pBuf); + + if (tsize < size) { + if (tsize == 0) tsize = 1024; + + while (tsize < size) { + tsize *= 2; + } + + *ppBuf = taosTRealloc(pBuf, tsize); + if (*ppBuf == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + return -1; + } + } + + return 0; +} + +// tsdbMemory +static FORCE_INLINE void *taosTMalloc(size_t size) { + if (size <= 0) return NULL; + + void *ret = taosMemoryMalloc(size + sizeof(size_t)); + if (ret == NULL) return NULL; + + *(size_t *)ret = size; + + return (void *)((char *)ret + sizeof(size_t)); +} + +static FORCE_INLINE void *taosTCalloc(size_t nmemb, size_t size) { + size_t tsize = nmemb * size; + void * ret = taosTMalloc(tsize); + if (ret == NULL) return NULL; + + taosTMemset(ret, 0); + return ret; +} + +static FORCE_INLINE size_t taosTSizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; } + +static FORCE_INLINE void taosTMemset(void *ptr, int c) { memset(ptr, c, taosTSizeof(ptr)); } + +static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) { + if (ptr == NULL) return taosTMalloc(size); + + if (size <= taosTSizeof(ptr)) return ptr; + + void * tptr = (void *)((char *)ptr - sizeof(size_t)); + size_t tsize = size + sizeof(size_t); + void* tptr1 = taosMemoryRealloc(tptr, tsize); + if (tptr1 == NULL) return NULL; + tptr = tptr1; + + *(size_t *)tptr = size; + + return (void *)((char *)tptr + sizeof(size_t)); +} + +static FORCE_INLINE void* taosTZfree(void* ptr) { + if (ptr) { + taosMemoryFree((void*)((char*)ptr - sizeof(size_t))); + } + return NULL; +} + +// tsdbCommit + +typedef struct { + uint64_t uid; + int64_t offset; + int64_t size; +} SKVRecord; + +void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn); + +static FORCE_INLINE int TSDB_KEY_FID(TSKEY key, int32_t days, int8_t precision) { + if (key < 0) { + return (int)((key + 1) / tsTickPerDay[precision] / days - 1); + } else { + return (int)((key / tsTickPerDay[precision] / days)); + } +} + +static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) { + if (fid >= pRtn->maxFid) { + return 0; + } else if (fid >= pRtn->midFid) { + return 1; + } else if (fid >= pRtn->minFid) { + return 2; + } else { + return -1; + } +} + +// tsdbDBDef +// typedef struct SDBFile SDBFile; +// typedef DB_ENV* TDBEnv; + +// struct SDBFile { +// int32_t fid; +// DB* pDB; +// char* path; +// }; + +// int32_t tsdbOpenDBF(TDBEnv pEnv, SDBFile* pDBF); +// void tsdbCloseDBF(SDBFile* pDBF); +// int32_t tsdbOpenBDBEnv(DB_ENV** ppEnv, const char* path); +// void tsdbCloseBDBEnv(DB_ENV* pEnv); +// int32_t tsdbSaveSmaToDB(SDBFile* pDBF, void* key, uint32_t keySize, void* data, uint32_t dataSize); +// void* tsdbGetSmaDataByKey(SDBFile* pDBF, void* key, uint32_t keySize, uint32_t* valueSize); + +// tsdbFile +#define TSDB_FILE_HEAD_SIZE 512 +#define TSDB_FILE_DELIMITER 0xF00AFA0F +#define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF +#define TSDB_IVLD_FID INT_MIN +#define TSDB_FILE_STATE_OK 0 +#define TSDB_FILE_STATE_BAD 1 + +#define TSDB_FILE_INFO(tf) (&((tf)->info)) +#define TSDB_FILE_F(tf) (&((tf)->f)) +#define TSDB_FILE_PFILE(tf) ((tf)->pFile) +#define TSDB_FILE_FULL_NAME(tf) (TSDB_FILE_F(tf)->aname) +#define TSDB_FILE_OPENED(tf) (TSDB_FILE_PFILE(tf) != NULL) +#define TSDB_FILE_CLOSED(tf) (!TSDB_FILE_OPENED(tf)) +#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_PFILE(f) = NULL) +#define TSDB_FILE_LEVEL(tf) (TSDB_FILE_F(tf)->did.level) +#define TSDB_FILE_ID(tf) (TSDB_FILE_F(tf)->did.id) +#define TSDB_FILE_DID(tf) (TSDB_FILE_F(tf)->did) +#define TSDB_FILE_REL_NAME(tf) (TSDB_FILE_F(tf)->rname) +#define TSDB_FILE_ABS_NAME(tf) (TSDB_FILE_F(tf)->aname) +#define TSDB_FILE_FSYNC(tf) taosFsyncFile(TSDB_FILE_PFILE(tf)) +#define TSDB_FILE_STATE(tf) ((tf)->state) +#define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s)) +#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK) +#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD) + +typedef int32_t TSDB_FILE_T; +typedef enum { + TSDB_FS_VER_0 = 0, + TSDB_FS_VER_MAX, +} ETsdbFsVer; + +#define TSDB_LATEST_FVER TSDB_FS_VER_0 // latest version for DFile +#define TSDB_LATEST_SFS_VER TSDB_FS_VER_0 // latest version for 'current' file + +static FORCE_INLINE uint32_t tsdbGetDFSVersion(TSDB_FILE_T fType) { // latest version for DFile + switch (fType) { + case TSDB_FILE_HEAD: // .head + case TSDB_FILE_DATA: // .data + case TSDB_FILE_LAST: // .last + case TSDB_FILE_SMAD: // .smad(Block-wise SMA) + case TSDB_FILE_SMAL: // .smal(Block-wise SMA) + default: + return TSDB_LATEST_FVER; + } +} + + +void tsdbInitDFile(STsdb *pRepo, SDFile* pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype); +void tsdbInitDFileEx(SDFile* pDFile, SDFile* pODFile); +int tsdbEncodeSDFile(void** buf, SDFile* pDFile); +void* tsdbDecodeSDFile(STsdb *pRepo, void* buf, SDFile* pDFile); +int tsdbCreateDFile(STsdb *pRepo, SDFile* pDFile, bool updateHeader, TSDB_FILE_T fType); +int tsdbUpdateDFileHeader(SDFile* pDFile); +int tsdbLoadDFileHeader(SDFile* pDFile, SDFInfo* pInfo); +int tsdbParseDFilename(const char* fname, int* vid, int* fid, TSDB_FILE_T* ftype, uint32_t* version); + +static FORCE_INLINE void tsdbSetDFileInfo(SDFile* pDFile, SDFInfo* pInfo) { pDFile->info = *pInfo; } + +static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) { + ASSERT(!TSDB_FILE_OPENED(pDFile)); + + pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), flags); + if (pDFile->pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return 0; +} + +static FORCE_INLINE void tsdbCloseDFile(SDFile* pDFile) { + if (TSDB_FILE_OPENED(pDFile)) { + taosCloseFile(&pDFile->pFile); + TSDB_FILE_SET_CLOSED(pDFile); + } +} + +static FORCE_INLINE int64_t tsdbSeekDFile(SDFile* pDFile, int64_t offset, int whence) { + // ASSERT(TSDB_FILE_OPENED(pDFile)); + + int64_t loffset = taosLSeekFile(TSDB_FILE_PFILE(pDFile), offset, whence); + if (loffset < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return loffset; +} + +static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nbyte) { + ASSERT(TSDB_FILE_OPENED(pDFile)); + + int64_t nwrite = taosWriteFile(pDFile->pFile, buf, nbyte); + if (nwrite < nbyte) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return nwrite; +} + +static FORCE_INLINE void tsdbUpdateDFileMagic(SDFile* pDFile, void* pCksm) { + pDFile->info.magic = taosCalcChecksum(pDFile->info.magic, (uint8_t*)(pCksm), sizeof(TSCKSUM)); +} + +static FORCE_INLINE int tsdbAppendDFile(SDFile* pDFile, void* buf, int64_t nbyte, int64_t* offset) { + ASSERT(TSDB_FILE_OPENED(pDFile)); + + int64_t toffset; + + if ((toffset = tsdbSeekDFile(pDFile, 0, SEEK_END)) < 0) { + return -1; + } + + ASSERT(pDFile->info.size == toffset); + + if (offset) { + *offset = toffset; + } + + if (tsdbWriteDFile(pDFile, buf, nbyte) < 0) { + return -1; + } + + pDFile->info.size += nbyte; + + return (int)nbyte; +} + +static FORCE_INLINE int tsdbRemoveDFile(SDFile* pDFile) { return tfsRemoveFile(TSDB_FILE_F(pDFile)); } + +static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nbyte) { + ASSERT(TSDB_FILE_OPENED(pDFile)); + + int64_t nread = taosReadFile(pDFile->pFile, buf, nbyte); + if (nread < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return nread; +} + +static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) { + if (tfsCopyFile(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + tsdbSetDFileInfo(pDest, TSDB_FILE_INFO(pSrc)); + return 0; +} + +// =============== SDFileSet + +typedef struct { + int fid; + int8_t state; + uint8_t ver; + uint16_t reserve; +#if 0 + SDFInfo info; +#endif + STfsFile f; + TdFilePtr pFile; + +} SSFile; // files split by days with fid + +#define TSDB_LATEST_FSET_VER 0 + +#define TSDB_FSET_FID(s) ((s)->fid) +#define TSDB_FSET_STATE(s) ((s)->state) +#define TSDB_FSET_VER(s) ((s)->ver) +#define TSDB_DFILE_IN_SET(s, t) ((s)->files + (t)) +#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0)) +#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0)) +#define TSDB_FSET_SET_CLOSED(s) \ + do { \ + for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ + TSDB_FILE_SET_CLOSED(TSDB_DFILE_IN_SET(s, ftype)); \ + } \ + } while (0); +#define TSDB_FSET_FSYNC(s) \ + do { \ + for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ + TSDB_FILE_FSYNC(TSDB_DFILE_IN_SET(s, ftype)); \ + } \ + } while (0); + +void tsdbInitDFileSet(STsdb *pRepo, SDFileSet* pSet, SDiskID did, int fid, uint32_t ver); +void tsdbInitDFileSetEx(SDFileSet* pSet, SDFileSet* pOSet); +int tsdbEncodeDFileSet(void** buf, SDFileSet* pSet); +void* tsdbDecodeDFileSet(STsdb *pRepo, void* buf, SDFileSet* pSet); +int tsdbEncodeDFileSetEx(void** buf, SDFileSet* pSet); +void* tsdbDecodeDFileSetEx(void* buf, SDFileSet* pSet); +int tsdbApplyDFileSetChange(SDFileSet* from, SDFileSet* to); +int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet* pSet, bool updateHeader); +int tsdbUpdateDFileSetHeader(SDFileSet* pSet); +int tsdbScanAndTryFixDFileSet(STsdb* pRepo, SDFileSet* pSet); + +static FORCE_INLINE void tsdbCloseDFileSet(SDFileSet* pSet) { + for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + tsdbCloseDFile(TSDB_DFILE_IN_SET(pSet, ftype)); + } +} + +static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet* pSet, int flags) { + for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + if (tsdbOpenDFile(TSDB_DFILE_IN_SET(pSet, ftype), flags) < 0) { + tsdbCloseDFileSet(pSet); + return -1; + } + } + return 0; +} + +static FORCE_INLINE void tsdbRemoveDFileSet(SDFileSet* pSet) { + for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + (void)tsdbRemoveDFile(TSDB_DFILE_IN_SET(pSet, ftype)); + } +} + +static FORCE_INLINE int tsdbCopyDFileSet(SDFileSet* pSrc, SDFileSet* pDest) { + for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + if (tsdbCopyDFile(TSDB_DFILE_IN_SET(pSrc, ftype), TSDB_DFILE_IN_SET(pDest, ftype)) < 0) { + tsdbRemoveDFileSet(pDest); + return -1; + } + } + + return 0; +} + +static FORCE_INLINE void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY* minKey, TSKEY* maxKey) { + *minKey = fid * days * tsTickPerDay[precision]; + *maxKey = *minKey + days * tsTickPerDay[precision] - 1; +} + +static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet* pSet) { + for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { + if (TSDB_FILE_IS_BAD(TSDB_DFILE_IN_SET(pSet, ftype))) { + return false; + } + } + + return true; +} + +// tsdbFS +// ================== TSDB global config +extern bool tsdbForceKeepFile; + +// ================== CURRENT file header info +typedef struct { + uint32_t version; // Current file system version (relating to code) + uint32_t len; // Encode content length (including checksum) +} SFSHeader; + +// ================== TSDB File System Meta + +/** + * @brief Directory structure of .tsma data files. + * + * /vnode2/tsdb $ tree tsma/ + * tsma/ + * ├── v2f100.index_name_1 + * ├── v2f101.index_name_1 + * ├── v2f102.index_name_1 + * ├── v2f1900.index_name_3 + * ├── v2f1901.index_name_3 + * ├── v2f1902.index_name_3 + * ├── v2f200.index_name_2 + * ├── v2f201.index_name_2 + * └── v2f202.index_name_2 + * + * 0 directories, 9 files + */ + +#define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus) +#define FS_NEW_STATUS(pfs) ((pfs)->nstatus) +#define FS_IN_TXN(pfs) (pfs)->intxn +#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version) +#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) + +typedef struct { + int direction; + uint64_t version; // current FS version + STsdbFS * pfs; + int index; // used to position next fset when version the same + int fid; // used to seek when version is changed + SDFileSet *pSet; +} SFSIter; + +#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC +#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC + +STsdbFS *tsdbNewFS(const STsdbCfg *pCfg); +void * tsdbFreeFS(STsdbFS *pfs); +int tsdbOpenFS(STsdb *pRepo); +void tsdbCloseFS(STsdb *pRepo); +void tsdbStartFSTxn(STsdb *pRepo, int64_t pointsAdd, int64_t storageAdd); +int tsdbEndFSTxn(STsdb *pRepo); +int tsdbEndFSTxnWithError(STsdbFS *pfs); +void tsdbUpdateFSTxnMeta(STsdbFS *pfs, STsdbFSMeta *pMeta); +// void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile); +int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet); + +void tsdbFSIterInit(SFSIter *pIter, STsdbFS *pfs, int direction); +void tsdbFSIterSeek(SFSIter *pIter, int fid); +SDFileSet *tsdbFSIterNext(SFSIter *pIter); +int tsdbLoadMetaCache(STsdb *pRepo, bool recoverMeta); + +static FORCE_INLINE int tsdbRLockFS(STsdbFS *pFs) { + int code = taosThreadRwlockRdlock(&(pFs->lock)); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(code); + return -1; + } + return 0; +} + +static FORCE_INLINE int tsdbWLockFS(STsdbFS *pFs) { + int code = taosThreadRwlockWrlock(&(pFs->lock)); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(code); + return -1; + } + return 0; +} + +static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { + int code = taosThreadRwlockUnlock(&(pFs->lock)); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(code); + return -1; + } + return 0; +} + +// tsdbSma +// #define TSDB_SMA_TEST // remove after test finished + + +// struct SSmaEnv { +// TdThreadRwlock lock; +// SDiskID did; +// TDBEnv dbEnv; // TODO: If it's better to put it in smaIndex level? +// char *path; // relative path +// SSmaStat *pStat; +// }; + +// #define SMA_ENV_LOCK(env) ((env)->lock) +// #define SMA_ENV_DID(env) ((env)->did) +// #define SMA_ENV_ENV(env) ((env)->dbEnv) +// #define SMA_ENV_PATH(env) ((env)->path) +// #define SMA_ENV_STAT(env) ((env)->pStat) +// #define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems) + + +// void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv); +// void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv); +// #if 0 +// int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result); +// int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); +// #endif + +// // internal func +// static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) { +// int32_t len = 0; +// len += taosEncodeFixedI64(pData, tsKey); +// len += taosEncodeFixedI64(pData, groupId); +// return len; +// } + +// static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) { +// int code = taosThreadRwlockRdlock(&(pEnv->lock)); +// if (code != 0) { +// terrno = TAOS_SYSTEM_ERROR(code); +// return -1; +// } +// return 0; +// } + +// static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) { +// int code = taosThreadRwlockWrlock(&(pEnv->lock)); +// if (code != 0) { +// terrno = TAOS_SYSTEM_ERROR(code); +// return -1; +// } +// return 0; +// } + +// static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) { +// int code = taosThreadRwlockUnlock(&(pEnv->lock)); +// if (code != 0) { +// terrno = TAOS_SYSTEM_ERROR(code); +// return -1; +// } +// return 0; +// } + #ifdef __cplusplus } #endif + #endif /*_TD_VNODE_TSDB_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbCommit.h b/source/dnode/vnode/src/inc/tsdbCommit.h deleted file mode 100644 index 6e31621384..0000000000 --- a/source/dnode/vnode/src/inc/tsdbCommit.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_COMMIT_H_ -#define _TD_TSDB_COMMIT_H_ - -#include "vnode.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - int minFid; - int midFid; - int maxFid; - TSKEY minKey; -} SRtn; - -typedef struct { - uint64_t uid; - int64_t offset; - int64_t size; -} SKVRecord; - -void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn); - -static FORCE_INLINE int TSDB_KEY_FID(TSKEY key, int32_t days, int8_t precision) { - if (key < 0) { - return (int)((key + 1) / tsTickPerDay[precision] / days - 1); - } else { - return (int)((key / tsTickPerDay[precision] / days)); - } -} - -static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) { - if (fid >= pRtn->maxFid) { - return 0; - } else if (fid >= pRtn->midFid) { - return 1; - } else if (fid >= pRtn->minFid) { - return 2; - } else { - return -1; - } -} - -#if 0 -#define TSDB_DEFAULT_BLOCK_ROWS(maxRows) ((maxRows)*4 / 5) - -int tsdbEncodeKVRecord(void **buf, SKVRecord *pRecord); -void *tsdbDecodeKVRecord(void *buf, SKVRecord *pRecord); -void *tsdbCommitData(STsdbRepo *pRepo); -int tsdbApplyRtnOnFSet(STsdbRepo *pRepo, SDFileSet *pSet, SRtn *pRtn); -int tsdbWriteBlockInfoImpl(SDFile *pHeadf, STable *pTable, SArray *pSupA, SArray *pSubA, void **ppBuf, SBlockIdx *pIdx); -int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf); -int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDataCols *pDataCols, SBlock *pBlock, - bool isLast, bool isSuper, void **ppBuf, void **ppCBuf); -int tsdbApplyRtn(STsdbRepo *pRepo); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _TD_TSDB_COMMIT_H_ */ diff --git a/source/dnode/vnode/src/inc/tsdbCompact.h b/source/dnode/vnode/src/inc/tsdbCompact.h deleted file mode 100644 index c5df4e27ac..0000000000 --- a/source/dnode/vnode/src/inc/tsdbCompact.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -#if 0 - -#ifndef _TD_TSDB_COMPACT_H_ -#define _TD_TSDB_COMPACT_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -void *tsdbCompactImpl(STsdbRepo *pRepo); - -#ifdef __cplusplus -} -#endif - -#endif /* _TD_TSDB_COMPACT_H_ */ - -#endif \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbDBDef.h b/source/dnode/vnode/src/inc/tsdbDBDef.h deleted file mode 100644 index ca9b60049e..0000000000 --- a/source/dnode/vnode/src/inc/tsdbDBDef.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_DB_DEF_H_ -#define _TD_TSDB_DB_DEF_H_ - -#include "db.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct SDBFile SDBFile; -typedef DB_ENV* TDBEnv; - -struct SDBFile { - int32_t fid; - DB* pDB; - char* path; -}; - -int32_t tsdbOpenDBF(TDBEnv pEnv, SDBFile* pDBF); -void tsdbCloseDBF(SDBFile* pDBF); -int32_t tsdbOpenBDBEnv(DB_ENV** ppEnv, const char* path); -void tsdbCloseBDBEnv(DB_ENV* pEnv); -int32_t tsdbSaveSmaToDB(SDBFile* pDBF, void* key, uint32_t keySize, void* data, uint32_t dataSize); -void* tsdbGetSmaDataByKey(SDBFile* pDBF, void* key, uint32_t keySize, uint32_t* valueSize); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TSDB_DB_DEF_H_*/ diff --git a/source/dnode/vnode/src/inc/tsdbDef.h b/source/dnode/vnode/src/inc/tsdbDef.h deleted file mode 100644 index 5b9f183252..0000000000 --- a/source/dnode/vnode/src/inc/tsdbDef.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_DEF_H_ -#define _TD_TSDB_DEF_H_ - -#include "tsdbDBDef.h" -#include "tmallocator.h" -#include "tcompression.h" -#include "tglobal.h" -#include "thash.h" -#include "tlist.h" -#include "tmsg.h" -#include "tskiplist.h" -#include "ttime.h" - -#include "tsdbCommit.h" -#include "tsdbFS.h" -#include "tsdbFile.h" -#include "tsdbLog.h" -#include "tsdbMemTable.h" -#include "tsdbMemory.h" -#include "tsdbOptions.h" -#include "tsdbReadImpl.h" -#include "tsdbSma.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -struct STsdb { - int32_t vgId; - bool repoLocked; - TdThreadMutex mutex; - char * path; - STsdbCfg config; - STsdbMemTable * mem; - STsdbMemTable * imem; - SRtn rtn; - SMemAllocatorFactory *pmaf; - STsdbFS * fs; - SMeta * pMeta; - STfs * pTfs; - SSmaEnvs smaEnvs; -}; - -#define REPO_ID(r) ((r)->vgId) -#define REPO_CFG(r) (&(r)->config) -#define REPO_FS(r) ((r)->fs) -#define REPO_META(r) ((r)->pMeta) -#define REPO_TFS(r) ((r)->pTfs) -#define IS_REPO_LOCKED(r) ((r)->repoLocked) -#define REPO_TSMA_NUM(r) ((r)->smaEnvs.nTSma) -#define REPO_RSMA_NUM(r) ((r)->smaEnvs.nRSma) -#define REPO_TSMA_ENV(r) ((r)->smaEnvs.pTSmaEnv) -#define REPO_RSMA_ENV(r) ((r)->smaEnvs.pRSmaEnv) - -int tsdbLockRepo(STsdb *pTsdb); -int tsdbUnlockRepo(STsdb *pTsdb); - -static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STable *pTable, bool lock, bool copy, int32_t version) { - return pTable->pSchema; -} - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TSDB_DEF_H_*/ diff --git a/source/dnode/vnode/src/inc/tsdbFS.h b/source/dnode/vnode/src/inc/tsdbFS.h deleted file mode 100644 index 8156cbae00..0000000000 --- a/source/dnode/vnode/src/inc/tsdbFS.h +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_FS_H_ -#define _TD_TSDB_FS_H_ - -#include "tsdbFile.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// ================== TSDB global config -extern bool tsdbForceKeepFile; - -// ================== CURRENT file header info -typedef struct { - uint32_t version; // Current file system version (relating to code) - uint32_t len; // Encode content length (including checksum) -} SFSHeader; - -// ================== TSDB File System Meta -typedef struct { - uint32_t version; // Commit version from 0 to increase - int64_t totalPoints; // total points - int64_t totalStorage; // Uncompressed total storage -} STsdbFSMeta; - -// ================== -typedef struct { - STsdbFSMeta meta; // FS meta - SArray * df; // data file array - SArray * sf; // sma data file array v2f1900.index_name_1 -} SFSStatus; - -/** - * @brief Directory structure of .tsma data files. - * - * /vnode2/tsdb $ tree tsma/ - * tsma/ - * ├── v2f100.index_name_1 - * ├── v2f101.index_name_1 - * ├── v2f102.index_name_1 - * ├── v2f1900.index_name_3 - * ├── v2f1901.index_name_3 - * ├── v2f1902.index_name_3 - * ├── v2f200.index_name_2 - * ├── v2f201.index_name_2 - * └── v2f202.index_name_2 - * - * 0 directories, 9 files - */ - -typedef struct { - TdThreadRwlock lock; - - SFSStatus *cstatus; // current status - SHashObj * metaCache; // meta cache - SHashObj * metaCacheComp; // meta cache for compact - bool intxn; - SFSStatus *nstatus; // new status -} STsdbFS; - -#define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus) -#define FS_NEW_STATUS(pfs) ((pfs)->nstatus) -#define FS_IN_TXN(pfs) (pfs)->intxn -#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version) -#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) - -typedef struct { - int direction; - uint64_t version; // current FS version - STsdbFS * pfs; - int index; // used to position next fset when version the same - int fid; // used to seek when version is changed - SDFileSet *pSet; -} SFSIter; - -#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC -#define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC - -STsdbFS *tsdbNewFS(const STsdbCfg *pCfg); -void * tsdbFreeFS(STsdbFS *pfs); -int tsdbOpenFS(STsdb *pRepo); -void tsdbCloseFS(STsdb *pRepo); -void tsdbStartFSTxn(STsdb *pRepo, int64_t pointsAdd, int64_t storageAdd); -int tsdbEndFSTxn(STsdb *pRepo); -int tsdbEndFSTxnWithError(STsdbFS *pfs); -void tsdbUpdateFSTxnMeta(STsdbFS *pfs, STsdbFSMeta *pMeta); -// void tsdbUpdateMFile(STsdbFS *pfs, const SMFile *pMFile); -int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet); - -void tsdbFSIterInit(SFSIter *pIter, STsdbFS *pfs, int direction); -void tsdbFSIterSeek(SFSIter *pIter, int fid); -SDFileSet *tsdbFSIterNext(SFSIter *pIter); -int tsdbLoadMetaCache(STsdb *pRepo, bool recoverMeta); - -static FORCE_INLINE int tsdbRLockFS(STsdbFS *pFs) { - int code = taosThreadRwlockRdlock(&(pFs->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; -} - -static FORCE_INLINE int tsdbWLockFS(STsdbFS *pFs) { - int code = taosThreadRwlockWrlock(&(pFs->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; -} - -static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { - int code = taosThreadRwlockUnlock(&(pFs->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; -} - -#ifdef __cplusplus -} -#endif - -#endif /* _TD_TSDB_FS_H_ */ diff --git a/source/dnode/vnode/src/inc/tsdbFile.h b/source/dnode/vnode/src/inc/tsdbFile.h deleted file mode 100644 index e65ef72623..0000000000 --- a/source/dnode/vnode/src/inc/tsdbFile.h +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TS_TSDB_FILE_H_ -#define _TS_TSDB_FILE_H_ - -#include "tchecksum.h" -#include "tfs.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define TSDB_FILE_HEAD_SIZE 512 -#define TSDB_FILE_DELIMITER 0xF00AFA0F -#define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF -#define TSDB_IVLD_FID INT_MIN -#define TSDB_FILE_STATE_OK 0 -#define TSDB_FILE_STATE_BAD 1 - -#define TSDB_FILE_INFO(tf) (&((tf)->info)) -#define TSDB_FILE_F(tf) (&((tf)->f)) -#define TSDB_FILE_PFILE(tf) ((tf)->pFile) -#define TSDB_FILE_FULL_NAME(tf) (TSDB_FILE_F(tf)->aname) -#define TSDB_FILE_OPENED(tf) (TSDB_FILE_PFILE(tf) != NULL) -#define TSDB_FILE_CLOSED(tf) (!TSDB_FILE_OPENED(tf)) -#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_PFILE(f) = NULL) -#define TSDB_FILE_LEVEL(tf) (TSDB_FILE_F(tf)->did.level) -#define TSDB_FILE_ID(tf) (TSDB_FILE_F(tf)->did.id) -#define TSDB_FILE_DID(tf) (TSDB_FILE_F(tf)->did) -#define TSDB_FILE_REL_NAME(tf) (TSDB_FILE_F(tf)->rname) -#define TSDB_FILE_ABS_NAME(tf) (TSDB_FILE_F(tf)->aname) -#define TSDB_FILE_FSYNC(tf) taosFsyncFile(TSDB_FILE_PFILE(tf)) -#define TSDB_FILE_STATE(tf) ((tf)->state) -#define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s)) -#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK) -#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD) - -typedef enum { - TSDB_FILE_HEAD = 0, // .head - TSDB_FILE_DATA, // .data - TSDB_FILE_LAST, // .last - TSDB_FILE_SMAD, // .smad(Block-wise SMA) - TSDB_FILE_SMAL, // .smal(Block-wise SMA) - TSDB_FILE_MAX, // - TSDB_FILE_META, // meta - TSDB_FILE_TSMA, // v2t100.${sma_index_name}, Time-range-wise SMA - TSDB_FILE_RSMA, // v2r100.${sma_index_name}, Time-range-wise Rollup SMA -} E_TSDB_FILE_T; - -typedef int32_t TSDB_FILE_T; -typedef enum { - TSDB_FS_VER_0 = 0, - TSDB_FS_VER_MAX, -} ETsdbFsVer; - -#define TSDB_LATEST_FVER TSDB_FS_VER_0 // latest version for DFile -#define TSDB_LATEST_SFS_VER TSDB_FS_VER_0 // latest version for 'current' file - -static FORCE_INLINE uint32_t tsdbGetDFSVersion(TSDB_FILE_T fType) { // latest version for DFile - switch (fType) { - case TSDB_FILE_HEAD: // .head - case TSDB_FILE_DATA: // .data - case TSDB_FILE_LAST: // .last - case TSDB_FILE_SMAD: // .smad(Block-wise SMA) - case TSDB_FILE_SMAL: // .smal(Block-wise SMA) - default: - return TSDB_LATEST_FVER; - } -} - -#if 0 -// =============== SMFile -typedef struct { - int64_t size; - int64_t tombSize; - int64_t nRecords; - int64_t nDels; - uint32_t magic; -} SMFInfo; - -typedef struct { - SMFInfo info; - STfsFile f; - int fd; - uint8_t state; -} SMFile; - -void tsdbInitMFile(SMFile* pMFile, SDiskID did, int vid, uint32_t ver); -void tsdbInitMFileEx(SMFile* pMFile, const SMFile* pOMFile); -int tsdbEncodeSMFile(void** buf, SMFile* pMFile); -void* tsdbDecodeSMFile(void* buf, SMFile* pMFile); -int tsdbEncodeSMFileEx(void** buf, SMFile* pMFile); -void* tsdbDecodeSMFileEx(void* buf, SMFile* pMFile); -int tsdbApplyMFileChange(SMFile* from, SMFile* to); -int tsdbCreateMFile(SMFile* pMFile, bool updateHeader); -int tsdbUpdateMFileHeader(SMFile* pMFile); -int tsdbLoadMFileHeader(SMFile* pMFile, SMFInfo* pInfo); -int tsdbScanAndTryFixMFile(STsdb* pRepo); -int tsdbEncodeMFInfo(void** buf, SMFInfo* pInfo); -void* tsdbDecodeMFInfo(void* buf, SMFInfo* pInfo); - -static FORCE_INLINE void tsdbSetMFileInfo(SMFile* pMFile, SMFInfo* pInfo) { pMFile->info = *pInfo; } - -static FORCE_INLINE int tsdbOpenMFile(SMFile* pMFile, int flags) { - ASSERT(TSDB_FILE_CLOSED(pMFile)); - - pMFile->fd = open(TSDB_FILE_FULL_NAME(pMFile), flags); - if (pMFile->fd < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return 0; -} - -static FORCE_INLINE void tsdbCloseMFile(SMFile* pMFile) { - if (TSDB_FILE_OPENED(pMFile)) { - close(pMFile->fd); - TSDB_FILE_SET_CLOSED(pMFile); - } -} - -static FORCE_INLINE int64_t tsdbSeekMFile(SMFile* pMFile, int64_t offset, int whence) { - ASSERT(TSDB_FILE_OPENED(pMFile)); - - int64_t loffset = taosLSeekFile(TSDB_FILE_FD(pMFile), offset, whence); - if (loffset < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return loffset; -} - -static FORCE_INLINE int64_t tsdbWriteMFile(SMFile* pMFile, void* buf, int64_t nbyte) { - ASSERT(TSDB_FILE_OPENED(pMFile)); - - int64_t nwrite = taosWriteFile(pMFile->fd, buf, nbyte); - if (nwrite < nbyte) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return nwrite; -} - -static FORCE_INLINE void tsdbUpdateMFileMagic(SMFile* pMFile, void* pCksum) { - pMFile->info.magic = taosCalcChecksum(pMFile->info.magic, (uint8_t*)(pCksum), sizeof(TSCKSUM)); -} - -static FORCE_INLINE int tsdbAppendMFile(SMFile* pMFile, void* buf, int64_t nbyte, int64_t* offset) { - ASSERT(TSDB_FILE_OPENED(pMFile)); - - int64_t toffset; - - if ((toffset = tsdbSeekMFile(pMFile, 0, SEEK_END)) < 0) { - return -1; - } - - ASSERT(pMFile->info.size == toffset); - - if (offset) { - *offset = toffset; - } - - if (tsdbWriteMFile(pMFile, buf, nbyte) < 0) { - return -1; - } - - pMFile->info.size += nbyte; - - return (int)nbyte; -} - -static FORCE_INLINE int tsdbRemoveMFile(SMFile* pMFile) { return tfsremove(TSDB_FILE_F(pMFile)); } - -static FORCE_INLINE int64_t tsdbReadMFile(SMFile* pMFile, void* buf, int64_t nbyte) { - ASSERT(TSDB_FILE_OPENED(pMFile)); - - int64_t nread = taosReadFile(pMFile->fd, buf, nbyte); - if (nread < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return nread; -} - -#endif - -// =============== SDFile -typedef struct { - uint32_t magic; - uint32_t fver; - uint32_t len; - uint32_t totalBlocks; - uint32_t totalSubBlocks; - uint32_t offset; - uint64_t size; - uint64_t tombSize; -} SDFInfo; - -typedef struct { - SDFInfo info; - STfsFile f; - TdFilePtr pFile; - uint8_t state; -} SDFile; - -void tsdbInitDFile(STsdb *pRepo, SDFile* pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype); -void tsdbInitDFileEx(SDFile* pDFile, SDFile* pODFile); -int tsdbEncodeSDFile(void** buf, SDFile* pDFile); -void* tsdbDecodeSDFile(STsdb *pRepo, void* buf, SDFile* pDFile); -int tsdbCreateDFile(STsdb *pRepo, SDFile* pDFile, bool updateHeader, TSDB_FILE_T fType); -int tsdbUpdateDFileHeader(SDFile* pDFile); -int tsdbLoadDFileHeader(SDFile* pDFile, SDFInfo* pInfo); -int tsdbParseDFilename(const char* fname, int* vid, int* fid, TSDB_FILE_T* ftype, uint32_t* version); - -static FORCE_INLINE void tsdbSetDFileInfo(SDFile* pDFile, SDFInfo* pInfo) { pDFile->info = *pInfo; } - -static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) { - ASSERT(!TSDB_FILE_OPENED(pDFile)); - - pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), flags); - if (pDFile->pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return 0; -} - -static FORCE_INLINE void tsdbCloseDFile(SDFile* pDFile) { - if (TSDB_FILE_OPENED(pDFile)) { - taosCloseFile(&pDFile->pFile); - TSDB_FILE_SET_CLOSED(pDFile); - } -} - -static FORCE_INLINE int64_t tsdbSeekDFile(SDFile* pDFile, int64_t offset, int whence) { - // ASSERT(TSDB_FILE_OPENED(pDFile)); - - int64_t loffset = taosLSeekFile(TSDB_FILE_PFILE(pDFile), offset, whence); - if (loffset < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return loffset; -} - -static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nbyte) { - ASSERT(TSDB_FILE_OPENED(pDFile)); - - int64_t nwrite = taosWriteFile(pDFile->pFile, buf, nbyte); - if (nwrite < nbyte) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return nwrite; -} - -static FORCE_INLINE void tsdbUpdateDFileMagic(SDFile* pDFile, void* pCksm) { - pDFile->info.magic = taosCalcChecksum(pDFile->info.magic, (uint8_t*)(pCksm), sizeof(TSCKSUM)); -} - -static FORCE_INLINE int tsdbAppendDFile(SDFile* pDFile, void* buf, int64_t nbyte, int64_t* offset) { - ASSERT(TSDB_FILE_OPENED(pDFile)); - - int64_t toffset; - - if ((toffset = tsdbSeekDFile(pDFile, 0, SEEK_END)) < 0) { - return -1; - } - - ASSERT(pDFile->info.size == toffset); - - if (offset) { - *offset = toffset; - } - - if (tsdbWriteDFile(pDFile, buf, nbyte) < 0) { - return -1; - } - - pDFile->info.size += nbyte; - - return (int)nbyte; -} - -static FORCE_INLINE int tsdbRemoveDFile(SDFile* pDFile) { return tfsRemoveFile(TSDB_FILE_F(pDFile)); } - -static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nbyte) { - ASSERT(TSDB_FILE_OPENED(pDFile)); - - int64_t nread = taosReadFile(pDFile->pFile, buf, nbyte); - if (nread < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - return nread; -} - -static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) { - if (tfsCopyFile(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } - - tsdbSetDFileInfo(pDest, TSDB_FILE_INFO(pSrc)); - return 0; -} - -// =============== SDFileSet -typedef struct { - int fid; - int8_t state; // -128~127 - uint8_t ver; // 0~255, DFileSet version - uint16_t reserve; - SDFile files[TSDB_FILE_MAX]; -} SDFileSet; - -typedef struct { - int fid; - int8_t state; - uint8_t ver; - uint16_t reserve; -#if 0 - SDFInfo info; -#endif - STfsFile f; - TdFilePtr pFile; - -} SSFile; // files split by days with fid - -#define TSDB_LATEST_FSET_VER 0 - -#define TSDB_FSET_FID(s) ((s)->fid) -#define TSDB_FSET_STATE(s) ((s)->state) -#define TSDB_FSET_VER(s) ((s)->ver) -#define TSDB_DFILE_IN_SET(s, t) ((s)->files + (t)) -#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0)) -#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0)) -#define TSDB_FSET_SET_CLOSED(s) \ - do { \ - for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ - TSDB_FILE_SET_CLOSED(TSDB_DFILE_IN_SET(s, ftype)); \ - } \ - } while (0); -#define TSDB_FSET_FSYNC(s) \ - do { \ - for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ - TSDB_FILE_FSYNC(TSDB_DFILE_IN_SET(s, ftype)); \ - } \ - } while (0); - -void tsdbInitDFileSet(STsdb *pRepo, SDFileSet* pSet, SDiskID did, int fid, uint32_t ver); -void tsdbInitDFileSetEx(SDFileSet* pSet, SDFileSet* pOSet); -int tsdbEncodeDFileSet(void** buf, SDFileSet* pSet); -void* tsdbDecodeDFileSet(STsdb *pRepo, void* buf, SDFileSet* pSet); -int tsdbEncodeDFileSetEx(void** buf, SDFileSet* pSet); -void* tsdbDecodeDFileSetEx(void* buf, SDFileSet* pSet); -int tsdbApplyDFileSetChange(SDFileSet* from, SDFileSet* to); -int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet* pSet, bool updateHeader); -int tsdbUpdateDFileSetHeader(SDFileSet* pSet); -int tsdbScanAndTryFixDFileSet(STsdb* pRepo, SDFileSet* pSet); - -static FORCE_INLINE void tsdbCloseDFileSet(SDFileSet* pSet) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - tsdbCloseDFile(TSDB_DFILE_IN_SET(pSet, ftype)); - } -} - -static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet* pSet, int flags) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (tsdbOpenDFile(TSDB_DFILE_IN_SET(pSet, ftype), flags) < 0) { - tsdbCloseDFileSet(pSet); - return -1; - } - } - return 0; -} - -static FORCE_INLINE void tsdbRemoveDFileSet(SDFileSet* pSet) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - (void)tsdbRemoveDFile(TSDB_DFILE_IN_SET(pSet, ftype)); - } -} - -static FORCE_INLINE int tsdbCopyDFileSet(SDFileSet* pSrc, SDFileSet* pDest) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (tsdbCopyDFile(TSDB_DFILE_IN_SET(pSrc, ftype), TSDB_DFILE_IN_SET(pDest, ftype)) < 0) { - tsdbRemoveDFileSet(pDest); - return -1; - } - } - - return 0; -} - -static FORCE_INLINE void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY* minKey, TSKEY* maxKey) { - *minKey = fid * days * tsTickPerDay[precision]; - *maxKey = *minKey + days * tsTickPerDay[precision] - 1; -} - -static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet* pSet) { - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { - if (TSDB_FILE_IS_BAD(TSDB_DFILE_IN_SET(pSet, ftype))) { - return false; - } - } - - return true; -} - -#ifdef __cplusplus -} -#endif - -#endif /* _TS_TSDB_FILE_H_ */ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbLog.h b/source/dnode/vnode/src/inc/tsdbLog.h deleted file mode 100644 index 3afe628198..0000000000 --- a/source/dnode/vnode/src/inc/tsdbLog.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_LOG_H_ -#define _TD_TSDB_LOG_H_ - -#include "tlog.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern int32_t tsdbDebugFlag; - -#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) -#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) -#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) -#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) -#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) -#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) - -#ifdef __cplusplus -} -#endif - -#endif /* _TD_TSDB_LOG_H_ */ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbMemTable.h b/source/dnode/vnode/src/inc/tsdbMemTable.h deleted file mode 100644 index d67402864e..0000000000 --- a/source/dnode/vnode/src/inc/tsdbMemTable.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_MEM_TABLE_H_ -#define _TD_TSDB_MEM_TABLE_H_ - -#include "vnode.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - int rowsInserted; - int rowsUpdated; - int rowsDeleteSucceed; - int rowsDeleteFailed; - int nOperations; - TSKEY keyFirst; - TSKEY keyLast; -} SMergeInfo; - -typedef struct STbData { - tb_uid_t uid; - TSKEY keyMin; - TSKEY keyMax; - int64_t nrows; - SSkipList *pData; -} STbData; - -typedef struct STsdbMemTable { - T_REF_DECLARE() - SRWLatch latch; - TSKEY keyMin; - TSKEY keyMax; - uint64_t nRow; - SMemAllocator *pMA; - // Container - SSkipList *pSlIdx; // SSkiplist - SHashObj * pHashIdx; -} STsdbMemTable; - -STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb); -void tsdbFreeMemTable(STsdb *pTsdb, STsdbMemTable *pMemTable); -int tsdbMemTableInsert(STsdb *pTsdb, STsdbMemTable *pMemTable, SSubmitReq *pMsg, SSubmitRsp *pRsp); -int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols, - TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo); - -static FORCE_INLINE STSRow *tsdbNextIterRow(SSkipListIterator *pIter) { - if (pIter == NULL) return NULL; - - SSkipListNode *node = tSkipListIterGet(pIter); - if (node == NULL) return NULL; - - return (STSRow *)SL_GET_NODE_DATA(node); -} - -static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator *pIter) { - STSRow *row = tsdbNextIterRow(pIter); - if (row == NULL) return TSDB_DATA_TIMESTAMP_NULL; - - return TD_ROW_KEY(row); -} - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TSDB_MEM_TABLE_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbMemory.h b/source/dnode/vnode/src/inc/tsdbMemory.h deleted file mode 100644 index 69976fc078..0000000000 --- a/source/dnode/vnode/src/inc/tsdbMemory.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_MEMORY_H_ -#define _TD_TSDB_MEMORY_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -static void * taosTMalloc(size_t size); -static void * taosTCalloc(size_t nmemb, size_t size); -static void * taosTRealloc(void *ptr, size_t size); -static void * taosTZfree(void *ptr); -static size_t taosTSizeof(void *ptr); -static void taosTMemset(void *ptr, int c); - -static FORCE_INLINE void *taosTMalloc(size_t size) { - if (size <= 0) return NULL; - - void *ret = taosMemoryMalloc(size + sizeof(size_t)); - if (ret == NULL) return NULL; - - *(size_t *)ret = size; - - return (void *)((char *)ret + sizeof(size_t)); -} - -static FORCE_INLINE void *taosTCalloc(size_t nmemb, size_t size) { - size_t tsize = nmemb * size; - void * ret = taosTMalloc(tsize); - if (ret == NULL) return NULL; - - taosTMemset(ret, 0); - return ret; -} - -static FORCE_INLINE size_t taosTSizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; } - -static FORCE_INLINE void taosTMemset(void *ptr, int c) { memset(ptr, c, taosTSizeof(ptr)); } - -static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) { - if (ptr == NULL) return taosTMalloc(size); - - if (size <= taosTSizeof(ptr)) return ptr; - - void * tptr = (void *)((char *)ptr - sizeof(size_t)); - size_t tsize = size + sizeof(size_t); - void* tptr1 = taosMemoryRealloc(tptr, tsize); - if (tptr1 == NULL) return NULL; - tptr = tptr1; - - *(size_t *)tptr = size; - - return (void *)((char *)tptr + sizeof(size_t)); -} - -static FORCE_INLINE void* taosTZfree(void* ptr) { - if (ptr) { - taosMemoryFree((void*)((char*)ptr - sizeof(size_t))); - } - return NULL; -} - -#ifdef __cplusplus -} -#endif - -#endif /* _TD_TSDB_MEMORY_H_ */ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbOptions.h b/source/dnode/vnode/src/inc/tsdbOptions.h deleted file mode 100644 index 46607ea2fe..0000000000 --- a/source/dnode/vnode/src/inc/tsdbOptions.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_OPTIONS_H_ -#define _TD_TSDB_OPTIONS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -extern const STsdbCfg defautlTsdbOptions; - -int tsdbValidateOptions(const STsdbCfg *); -void tsdbOptionsCopy(STsdbCfg *pDest, const STsdbCfg *pSrc); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TSDB_OPTIONS_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbReadImpl.h b/source/dnode/vnode/src/inc/tsdbReadImpl.h deleted file mode 100644 index 6c383063e3..0000000000 --- a/source/dnode/vnode/src/inc/tsdbReadImpl.h +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_READ_IMPL_H_ -#define _TD_TSDB_READ_IMPL_H_ - -#include "os.h" -#include "tcommon.h" -#include "tfs.h" -#include "vnode.h" -#include "tsdbFile.h" -#include "tsdbMemory.h" -#include "tskiplist.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct SReadH SReadH; - -typedef struct { - uint32_t len; - uint32_t offset; - uint32_t hasLast : 2; - uint32_t numOfBlocks : 30; - uint64_t uid; - TSKEY maxKey; -} SBlockIdx; - -#ifdef TD_REFACTOR_3 -typedef struct { - int64_t last : 1; - int64_t offset : 63; - int32_t algorithm : 8; - int32_t numOfRows : 24; - int32_t len; - int32_t keyLen; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols - int16_t numOfSubBlocks; - int16_t numOfCols; // not including timestamp column - TSKEY keyFirst; - TSKEY keyLast; -} SBlock; - -#else - -typedef enum { - TSDB_SBLK_VER_0 = 0, - TSDB_SBLK_VER_MAX, -} ESBlockVer; - -#define SBlockVerLatest TSDB_SBLK_VER_0 - -typedef struct { - uint8_t last : 1; - uint8_t blkVer : 7; - uint8_t numOfSubBlocks; - col_id_t numOfCols; // not including timestamp column - uint32_t len; // data block length - uint32_t keyLen : 20; // key column length, keyOffset = offset+sizeof(SBlockData)+sizeof(SBlockCol)*numOfCols - uint32_t algorithm : 4; - uint32_t reserve : 8; - col_id_t numOfBSma; - uint16_t numOfRows; - int64_t offset; - uint64_t aggrStat : 1; - uint64_t aggrOffset : 63; - TSKEY keyFirst; - TSKEY keyLast; -} SBlockV0; - -#define SBlock SBlockV0 // latest SBlock definition - -#endif - -typedef struct { - int32_t delimiter; // For recovery usage - int32_t tid; - uint64_t uid; - SBlock blocks[]; -} SBlockInfo; - -#ifdef TD_REFACTOR_3 -typedef struct { - int16_t colId; - uint16_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM - uint16_t reserve : 15; - int32_t len; - uint32_t type : 8; - uint32_t offset : 24; - int64_t sum; - int64_t max; - int64_t min; - int16_t maxIndex; - int16_t minIndex; - int16_t numOfNull; - uint8_t offsetH; - char padding[1]; -} SBlockCol; -#else -typedef struct { - int16_t colId; - uint16_t type : 6; - uint16_t blen : 10; // bitmap length(TODO: full UT for the bitmap compress of various data input) - uint32_t bitmap : 1; // 0: has bitmap if has NULL/NORM rows, 1: no bitmap if all rows are NORM - uint32_t len : 31; // data length + bitmap length - uint32_t offset; -} SBlockColV0; - -#define SBlockCol SBlockColV0 // latest SBlockCol definition - -typedef struct { - int16_t colId; - int16_t maxIndex; - int16_t minIndex; - int16_t numOfNull; - int64_t sum; - int64_t max; - int64_t min; -} SAggrBlkColV0; - -#define SAggrBlkCol SAggrBlkColV0 // latest SAggrBlkCol definition - -#endif - -// Code here just for back-ward compatibility -static FORCE_INLINE void tsdbSetBlockColOffset(SBlockCol *pBlockCol, uint32_t offset) { -#ifdef TD_REFACTOR_3 - pBlockCol->offset = offset & ((((uint32_t)1) << 24) - 1); - pBlockCol->offsetH = (uint8_t)(offset >> 24); -#else - pBlockCol->offset = offset; -#endif -} - -static FORCE_INLINE uint32_t tsdbGetBlockColOffset(SBlockCol *pBlockCol) { -#ifdef TD_REFACTOR_3 - uint32_t offset1 = pBlockCol->offset; - uint32_t offset2 = pBlockCol->offsetH; - return (offset1 | (offset2 << 24)); -#else - return pBlockCol->offset; -#endif -} - -typedef struct { - int32_t delimiter; // For recovery usage - int32_t numOfCols; // For recovery usage - uint64_t uid; // For recovery usage - SBlockCol cols[]; -} SBlockData; - -typedef void SAggrBlkData; // SBlockCol cols[]; - -struct SReadH { - STsdb *pRepo; - SDFileSet rSet; // FSET to read - SArray *aBlkIdx; // SBlockIdx array - STable *pTable; // table to read - SBlockIdx *pBlkIdx; // current reading table SBlockIdx - int cidx; - SBlockInfo *pBlkInfo; - SBlockData *pBlkData; // Block info - SAggrBlkData *pAggrBlkData; // Aggregate Block info - SDataCols *pDCols[2]; - void *pBuf; // buffer - void *pCBuf; // compression buffer - void *pExBuf; // extra buffer -}; - -#define TSDB_READ_REPO(rh) ((rh)->pRepo) -#define TSDB_READ_REPO_ID(rh) REPO_ID(TSDB_READ_REPO(rh)) -#define TSDB_READ_FSET(rh) (&((rh)->rSet)) -#define TSDB_READ_TABLE(rh) ((rh)->pTable) -#define TSDB_READ_HEAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_HEAD) -#define TSDB_READ_DATA_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_DATA) -#define TSDB_READ_LAST_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_LAST) -#define TSDB_READ_SMAD_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_SMAD) -#define TSDB_READ_SMAL_FILE(rh) TSDB_DFILE_IN_SET(TSDB_READ_FSET(rh), TSDB_FILE_SMAL) -#define TSDB_READ_BUF(rh) ((rh)->pBuf) -#define TSDB_READ_COMP_BUF(rh) ((rh)->pCBuf) -#define TSDB_READ_EXBUF(rh) ((rh)->pExBuf) - -#define TSDB_BLOCK_STATIS_SIZE(ncols, blkVer) \ - (sizeof(SBlockData) + sizeof(SBlockColV##blkVer) * (ncols) + sizeof(TSCKSUM)) - -static FORCE_INLINE size_t tsdbBlockStatisSize(int nCols, uint32_t blkVer) { - switch (blkVer) { - case TSDB_SBLK_VER_0: - default: - return TSDB_BLOCK_STATIS_SIZE(nCols, 0); - } -} - -#define TSDB_BLOCK_AGGR_SIZE(ncols, blkVer) (sizeof(SAggrBlkColV##blkVer) * (ncols) + sizeof(TSCKSUM)) - -static FORCE_INLINE size_t tsdbBlockAggrSize(int nCols, uint32_t blkVer) { - switch (blkVer) { - case TSDB_SBLK_VER_0: - default: - return TSDB_BLOCK_AGGR_SIZE(nCols, 0); - } -} - -int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo); -void tsdbDestroyReadH(SReadH *pReadh); -int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet); -void tsdbCloseAndUnsetFSet(SReadH *pReadh); -int tsdbLoadBlockIdx(SReadH *pReadh); -int tsdbSetReadTable(SReadH *pReadh, STable *pTable); -int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget); -int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlockInfo); -int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, - int numOfColsIds); -int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock); -int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx); -void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx); -void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBlock *pBlock); - -static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) { - void *pBuf = *ppBuf; - size_t tsize = taosTSizeof(pBuf); - - if (tsize < size) { - if (tsize == 0) tsize = 1024; - - while (tsize < size) { - tsize *= 2; - } - - *ppBuf = taosTRealloc(pBuf, tsize); - if (*ppBuf == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - } - - return 0; -} - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TSDB_READ_IMPL_H_*/ diff --git a/source/dnode/vnode/src/inc/tsdbSma.h b/source/dnode/vnode/src/inc/tsdbSma.h deleted file mode 100644 index ebeb67261d..0000000000 --- a/source/dnode/vnode/src/inc/tsdbSma.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TSDB_SMA_H_ -#define _TD_TSDB_SMA_H_ - -#define TSDB_SMA_TEST // remove after test finished - -typedef struct SSmaStat SSmaStat; -typedef struct SSmaEnv SSmaEnv; -typedef struct SSmaEnvs SSmaEnvs; - -struct SSmaEnv { - TdThreadRwlock lock; - SDiskID did; - TDBEnv dbEnv; // TODO: If it's better to put it in smaIndex level? - char *path; // relative path - SSmaStat *pStat; -}; - -#define SMA_ENV_LOCK(env) ((env)->lock) -#define SMA_ENV_DID(env) ((env)->did) -#define SMA_ENV_ENV(env) ((env)->dbEnv) -#define SMA_ENV_PATH(env) ((env)->path) -#define SMA_ENV_STAT(env) ((env)->pStat) -#define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems) - -struct SSmaEnvs { - int16_t nTSma; - int16_t nRSma; - SSmaEnv *pTSmaEnv; - SSmaEnv *pRSmaEnv; -}; - -void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv); -void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv); -#if 0 -int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result); -int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); -#endif - -// internal func -static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) { - int32_t len = 0; - len += taosEncodeFixedI64(pData, tsKey); - len += taosEncodeFixedI64(pData, groupId); - return len; -} - -static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) { - int code = taosThreadRwlockRdlock(&(pEnv->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; -} - -static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) { - int code = taosThreadRwlockWrlock(&(pEnv->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; -} - -static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) { - int code = taosThreadRwlockUnlock(&(pEnv->lock)); - if (code != 0) { - terrno = TAOS_SYSTEM_ERROR(code); - return -1; - } - return 0; -} - -#endif /* _TD_TSDB_SMA_H_ */ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 8b9f0d9a8a..2242f6803f 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -17,7 +17,6 @@ #define _TD_VNODE_DEF_H_ #include "tmallocator.h" -// #include "sync.h" #include "tcoding.h" #include "tdatablock.h" #include "tfs.h" @@ -27,6 +26,11 @@ #include "vnode.h" #include "vnodeQuery.h" #include "wal.h" +#include "tskiplist.h" +#include "tchecksum.h" +#include "tglobal.h" +#include "ttime.h" +#include "tcompression.h" #ifdef __cplusplus extern "C" { diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 7af5cbc5e5..70d6dba36f 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -83,9 +83,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t versi memcpy(data, msg, msgLen); if (msgType == TDMT_VND_SUBMIT) { - if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg) != 0) { - return -1; - } + // if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg) != 0) { + // return -1; + // } } SRpcMsg req = { diff --git a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c index c8f4cd642a..0deef2e4c9 100644 --- a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c @@ -19,8 +19,6 @@ #include "taoserror.h" #include "tcoding.h" #include "thash.h" -#include "tsdbDBDef.h" -#include "tsdbLog.h" #define IMPL_WITH_LOCK 1 diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 18d3de94cc..42d29209f5 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" #define TSDB_MAX_SUBBLOCKS 8 diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 51d6efe077..1f42e90616 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -14,7 +14,7 @@ */ #include -#include "tsdbDef.h" +#include "vnodeInt.h" #include "os.h" typedef enum { TSDB_TXN_TEMP_FILE = 0, TSDB_TXN_CURR_FILE } TSDB_TXN_FILE_T; diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 271616e9c2..a2dab19141 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" static const char *TSDB_FNAME_SUFFIX[] = { "head", // TSDB_FILE_HEAD diff --git a/source/dnode/vnode/src/tsdb/tsdbMain.c b/source/dnode/vnode/src/tsdb/tsdbMain.c index 653c30c091..8543cde046 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMain.c +++ b/source/dnode/vnode/src/tsdb/tsdbMain.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta, STfs *pTfs); @@ -87,8 +87,8 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, static void tsdbFree(STsdb *pTsdb) { if (pTsdb) { - tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb)); - tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb)); + // tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb)); + // tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb)); tsdbFreeFS(pTsdb->fs); taosMemoryFreeClear(pTsdb->path); taosMemoryFree(pTsdb); @@ -98,7 +98,7 @@ static void tsdbFree(STsdb *pTsdb) { static int tsdbOpenImpl(STsdb *pTsdb) { tsdbOpenFS(pTsdb); - tsdbInitSma(pTsdb); + // tsdbInitSma(pTsdb); // TODO return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index 34dba5d3ba..c657b2e947 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" static int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg); static int tsdbMemTableInsertTbData(STsdb *pRepo, SSubmitBlk *pBlock, int32_t *pAffectedRows); diff --git a/source/dnode/vnode/src/tsdb/tsdbOptions.c b/source/dnode/vnode/src/tsdb/tsdbOptions.c index 6bca2e3028..da7a1d393f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOptions.c +++ b/source/dnode/vnode/src/tsdb/tsdbOptions.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" const STsdbCfg defautlTsdbOptions = {.precision = 0, .lruCacheSize = 0, diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 1e2687d46f..de6a05df46 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -13,25 +13,18 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" #include "tdatablock.h" #include "os.h" #include "talgo.h" #include "tcompare.h" #include "tdataformat.h" #include "texception.h" -#include "vnode.h" -#include "tsdbFS.h" -#include "tsdbLog.h" -#include "tsdbReadImpl.h" -#include "tskiplist.h" -#include "ttime.h" #include "taosdef.h" #include "tlosertree.h" -#include "tsdbDef.h" +#include "vnodeInt.h" #include "tmsg.h" -#include "tsdbCommit.h" #define EXTRA_BYTES 2 #define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index 687e2ca776..8b718dbb0e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" #define TSDB_KEY_COL_OFFSET 0 diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index aacaf1b3ec..4ee85e61f1 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" static const char *TSDB_SMA_DNAME[] = { "", // TSDB_SMA_TYPE_BLOCK diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c index 5590f13cc6..abfcc675ea 100644 --- a/source/dnode/vnode/src/tsdb/tsdbWrite.c +++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tsdbDef.h" +#include "vnodeInt.h" /** * @brief insert TS data diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index fb0340046e..bf2260c51c 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -18,8 +18,8 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { // TODO - blockDebugShowData(data); - tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); + // blockDebugShowData(data); + // tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); } void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { @@ -232,16 +232,16 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { tdDestroyTSma(&vCreateSmaReq.tSma); // TODO: return directly or go on follow steps? #endif - if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - // TODO - } - } break; - case TDMT_VND_CANCEL_SMA: { // timeRangeSMA - } break; - case TDMT_VND_DROP_SMA: { // timeRangeSMA - if (tsdbDropTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - // TODO - } + // if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + // // TODO + // } + // } break; + // case TDMT_VND_CANCEL_SMA: { // timeRangeSMA + // } break; + // case TDMT_VND_DROP_SMA: { // timeRangeSMA + // if (tsdbDropTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + // // TODO + // } #if 0 tsdbTSmaSub(pVnode->pTsdb, 1); SVDropTSmaReq vDropSmaReq = {0}; diff --git a/source/dnode/vnode/test/CMakeLists.txt b/source/dnode/vnode/test/CMakeLists.txt index af123a3133..59f459462f 100644 --- a/source/dnode/vnode/test/CMakeLists.txt +++ b/source/dnode/vnode/test/CMakeLists.txt @@ -25,15 +25,15 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) # COMMAND tqTest # ) -ADD_EXECUTABLE(tsdbSmaTest tsdbSmaTest.cpp) -TARGET_LINK_LIBRARIES( - tsdbSmaTest - PUBLIC os util common vnode gtest_main -) +# ADD_EXECUTABLE(tsdbSmaTest tsdbSmaTest.cpp) +# TARGET_LINK_LIBRARIES( +# tsdbSmaTest +# PUBLIC os util common vnode gtest_main +# ) -TARGET_INCLUDE_DIRECTORIES( - tsdbSmaTest - PUBLIC "${CMAKE_SOURCE_DIR}/include/common" - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../src/inc" - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../inc" -) \ No newline at end of file +# TARGET_INCLUDE_DIRECTORIES( +# tsdbSmaTest +# PUBLIC "${CMAKE_SOURCE_DIR}/include/common" +# PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../src/inc" +# PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +# ) \ No newline at end of file diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 208493bdf6..6a4adfe4f8 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -14,7 +14,7 @@ */ #include -#include +#include #include #include From 742b2918ff443b32826b6d32b8b27549aba1f034 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 06:49:07 +0000 Subject: [PATCH 17/19] refact more --- source/dnode/vnode/src/inc/tq.h | 275 +++++++++++++++++++++++ source/dnode/vnode/src/inc/tqInt.h | 223 ------------------ source/dnode/vnode/src/inc/tqMetaStore.h | 51 ----- source/dnode/vnode/src/inc/tqOffset.h | 40 ---- source/dnode/vnode/src/inc/tqPush.h | 80 ------- source/dnode/vnode/src/inc/vnodeInt.h | 25 ++- source/dnode/vnode/src/inc/vnodeQuery.h | 35 --- source/dnode/vnode/src/tq/tq.c | 34 +-- source/dnode/vnode/src/tq/tqMetaStore.c | 2 +- source/dnode/vnode/src/tq/tqOffset.c | 3 +- source/dnode/vnode/src/tq/tqPush.c | 2 +- source/dnode/vnode/src/vnd/vnodeQuery.c | 1 - 12 files changed, 313 insertions(+), 458 deletions(-) delete mode 100644 source/dnode/vnode/src/inc/tqInt.h delete mode 100644 source/dnode/vnode/src/inc/tqMetaStore.h delete mode 100644 source/dnode/vnode/src/inc/tqOffset.h delete mode 100644 source/dnode/vnode/src/inc/tqPush.h delete mode 100644 source/dnode/vnode/src/inc/vnodeQuery.h diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index 573fc78df0..bee443f487 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -20,6 +20,281 @@ extern "C" { #endif +// tqInt.h +#define tqFatal(...) \ + { \ + if (tqDebugFlag & DEBUG_FATAL) { \ + taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ + } \ + } + +#define tqError(...) \ + { \ + if (tqDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ + } \ + } + +#define tqWarn(...) \ + { \ + if (tqDebugFlag & DEBUG_WARN) { \ + taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ + } \ + } + +#define tqInfo(...) \ + { \ + if (tqDebugFlag & DEBUG_INFO) { \ + taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); \ + } \ + } + +#define tqDebug(...) \ + { \ + if (tqDebugFlag & DEBUG_DEBUG) { \ + taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); \ + } \ + } + +#define tqTrace(...) \ + { \ + if (tqDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); \ + } \ + } + +#define TQ_BUFFER_SIZE 4 + +#define TQ_BUCKET_MASK 0xFF +#define TQ_BUCKET_SIZE 256 + +#define TQ_PAGE_SIZE 4096 +// key + offset + size +#define TQ_IDX_SIZE 24 +// 4096 / 24 +#define TQ_MAX_IDX_ONE_PAGE 170 +// 24 * 170 +#define TQ_IDX_PAGE_BODY_SIZE 4080 +// 4096 - 4080 +#define TQ_IDX_PAGE_HEAD_SIZE 16 + +#define TQ_ACTION_CONST 0 +#define TQ_ACTION_INUSE 1 +#define TQ_ACTION_INUSE_CONT 2 +#define TQ_ACTION_INTXN 3 + +#define TQ_SVER 0 + +// TODO: inplace mode is not implemented +#define TQ_UPDATE_INPLACE 0 +#define TQ_UPDATE_APPEND 1 + +#define TQ_DUP_INTXN_REWRITE 0 +#define TQ_DUP_INTXN_REJECT 2 + +static inline bool tqUpdateAppend(int32_t tqConfigFlag) { return tqConfigFlag & TQ_UPDATE_APPEND; } + +static inline bool tqDupIntxnReject(int32_t tqConfigFlag) { return tqConfigFlag & TQ_DUP_INTXN_REJECT; } + +static const int8_t TQ_CONST_DELETE = TQ_ACTION_CONST; + +#define TQ_DELETE_TOKEN (void*)&TQ_CONST_DELETE + +typedef enum { TQ_ITEM_READY, TQ_ITEM_PROCESS, TQ_ITEM_EMPTY } STqItemStatus; + +typedef struct STqOffsetCfg STqOffsetCfg; +typedef struct STqOffsetStore STqOffsetStore; + +typedef struct { + int16_t ver; + int16_t action; + int32_t checksum; + int64_t ssize; + char content[]; +} STqSerializedHead; + +typedef int32_t (*FTqSerialize)(const void* pObj, STqSerializedHead** ppHead); +typedef int32_t (*FTqDeserialize)(void* self, const STqSerializedHead* pHead, void** ppObj); +typedef void (*FTqDelete)(void*); + +typedef struct { + int64_t key; + int64_t offset; + int64_t serializedSize; + void* valueInUse; + void* valueInTxn; +} STqMetaHandle; + +typedef struct STqMetaList { + STqMetaHandle handle; + struct STqMetaList* next; + // struct STqMetaList* inTxnPrev; + // struct STqMetaList* inTxnNext; + struct STqMetaList* unpersistPrev; + struct STqMetaList* unpersistNext; +} STqMetaList; + +typedef struct { + STQ* pTq; + STqMetaList* bucket[TQ_BUCKET_SIZE]; + // a table head + STqMetaList* unpersistHead; + // topics that are not connectted + STqMetaList* unconnectTopic; + + TdFilePtr pFile; + TdFilePtr pIdxFile; + + char* dirPath; + int32_t tqConfigFlag; + FTqSerialize pSerializer; + FTqDeserialize pDeserializer; + FTqDelete pDeleter; +} STqMetaStore; + +typedef struct { + SMemAllocatorFactory* pAllocatorFactory; + SMemAllocator* pAllocator; +} STqMemRef; + +struct STQ { + // the collection of groups + // the handle of meta kvstore + bool writeTrigger; + char* path; + STqCfg* tqConfig; + STqMemRef tqMemRef; + STqMetaStore* tqMeta; + // STqPushMgr* tqPushMgr; + SHashObj* pStreamTasks; + SVnode* pVnode; + SWal* pWal; + SMeta* pVnodeMeta; +}; + +typedef struct { + int8_t inited; + tmr_h timer; +} STqMgmt; + +static STqMgmt tqMgmt; + +typedef struct { + int8_t status; + int64_t offset; + qTaskInfo_t task; + STqReadHandle* pReadHandle; +} STqTaskItem; + +// new version +typedef struct { + int64_t firstOffset; + int64_t lastOffset; + STqTaskItem output[TQ_BUFFER_SIZE]; +} STqBuffer; + +typedef struct { + char topicName[TSDB_TOPIC_FNAME_LEN]; + char* sql; + char* logicalPlan; + char* physicalPlan; + char* qmsg; + STqBuffer buffer; + SWalReadHandle* pReadhandle; +} STqTopic; + +typedef struct { + int64_t consumerId; + int32_t epoch; + char cgroup[TSDB_TOPIC_FNAME_LEN]; + SArray* topics; // SArray +} STqConsumer; + +enum { + TQ_PUSHER_TYPE__CLIENT = 1, + TQ_PUSHER_TYPE__STREAM, +}; + +typedef struct { + int8_t type; + int8_t reserved[3]; + int32_t ttl; + int64_t consumerId; + SRpcMsg* pMsg; + // SMqPollRsp* rsp; +} STqClientPusher; + +typedef struct { + int8_t type; + int8_t nodeType; + int8_t reserved[6]; + int64_t streamId; + qTaskInfo_t task; + // TODO sync function +} STqStreamPusher; + +typedef struct { + int8_t type; // mq or stream +} STqPusher; + +typedef struct { + SHashObj* pHash; // +} STqPushMgr; + +typedef struct { + int8_t inited; + tmr_h timer; +} STqPushMgmt; + +static STqPushMgmt tqPushMgmt; + + +int32_t tqSerializeConsumer(const STqConsumer*, STqSerializedHead**); +int32_t tqDeserializeConsumer(STQ*, const STqSerializedHead*, STqConsumer**); + +static int FORCE_INLINE tqQueryExecuting(int32_t status) { return status; } + +// tqMetaStore.h +STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize pSerializer, FTqDeserialize pDeserializer, + FTqDelete pDeleter, int32_t tqConfigFlag); +int32_t tqStoreClose(STqMetaStore*); +// int32_t tqStoreDelete(TqMetaStore*); +// int32_t tqStoreCommitAll(TqMetaStore*); +int32_t tqStorePersist(STqMetaStore*); +// clean deleted idx and data from persistent file +int32_t tqStoreCompact(STqMetaStore*); + +void* tqHandleGet(STqMetaStore*, int64_t key); +// make it unpersist +void* tqHandleTouchGet(STqMetaStore*, int64_t key); +int32_t tqHandleMovePut(STqMetaStore*, int64_t key, void* value); +int32_t tqHandleCopyPut(STqMetaStore*, int64_t key, void* value, size_t vsize); +// delete committed kv pair +// notice that a delete action still needs to be committed +int32_t tqHandleDel(STqMetaStore*, int64_t key); +int32_t tqHandlePurge(STqMetaStore*, int64_t key); +int32_t tqHandleCommit(STqMetaStore*, int64_t key); +int32_t tqHandleAbort(STqMetaStore*, int64_t key); + +// tqOffset +STqOffsetStore* STqOffsetOpen(STqOffsetCfg*); +void STqOffsetClose(STqOffsetStore*); + +int64_t tqOffsetFetch(STqOffsetStore* pStore, const char* subscribeKey); +int32_t tqOffsetCommit(STqOffsetStore* pStore, const char* subscribeKey, int64_t offset); +int32_t tqOffsetPersist(STqOffsetStore* pStore, const char* subscribeKey); +int32_t tqOffsetPersistAll(STqOffsetStore* pStore); + +// tqPush +int32_t tqPushMgrInit(); +void tqPushMgrCleanUp(); + +STqPushMgr* tqPushMgrOpen(); +void tqPushMgrClose(STqPushMgr* pushMgr); + +STqClientPusher* tqAddClientPusher(STqPushMgr* pushMgr, SRpcMsg* pMsg, int64_t consumerId, int64_t ttl); +STqStreamPusher* tqAddStreamPusher(STqPushMgr* pushMgr, int64_t streamId, SEpSet* pEpSet); + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/inc/tqInt.h b/source/dnode/vnode/src/inc/tqInt.h deleted file mode 100644 index c71c102b06..0000000000 --- a/source/dnode/vnode/src/inc/tqInt.h +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TQ_INT_H_ -#define _TD_TQ_INT_H_ - -#include "vnode.h" -#include "tlog.h" -#include "tqPush.h" -#include "vnodeInt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define tqFatal(...) \ - { \ - if (tqDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ - } \ - } - -#define tqError(...) \ - { \ - if (tqDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ - } \ - } - -#define tqWarn(...) \ - { \ - if (tqDebugFlag & DEBUG_WARN) { \ - taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ - } \ - } - -#define tqInfo(...) \ - { \ - if (tqDebugFlag & DEBUG_INFO) { \ - taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); \ - } \ - } - -#define tqDebug(...) \ - { \ - if (tqDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); \ - } \ - } - -#define tqTrace(...) \ - { \ - if (tqDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); \ - } \ - } - -#define TQ_BUFFER_SIZE 4 - -#define TQ_BUCKET_MASK 0xFF -#define TQ_BUCKET_SIZE 256 - -#define TQ_PAGE_SIZE 4096 -// key + offset + size -#define TQ_IDX_SIZE 24 -// 4096 / 24 -#define TQ_MAX_IDX_ONE_PAGE 170 -// 24 * 170 -#define TQ_IDX_PAGE_BODY_SIZE 4080 -// 4096 - 4080 -#define TQ_IDX_PAGE_HEAD_SIZE 16 - -#define TQ_ACTION_CONST 0 -#define TQ_ACTION_INUSE 1 -#define TQ_ACTION_INUSE_CONT 2 -#define TQ_ACTION_INTXN 3 - -#define TQ_SVER 0 - -// TODO: inplace mode is not implemented -#define TQ_UPDATE_INPLACE 0 -#define TQ_UPDATE_APPEND 1 - -#define TQ_DUP_INTXN_REWRITE 0 -#define TQ_DUP_INTXN_REJECT 2 - -static inline bool tqUpdateAppend(int32_t tqConfigFlag) { return tqConfigFlag & TQ_UPDATE_APPEND; } - -static inline bool tqDupIntxnReject(int32_t tqConfigFlag) { return tqConfigFlag & TQ_DUP_INTXN_REJECT; } - -static const int8_t TQ_CONST_DELETE = TQ_ACTION_CONST; - -#define TQ_DELETE_TOKEN (void*)&TQ_CONST_DELETE - -typedef enum { TQ_ITEM_READY, TQ_ITEM_PROCESS, TQ_ITEM_EMPTY } STqItemStatus; - -typedef struct { - int16_t ver; - int16_t action; - int32_t checksum; - int64_t ssize; - char content[]; -} STqSerializedHead; - -typedef int32_t (*FTqSerialize)(const void* pObj, STqSerializedHead** ppHead); -typedef int32_t (*FTqDeserialize)(void* self, const STqSerializedHead* pHead, void** ppObj); -typedef void (*FTqDelete)(void*); - -typedef struct { - int64_t key; - int64_t offset; - int64_t serializedSize; - void* valueInUse; - void* valueInTxn; -} STqMetaHandle; - -typedef struct STqMetaList { - STqMetaHandle handle; - struct STqMetaList* next; - // struct STqMetaList* inTxnPrev; - // struct STqMetaList* inTxnNext; - struct STqMetaList* unpersistPrev; - struct STqMetaList* unpersistNext; -} STqMetaList; - -typedef struct { - STQ* pTq; - STqMetaList* bucket[TQ_BUCKET_SIZE]; - // a table head - STqMetaList* unpersistHead; - // topics that are not connectted - STqMetaList* unconnectTopic; - - TdFilePtr pFile; - TdFilePtr pIdxFile; - - char* dirPath; - int32_t tqConfigFlag; - FTqSerialize pSerializer; - FTqDeserialize pDeserializer; - FTqDelete pDeleter; -} STqMetaStore; - -typedef struct { - SMemAllocatorFactory* pAllocatorFactory; - SMemAllocator* pAllocator; -} STqMemRef; - -struct STQ { - // the collection of groups - // the handle of meta kvstore - bool writeTrigger; - char* path; - STqCfg* tqConfig; - STqMemRef tqMemRef; - STqMetaStore* tqMeta; - // STqPushMgr* tqPushMgr; - SHashObj* pStreamTasks; - SVnode* pVnode; - SWal* pWal; - SMeta* pVnodeMeta; -}; - -typedef struct { - int8_t inited; - tmr_h timer; -} STqMgmt; - -static STqMgmt tqMgmt; - -typedef struct { - int8_t status; - int64_t offset; - qTaskInfo_t task; - STqReadHandle* pReadHandle; -} STqTaskItem; - -// new version -typedef struct { - int64_t firstOffset; - int64_t lastOffset; - STqTaskItem output[TQ_BUFFER_SIZE]; -} STqBuffer; - -typedef struct { - char topicName[TSDB_TOPIC_FNAME_LEN]; - char* sql; - char* logicalPlan; - char* physicalPlan; - char* qmsg; - STqBuffer buffer; - SWalReadHandle* pReadhandle; -} STqTopic; - -typedef struct { - int64_t consumerId; - int32_t epoch; - char cgroup[TSDB_TOPIC_FNAME_LEN]; - SArray* topics; // SArray -} STqConsumer; - -int32_t tqSerializeConsumer(const STqConsumer*, STqSerializedHead**); -int32_t tqDeserializeConsumer(STQ*, const STqSerializedHead*, STqConsumer**); - -static int FORCE_INLINE tqQueryExecuting(int32_t status) { return status; } - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TQ_INT_H_*/ diff --git a/source/dnode/vnode/src/inc/tqMetaStore.h b/source/dnode/vnode/src/inc/tqMetaStore.h deleted file mode 100644 index eb203b7117..0000000000 --- a/source/dnode/vnode/src/inc/tqMetaStore.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TQ_META_STORE_H_ -#define _TQ_META_STORE_H_ - -#include "os.h" -#include "tqInt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize pSerializer, FTqDeserialize pDeserializer, - FTqDelete pDeleter, int32_t tqConfigFlag); -int32_t tqStoreClose(STqMetaStore*); -// int32_t tqStoreDelete(TqMetaStore*); -// int32_t tqStoreCommitAll(TqMetaStore*); -int32_t tqStorePersist(STqMetaStore*); -// clean deleted idx and data from persistent file -int32_t tqStoreCompact(STqMetaStore*); - -void* tqHandleGet(STqMetaStore*, int64_t key); -// make it unpersist -void* tqHandleTouchGet(STqMetaStore*, int64_t key); -int32_t tqHandleMovePut(STqMetaStore*, int64_t key, void* value); -int32_t tqHandleCopyPut(STqMetaStore*, int64_t key, void* value, size_t vsize); -// delete committed kv pair -// notice that a delete action still needs to be committed -int32_t tqHandleDel(STqMetaStore*, int64_t key); -int32_t tqHandlePurge(STqMetaStore*, int64_t key); -int32_t tqHandleCommit(STqMetaStore*, int64_t key); -int32_t tqHandleAbort(STqMetaStore*, int64_t key); - -#ifdef __cplusplus -} -#endif - -#endif /* ifndef _TQ_META_STORE_H_ */ diff --git a/source/dnode/vnode/src/inc/tqOffset.h b/source/dnode/vnode/src/inc/tqOffset.h deleted file mode 100644 index b58de26f68..0000000000 --- a/source/dnode/vnode/src/inc/tqOffset.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_TQ_OFFSET_H_ -#define _TD_TQ_OFFSET_H_ - -#include "tqInt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct STqOffsetCfg STqOffsetCfg; -typedef struct STqOffsetStore STqOffsetStore; - -STqOffsetStore* STqOffsetOpen(STqOffsetCfg*); -void STqOffsetClose(STqOffsetStore*); - -int64_t tqOffsetFetch(STqOffsetStore* pStore, const char* subscribeKey); -int32_t tqOffsetCommit(STqOffsetStore* pStore, const char* subscribeKey, int64_t offset); -int32_t tqOffsetPersist(STqOffsetStore* pStore, const char* subscribeKey); -int32_t tqOffsetPersistAll(STqOffsetStore* pStore); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_TQ_OFFSET_H_*/ diff --git a/source/dnode/vnode/src/inc/tqPush.h b/source/dnode/vnode/src/inc/tqPush.h deleted file mode 100644 index a6121c5dc1..0000000000 --- a/source/dnode/vnode/src/inc/tqPush.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TQ_PUSH_H_ -#define _TQ_PUSH_H_ - -#include "executor.h" -#include "thash.h" -#include "trpc.h" -#include "ttimer.h" -#include "vnode.h" - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - TQ_PUSHER_TYPE__CLIENT = 1, - TQ_PUSHER_TYPE__STREAM, -}; - -typedef struct { - int8_t type; - int8_t reserved[3]; - int32_t ttl; - int64_t consumerId; - SRpcMsg* pMsg; - // SMqPollRsp* rsp; -} STqClientPusher; - -typedef struct { - int8_t type; - int8_t nodeType; - int8_t reserved[6]; - int64_t streamId; - qTaskInfo_t task; - // TODO sync function -} STqStreamPusher; - -typedef struct { - int8_t type; // mq or stream -} STqPusher; - -typedef struct { - SHashObj* pHash; // -} STqPushMgr; - -typedef struct { - int8_t inited; - tmr_h timer; -} STqPushMgmt; - -static STqPushMgmt tqPushMgmt; - -int32_t tqPushMgrInit(); -void tqPushMgrCleanUp(); - -STqPushMgr* tqPushMgrOpen(); -void tqPushMgrClose(STqPushMgr* pushMgr); - -STqClientPusher* tqAddClientPusher(STqPushMgr* pushMgr, SRpcMsg* pMsg, int64_t consumerId, int64_t ttl); -STqStreamPusher* tqAddStreamPusher(STqPushMgr* pushMgr, int64_t streamId, SEpSet* pEpSet); - -#ifdef __cplusplus -} -#endif - -#endif /*_TQ_PUSH_H_*/ diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 2242f6803f..6e1f00f931 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -16,21 +16,23 @@ #ifndef _TD_VNODE_DEF_H_ #define _TD_VNODE_DEF_H_ -#include "tmallocator.h" +#include "executor.h" +#include "tchecksum.h" #include "tcoding.h" +#include "tcompression.h" #include "tdatablock.h" #include "tfs.h" +#include "tglobal.h" #include "tlist.h" #include "tlockfree.h" #include "tmacro.h" -#include "vnode.h" -#include "vnodeQuery.h" -#include "wal.h" +#include "tmallocator.h" #include "tskiplist.h" -#include "tchecksum.h" -#include "tglobal.h" #include "ttime.h" -#include "tcompression.h" +#include "ttimer.h" +#include "vnode.h" +#include "wal.h" +#include "qworker.h" #ifdef __cplusplus extern "C" { @@ -38,8 +40,9 @@ extern "C" { typedef struct STQ STQ; -typedef struct SVState SVState; -typedef struct SVBufPool SVBufPool; +typedef struct SVState SVState; +typedef struct SVBufPool SVBufPool; +typedef struct SQWorkerMgmt SQHandle; typedef struct SVnodeTask { TD_DLIST_NODE(SVnodeTask); @@ -99,7 +102,9 @@ struct SVnode { STfs* pTfs; }; -int vnodeScheduleTask(SVnodeTask* task); +int vnodeScheduleTask(SVnodeTask* task); +int vnodeQueryOpen(SVnode* pVnode); +void vnodeQueryClose(SVnode* pVnode); #define vFatal(...) \ do { \ diff --git a/source/dnode/vnode/src/inc/vnodeQuery.h b/source/dnode/vnode/src/inc/vnodeQuery.h deleted file mode 100644 index 7816b4eb46..0000000000 --- a/source/dnode/vnode/src/inc/vnodeQuery.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_VNODE_READ_H_ -#define _TD_VNODE_READ_H_ - -#ifdef __cplusplus -extern "C" { -#endif -#include "qworker.h" -#include "vnode.h" - - -typedef struct SQWorkerMgmt SQHandle; - -int vnodeQueryOpen(SVnode *pVnode); -void vnodeQueryClose(SVnode *pVnode); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_VNODE_READ_H_*/ diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 70d6dba36f..28d71fb842 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -15,9 +15,8 @@ #include "tcompare.h" #include "tdatablock.h" -#include "tqInt.h" -#include "tqMetaStore.h" #include "tstream.h" +#include "vnodeInt.h" int32_t tqInit() { return tqPushMgrInit(); } @@ -272,7 +271,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { fetchOffset = pReq->currentOffset + 1; } - vDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld", consumerId, pReq->epoch, pTq->pVnode->vgId, pReq->currentOffset, fetchOffset); + vDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld", consumerId, pReq->epoch, + pTq->pVnode->vgId, pReq->currentOffset, fetchOffset); SMqPollRsp rsp = { /*.consumerId = consumerId,*/ @@ -296,10 +296,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } STqTopic* pTopic = NULL; - int sz = taosArrayGetSize(pConsumer->topics); + int sz = taosArrayGetSize(pConsumer->topics); for (int32_t i = 0; i < sz; i++) { STqTopic* topic = taosArrayGet(pConsumer->topics, i); - //TODO race condition + // TODO race condition ASSERT(pConsumer->consumerId == consumerId); if (strcmp(topic->topicName, pReq->topic) == 0) { pTopic = topic; @@ -307,7 +307,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } } if (pTopic == NULL) { - vWarn("tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d", consumerId, pReq->epoch, pReq->topic, pTq->pVnode->vgId); + vWarn("tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d", consumerId, pReq->epoch, pReq->topic, + pTq->pVnode->vgId); pMsg->pCont = NULL; pMsg->contLen = 0; pMsg->code = -1; @@ -322,10 +323,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { while (1) { /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/ - //TODO + // TODO consumerEpoch = atomic_load_32(&pConsumer->epoch); if (consumerEpoch > pReq->epoch) { - //TODO: return + // TODO: return break; } SWalReadHead* pHead; @@ -333,10 +334,12 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { // TODO: no more log, set timer to wait blocking time // if data inserted during waiting, launch query and // response to user - vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset); + vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", consumerId, pReq->epoch, + pTq->pVnode->vgId, fetchOffset); break; } - vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset, pHead->msgType); + vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch, + pTq->pVnode->vgId, fetchOffset, pHead->msgType); /*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/ /*pHead = pTopic->pReadhandle->pHead;*/ if (pHead->msgType == TDMT_VND_SUBMIT) { @@ -360,7 +363,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { } if (taosArrayGetSize(pRes) == 0) { - vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset); + vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId, + pReq->epoch, pTq->pVnode->vgId, fetchOffset); fetchOffset++; rsp.skipLogNum++; taosArrayDestroy(pRes); @@ -389,7 +393,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { pMsg->pCont = buf; pMsg->contLen = tlen; pMsg->code = 0; - vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", pTq->pVnode->vgId, fetchOffset, pHead->msgType, consumerId, pReq->epoch); + vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", pTq->pVnode->vgId, fetchOffset, + pHead->msgType, consumerId, pReq->epoch); tmsgSendRsp(pMsg); taosMemoryFree(pHead); return 0; @@ -420,7 +425,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { pMsg->contLen = tlen; pMsg->code = 0; tmsgSendRsp(pMsg); - vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", pTq->pVnode->vgId, fetchOffset, consumerId, pReq->epoch); + vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", pTq->pVnode->vgId, fetchOffset, consumerId, + pReq->epoch); /*}*/ return 0; @@ -431,7 +437,7 @@ int32_t tqProcessRebReq(STQ* pTq, char* msg) { terrno = TSDB_CODE_SUCCESS; tDecodeSMqMVRebReq(msg, &req); - vDebug("vg %d set from consumer %ld to consumer %ld", req.vgId, req.oldConsumerId ,req.newConsumerId); + vDebug("vg %d set from consumer %ld to consumer %ld", req.vgId, req.oldConsumerId, req.newConsumerId); STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, req.oldConsumerId); ASSERT(pConsumer); ASSERT(pConsumer->consumerId == req.oldConsumerId); diff --git a/source/dnode/vnode/src/tq/tqMetaStore.c b/source/dnode/vnode/src/tq/tqMetaStore.c index 505687755d..beb19f48f1 100644 --- a/source/dnode/vnode/src/tq/tqMetaStore.c +++ b/source/dnode/vnode/src/tq/tqMetaStore.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "tqMetaStore.h" +#include "vnodeInt.h" // TODO:replace by an abstract file layer #include #include diff --git a/source/dnode/vnode/src/tq/tqOffset.c b/source/dnode/vnode/src/tq/tqOffset.c index 20270950cd..3cff87340d 100644 --- a/source/dnode/vnode/src/tq/tqOffset.c +++ b/source/dnode/vnode/src/tq/tqOffset.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "tqOffset.h" +#include "vnodeInt.h" enum ETqOffsetPersist { TQ_OFFSET_PERSIST__LAZY = 1, @@ -39,4 +39,3 @@ STqOffsetStore* STqOffsetOpen(STqOffsetCfg* pCfg) { pStore->pHash = taosHashInit(64, MurmurHash3_32, true, HASH_NO_LOCK); return pStore; } - diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c index 7851c071c3..4384255f89 100644 --- a/source/dnode/vnode/src/tq/tqPush.c +++ b/source/dnode/vnode/src/tq/tqPush.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tqPush.h" +#include "vnodeInt.h" int32_t tqPushMgrInit() { // diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 0590bd4321..f56ded9f15 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -13,7 +13,6 @@ * along with this program. If not, see . */ -#include "vnodeQuery.h" #include "executor.h" #include "vnodeInt.h" From 9f4744c6f3d7897d947d482fc8249e228c27a869 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 8 Apr 2022 16:05:30 +0800 Subject: [PATCH 18/19] feature/qnode --- include/common/tmsg.h | 37 +++++++++ include/common/tmsgdef.h | 1 + include/libs/catalog/catalog.h | 4 + source/common/src/tmsg.c | 92 +++++++++++++++++++++ source/dnode/mgmt/mm/mmHandle.c | 1 + source/dnode/mnode/impl/inc/mndDef.h | 2 + source/dnode/mnode/impl/src/mndDb.c | 90 ++++++++++++++++++++ source/dnode/mnode/impl/src/mndInfoSchema.c | 6 +- source/libs/catalog/src/catalog.c | 48 ++++++++++- source/libs/parser/src/parTranslater.c | 2 + source/libs/qcom/src/querymsg.c | 40 ++++++++- source/libs/scheduler/src/scheduler.c | 6 +- 12 files changed, 322 insertions(+), 7 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 61da9cb213..4efb68d490 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -512,6 +512,7 @@ typedef struct { int32_t maxRows; int32_t commitTime; int32_t fsyncPeriod; + int32_t ttl; int8_t walLevel; int8_t precision; // time resolution int8_t compression; @@ -521,6 +522,7 @@ typedef struct { int8_t cacheLastRow; int8_t ignoreExist; int8_t streamMode; + int8_t singleSTable; int32_t numOfRetensions; SArray* pRetensions; // SRetention } SCreateDbReq; @@ -586,6 +588,41 @@ int32_t tSerializeSUseDbRspImp(SCoder* pEncoder, const SUseDbRsp* pRsp); int32_t tDeserializeSUseDbRspImp(SCoder* pDecoder, SUseDbRsp* pRsp); void tFreeSUsedbRsp(SUseDbRsp* pRsp); +typedef struct { + char db[TSDB_DB_FNAME_LEN]; +} SDbCfgReq; + +int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq); +int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq); + +typedef struct { + int32_t numOfVgroups; + int32_t cacheBlockSize; + int32_t totalBlocks; + int32_t daysPerFile; + int32_t daysToKeep0; + int32_t daysToKeep1; + int32_t daysToKeep2; + int32_t minRows; + int32_t maxRows; + int32_t commitTime; + int32_t fsyncPeriod; + int32_t ttl; + int8_t walLevel; + int8_t precision; + int8_t compression; + int8_t replications; + int8_t quorum; + int8_t update; + int8_t cacheLastRow; + int8_t streamMode; + int8_t singleSTable; +} SDbCfgRsp; + +int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp); +int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp); + + typedef struct { int32_t rowNum; } SQnodeListReq; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 31ca2ac215..63d1fc5014 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -155,6 +155,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STREAM, "mnode-create-stream", SCMCreateStreamReq, SCMCreateStreamRsp) TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STREAM, "mnode-alter-stream", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_DROP_STREAM, "mnode-drop-stream", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_GET_DB_CFG, "mnode-get-db-cfg", NULL, NULL) // Requests handled by VNODE TD_NEW_MSG_SEG(TDMT_VND_MSG) diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 9f0d4b11c2..a0b342fca2 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -77,6 +77,8 @@ typedef struct SDbVgVersion { int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT } SDbVgVersion; +typedef SDbCfgRsp SDbCfgInfo; + int32_t catalogInit(SCatalogCfg *cfg); /** @@ -217,6 +219,8 @@ int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableMetaVersion **stable int32_t catalogGetExpiredDBs(SCatalog* pCatalog, SDbVgVersion **dbs, uint32_t *num); +int32_t catalogGetDBCfg(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SDbCfgInfo* pDbCfg); + /** * Destroy catalog and relase all resources diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index acb77648ae..57a8953253 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1515,6 +1515,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { if (tEncodeI32(&encoder, pReq->maxRows) < 0) return -1; if (tEncodeI32(&encoder, pReq->commitTime) < 0) return -1; if (tEncodeI32(&encoder, pReq->fsyncPeriod) < 0) return -1; + if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1; if (tEncodeI8(&encoder, pReq->walLevel) < 0) return -1; if (tEncodeI8(&encoder, pReq->precision) < 0) return -1; if (tEncodeI8(&encoder, pReq->compression) < 0) return -1; @@ -1524,6 +1525,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1; if (tEncodeI8(&encoder, pReq->ignoreExist) < 0) return -1; if (tEncodeI8(&encoder, pReq->streamMode) < 0) return -1; + if (tEncodeI8(&encoder, pReq->singleSTable) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfRetensions) < 0) return -1; for (int32_t i = 0; i < pReq->numOfRetensions; ++i) { SRetention *pRetension = taosArrayGet(pReq->pRetensions, i); @@ -1556,6 +1558,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) if (tDecodeI32(&decoder, &pReq->maxRows) < 0) return -1; if (tDecodeI32(&decoder, &pReq->commitTime) < 0) return -1; if (tDecodeI32(&decoder, &pReq->fsyncPeriod) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1; if (tDecodeI8(&decoder, &pReq->walLevel) < 0) return -1; if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1; if (tDecodeI8(&decoder, &pReq->compression) < 0) return -1; @@ -1565,6 +1568,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1; if (tDecodeI8(&decoder, &pReq->ignoreExist) < 0) return -1; if (tDecodeI8(&decoder, &pReq->streamMode) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->singleSTable) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1; pReq->pRetensions = taosArrayInit(pReq->numOfRetensions, sizeof(SRetention)); if (pReq->pRetensions == NULL) { @@ -1942,6 +1946,94 @@ void tFreeSUseDbBatchRsp(SUseDbBatchRsp *pRsp) { taosArrayDestroy(pRsp->pArray); } +int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->numOfVgroups) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->cacheBlockSize) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->totalBlocks) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->daysPerFile) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->daysToKeep0) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->daysToKeep1) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->daysToKeep2) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->minRows) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->maxRows) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->commitTime) < 0) return -1; + if (tEncodeI32(&encoder, pRsp->fsyncPeriod) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->walLevel) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->precision) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->compression) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->replications) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->quorum) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->update) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->cacheLastRow) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->streamMode) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->numOfVgroups) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->cacheBlockSize) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->totalBlocks) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->daysPerFile) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->daysToKeep0) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->daysToKeep1) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->daysToKeep2) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->minRows) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->maxRows) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->commitTime) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->fsyncPeriod) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->walLevel) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->precision) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->compression) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->replications) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->quorum) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->update) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->cacheLastRow) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->streamMode) < 0) return -1; + + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + + int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c index dc7725dcd2..e5495c7e1d 100644 --- a/source/dnode/mgmt/mm/mmHandle.c +++ b/source/dnode/mgmt/mm/mmHandle.c @@ -146,6 +146,7 @@ void mmInitMsgHandle(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE); // Requests handled by VNODE dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 38ef1185e8..38dbdc4799 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -260,6 +260,7 @@ typedef struct { int32_t maxRows; int32_t commitTime; int32_t fsyncPeriod; + int32_t ttl; int8_t walLevel; int8_t precision; int8_t compression; @@ -268,6 +269,7 @@ typedef struct { int8_t update; int8_t cacheLastRow; int8_t streamMode; + int8_t singleSTable; int32_t numOfRetensions; SArray* pRetensions; } SDbCfg; diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 44c547bec3..ff2ea162fb 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -40,6 +40,7 @@ static int32_t mndProcessCompactDbReq(SNodeMsg *pReq); static int32_t mndGetDbMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextDb(SMnode *pMnode, void *pIter); +static int32_t mndProcessGetDbCfgReq(SNodeMsg *pReq); int32_t mndInitDb(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_DB, @@ -56,6 +57,7 @@ int32_t mndInitDb(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_USE_DB, mndProcessUseDbReq); mndSetMsgHandle(pMnode, TDMT_MND_SYNC_DB, mndProcessSyncDbReq); mndSetMsgHandle(pMnode, TDMT_MND_COMPACT_DB, mndProcessCompactDbReq); + mndSetMsgHandle(pMnode, TDMT_MND_GET_DB_CFG, mndProcessGetDbCfgReq); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_DB, mndGetDbMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DB, mndRetrieveDbs); @@ -268,6 +270,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->minRows > pCfg->maxRows) return -1; if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) return -1; if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) return -1; + if (pCfg->ttl < TSDB_MIN_DB_TTL_OPTION && pCfg->ttl != TSDB_DEFAULT_DB_TTL_OPTION) return -1; if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) return -1; if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) return -1; if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) return -1; @@ -278,6 +281,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) return -1; if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1; if (pCfg->streamMode < TSDB_MIN_DB_STREAM_MODE || pCfg->streamMode > TSDB_MAX_DB_STREAM_MODE) return -1; + if (pCfg->singleSTable < TSDB_MIN_DB_SINGLE_STABLE_OPTION || pCfg->streamMode > TSDB_MAX_DB_SINGLE_STABLE_OPTION) return -1; return TSDB_CODE_SUCCESS; } @@ -293,6 +297,7 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->maxRows < 0) pCfg->maxRows = TSDB_DEFAULT_MAX_ROW_FBLOCK; if (pCfg->commitTime < 0) pCfg->commitTime = TSDB_DEFAULT_COMMIT_TIME; if (pCfg->fsyncPeriod < 0) pCfg->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; + if (pCfg->ttl < 0) pCfg->ttl = TSDB_DEFAULT_DB_TTL_OPTION; if (pCfg->walLevel < 0) pCfg->walLevel = TSDB_DEFAULT_WAL_LEVEL; if (pCfg->precision < 0) pCfg->precision = TSDB_DEFAULT_PRECISION; if (pCfg->compression < 0) pCfg->compression = TSDB_DEFAULT_COMP_LEVEL; @@ -301,6 +306,7 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { if (pCfg->update < 0) pCfg->update = TSDB_DEFAULT_DB_UPDATE_OPTION; if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW; if (pCfg->streamMode < 0) pCfg->streamMode = TSDB_DEFAULT_DB_STREAM_MODE; + if (pCfg->singleSTable < 0) pCfg->singleSTable = TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION; if (pCfg->numOfRetensions < 0) pCfg->numOfRetensions = 0; } @@ -437,6 +443,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate .maxRows = pCreate->maxRows, .commitTime = pCreate->commitTime, .fsyncPeriod = pCreate->fsyncPeriod, + .ttl = pCreate->ttl, .walLevel = pCreate->walLevel, .precision = pCreate->precision, .compression = pCreate->compression, @@ -445,6 +452,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SNodeMsg *pReq, SCreateDbReq *pCreate .update = pCreate->update, .cacheLastRow = pCreate->cacheLastRow, .streamMode = pCreate->streamMode, + .singleSTable = pCreate->singleSTable, }; dbObj.cfg.numOfRetensions = pCreate->numOfRetensions; @@ -730,6 +738,71 @@ ALTER_DB_OVER: return code; } +static int32_t mndProcessGetDbCfgReq(SNodeMsg *pReq) { + SMnode *pMnode = pReq->pNode; + int32_t code = -1; + SDbObj *pDb = NULL; + SDbCfgReq cfgReq = {0}; + SDbCfgRsp cfgRsp = {0}; + + if (tDeserializeSDbCfgReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &cfgReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + goto GET_DB_CFG_OVER; + } + + pDb = mndAcquireDb(pMnode, cfgReq.db); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_EXIST; + goto GET_DB_CFG_OVER; + } + + cfgRsp.numOfVgroups = pDb->cfg.numOfVgroups; + cfgRsp.cacheBlockSize = pDb->cfg.cacheBlockSize; + cfgRsp.totalBlocks = pDb->cfg.totalBlocks; + cfgRsp.daysPerFile = pDb->cfg.daysPerFile; + cfgRsp.daysToKeep0 = pDb->cfg.daysToKeep0; + cfgRsp.daysToKeep1 = pDb->cfg.daysToKeep1; + cfgRsp.daysToKeep2 = pDb->cfg.daysToKeep2; + cfgRsp.minRows = pDb->cfg.minRows; + cfgRsp.maxRows = pDb->cfg.maxRows; + cfgRsp.commitTime = pDb->cfg.commitTime; + cfgRsp.fsyncPeriod = pDb->cfg.fsyncPeriod; + cfgRsp.ttl = pDb->cfg.ttl; + cfgRsp.walLevel = pDb->cfg.walLevel; + cfgRsp.precision = pDb->cfg.precision; + cfgRsp.compression = pDb->cfg.compression; + cfgRsp.replications = pDb->cfg.replications; + cfgRsp.quorum = pDb->cfg.quorum; + cfgRsp.update = pDb->cfg.update; + cfgRsp.cacheLastRow = pDb->cfg.cacheLastRow; + cfgRsp.streamMode = pDb->cfg.streamMode; + cfgRsp.singleSTable = pDb->cfg.singleSTable; + + int32_t contLen = tSerializeSDbCfgRsp(NULL, 0, &cfgRsp); + void *pRsp = rpcMallocCont(contLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + code = -1; + goto GET_DB_CFG_OVER; + } + + tSerializeSDbCfgRsp(pRsp, contLen, &cfgRsp); + + pReq->pRsp = pRsp; + pReq->rspLen = contLen; + +GET_DB_CFG_OVER: + + if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + mError("db:%s, failed to get cfg since %s", cfgReq.db, terrstr()); + } + + mndReleaseDb(pMnode, pDb); + + return code; +} + + static int32_t mndSetDropDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { SSdbRaw *pRedoRaw = mndDbActionEncode(pDb); if (pRedoRaw == NULL) return -1; @@ -1509,6 +1582,23 @@ static void dumpDbInfoToPayload(char *data, SDbObj *pDb, SShowObj *pShow, int32_ STR_WITH_SIZE_TO_VARSTR(pWrite, prec, 2); cols++; + pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + *(int32_t *)pWrite = pDb->cfg.ttl; + cols++; + + pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + *(int8_t *)pWrite = pDb->cfg.singleSTable; + cols++; + + pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + *(int8_t *)pWrite = pDb->cfg.streamMode; + cols++; + + pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + char *status = "ready"; + STR_WITH_SIZE_TO_VARSTR(pWrite, status, strlen(status)); + cols++; + // pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); // *(int8_t *)pWrite = pDb->cfg.update; } diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index 92b854157b..aadd914439 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -63,7 +63,11 @@ static const SInfosTableSchema userDBSchema[] = { {.name = "fsync", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, {.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "precision", .bytes = 3 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "precision", .bytes = 2 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "single_stable", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "stream_mode", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, // {.name = "update", .bytes = 1, .type = // TSDB_DATA_TYPE_TINYINT}, // disable update }; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index e1f5332899..6ed09ce7eb 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -569,6 +569,44 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtE return TSDB_CODE_SUCCESS; } +int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char *dbFName, SDbCfgInfo *out) { + char *msg = NULL; + int32_t msgLen = 0; + + ctgDebug("try to get db cfg from mnode, dbFName:%s", dbFName); + + int32_t code = queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)]((void *)dbFName, &msg, 0, &msgLen); + if (code) { + ctgError("Build get db cfg msg failed, code:%x, db:%s", code, dbFName); + CTG_ERR_RET(code); + } + + SRpcMsg rpcMsg = { + .msgType = TDMT_MND_GET_DB_CFG, + .pCont = msg, + .contLen = msgLen, + }; + + SRpcMsg rpcRsp = {0}; + + rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp); + if (TSDB_CODE_SUCCESS != rpcRsp.code) { + ctgError("error rsp for get db cfg, error:%s, db:%s", tstrerror(rpcRsp.code), dbFName); + CTG_ERR_RET(rpcRsp.code); + } + + code = queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)](out, rpcRsp.pCont, rpcRsp.contLen); + if (code) { + ctgError("Process get db cfg rsp failed, code:%x, db:%s", code, dbFName); + CTG_ERR_RET(code); + } + + ctgDebug("Got db cfg from mnode, dbFName:%s", dbFName); + + return TSDB_CODE_SUCCESS; +} + + int32_t ctgIsTableMetaExistInCache(SCatalog* pCtg, char *dbFName, char* tbName, int32_t *exist) { if (NULL == pCtg->dbCache) { *exist = 0; @@ -2137,7 +2175,6 @@ _return: CTG_RET(code); } - int32_t catalogInit(SCatalogCfg *cfg) { if (gCtgMgmt.pCluster) { qError("catalog already initialized"); @@ -2717,6 +2754,15 @@ int32_t catalogGetExpiredDBs(SCatalog* pCtg, SDbVgVersion **dbs, uint32_t *num) CTG_API_LEAVE(ctgMetaRentGet(&pCtg->dbRent, (void **)dbs, num, sizeof(SDbVgVersion))); } +int32_t catalogGetDBCfg(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SDbCfgInfo* pDbCfg) { + CTG_API_ENTER(); + + if (NULL == pCtg || NULL == pRpc || NULL == pMgmtEps || NULL == dbFName || NULL == pDbCfg) { + CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); + } + + CTG_API_LEAVE(ctgGetDBCfgFromMnode(pCtg, pRpc, pMgmtEps, dbFName, pDbCfg)); +} void catalogDestroy(void) { qInfo("start to destroy catalog"); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 3491974eab..8b3bf5b492 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -984,6 +984,8 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS pReq->cacheLastRow = GET_OPTION_VAL(pStmt->pOptions->pCachelast, TSDB_DEFAULT_CACHE_LAST_ROW); pReq->ignoreExist = pStmt->ignoreExists; pReq->streamMode = GET_OPTION_VAL(pStmt->pOptions->pStreamMode, TSDB_DEFAULT_DB_STREAM_MODE_OPTION); + pReq->ttl = GET_OPTION_VAL(pStmt->pOptions->pTtl, TSDB_DEFAULT_DB_TTL_OPTION); + pReq->singleSTable = GET_OPTION_VAL(pStmt->pOptions->pSingleStable, TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION); return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq); } diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 1e91c55dc0..d211e780b0 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -121,6 +121,23 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } +int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) { + if (NULL == msg || NULL == msgLen) { + return TSDB_CODE_TSC_INVALID_INPUT; + } + + SDbCfgReq dbCfgReq = {0}; + strcpy(dbCfgReq.db, input); + + int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq); + void *pBuf = rpcMallocCont(bufLen); + tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq); + + *msg = pBuf; + *msgLen = bufLen; + + return TSDB_CODE_SUCCESS; +} int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) { SUseDbOutput *pOut = output; @@ -309,17 +326,36 @@ PROCESS_QLIST_OVER: return code; } +int32_t queryProcessGetDbCfgRsp(void *output, char *msg, int32_t msgSize) { + SDbCfgRsp out = {0}; + + if (NULL == output || NULL == msg || msgSize <= 0) { + return TSDB_CODE_TSC_INVALID_INPUT; + } + + if (tDeserializeSDbCfgRsp(msg, msgSize, &out) != 0) { + qError("tDeserializeSDbCfgRsp failed, msgSize:%d", msgSize); + return TSDB_CODE_INVALID_MSG; + } + + memcpy(output, &out, sizeof(out)); + + return TSDB_CODE_SUCCESS; +} + void initQueryModuleMsgHandle() { queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg; - queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg; + queryBuildMsg[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryBuildGetDBCfgMsg; queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp; - queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_GET_DB_CFG)] = queryProcessGetDbCfgRsp; } #pragma GCC diagnostic pop diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index d1352bac24..5fb6069eff 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -1251,8 +1251,8 @@ int32_t schGetTaskFromTaskList(SHashObj *pTaskList, uint64_t taskId, SSchTask ** return TSDB_CODE_SUCCESS; } -int32_t schUpdateTaskExecNodeHandle(SSchTask *pTask, void *handle) { - if (NULL == pTask->execNodes || taosArrayGetSize(pTask->execNodes) > 1 || taosArrayGetSize(pTask->execNodes) <= 0) { +int32_t schUpdateTaskExecNodeHandle(SSchTask *pTask, void *handle, int32_t rspCode) { + if (rspCode || NULL == pTask->execNodes || taosArrayGetSize(pTask->execNodes) > 1 || taosArrayGetSize(pTask->execNodes) <= 0) { return TSDB_CODE_SUCCESS; } @@ -1293,7 +1293,7 @@ int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, in SCH_TASK_DLOG("rsp msg received, type:%s, handle:%p, code:%s", TMSG_INFO(msgType), pMsg->handle, tstrerror(rspCode)); SCH_SET_TASK_HANDLE(pTask, pMsg->handle); - schUpdateTaskExecNodeHandle(pTask, pMsg->handle); + schUpdateTaskExecNodeHandle(pTask, pMsg->handle, rspCode); SCH_ERR_JRET(schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode)); _return: From 70797ef81609829a9c9e233935caf466cc435bc2 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Fri, 8 Apr 2022 17:35:44 +0800 Subject: [PATCH 19/19] [test] --- .../script/tsim/query/charScalarFunction.sim | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index d7b1139b5b..13108fecb7 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -286,25 +286,25 @@ endi #sql_error select c1, ltrim(t1), c2, ltrim(t2) from ctb3 -#print ====> rtrim -#sql select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ntb3 -#print ====> select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ctb3 -#sql select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ctb3 -#print ====> rows: $rows -#print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] -#print ====> $data10 $data11 $data12 $data13 $data14 $data15 -#if $rows != 1 then -# return -1 -#endi -#if $data01 != @ abcd 1234@ then -# return -1 -#endi -#if $data03 != @ abcd 1234@ then -# return -1 -#endi -#if $data04 != @ abcdEFGH =-*&%@ then -# return -1 -#endi +print ====> rtrim +sql select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ntb3 +print ====> select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ctb3 +sql select c1, rtrim(c1), c2, rtrim(c2), rtrim(" abcdEFGH =-*&% ") from ctb3 +print ====> rows: $rows +print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 1 then + return -1 +endi +if $data01 != @ abcd 1234@ then + return -1 +endi +if $data03 != @ abcd 1234@ then + return -1 +endi +if $data04 != @ abcdEFGH =-*&%@ then + return -1 +endi #sql_error select c1, rtrim(t1), c2, rtrim(t2) from ctb3