From 878e54f143d1c20aa28ea3b360b35050f780ed55 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 31 Mar 2022 22:23:12 +0800 Subject: [PATCH 01/57] fix test error --- source/libs/executor/src/tsort.c | 1 + source/libs/executor/test/sortTests.cpp | 13 +++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 7a57d62969..414f3ded6e 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -266,6 +266,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa pSource->src.rowIndex = 0; if (pHandle->type == SORT_SINGLESOURCE_SORT) { + pSource->pageIndex ++; if (pSource->pageIndex >= taosArrayGetSize(pSource->pageIdList)) { (*numOfCompleted) += 1; pSource->src.rowIndex = -1; diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index ecea24135f..5a7edd816b 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -150,7 +150,7 @@ int32_t docomp(const void* p1, const void* p2, void* param) { } } // namespace -#if 0 +#if 1 TEST(testCase, inMem_sort_Test) { SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SOrder o = {.order = TSDB_ORDER_ASC}; @@ -187,20 +187,13 @@ TEST(testCase, inMem_sort_Test) { } TEST(testCase, external_mem_sort_Test) { - SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); - SOrder o = {.order = TSDB_ORDER_ASC}; - o.col.info.colId = 1; - o.col.info.type = TSDB_DATA_TYPE_INT; - taosArrayPush(pOrderVal, &o); - SBlockOrderInfo oi = {0}; oi.order = TSDB_ORDER_ASC; - oi.colIndex = 0; + oi.slotId = 0; SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSchema s = {.type = TSDB_DATA_TYPE_INT, .colId = 1, .bytes = 4, }; - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, false, SORT_SINGLESOURCE_SORT, 1024, 5, &s, 1, "test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 1024, 5, &s, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); _info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info)); From 69a5e55a24a7b8429a2fe3984ea7eee10c5278a1 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 1 Apr 2022 10:05:16 +0800 Subject: [PATCH 02/57] [TD-14422] fix error in sort logic & add test case --- source/common/src/tdatablock.c | 3 ++ source/libs/executor/src/tsort.c | 5 ++- source/libs/executor/test/sortTests.cpp | 51 ++++++++++++------------- source/util/src/tpagedbuf.c | 7 ++-- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 7f25fd1e80..f22051f1c6 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1201,6 +1201,9 @@ void* blockDataDestroy(SSDataBlock* pBlock) { } SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) { + if(pDataBlock == NULL){ + return NULL; + } int32_t numOfCols = pDataBlock->info.numOfCols; SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 414f3ded6e..0d69ed711c 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -148,7 +148,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { int32_t start = 0; if (pHandle->pBuf == NULL) { - int32_t code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, 0, "/tmp"); + int32_t code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, "doAddToBuf", "/tmp"); dBufSetPrintInfo(pHandle->pBuf); if (code != TSDB_CODE_SUCCESS) { return code; @@ -212,7 +212,7 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int } else { // multi-pass internal merge sort is required if (pHandle->pBuf == NULL) { - code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, 0, "/tmp"); + code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, "sortComparInit", "/tmp"); dBufSetPrintInfo(pHandle->pBuf); if (code != TSDB_CODE_SUCCESS) { return code; @@ -411,6 +411,7 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { assert(0); } } + return 0; } static int32_t doInternalMergeSort(SSortHandle* pHandle) { diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 5a7edd816b..1b64182266 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -152,23 +152,24 @@ int32_t docomp(const void* p1, const void* p2, void* param) { #if 1 TEST(testCase, inMem_sort_Test) { - SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); - SOrder o = {.order = TSDB_ORDER_ASC}; - o.col.info.colId = 1; - o.col.info.type = TSDB_DATA_TYPE_INT; - taosArrayPush(pOrderVal, &o); - - int32_t numOfRows = 1000; SBlockOrderInfo oi = {0}; oi.order = TSDB_ORDER_ASC; - oi.colIndex = 0; + oi.slotId = 0; SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); SSchema s = {.type = TSDB_DATA_TYPE_INT, .colId = 1, .bytes = 4, }; - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, false, SORT_SINGLESOURCE_SORT, 1024, 5, &s, 1, "test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 1024, 5, NULL, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); - tsortAddSource(phandle, &numOfRows); + + _info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info)); + pInfo->startVal = 0; + pInfo->pageRows = 100; + pInfo->count = 6; + + SGenericSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); + ps->param = pInfo; + tsortAddSource(phandle, ps); int32_t code = tsortOpen(phandle); int32_t row = 1; @@ -180,7 +181,8 @@ TEST(testCase, inMem_sort_Test) { } void* v = tsortGetValue(pTupleHandle, 0); - printf("%d: %d\n", row++, *(int32_t*) v); + printf("%d: %d\n", row, *(int32_t*) v); + ASSERT_EQ(row++, *(int32_t*) v); } tsortDestroySortHandle(phandle); @@ -193,13 +195,13 @@ TEST(testCase, external_mem_sort_Test) { SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 1024, 5, &s, "test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 32, 6, NULL, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); _info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info)); - pInfo->startVal = 100000; - pInfo->pageRows = 1000; - pInfo->count = 50; + pInfo->startVal = 0; + pInfo->pageRows = 100; + pInfo->count = 6; SGenericSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); ps->param = pInfo; @@ -216,28 +218,22 @@ TEST(testCase, external_mem_sort_Test) { } void* v = tsortGetValue(pTupleHandle, 0); - printf("%d: %d\n", row++, *(int32_t*) v); + printf("%d: %d\n", row, *(int32_t*) v); + ASSERT_EQ(row++, *(int32_t*) v); } tsortDestroySortHandle(phandle); } TEST(testCase, ordered_merge_sort_Test) { - SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); - SOrder o = {.order = TSDB_ORDER_ASC}; - o.col.info.colId = 1; - o.col.info.type = TSDB_DATA_TYPE_INT; - taosArrayPush(pOrderVal, &o); - - int32_t numOfRows = 1000; SBlockOrderInfo oi = {0}; oi.order = TSDB_ORDER_ASC; - oi.colIndex = 0; + oi.slotId = 0; SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); SSchema s = {.type = TSDB_DATA_TYPE_INT, .colId = 1, .bytes = 4}; - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, false, SORT_MULTISOURCE_MERGE, 1024, 5, &s, 1,"test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_MULTISOURCE_MERGE, 1024, 5, NULL,"test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); tsortSetComparFp(phandle, docomp); @@ -246,7 +242,7 @@ TEST(testCase, ordered_merge_sort_Test) { _info* c = static_cast<_info*>(taosMemoryCalloc(1, sizeof(_info))); c->count = 1; c->pageRows = 1000; - c->startVal = 0; + c->startVal = i*1000; p->param = c; tsortAddSource(phandle, p); @@ -262,7 +258,8 @@ TEST(testCase, ordered_merge_sort_Test) { } void* v = tsortGetValue(pTupleHandle, 0); - printf("%d: %d\n", row++, *(int32_t*) v); + printf("%d: %d\n", row, *(int32_t*) v); + ASSERT_EQ(row++, *(int32_t*) v); } tsortDestroySortHandle(phandle); diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index d834263b94..096a16ec94 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -138,7 +138,7 @@ static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) { pBuf->nextPos += size; int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET); - if (ret != 0) { + if (ret == -1) { terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -169,7 +169,7 @@ static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) { // 3. write to disk. int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET); - if (ret != 0) { + if (ret == -1) { terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -224,7 +224,7 @@ static char* flushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) { // load file block data in disk static int32_t loadPageFromDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) { int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET); - if (ret != 0) { + if (ret == -1) { ret = TAOS_SYSTEM_ERROR(errno); return ret; } @@ -371,7 +371,6 @@ int32_t createDiskbasedBuf(SDiskbasedBuf** pBuf, int32_t pagesize, int32_t inMem pPBuf->totalBufSize = 0; pPBuf->inMemPages = inMemBufSize / pagesize; // maximum allowed pages, it is a soft limit. pPBuf->allocateId = -1; - pPBuf->comp = true; pPBuf->pFile = NULL; pPBuf->id = strdup(id); pPBuf->fileSize = 0; From 12c3a10a9bd06ba87cc0d523180a1d455bc87738 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 2 Apr 2022 14:29:43 +0800 Subject: [PATCH 03/57] fix error in order by logic & fix no return error --- cmake/cmake.define | 4 +- cmake/cmake.platform | 2 +- include/common/tdatablock.h | 12 ++--- source/common/src/tdatablock.c | 66 ++++++----------------- source/common/src/tmsg.c | 1 + source/dnode/mgmt/dm/src/dmMsg.c | 1 + source/dnode/mgmt/dm/src/dmWorker.c | 1 + source/dnode/mgmt/main/src/dndTransport.c | 1 + source/dnode/mnode/impl/src/mndDnode.c | 1 + source/dnode/vnode/src/tsdb/tsdbSma.c | 5 ++ source/libs/catalog/src/catalog.c | 4 +- source/libs/executor/inc/executil.h | 4 +- source/libs/executor/src/dataDispatcher.c | 1 + source/libs/executor/src/executorimpl.c | 21 ++++++-- source/libs/executor/src/tlinearhash.c | 1 + source/libs/executor/src/tsimplehash.c | 1 + source/libs/executor/src/tsort.c | 63 ++++++++++------------ source/libs/executor/test/sortTests.cpp | 24 +++------ source/libs/index/src/indexFstRegex.c | 1 + source/libs/scalar/src/scalar.c | 1 - source/libs/scalar/src/sclfunc.c | 3 ++ source/libs/scalar/src/sclvector.c | 1 - source/libs/scheduler/src/scheduler.c | 6 ++- source/util/src/tcompare.c | 44 +++++---------- source/util/src/tpagedbuf.c | 3 +- 25 files changed, 116 insertions(+), 156 deletions(-) diff --git a/cmake/cmake.define b/cmake/cmake.define index 9c2d5dc04c..298d102b87 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -36,8 +36,8 @@ IF (TD_WINDOWS) ENDIF () ELSE () - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -g3") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -g3") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64") diff --git a/cmake/cmake.platform b/cmake/cmake.platform index dfb79c0fae..0312f92a5b 100644 --- a/cmake/cmake.platform +++ b/cmake/cmake.platform @@ -42,7 +42,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin SET(TD_DARWIN TRUE) SET(OSTYPE "macOS") - ADD_DEFINITIONS("-DDARWIN -Wno-tautological-pointer-compare -Wno-return-type") + ADD_DEFINITIONS("-DDARWIN -Wno-tautological-pointer-compare") MESSAGE("Current system processor is ${CMAKE_SYSTEM_PROCESSOR}.") IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 4bbe42bc50..3afdcfba8e 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -113,39 +113,39 @@ static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uin pColumnInfoData->hasNull = true; } -static FORCE_INLINE int32_t colDataAppendInt8(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int8_t* v) { +static FORCE_INLINE void colDataAppendInt8(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int8_t* v) { ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_TINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UTINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_BOOL); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(int8_t*)p = *(int8_t*)v; } -static FORCE_INLINE int32_t colDataAppendInt16(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int16_t* v) { +static FORCE_INLINE void colDataAppendInt16(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int16_t* v) { ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(int16_t*)p = *(int16_t*)v; } -static FORCE_INLINE int32_t colDataAppendInt32(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int32_t* v) { +static FORCE_INLINE void colDataAppendInt32(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int32_t* v) { ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_INT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UINT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(int32_t*)p = *(int32_t*)v; } -static FORCE_INLINE int32_t colDataAppendInt64(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int64_t* v) { +static FORCE_INLINE void colDataAppendInt64(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int64_t* v) { int32_t type = pColumnInfoData->info.type; ASSERT(type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT || type == TSDB_DATA_TYPE_TIMESTAMP); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(int64_t*)p = *(int64_t*)v; } -static FORCE_INLINE int32_t colDataAppendFloat(SColumnInfoData* pColumnInfoData, uint32_t currentRow, float* v) { +static FORCE_INLINE void colDataAppendFloat(SColumnInfoData* pColumnInfoData, uint32_t currentRow, float* v) { ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_FLOAT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(float*)p = *(float*)v; } -static FORCE_INLINE int32_t colDataAppendDouble(SColumnInfoData* pColumnInfoData, uint32_t currentRow, double* v) { +static FORCE_INLINE void colDataAppendDouble(SColumnInfoData* pColumnInfoData, uint32_t currentRow, double* v) { ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_DOUBLE); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(double*)p = *(double*)v; diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index f22051f1c6..67cc597fdf 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -17,6 +17,7 @@ #include "tdatablock.h" #include "tcompare.h" #include "tglobal.h" +#include "tlog.h" int32_t taosGetFqdnPortFromEp(const char* ep, SEp* pEp) { pEp->port = 0; @@ -424,7 +425,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd } size += sizeof(pColInfoData->varmeta.offset[0]); - } else { + } else { // this block is unreached, because hasVarCol = true size += pColInfoData->info.bytes; if (((j - startIndex) & 0x07) == 0) { @@ -665,23 +666,13 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) { void* left1 = colDataGetData(pColInfoData, left); void* right1 = colDataGetData(pColInfoData, right); - switch (pColInfoData->info.type) { - case TSDB_DATA_TYPE_INT: { - int32_t leftx = *(int32_t*)left1; - int32_t rightx = *(int32_t*)right1; + __compar_fn_t fn = getKeyComparFunc(pColInfoData->info.type, pOrder->order); - if (leftx == rightx) { - break; - } else { - if (pOrder->order == TSDB_ORDER_ASC) { - return (leftx < rightx) ? -1 : 1; - } else { - return (leftx < rightx) ? 1 : -1; - } - } - } - default: - assert(0); + int ret = fn(left1, right1); + if (ret == 0) { + continue; + } else { + return ret; } } @@ -834,17 +825,14 @@ static void copyBackToBlock(SSDataBlock* pDataBlock, SColumnInfoData* pCols) { if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { taosMemoryFreeClear(pColInfoData->varmeta.offset); - pColInfoData->varmeta = pCols[i].varmeta; } else { taosMemoryFreeClear(pColInfoData->nullbitmap); - pColInfoData->nullbitmap = pCols[i].nullbitmap; } taosMemoryFreeClear(pColInfoData->pData); - pColInfoData->pData = pCols[i].pData; } - taosMemoryFreeClear(pCols); + colDataDestroy(pCols); } static int32_t* createTupleIndex(size_t rows) { @@ -862,33 +850,6 @@ static int32_t* createTupleIndex(size_t rows) { static void destroyTupleIndex(int32_t* index) { taosMemoryFreeClear(index); } -static __compar_fn_t getComparFn(int32_t type, int32_t order) { - switch (type) { - case TSDB_DATA_TYPE_TINYINT: - return order == TSDB_ORDER_ASC ? compareInt8Val : compareInt8ValDesc; - case TSDB_DATA_TYPE_SMALLINT: - return order == TSDB_ORDER_ASC ? compareInt16Val : compareInt16ValDesc; - case TSDB_DATA_TYPE_INT: - return order == TSDB_ORDER_ASC ? compareInt32Val : compareInt32ValDesc; - case TSDB_DATA_TYPE_BIGINT: - return order == TSDB_ORDER_ASC ? compareInt64Val : compareInt64ValDesc; - case TSDB_DATA_TYPE_FLOAT: - return order == TSDB_ORDER_ASC ? compareFloatVal : compareFloatValDesc; - case TSDB_DATA_TYPE_DOUBLE: - return order == TSDB_ORDER_ASC ? compareDoubleVal : compareDoubleValDesc; - case TSDB_DATA_TYPE_UTINYINT: - return order == TSDB_ORDER_ASC ? compareUint8Val : compareUint8ValDesc; - case TSDB_DATA_TYPE_USMALLINT: - return order == TSDB_ORDER_ASC ? compareUint16Val : compareUint16ValDesc; - case TSDB_DATA_TYPE_UINT: - return order == TSDB_ORDER_ASC ? compareUint32Val : compareUint32ValDesc; - case TSDB_DATA_TYPE_UBIGINT: - return order == TSDB_ORDER_ASC ? compareUint64Val : compareUint64ValDesc; - default: - return order == TSDB_ORDER_ASC ? compareInt32Val : compareInt32ValDesc; - } -} - int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { ASSERT(pDataBlock != NULL && pOrderInfo != NULL); if (pDataBlock->info.rows <= 1) { @@ -922,11 +883,11 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { int64_t p0 = taosGetTimestampUs(); - __compar_fn_t fn = getComparFn(pColInfoData->info.type, pOrder->order); + __compar_fn_t fn = getKeyComparFunc(pColInfoData->info.type, pOrder->order); qsort(pColInfoData->pData, pDataBlock->info.rows, pColInfoData->info.bytes, fn); int64_t p1 = taosGetTimestampUs(); - printf("sort:%" PRId64 ", rows:%d\n", p1 - p0, pDataBlock->info.rows); + uDebug("blockDataSort easy cost:%" PRId64 ", rows:%d\n", p1 - p0, pDataBlock->info.rows); return TSDB_CODE_SUCCESS; } else { // var data type @@ -955,6 +916,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { SColumnInfoData* pCols = createHelpColInfoData(pDataBlock); if (pCols == NULL) { + destroyTupleIndex(index); terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } @@ -963,6 +925,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { int32_t code = blockDataAssign(pCols, pDataBlock, index); if (code != TSDB_CODE_SUCCESS) { + destroyTupleIndex(index); terrno = code; return code; } @@ -972,7 +935,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { copyBackToBlock(pDataBlock, pCols); int64_t p4 = taosGetTimestampUs(); - printf("sort:%" PRId64 ", create:%" PRId64 ", assign:%" PRId64 ", copyback:%" PRId64 ", rows:%d\n", p1 - p0, p2 - p1, + uDebug("blockDataSort complex sort:%" PRId64 ", create:%" PRId64 ", assign:%" PRId64 ", copyback:%" PRId64 ", rows:%d\n", p1 - p0, p2 - p1, p3 - p2, p4 - p3, rows); destroyTupleIndex(index); @@ -1234,6 +1197,7 @@ void colDataDestroy(SColumnInfoData* pColData) { } taosMemoryFree(pColData->pData); + taosMemoryFree(pColData); } int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c85184ffba..7a9014dc43 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -2571,6 +2571,7 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq * int32_t tFreeSCreateVnodeReq(SCreateVnodeReq *pReq) { taosArrayDestroy(pReq->pRetensions); pReq->pRetensions = NULL; + return 0; } int32_t tSerializeSDropVnodeReq(void *buf, int32_t bufLen, SDropVnodeReq *pReq) { diff --git a/source/dnode/mgmt/dm/src/dmMsg.c b/source/dnode/mgmt/dm/src/dmMsg.c index b301ef478b..b08657d4dc 100644 --- a/source/dnode/mgmt/dm/src/dmMsg.c +++ b/source/dnode/mgmt/dm/src/dmMsg.c @@ -95,6 +95,7 @@ int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { } pMgmt->statusSent = 0; + return TSDB_CODE_SUCCESS; } int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { diff --git a/source/dnode/mgmt/dm/src/dmWorker.c b/source/dnode/mgmt/dm/src/dmWorker.c index 63b9704b78..ca86f42608 100644 --- a/source/dnode/mgmt/dm/src/dmWorker.c +++ b/source/dnode/mgmt/dm/src/dmWorker.c @@ -50,6 +50,7 @@ static void *dmThreadRoutine(void *param) { lastMonitorTime = curTime; } } + return TSDB_CODE_SUCCESS; } static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { diff --git a/source/dnode/mgmt/main/src/dndTransport.c b/source/dnode/mgmt/main/src/dndTransport.c index 07ea0309a8..6398af21dc 100644 --- a/source/dnode/mgmt/main/src/dndTransport.c +++ b/source/dnode/mgmt/main/src/dndTransport.c @@ -333,6 +333,7 @@ int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg taosMsleep(1); } } + return TSDB_CODE_SUCCESS; } int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pReq) { diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 314e70db9b..4149cb5602 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -630,6 +630,7 @@ static int32_t mndProcessConfigDnodeReq(SNodeMsg *pReq) { static int32_t mndProcessConfigDnodeRsp(SNodeMsg *pRsp) { mInfo("app:%p config rsp from dnode", pRsp->rpcMsg.ahandle); + return TSDB_CODE_SUCCESS; } static int32_t mndGetConfigMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index f04f4791b5..9cb444f667 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -331,6 +331,7 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) { } taosHashCleanup(pSmaStat->smaStatItems); } + return TSDB_CODE_SUCCESS; } static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { @@ -433,6 +434,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t return TSDB_CODE_FAILED; } tsdbDebug("vgId:%d smaIndex %" PRIi64 " tsKey %" PRIi64 " is put to hash", REPO_ID(pTsdb), indexUid, winSKey); + return TSDB_CODE_SUCCESS; } /** @@ -1051,6 +1053,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) { } // clear sma data files // TODO: + return TSDB_CODE_SUCCESS; } static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, int32_t fid) { @@ -1173,6 +1176,7 @@ static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interv pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision, true); pSmaH->storageLevel = tsdbGetSmaStorageLevel(interval, intervalUnit); pSmaH->days = tsdbGetTSmaDays(pTsdb, pSmaH->interval, pSmaH->storageLevel); + return TSDB_CODE_SUCCESS; } /** @@ -1192,6 +1196,7 @@ static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, int64_t indexUid, TSKEY skey) pSmaH->dFile.path = strdup(tSmaFile); pSmaH->smaFsIter.iter = 0; pSmaH->smaFsIter.fid = fid; + return TSDB_CODE_SUCCESS; } /** diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index e87fdba71d..0305d045a9 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -2532,7 +2532,7 @@ _return: } int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet *epSet) { - + return 0; } int32_t catalogRemoveTableMeta(SCatalog* pCtg, const SName* pTableName) { @@ -2599,7 +2599,7 @@ _return: } int32_t catalogGetIndexMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pTableName, const char *pIndexName, SIndexMeta** pIndexMeta) { - + return 0; } int32_t catalogGetTableMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index bcbfeb7015..d375299d57 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -128,8 +128,8 @@ static FORCE_INLINE char* getPosInResultPage(struct STaskAttr* pQueryAttr, SFile int32_t offset) { assert(rowOffset >= 0 && pQueryAttr != NULL); -// int32_t numOfRows = (int32_t)getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery); -// return ((char *)page->data) + rowOffset + offset * numOfRows; + // int32_t numOfRows = (int32_t)getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery); + return ((char *)page->data); } static FORCE_INLINE char* getPosInResultPage_rv(SFilePage* page, int32_t rowOffset, int32_t offset) { diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 34894c235b..0b03613ab5 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -236,6 +236,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) { } taosCloseQueue(pDispatcher->pDataBlocks); taosThreadMutexDestroy(&pDispatcher->mutex); + return TSDB_CODE_SUCCESS; } int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle) { diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 2df18f135c..209ffb9101 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -359,6 +359,10 @@ SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { idata.info.precision = pDescNode->dataType.precision; taosArrayPush(pBlock->pDataBlock, &idata); + + if (IS_VAR_DATA_TYPE(idata.info.type)) { + pBlock->info.hasVarCol = true; + } } return pBlock; @@ -4924,6 +4928,7 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator, bool* newgroup) { pOperator->status = OP_EXEC_DONE; return pBlock; #endif + return TSDB_CODE_SUCCESS; } static void doClearBufferedBlocks(SStreamBlockScanInfo* pInfo) { @@ -5000,6 +5005,7 @@ int32_t loadRemoteDataCallback(void* param, const SDataBuf* pMsg, int32_t code) pSourceDataInfo->status = EX_SOURCE_DATA_READY; tsem_post(&pSourceDataInfo->pEx->ready); + return TSDB_CODE_SUCCESS; } static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { @@ -5673,6 +5679,7 @@ static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t } tsem_post(&pScanResInfo->ready); + return TSDB_CODE_SUCCESS; } static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { @@ -6484,6 +6491,7 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator, bool* newgroup) { tsortAddSource(pInfo->pSortHandle, ps); int32_t code = tsortOpen(pInfo->pSortHandle); + taosMemoryFreeClear(ps); if (code != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, terrno); } @@ -6496,15 +6504,18 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR SExecTaskInfo* pTaskInfo) { SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL) { + int32_t rowSize = pResBlock->info.rowSize; + + if (pInfo == NULL || pOperator == NULL || rowSize > 100 * 1024 * 1024) { taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } - pInfo->sortBufSize = 1024 * 16; // 1MB, TODO dynamic set the available sort buffer - pInfo->bufPageSize = 1024; + pInfo->bufPageSize = rowSize < 1024 ? 1024 : rowSize; + + pInfo->sortBufSize = pInfo->bufPageSize * 16; // 1MB, TODO dynamic set the available sort buffer pInfo->numOfRowsInRes = 1024; pInfo->pDataBlock = pResBlock; pInfo->pSortInfo = pSortInfo; @@ -7590,6 +7601,7 @@ static int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, S pBasicInfo->capacity = numOfRows; doInitAggInfoSup(pAggSup, pBasicInfo->pCtx, numOfCols, pkey); + return TSDB_CODE_SUCCESS; } static STableQueryInfo* initTableQueryInfo(const STableGroupInfo* pTableGroupInfo) { @@ -8389,6 +8401,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator, bool* newgroup) { return (pRes->info.rows == 0)? NULL:pInfo->pRes; #endif + return TSDB_CODE_SUCCESS; } SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput) { @@ -8906,6 +8919,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo return createMultiTableAggOperatorInfo(op, pPhyNode->pTargets, pTaskInfo, pTableGroupInfo); } }*/ + return NULL; } static tsdbReaderT createDataReaderImpl(STableScanPhysiNode* pTableScanNode, STableGroupInfo* pGroupInfo, @@ -9217,6 +9231,7 @@ int32_t createQueryFilter(char* data, uint16_t len, SFilterInfo** pFilters) { // tExprTreeDestroy(expr, NULL); // return ret; + return TSDB_CODE_SUCCESS; } // int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** diff --git a/source/libs/executor/src/tlinearhash.c b/source/libs/executor/src/tlinearhash.c index 1b55467c85..21fd54b620 100644 --- a/source/libs/executor/src/tlinearhash.c +++ b/source/libs/executor/src/tlinearhash.c @@ -409,6 +409,7 @@ char* tHashGet(SLHashObj* pHashObj, const void *key, size_t keyLen) { int32_t tHashRemove(SLHashObj* pHashObj, const void *key, size_t keyLen) { // todo + return TSDB_CODE_SUCCESS; } void tHashPrint(const SLHashObj* pHashObj, int32_t type) { diff --git a/source/libs/executor/src/tsimplehash.c b/source/libs/executor/src/tsimplehash.c index 981da0415e..eb6a5dcabe 100644 --- a/source/libs/executor/src/tsimplehash.c +++ b/source/libs/executor/src/tsimplehash.c @@ -258,6 +258,7 @@ void *tSimpleHashGet(SSHashObj *pHashObj, const void *key) { int32_t tSimpleHashRemove(SSHashObj *pHashObj, const void *key) { // todo + return TSDB_CODE_SUCCESS; } void tSimpleHashClear(SSHashObj *pHashObj) { diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 0d69ed711c..343efb5fbf 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -22,6 +22,7 @@ #include "tpagedbuf.h" #include "tsort.h" #include "tutil.h" +#include "tcompare.h" struct STupleHandle { SSDataBlock* pBlock; @@ -123,6 +124,7 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource) { taosArrayPush(pSortHandle->pOrderedSource, &pSource); + return TSDB_CODE_SUCCESS; } static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSources, SSDataBlock* pBlock, int32_t* sourceId) { @@ -164,7 +166,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { } int32_t pageId = -1; - SFilePage* pPage = getNewBufPage(pHandle->pBuf, pHandle->sourceId, &pageId); + void* pPage = getNewBufPage(pHandle->pBuf, pHandle->sourceId, &pageId); if (pPage == NULL) { return terrno; } @@ -172,7 +174,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { int32_t size = blockDataGetSize(p) + sizeof(int32_t) + p->info.numOfCols * sizeof(int32_t); assert(size <= getBufPageSize(pHandle->pBuf)); - blockDataToBuf(pPage->data, p); + blockDataToBuf(pPage, p); setBufPageDirty(pPage, true); releaseBufPage(pHandle->pBuf, pPage); @@ -184,10 +186,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { blockDataCleanup(pDataBlock); SSDataBlock* pBlock = createOneDataBlock(pDataBlock); - int32_t code = doAddNewExternalMemSource(pHandle->pBuf, pHandle->pOrderedSource, pBlock, &pHandle->sourceId); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + return doAddNewExternalMemSource(pHandle->pBuf, pHandle->pOrderedSource, pBlock, &pHandle->sourceId); } static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int32_t startIndex, int32_t endIndex, SSortHandle* pHandle) { @@ -201,8 +200,8 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int SExternalMemSource* pSource = cmpParam->pSources[i]; SPageInfo* pPgInfo = *(SPageInfo**)taosArrayGet(pSource->pageIdList, pSource->pageIndex); - SFilePage* pPage = getBufPage(pHandle->pBuf, getPageId(pPgInfo)); - code = blockDataFromBuf(pSource->src.pBlock, pPage->data); + void* pPage = getBufPage(pHandle->pBuf, getPageId(pPgInfo)); + code = blockDataFromBuf(pSource->src.pBlock, pPage); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -236,6 +235,7 @@ static int32_t sortComparClearup(SMsortComparParam* cmpParam) { } cmpParam->numOfSources = 0; + return TSDB_CODE_SUCCESS; } static void appendOneRowToDataBlock(SSDataBlock *pBlock, const SSDataBlock* pSource, int32_t* rowIndex) { @@ -309,6 +309,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa printf("\nafter adjust:\t"); tMergeTreePrint(pTree); #endif + return TSDB_CODE_SUCCESS; } static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SMsortComparParam* cmpParam, int32_t capacity) { @@ -392,23 +393,13 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { void* left1 = colDataGetData(pLeftColInfoData, pLeftSource->src.rowIndex); void* right1 = colDataGetData(pRightColInfoData, pRightSource->src.rowIndex); - switch(pLeftColInfoData->info.type) { - case TSDB_DATA_TYPE_INT: { - int32_t leftv = *(int32_t*)left1; - int32_t rightv = *(int32_t*)right1; + __compar_fn_t fn = getKeyComparFunc(pLeftColInfoData->info.type, pOrder->order); - if (leftv == rightv) { - break; - } else { - if (pOrder->order == TSDB_ORDER_ASC) { - return leftv < rightv? -1 : 1; - } else { - return leftv < rightv? 1 : -1; - } - } - } - default: - assert(0); + int ret = fn(left1, right1); + if (ret == 0) { + continue; + } else { + return ret; } } return 0; @@ -424,13 +415,13 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { double sortPass = floorl(log2(numOfSources) / log2(pHandle->numOfPages)); pHandle->totalElapsed = taosGetTimestampUs() - pHandle->startTs; - qDebug("%s %d rounds mergesort required to complete the sort, first-round sorted data size:%"PRIzu", sort:%"PRId64", total elapsed:%"PRId64, + qDebug("%s %d rounds mergesort required to complete the sort, first-round sorted data size:%"PRIzu", sort elapsed:%"PRId64", total elapsed:%"PRId64, pHandle->idStr, (int32_t) (sortPass + 1), getTotalBufSize(pHandle->pBuf), pHandle->sortElapsed, pHandle->totalElapsed); size_t pgSize = pHandle->pageSize; int32_t numOfRows = (pgSize - blockDataGetSerialMetaSize(pHandle->pDataBlock))/ blockDataGetSerialRowSize(pHandle->pDataBlock); - blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); + // blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); // useless, it is already enough size_t numOfSorted = taosArrayGetSize(pHandle->pOrderedSource); for(int32_t t = 0; t < sortPass; ++t) { @@ -469,7 +460,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { } int32_t pageId = -1; - SFilePage* pPage = getNewBufPage(pHandle->pBuf, pHandle->sourceId, &pageId); + void* pPage = getNewBufPage(pHandle->pBuf, pHandle->sourceId, &pageId); if (pPage == NULL) { return terrno; } @@ -477,7 +468,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { int32_t size = blockDataGetSize(pDataBlock) + sizeof(int32_t) + pDataBlock->info.numOfCols * sizeof(int32_t); assert(size <= getBufPageSize(pHandle->pBuf)); - blockDataToBuf(pPage->data, pDataBlock); + blockDataToBuf(pPage, pDataBlock); setBufPageDirty(pPage, true); releaseBufPage(pHandle->pBuf, pPage); @@ -526,7 +517,6 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { if (pHandle->type == SORT_SINGLESOURCE_SORT) { SGenericSource* source = taosArrayGetP(pHandle->pOrderedSource, 0); taosArrayClear(pHandle->pOrderedSource); - while (1) { SSDataBlock* pBlock = pHandle->fetchfp(source->param); if (pBlock == NULL) { @@ -559,8 +549,13 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { size_t size = blockDataGetSize(pHandle->pDataBlock); // Perform the in-memory sort and then flush data in the buffer into disk. + int64_t p = taosGetTimestampUs(); + blockDataSort(pHandle->pDataBlock, pHandle->pSortInfo); + int64_t el = taosGetTimestampUs() - p; + pHandle->sortElapsed += el; + // All sorted data can fit in memory, external memory sort is not needed. Return to directly if (size <= sortBufSize) { pHandle->cmpParam.numOfSources = 1; @@ -573,8 +568,6 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { doAddToBuf(pHandle->pDataBlock, pHandle); } } - - taosMemoryFreeClear(source); } return TSDB_CODE_SUCCESS; @@ -616,22 +609,22 @@ int32_t tsortOpen(SSortHandle* pHandle) { return code; } - code = tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + return tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn); } int32_t tsortClose(SSortHandle* pHandle) { // do nothing + return TSDB_CODE_SUCCESS; } int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fp) { pHandle->fetchfp = fp; + return TSDB_CODE_SUCCESS; } int32_t tsortSetComparFp(SSortHandle* pHandle, _sort_merge_compar_fn_t fp) { pHandle->comparFn = fp; + return TSDB_CODE_SUCCESS; } STupleHandle* tsortNextTuple(SSortHandle* pHandle) { diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 1b64182266..3bff67eb69 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -33,6 +33,7 @@ #include "tdef.h" #include "trpc.h" #include "tvariant.h" +#include "tcompare.h" namespace { typedef struct { @@ -125,24 +126,13 @@ int32_t docomp(const void* p1, const void* p2, void* param) { void* left1 = colDataGetData(pLeftColInfoData, pLeftSource->src.rowIndex); void* right1 = colDataGetData(pRightColInfoData, pRightSource->src.rowIndex); + __compar_fn_t fn = getKeyComparFunc(pLeftColInfoData->info.type, pOrder->order); - switch(pLeftColInfoData->info.type) { - case TSDB_DATA_TYPE_INT: { - int32_t leftv = *(int32_t*)left1; - int32_t rightv = *(int32_t*)right1; - - if (leftv == rightv) { - break; - } else { - if (pOrder->order == TSDB_ORDER_ASC) { - return leftv < rightv? -1 : 1; - } else { - return leftv < rightv? 1 : -1; - } - } - } - default: - assert(0); + int ret = fn(left1, right1); + if (ret == 0) { + continue; + } else { + return ret; } } diff --git a/source/libs/index/src/indexFstRegex.c b/source/libs/index/src/indexFstRegex.c index ec41a7f58e..e89c94079e 100644 --- a/source/libs/index/src/indexFstRegex.c +++ b/source/libs/index/src/indexFstRegex.c @@ -26,6 +26,7 @@ FstRegex *regexCreate(const char *str) { memcpy(orig, str, sz); regex->orig = orig; + return regex; } void regexSetup(FstRegex *regex, uint32_t size, const char *str) { diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 1cc259d4da..dd3edcf1a3 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -132,7 +132,6 @@ void sclFreeRes(SHashObj *res) { void sclFreeParam(SScalarParam *param) { if (param->columnData != NULL) { colDataDestroy(param->columnData); - taosMemoryFreeClear(param->columnData); } if (param->pHashFilter != NULL) { diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index d8e97e7e12..0486049296 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -385,16 +385,19 @@ bool getTimePseudoFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv int32_t qStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { ASSERT(inputNum == 1); colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 0)); + return TSDB_CODE_SUCCESS; } int32_t qEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { ASSERT(inputNum == 1); colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 1)); + return TSDB_CODE_SUCCESS; } int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { ASSERT(inputNum == 1); colDataAppendInt64(pOutput->columnData, pOutput->numOfRows, (int64_t *)colDataGetData(pInput->columnData, 2)); + return TSDB_CODE_SUCCESS; } int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index f22f9a5c3c..d08352602d 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -476,7 +476,6 @@ static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert static void doReleaseVec(SColumnInfoData* pCol, int32_t type) { if (type == VECTOR_DO_CONVERT) { colDataDestroy(pCol); - taosMemoryFree(pCol); } } diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 5af13d97ca..86eaa09594 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -258,6 +258,7 @@ _return: SCH_JOB_ELOG("invalid job status update, from %s to %s", jobTaskStatusStr(oriStatus), jobTaskStatusStr(newStatus)); SCH_ERR_RET(code); + return TSDB_CODE_SUCCESS; } int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { @@ -791,7 +792,7 @@ _return: SCH_RET(schProcessOnJobFailure(pJob, code)); } -int32_t schProcessOnDataFetched(SSchJob *job) { +void schProcessOnDataFetched(SSchJob *job) { atomic_val_compare_exchange_32(&job->remoteFetch, 1, 0); tsem_post(&job->rspSem); } @@ -1150,6 +1151,7 @@ int32_t schHandleReadyCallback(void *param, const SDataBuf *pMsg, int32_t code) int32_t schHandleDropCallback(void *param, const SDataBuf *pMsg, int32_t code) { SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; qDebug("QID:%" PRIx64 ",TID:%" PRIx64 " drop task rsp received, code:%x", pParam->queryId, pParam->taskId, code); + return TSDB_CODE_SUCCESS; } int32_t schHandleHbCallback(void *param, const SDataBuf *pMsg, int32_t code) { @@ -2029,7 +2031,7 @@ void schDropJobAllTasks(SSchJob *pJob) { int32_t schCancelJob(SSchJob *pJob) { // TODO - + return TSDB_CODE_SUCCESS; // TODO MOVE ALL TASKS FROM EXEC LIST TO FAIL LIST } diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index c98f6eb9be..d4abcb962a 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -436,7 +436,6 @@ int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight) { int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight) { return compareWStrPatternMatch(pLeft, pRight) ? 0 : 1; } - __compar_fn_t getComparFunc(int32_t type, int32_t optr) { __compar_fn_t comparFn = NULL; @@ -568,53 +567,36 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { } __compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order) { - __compar_fn_t comparFn = NULL; - switch (keyType) { case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_BOOL: - comparFn = (order == TSDB_ORDER_ASC) ? compareInt8Val : compareInt8ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareInt8Val : compareInt8ValDesc; case TSDB_DATA_TYPE_SMALLINT: - comparFn = (order == TSDB_ORDER_ASC) ? compareInt16Val : compareInt16ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareInt16Val : compareInt16ValDesc; case TSDB_DATA_TYPE_INT: - comparFn = (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc; case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: - comparFn = (order == TSDB_ORDER_ASC) ? compareInt64Val : compareInt64ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareInt64Val : compareInt64ValDesc; case TSDB_DATA_TYPE_FLOAT: - comparFn = (order == TSDB_ORDER_ASC) ? compareFloatVal : compareFloatValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareFloatVal : compareFloatValDesc; case TSDB_DATA_TYPE_DOUBLE: - comparFn = (order == TSDB_ORDER_ASC) ? compareDoubleVal : compareDoubleValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareDoubleVal : compareDoubleValDesc; case TSDB_DATA_TYPE_UTINYINT: - comparFn = (order == TSDB_ORDER_ASC) ? compareUint8Val : compareUint8ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareUint8Val : compareUint8ValDesc; case TSDB_DATA_TYPE_USMALLINT: - comparFn = (order == TSDB_ORDER_ASC) ? compareUint16Val : compareUint16ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareUint16Val : compareUint16ValDesc; case TSDB_DATA_TYPE_UINT: - comparFn = (order == TSDB_ORDER_ASC) ? compareUint32Val : compareUint32ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareUint32Val : compareUint32ValDesc; case TSDB_DATA_TYPE_UBIGINT: - comparFn = (order == TSDB_ORDER_ASC) ? compareUint64Val : compareUint64ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareUint64Val : compareUint64ValDesc; case TSDB_DATA_TYPE_BINARY: - comparFn = (order == TSDB_ORDER_ASC) ? compareLenPrefixedStr : compareLenPrefixedStrDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareLenPrefixedStr : compareLenPrefixedStrDesc; case TSDB_DATA_TYPE_NCHAR: - comparFn = (order == TSDB_ORDER_ASC) ? compareLenPrefixedWStr : compareLenPrefixedWStrDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareLenPrefixedWStr : compareLenPrefixedWStrDesc; default: - comparFn = (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc; - break; + return (order == TSDB_ORDER_ASC) ? compareInt32Val : compareInt32ValDesc; } - - return comparFn; } int32_t doCompare(const char *f1, const char *f2, int32_t type, size_t size) { diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 096a16ec94..e6bc2787e8 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -350,8 +350,7 @@ static void lruListMoveToFront(SList* pList, SPageInfo* pi) { } static SPageInfo* getPageInfoFromPayload(void* page) { - int32_t offset = offsetof(SPageInfo, pData); - char* p = (char *)page - offset; + char* p = (char *)page - POINTER_BYTES; SPageInfo* ppi = ((SPageInfo**)p)[0]; return ppi; From eba69fdb917e541cb08e133d064e818784f4f2db Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 2 Apr 2022 16:03:48 +0800 Subject: [PATCH 04/57] fix error in order by logic --- source/libs/executor/src/tsort.c | 4 +- source/libs/executor/test/sortTests.cpp | 52 +++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 343efb5fbf..ba95aa0a47 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -275,8 +275,8 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa } else { SPageInfo* pPgInfo = *(SPageInfo**)taosArrayGet(pSource->pageIdList, pSource->pageIndex); - SFilePage* pPage = getBufPage(pHandle->pBuf, getPageId(pPgInfo)); - int32_t code = blockDataFromBuf(pSource->src.pBlock, pPage->data); + void* pPage = getBufPage(pHandle->pBuf, getPageId(pPgInfo)); + int32_t code = blockDataFromBuf(pSource->src.pBlock, pPage); if (code != TSDB_CODE_SUCCESS) { return code; } diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 3bff67eb69..73808f86b2 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -72,6 +72,39 @@ SSDataBlock* getSingleColDummyBlock(void* param) { return pBlock; } +SSDataBlock* getSingleColStrBlock(void* param) { + _info* pInfo = (_info*) param; + if (--pInfo->count < 0) { + return NULL; + } + + SSDataBlock* pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); + pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); + + SColumnInfoData colInfo = {0}; + colInfo.info.type = TSDB_DATA_TYPE_NCHAR; + colInfo.info.bytes = TSDB_NCHAR_SIZE * 32; + colInfo.info.colId = 1; + colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); + + taosArrayPush(pBlock->pDataBlock, &colInfo); + + for (int32_t i = 0; i < pInfo->pageRows; ++i) { + SColumnInfoData* pColInfo = static_cast(TARRAY_GET_ELEM(pBlock->pDataBlock, 0)); + + int32_t size = taosRand() % 32; + char str[64] = {0}; + taosRandStr(varDataVal(str), size); + varDataSetLen(str, size); + colDataAppend(pColInfo, i, reinterpret_cast(str), false); + } + + pBlock->info.rows = pInfo->pageRows; + pBlock->info.numOfCols = 1; + return pBlock; +} + + int32_t docomp(const void* p1, const void* p2, void* param) { int32_t pLeftIdx = *(int32_t *)p1; int32_t pRightIdx = *(int32_t *)p2; @@ -210,7 +243,9 @@ TEST(testCase, external_mem_sort_Test) { void* v = tsortGetValue(pTupleHandle, 0); printf("%d: %d\n", row, *(int32_t*) v); ASSERT_EQ(row++, *(int32_t*) v); - + //char buf[64] = {0}; + //snprintf(buf, varDataLen(v), "%s", varDataVal(v)); + //printf("%d: %s\n", row, buf); } tsortDestroySortHandle(phandle); } @@ -222,8 +257,18 @@ TEST(testCase, ordered_merge_sort_Test) { SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSchema s = {.type = TSDB_DATA_TYPE_INT, .colId = 1, .bytes = 4}; - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_MULTISOURCE_MERGE, 1024, 5, NULL,"test_abc"); + SSDataBlock* pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); + pBlock->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); + pBlock->info.numOfCols = 1; + for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + SColumnInfoData colInfo = {0}; + colInfo.info.type = TSDB_DATA_TYPE_INT; + colInfo.info.bytes = sizeof(int32_t); + colInfo.info.colId = 1; + taosArrayPush(pBlock->pDataBlock, &colInfo); + } + + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_MULTISOURCE_MERGE, 1024, 5, pBlock,"test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); tsortSetComparFp(phandle, docomp); @@ -253,6 +298,7 @@ TEST(testCase, ordered_merge_sort_Test) { } tsortDestroySortHandle(phandle); + taosMemoryFree(pBlock); } #endif From 155b14388b622ad09a68737ae852806040b664b5 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 2 Apr 2022 16:31:19 +0800 Subject: [PATCH 05/57] fix error in order by logic --- source/common/src/tdatablock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 67cc597fdf..67f4f251f2 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -825,14 +825,17 @@ static void copyBackToBlock(SSDataBlock* pDataBlock, SColumnInfoData* pCols) { if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { taosMemoryFreeClear(pColInfoData->varmeta.offset); + pColInfoData->varmeta = pCols[i].varmeta; } else { taosMemoryFreeClear(pColInfoData->nullbitmap); + pColInfoData->nullbitmap = pCols[i].nullbitmap; } taosMemoryFreeClear(pColInfoData->pData); + pColInfoData->pData = pCols[i].pData; } - colDataDestroy(pCols); + taosMemoryFreeClear(pCols); } static int32_t* createTupleIndex(size_t rows) { @@ -1197,7 +1200,6 @@ void colDataDestroy(SColumnInfoData* pColData) { } taosMemoryFree(pColData->pData); - taosMemoryFree(pColData); } int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) { From e7585db216d9a3d4d39b6b12ea5e4b6c56581d84 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 2 Apr 2022 18:52:41 +0800 Subject: [PATCH 06/57] fix error in order by logic --- source/libs/executor/src/executorimpl.c | 4 ++-- source/libs/executor/src/tsort.c | 6 +++--- source/libs/executor/test/sortTests.cpp | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 209ffb9101..f371103490 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -6513,9 +6513,9 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR return NULL; } - pInfo->bufPageSize = rowSize < 1024 ? 1024 : rowSize; + pInfo->bufPageSize = rowSize < 1024 ? 1024 : rowSize*2; - pInfo->sortBufSize = pInfo->bufPageSize * 16; // 1MB, TODO dynamic set the available sort buffer + pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer pInfo->numOfRowsInRes = 1024; pInfo->pDataBlock = pResBlock; pInfo->pSortInfo = pSortInfo; diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index ba95aa0a47..cc7416bc87 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -141,8 +141,8 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSource (*sourceId) += 1; int32_t rowSize = blockDataGetSerialRowSize(pSource->src.pBlock); - int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(pBlock))/rowSize; - + int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(pBlock))/rowSize; // The value of numOfRows must be greater than 0, which is guaranteed by the previous memory allocation + ASSERT(numOfRows > 0); return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); } @@ -421,7 +421,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { size_t pgSize = pHandle->pageSize; int32_t numOfRows = (pgSize - blockDataGetSerialMetaSize(pHandle->pDataBlock))/ blockDataGetSerialRowSize(pHandle->pDataBlock); - // blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); // useless, it is already enough + blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); // useless, it is already enough size_t numOfSorted = taosArrayGetSize(pHandle->pOrderedSource); for(int32_t t = 0; t < sortPass; ++t) { diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 73808f86b2..229b84b923 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -83,7 +83,7 @@ SSDataBlock* getSingleColStrBlock(void* param) { SColumnInfoData colInfo = {0}; colInfo.info.type = TSDB_DATA_TYPE_NCHAR; - colInfo.info.bytes = TSDB_NCHAR_SIZE * 32; + colInfo.info.bytes = TSDB_NCHAR_SIZE * 16; colInfo.info.colId = 1; colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); @@ -92,7 +92,7 @@ SSDataBlock* getSingleColStrBlock(void* param) { for (int32_t i = 0; i < pInfo->pageRows; ++i) { SColumnInfoData* pColInfo = static_cast(TARRAY_GET_ELEM(pBlock->pDataBlock, 0)); - int32_t size = taosRand() % 32; + int32_t size = taosRand() % 16; char str[64] = {0}; taosRandStr(varDataVal(str), size); varDataSetLen(str, size); @@ -101,6 +101,8 @@ SSDataBlock* getSingleColStrBlock(void* param) { pBlock->info.rows = pInfo->pageRows; pBlock->info.numOfCols = 1; + pBlock->info.hasVarCol = true; + return pBlock; } @@ -218,7 +220,7 @@ TEST(testCase, external_mem_sort_Test) { SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 32, 6, NULL, "test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 128, 6, NULL, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); _info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info)); From 9f959e17f8b0848cc3e58e2552a9925550207088 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 2 Apr 2022 18:53:13 +0800 Subject: [PATCH 07/57] fix error in order by logic --- source/libs/executor/src/tsort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index cc7416bc87..511cba972c 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -421,7 +421,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { size_t pgSize = pHandle->pageSize; int32_t numOfRows = (pgSize - blockDataGetSerialMetaSize(pHandle->pDataBlock))/ blockDataGetSerialRowSize(pHandle->pDataBlock); - blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); // useless, it is already enough + blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); size_t numOfSorted = taosArrayGetSize(pHandle->pOrderedSource); for(int32_t t = 0; t < sortPass; ++t) { From 411086c81161e29aef6e1546d80e6c28ff9033d5 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sun, 3 Apr 2022 10:42:55 +0800 Subject: [PATCH 08/57] fix error in sort operation --- source/common/src/tdatablock.c | 96 ++++++++++++++----------- source/libs/executor/test/sortTests.cpp | 2 +- 2 files changed, 55 insertions(+), 43 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 46aeb83943..772b1f69a3 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -176,6 +176,8 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con static void doBitmapMerge(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, const SColumnInfoData* pSource, int32_t numOfRow2) { + if (numOfRow2 <= 0) return; + uint32_t total = numOfRow1 + numOfRow2; if (BitmapLen(numOfRow1) < BitmapLen(total)) { @@ -190,22 +192,32 @@ static void doBitmapMerge(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, c if (remindBits == 0) { // no need to shift bits of bitmap memcpy(pColumnInfoData->nullbitmap + BitmapLen(numOfRow1), pSource->nullbitmap, BitmapLen(numOfRow2)); - } else { - int32_t len = BitmapLen(numOfRow2); - int32_t i = 0; + return; + } - uint8_t* p = (uint8_t*)pSource->nullbitmap; - pColumnInfoData->nullbitmap[BitmapLen(numOfRow1) - 1] |= (p[0] >> remindBits); + uint8_t* p = (uint8_t*)pSource->nullbitmap; + pColumnInfoData->nullbitmap[BitmapLen(numOfRow1) - 1] |= (p[0] >> remindBits); // copy remind bits - uint8_t* start = (uint8_t*)&pColumnInfoData->nullbitmap[BitmapLen(numOfRow1)]; - while (i < len) { - start[i] |= (p[i] << shiftBits); - i += 1; + if (BitmapLen(numOfRow1) == BitmapLen(total)) { + return; + } - if (i > 1) { - start[i - 1] |= (p[i] >> remindBits); - } + int32_t len = BitmapLen(numOfRow2); + int32_t i = 0; + + uint8_t* start = (uint8_t*)&pColumnInfoData->nullbitmap[BitmapLen(numOfRow1)]; + int32_t overCount = BitmapLen(total) - BitmapLen(numOfRow1); + while (i < len) { // size limit of pSource->nullbitmap + if (i >= 1) { + start[i - 1] |= (p[i] >> remindBits); //copy remind bits } + + if (i >= overCount) { // size limit of pColumnInfoData->nullbitmap + return; + } + + start[i] |= (p[i] << shiftBits); //copy shift bits + i += 1; } } @@ -408,44 +420,44 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd } return TSDB_CODE_SUCCESS; - } else { - // iterate the rows that can be fit in this buffer page - int32_t size = (headerSize + colHeaderSize); + } + // iterate the rows that can be fit in this buffer page + int32_t size = (headerSize + colHeaderSize); - for (int32_t j = startIndex; j < numOfRows; ++j) { - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* pColInfoData = TARRAY_GET_ELEM(pBlock->pDataBlock, i); - if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - bool isNull = colDataIsNull(pColInfoData, numOfRows, j, NULL); - if (isNull) { - // do nothing - } else { - char* p = colDataGetData(pColInfoData, j); - size += varDataTLen(p); - } - - size += sizeof(pColInfoData->varmeta.offset[0]); - } else { // this block is unreached, because hasVarCol = true - size += pColInfoData->info.bytes; - - if (((j - startIndex) & 0x07) == 0) { - size += 1; // the space for null bitmap - } + for (int32_t j = startIndex; j < numOfRows; ++j) { + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pColInfoData = TARRAY_GET_ELEM(pBlock->pDataBlock, i); + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + bool isNull = colDataIsNull(pColInfoData, numOfRows, j, NULL); + if (isNull) { + // do nothing + } else { + char* p = colDataGetData(pColInfoData, j); + size += varDataTLen(p); } - } - if (size > pageSize) { - *stopIndex = j - 1; - ASSERT(*stopIndex > startIndex); + size += sizeof(pColInfoData->varmeta.offset[0]); + } else { // this block is unreached, because hasVarCol = true + size += pColInfoData->info.bytes; - return TSDB_CODE_SUCCESS; + if (((j - startIndex) & 0x07) == 0) { + size += 1; // the space for null bitmap + } } } - // all fit in - *stopIndex = numOfRows - 1; - return TSDB_CODE_SUCCESS; + if (size > pageSize) { + *stopIndex = j - 1; + ASSERT(*stopIndex > startIndex); + + return TSDB_CODE_SUCCESS; + } } + + // all fit in + *stopIndex = numOfRows - 1; + return TSDB_CODE_SUCCESS; + } SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int32_t rowCount) { diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 229b84b923..7e2fd0fed2 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -83,7 +83,7 @@ SSDataBlock* getSingleColStrBlock(void* param) { SColumnInfoData colInfo = {0}; colInfo.info.type = TSDB_DATA_TYPE_NCHAR; - colInfo.info.bytes = TSDB_NCHAR_SIZE * 16; + colInfo.info.bytes = TSDB_NCHAR_SIZE * 16 + VARSTR_HEADER_SIZE; colInfo.info.colId = 1; colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); From ff21ecd3648b7f9c3041722998a9d1bdeb0ca5e9 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 11:43:17 +0800 Subject: [PATCH 09/57] optimize sort logic & fix memory leak --- source/common/src/tdatablock.c | 110 +++--------------------- source/libs/executor/src/executorimpl.c | 12 +-- source/libs/executor/src/tsort.c | 29 ++++--- source/libs/executor/test/sortTests.cpp | 6 +- 4 files changed, 38 insertions(+), 119 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 772b1f69a3..caf82924f4 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -131,44 +131,7 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con memcpy(pColumnInfoData->pData + len, pData, varDataTLen(pData)); pColumnInfoData->varmeta.length += varDataTLen(pData); } else { - char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; - switch (type) { - case TSDB_DATA_TYPE_BOOL: { - *(bool*)p = *(bool*)pData; - break; - } - case TSDB_DATA_TYPE_TINYINT: - case TSDB_DATA_TYPE_UTINYINT: { - *(int8_t*)p = *(int8_t*)pData; - break; - } - case TSDB_DATA_TYPE_SMALLINT: - case TSDB_DATA_TYPE_USMALLINT: { - *(int16_t*)p = *(int16_t*)pData; - break; - } - case TSDB_DATA_TYPE_INT: - case TSDB_DATA_TYPE_UINT: { - *(int32_t*)p = *(int32_t*)pData; - break; - } - case TSDB_DATA_TYPE_TIMESTAMP: - case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_UBIGINT: { - *(int64_t*)p = *(int64_t*)pData; - break; - } - case TSDB_DATA_TYPE_FLOAT: { - *(float*)p = *(float*)pData; - break; - } - case TSDB_DATA_TYPE_DOUBLE: { - *(double*)p = *(double*)pData; - break; - } - default: - assert(0); - } + memcpy(pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow, pData, pColumnInfoData->info.bytes); } return 0; @@ -562,6 +525,11 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) { size_t metaSize = pBlock->info.rows * sizeof(int32_t); if (IS_VAR_DATA_TYPE(pCol->info.type)) { + char* tmp = taosMemoryRealloc(pCol->varmeta.offset, metaSize); + if (tmp == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCol->varmeta.offset = (int32_t*)tmp; memcpy(pCol->varmeta.offset, pStart, metaSize); pStart += metaSize; } else { @@ -738,61 +706,12 @@ static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataB pDst->varmeta.offset[j] = pSrc->varmeta.offset[index[j]]; } } else { - switch (pSrc->info.type) { - case TSDB_DATA_TYPE_UINT: - case TSDB_DATA_TYPE_INT: { - for (int32_t j = 0; j < pDataBlock->info.rows; ++j) { - int32_t* p = (int32_t*)pDst->pData; - int32_t* srclist = (int32_t*)pSrc->pData; - - p[j] = srclist[index[j]]; - if (colDataIsNull_f(pSrc->nullbitmap, index[j])) { - colDataSetNull_f(pDst->nullbitmap, j); - } - } - break; + for (int32_t j = 0; j < pDataBlock->info.rows; ++j) { + if (colDataIsNull_f(pSrc->nullbitmap, index[j])) { + colDataSetNull_f(pDst->nullbitmap, j); + continue; } - case TSDB_DATA_TYPE_UTINYINT: - case TSDB_DATA_TYPE_TINYINT: { - for (int32_t j = 0; j < pDataBlock->info.rows; ++j) { - int32_t* p = (int32_t*)pDst->pData; - int32_t* srclist = (int32_t*)pSrc->pData; - - p[j] = srclist[index[j]]; - if (colDataIsNull_f(pSrc->nullbitmap, index[j])) { - colDataSetNull_f(pDst->nullbitmap, j); - } - } - break; - } - case TSDB_DATA_TYPE_USMALLINT: - case TSDB_DATA_TYPE_SMALLINT: { - for (int32_t j = 0; j < pDataBlock->info.rows; ++j) { - int32_t* p = (int32_t*)pDst->pData; - int32_t* srclist = (int32_t*)pSrc->pData; - - p[j] = srclist[index[j]]; - if (colDataIsNull_f(pSrc->nullbitmap, index[j])) { - colDataSetNull_f(pDst->nullbitmap, j); - } - } - break; - } - case TSDB_DATA_TYPE_UBIGINT: - case TSDB_DATA_TYPE_BIGINT: { - for (int32_t j = 0; j < pDataBlock->info.rows; ++j) { - int32_t* p = (int32_t*)pDst->pData; - int32_t* srclist = (int32_t*)pSrc->pData; - - p[j] = srclist[index[j]]; - if (colDataIsNull_f(pSrc->nullbitmap, index[j])) { - colDataSetNull_f(pDst->nullbitmap, j); - } - } - break; - } - default: - assert(0); + memcpy(pDst->pData + j * pDst->info.bytes, pSrc->pData + index[j] * pDst->info.bytes, pDst->info.bytes); } } } @@ -938,12 +857,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) { int64_t p2 = taosGetTimestampUs(); - int32_t code = blockDataAssign(pCols, pDataBlock, index); - if (code != TSDB_CODE_SUCCESS) { - destroyTupleIndex(index); - terrno = code; - return code; - } + blockDataAssign(pCols, pDataBlock, index); int64_t p3 = taosGetTimestampUs(); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 2ccc92111a..f960993e3e 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -5769,10 +5769,11 @@ static void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHan pBlock->info.rows += 1; } -static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, bool hasVarCol, - int32_t capacity) { +static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity) { blockDataCleanup(pDataBlock); + blockDataEnsureCapacity(pDataBlock, capacity); + while (1) { STupleHandle* pTupleHandle = tsortNextTuple(pHandle); if (pTupleHandle == NULL) { @@ -5971,7 +5972,7 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator, bool* newgroup) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SSortedMergeOperatorInfo* pInfo = pOperator->info; if (pOperator->status == OP_RES_TO_RETURN) { - return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pInfo->hasVarCol, pInfo->binfo.capacity); + return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pInfo->binfo.capacity); } int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; @@ -6116,10 +6117,9 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator, bool* newgroup) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SSortOperatorInfo* pInfo = pOperator->info; - bool hasVarCol = pInfo->pDataBlock->info.hasVarCol; if (pOperator->status == OP_RES_TO_RETURN) { - return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, hasVarCol, pInfo->numOfRowsInRes); + return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, pInfo->numOfRowsInRes); } int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; @@ -6139,7 +6139,7 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator, bool* newgroup) { } pOperator->status = OP_RES_TO_RETURN; - return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, hasVarCol, pInfo->numOfRowsInRes); + return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, pInfo->numOfRowsInRes); } SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 511cba972c..49a99ec284 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -111,6 +111,17 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t page return pSortHandle; } +static int32_t sortComparClearup(SMsortComparParam* cmpParam) { + for(int32_t i = 0; i < cmpParam->numOfSources; ++i) { + SExternalMemSource* pSource = cmpParam->pSources[i]; + blockDataDestroy(pSource->src.pBlock); + taosMemoryFreeClear(pSource); + } + + cmpParam->numOfSources = 0; + return TSDB_CODE_SUCCESS; +} + void tsortDestroySortHandle(SSortHandle* pSortHandle) { tsortClose(pSortHandle); if (pSortHandle->pMergeTree != NULL) { @@ -119,6 +130,8 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { destroyDiskbasedBuf(pSortHandle->pBuf); taosMemoryFreeClear(pSortHandle->idStr); + blockDataDestroy(pSortHandle->pDataBlock); + sortComparClearup(&pSortHandle->cmpParam); // pOrderedSource is in cmpParam taosMemoryFreeClear(pSortHandle); } @@ -168,6 +181,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { int32_t pageId = -1; void* pPage = getNewBufPage(pHandle->pBuf, pHandle->sourceId, &pageId); if (pPage == NULL) { + blockDataDestroy(p); return terrno; } @@ -227,17 +241,6 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int return code; } -static int32_t sortComparClearup(SMsortComparParam* cmpParam) { - for(int32_t i = 0; i < cmpParam->numOfSources; ++i) { - SExternalMemSource* pSource = cmpParam->pSources[i]; - blockDataDestroy(pSource->src.pBlock); - taosMemoryFreeClear(pSource); - } - - cmpParam->numOfSources = 0; - return TSDB_CODE_SUCCESS; -} - static void appendOneRowToDataBlock(SSDataBlock *pBlock, const SSDataBlock* pSource, int32_t* rowIndex) { for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); @@ -312,7 +315,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa return TSDB_CODE_SUCCESS; } -static SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SMsortComparParam* cmpParam, int32_t capacity) { +static SSDataBlock* getSortedBlockDataInner(SSortHandle* pHandle, SMsortComparParam* cmpParam, int32_t capacity) { blockDataCleanup(pHandle->pDataBlock); while(1) { @@ -454,7 +457,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { } while (1) { - SSDataBlock* pDataBlock = getSortedBlockData(pHandle, &pHandle->cmpParam, numOfRows); + SSDataBlock* pDataBlock = getSortedBlockDataInner(pHandle, &pHandle->cmpParam, numOfRows); if (pDataBlock == NULL) { break; } diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 7e2fd0fed2..0674f05f33 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -198,6 +198,7 @@ TEST(testCase, inMem_sort_Test) { int32_t code = tsortOpen(phandle); int32_t row = 1; + taosMemoryFreeClear(ps); while(1) { STupleHandle* pTupleHandle = tsortNextTuple(phandle); @@ -235,6 +236,7 @@ TEST(testCase, external_mem_sort_Test) { int32_t code = tsortOpen(phandle); int32_t row = 1; + taosMemoryFreeClear(ps); while(1) { STupleHandle* pTupleHandle = tsortNextTuple(phandle); @@ -245,8 +247,8 @@ TEST(testCase, external_mem_sort_Test) { void* v = tsortGetValue(pTupleHandle, 0); printf("%d: %d\n", row, *(int32_t*) v); ASSERT_EQ(row++, *(int32_t*) v); - //char buf[64] = {0}; - //snprintf(buf, varDataLen(v), "%s", varDataVal(v)); + char buf[64] = {0}; + memcpy(buf, varDataVal(v), varDataLen(v)); //printf("%d: %s\n", row, buf); } tsortDestroySortHandle(phandle); From 9b66bb168293a09a1dfe5c2fcea3ab4622cc2524 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 14:32:07 +0800 Subject: [PATCH 10/57] optimize sort logic & fix memory leak --- source/libs/executor/test/sortTests.cpp | 225 ++++++++++++++++-------- 1 file changed, 153 insertions(+), 72 deletions(-) diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 0674f05f33..14d527f302 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -40,8 +40,22 @@ typedef struct { int32_t startVal; int32_t count; int32_t pageRows; + int16_t type; } _info; +int16_t VARCOUNT = 16; + +float rand_f2() +{ + unsigned r = taosRand(); + r &= 0x007fffff; + r |= 0x40800000; + return *(float*)&r - 6.0; +} + +static const int32_t TEST_NUMBER = 1; +#define bigendian() ((*(char *)&TEST_NUMBER) == 0) + SSDataBlock* getSingleColDummyBlock(void* param) { _info* pInfo = (_info*) param; if (--pInfo->count < 0) { @@ -52,19 +66,64 @@ SSDataBlock* getSingleColDummyBlock(void* param) { pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); SColumnInfoData colInfo = {0}; - colInfo.info.type = TSDB_DATA_TYPE_INT; - colInfo.info.bytes = sizeof(int32_t); + colInfo.info.type = pInfo->type; + if (pInfo->type == TSDB_DATA_TYPE_NCHAR){ + colInfo.info.bytes = TSDB_NCHAR_SIZE * VARCOUNT + VARSTR_HEADER_SIZE; + colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); + } else if(pInfo->type == TSDB_DATA_TYPE_BINARY) { + colInfo.info.bytes = VARCOUNT + VARSTR_HEADER_SIZE; + colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); + } else{ + colInfo.info.bytes = tDataTypes[pInfo->type].bytes; + colInfo.pData = static_cast(taosMemoryCalloc(pInfo->pageRows, colInfo.info.bytes)); + colInfo.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->pageRows + 7) / 8)); + } colInfo.info.colId = 1; - colInfo.pData = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); - colInfo.nullbitmap = static_cast(taosMemoryCalloc(1, (pInfo->pageRows + 7) / 8)); taosArrayPush(pBlock->pDataBlock, &colInfo); for (int32_t i = 0; i < pInfo->pageRows; ++i) { SColumnInfoData* pColInfo = static_cast(TARRAY_GET_ELEM(pBlock->pDataBlock, 0)); - int32_t v = ++pInfo->startVal; - colDataAppend(pColInfo, i, reinterpret_cast(&v), false); + if (pInfo->type == TSDB_DATA_TYPE_NCHAR){ + int32_t size = taosRand() % VARCOUNT; + char str[128] = {0}; + char strOri[128] = {0}; + taosRandStr(strOri, size); + int32_t len = 0; + bool ret = taosMbsToUcs4(strOri, size, (TdUcs4*)varDataVal(str), 128, &len); + if (!ret){ + printf("error\n"); + return NULL; + } + varDataSetLen(str, len); + colDataAppend(pColInfo, i, reinterpret_cast(str), false); + pBlock->info.hasVarCol = true; + printf("nchar: %s\n",strOri); + } else if(pInfo->type == TSDB_DATA_TYPE_BINARY){ + int32_t size = taosRand() % VARCOUNT; + char str[64] = {0}; + taosRandStr(varDataVal(str), size); + varDataSetLen(str, size); + colDataAppend(pColInfo, i, reinterpret_cast(str), false); + pBlock->info.hasVarCol = true; + printf("binary: %s\n", varDataVal(str)); + } else if(pInfo->type == TSDB_DATA_TYPE_DOUBLE || pInfo->type == TSDB_DATA_TYPE_FLOAT) { + double v = rand_f2(); + colDataAppend(pColInfo, i, reinterpret_cast(&v), false); + printf("float: %f\n", v); + } else{ + int64_t v = ++pInfo->startVal; + char *result = static_cast(taosMemoryCalloc(tDataTypes[pInfo->type].bytes, 1)); + if (!bigendian()){ + memcpy(result, &v, tDataTypes[pInfo->type].bytes); + }else{ + memcpy(result, (char*)(&v) + sizeof(int64_t) - tDataTypes[pInfo->type].bytes, tDataTypes[pInfo->type].bytes); + } + + colDataAppend(pColInfo, i, result, false); + printf("int: %lld\n", v); + } } pBlock->info.rows = pInfo->pageRows; @@ -72,40 +131,6 @@ SSDataBlock* getSingleColDummyBlock(void* param) { return pBlock; } -SSDataBlock* getSingleColStrBlock(void* param) { - _info* pInfo = (_info*) param; - if (--pInfo->count < 0) { - return NULL; - } - - SSDataBlock* pBlock = static_cast(taosMemoryCalloc(1, sizeof(SSDataBlock))); - pBlock->pDataBlock = taosArrayInit(4, sizeof(SColumnInfoData)); - - SColumnInfoData colInfo = {0}; - colInfo.info.type = TSDB_DATA_TYPE_NCHAR; - colInfo.info.bytes = TSDB_NCHAR_SIZE * 16 + VARSTR_HEADER_SIZE; - colInfo.info.colId = 1; - colInfo.varmeta.offset = static_cast(taosMemoryCalloc(pInfo->pageRows, sizeof(int32_t))); - - taosArrayPush(pBlock->pDataBlock, &colInfo); - - for (int32_t i = 0; i < pInfo->pageRows; ++i) { - SColumnInfoData* pColInfo = static_cast(TARRAY_GET_ELEM(pBlock->pDataBlock, 0)); - - int32_t size = taosRand() % 16; - char str[64] = {0}; - taosRandStr(varDataVal(str), size); - varDataSetLen(str, size); - colDataAppend(pColInfo, i, reinterpret_cast(str), false); - } - - pBlock->info.rows = pInfo->pageRows; - pBlock->info.numOfCols = 1; - pBlock->info.hasVarCol = true; - - return pBlock; -} - int32_t docomp(const void* p1, const void* p2, void* param) { int32_t pLeftIdx = *(int32_t *)p1; @@ -183,7 +208,6 @@ TEST(testCase, inMem_sort_Test) { SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSchema s = {.type = TSDB_DATA_TYPE_INT, .colId = 1, .bytes = 4, }; SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 1024, 5, NULL, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); @@ -191,6 +215,7 @@ TEST(testCase, inMem_sort_Test) { pInfo->startVal = 0; pInfo->pageRows = 100; pInfo->count = 6; + pInfo->type = TSDB_DATA_TYPE_USMALLINT; SGenericSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); ps->param = pInfo; @@ -207,51 +232,107 @@ TEST(testCase, inMem_sort_Test) { } void* v = tsortGetValue(pTupleHandle, 0); - printf("%d: %d\n", row, *(int32_t*) v); - ASSERT_EQ(row++, *(int32_t*) v); + printf("%d: %d\n", row, *(uint16_t*) v); + ASSERT_EQ(row++, *(uint16_t*) v); } + taosArrayDestroy(orderInfo); tsortDestroySortHandle(phandle); } TEST(testCase, external_mem_sort_Test) { - SBlockOrderInfo oi = {0}; - oi.order = TSDB_ORDER_ASC; - oi.slotId = 0; - SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); - taosArrayPush(orderInfo, &oi); - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 128, 6, NULL, "test_abc"); - tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); + _info* pInfo = (_info*) taosMemoryCalloc(7, sizeof(_info)); + pInfo[0].startVal = 0; + pInfo[0].pageRows = 10; + pInfo[0].count = 6; + pInfo[0].type = TSDB_DATA_TYPE_BOOL; - _info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info)); - pInfo->startVal = 0; - pInfo->pageRows = 100; - pInfo->count = 6; + pInfo[1].startVal = 0; + pInfo[1].pageRows = 10; + pInfo[1].count = 6; + pInfo[1].type = TSDB_DATA_TYPE_TINYINT; - SGenericSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); - ps->param = pInfo; + pInfo[2].startVal = 0; + pInfo[2].pageRows = 100; + pInfo[2].count = 6; + pInfo[2].type = TSDB_DATA_TYPE_USMALLINT; - tsortAddSource(phandle, ps); + pInfo[2].startVal = 0; + pInfo[2].pageRows = 100; + pInfo[2].count = 6; + pInfo[2].type = TSDB_DATA_TYPE_INT; - int32_t code = tsortOpen(phandle); - int32_t row = 1; - taosMemoryFreeClear(ps); + pInfo[3].startVal = 0; + pInfo[3].pageRows = 100; + pInfo[3].count = 6; + pInfo[3].type = TSDB_DATA_TYPE_UBIGINT; - while(1) { - STupleHandle* pTupleHandle = tsortNextTuple(phandle); - if (pTupleHandle == NULL) { - break; + pInfo[4].startVal = 0; + pInfo[4].pageRows = 100; + pInfo[4].count = 6; + pInfo[4].type = TSDB_DATA_TYPE_DOUBLE; + + pInfo[5].startVal = 0; + pInfo[5].pageRows = 50; + pInfo[5].count = 6; + pInfo[5].type = TSDB_DATA_TYPE_NCHAR; + + pInfo[6].startVal = 0; + pInfo[6].pageRows = 100; + pInfo[6].count = 6; + pInfo[6].type = TSDB_DATA_TYPE_BINARY; + + for (int i = 0; i < 7; i++){ + SBlockOrderInfo oi = {0}; + oi.order = TSDB_ORDER_ASC; + oi.slotId = 0; + SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); + taosArrayPush(orderInfo, &oi); + + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 128, 3, NULL, "test_abc"); + tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); + + SGenericSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); + ps->param = &pInfo[i]; + + tsortAddSource(phandle, ps); + + int32_t code = tsortOpen(phandle); + int32_t row = 1; + taosMemoryFreeClear(ps); + + printf("--------start with %s-----------\n", tDataTypes[pInfo[i].type].name); + while(1) { + STupleHandle* pTupleHandle = tsortNextTuple(phandle); + if (pTupleHandle == NULL) { + break; + } + + void* v = tsortGetValue(pTupleHandle, 0); + + if(pInfo[i].type == TSDB_DATA_TYPE_NCHAR){ + char buf[128] = {0}; + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(v), varDataLen(v), buf); + printf("%d: %s\n", row++, buf); + }else if(pInfo[i].type == TSDB_DATA_TYPE_BINARY){ + char buf[128] = {0}; + memcpy(buf, varDataVal(v), varDataLen(v)); + printf("%d: %s\n", row++, buf); + }else{ + int64_t result = 0; + if (!bigendian()){ + memcpy(&result, v, tDataTypes[pInfo[i].type].bytes); + }else{ + memcpy((char*)(&result) + sizeof(int64_t) - tDataTypes[pInfo[i].type].bytes, v, tDataTypes[pInfo[i].type].bytes); + } + printf("%d: %lld\n", row++, result); + } } - - void* v = tsortGetValue(pTupleHandle, 0); - printf("%d: %d\n", row, *(int32_t*) v); - ASSERT_EQ(row++, *(int32_t*) v); - char buf[64] = {0}; - memcpy(buf, varDataVal(v), varDataLen(v)); - //printf("%d: %s\n", row, buf); + taosArrayDestroy(orderInfo); + tsortDestroySortHandle(phandle); } - tsortDestroySortHandle(phandle); + taosMemoryFree(pInfo); } TEST(testCase, ordered_merge_sort_Test) { From 78acaed84ebcd5127f8a38c0904f6e51dd3aa4af Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 15:44:14 +0800 Subject: [PATCH 11/57] fix error in sort logic --- cmake/cmake.define | 8 ++++--- source/common/src/tdatablock.c | 6 ++--- source/libs/executor/src/tsort.c | 7 +++++- source/libs/executor/test/sortTests.cpp | 32 +++++++++++++------------ 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/cmake/cmake.define b/cmake/cmake.define index 298d102b87..03feca37bd 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -36,11 +36,13 @@ IF (TD_WINDOWS) ENDIF () ELSE () - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") -IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64") +IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") ADD_DEFINITIONS("-D_TD_ARM_") ELSE () ADD_DEFINITIONS("-msse4.2 -mfma") diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index caf82924f4..372ea9a2d7 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -373,9 +373,9 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd size_t payloadSize = pageSize - (headerSize + colHeaderSize); // TODO speedup by checking if the whole page can fit in firstly. - if (!hasVarCol) { + /*if (!hasVarCol) { size_t rowSize = blockDataGetRowSize(pBlock); - int32_t capacity = (payloadSize / (rowSize * 8 + bitmapChar * numOfCols)) * 8; + int32_t capacity = (payloadSize / (rowSize * 8 + bitmapChar * numOfCols)) * 8; //if pageSize = 128, rowSize = 2, it will core in doAddToBuf:assert(size <= getBufPageSize(pHandle->pBuf)); *stopIndex = startIndex + capacity; if (*stopIndex >= numOfRows) { @@ -383,7 +383,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd } return TSDB_CODE_SUCCESS; - } + }*/ // iterate the rows that can be fit in this buffer page int32_t size = (headerSize + colHeaderSize); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 49a99ec284..e5312921fa 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -131,7 +131,12 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { destroyDiskbasedBuf(pSortHandle->pBuf); taosMemoryFreeClear(pSortHandle->idStr); blockDataDestroy(pSortHandle->pDataBlock); - sortComparClearup(&pSortHandle->cmpParam); // pOrderedSource is in cmpParam + for (size_t i = 0; i < taosArrayGetSize(pSortHandle->pOrderedSource); i++){ + SExternalMemSource* pSource = taosArrayGet(pSortHandle->pOrderedSource, i); + blockDataDestroy(pSource->src.pBlock); + taosMemoryFreeClear(pSource); + } + taosArrayDestroy(pSortHandle->pOrderedSource); taosMemoryFreeClear(pSortHandle); } diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 14d527f302..9ad16669a4 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -122,7 +122,8 @@ SSDataBlock* getSingleColDummyBlock(void* param) { } colDataAppend(pColInfo, i, result, false); - printf("int: %lld\n", v); + printf("int: %ld\n", v); + taosMemoryFree(result); } } @@ -238,11 +239,12 @@ TEST(testCase, inMem_sort_Test) { } taosArrayDestroy(orderInfo); tsortDestroySortHandle(phandle); + taosMemoryFree(pInfo); } TEST(testCase, external_mem_sort_Test) { - _info* pInfo = (_info*) taosMemoryCalloc(7, sizeof(_info)); + _info* pInfo = (_info*) taosMemoryCalloc(8, sizeof(_info)); pInfo[0].startVal = 0; pInfo[0].pageRows = 10; pInfo[0].count = 6; @@ -258,32 +260,32 @@ TEST(testCase, external_mem_sort_Test) { pInfo[2].count = 6; pInfo[2].type = TSDB_DATA_TYPE_USMALLINT; - pInfo[2].startVal = 0; - pInfo[2].pageRows = 100; - pInfo[2].count = 6; - pInfo[2].type = TSDB_DATA_TYPE_INT; - pInfo[3].startVal = 0; pInfo[3].pageRows = 100; pInfo[3].count = 6; - pInfo[3].type = TSDB_DATA_TYPE_UBIGINT; + pInfo[3].type = TSDB_DATA_TYPE_INT; pInfo[4].startVal = 0; pInfo[4].pageRows = 100; pInfo[4].count = 6; - pInfo[4].type = TSDB_DATA_TYPE_DOUBLE; + pInfo[4].type = TSDB_DATA_TYPE_UBIGINT; pInfo[5].startVal = 0; - pInfo[5].pageRows = 50; + pInfo[5].pageRows = 100; pInfo[5].count = 6; - pInfo[5].type = TSDB_DATA_TYPE_NCHAR; + pInfo[5].type = TSDB_DATA_TYPE_DOUBLE; pInfo[6].startVal = 0; - pInfo[6].pageRows = 100; + pInfo[6].pageRows = 50; pInfo[6].count = 6; - pInfo[6].type = TSDB_DATA_TYPE_BINARY; + pInfo[6].type = TSDB_DATA_TYPE_NCHAR; - for (int i = 0; i < 7; i++){ + pInfo[7].startVal = 0; + pInfo[7].pageRows = 100; + pInfo[7].count = 6; + pInfo[7].type = TSDB_DATA_TYPE_BINARY; + + for (int i = 0; i < 8; i++){ SBlockOrderInfo oi = {0}; oi.order = TSDB_ORDER_ASC; oi.slotId = 0; @@ -326,7 +328,7 @@ TEST(testCase, external_mem_sort_Test) { }else{ memcpy((char*)(&result) + sizeof(int64_t) - tDataTypes[pInfo[i].type].bytes, v, tDataTypes[pInfo[i].type].bytes); } - printf("%d: %lld\n", row++, result); + printf("%d: %ld\n", row++, result); } } taosArrayDestroy(orderInfo); From 865a13c1c2bfa8000f2df1452587c34bdca2da11 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 16:46:26 +0800 Subject: [PATCH 12/57] fix error in sort logic --- source/common/src/tdatablock.c | 2 +- source/libs/executor/src/tsort.c | 6 +++--- source/libs/executor/test/sortTests.cpp | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 372ea9a2d7..63c095ecf5 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -411,7 +411,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd if (size > pageSize) { *stopIndex = j - 1; - ASSERT(*stopIndex > startIndex); + ASSERT(*stopIndex >= startIndex); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index e5312921fa..7e01fe0ba8 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -132,9 +132,9 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { taosMemoryFreeClear(pSortHandle->idStr); blockDataDestroy(pSortHandle->pDataBlock); for (size_t i = 0; i < taosArrayGetSize(pSortHandle->pOrderedSource); i++){ - SExternalMemSource* pSource = taosArrayGet(pSortHandle->pOrderedSource, i); - blockDataDestroy(pSource->src.pBlock); - taosMemoryFreeClear(pSource); + SExternalMemSource** pSource = taosArrayGet(pSortHandle->pOrderedSource, i); + blockDataDestroy((*pSource)->src.pBlock); + taosMemoryFreeClear(*pSource); } taosArrayDestroy(pSortHandle->pOrderedSource); taosMemoryFreeClear(pSortHandle); diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 9ad16669a4..f1891f9c62 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -91,7 +91,7 @@ SSDataBlock* getSingleColDummyBlock(void* param) { char strOri[128] = {0}; taosRandStr(strOri, size); int32_t len = 0; - bool ret = taosMbsToUcs4(strOri, size, (TdUcs4*)varDataVal(str), 128, &len); + bool ret = taosMbsToUcs4(strOri, size, (TdUcs4*)varDataVal(str), size * TSDB_NCHAR_SIZE, &len); if (!ret){ printf("error\n"); return NULL; @@ -321,6 +321,10 @@ TEST(testCase, external_mem_sort_Test) { char buf[128] = {0}; memcpy(buf, varDataVal(v), varDataLen(v)); printf("%d: %s\n", row++, buf); + }else if(pInfo[i].type == TSDB_DATA_TYPE_DOUBLE) { + printf("double: %lf\n", *(double*)v); + }else if (pInfo[i].type == TSDB_DATA_TYPE_FLOAT) { + printf("float: %f\n", *(float*)v); }else{ int64_t result = 0; if (!bigendian()){ From f72c983792386b521ab6f4b009b585a4373997f5 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 16:56:13 +0800 Subject: [PATCH 13/57] modify test case --- source/common/src/tdatablock.c | 2 +- source/libs/executor/src/executorimpl.c | 2 +- source/libs/executor/test/sortTests.cpp | 27 ++++++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 63c095ecf5..33dc3a2469 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -409,7 +409,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd } } - if (size > pageSize) { + if (size > pageSize) { // pageSize must be able to hold one row *stopIndex = j - 1; ASSERT(*stopIndex >= startIndex); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index f960993e3e..b66107b4a7 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -6155,7 +6155,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR return NULL; } - pInfo->bufPageSize = rowSize < 1024 ? 1024 : rowSize*2; + pInfo->bufPageSize = rowSize < 1024 ? 1024*2 : rowSize*2; // there are headers, so pageSize = rowSize + header pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer pInfo->numOfRowsInRes = 1024; diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index f1891f9c62..a89b76e81e 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -287,7 +287,13 @@ TEST(testCase, external_mem_sort_Test) { for (int i = 0; i < 8; i++){ SBlockOrderInfo oi = {0}; - oi.order = TSDB_ORDER_ASC; + + if(pInfo[i].type == TSDB_DATA_TYPE_NCHAR){ + oi.order = TSDB_ORDER_DESC; + }else{ + oi.order = TSDB_ORDER_ASC; + } + oi.slotId = 0; SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); @@ -363,15 +369,16 @@ TEST(testCase, ordered_merge_sort_Test) { tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); tsortSetComparFp(phandle, docomp); + SGenericSource* p = static_cast(taosMemoryCalloc(10, sizeof(SGenericSource))); + _info* c = static_cast<_info*>(taosMemoryCalloc(10, sizeof(_info))); for(int32_t i = 0; i < 10; ++i) { - SGenericSource* p = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); - _info* c = static_cast<_info*>(taosMemoryCalloc(1, sizeof(_info))); - c->count = 1; - c->pageRows = 1000; - c->startVal = i*1000; + c[i].count = 1; + c[i].pageRows = 1000; + c[i].startVal = i*1000; + c[i].type = TSDB_DATA_TYPE_INT; - p->param = c; - tsortAddSource(phandle, p); + p[i].param = c; + tsortAddSource(phandle, &p[i]); } int32_t code = tsortOpen(phandle); @@ -388,8 +395,10 @@ TEST(testCase, ordered_merge_sort_Test) { ASSERT_EQ(row++, *(int32_t*) v); } + taosMemoryFree(p); + taosMemoryFree(c); tsortDestroySortHandle(phandle); - taosMemoryFree(pBlock); + blockDataDestroy(pBlock); } #endif From 4bc0e507da6e383aa46221ba2743afb24385a3c0 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 17:10:51 +0800 Subject: [PATCH 14/57] modify test case --- source/libs/executor/test/sortTests.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index a89b76e81e..e774b8d2e3 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -369,16 +369,17 @@ TEST(testCase, ordered_merge_sort_Test) { tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); tsortSetComparFp(phandle, docomp); - SGenericSource* p = static_cast(taosMemoryCalloc(10, sizeof(SGenericSource))); - _info* c = static_cast<_info*>(taosMemoryCalloc(10, sizeof(_info))); + SGenericSource* p[10] = {0}; + _info c[10] = {0}; for(int32_t i = 0; i < 10; ++i) { + p[i] = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); c[i].count = 1; c[i].pageRows = 1000; c[i].startVal = i*1000; c[i].type = TSDB_DATA_TYPE_INT; - p[i].param = c; - tsortAddSource(phandle, &p[i]); + p[i]->param = &c[i]; + tsortAddSource(phandle, p[i]); } int32_t code = tsortOpen(phandle); @@ -395,8 +396,9 @@ TEST(testCase, ordered_merge_sort_Test) { ASSERT_EQ(row++, *(int32_t*) v); } - taosMemoryFree(p); - taosMemoryFree(c); + for(int32_t i = 0; i < 10; ++i) { + taosMemoryFree(p[i]); + } tsortDestroySortHandle(phandle); blockDataDestroy(pBlock); } From 460036a0d49194c04472ecd076dcc655856b7809 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Wed, 6 Apr 2022 17:50:03 +0800 Subject: [PATCH 15/57] 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 16/57] 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 17/57] 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 aced34c4387a502895a15b690140afdaac2edcdb Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 18:30:25 +0800 Subject: [PATCH 18/57] fix error in sort operation --- source/libs/executor/inc/tsort.h | 17 ++++++++-------- source/libs/executor/src/executorimpl.c | 4 ++-- source/libs/executor/src/tsort.c | 27 ++++++++++++------------- source/libs/executor/test/sortTests.cpp | 19 +++++++++-------- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index 8971ee33d3..cc5db32666 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -34,16 +34,17 @@ typedef struct SMultiMergeSource { SSDataBlock *pBlock; } SMultiMergeSource; -typedef struct SExternalMemSource { +typedef struct SSortSource { SMultiMergeSource src; - SArray* pageIdList; - int32_t pageIndex; -} SExternalMemSource; + union{ + struct{ + SArray* pageIdList; + int32_t pageIndex; + }; + void *param; + }; -typedef struct SGenericSource { - SMultiMergeSource src; - void *param; -} SGenericSource; +} SSortSource; typedef struct SMsortComparParam { void **pSources; diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index b66107b4a7..c418d78540 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -5982,7 +5982,7 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator, bool* newgroup) { tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) { - SGenericSource* ps = taosMemoryCalloc(1, sizeof(SGenericSource)); + SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); ps->param = pOperator->pDownstream[i]; tsortAddSource(pInfo->pSortHandle, ps); } @@ -6128,7 +6128,7 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator, bool* newgroup) { tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); - SGenericSource* ps = taosMemoryCalloc(1, sizeof(SGenericSource)); + SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); ps->param = pOperator->pDownstream[0]; tsortAddSource(pInfo->pSortHandle, ps); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 7e01fe0ba8..2aa8f6a09d 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -113,7 +113,7 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t page static int32_t sortComparClearup(SMsortComparParam* cmpParam) { for(int32_t i = 0; i < cmpParam->numOfSources; ++i) { - SExternalMemSource* pSource = cmpParam->pSources[i]; + SSortSource* pSource = cmpParam->pSources[i]; // NOTICE: pSource may be SGenericSource *, if it is SORT_MULTISOURCE_MERGE blockDataDestroy(pSource->src.pBlock); taosMemoryFreeClear(pSource); } @@ -132,7 +132,7 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { taosMemoryFreeClear(pSortHandle->idStr); blockDataDestroy(pSortHandle->pDataBlock); for (size_t i = 0; i < taosArrayGetSize(pSortHandle->pOrderedSource); i++){ - SExternalMemSource** pSource = taosArrayGet(pSortHandle->pOrderedSource, i); + SSortSource** pSource = taosArrayGet(pSortHandle->pOrderedSource, i); blockDataDestroy((*pSource)->src.pBlock); taosMemoryFreeClear(*pSource); } @@ -146,7 +146,7 @@ int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource) { } static int32_t doAddNewExternalMemSource(SDiskbasedBuf *pBuf, SArray* pAllSources, SSDataBlock* pBlock, int32_t* sourceId) { - SExternalMemSource* pSource = taosMemoryCalloc(1, sizeof(SExternalMemSource)); + SSortSource* pSource = taosMemoryCalloc(1, sizeof(SSortSource)); if (pSource == NULL) { return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -216,7 +216,7 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int if (pHandle->type == SORT_SINGLESOURCE_SORT) { for (int32_t i = 0; i < cmpParam->numOfSources; ++i) { - SExternalMemSource* pSource = cmpParam->pSources[i]; + SSortSource* pSource = cmpParam->pSources[i]; SPageInfo* pPgInfo = *(SPageInfo**)taosArrayGet(pSource->pageIdList, pSource->pageIndex); void* pPage = getBufPage(pHandle->pBuf, getPageId(pPgInfo)); @@ -238,7 +238,7 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int } for (int32_t i = 0; i < cmpParam->numOfSources; ++i) { - SGenericSource* pSource = cmpParam->pSources[i]; + SSortSource* pSource = cmpParam->pSources[i]; pSource->src.pBlock = pHandle->fetchfp(pSource->param); } } @@ -265,7 +265,7 @@ static void appendOneRowToDataBlock(SSDataBlock *pBlock, const SSDataBlock* pSou *rowIndex += 1; } -static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwayMergeTreeInfo *pTree, SSortHandle *pHandle, int32_t* numOfCompleted) { +static int32_t adjustMergeTreeForNextTuple(SSortSource *pSource, SMultiwayMergeTreeInfo *pTree, SSortHandle *pHandle, int32_t* numOfCompleted) { /* * load a new SDataBlock into memory of a given intermediate data-set source, * since it's last record in buffer has been chosen to be processed, as the winner of loser-tree @@ -292,7 +292,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa releaseBufPage(pHandle->pBuf, pPage); } } else { - pSource->src.pBlock = pHandle->fetchfp(((SGenericSource*)pSource)->param); + pSource->src.pBlock = pHandle->fetchfp(((SSortSource*)pSource)->param); if (pSource->src.pBlock == NULL) { (*numOfCompleted) += 1; pSource->src.rowIndex = -1; @@ -330,7 +330,7 @@ static SSDataBlock* getSortedBlockDataInner(SSortHandle* pHandle, SMsortComparPa int32_t index = tMergeTreeGetChosenIndex(pHandle->pMergeTree); - SExternalMemSource *pSource = (*cmpParam).pSources[index]; + SSortSource *pSource = (*cmpParam).pSources[index]; appendOneRowToDataBlock(pHandle->pDataBlock, pSource->src.pBlock, &pSource->src.rowIndex); int32_t code = adjustMergeTreeForNextTuple(pSource, pHandle->pMergeTree, pHandle, &pHandle->numOfCompletedSources); @@ -355,8 +355,8 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { SArray *pInfo = pParam->orderInfo; - SExternalMemSource* pLeftSource = pParam->pSources[pLeftIdx]; - SExternalMemSource* pRightSource = pParam->pSources[pRightIdx]; + SSortSource* pLeftSource = pParam->pSources[pLeftIdx]; + SSortSource* pRightSource = pParam->pSources[pRightIdx]; // this input is exhausted, set the special value to denote this if (pLeftSource->src.rowIndex == -1) { @@ -484,6 +484,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { blockDataCleanup(pDataBlock); } + sortComparClearup(&pHandle->cmpParam); tMergeTreeDestroy(pHandle->pMergeTree); pHandle->numOfCompletedSources = 0; @@ -494,8 +495,6 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { } } - sortComparClearup(&pHandle->cmpParam); - taosArrayClear(pHandle->pOrderedSource); taosArrayAddAll(pHandle->pOrderedSource, pResList); taosArrayDestroy(pResList); @@ -523,7 +522,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { size_t sortBufSize = pHandle->numOfPages * pHandle->pageSize; if (pHandle->type == SORT_SINGLESOURCE_SORT) { - SGenericSource* source = taosArrayGetP(pHandle->pOrderedSource, 0); + SSortSource* source = taosArrayGetP(pHandle->pOrderedSource, 0); taosArrayClear(pHandle->pOrderedSource); while (1) { SSDataBlock* pBlock = pHandle->fetchfp(source->param); @@ -652,7 +651,7 @@ STupleHandle* tsortNextTuple(SSortHandle* pHandle) { } int32_t index = tMergeTreeGetChosenIndex(pHandle->pMergeTree); - SExternalMemSource *pSource = pHandle->cmpParam.pSources[index]; + SSortSource *pSource = pHandle->cmpParam.pSources[index]; if (pHandle->needAdjust) { int32_t code = adjustMergeTreeForNextTuple(pSource, pHandle->pMergeTree, pHandle, &pHandle->numOfCompletedSources); diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index e774b8d2e3..bf77e30eaa 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -138,12 +138,12 @@ int32_t docomp(const void* p1, const void* p2, void* param) { int32_t pRightIdx = *(int32_t *)p2; SMsortComparParam *pParam = (SMsortComparParam *)param; - SGenericSource** px = reinterpret_cast(pParam->pSources); + SSortSource** px = reinterpret_cast(pParam->pSources); SArray *pInfo = pParam->orderInfo; - SGenericSource* pLeftSource = px[pLeftIdx]; - SGenericSource* pRightSource = px[pRightIdx]; + SSortSource* pLeftSource = px[pLeftIdx]; + SSortSource* pRightSource = px[pRightIdx]; // this input is exhausted, set the special value to denote this if (pLeftSource->src.rowIndex == -1) { @@ -218,7 +218,7 @@ TEST(testCase, inMem_sort_Test) { pInfo->count = 6; pInfo->type = TSDB_DATA_TYPE_USMALLINT; - SGenericSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); + SSortSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SSortSource))); ps->param = pInfo; tsortAddSource(phandle, ps); @@ -301,7 +301,7 @@ TEST(testCase, external_mem_sort_Test) { SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 128, 3, NULL, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); - SGenericSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); + SSortSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SSortSource))); ps->param = &pInfo[i]; tsortAddSource(phandle, ps); @@ -369,10 +369,10 @@ TEST(testCase, ordered_merge_sort_Test) { tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); tsortSetComparFp(phandle, docomp); - SGenericSource* p[10] = {0}; + SSortSource* p[10] = {0}; _info c[10] = {0}; for(int32_t i = 0; i < 10; ++i) { - p[i] = static_cast(taosMemoryCalloc(1, sizeof(SGenericSource))); + p[i] = static_cast(taosMemoryCalloc(1, sizeof(SSortSource))); c[i].count = 1; c[i].pageRows = 1000; c[i].startVal = i*1000; @@ -396,9 +396,8 @@ TEST(testCase, ordered_merge_sort_Test) { ASSERT_EQ(row++, *(int32_t*) v); } - for(int32_t i = 0; i < 10; ++i) { - taosMemoryFree(p[i]); - } + + taosArrayDestroy(orderInfo); tsortDestroySortHandle(phandle); blockDataDestroy(pBlock); } From c4f67c25fbb05db4f9c6f5703666670f9aef336a Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 18:47:56 +0800 Subject: [PATCH 19/57] fix no return error --- source/libs/function/src/builtinsimpl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index fb6abe3c5d..eb77bce5e5 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -97,6 +97,7 @@ int32_t countFunction(SqlFunctionCtx *pCtx) { *((int64_t *)buf) += numOfElem; SET_VAL(pResInfo, numOfElem, 1); + return TSDB_CODE_SUCCESS; } #define LIST_ADD_N(_res, _col, _start, _rows, _t, numOfElem) \ @@ -167,6 +168,7 @@ int32_t sumFunction(SqlFunctionCtx *pCtx) { // data in the check operation are all null, not output SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1); + return TSDB_CODE_SUCCESS; } bool getSumFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { @@ -435,11 +437,13 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { int32_t minFunction(SqlFunctionCtx *pCtx) { int32_t numOfElems = doMinMaxHelper(pCtx, 1); SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); + return TSDB_CODE_SUCCESS; } int32_t maxFunction(SqlFunctionCtx *pCtx) { int32_t numOfElems = doMinMaxHelper(pCtx, 0); SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); + return TSDB_CODE_SUCCESS; } typedef struct STopBotRes { @@ -589,6 +593,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { // data in the check operation are all null, not output SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1); + return TSDB_CODE_SUCCESS; } void stddevFinalize(SqlFunctionCtx* pCtx) { @@ -716,6 +721,7 @@ int32_t percentileFunction(SqlFunctionCtx *pCtx) { SET_VAL(pResInfo, notNullElems, 1); pResInfo->hasResult = DATA_SET_FLAG; + return TSDB_CODE_SUCCESS; } // TODO set the correct parameter. @@ -783,6 +789,7 @@ int32_t firstFunction(SqlFunctionCtx *pCtx) { } SET_VAL(pResInfo, numOfElems, 1); + return TSDB_CODE_SUCCESS; } int32_t lastFunction(SqlFunctionCtx *pCtx) { @@ -844,6 +851,7 @@ int32_t lastFunction(SqlFunctionCtx *pCtx) { } SET_VAL(pResInfo, numOfElems, 1); + return TSDB_CODE_SUCCESS; } typedef struct SDiffInfo { @@ -1072,6 +1080,7 @@ int32_t diffFunction(SqlFunctionCtx *pCtx) { * 2. current block may be null value */ assert(pCtx->hasNull); + return 0; } else { // for (int t = 0; t < pCtx->tagInfo.numOfTagCols; ++t) { // SqlFunctionCtx* tagCtx = pCtx->tagInfo.pTagCtxList[t]; From c9de8b3b15ad5d81dca55f25c072c87e1a22f77f Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 19:50:24 +0800 Subject: [PATCH 20/57] fix error in sort logic --- source/libs/executor/inc/tsort.h | 1 - source/libs/executor/src/executorimpl.c | 1 + source/libs/executor/src/tsort.c | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index cc5db32666..3c7194de6f 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -50,7 +50,6 @@ typedef struct SMsortComparParam { void **pSources; int32_t numOfSources; SArray *orderInfo; // SArray - bool nullFirst; } SMsortComparParam; typedef struct SSortHandle SSortHandle; diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index f3f52455f0..34f3325a8d 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -4144,6 +4144,7 @@ int32_t loadRemoteDataCallback(void* param, const SDataBuf* pMsg, int32_t code) pSourceDataInfo->status = EX_SOURCE_DATA_READY; tsem_post(&pSourceDataInfo->pEx->ready); + return TSDB_CODE_SUCCESS; } static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 2aa8f6a09d..a052cbe846 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -391,11 +391,11 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) { } if (rightNull) { - return pParam->nullFirst? 1:-1; + return pOrder->nullFirst? 1:-1; } if (leftNull) { - return pParam->nullFirst? -1:1; + return pOrder->nullFirst? -1:1; } void* left1 = colDataGetData(pLeftColInfoData, pLeftSource->src.rowIndex); From 4cc93f9984bdd8839212b3672e93d5c3c757bb1f Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 19:51:28 +0800 Subject: [PATCH 21/57] fix error in sort logic --- source/libs/executor/src/scanoperator.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index f39a18da68..4633300a44 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -576,6 +576,7 @@ static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t } tsem_post(&pScanResInfo->ready); + return TSDB_CODE_SUCCESS; } static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { From 288b50aef2438c8e72f5a01e78159e163118df9e Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 6 Apr 2022 19:53:17 +0800 Subject: [PATCH 22/57] fix error in sort logic --- source/libs/executor/test/sortTests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index bf77e30eaa..5bb184e5b7 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -178,11 +178,11 @@ int32_t docomp(const void* p1, const void* p2, void* param) { } if (rightNull) { - return pParam->nullFirst? 1:-1; + return pOrder->nullFirst? 1:-1; } if (leftNull) { - return pParam->nullFirst? -1:1; + return pOrder->nullFirst? -1:1; } void* left1 = colDataGetData(pLeftColInfoData, pLeftSource->src.rowIndex); From cc2726debec0edb5b2c98d2d89d283328b3cbb19 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 7 Apr 2022 09:35:00 +0000 Subject: [PATCH 23/57] 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 bb18e3c4850fb146fa936d11d3d485f01b378673 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 7 Apr 2022 17:50:06 +0800 Subject: [PATCH 24/57] fix error in sort logic --- source/common/src/tdatablock.c | 7 +++++-- source/libs/executor/inc/tsort.h | 5 +++++ source/libs/executor/src/executorimpl.c | 7 ++----- source/libs/executor/src/tsort.c | 5 ----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 33dc3a2469..44d261bd31 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -192,6 +192,9 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co return numOfRow1; } + if (pSource->hasNull) { + pColumnInfoData->hasNull = pSource->hasNull; + } if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { // Handle the bitmap char* p = taosMemoryRealloc(pColumnInfoData->varmeta.offset, sizeof(int32_t) * (numOfRow1 + numOfRow2)); @@ -313,9 +316,9 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) { } int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) { - assert(pSrc != NULL && pDest != NULL && pDest->info.numOfCols == pSrc->info.numOfCols); + assert(pSrc != NULL && pDest != NULL); - int32_t numOfCols = pSrc->info.numOfCols; + int32_t numOfCols = pDest->info.numOfCols; for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pCol2 = taosArrayGet(pDest->pDataBlock, i); SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, i); diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index 3c7194de6f..03bbe8098c 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -52,6 +52,11 @@ typedef struct SMsortComparParam { SArray *orderInfo; // SArray } SMsortComparParam; +struct STupleHandle { + SSDataBlock* pBlock; + int32_t rowIndex; +}; + typedef struct SSortHandle SSortHandle; typedef struct STupleHandle STupleHandle; diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 4cc1658e64..48b734f3aa 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -302,10 +302,6 @@ SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { } taosArrayPush(pBlock->pDataBlock, &idata); - - if (IS_VAR_DATA_TYPE(idata.info.type)) { - pBlock->info.hasVarCol = true; - } } return pBlock; @@ -4748,7 +4744,8 @@ static void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHan for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); - bool isNull = tsortIsNullVal(pTupleHandle, i); + SColumnInfoData* pColInfoSrc = taosArrayGet(pTupleHandle->pBlock->pDataBlock, i); + bool isNull = colDataIsNull(pColInfoSrc, 0, pTupleHandle->rowIndex, NULL); if (isNull) { colDataAppend(pColInfo, pBlock->info.rows, NULL, true); } else { diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index a052cbe846..b226106e01 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -24,11 +24,6 @@ #include "tutil.h" #include "tcompare.h" -struct STupleHandle { - SSDataBlock* pBlock; - int32_t rowIndex; -}; - struct SSortHandle { int32_t type; From 8da690e575574c36d5e533867582ce2f17bafb57 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 8 Apr 2022 10:25:15 +0800 Subject: [PATCH 25/57] adjust threads num --- source/common/src/tglobal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 4ecacb9d9d..b351536839 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -394,7 +394,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "numOfMnodeReadThreads", tsNumOfMnodeReadThreads, 1, 1024, 0) != 0) return -1; tsNumOfVnodeQueryThreads = tsNumOfCores / 2; - tsNumOfVnodeQueryThreads = TMIN(tsNumOfVnodeQueryThreads, 1); + tsNumOfVnodeQueryThreads = TMAX(tsNumOfVnodeQueryThreads, 1); if (cfgAddInt32(pCfg, "numOfVnodeQueryThreads", tsNumOfVnodeQueryThreads, 1, 1024, 0) != 0) return -1; tsNumOfVnodeFetchThreads = tsNumOfCores / 2; @@ -402,11 +402,11 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "numOfVnodeFetchThreads", tsNumOfVnodeFetchThreads, 1, 1024, 0) != 0) return -1; tsNumOfVnodeWriteThreads = tsNumOfCores; - tsNumOfVnodeWriteThreads = TMIN(tsNumOfVnodeWriteThreads, 1); + tsNumOfVnodeWriteThreads = TMAX(tsNumOfVnodeWriteThreads, 1); if (cfgAddInt32(pCfg, "numOfVnodeWriteThreads", tsNumOfVnodeWriteThreads, 1, 1024, 0) != 0) return -1; tsNumOfVnodeSyncThreads = tsNumOfCores / 2; - tsNumOfVnodeSyncThreads = TMIN(tsNumOfVnodeSyncThreads, 1); + tsNumOfVnodeSyncThreads = TMAX(tsNumOfVnodeSyncThreads, 1); if (cfgAddInt32(pCfg, "numOfVnodeSyncThreads", tsNumOfVnodeSyncThreads, 1, 1024, 0) != 0) return -1; tsNumOfVnodeMergeThreads = tsNumOfCores / 8; @@ -414,7 +414,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "numOfVnodeMergeThreads", tsNumOfVnodeMergeThreads, 1, 1024, 0) != 0) return -1; tsNumOfQnodeQueryThreads = tsNumOfCores / 2; - tsNumOfQnodeQueryThreads = TMIN(tsNumOfQnodeQueryThreads, 1); + tsNumOfQnodeQueryThreads = TMAX(tsNumOfQnodeQueryThreads, 1); if (cfgAddInt32(pCfg, "numOfQnodeQueryThreads", tsNumOfQnodeQueryThreads, 1, 1024, 0) != 0) return -1; tsNumOfQnodeFetchThreads = tsNumOfCores / 2; From b0184c201f581ecd181c4926bdcf8bd9557bb785 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 8 Apr 2022 10:27:27 +0800 Subject: [PATCH 26/57] 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 afea903a9826c6ffd04a544b594e669b82bd7fe0 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 03:30:11 +0000 Subject: [PATCH 27/57] 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 28/57] 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 29/57] 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 30/57] 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 31/57] 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 1f8d2ea4465d58f3a16c24f2fc37f187bcb8a8b3 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 8 Apr 2022 14:17:32 +0800 Subject: [PATCH 32/57] : fix index map error from table scan to sort output --- cmake/cmake.define | 8 +++--- include/common/tdatablock.h | 2 +- source/common/src/tdatablock.c | 8 ++++-- source/dnode/vnode/src/tsdb/tsdbSma.c | 2 ++ source/libs/executor/inc/executorimpl.h | 3 ++- source/libs/executor/inc/tsort.h | 2 +- source/libs/executor/src/executorimpl.c | 33 +++++++++++++++++++----- source/libs/executor/src/groupoperator.c | 4 +-- source/libs/executor/src/tsort.c | 6 +++-- source/libs/executor/test/sortTests.cpp | 6 ++--- 10 files changed, 52 insertions(+), 22 deletions(-) diff --git a/cmake/cmake.define b/cmake/cmake.define index 03feca37bd..639ae9ca3f 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -36,10 +36,10 @@ IF (TD_WINDOWS) ENDIF () ELSE () - #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") - #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") + #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index d6d82875e0..0f9216a541 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -177,7 +177,7 @@ void colDataTrim(SColumnInfoData* pColumnInfoData); size_t blockDataGetNumOfCols(const SSDataBlock* pBlock); size_t blockDataGetNumOfRows(const SSDataBlock* pBlock); -int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc); +int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pIndexMap); int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex, int32_t pageSize); int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 44d261bd31..abcb4283d2 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -315,13 +315,17 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) { return 0; } -int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) { +int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pIndexMap) { assert(pSrc != NULL && pDest != NULL); int32_t numOfCols = pDest->info.numOfCols; for (int32_t i = 0; i < numOfCols; ++i) { + int32_t mapIndex = i; + if(pIndexMap) { + mapIndex = *(int32_t*)taosArrayGet(pIndexMap, i); + } SColumnInfoData* pCol2 = taosArrayGet(pDest->pDataBlock, i); - SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, i); + SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, mapIndex); uint32_t oldLen = colDataGetLength(pCol2, pDest->info.rows); uint32_t newLen = colDataGetLength(pCol1, pSrc->info.rows); diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index 87660e6fe1..ae0befd524 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -1437,6 +1437,7 @@ int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) { tdDestroyTSma(&vCreateSmaReq.tSma); // TODO: return directly or go on follow steps? + return TSDB_CODE_SUCCESS; } int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) { @@ -1466,6 +1467,7 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) { tsdbTSmaSub(pTsdb, 1); // TODO: return directly or go on follow steps? + return TSDB_CODE_SUCCESS; } #if 0 diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 57edc40007..fc59412b75 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -614,6 +614,7 @@ typedef struct SSortOperatorInfo { SSDataBlock *pDataBlock; SArray* pSortInfo; SSortHandle *pSortHandle; + SArray* inputSlotMap; // for index map from table scan output int32_t bufPageSize; int32_t numOfRowsInRes; @@ -651,7 +652,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SLimit* pLimit, SExecTaskInfo* pTaskInfo); -SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExecTaskInfo* pTaskInfo); +SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SArray* pIndexMap, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pSortInfo, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName, SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId); diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index 03bbe8098c..f012cc2448 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -68,7 +68,7 @@ typedef int32_t (*_sort_merge_compar_fn_t)(const void* p1, const void* p2, void* * @param type * @return */ -SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr); +SSortHandle* tsortCreateSortHandle(SArray* pOrderInfo, SArray* pIndexMap, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr); /** * diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 20899098cc..9b2772ddfa 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -4953,7 +4953,7 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator, bool* newgroup) { } int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, NULL, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, pInfo->binfo.pRes, "GET_TASKID(pTaskInfo)"); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); @@ -5100,7 +5100,7 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator, bool* newgroup) { } int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, pInfo->bufPageSize, numOfBufPage, + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->inputSlotMap, SORT_SINGLESOURCE_SORT, pInfo->bufPageSize, numOfBufPage, pInfo->pDataBlock, pTaskInfo->id.str); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); @@ -5119,7 +5119,7 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator, bool* newgroup) { return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, pInfo->numOfRowsInRes); } -SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SArray* pIndexMap, SExecTaskInfo* pTaskInfo) { SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); int32_t rowSize = pResBlock->info.rowSize; @@ -5137,6 +5137,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR pInfo->numOfRowsInRes = 1024; pInfo->pDataBlock = pResBlock; pInfo->pSortInfo = pSortInfo; + pInfo->inputSlotMap = pIndexMap; pOperator->name = "SortOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; @@ -6265,6 +6266,7 @@ static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) { pInfo->pDataBlock = blockDataDestroy(pInfo->pDataBlock); taosArrayDestroy(pInfo->pSortInfo); + taosArrayDestroy(pInfo->inputSlotMap); } void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) { @@ -7065,6 +7067,7 @@ static SArray* extractScanColumnId(SNodeList* pNodeList); static SArray* extractColumnInfo(SNodeList* pNodeList); static SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols); static SArray* createSortInfo(SNodeList* pNodeList); +static SArray* createIndexMap(SNodeList* pNodeList); SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId, STableGroupInfo* pTableGroupInfo) { @@ -7183,7 +7186,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); SArray* info = createSortInfo(pSortPhyNode->pSortKeys); - return createSortOperatorInfo(op, pResBlock, info, pTaskInfo); + SArray* slotMap = createIndexMap(pSortPhyNode->pTargets); + return createSortOperatorInfo(op, pResBlock, info, slotMap, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW == nodeType(pPhyNode)) { size_t size = LIST_LENGTH(pPhyNode->pChildren); assert(size == 1); @@ -7303,8 +7307,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); @@ -7326,6 +7329,24 @@ SArray* createSortInfo(SNodeList* pNodeList) { return pList; } +SArray* createIndexMap(SNodeList* pNodeList) { + size_t numOfCols = LIST_LENGTH(pNodeList); + SArray* pList = taosArrayInit(numOfCols, sizeof(int32_t)); + if (pList == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return pList; + } + + for (int32_t i = 0; i < numOfCols; ++i) { + STargetNode* pTarget = (STargetNode*)nodesListGetNode(pNodeList, i); + + SColumnNode* pColNode = (SColumnNode*)pTarget->pExpr; + taosArrayPush(pList, &pColNode->slotId); + } + + return pList; +} + SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols) { size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchInfo)); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index b3a8e09f16..7f5935d339 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -365,12 +365,12 @@ static SSDataBlock* doPartitionData(SOperatorInfo* pOperator, bool* newgroup) { } int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; - pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, pInfo->bufPageSize, numOfBufPage, + pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->inputSlotMap, SORT_SINGLESOURCE_SORT, pInfo->bufPageSize, numOfBufPage, pInfo->pDataBlock, pTaskInfo->id.str); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock); - SGenericSource* ps = taosMemoryCalloc(1, sizeof(SGenericSource)); + SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); ps->param = pOperator->pDownstream[0]; tsortAddSource(pInfo->pSortHandle, ps); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index b226106e01..965cf14400 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -32,6 +32,7 @@ struct SSortHandle { SDiskbasedBuf *pBuf; SArray *pSortInfo; + SArray *pIndexMap; SArray *pOrderedSource; _sort_fetch_block_fn_t fetchfp; @@ -85,13 +86,14 @@ static SSDataBlock* createDataBlock_rv(SSchema* pSchema, int32_t numOfCols) { * @param type * @return */ -SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr) { +SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, SArray* pIndexMap, int32_t type, int32_t pageSize, int32_t numOfPages, SSDataBlock* pBlock, const char* idstr) { SSortHandle* pSortHandle = taosMemoryCalloc(1, sizeof(SSortHandle)); pSortHandle->type = type; pSortHandle->pageSize = pageSize; pSortHandle->numOfPages = numOfPages; pSortHandle->pSortInfo = pSortInfo; + pSortHandle->pIndexMap = pIndexMap; pSortHandle->pDataBlock = createOneDataBlock(pBlock); pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES); @@ -529,7 +531,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { pHandle->pDataBlock = createOneDataBlock(pBlock); } - int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock); + int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock, pHandle->pIndexMap); if (code != 0) { return code; } diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp index 5bb184e5b7..efa0581fd0 100644 --- a/source/libs/executor/test/sortTests.cpp +++ b/source/libs/executor/test/sortTests.cpp @@ -209,7 +209,7 @@ TEST(testCase, inMem_sort_Test) { SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 1024, 5, NULL, "test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, NULL, SORT_SINGLESOURCE_SORT, 1024, 5, NULL, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); _info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info)); @@ -298,7 +298,7 @@ TEST(testCase, external_mem_sort_Test) { SArray* orderInfo = taosArrayInit(1, sizeof(SBlockOrderInfo)); taosArrayPush(orderInfo, &oi); - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_SINGLESOURCE_SORT, 128, 3, NULL, "test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, NULL, SORT_SINGLESOURCE_SORT, 128, 3, NULL, "test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); SSortSource* ps = static_cast(taosMemoryCalloc(1, sizeof(SSortSource))); @@ -365,7 +365,7 @@ TEST(testCase, ordered_merge_sort_Test) { taosArrayPush(pBlock->pDataBlock, &colInfo); } - SSortHandle* phandle = tsortCreateSortHandle(orderInfo, SORT_MULTISOURCE_MERGE, 1024, 5, pBlock,"test_abc"); + SSortHandle* phandle = tsortCreateSortHandle(orderInfo, NULL, SORT_MULTISOURCE_MERGE, 1024, 5, pBlock,"test_abc"); tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock); tsortSetComparFp(phandle, docomp); From 0e1a27c750b842d686e905fb16a4b0d6917e393b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 06:19:58 +0000 Subject: [PATCH 33/57] 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 65a21314933ba9ec4892b1e5c301d18436591067 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 8 Apr 2022 14:40:02 +0800 Subject: [PATCH 34/57] : fix index map error from table scan to sort output --- source/libs/executor/src/executorimpl.c | 30 +++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 9b2772ddfa..0cc73bb2cd 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -7066,7 +7066,7 @@ static SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo); static SArray* extractScanColumnId(SNodeList* pNodeList); static SArray* extractColumnInfo(SNodeList* pNodeList); static SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols); -static SArray* createSortInfo(SNodeList* pNodeList); +static SArray* createSortInfo(SNodeList* pNodeList, SNodeList* pNodeListTarget); static SArray* createIndexMap(SNodeList* pNodeList); SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, @@ -7185,7 +7185,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode; SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); - SArray* info = createSortInfo(pSortPhyNode->pSortKeys); + SArray* info = createSortInfo(pSortPhyNode->pSortKeys, pSortPhyNode->pTargets); SArray* slotMap = createIndexMap(pSortPhyNode->pTargets); return createSortOperatorInfo(op, pResBlock, info, slotMap, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW == nodeType(pPhyNode)) { @@ -7298,7 +7298,7 @@ SArray* extractColumnInfo(SNodeList* pNodeList) { return pList; } -SArray* createSortInfo(SNodeList* pNodeList) { +SArray* createSortInfo(SNodeList* pNodeList, SNodeList* pNodeListTarget) { size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(SBlockOrderInfo)); if (pList == NULL) { @@ -7313,16 +7313,22 @@ SArray* createSortInfo(SNodeList* pNodeList) { bi.nullFirst = (pSortKey->nullOrder == NULL_ORDER_FIRST); SColumnNode* pColNode = (SColumnNode*)pSortKey->pExpr; - bi.slotId = pColNode->slotId; - // pColNode->order; - // SColumn c = {0}; - // c.slotId = pColNode->slotId; - // c.colId = pColNode->colId; - // c.type = pColNode->node.resType.type; - // c.bytes = pColNode->node.resType.bytes; - // c.precision = pColNode->node.resType.precision; - // c.scale = pColNode->node.resType.scale; + bool found = false; + for (int32_t j = 0; j < LIST_LENGTH(pNodeListTarget); ++j) { + STargetNode* pTarget = (STargetNode*)nodesListGetNode(pNodeListTarget, j); + + SColumnNode* pColNodeT = (SColumnNode*)pTarget->pExpr; + if(pColNode->slotId == pColNodeT->slotId){ // to find slotId in PhysiSort OutputDataBlockDesc + bi.slotId = pTarget->slotId; + found = true; + break; + } + } + + if(!found){ + qError("sort slot id does not found"); + } taosArrayPush(pList, &bi); } From 94bcbf6bacc70a54e7711ef6b82bd4f4c30c3c7b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 06:41:42 +0000 Subject: [PATCH 35/57] 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 ca7eee7451a3b92443a0e952b20035dea30a96d2 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Fri, 8 Apr 2022 14:42:30 +0800 Subject: [PATCH 36/57] add log --- include/common/tmsg.h | 1 + tests/test/c/tmqSim.c | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 61da9cb213..aeaf5832b9 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2273,6 +2273,7 @@ typedef struct { char cgroup[TSDB_CGROUP_LEN]; int64_t currentOffset; + uint64_t reqId; char topic[TSDB_TOPIC_FNAME_LEN]; } SMqPollReq; diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 22d8c2b735..7372745cb8 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -274,17 +274,11 @@ int main(int32_t argc, char *argv[]) { loop_consume(tmq); - err = tmq_unsubscribe(tmq); - ASSERT(err == TMQ_RESP_ERR__SUCCESS); - - - #if 0 err = tmq_unsubscribe(tmq); if (err) { printf("tmq_unsubscribe() fail, reason: %s\n", tmq_err2str(err)); exit(-1); } - #endif return 0; } From 742b2918ff443b32826b6d32b8b27549aba1f034 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 8 Apr 2022 06:49:07 +0000 Subject: [PATCH 37/57] 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 6df2fae1a231b9d5d7960f5f34be0eb1bb9da758 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Fri, 8 Apr 2022 15:26:02 +0800 Subject: [PATCH 38/57] fix compile --- source/client/src/tmq.c | 5 +++-- source/dnode/mnode/impl/src/mndSubscribe.c | 20 +++++++++++--------- source/dnode/vnode/src/tq/tq.c | 4 ++-- source/libs/transport/src/transCli.c | 4 ++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index a6e5fee2d1..5893a14bd5 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -1149,6 +1149,7 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo pReq->consumerId = tmq->consumerId; pReq->epoch = tmq->epoch; pReq->currentOffset = reqOffset; + pReq->reqId = generateRequestId(); pReq->head.vgId = htonl(pVg->vgId); pReq->head.contLen = htonl(sizeof(SMqPollReq)); @@ -1279,7 +1280,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { .len = sizeof(SMqPollReq), .handle = NULL, }; - sendInfo->requestId = generateRequestId(); + sendInfo->requestId = pReq->reqId; sendInfo->requestObjRefId = 0; sendInfo->param = pParam; sendInfo->fp = tmqPollCb; @@ -1288,7 +1289,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { int64_t transporterId = 0; /*printf("send poll\n");*/ atomic_add_fetch_32(&tmq->waitingRequest, 1); - tscDebug("consumer %ld send poll: vg %d, epoch %d, req offset %ld", tmq->consumerId, pVg->vgId, tmq->epoch, pVg->currentOffset); + tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId, pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId); /*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/ asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo); pVg->pollCnt++; diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index 8078338238..dbd5e43b6d 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -60,7 +60,7 @@ static int32_t mndProcessResetOffsetReq(SNodeMsg *pMsg); static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqTopicObj *pTopic, const char *cgroup, const SMqConsumerEp *pConsumerEp); -static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp); +static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, const char* topicName); static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, const char* oldTopicName); int32_t mndInitSubscribe(SMnode *pMnode) { @@ -102,12 +102,13 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj return pSub; } -static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsumerEp *pConsumerEp) { +static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsumerEp *pConsumerEp, const char* topicName) { SMqMVRebReq req = { .vgId = pConsumerEp->vgId, .oldConsumerId = pConsumerEp->oldConsumerId, .newConsumerId = pConsumerEp->consumerId, }; + req.topic = strdup(topicName); int32_t tlen = tEncodeSMqMVRebReq(NULL, &req); void *buf = taosMemoryMalloc(sizeof(SMsgHead) + tlen); @@ -122,6 +123,7 @@ static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsume void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); tEncodeSMqMVRebReq(&abuf, &req); + taosMemoryFree(req.topic); *pBuf = buf; *pLen = tlen; @@ -129,12 +131,12 @@ static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsume return 0; } -static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp) { +static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, const char* topicName) { ASSERT(pConsumerEp->oldConsumerId != -1); void *buf; int32_t tlen; - if (mndBuildRebalanceMsg(&buf, &tlen, pConsumerEp) < 0) { + if (mndBuildRebalanceMsg(&buf, &tlen, pConsumerEp, topicName) < 0) { return -1; } @@ -502,10 +504,10 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { pConsumerEp->epoch = 0; taosArrayPush(pSubConsumer->vgInfo, pConsumerEp); + char topic[TSDB_TOPIC_FNAME_LEN]; + char cgroup[TSDB_CGROUP_LEN]; + mndSplitSubscribeKey(pSub->key, topic, cgroup); if (pConsumerEp->oldConsumerId == -1) { - char topic[TSDB_TOPIC_FNAME_LEN]; - char cgroup[TSDB_CGROUP_LEN]; - mndSplitSubscribeKey(pSub->key, topic, cgroup); SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic); mInfo("mq set conn: assign vgroup %d of topic %s to consumer %" PRId64 " cgroup: %s", pConsumerEp->vgId, @@ -517,7 +519,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { mInfo("mq rebalance: assign vgroup %d, from consumer %" PRId64 " to consumer %" PRId64 "", pConsumerEp->vgId, pConsumerEp->oldConsumerId, pConsumerEp->consumerId); - mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp); + mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp, topic); } } } @@ -849,7 +851,7 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) { pConsumerEp->consumerId); mndPersistMqSetConnReq(pMnode, pTrans, pTopic, cgroup, pConsumerEp); } else { - mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp); + mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp, newTopicName); } // to trigger rebalance at once, do not set status active /*atomic_store_32(&pConsumer->status, MQ_CONSUMER_STATUS__ACTIVE);*/ diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index fbb515f29c..71a41c13d6 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -265,7 +265,7 @@ 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, offset %ld %ld, reqId %lu", consumerId, pReq->epoch, pTq->pVnode->vgId, pReq->currentOffset, fetchOffset, pReq->reqId); SMqPollRsp rsp = { /*.consumerId = consumerId,*/ @@ -308,7 +308,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { return 0; } - vDebug("poll topic %s from consumer %ld (epoch %d)", pTopic->topicName, consumerId, pReq->epoch); + vDebug("poll topic %s from consumer %ld (epoch %d) %s", pTopic->topicName, consumerId, pReq->epoch, pTopic->topicName); rsp.reqOffset = pReq->currentOffset; rsp.skipLogNum = 0; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d9c288a39b..9bd86a2e22 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -943,8 +943,8 @@ void transSendRequest(void* shandle, const char* ip, uint32_t port, STransMsg* p SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[index]; - tDebug("send request at thread:%d %p, dst: %s:%d", index, pMsg, ip, port); - transSendAsync(thrd->asyncPool, &(cliMsg->q)); + tDebug("send request at thread:%d %p, dst: %s:%d, app:%p", index, pMsg, ip, port, pMsg->ahandle); + ASSERT(transSendAsync(thrd->asyncPool, &(cliMsg->q)) == 0); } void transSendRecv(void* shandle, const char* ip, uint32_t port, STransMsg* pReq, STransMsg* pRsp) { From f492ae743aadb7a947bac2e0130a12713c74c8a4 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 7 Apr 2022 19:06:01 +0800 Subject: [PATCH 39/57] feat: send monitor information in multi-process mode --- include/common/tmsg.h | 12 + include/common/tmsgdef.h | 9 + include/libs/monitor/monitor.h | 153 +++++++---- include/os/osSysinfo.h | 4 +- source/dnode/mgmt/dm/dmHandle.c | 3 + source/dnode/mgmt/dm/dmMonitor.c | 34 ++- source/dnode/mgmt/dm/dmWorker.c | 3 + source/dnode/mgmt/inc/dmInt.h | 10 +- source/libs/monitor/inc/monInt.h | 49 ++-- source/libs/monitor/src/monMsg.c | 54 ++++ source/libs/monitor/src/monitor.c | 326 +++++++++++++++++------- source/libs/monitor/test/CMakeLists.txt | 8 +- source/libs/monitor/test/monTest.cpp | 192 ++++++++------ source/os/src/osSysinfo.c | 52 +++- 14 files changed, 649 insertions(+), 260 deletions(-) create mode 100644 source/libs/monitor/src/monMsg.c diff --git a/include/common/tmsg.h b/include/common/tmsg.h index fc7e994cbb..1b24b50ae2 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -679,6 +679,18 @@ typedef struct { char charset[TD_LOCALE_LEN]; // tsCharset } SClusterCfg; +typedef struct { + int32_t openVnodes; + int32_t totalVnodes; + int32_t masterNum; + int64_t numOfSelectReqs; + int64_t numOfInsertReqs; + int64_t numOfInsertSuccessReqs; + int64_t numOfBatchInsertReqs; + int64_t numOfBatchInsertSuccessReqs; + int64_t errors; +} SVnodesStat; + typedef struct { int32_t vgId; int8_t role; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 1d4667cda0..bdfe20bfa1 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -216,6 +216,15 @@ enum { TD_NEW_MSG_SEG(TDMT_SCH_MSG) TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "scheduler-link-broken", NULL, NULL) + // Monitor info exchange between processes + TD_NEW_MSG_SEG(TDMT_MON_MSG) + TD_DEF_MSG_TYPE(TDMT_MON_MM_INFO, "monitor-minfo", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MON_VM_INFO, "monitor-vinfo", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MON_QM_INFO, "monitor-qinfo", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MON_SM_INFO, "monitor-sinfo", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MON_BM_INFO, "monitor-binfo", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MON_VM_LOAD, "monitor-vload", NULL, NULL) + #if defined(TD_MSG_NUMBER_) TDMT_MAX #endif diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index fc7a4bb95d..342796b070 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -19,6 +19,7 @@ #include "tarray.h" #include "tdef.h" #include "tlog.h" +#include "tmsg.h" #ifdef __cplusplus extern "C" { @@ -29,6 +30,44 @@ extern "C" { #define MON_VER_LEN 12 #define MON_LOG_LEN 1024 +typedef struct { + int64_t ts; + ELogLevel level; + char content[MON_LOG_LEN]; +} SMonLogItem; + +typedef struct { + SArray *logs; // array of SMonLogItem + int32_t numOfErrorLogs; + int32_t numOfInfoLogs; + int32_t numOfDebugLogs; + int32_t numOfTraceLogs; +} SMonLogs; + +typedef struct { + char name[TSDB_FILENAME_LEN]; + int8_t level; + SDiskSize size; +} SMonDiskDesc; + +typedef struct { + double cpu_engine; + double cpu_system; + float cpu_cores; + int64_t mem_engine; // KB + int64_t mem_system; // KB + int64_t mem_total; // KB + int64_t disk_engine; // Byte + int64_t disk_used; // Byte + int64_t disk_total; // Byte + int64_t net_in; // bytes + int64_t net_out; // bytes + int64_t io_read; // bytes + int64_t io_write; // bytes + int64_t io_read_disk; // bytes + int64_t io_write_disk; // bytes +} SMonSysInfo; + typedef struct { int32_t dnode_id; char dnode_ep[TSDB_EP_LEN]; @@ -36,6 +75,19 @@ typedef struct { int32_t protocol; } SMonBasicInfo; +typedef struct { + float uptime; // day + int8_t has_mnode; + SMonDiskDesc logdir; + SMonDiskDesc tempdir; +} SMonDnodeInfo; + +typedef struct { + SMonBasicInfo basic; + SMonDnodeInfo dnode; + SMonSysInfo sys; +} SMonDmInfo; + typedef struct { int32_t dnode_id; char dnode_ep[TSDB_EP_LEN]; @@ -87,46 +139,57 @@ typedef struct { } SMonGrantInfo; typedef struct { - float uptime; // day - double cpu_engine; - double cpu_system; - float cpu_cores; - int64_t mem_engine; // KB - int64_t mem_system; // KB - int64_t mem_total; // KB - int64_t disk_engine; // Byte - int64_t disk_used; // Byte - int64_t disk_total; // Byte - int64_t net_in; // bytes - int64_t net_out; // bytes - int64_t io_read; // bytes - int64_t io_write; // bytes - int64_t io_read_disk; // bytes - int64_t io_write_disk; // bytes - int64_t req_select; - int64_t req_insert; - int64_t req_insert_success; - int64_t req_insert_batch; - int64_t req_insert_batch_success; - int32_t errors; - int32_t vnodes_num; - int32_t masters; - int8_t has_mnode; -} SMonDnodeInfo; + SMonClusterInfo cluster; + SMonVgroupInfo vgroup; + SMonGrantInfo grant; + SMonSysInfo sys; + SMonLogs logs; +} SMonMmInfo; + +int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); +int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); +void tFreeSMonMmInfo(SMonMmInfo *pInfo); typedef struct { - char name[TSDB_FILENAME_LEN]; - int8_t level; - SDiskSize size; -} SMonDiskDesc; - -typedef struct { - SArray *datadirs; // array of SMonDiskDesc - SMonDiskDesc logdir; - SMonDiskDesc tempdir; + SArray *datadirs; // array of SMonDiskDesc } SMonDiskInfo; -typedef struct SMonInfo SMonInfo; +typedef struct { + SMonDiskInfo tfs; + SVnodesStat vstat; + SMonSysInfo sys; + SMonLogs logs; +} SMonVmInfo; + +int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); +int32_t tDeserializeSMonVMmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); +void tFreeSMonVmInfo(SMonVmInfo *pInfo); + +typedef struct { + SMonSysInfo sys; + SMonLogs logs; +} SMonQmInfo; + +int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); +int32_t tDeserializeSMonQMmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); +void tFreeSMonQmInfo(SMonQmInfo *pInfo); + +typedef struct { + SMonSysInfo sys; + SMonLogs logs; +} SMonSmInfo; + +int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); +int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); +void tFreeSMonSmInfo(SMonSmInfo *pInfo); +typedef struct { + SMonSysInfo sys; + SMonLogs logs; +} SMonBmInfo; + +int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); +int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); +void tFreeSMonBmInfo(SMonBmInfo *pInfo); typedef struct { const char *server; @@ -138,16 +201,14 @@ typedef struct { int32_t monInit(const SMonCfg *pCfg); void monCleanup(); void monRecordLog(int64_t ts, ELogLevel level, const char *content); - -SMonInfo *monCreateMonitorInfo(); -void monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo); -void monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo); -void monSetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo); -void monSetGrantInfo(SMonInfo *pMonitor, SMonGrantInfo *pInfo); -void monSetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo); -void monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo); -void monSendReport(SMonInfo *pMonitor); -void monCleanupMonitorInfo(SMonInfo *pMonitor); +int32_t monGetLogs(SMonLogs *logs); +void monSetDmInfo(SMonDmInfo *pInfo); +void monSetMmInfo(SMonMmInfo *pInfo); +void monSetVmInfo(SMonVmInfo *pInfo); +void monSetQmInfo(SMonQmInfo *pInfo); +void monSetSmInfo(SMonSmInfo *pInfo); +void monSetBmInfo(SMonBmInfo *pInfo); +void monSendReport(); #ifdef __cplusplus } diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index e1cc6f7829..022f11bb0e 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -44,8 +44,8 @@ int32_t taosGetTotalMemory(int64_t *totalKB); int32_t taosGetProcMemory(int64_t *usedKB); int32_t taosGetSysMemory(int64_t *usedKB); int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize); -int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes); -int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes); +void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes); +void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes); void taosKillSystem(); int32_t taosGetSystemUUID(char *uid, int32_t uidlen); diff --git a/source/dnode/mgmt/dm/dmHandle.c b/source/dnode/mgmt/dm/dmHandle.c index cb712bfb48..40d85b2a9a 100644 --- a/source/dnode/mgmt/dm/dmHandle.c +++ b/source/dnode/mgmt/dm/dmHandle.c @@ -212,4 +212,7 @@ void dmInitMsgHandle(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessStatusMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); + + // Monitor info exchange between processes + dndSetMsgHandle(pWrapper, TDMT_MON_DISK_INFO, dmProcessStatusMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/dm/dmMonitor.c b/source/dnode/mgmt/dm/dmMonitor.c index 22d9086971..7117bc5d12 100644 --- a/source/dnode/mgmt/dm/dmMonitor.c +++ b/source/dnode/mgmt/dm/dmMonitor.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmInt.h" static int32_t dmGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo) { tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name)); @@ -104,4 +104,36 @@ void dmSendMonitorReport(SDnode *pDnode) { monSendReport(pMonitor); monCleanupMonitorInfo(pMonitor); +} + +int32_t dmSetDiskInfo(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { + SDnode *pDnode = pMgmt->pDnode; + SMonDiskInfo info = {0}; + + if (tDeserializeSMonDiskInfo(pMsg->rpcMsg.pCont, pMsg->rpcMsg.contLen, &info) != 0) { + dError("failed to parse diskinfo since %s", terrstr()); + return 0; + } + + taosWLockLatch(&pMgmt->latch); + memcpy(&pMgmt->diskInfo, &info, sizeof(SMonDiskInfo)); + taosWUnLockLatch(&pMgmt->latch); + + return 0; +} + +int32_t dmSetVnodeStat(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { + SDnode *pDnode = pMgmt->pDnode; + SVnodesStat info = {0}; + + if (tDeserializeSMonDiskInfo(pMsg->rpcMsg.pCont, pMsg->rpcMsg.contLen, &info) != 0) { + dError("failed to parse diskinfo since %s", terrstr()); + return 0; + } + + taosWLockLatch(&pMgmt->latch); + memcpy(&pMgmt->diskInfo, &info, sizeof(SMonDiskInfo)); + taosWUnLockLatch(&pMgmt->latch); + + return 0; } \ No newline at end of file diff --git a/source/dnode/mgmt/dm/dmWorker.c b/source/dnode/mgmt/dm/dmWorker.c index ec7392d7e4..1d11c4d25b 100644 --- a/source/dnode/mgmt/dm/dmWorker.c +++ b/source/dnode/mgmt/dm/dmWorker.c @@ -78,6 +78,9 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { case TDMT_MND_GRANT_RSP: code = dmProcessGrantRsp(pMgmt, pMsg); break; + case TDMT_MON_DISK_INFO_RSP: + code = dmSetDiskInfo(pMgmt, pMsg); + break; default: code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg); break; diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/inc/dmInt.h index 5dcd1be47c..d7358d0ca4 100644 --- a/source/dnode/mgmt/inc/dmInt.h +++ b/source/dnode/mgmt/inc/dmInt.h @@ -37,6 +37,11 @@ typedef struct SDnodeMgmt { const char *path; SDnode *pDnode; SMgmtWrapper *pWrapper; + + // monitor infos + SMonDiskInfo diskInfo; + SMonVnodesStat vnodesStat; + SMonVnodesLoad vnodesLoad; } SDnodeMgmt; // dmFile.c @@ -54,7 +59,10 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); // dmMonitor.c -void dmSendMonitorReport(SDnode *pDnode); +int32_t dmSetDiskInfo(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t dmSetVnodesStat(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t dmSetVnodesLoad(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); +void dmSendMonitorReport(SDnode *pDnode); // dmWorker.c int32_t dmStartThread(SDnodeMgmt *pMgmt); diff --git a/source/libs/monitor/inc/monInt.h b/source/libs/monitor/inc/monInt.h index 452c38f66b..4b10aacdee 100644 --- a/source/libs/monitor/inc/monInt.h +++ b/source/libs/monitor/inc/monInt.h @@ -18,43 +18,32 @@ #include "monitor.h" -#include "tarray.h" #include "tjson.h" typedef struct { - int64_t ts; - ELogLevel level; - char content[MON_LOG_LEN]; -} SMonLogItem; - -typedef struct { - int64_t time; - int64_t req_select; - int64_t req_insert; - int64_t req_insert_batch; - int64_t net_in; - int64_t net_out; - int64_t io_read; - int64_t io_write; - int64_t io_read_disk; - int64_t io_write_disk; -} SMonState; - -typedef struct SMonInfo { - int64_t curTime; - SMonState lastState; - SArray *logs; // array of SMonLogItem - SJson *pJson; + int64_t curTime; + int64_t lastTime; + SJson *pJson; + SMonLogs logs; + SMonDmInfo dmInfo; + SMonMmInfo mmInfo; + SMonVmInfo vmInfo; + SMonSmInfo smInfo; + SMonQmInfo qmInfo; + SMonBmInfo bmInfo; } SMonInfo; typedef struct { TdThreadMutex lock; - SArray *logs; // array of SMonLogItem - int32_t maxLogs; - const char *server; - uint16_t port; - bool comp; - SMonState state; + SArray *logs; // array of SMonLogItem + SMonCfg cfg; + int64_t lastTime; + SMonDmInfo dmInfo; + SMonMmInfo mmInfo; + SMonVmInfo vmInfo; + SMonSmInfo smInfo; + SMonQmInfo qmInfo; + SMonBmInfo bmInfo; } SMonitor; #ifdef __cplusplus diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c new file mode 100644 index 0000000000..27d35d266d --- /dev/null +++ b/source/libs/monitor/src/monMsg.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "monInt.h" +#include "tcoding.h" +#include "tencode.h" + +int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); +int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); +void tFreeSMonMmInfo(SMonMmInfo *pInfo) { + taosArrayDestroy(pInfo->logs.logs); + pInfo->logs.logs = NULL; +} + +int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); +int32_t tDeserializeSMonVMmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); +void tFreeSMonVmInfo(SMonVmInfo *pInfo) { + taosArrayDestroy(pInfo->logs.logs); + pInfo->logs.logs = NULL; +} + +int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); +int32_t tDeserializeSMonQMmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); +void tFreeSMonQmInfo(SMonQmInfo *pInfo) { + taosArrayDestroy(pInfo->logs.logs); + pInfo->logs.logs = NULL; +} + +int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); +int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); +void tFreeSMonSmInfo(SMonSmInfo *pInfo) { + taosArrayDestroy(pInfo->logs.logs); + pInfo->logs.logs = NULL; +} + +int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); +int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); +void tFreeSMonBmInfo(SMonBmInfo *pInfo) { + taosArrayDestroy(pInfo->logs.logs); + pInfo->logs.logs = NULL; +} \ No newline at end of file diff --git a/source/libs/monitor/src/monitor.c b/source/libs/monitor/src/monitor.c index b92c08d51c..1938b0d859 100644 --- a/source/libs/monitor/src/monitor.c +++ b/source/libs/monitor/src/monitor.c @@ -17,7 +17,6 @@ #include "monInt.h" #include "taoserror.h" #include "thttp.h" -#include "tlog.h" #include "ttime.h" static SMonitor tsMonitor = {0}; @@ -25,7 +24,7 @@ static SMonitor tsMonitor = {0}; void monRecordLog(int64_t ts, ELogLevel level, const char *content) { taosThreadMutexLock(&tsMonitor.lock); int32_t size = taosArrayGetSize(tsMonitor.logs); - if (size < tsMonitor.maxLogs) { + if (size < tsMonitor.cfg.maxLogs) { SMonLogItem item = {.ts = ts, .level = level}; SMonLogItem *pItem = taosArrayPush(tsMonitor.logs, &item); if (pItem != NULL) { @@ -35,6 +34,68 @@ void monRecordLog(int64_t ts, ELogLevel level, const char *content) { taosThreadMutexUnlock(&tsMonitor.lock); } +int32_t monGetLogs(SMonLogs *logs) { + taosThreadMutexLock(&tsMonitor.lock); + logs->logs = taosArrayDup(tsMonitor.logs); + logs->numOfInfoLogs = tsNumOfInfoLogs; + logs->numOfErrorLogs = tsNumOfErrorLogs; + logs->numOfDebugLogs = tsNumOfDebugLogs; + logs->numOfTraceLogs = tsNumOfTraceLogs; + tsNumOfInfoLogs = 0; + tsNumOfErrorLogs = 0; + tsNumOfDebugLogs = 0; + tsNumOfTraceLogs = 0; + taosArrayClear(tsMonitor.logs); + taosThreadMutexUnlock(&tsMonitor.lock); + if (logs->logs == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + return 0; +} + +void monSetDmInfo(SMonDmInfo *pInfo) { + taosThreadMutexLock(&tsMonitor.lock); + memcpy(&tsMonitor.dmInfo, pInfo, sizeof(SMonDmInfo)); + taosThreadMutexUnlock(&tsMonitor.lock); + memset(pInfo, 0, sizeof(SMonDmInfo)); +} + +void monSetMmInfo(SMonMmInfo *pInfo) { + taosThreadMutexLock(&tsMonitor.lock); + memcpy(&tsMonitor.mmInfo, pInfo, sizeof(SMonMmInfo)); + taosThreadMutexUnlock(&tsMonitor.lock); + memset(pInfo, 0, sizeof(SMonMmInfo)); +} + +void monSetVmInfo(SMonVmInfo *pInfo) { + taosThreadMutexLock(&tsMonitor.lock); + memcpy(&tsMonitor.vmInfo, pInfo, sizeof(SMonVmInfo)); + taosThreadMutexUnlock(&tsMonitor.lock); + memset(pInfo, 0, sizeof(SMonVmInfo)); +} + +void monSetQmInfo(SMonQmInfo *pInfo) { + taosThreadMutexLock(&tsMonitor.lock); + memcpy(&tsMonitor.qmInfo, pInfo, sizeof(SMonQmInfo)); + taosThreadMutexUnlock(&tsMonitor.lock); + memset(pInfo, 0, sizeof(SMonQmInfo)); +} + +void monSetSmInfo(SMonSmInfo *pInfo) { + taosThreadMutexLock(&tsMonitor.lock); + memcpy(&tsMonitor.smInfo, pInfo, sizeof(SMonSmInfo)); + taosThreadMutexUnlock(&tsMonitor.lock); + memset(pInfo, 0, sizeof(SMonSmInfo)); +} + +void monSetBmInfo(SMonBmInfo *pInfo) { + taosThreadMutexLock(&tsMonitor.lock); + memcpy(&tsMonitor.bmInfo, pInfo, sizeof(SMonBmInfo)); + taosThreadMutexUnlock(&tsMonitor.lock); + memset(pInfo, 0, sizeof(SMonBmInfo)); +} + int32_t monInit(const SMonCfg *pCfg) { tsMonitor.logs = taosArrayInit(16, sizeof(SMonLogItem)); if (tsMonitor.logs == NULL) { @@ -42,12 +103,9 @@ int32_t monInit(const SMonCfg *pCfg) { return -1; } - tsMonitor.maxLogs = pCfg->maxLogs; - tsMonitor.server = pCfg->server; - tsMonitor.port = pCfg->port; - tsMonitor.comp = pCfg->comp; + tsMonitor.cfg = *pCfg; tsLogFp = monRecordLog; - tsMonitor.state.time = taosGetTimestampMs(); + tsMonitor.lastTime = taosGetTimestampMs(); taosThreadMutexInit(&tsMonitor.lock, NULL); return 0; } @@ -56,42 +114,65 @@ void monCleanup() { tsLogFp = NULL; taosArrayDestroy(tsMonitor.logs); tsMonitor.logs = NULL; + tFreeSMonMmInfo(&tsMonitor.mmInfo); + tFreeSMonVmInfo(&tsMonitor.vmInfo); + tFreeSMonSmInfo(&tsMonitor.smInfo); + tFreeSMonQmInfo(&tsMonitor.qmInfo); + tFreeSMonBmInfo(&tsMonitor.bmInfo); taosThreadMutexDestroy(&tsMonitor.lock); } -SMonInfo *monCreateMonitorInfo() { +static void monCleanupMonitorInfo(SMonInfo *pMonitor) { + tsMonitor.lastTime = pMonitor->curTime; + taosArrayDestroy(pMonitor->logs.logs); + tFreeSMonMmInfo(&pMonitor->mmInfo); + tFreeSMonVmInfo(&pMonitor->vmInfo); + tFreeSMonSmInfo(&pMonitor->smInfo); + tFreeSMonQmInfo(&pMonitor->qmInfo); + tFreeSMonBmInfo(&pMonitor->bmInfo); + tjsonDelete(pMonitor->pJson); + taosMemoryFree(pMonitor); +} + +static SMonInfo *monCreateMonitorInfo() { SMonInfo *pMonitor = taosMemoryCalloc(1, sizeof(SMonInfo)); if (pMonitor == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } + monGetLogs(&pMonitor->logs); + taosThreadMutexLock(&tsMonitor.lock); - pMonitor->logs = taosArrayDup(tsMonitor.logs); - taosArrayClear(tsMonitor.logs); + memcpy(&pMonitor->dmInfo, &tsMonitor.dmInfo, sizeof(SMonDmInfo)); + memcpy(&pMonitor->mmInfo, &tsMonitor.mmInfo, sizeof(SMonMmInfo)); + memcpy(&pMonitor->vmInfo, &tsMonitor.vmInfo, sizeof(SMonVmInfo)); + memcpy(&pMonitor->smInfo, &tsMonitor.smInfo, sizeof(SMonSmInfo)); + memcpy(&pMonitor->qmInfo, &tsMonitor.qmInfo, sizeof(SMonQmInfo)); + memcpy(&pMonitor->bmInfo, &tsMonitor.bmInfo, sizeof(SMonBmInfo)); + memset(&tsMonitor.dmInfo, 0, sizeof(SMonDmInfo)); + memset(&tsMonitor.mmInfo, 0, sizeof(SMonMmInfo)); + memset(&tsMonitor.vmInfo, 0, sizeof(SMonVmInfo)); + memset(&tsMonitor.smInfo, 0, sizeof(SMonSmInfo)); + memset(&tsMonitor.qmInfo, 0, sizeof(SMonQmInfo)); + memset(&tsMonitor.bmInfo, 0, sizeof(SMonBmInfo)); taosThreadMutexUnlock(&tsMonitor.lock); pMonitor->pJson = tjsonCreateObject(); - if (pMonitor->pJson == NULL || pMonitor->logs == NULL) { + if (pMonitor->pJson == NULL || pMonitor->logs.logs == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; monCleanupMonitorInfo(pMonitor); return NULL; } pMonitor->curTime = taosGetTimestampMs(); - pMonitor->lastState = tsMonitor.state; + pMonitor->lastTime = tsMonitor.lastTime; return pMonitor; } -void monCleanupMonitorInfo(SMonInfo *pMonitor) { - tsMonitor.state = pMonitor->lastState; - tsMonitor.state.time = pMonitor->curTime; - taosArrayDestroy(pMonitor->logs); - tjsonDelete(pMonitor->pJson); - taosMemoryFree(pMonitor); -} +static void monGenBasicJson(SMonInfo *pMonitor) { + SMonBasicInfo *pInfo = &pMonitor->dmInfo.basic; -void monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo) { SJson *pJson = pMonitor->pJson; char buf[40] = {0}; taosFormatUtcTime(buf, sizeof(buf), pMonitor->curTime, TSDB_TIME_PRECISION_MILLI); @@ -104,7 +185,9 @@ void monSetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo) { tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol); } -void monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo) { +static void monGenClusterJson(SMonInfo *pMonitor) { + SMonClusterInfo *pInfo = &pMonitor->mmInfo.cluster; + SJson *pJson = tjsonCreateObject(); if (pJson == NULL) return; if (tjsonAddItemToObject(pMonitor->pJson, "cluster_info", pJson) != 0) { @@ -154,7 +237,9 @@ void monSetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo) { } } -void monSetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo) { +static void monGenVgroupJson(SMonInfo *pMonitor) { + SMonVgroupInfo *pInfo = &pMonitor->mmInfo.vgroup; + SJson *pJson = tjsonAddArrayToObject(pMonitor->pJson, "vgroup_infos"); if (pJson == NULL) return; @@ -190,7 +275,9 @@ void monSetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo) { } } -void monSetGrantInfo(SMonInfo *pMonitor, SMonGrantInfo *pInfo) { +static void monGenGrantJson(SMonInfo *pMonitor) { + SMonGrantInfo *pInfo = &pMonitor->mmInfo.grant; + SJson *pJson = tjsonCreateObject(); if (pJson == NULL) return; if (tjsonAddItemToObject(pMonitor->pJson, "grant_info", pJson) != 0) { @@ -203,7 +290,11 @@ void monSetGrantInfo(SMonInfo *pMonitor, SMonGrantInfo *pInfo) { tjsonAddDoubleToObject(pJson, "timeseries_total", pInfo->timeseries_total); } -void monSetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo) { +static void monGenDnodeJson(SMonInfo *pMonitor) { + SMonDnodeInfo *pInfo = &pMonitor->dmInfo.dnode; + SMonSysInfo *pSys = &pMonitor->dmInfo.sys; + SVnodesStat *pStat = &pMonitor->vmInfo.vstat; + SJson *pJson = tjsonCreateObject(); if (pJson == NULL) return; if (tjsonAddItemToObject(pMonitor->pJson, "dnode_info", pJson) != 0) { @@ -211,58 +302,83 @@ void monSetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo) { return; } - SMonState *pLast = &pMonitor->lastState; - double interval = (pMonitor->curTime - pLast->time) / 1000.0; - double req_select_rate = (pInfo->req_select - pLast->req_select) / interval; - double req_insert_rate = (pInfo->req_insert - pLast->req_insert) / interval; - double req_insert_batch_rate = (pInfo->req_insert_batch - pLast->req_insert_batch) / interval; - double net_in_rate = (pInfo->net_in - pLast->net_in) / interval; - double net_out_rate = (pInfo->net_out - pLast->net_out) / interval; - double io_read_rate = (pInfo->io_read - pLast->io_read) / interval; - double io_write_rate = (pInfo->io_write - pLast->io_write) / interval; - double io_read_disk_rate = (pInfo->io_read_disk - pLast->io_read_disk) / interval; - double io_write_disk_rate = (pInfo->io_write_disk - pLast->io_write_disk) / interval; - pLast->req_select = pInfo->req_select; - pLast->req_insert = pInfo->req_insert; - pLast->req_insert_batch = pInfo->req_insert_batch; - pLast->net_in = pInfo->net_in; - pLast->net_out = pInfo->net_out; - pLast->io_read = pInfo->io_read; - pLast->io_write = pInfo->io_write; - pLast->io_read_disk = pInfo->io_read_disk; - pLast->io_write_disk = pInfo->io_write_disk; + double interval = (pMonitor->curTime - pMonitor->lastTime) / 1000.0; + if (pMonitor->curTime - pMonitor->lastTime == 0) { + interval = 1; + } + + double cpu_engine = 0; + double mem_engine = 0; + double net_in = 0; + double net_out = 0; + double io_read = 0; + double io_write = 0; + double io_read_disk = 0; + double io_write_disk = 0; + + SMonSysInfo *sysArrays[6]; + sysArrays[0] = &pMonitor->dmInfo.sys; + sysArrays[1] = &pMonitor->mmInfo.sys; + sysArrays[2] = &pMonitor->vmInfo.sys; + sysArrays[3] = &pMonitor->qmInfo.sys; + sysArrays[4] = &pMonitor->smInfo.sys; + sysArrays[5] = &pMonitor->bmInfo.sys; + for (int32_t i = 0; i < 6; ++i) { + cpu_engine += sysArrays[i]->cpu_engine; + mem_engine += sysArrays[i]->mem_engine; + net_in += sysArrays[i]->net_in; + net_out += sysArrays[i]->net_out; + io_read += sysArrays[i]->io_read; + io_write += sysArrays[i]->io_write; + io_read_disk += sysArrays[i]->io_read_disk; + io_write_disk += sysArrays[i]->io_write_disk; + } + + double req_select_rate = pStat->numOfSelectReqs / interval; + double req_insert_rate = pStat->numOfInsertReqs / interval; + double req_insert_batch_rate = pStat->numOfBatchInsertReqs / interval; + double net_in_rate = net_in / interval; + double net_out_rate = net_out / interval; + double io_read_rate = io_read / interval; + double io_write_rate = io_write / interval; + double io_read_disk_rate = io_read_disk / interval; + double io_write_disk_rate = io_write_disk / interval; tjsonAddDoubleToObject(pJson, "uptime", pInfo->uptime); - tjsonAddDoubleToObject(pJson, "cpu_engine", pInfo->cpu_engine); - tjsonAddDoubleToObject(pJson, "cpu_system", pInfo->cpu_system); - tjsonAddDoubleToObject(pJson, "cpu_cores", pInfo->cpu_cores); - tjsonAddDoubleToObject(pJson, "mem_engine", pInfo->mem_engine); - tjsonAddDoubleToObject(pJson, "mem_system", pInfo->mem_system); - tjsonAddDoubleToObject(pJson, "mem_total", pInfo->mem_total); - tjsonAddDoubleToObject(pJson, "disk_engine", pInfo->disk_engine); - tjsonAddDoubleToObject(pJson, "disk_used", pInfo->disk_used); - tjsonAddDoubleToObject(pJson, "disk_total", pInfo->disk_total); + tjsonAddDoubleToObject(pJson, "cpu_engine", cpu_engine); + tjsonAddDoubleToObject(pJson, "cpu_system", pSys->cpu_system); + tjsonAddDoubleToObject(pJson, "cpu_cores", pSys->cpu_cores); + tjsonAddDoubleToObject(pJson, "mem_engine", mem_engine); + tjsonAddDoubleToObject(pJson, "mem_system", pSys->mem_system); + tjsonAddDoubleToObject(pJson, "mem_total", pSys->mem_total); + tjsonAddDoubleToObject(pJson, "disk_engine", pSys->disk_engine); + tjsonAddDoubleToObject(pJson, "disk_used", pSys->disk_used); + tjsonAddDoubleToObject(pJson, "disk_total", pSys->disk_total); tjsonAddDoubleToObject(pJson, "net_in", net_in_rate); tjsonAddDoubleToObject(pJson, "net_out", net_out_rate); tjsonAddDoubleToObject(pJson, "io_read", io_read_rate); tjsonAddDoubleToObject(pJson, "io_write", io_write_rate); tjsonAddDoubleToObject(pJson, "io_read_disk", io_read_disk_rate); tjsonAddDoubleToObject(pJson, "io_write_disk", io_write_disk_rate); - tjsonAddDoubleToObject(pJson, "req_select", pInfo->req_select); + tjsonAddDoubleToObject(pJson, "req_select", pStat->numOfSelectReqs); tjsonAddDoubleToObject(pJson, "req_select_rate", req_select_rate); - tjsonAddDoubleToObject(pJson, "req_insert", pInfo->req_insert); - tjsonAddDoubleToObject(pJson, "req_insert_success", pInfo->req_insert_success); + tjsonAddDoubleToObject(pJson, "req_insert", pStat->numOfInsertReqs); + tjsonAddDoubleToObject(pJson, "req_insert_success", pStat->numOfInsertSuccessReqs); tjsonAddDoubleToObject(pJson, "req_insert_rate", req_insert_rate); - tjsonAddDoubleToObject(pJson, "req_insert_batch", pInfo->req_insert_batch); - tjsonAddDoubleToObject(pJson, "req_insert_batch_success", pInfo->req_insert_batch_success); + tjsonAddDoubleToObject(pJson, "req_insert_batch", pStat->numOfBatchInsertReqs); + tjsonAddDoubleToObject(pJson, "req_insert_batch_success", pStat->numOfBatchInsertSuccessReqs); tjsonAddDoubleToObject(pJson, "req_insert_batch_rate", req_insert_batch_rate); - tjsonAddDoubleToObject(pJson, "errors", pInfo->errors); - tjsonAddDoubleToObject(pJson, "vnodes_num", pInfo->vnodes_num); - tjsonAddDoubleToObject(pJson, "masters", pInfo->masters); + tjsonAddDoubleToObject(pJson, "errors", pStat->errors); + tjsonAddDoubleToObject(pJson, "vnodes_num", pStat->totalVnodes); + tjsonAddDoubleToObject(pJson, "masters", pStat->masterNum); tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode); } -void monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) { +static void monGenDiskJson(SMonInfo *pMonitor) { + SMonDiskInfo *pInfo = &pMonitor->vmInfo.tfs; + SMonDiskDesc *pLogDesc = &pMonitor->dmInfo.dnode.logdir; + SMonDiskDesc *pTempDesc = &pMonitor->dmInfo.dnode.tempdir; + SJson *pJson = tjsonCreateObject(); if (pJson == NULL) return; if (tjsonAddItemToObject(pMonitor->pJson, "disk_infos", pJson) != 0) { @@ -290,18 +406,18 @@ void monSetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) { SJson *pLogdirJson = tjsonCreateObject(); if (pLogdirJson == NULL) return; if (tjsonAddItemToObject(pJson, "logdir", pLogdirJson) != 0) return; - tjsonAddStringToObject(pLogdirJson, "name", pInfo->logdir.name); - tjsonAddDoubleToObject(pLogdirJson, "avail", pInfo->logdir.size.avail); - tjsonAddDoubleToObject(pLogdirJson, "used", pInfo->logdir.size.used); - tjsonAddDoubleToObject(pLogdirJson, "total", pInfo->logdir.size.total); + tjsonAddStringToObject(pLogdirJson, "name", pLogDesc->name); + tjsonAddDoubleToObject(pLogdirJson, "avail", pLogDesc->size.avail); + tjsonAddDoubleToObject(pLogdirJson, "used", pLogDesc->size.used); + tjsonAddDoubleToObject(pLogdirJson, "total", pLogDesc->size.total); SJson *pTempdirJson = tjsonCreateObject(); if (pTempdirJson == NULL) return; if (tjsonAddItemToObject(pJson, "tempdir", pTempdirJson) != 0) return; - tjsonAddStringToObject(pTempdirJson, "name", pInfo->tempdir.name); - tjsonAddDoubleToObject(pTempdirJson, "avail", pInfo->tempdir.size.avail); - tjsonAddDoubleToObject(pTempdirJson, "used", pInfo->tempdir.size.used); - tjsonAddDoubleToObject(pTempdirJson, "total", pInfo->tempdir.size.total); + tjsonAddStringToObject(pTempdirJson, "name", pTempDesc->name); + tjsonAddDoubleToObject(pTempdirJson, "avail", pTempDesc->size.avail); + tjsonAddDoubleToObject(pTempdirJson, "used", pTempDesc->size.used); + tjsonAddDoubleToObject(pTempdirJson, "total", pTempDesc->size.total); } static const char *monLogLevelStr(ELogLevel level) { @@ -319,7 +435,7 @@ static const char *monLogLevelStr(ELogLevel level) { } } -static void monSetLogInfo(SMonInfo *pMonitor) { +static void monGenLogJson(SMonInfo *pMonitor) { SJson *pJson = tjsonCreateObject(); if (pJson == NULL) return; if (tjsonAddItemToObject(pMonitor->pJson, "log_infos", pJson) != 0) { @@ -330,20 +446,41 @@ static void monSetLogInfo(SMonInfo *pMonitor) { SJson *pLogsJson = tjsonAddArrayToObject(pJson, "logs"); if (pLogsJson == NULL) return; - for (int32_t i = 0; i < taosArrayGetSize(pMonitor->logs); ++i) { - SJson *pLogJson = tjsonCreateObject(); - if (pLogJson == NULL) continue; + SMonLogs *logs[6]; + logs[0] = &pMonitor->logs; + logs[1] = &pMonitor->mmInfo.logs; + logs[2] = &pMonitor->vmInfo.logs; + logs[3] = &pMonitor->smInfo.logs; + logs[4] = &pMonitor->qmInfo.logs; + logs[5] = &pMonitor->bmInfo.logs; - SMonLogItem *pLogItem = taosArrayGet(pMonitor->logs, i); + int32_t numOfErrorLogs = 0; + int32_t numOfInfoLogs = 0; + int32_t numOfDebugLogs = 0; + int32_t numOfTraceLogs = 0; - char buf[40] = {0}; - taosFormatUtcTime(buf, sizeof(buf), pLogItem->ts, TSDB_TIME_PRECISION_MILLI); + for (int32_t j = 0; j < 6; j++) { + SMonLogs *pLogs = logs[j]; + numOfErrorLogs += pLogs->numOfErrorLogs; + numOfInfoLogs += pLogs->numOfInfoLogs; + numOfDebugLogs += pLogs->numOfDebugLogs; + numOfTraceLogs += pLogs->numOfTraceLogs; - tjsonAddStringToObject(pLogJson, "ts", buf); - tjsonAddStringToObject(pLogJson, "level", monLogLevelStr(pLogItem->level)); - tjsonAddStringToObject(pLogJson, "content", pLogItem->content); + for (int32_t i = 0; i < taosArrayGetSize(pLogs->logs); ++i) { + SJson *pLogJson = tjsonCreateObject(); + if (pLogJson == NULL) continue; - if (tjsonAddItemToArray(pLogsJson, pLogJson) != 0) tjsonDelete(pLogJson); + SMonLogItem *pLogItem = taosArrayGet(pLogs->logs, i); + + char buf[40] = {0}; + taosFormatUtcTime(buf, sizeof(buf), pLogItem->ts, TSDB_TIME_PRECISION_MILLI); + + tjsonAddStringToObject(pLogJson, "ts", buf); + tjsonAddStringToObject(pLogJson, "level", monLogLevelStr(pLogItem->level)); + tjsonAddStringToObject(pLogJson, "content", pLogItem->content); + + if (tjsonAddItemToArray(pLogsJson, pLogJson) != 0) tjsonDelete(pLogJson); + } } SJson *pSummaryJson = tjsonAddArrayToObject(pJson, "summary"); @@ -352,35 +489,46 @@ static void monSetLogInfo(SMonInfo *pMonitor) { SJson *pLogError = tjsonCreateObject(); if (pLogError == NULL) return; tjsonAddStringToObject(pLogError, "level", "error"); - tjsonAddDoubleToObject(pLogError, "total", tsNumOfErrorLogs); + tjsonAddDoubleToObject(pLogError, "total", numOfErrorLogs); if (tjsonAddItemToArray(pSummaryJson, pLogError) != 0) tjsonDelete(pLogError); SJson *pLogInfo = tjsonCreateObject(); if (pLogInfo == NULL) return; tjsonAddStringToObject(pLogInfo, "level", "info"); - tjsonAddDoubleToObject(pLogInfo, "total", tsNumOfInfoLogs); + tjsonAddDoubleToObject(pLogInfo, "total", numOfInfoLogs); if (tjsonAddItemToArray(pSummaryJson, pLogInfo) != 0) tjsonDelete(pLogInfo); SJson *pLogDebug = tjsonCreateObject(); if (pLogDebug == NULL) return; tjsonAddStringToObject(pLogDebug, "level", "debug"); - tjsonAddDoubleToObject(pLogDebug, "total", tsNumOfDebugLogs); + tjsonAddDoubleToObject(pLogDebug, "total", numOfDebugLogs); if (tjsonAddItemToArray(pSummaryJson, pLogDebug) != 0) tjsonDelete(pLogDebug); SJson *pLogTrace = tjsonCreateObject(); if (pLogTrace == NULL) return; tjsonAddStringToObject(pLogTrace, "level", "trace"); - tjsonAddDoubleToObject(pLogTrace, "total", tsNumOfTraceLogs); + tjsonAddDoubleToObject(pLogTrace, "total", numOfTraceLogs); if (tjsonAddItemToArray(pSummaryJson, pLogTrace) != 0) tjsonDelete(pLogTrace); } -void monSendReport(SMonInfo *pMonitor) { - monSetLogInfo(pMonitor); +void monSendReport() { + SMonInfo *pMonitor = monCreateMonitorInfo(); + if (pMonitor == NULL) return; + + monGenBasicJson(pMonitor); + monGenClusterJson(pMonitor); + monGenVgroupJson(pMonitor); + monGenGrantJson(pMonitor); + monGenDnodeJson(pMonitor); + monGenDiskJson(pMonitor); + monGenLogJson(pMonitor); char *pCont = tjsonToString(pMonitor->pJson); if (pCont != NULL) { - EHttpCompFlag flag = tsMonitor.comp ? HTTP_GZIP : HTTP_FLAT; - taosSendHttpReport(tsMonitor.server, tsMonitor.port, pCont, strlen(pCont), flag); + EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; + taosSendHttpReport(tsMonitor.cfg.server, tsMonitor.cfg.port, pCont, strlen(pCont), flag); taosMemoryFree(pCont); } + + monCleanupMonitorInfo(pMonitor); } diff --git a/source/libs/monitor/test/CMakeLists.txt b/source/libs/monitor/test/CMakeLists.txt index e3ab7e7337..cd1b94574d 100644 --- a/source/libs/monitor/test/CMakeLists.txt +++ b/source/libs/monitor/test/CMakeLists.txt @@ -1,14 +1,14 @@ enable_testing() aux_source_directory(. MONITOR_TEST_SRC) -add_executable(monitor_test ${MONITOR_TEST_SRC}) +add_executable(monitorTest ${MONITOR_TEST_SRC}) target_link_libraries( - monitor_test + monitorTest PUBLIC monitor PUBLIC gtest_main ) add_test( - NAME monitor_test - COMMAND monitor_test + NAME monitorTest + COMMAND monitorTest ) diff --git a/source/libs/monitor/test/monTest.cpp b/source/libs/monitor/test/monTest.cpp index 05c9fb8b38..af12297215 100644 --- a/source/libs/monitor/test/monTest.cpp +++ b/source/libs/monitor/test/monTest.cpp @@ -22,7 +22,7 @@ class MonitorTest : public ::testing::Test { cfg.maxLogs = 2; cfg.port = 80; cfg.server = "localhost"; - cfg.comp = 0; + cfg.comp = 1; monInit(&cfg); } @@ -32,24 +32,64 @@ class MonitorTest : public ::testing::Test { void SetUp() override {} void TearDown() override {} - void GetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo); - void GetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo); - void GetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo); - void GetGrantInfo(SMonInfo *pMonitor, SMonGrantInfo *pInfo); - void GetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo); - void GetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo); + void GetBasicInfo(SMonBasicInfo *pInfo); + void GetDnodeInfo(SMonDnodeInfo *pInfo); + void GetSysInfo(SMonSysInfo *pInfo); + + void GetClusterInfo(SMonClusterInfo *pInfo); + void GetVgroupInfo(SMonVgroupInfo *pInfo); + void GetGrantInfo(SMonGrantInfo *pInfo); + + void GetVnodeStat(SVnodesStat *pStat); + void GetDiskInfo(SMonDiskInfo *pInfo); + + void GetLogInfo(SMonLogs *logs); + void AddLogInfo1(); void AddLogInfo2(); }; -void MonitorTest::GetBasicInfo(SMonInfo *pMonitor, SMonBasicInfo *pInfo) { +void MonitorTest::GetBasicInfo(SMonBasicInfo *pInfo) { pInfo->dnode_id = 1; strcpy(pInfo->dnode_ep, "localhost"); pInfo->cluster_id = 6980428120398645172; pInfo->protocol = 1; } -void MonitorTest::GetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo) { +void MonitorTest::GetDnodeInfo(SMonDnodeInfo *pInfo) { + pInfo->uptime = 1.2; + pInfo->has_mnode = 1; + + strcpy(pInfo->logdir.name, "/log/dir/d"); + pInfo->logdir.size.avail = 41; + pInfo->logdir.size.total = 42; + pInfo->logdir.size.used = 43; + + strcpy(pInfo->tempdir.name, "/data/dir/d"); + pInfo->tempdir.size.avail = 51; + pInfo->tempdir.size.total = 52; + pInfo->tempdir.size.used = 53; +} + +void MonitorTest::GetSysInfo(SMonSysInfo *pInfo) { + pInfo->cpu_engine = 2.1; + pInfo->cpu_system = 2.1; + pInfo->cpu_cores = 2; + pInfo->mem_engine = 3.1; + pInfo->mem_system = 3.2; + pInfo->mem_total = 3.3; + pInfo->disk_engine = 4.1; + pInfo->disk_used = 4.2; + pInfo->disk_total = 4.3; + pInfo->net_in = 5.1; + pInfo->net_out = 5.2; + pInfo->io_read = 6.1; + pInfo->io_write = 6.2; + pInfo->io_read_disk = 7.1; + pInfo->io_write_disk = 7.2; +} + +void MonitorTest::GetClusterInfo(SMonClusterInfo *pInfo) { strcpy(pInfo->first_ep, "localhost:6030"); pInfo->first_ep_dnode_id = 1; strcpy(pInfo->version, "3.0.0.0"); @@ -86,7 +126,7 @@ void MonitorTest::GetClusterInfo(SMonInfo *pMonitor, SMonClusterInfo *pInfo) { taosArrayPush(pInfo->mnodes, &m2); } -void MonitorTest::GetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo) { +void MonitorTest::GetVgroupInfo(SMonVgroupInfo *pInfo) { pInfo->vgroups = taosArrayInit(4, sizeof(SMonVgroupDesc)); SMonVgroupDesc vg1 = {0}; @@ -121,41 +161,24 @@ void MonitorTest::GetVgroupInfo(SMonInfo *pMonitor, SMonVgroupInfo *pInfo) { taosArrayPush(pInfo->vgroups, &vg3); } -void MonitorTest::GetGrantInfo(SMonInfo *pMonitor, SMonGrantInfo *pInfo) { +void MonitorTest::GetGrantInfo(SMonGrantInfo *pInfo) { pInfo->expire_time = 1234567; pInfo->timeseries_total = 234567; pInfo->timeseries_used = 34567; } -void MonitorTest::GetDnodeInfo(SMonInfo *pMonitor, SMonDnodeInfo *pInfo) { - pInfo->uptime = 1.2; - pInfo->cpu_engine = 2.1; - pInfo->cpu_system = 2.1; - pInfo->cpu_cores = 2; - pInfo->mem_engine = 3.1; - pInfo->mem_system = 3.2; - pInfo->mem_total = 3.3; - pInfo->disk_engine = 4.1; - pInfo->disk_used = 4.2; - pInfo->disk_total = 4.3; - pInfo->net_in = 5.1; - pInfo->net_out = 5.2; - pInfo->io_read = 6.1; - pInfo->io_write = 6.2; - pInfo->io_read_disk = 7.1; - pInfo->io_write_disk = 7.2; - pInfo->req_select = 8; - pInfo->req_insert = 9; - pInfo->req_insert_success = 10; - pInfo->req_insert_batch = 11; - pInfo->req_insert_batch_success = 12; +void MonitorTest::GetVnodeStat(SVnodesStat *pInfo) { + pInfo->numOfSelectReqs = 8; + pInfo->numOfInsertReqs = 9; + pInfo->numOfInsertSuccessReqs = 10; + pInfo->numOfBatchInsertReqs = 11; + pInfo->numOfBatchInsertSuccessReqs = 12; pInfo->errors = 4; - pInfo->vnodes_num = 5; - pInfo->masters = 6; - pInfo->has_mnode = 1; + pInfo->totalVnodes = 5; + pInfo->masterNum = 6; } -void MonitorTest::GetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) { +void MonitorTest::GetDiskInfo(SMonDiskInfo *pInfo) { pInfo->datadirs = taosArrayInit(2, sizeof(SMonDiskDesc)); SMonDiskDesc d1 = {0}; strcpy(d1.name, "/t1/d1/d"); @@ -180,16 +203,25 @@ void MonitorTest::GetDiskInfo(SMonInfo *pMonitor, SMonDiskInfo *pInfo) { d3.size.total = 32; d3.size.used = 33; taosArrayPush(pInfo->datadirs, &d3); +} - strcpy(pInfo->logdir.name, "/log/dir/d"); - pInfo->logdir.size.avail = 41; - pInfo->logdir.size.total = 42; - pInfo->logdir.size.used = 43; +void MonitorTest::GetLogInfo(SMonLogs *logs) { + logs->logs = taosArrayInit(4, sizeof(SMonLogItem)); - strcpy(pInfo->tempdir.name, "/data/dir/d"); - pInfo->tempdir.size.avail = 51; - pInfo->tempdir.size.total = 52; - pInfo->tempdir.size.used = 53; + SMonLogItem item1 = {.level = DEBUG_INFO}; + item1.ts = taosGetTimestampMs(); + strcpy(item1.content, "log test1"); + taosArrayPush(logs->logs, &item1); + + SMonLogItem item2 = {.level = DEBUG_ERROR}; + item2.ts = taosGetTimestampMs(); + strcpy(item2.content, "log test2"); + taosArrayPush(logs->logs, &item2); + + logs->numOfErrorLogs = 1; + logs->numOfInfoLogs = 2; + logs->numOfDebugLogs = 3; + logs->numOfTraceLogs = 4; } void MonitorTest::AddLogInfo1() { @@ -206,46 +238,52 @@ void MonitorTest::AddLogInfo2() { TEST_F(MonitorTest, 01_Full) { AddLogInfo1(); - SMonInfo *pMonitor = monCreateMonitorInfo(); - if (pMonitor == NULL) return; + SMonDmInfo dmInfo = {0}; + GetBasicInfo(&dmInfo.basic); + GetDnodeInfo(&dmInfo.dnode); + GetSysInfo(&dmInfo.sys); - SMonBasicInfo basicInfo = {0}; - GetBasicInfo(pMonitor, &basicInfo); - monSetBasicInfo(pMonitor, &basicInfo); + SMonMmInfo mmInfo = {0}; + GetClusterInfo(&mmInfo.cluster); + GetVgroupInfo(&mmInfo.vgroup); + GetGrantInfo(&mmInfo.grant); + GetSysInfo(&mmInfo.sys); + GetLogInfo(&mmInfo.logs); - SMonClusterInfo clusterInfo = {0}; - SMonVgroupInfo vgroupInfo = {0}; - SMonGrantInfo grantInfo = {0}; - GetClusterInfo(pMonitor, &clusterInfo); - GetVgroupInfo(pMonitor, &vgroupInfo); - GetGrantInfo(pMonitor, &grantInfo); - monSetClusterInfo(pMonitor, &clusterInfo); - monSetVgroupInfo(pMonitor, &vgroupInfo); - monSetGrantInfo(pMonitor, &grantInfo); + SMonVmInfo vmInfo = {0}; + GetDiskInfo(&vmInfo.tfs); + GetVnodeStat(&vmInfo.vstat); + GetSysInfo(&vmInfo.sys); + GetLogInfo(&vmInfo.logs); - SMonDnodeInfo dnodeInfo = {0}; - GetDnodeInfo(pMonitor, &dnodeInfo); - monSetDnodeInfo(pMonitor, &dnodeInfo); + SMonQmInfo qmInfo = {0}; + GetSysInfo(&qmInfo.sys); + GetLogInfo(&qmInfo.logs); - SMonDiskInfo diskInfo = {0}; - GetDiskInfo(pMonitor, &diskInfo); - monSetDiskInfo(pMonitor, &diskInfo); + SMonSmInfo smInfo = {0}; + GetSysInfo(&smInfo.sys); + GetLogInfo(&smInfo.logs); - monSendReport(pMonitor); - monCleanupMonitorInfo(pMonitor); + SMonBmInfo bmInfo = {0}; + GetSysInfo(&bmInfo.sys); + GetLogInfo(&bmInfo.logs); - taosArrayDestroy(clusterInfo.dnodes); - taosArrayDestroy(clusterInfo.mnodes); - taosArrayDestroy(vgroupInfo.vgroups); - taosArrayDestroy(diskInfo.datadirs); + monSetDmInfo(&dmInfo); + monSetMmInfo(&mmInfo); + monSetVmInfo(&vmInfo); + monSetQmInfo(&qmInfo); + monSetSmInfo(&smInfo); + monSetBmInfo(&bmInfo); + + tFreeSMonMmInfo(&mmInfo); + tFreeSMonVmInfo(&vmInfo); + tFreeSMonSmInfo(&smInfo); + tFreeSMonQmInfo(&qmInfo); + tFreeSMonBmInfo(&bmInfo); + monSendReport(); } TEST_F(MonitorTest, 02_Log) { AddLogInfo2(); - - SMonInfo *pMonitor = monCreateMonitorInfo(); - if (pMonitor == NULL) return; - - monSendReport(pMonitor); - monCleanupMonitorInfo(pMonitor); + monSendReport(); } diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index eb5712d2e5..5e71505658 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -129,14 +129,12 @@ static void taosGetProcIOnfos() { static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { TdFilePtr pFile = taosOpenFile(tsSysCpuFile, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { - // printf("open file:%s failed", tsSysCpuFile); return -1; } char *line = NULL; ssize_t _bytes = taosGetLineFile(pFile, &line); if ((_bytes < 0) || (line == NULL)) { - // printf("read file:%s failed", tsSysCpuFile); taosCloseFile(&pFile); return -1; } @@ -153,14 +151,12 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { TdFilePtr pFile = taosOpenFile(tsProcCpuFile, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { - // printf("open file:%s failed", tsProcCpuFile); return -1; } char *line = NULL; ssize_t _bytes = taosGetLineFile(pFile, &line); if ((_bytes < 0) || (line == NULL)) { - // printf("read file:%s failed", tsProcCpuFile); taosCloseFile(&pFile); return -1; } @@ -182,12 +178,12 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { #endif bool taosCheckSystemIsSmallEnd() { - union check{ - int16_t i; - char ch[2]; - }c; - c.i=1; - return c.ch[0]==1; + union check { + int16_t i; + char ch[2]; + } c; + c.i = 1; + return c.ch[0] == 1; } void taosGetSystemInfo() { @@ -617,6 +613,28 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int #endif } +void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { + static int64_t last_rchars = 0; + static int64_t last_wchars = 0; + static int64_t last_read_bytes = 0; + static int64_t last_write_bytes = 0; + + static int64_t cur_rchars = 0; + static int64_t cur_wchars = 0; + static int64_t cur_read_bytes = 0; + static int64_t cur_write_bytes = 0; + if (taosGetProcIO(&cur_rchars, &cur_wchars, &cur_read_bytes, &cur_write_bytes) != 0) { + *rchars = cur_rchars - last_rchars; + *wchars = cur_wchars - last_wchars; + *read_bytes = cur_read_bytes - last_read_bytes; + *write_bytes = cur_write_bytes - last_write_bytes; + last_rchars = cur_rchars; + last_wchars = cur_wchars; + last_read_bytes = cur_read_bytes; + last_write_bytes = cur_write_bytes; + } +} + int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) *receive_bytes = 0; @@ -672,6 +690,20 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { #endif } +void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { + static int64_t last_receive_bytes = 0; + static int64_t last_transmit_bytes = 0; + + static int64_t cur_receive_bytes = 0; + static int64_t cur_transmit_bytes = 0; + if (taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes) != 0) { + *receive_bytes = cur_receive_bytes - last_receive_bytes; + *transmit_bytes = cur_transmit_bytes - last_transmit_bytes; + last_receive_bytes = cur_receive_bytes; + last_transmit_bytes = cur_transmit_bytes; + } +} + void taosKillSystem() { #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) printf("function taosKillSystem, exit!"); From 9f4744c6f3d7897d947d482fc8249e228c27a869 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Fri, 8 Apr 2022 16:05:30 +0800 Subject: [PATCH 40/57] 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 e84abcfb7986e11a69eb9d0bd684e007e2bfc05b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 8 Apr 2022 16:06:35 +0800 Subject: [PATCH 41/57] feat: send monitor information in multi-process mode --- source/libs/monitor/src/{monitor.c => monMain.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/libs/monitor/src/{monitor.c => monMain.c} (100%) diff --git a/source/libs/monitor/src/monitor.c b/source/libs/monitor/src/monMain.c similarity index 100% rename from source/libs/monitor/src/monitor.c rename to source/libs/monitor/src/monMain.c From 471522d9b9a7c61430edb859d3be3655189004ab Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Fri, 8 Apr 2022 16:43:01 +0800 Subject: [PATCH 42/57] add log --- source/dnode/vnode/src/tq/tq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 71a41c13d6..9a4e655b4c 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -345,9 +345,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { ASSERT(false); } if (pDataBlock == NULL) { - /*pos = fetchOffset % TQ_BUFFER_SIZE;*/ + vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d, exec task over, no more data, time passed: %lu", consumerId, pReq->epoch, pTq->pVnode->vgId, ts); break; } + vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d, exec task over", consumerId, pReq->epoch, pTq->pVnode->vgId); taosArrayPush(pRes, pDataBlock); } From 460d43f22c4c16321cf371e6a4d79ee3accd3092 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 8 Apr 2022 16:53:09 +0800 Subject: [PATCH 43/57] : fix index map error from table scan to sort output --- source/common/src/tdatablock.c | 12 +++++++----- source/libs/executor/inc/tsort.h | 5 ----- source/libs/executor/src/executorimpl.c | 3 +-- source/libs/executor/src/tsort.c | 8 +++++++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index abcb4283d2..111dfc7377 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -315,6 +315,7 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) { return 0; } +// if pIndexMap = NULL, merger one column by on column int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pIndexMap) { assert(pSrc != NULL && pDest != NULL); @@ -380,17 +381,18 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd size_t payloadSize = pageSize - (headerSize + colHeaderSize); // TODO speedup by checking if the whole page can fit in firstly. - /*if (!hasVarCol) { + if (!hasVarCol) { size_t rowSize = blockDataGetRowSize(pBlock); - int32_t capacity = (payloadSize / (rowSize * 8 + bitmapChar * numOfCols)) * 8; //if pageSize = 128, rowSize = 2, it will core in doAddToBuf:assert(size <= getBufPageSize(pHandle->pBuf)); + int32_t capacity = payloadSize / (rowSize + numOfCols * bitmapChar / 8.0); + ASSERT(capacity > 0); - *stopIndex = startIndex + capacity; + *stopIndex = startIndex + capacity - 1; if (*stopIndex >= numOfRows) { *stopIndex = numOfRows - 1; } return TSDB_CODE_SUCCESS; - }*/ + } // iterate the rows that can be fit in this buffer page int32_t size = (headerSize + colHeaderSize); @@ -532,7 +534,7 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) { size_t metaSize = pBlock->info.rows * sizeof(int32_t); if (IS_VAR_DATA_TYPE(pCol->info.type)) { - char* tmp = taosMemoryRealloc(pCol->varmeta.offset, metaSize); + char* tmp = taosMemoryRealloc(pCol->varmeta.offset, metaSize); // preview calloc is too small if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index f012cc2448..c584df05dd 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -52,11 +52,6 @@ typedef struct SMsortComparParam { SArray *orderInfo; // SArray } SMsortComparParam; -struct STupleHandle { - SSDataBlock* pBlock; - int32_t rowIndex; -}; - typedef struct SSortHandle SSortHandle; typedef struct STupleHandle STupleHandle; diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 0cc73bb2cd..a8857dbc1d 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -4734,8 +4734,7 @@ static void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHan for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i); - SColumnInfoData* pColInfoSrc = taosArrayGet(pTupleHandle->pBlock->pDataBlock, i); - bool isNull = colDataIsNull(pColInfoSrc, 0, pTupleHandle->rowIndex, NULL); + bool isNull = tsortIsNullVal(pTupleHandle, i); if (isNull) { colDataAppend(pColInfo, pBlock->info.rows, NULL, true); } else { diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 965cf14400..3155b69a86 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -24,6 +24,11 @@ #include "tutil.h" #include "tcompare.h" +struct STupleHandle { + SSDataBlock* pBlock; + int32_t rowIndex; +}; + struct SSortHandle { int32_t type; @@ -678,7 +683,8 @@ STupleHandle* tsortNextTuple(SSortHandle* pHandle) { } bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colIndex) { - return false; + SColumnInfoData* pColInfoSrc = taosArrayGet(pVHandle->pBlock->pDataBlock, colIndex); + return colDataIsNull(pColInfoSrc, 0, pVHandle->rowIndex, NULL); } void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex) { From 70797ef81609829a9c9e233935caf466cc435bc2 Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Fri, 8 Apr 2022 17:35:44 +0800 Subject: [PATCH 44/57] [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 From 2e6b9c7b99a1fafff72cd923c37587e870bf3572 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 8 Apr 2022 17:43:48 +0800 Subject: [PATCH 45/57] [transport] cannot transport by hostname --- source/libs/transport/src/transCli.c | 65 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d9c288a39b..8bebd626c4 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 { \ @@ -205,12 +205,10 @@ static void destroyThrdObj(SCliThrdObj* pThrd); transRefCliHandle(conn); \ } \ } while (0) -#define CONN_NO_PERSIST_BY_APP(conn) \ - (((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 CONN_NO_PERSIST_BY_APP(conn) (((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_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release) static void* cliWorkThread(void* arg); @@ -281,9 +279,8 @@ void cliHandleResp(SCliConn* conn) { tDebug("%s cli conn %p ref by app", CONN_GET_INST_LABEL(conn), conn); } - tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn, - TMSG_INFO(pHead->msgType), taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), - taosInetNtoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), transMsg.contLen); + tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn, TMSG_INFO(pHead->msgType), + taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), taosInetNtoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), transMsg.contLen); conn->secured = pHead->secured; @@ -349,12 +346,10 @@ void cliHandleExcept(SCliConn* pConn) { if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { transMsg.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType); - tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle, - TMSG_INFO(transMsg.msgType)); + tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle, TMSG_INFO(transMsg.msgType)); if (transMsg.ahandle == NULL) { transMsg.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, (int32_t*)&(transMsg.msgType)); - tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, - transMsg.ahandle); + tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle); } } else { transMsg.ahandle = pCtx ? pCtx->ahandle : NULL; @@ -628,9 +623,8 @@ void cliSend(SCliConn* pConn) { pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); - tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn, - TMSG_INFO(pHead->msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), - taosInetNtoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port)); + tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pHead->msgType), + taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port)); if (pHead->persist == 1) { CONN_SET_PERSIST_BY_APP(pConn); @@ -740,8 +734,13 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) { if (ret) { tError("%s cli conn %p failed to set conn option, errmsg %s", pTransInst->label, conn, uv_err_name(ret)); } + struct sockaddr_in addr; - uv_ip4_addr(pMsg->ctx->ip, pMsg->ctx->port, &addr); + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = taosGetIpv4FromFqdn(conn->ip); + addr.sin_port = (uint16_t)htons((uint16_t)conn->port); + // uv_ip4_addr(pMsg->ctx->ip, pMsg->ctx->port, &addr); // handle error in callback if fail to connect tTrace("%s cli conn %p try to connect to %s:%d", pTransInst->label, conn, pMsg->ctx->ip, pMsg->ctx->port); uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb); From 32cc09ae8caf9174aab9109d6114fa4297c9fe38 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Fri, 8 Apr 2022 17:52:24 +0800 Subject: [PATCH 46/57] remove bdb --- ...db_CMakeLists.txt.in => bdb_CMakeLists.txt.in.bak} | 0 cmake/cmake.options | 11 ----------- contrib/CMakeLists.txt | 6 +++--- contrib/test/CMakeLists.txt | 6 +++--- source/dnode/vnode/CMakeLists.txt | 2 +- source/dnode/vnode/src/tq/tqRead.c | 4 ++-- 6 files changed, 9 insertions(+), 20 deletions(-) rename cmake/{bdb_CMakeLists.txt.in => bdb_CMakeLists.txt.in.bak} (100%) diff --git a/cmake/bdb_CMakeLists.txt.in b/cmake/bdb_CMakeLists.txt.in.bak similarity index 100% rename from cmake/bdb_CMakeLists.txt.in rename to cmake/bdb_CMakeLists.txt.in.bak diff --git a/cmake/cmake.options b/cmake/cmake.options index 946eb5d258..b51f096185 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -55,17 +55,6 @@ option( OFF ) -IF(${TD_WINDOWS}) - MESSAGE("Not build BDB on Windows") -ELSE () - option( - BUILD_WITH_BDB - "If build with BerkleyDB" - ON - ) - -ENDIF () - option( BUILD_WITH_LUCENE "If build with lucene" diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 575a0e6274..377e3fbccc 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -63,9 +63,9 @@ if(${BUILD_WITH_UV}) endif(${BUILD_WITH_UV}) # bdb -if(${BUILD_WITH_BDB}) - cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) -endif(${BUILD_WITH_BDB}) +#if(${BUILD_WITH_BDB}) + #cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}) +#endif(${BUILD_WITH_BDB}) # sqlite if(${BUILD_WITH_SQLITE}) diff --git a/contrib/test/CMakeLists.txt b/contrib/test/CMakeLists.txt index eacaeb9524..740488b39b 100644 --- a/contrib/test/CMakeLists.txt +++ b/contrib/test/CMakeLists.txt @@ -7,9 +7,9 @@ if(${BUILD_WITH_LUCENE}) add_subdirectory(lucene) endif(${BUILD_WITH_LUCENE}) -if(${BUILD_WITH_BDB}) - add_subdirectory(bdb) -endif(${BUILD_WITH_BDB}) +#if(${BUILD_WITH_BDB}) + #add_subdirectory(bdb) +#endif(${BUILD_WITH_BDB}) if(${BUILD_WITH_SQLITE}) add_subdirectory(sqlite) diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 28e19dc017..b5fe7d460f 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -68,7 +68,7 @@ target_link_libraries( PUBLIC executor PUBLIC scheduler PUBLIC tdb - PUBLIC bdb + #PUBLIC bdb PUBLIC transport PUBLIC stream ) diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index a18374015b..fee8bdf27e 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -167,8 +167,8 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { break; } - if (colDataAppend(pColData, curRow, sVal.val, false) < 0) { - /*if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) {*/ + /*if (colDataAppend(pColData, curRow, sVal.val, false) < 0) {*/ + if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) { taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock); return NULL; } From 0936b8666034cca915cc14a276b66f171d640359 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 8 Apr 2022 18:49:34 +0800 Subject: [PATCH 47/57] [transport] cannot transport by hostname --- source/libs/transport/src/transCli.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index dfcb333c9b..db66102cab 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -206,10 +206,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd); } \ } while (0) -#define CONN_NO_PERSIST_BY_APP(conn) \ - (((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 CONN_NO_PERSIST_BY_APP(conn) (((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) From f98ceb04bec417a6f6e6a14cb6f7083524d96b7e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 8 Apr 2022 16:43:20 +0800 Subject: [PATCH 48/57] feat: send monitor information in multi-process mode --- include/libs/monitor/monitor.h | 12 +- source/dnode/mgmt/bm/bmHandle.c | 7 + source/dnode/mgmt/dm/dmHandle.c | 15 +- source/dnode/mgmt/dm/dmMonitor.c | 404 +++++++++++++++------ source/dnode/mgmt/dm/dmWorker.c | 21 +- source/dnode/mgmt/inc/dmInt.h | 17 +- source/dnode/mgmt/inc/dndInt.h | 24 +- source/dnode/mgmt/inc/vmInt.h | 1 + source/dnode/mgmt/main/dndTransport.c | 6 +- source/dnode/mgmt/mm/mmHandle.c | 10 +- source/dnode/mgmt/mm/mmInt.c | 5 - source/dnode/mgmt/qm/qmHandle.c | 7 + source/dnode/mgmt/sm/smHandle.c | 7 + source/dnode/mgmt/vm/vmHandle.c | 22 ++ source/dnode/mgmt/vm/vmInt.c | 45 +-- source/libs/monitor/src/monMsg.c | 499 +++++++++++++++++++++++++- 16 files changed, 912 insertions(+), 190 deletions(-) diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index 342796b070..3cecb139e1 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -162,7 +162,7 @@ typedef struct { } SMonVmInfo; int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); -int32_t tDeserializeSMonVMmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); +int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); void tFreeSMonVmInfo(SMonVmInfo *pInfo); typedef struct { @@ -171,7 +171,7 @@ typedef struct { } SMonQmInfo; int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); -int32_t tDeserializeSMonQMmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); +int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); void tFreeSMonQmInfo(SMonQmInfo *pInfo); typedef struct { @@ -191,6 +191,14 @@ int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); void tFreeSMonBmInfo(SMonBmInfo *pInfo); +typedef struct { + SArray *pVloads; // SVnodeLoad +} SMonVloadInfo; + +int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo); +int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo); +void tFreeSMonVloadInfo(SMonVloadInfo *pInfo); + typedef struct { const char *server; uint16_t port; diff --git a/source/dnode/mgmt/bm/bmHandle.c b/source/dnode/mgmt/bm/bmHandle.c index 2ae9b3817f..8abfa8955c 100644 --- a/source/dnode/mgmt/bm/bmHandle.c +++ b/source/dnode/mgmt/bm/bmHandle.c @@ -16,6 +16,13 @@ #define _DEFAULT_SOURCE #include "bmInt.h" +void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo) { + if (pWrapper->procType == PROC_CHILD) { + dmGetMonitorSysInfo(&bmInfo->sys); + monGetLogs(&bmInfo->logs); + } +} + int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnode *pDnode = pWrapper->pDnode; SRpcMsg *pReq = &pMsg->rpcMsg; diff --git a/source/dnode/mgmt/dm/dmHandle.c b/source/dnode/mgmt/dm/dmHandle.c index 40d85b2a9a..c0175fed10 100644 --- a/source/dnode/mgmt/dm/dmHandle.c +++ b/source/dnode/mgmt/dm/dmHandle.c @@ -42,8 +42,9 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES); if (pWrapper != NULL) { - req.pVloads = taosArrayInit(TSDB_MAX_VNODES, sizeof(SVnodeLoad)); - vmMonitorVnodeLoads(pWrapper, req.pVloads); + SMonVloadInfo info = {0}; + dmGetVnodeLoads(pWrapper, &info); + req.pVloads = info.pVloads; dndReleaseWrapper(pWrapper); } @@ -117,7 +118,6 @@ int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { return TSDB_CODE_OPS_NOT_SUPPORT; } - static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); if (pWrapper != NULL) { @@ -209,10 +209,15 @@ void dmInitMsgHandle(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, dmProcessMgmtMsg, DEFAULT_HANDLE); // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessStatusMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMonitorMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); // Monitor info exchange between processes - dndSetMsgHandle(pWrapper, TDMT_MON_DISK_INFO, dmProcessStatusMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, dmProcessMonitorMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/dm/dmMonitor.c b/source/dnode/mgmt/dm/dmMonitor.c index 7117bc5d12..b9199efac2 100644 --- a/source/dnode/mgmt/dm/dmMonitor.c +++ b/source/dnode/mgmt/dm/dmMonitor.c @@ -16,20 +16,6 @@ #define _DEFAULT_SOURCE #include "dmInt.h" -static int32_t dmGetMonitorDiskInfo(SDnode *pDnode, SMonDiskInfo *pInfo) { - tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name)); - pInfo->logdir.size = tsLogSpace.size; - tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name)); - pInfo->tempdir.size = tsTempSpace.size; - - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES); - if (pWrapper != NULL) { - vmMonitorTfsInfo(pWrapper, pInfo); - dndReleaseWrapper(pWrapper); - } - return 0; -} - static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { pInfo->protocol = 1; pInfo->dnode_id = pDnode->dnodeId; @@ -39,6 +25,305 @@ static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { pInfo->uptime = (taosGetTimestampMs() - pDnode->rebootTime) / (86400000.0f); + SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, MNODE); + if (pWrapper != NULL) { + pInfo->has_mnode = pWrapper->required; + dndReleaseWrapper(pWrapper); + } + tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name)); + pInfo->logdir.size = tsLogSpace.size; + tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name)); + pInfo->tempdir.size = tsTempSpace.size; +} + +static void dmGetMonitorInfo(SDnode *pDnode, SMonDmInfo *pInfo) { + dmGetMonitorBasicInfo(pDnode, &pInfo->basic); + dmGetMonitorSysInfo(&pInfo->sys); + dmGetMonitorDnodeInfo(pDnode, &pInfo->dnode); +} + +void dmSendMonitorReport(SDnode *pDnode) { + if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return; + dTrace("send monitor report to %s:%u", tsMonitorFqdn, tsMonitorPort); + + SMonDmInfo dmInfo = {0}; + SMonMmInfo mmInfo = {0}; + SMonVmInfo vmInfo = {0}; + SMonQmInfo qmInfo = {0}; + SMonSmInfo smInfo = {0}; + SMonBmInfo bmInfo = {0}; + + SRpcMsg req = {0}; + SRpcMsg rsp; + SEpSet epset = {.inUse = 0, .numOfEps = 1}; + tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); + epset.eps[0].port = tsServerPort; + + dmGetMonitorInfo(pDnode, &dmInfo); + + SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, MNODE); + if (pWrapper != NULL) { + if (!tsMultiProcess) { + mmGetMonitorInfo(pWrapper, &mmInfo); + } else { + req.msgType = TDMT_MON_MM_INFO; + dndSendRecv(pDnode, &epset, &req, &rsp); + tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo); + rpcFreeCont(rsp.pCont); + } + dndReleaseWrapper(pWrapper); + } + + pWrapper = dndAcquireWrapper(pDnode, VNODES); + if (pWrapper != NULL) { + if (!tsMultiProcess) { + vmGetMonitorInfo(pWrapper, &vmInfo); + } else { + req.msgType = TDMT_MON_VM_INFO; + dndSendRecv(pDnode, &epset, &req, &rsp); + dndReleaseWrapper(pWrapper); + tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo); + rpcFreeCont(rsp.pCont); + } + } + + pWrapper = dndAcquireWrapper(pDnode, QNODE); + if (pWrapper != NULL) { + if (!tsMultiProcess) { + qmGetMonitorInfo(pWrapper, &qmInfo); + } else { + req.msgType = TDMT_MON_QM_INFO; + dndSendRecv(pDnode, &epset, &req, &rsp); + dndReleaseWrapper(pWrapper); + tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo); + rpcFreeCont(rsp.pCont); + } + dndReleaseWrapper(pWrapper); + } + + pWrapper = dndAcquireWrapper(pDnode, SNODE); + if (pWrapper != NULL) { + if (!tsMultiProcess) { + smGetMonitorInfo(pWrapper, &smInfo); + } else { + req.msgType = TDMT_MON_SM_INFO; + dndSendRecv(pDnode, &epset, &req, &rsp); + dndReleaseWrapper(pWrapper); + tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo); + rpcFreeCont(rsp.pCont); + } + dndReleaseWrapper(pWrapper); + } + + pWrapper = dndAcquireWrapper(pDnode, BNODE); + if (pWrapper != NULL) { + if (!tsMultiProcess) { + bmGetMonitorInfo(pWrapper, &bmInfo); + } else { + req.msgType = TDMT_MON_BM_INFO; + dndSendRecv(pDnode, &epset, &req, &rsp); + dndReleaseWrapper(pWrapper); + tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo); + rpcFreeCont(rsp.pCont); + } + dndReleaseWrapper(pWrapper); + } + + monSetDmInfo(&dmInfo); + monSetMmInfo(&mmInfo); + monSetVmInfo(&vmInfo); + monSetQmInfo(&qmInfo); + monSetSmInfo(&smInfo); + monSetBmInfo(&bmInfo); + tFreeSMonMmInfo(&mmInfo); + tFreeSMonVmInfo(&vmInfo); + tFreeSMonQmInfo(&qmInfo); + tFreeSMonSmInfo(&smInfo); + tFreeSMonBmInfo(&bmInfo); + monSendReport(); +} + +int32_t dmProcessGetMonMmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { + SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, MNODE); + if (pWrapper == NULL) return -1; + + SMonMmInfo mmInfo = {0}; + mmGetMonitorInfo(pWrapper, &mmInfo); + dndReleaseWrapper(pWrapper); + + int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonMmInfo(&mmInfo); + return 0; +} + +int32_t dmProcessGetMonVmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { + SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, VNODES); + if (pWrapper == NULL) return -1; + + SMonVmInfo vmInfo = {0}; + vmGetMonitorInfo(pWrapper, &vmInfo); + dndReleaseWrapper(pWrapper); + + int32_t rspLen = tSerializeSMonVmInfo(NULL, 0, &vmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonVmInfo(pRsp, rspLen, &vmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonVmInfo(&vmInfo); + return 0; +} + +int32_t dmProcessGetMonQmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { + SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, QNODE); + if (pWrapper == NULL) return -1; + + SMonQmInfo qmInfo = {0}; + qmGetMonitorInfo(pWrapper, &qmInfo); + dndReleaseWrapper(pWrapper); + + int32_t rspLen = tSerializeSMonQmInfo(NULL, 0, &qmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonQmInfo(pRsp, rspLen, &qmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonQmInfo(&qmInfo); + return 0; +} + +int32_t dmProcessGetMonSmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { + SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, SNODE); + if (pWrapper == NULL) return -1; + + SMonSmInfo smInfo = {0}; + smGetMonitorInfo(pWrapper, &smInfo); + dndReleaseWrapper(pWrapper); + + int32_t rspLen = tSerializeSMonSmInfo(NULL, 0, &smInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonSmInfo(pRsp, rspLen, &smInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonSmInfo(&smInfo); + return 0; +} + +int32_t dmProcessGetMonBmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { + SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, BNODE); + if (pWrapper == NULL) return -1; + + SMonBmInfo bmInfo = {0}; + bmGetMonitorInfo(pWrapper, &bmInfo); + dndReleaseWrapper(pWrapper); + + int32_t rspLen = tSerializeSMonBmInfo(NULL, 0, &bmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonBmInfo(pRsp, rspLen, &bmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonBmInfo(&bmInfo); + return 0; +} + +int32_t dmProcessGetVnodeLoadsReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { + SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, VNODES); + if (pWrapper == NULL) return -1; + + SMonVloadInfo vloads = {0}; + vmGetVnodeLoads(pWrapper, &vloads); + dndReleaseWrapper(pWrapper); + + int32_t rspLen = tSerializeSMonVloadInfo(NULL, 0, &vloads); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonVloadInfo(pRsp, rspLen, &vloads); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonVloadInfo(&vloads); + return 0; +} + +void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { + if (!tsMultiProcess) { + vmGetVnodeLoads(pWrapper, pInfo); + } else { + SRpcMsg req = {.msgType = TDMT_MON_VM_LOAD}; + SRpcMsg rsp = {0}; + SEpSet epset = {.inUse = 0, .numOfEps = 1}; + tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); + epset.eps[0].port = tsServerPort; + + dndSendRecv(pWrapper->pDnode, &epset, &req, &rsp); + if (rsp.code == 0) { + tDeserializeSMonVloadInfo(rsp.pCont, rsp.contLen, pInfo); + } + rpcFreeCont(rsp.pCont); + } +} + +void dmGetMonitorSysInfo(SMonSysInfo *pInfo) { taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system); taosGetCpuCores(&pInfo->cpu_cores); taosGetProcMemory(&pInfo->mem_engine); @@ -47,93 +332,6 @@ static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { pInfo->disk_engine = 0; pInfo->disk_used = tsDataSpace.size.used; pInfo->disk_total = tsDataSpace.size.total; - taosGetCardInfo(&pInfo->net_in, &pInfo->net_out); - taosGetProcIO(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); - - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES); - if (pWrapper != NULL) { - vmMonitorVnodeReqs(pWrapper, pInfo); - dndReleaseWrapper(pWrapper); - } - - pWrapper = dndAcquireWrapper(pDnode, MNODE); - if (pWrapper != NULL) { - pInfo->has_mnode = pWrapper->required; - dndReleaseWrapper(pWrapper); - } + taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); + taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); } - -void dmSendMonitorReport(SDnode *pDnode) { - if (!tsEnableMonitor || tsMonitorFqdn[0] == 0 || tsMonitorPort == 0) return; - dTrace("send monitor report to %s:%u", tsMonitorFqdn, tsMonitorPort); - - SMonInfo *pMonitor = monCreateMonitorInfo(); - if (pMonitor == NULL) return; - - SMonBasicInfo basicInfo = {0}; - dmGetMonitorBasicInfo(pDnode, &basicInfo); - monSetBasicInfo(pMonitor, &basicInfo); - - SMonClusterInfo clusterInfo = {0}; - SMonVgroupInfo vgroupInfo = {0}; - SMonGrantInfo grantInfo = {0}; - - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, MNODE); - if (pWrapper != NULL) { - if (mmMonitorMnodeInfo(pWrapper, &clusterInfo, &vgroupInfo, &grantInfo) == 0) { - monSetClusterInfo(pMonitor, &clusterInfo); - monSetVgroupInfo(pMonitor, &vgroupInfo); - monSetGrantInfo(pMonitor, &grantInfo); - } - dndReleaseWrapper(pWrapper); - } - - SMonDnodeInfo dnodeInfo = {0}; - dmGetMonitorDnodeInfo(pDnode, &dnodeInfo); - monSetDnodeInfo(pMonitor, &dnodeInfo); - - SMonDiskInfo diskInfo = {0}; - if (dmGetMonitorDiskInfo(pDnode, &diskInfo) == 0) { - monSetDiskInfo(pMonitor, &diskInfo); - } - - taosArrayDestroy(clusterInfo.dnodes); - taosArrayDestroy(clusterInfo.mnodes); - taosArrayDestroy(vgroupInfo.vgroups); - taosArrayDestroy(diskInfo.datadirs); - - monSendReport(pMonitor); - monCleanupMonitorInfo(pMonitor); -} - -int32_t dmSetDiskInfo(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SDnode *pDnode = pMgmt->pDnode; - SMonDiskInfo info = {0}; - - if (tDeserializeSMonDiskInfo(pMsg->rpcMsg.pCont, pMsg->rpcMsg.contLen, &info) != 0) { - dError("failed to parse diskinfo since %s", terrstr()); - return 0; - } - - taosWLockLatch(&pMgmt->latch); - memcpy(&pMgmt->diskInfo, &info, sizeof(SMonDiskInfo)); - taosWUnLockLatch(&pMgmt->latch); - - return 0; -} - -int32_t dmSetVnodeStat(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SDnode *pDnode = pMgmt->pDnode; - SVnodesStat info = {0}; - - if (tDeserializeSMonDiskInfo(pMsg->rpcMsg.pCont, pMsg->rpcMsg.contLen, &info) != 0) { - dError("failed to parse diskinfo since %s", terrstr()); - return 0; - } - - taosWLockLatch(&pMgmt->latch); - memcpy(&pMgmt->diskInfo, &info, sizeof(SMonDiskInfo)); - taosWUnLockLatch(&pMgmt->latch); - - return 0; -} \ No newline at end of file diff --git a/source/dnode/mgmt/dm/dmWorker.c b/source/dnode/mgmt/dm/dmWorker.c index 1d11c4d25b..7b2a3c7015 100644 --- a/source/dnode/mgmt/dm/dmWorker.c +++ b/source/dnode/mgmt/dm/dmWorker.c @@ -78,8 +78,23 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { case TDMT_MND_GRANT_RSP: code = dmProcessGrantRsp(pMgmt, pMsg); break; - case TDMT_MON_DISK_INFO_RSP: - code = dmSetDiskInfo(pMgmt, pMsg); + case TDMT_MON_MM_INFO: + code = dmProcessGetMonMmInfoReq(pMgmt, pMsg); + break; + case TDMT_MON_VM_INFO: + code = dmProcessGetMonVmInfoReq(pMgmt, pMsg); + break; + case TDMT_MON_QM_INFO: + code = dmProcessGetMonQmInfoReq(pMgmt, pMsg); + break; + case TDMT_MON_SM_INFO: + code = dmProcessGetMonSmInfoReq(pMgmt, pMsg); + break; + case TDMT_MON_BM_INFO: + code = dmProcessGetMonBmInfoReq(pMgmt, pMsg); + break; + case TDMT_MON_VM_LOAD: + code = dmProcessGetVnodeLoadsReq(pMgmt, pMsg); break; default: code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg); @@ -134,7 +149,7 @@ int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } -int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { +int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnodeMgmt *pMgmt = pWrapper->pMgmt; SSingleWorker *pWorker = &pMgmt->statusWorker; diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/inc/dmInt.h index d7358d0ca4..eee529757e 100644 --- a/source/dnode/mgmt/inc/dmInt.h +++ b/source/dnode/mgmt/inc/dmInt.h @@ -37,11 +37,6 @@ typedef struct SDnodeMgmt { const char *path; SDnode *pDnode; SMgmtWrapper *pWrapper; - - // monitor infos - SMonDiskInfo diskInfo; - SMonVnodesStat vnodesStat; - SMonVnodesLoad vnodesLoad; } SDnodeMgmt; // dmFile.c @@ -59,9 +54,13 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); // dmMonitor.c -int32_t dmSetDiskInfo(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmSetVnodesStat(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmSetVnodesLoad(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t dmProcessGetVnodeLoadsReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); +int32_t dmProcessGetMonMmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); +int32_t dmProcessGetMonVmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); +int32_t dmProcessGetMonQmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); +int32_t dmProcessGetMonSmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); +int32_t dmProcessGetMonBmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); +void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); void dmSendMonitorReport(SDnode *pDnode); // dmWorker.c @@ -69,7 +68,7 @@ int32_t dmStartThread(SDnodeMgmt *pMgmt); int32_t dmStartWorker(SDnodeMgmt *pMgmt); void dmStopWorker(SDnodeMgmt *pMgmt); int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/inc/dndInt.h b/source/dnode/mgmt/inc/dndInt.h index 5659becb20..7faf1e4276 100644 --- a/source/dnode/mgmt/inc/dndInt.h +++ b/source/dnode/mgmt/inc/dndInt.h @@ -169,6 +169,7 @@ void dndCleanupTrans(SDnode *pDnode); SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); int32_t dndInitMsgHandle(SDnode *pDnode); +void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); // mgmt void dmSetMgmtFp(SMgmtWrapper *pWrapper); @@ -182,22 +183,13 @@ void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pMsg); -typedef struct { - int32_t openVnodes; - int32_t totalVnodes; - int32_t masterNum; - int64_t numOfSelectReqs; - int64_t numOfInsertReqs; - int64_t numOfInsertSuccessReqs; - int64_t numOfBatchInsertReqs; - int64_t numOfBatchInsertSuccessReqs; -} SVnodesStat; - -void vmMonitorVnodeLoads(SMgmtWrapper *pWrapper, SArray *pLoads); -int32_t vmMonitorTfsInfo(SMgmtWrapper *pWrapper, SMonDiskInfo *pInfo); -void vmMonitorVnodeReqs(SMgmtWrapper *pWrapper, SMonDnodeInfo *pInfo); -int32_t mmMonitorMnodeInfo(SMgmtWrapper *pWrapper, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, - SMonGrantInfo *pGrantInfo); +void dmGetMonitorSysInfo(SMonSysInfo *pInfo); +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); +void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); +void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); +void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); +void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/inc/vmInt.h b/source/dnode/mgmt/inc/vmInt.h index 889ad7c164..ca210d62c6 100644 --- a/source/dnode/mgmt/inc/vmInt.h +++ b/source/dnode/mgmt/inc/vmInt.h @@ -28,6 +28,7 @@ typedef struct SVnodesMgmt { SHashObj *hash; SRWLatch latch; SVnodesStat state; + SVnodesStat lastState; STfs *pTfs; SQWorkerPool queryPool; SQWorkerPool fetchPool; diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/main/dndTransport.c index e76633bb1f..3b0aca4b39 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/main/dndTransport.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 . */ - + #define _DEFAULT_SOURCE #include "dndInt.h" @@ -482,4 +482,8 @@ SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) { .parent = pWrapper, .name = pWrapper->name}; return cfg; +} + +void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) { + rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp); } \ No newline at end of file diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c index acf83d4ba8..a8d7590d59 100644 --- a/source/dnode/mgmt/mm/mmHandle.c +++ b/source/dnode/mgmt/mm/mmHandle.c @@ -16,6 +16,15 @@ #define _DEFAULT_SOURCE #include "mmInt.h" +void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant); + if (pWrapper->procType == PROC_CHILD) { + dmGetMonitorSysInfo(&mmInfo->sys); + monGetLogs(&mmInfo->logs); + } +} + int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnode *pDnode = pWrapper->pDnode; SRpcMsg *pReq = &pMsg->rpcMsg; @@ -161,5 +170,4 @@ void mmInitMsgHandle(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE); dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE); dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE); - } diff --git a/source/dnode/mgmt/mm/mmInt.c b/source/dnode/mgmt/mm/mmInt.c index cd6ea1499f..8d4ac80e72 100644 --- a/source/dnode/mgmt/mm/mmInt.c +++ b/source/dnode/mgmt/mm/mmInt.c @@ -241,8 +241,3 @@ void mmSetMgmtFp(SMgmtWrapper *pWrapper) { pWrapper->fp = mgmtFp; } -int32_t mmMonitorMnodeInfo(SMgmtWrapper *pWrapper, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, - SMonGrantInfo *pGrantInfo) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - return mndGetMonitorInfo(pMgmt->pMnode, pClusterInfo, pVgroupInfo, pGrantInfo); -} diff --git a/source/dnode/mgmt/qm/qmHandle.c b/source/dnode/mgmt/qm/qmHandle.c index 77a9db1175..7f1164bda8 100644 --- a/source/dnode/mgmt/qm/qmHandle.c +++ b/source/dnode/mgmt/qm/qmHandle.c @@ -16,6 +16,13 @@ #define _DEFAULT_SOURCE #include "qmInt.h" +void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo) { + if (pWrapper->procType == PROC_CHILD) { + dmGetMonitorSysInfo(&qmInfo->sys); + monGetLogs(&qmInfo->logs); + } +} + int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnode *pDnode = pWrapper->pDnode; SRpcMsg *pReq = &pMsg->rpcMsg; diff --git a/source/dnode/mgmt/sm/smHandle.c b/source/dnode/mgmt/sm/smHandle.c index a1fa41a686..1e275d016b 100644 --- a/source/dnode/mgmt/sm/smHandle.c +++ b/source/dnode/mgmt/sm/smHandle.c @@ -16,6 +16,13 @@ #define _DEFAULT_SOURCE #include "smInt.h" +void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo) { + if (pWrapper->procType == PROC_CHILD) { + dmGetMonitorSysInfo(&smInfo->sys); + monGetLogs(&smInfo->logs); + } +} + int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnode *pDnode = pWrapper->pDnode; SRpcMsg *pReq = &pMsg->rpcMsg; diff --git a/source/dnode/mgmt/vm/vmHandle.c b/source/dnode/mgmt/vm/vmHandle.c index bcb9ef9e5a..6391fe3570 100644 --- a/source/dnode/mgmt/vm/vmHandle.c +++ b/source/dnode/mgmt/vm/vmHandle.c @@ -16,6 +16,28 @@ #define _DEFAULT_SOURCE #include "vmInt.h" +void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + tfsGetMonitorInfo(pMgmt->pTfs, &vmInfo->tfs); + + taosWLockLatch(&pMgmt->latch); + vmInfo->vstat.totalVnodes = pMgmt->state.totalVnodes; + vmInfo->vstat.masterNum = pMgmt->state.masterNum; + vmInfo->vstat.numOfSelectReqs = pMgmt->state.numOfSelectReqs - pMgmt->lastState.numOfSelectReqs; + vmInfo->vstat.numOfInsertReqs = pMgmt->state.numOfInsertReqs - pMgmt->lastState.numOfInsertReqs; + vmInfo->vstat.numOfInsertSuccessReqs = pMgmt->state.numOfInsertSuccessReqs - pMgmt->lastState.numOfInsertSuccessReqs; + vmInfo->vstat.numOfBatchInsertReqs = pMgmt->state.numOfBatchInsertReqs - pMgmt->lastState.numOfBatchInsertReqs; + vmInfo->vstat.numOfBatchInsertSuccessReqs = + pMgmt->state.numOfBatchInsertSuccessReqs - pMgmt->lastState.numOfBatchInsertSuccessReqs; + pMgmt->lastState = pMgmt->state; + taosWUnLockLatch(&pMgmt->latch); + + if (pWrapper->procType == PROC_CHILD) { + dmGetMonitorSysInfo(&vmInfo->sys); + monGetLogs(&vmInfo->logs); + } +} + static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pCfg->vgId = pCreate->vgId; pCfg->wsize = pCreate->cacheBlockSize; diff --git a/source/dnode/mgmt/vm/vmInt.c b/source/dnode/mgmt/vm/vmInt.c index b3390ba31c..6a1a5c3987 100644 --- a/source/dnode/mgmt/vm/vmInt.c +++ b/source/dnode/mgmt/vm/vmInt.c @@ -344,38 +344,21 @@ void vmSetMgmtFp(SMgmtWrapper *pWrapper) { pWrapper->fp = mgmtFp; } -int32_t vmMonitorTfsInfo(SMgmtWrapper *pWrapper, SMonDiskInfo *pInfo) { - SVnodesMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return -1; - - return tfsGetMonitorInfo(pMgmt->pTfs, pInfo); -} - -void vmMonitorVnodeReqs(SMgmtWrapper *pWrapper, SMonDnodeInfo *pInfo) { - SVnodesMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - - SVnodesStat *pStat = &pMgmt->state; - pInfo->req_select = pStat->numOfSelectReqs; - pInfo->req_insert = pStat->numOfInsertReqs; - pInfo->req_insert_success = pStat->numOfInsertSuccessReqs; - pInfo->req_insert_batch = pStat->numOfBatchInsertReqs; - pInfo->req_insert_batch_success = pStat->numOfBatchInsertSuccessReqs; - pInfo->errors = tsNumOfErrorLogs; - pInfo->vnodes_num = pStat->totalVnodes; - pInfo->masters = pStat->masterNum; -} - -void vmMonitorVnodeLoads(SMgmtWrapper *pWrapper, SArray *pLoads) { +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { SVnodesMgmt *pMgmt = pWrapper->pMgmt; SVnodesStat *pStat = &pMgmt->state; - int32_t totalVnodes = 0; - int32_t masterNum = 0; - int64_t numOfSelectReqs = 0; - int64_t numOfInsertReqs = 0; - int64_t numOfInsertSuccessReqs = 0; - int64_t numOfBatchInsertReqs = 0; - int64_t numOfBatchInsertSuccessReqs = 0; + SArray *pLoads = taosArrayInit(pMgmt->state.totalVnodes, sizeof(SVnodeLoad)); + + int32_t totalVnodes = 0; + int32_t masterNum = 0; + int64_t numOfSelectReqs = 0; + int64_t numOfInsertReqs = 0; + int64_t numOfInsertSuccessReqs = 0; + int64_t numOfBatchInsertReqs = 0; + int64_t numOfBatchInsertSuccessReqs = 0; + + pInfo->pVloads = pLoads; + if (pLoads == NULL) return; taosRLockLatch(&pMgmt->latch); @@ -402,6 +385,7 @@ void vmMonitorVnodeLoads(SMgmtWrapper *pWrapper, SArray *pLoads) { taosRUnLockLatch(&pMgmt->latch); + taosWLockLatch(&pMgmt->latch); pStat->totalVnodes = totalVnodes; pStat->masterNum = masterNum; pStat->numOfSelectReqs = numOfSelectReqs; @@ -409,4 +393,5 @@ void vmMonitorVnodeLoads(SMgmtWrapper *pWrapper, SArray *pLoads) { pStat->numOfInsertSuccessReqs = numOfInsertSuccessReqs; pStat->numOfBatchInsertReqs = numOfBatchInsertReqs; pStat->numOfBatchInsertSuccessReqs = numOfBatchInsertSuccessReqs; + taosWUnLockLatch(&pMgmt->latch); } \ No newline at end of file diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c index 27d35d266d..e58179e394 100644 --- a/source/libs/monitor/src/monMsg.c +++ b/source/libs/monitor/src/monMsg.c @@ -18,37 +18,506 @@ #include "tcoding.h" #include "tencode.h" -int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); -int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); -void tFreeSMonMmInfo(SMonMmInfo *pInfo) { +static int32_t tEncodeSMonSysInfo(SCoder *encoder, const SMonSysInfo *pInfo) { + if (tEncodeDouble(encoder, pInfo->cpu_engine) < 0) return -1; + if (tEncodeDouble(encoder, pInfo->cpu_system) < 0) return -1; + if (tEncodeFloat(encoder, pInfo->cpu_cores) < 0) return -1; + if (tEncodeI64(encoder, pInfo->mem_engine) < 0) return -1; + if (tEncodeI64(encoder, pInfo->mem_system) < 0) return -1; + if (tEncodeI64(encoder, pInfo->mem_total) < 0) return -1; + if (tEncodeI64(encoder, pInfo->disk_engine) < 0) return -1; + if (tEncodeI64(encoder, pInfo->disk_used) < 0) return -1; + if (tEncodeI64(encoder, pInfo->disk_total) < 0) return -1; + if (tEncodeI64(encoder, pInfo->net_in) < 0) return -1; + if (tEncodeI64(encoder, pInfo->net_out) < 0) return -1; + if (tEncodeI64(encoder, pInfo->io_read) < 0) return -1; + if (tEncodeI64(encoder, pInfo->io_write) < 0) return -1; + if (tEncodeI64(encoder, pInfo->io_read_disk) < 0) return -1; + if (tEncodeI64(encoder, pInfo->io_write_disk) < 0) return -1; + return 0; +} + +static int32_t tDecodeSMonSysInfo(SCoder *decoder, SMonSysInfo *pInfo) { + if (tDecodeDouble(decoder, &pInfo->cpu_engine) < 0) return -1; + if (tDecodeDouble(decoder, &pInfo->cpu_system) < 0) return -1; + if (tDecodeFloat(decoder, &pInfo->cpu_cores) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->mem_engine) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->mem_system) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->mem_total) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->disk_engine) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->disk_used) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->disk_total) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->net_in) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->net_out) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->io_read) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->io_write) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->io_read_disk) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->io_write_disk) < 0) return -1; + return 0; +} + +int32_t tEncodeSMonLogs(SCoder *encoder, const SMonLogs *pInfo) { + if (tEncodeI32(encoder, pInfo->numOfErrorLogs) < 0) return -1; + if (tEncodeI32(encoder, pInfo->numOfInfoLogs) < 0) return -1; + if (tEncodeI32(encoder, pInfo->numOfDebugLogs) < 0) return -1; + if (tEncodeI32(encoder, pInfo->numOfTraceLogs) < 0) return -1; + if (tEncodeI32(encoder, taosArrayGetSize(pInfo->logs)) < 0) return -1; + for (int32_t i = 0; i < taosArrayGetSize(pInfo->logs); ++i) { + SMonLogItem *pLog = taosArrayGet(pInfo->logs, i); + if (tEncodeI64(encoder, pLog->ts) < 0) return -1; + if (tEncodeI8(encoder, pLog->level) < 0) return -1; + if (tEncodeCStr(encoder, pLog->content) < 0) return -1; + } + return 0; +} + +static int32_t tDecodeSMonLogs(SCoder *decoder, SMonLogs *pInfo) { + if (tDecodeI32(decoder, &pInfo->numOfErrorLogs) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->numOfInfoLogs) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->numOfDebugLogs) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->numOfTraceLogs) < 0) return -1; + + int32_t arraySize = 0; + if (tDecodeI32(decoder, &arraySize) < 0) return -1; + + pInfo->logs = taosArrayInit(arraySize, sizeof(SMonLogItem)); + if (pInfo->logs != NULL) return -1; + + for (int32_t i = 0; i < arraySize; ++i) { + SMonLogItem desc = {0}; + if (tDecodeI64(decoder, &desc.ts) < 0) return -1; + int8_t level = 0; + if (tDecodeI8(decoder, &level) < 0) return -1; + desc.level = level; + if (tDecodeCStrTo(decoder, desc.content) < 0) return -1; + taosArrayPush(pInfo->logs, &desc); + } + + return 0; +} + +int32_t tEncodeSMonClusterInfo(SCoder *encoder, const SMonClusterInfo *pInfo) { + if (tEncodeCStr(encoder, pInfo->first_ep) < 0) return -1; + if (tEncodeI32(encoder, pInfo->first_ep_dnode_id) < 0) return -1; + if (tEncodeCStr(encoder, pInfo->version) < 0) return -1; + if (tEncodeFloat(encoder, pInfo->master_uptime) < 0) return -1; + if (tEncodeI32(encoder, pInfo->monitor_interval) < 0) return -1; + if (tEncodeI32(encoder, pInfo->vgroups_total) < 0) return -1; + if (tEncodeI32(encoder, pInfo->vgroups_alive) < 0) return -1; + if (tEncodeI32(encoder, pInfo->vnodes_total) < 0) return -1; + if (tEncodeI32(encoder, pInfo->vnodes_alive) < 0) return -1; + if (tEncodeI32(encoder, pInfo->connections_total) < 0) return -1; + if (tEncodeI32(encoder, taosArrayGetSize(pInfo->dnodes)) < 0) return -1; + if (tEncodeI32(encoder, taosArrayGetSize(pInfo->mnodes)) < 0) return -1; + for (int32_t i = 0; i < taosArrayGetSize(pInfo->dnodes); ++i) { + SMonDnodeDesc *pDesc = taosArrayGet(pInfo->dnodes, i); + if (tEncodeI32(encoder, pDesc->dnode_id) < 0) return -1; + if (tEncodeCStr(encoder, pDesc->dnode_ep) < 0) return -1; + if (tEncodeCStr(encoder, pDesc->status) < 0) return -1; + } + for (int32_t i = 0; i < taosArrayGetSize(pInfo->mnodes); ++i) { + SMonMnodeDesc *pDesc = taosArrayGet(pInfo->mnodes, i); + if (tEncodeI32(encoder, pDesc->mnode_id) < 0) return -1; + if (tEncodeCStr(encoder, pDesc->mnode_ep) < 0) return -1; + if (tEncodeCStr(encoder, pDesc->role) < 0) return -1; + } + return 0; +} + +int32_t tDecodeSMonClusterInfo(SCoder *decoder, SMonClusterInfo *pInfo) { + if (tDecodeCStrTo(decoder, pInfo->first_ep) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->first_ep_dnode_id) < 0) return -1; + if (tDecodeCStrTo(decoder, pInfo->version) < 0) return -1; + if (tDecodeFloat(decoder, &pInfo->master_uptime) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->monitor_interval) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->vgroups_total) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->vgroups_alive) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->vnodes_total) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->vnodes_alive) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->connections_total) < 0) return -1; + + int32_t dnodesSize = 0; + int32_t mnodesSize = 0; + if (tDecodeI32(decoder, &dnodesSize) < 0) return -1; + if (tDecodeI32(decoder, &mnodesSize) < 0) return -1; + + pInfo->dnodes = taosArrayInit(dnodesSize, sizeof(SMonDnodeDesc)); + pInfo->mnodes = taosArrayInit(mnodesSize, sizeof(SMonMnodeDesc)); + if (pInfo->dnodes != NULL || pInfo->mnodes != NULL) return -1; + + for (int32_t i = 0; i < dnodesSize; ++i) { + SMonDnodeDesc desc = {0}; + if (tDecodeI32(decoder, &desc.dnode_id) < 0) return -1; + if (tDecodeCStrTo(decoder, desc.dnode_ep) < 0) return -1; + if (tDecodeCStrTo(decoder, desc.status) < 0) return -1; + taosArrayPush(pInfo->dnodes, &desc); + } + + for (int32_t i = 0; i < mnodesSize; ++i) { + SMonMnodeDesc desc = {0}; + if (tDecodeI32(decoder, &desc.mnode_id) < 0) return -1; + if (tDecodeCStrTo(decoder, desc.mnode_ep) < 0) return -1; + if (tDecodeCStrTo(decoder, desc.role) < 0) return -1; + taosArrayPush(pInfo->mnodes, &desc); + } + return 0; +} + +int32_t tEncodeSMonVgroupInfo(SCoder *encoder, const SMonVgroupInfo *pInfo) { + if (tEncodeI32(encoder, taosArrayGetSize(pInfo->vgroups)) < 0) return -1; + for (int32_t i = 0; i < taosArrayGetSize(pInfo->vgroups); ++i) { + SMonVgroupDesc *pDesc = taosArrayGet(pInfo->vgroups, i); + if (tEncodeI32(encoder, pDesc->vgroup_id) < 0) return -1; + if (tEncodeI32(encoder, pDesc->tables_num) < 0) return -1; + if (tEncodeCStr(encoder, pDesc->database_name) < 0) return -1; + if (tEncodeCStr(encoder, pDesc->status) < 0) return -1; + for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) { + SMonVnodeDesc *pVDesc = &pDesc->vnodes[j]; + if (tEncodeI32(encoder, pVDesc->dnode_id) < 0) return -1; + if (tEncodeCStr(encoder, pVDesc->vnode_role) < 0) return -1; + } + } + return 0; +} + +int32_t tDecodeSMonVgroupInfo(SCoder *decoder, SMonVgroupInfo *pInfo) { + int32_t arraySize = 0; + if (tDecodeI32(decoder, &arraySize) < 0) return -1; + + pInfo->vgroups = taosArrayInit(arraySize, sizeof(SMonVgroupDesc)); + if (pInfo->vgroups != NULL) return -1; + + for (int32_t i = 0; i < arraySize; ++i) { + SMonVgroupDesc desc = {0}; + if (tDecodeI32(decoder, &desc.vgroup_id) < 0) return -1; + if (tDecodeI32(decoder, &desc.tables_num) < 0) return -1; + if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1; + if (tDecodeCStrTo(decoder, desc.status) < 0) return -1; + for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) { + SMonVnodeDesc vdesc = {0}; + if (tDecodeI32(decoder, &vdesc.dnode_id) < 0) return -1; + if (tDecodeCStrTo(decoder, vdesc.vnode_role) < 0) return -1; + } + taosArrayPush(pInfo->vgroups, &desc); + } + return 0; +} + +int32_t tEncodeSMonGrantInfo(SCoder *encoder, const SMonGrantInfo *pInfo) { + if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1; + if (tEncodeI32(encoder, pInfo->timeseries_used) < 0) return -1; + if (tEncodeI32(encoder, pInfo->timeseries_total) < 0) return -1; + return 0; +} + +int32_t tDecodeSMonGrantInfo(SCoder *decoder, SMonGrantInfo *pInfo) { + if (tDecodeI32(decoder, &pInfo->expire_time) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->timeseries_used) < 0) return -1; + if (tDecodeI32(decoder, &pInfo->timeseries_total) < 0) return -1; + return 0; +} + +int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeSMonClusterInfo(&encoder, &pInfo->cluster) < 0) return -1; + if (tEncodeSMonVgroupInfo(&encoder, &pInfo->vgroup) < 0) return -1; + if (tEncodeSMonGrantInfo(&encoder, &pInfo->grant) < 0) return -1; + if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeSMonClusterInfo(&decoder, &pInfo->cluster) < 0) return -1; + if (tDecodeSMonVgroupInfo(&decoder, &pInfo->vgroup) < 0) return -1; + if (tDecodeSMonGrantInfo(&decoder, &pInfo->grant) < 0) return -1; + if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +void tFreeSMonMmInfo(SMonMmInfo *pInfo) { taosArrayDestroy(pInfo->logs.logs); pInfo->logs.logs = NULL; } -int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); -int32_t tDeserializeSMonVMmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); -void tFreeSMonVmInfo(SMonVmInfo *pInfo) { +int32_t tEncodeSMonDiskDesc(SCoder *encoder, const SMonDiskDesc *pDesc) { + if (tEncodeCStr(encoder, pDesc->name) < 0) return -1; + if (tEncodeI8(encoder, pDesc->level) < 0) return -1; + if (tEncodeI64(encoder, pDesc->size.total) < 0) return -1; + if (tEncodeI64(encoder, pDesc->size.used) < 0) return -1; + if (tEncodeI64(encoder, pDesc->size.avail) < 0) return -1; +} + +static int32_t tDecodeSMonDiskDesc(SCoder *decoder, SMonDiskDesc *pDesc) { + if (tDecodeCStrTo(decoder, pDesc->name) < 0) return -1; + if (tDecodeI8(decoder, &pDesc->level) < 0) return -1; + if (tDecodeI64(decoder, &pDesc->size.total) < 0) return -1; + if (tDecodeI64(decoder, &pDesc->size.used) < 0) return -1; + if (tDecodeI64(decoder, &pDesc->size.avail) < 0) return -1; + return 0; +} + +int32_t tEncodeSMonDiskInfo(SCoder *encoder, const SMonDiskInfo *pInfo) { + if (tEncodeI32(encoder, taosArrayGetSize(pInfo->datadirs)) < 0) return -1; + for (int32_t i = 0; i < taosArrayGetSize(pInfo->datadirs); ++i) { + SMonDiskDesc *pDesc = taosArrayGet(pInfo->datadirs, i); + if (tEncodeSMonDiskDesc(encoder, pDesc) < 0) return -1; + } + return 0; +} + +static int32_t tDecodeSMonDiskInfo(SCoder *decoder, SMonDiskInfo *pInfo) { + int32_t arraySize = 0; + if (tDecodeI32(decoder, &arraySize) < 0) return -1; + + pInfo->datadirs = taosArrayInit(arraySize, sizeof(SMonDiskDesc)); + if (pInfo->datadirs != NULL) return -1; + + for (int32_t i = 0; i < arraySize; ++i) { + SMonDiskDesc desc = {0}; + if (tDecodeSMonDiskDesc(decoder, &desc) < 0) return -1; + taosArrayPush(pInfo->datadirs, &desc); + } + + return 0; +} + +int32_t tEncodeSVnodesStat(SCoder *encoder, const SVnodesStat *pStat) { + if (tEncodeI32(encoder, pStat->openVnodes) < 0) return -1; + if (tEncodeI32(encoder, pStat->totalVnodes) < 0) return -1; + if (tEncodeI32(encoder, pStat->masterNum) < 0) return -1; + if (tEncodeI64(encoder, pStat->numOfSelectReqs) < 0) return -1; + if (tEncodeI64(encoder, pStat->numOfInsertReqs) < 0) return -1; + if (tEncodeI64(encoder, pStat->numOfInsertSuccessReqs) < 0) return -1; + if (tEncodeI64(encoder, pStat->numOfBatchInsertReqs) < 0) return -1; + if (tEncodeI64(encoder, pStat->numOfBatchInsertSuccessReqs) < 0) return -1; + if (tEncodeI64(encoder, pStat->errors) < 0) return -1; + return 0; +} + +static int32_t tDecodeSVnodesStat(SCoder *decoder, SVnodesStat *pStat) { + if (tDecodeI32(decoder, &pStat->openVnodes) < 0) return -1; + if (tDecodeI32(decoder, &pStat->totalVnodes) < 0) return -1; + if (tDecodeI32(decoder, &pStat->masterNum) < 0) return -1; + if (tDecodeI64(decoder, &pStat->numOfSelectReqs) < 0) return -1; + if (tDecodeI64(decoder, &pStat->numOfInsertReqs) < 0) return -1; + if (tDecodeI64(decoder, &pStat->numOfInsertSuccessReqs) < 0) return -1; + if (tDecodeI64(decoder, &pStat->numOfBatchInsertReqs) < 0) return -1; + if (tDecodeI64(decoder, &pStat->numOfBatchInsertSuccessReqs) < 0) return -1; + if (tDecodeI64(decoder, &pStat->errors) < 0) return -1; + return 0; +} + +int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeSMonDiskInfo(&encoder, &pInfo->tfs) < 0) return -1; + if (tEncodeSVnodesStat(&encoder, &pInfo->vstat) < 0) return -1; + if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeSMonDiskInfo(&decoder, &pInfo->tfs) < 0) return -1; + if (tDecodeSVnodesStat(&decoder, &pInfo->vstat) < 0) return -1; + if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +void tFreeSMonVmInfo(SMonVmInfo *pInfo) { taosArrayDestroy(pInfo->logs.logs); pInfo->logs.logs = NULL; } -int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); -int32_t tDeserializeSMonQMmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); -void tFreeSMonQmInfo(SMonQmInfo *pInfo) { +int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +void tFreeSMonQmInfo(SMonQmInfo *pInfo) { taosArrayDestroy(pInfo->logs.logs); pInfo->logs.logs = NULL; } -int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); -int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); -void tFreeSMonSmInfo(SMonSmInfo *pInfo) { +int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +void tFreeSMonSmInfo(SMonSmInfo *pInfo) { taosArrayDestroy(pInfo->logs.logs); pInfo->logs.logs = NULL; } -int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); -int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); -void tFreeSMonBmInfo(SMonBmInfo *pInfo) { +int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + tEndDecode(&decoder); + + tCoderClear(&decoder); + return 0; +} + +void tFreeSMonBmInfo(SMonBmInfo *pInfo) { taosArrayDestroy(pInfo->logs.logs); pInfo->logs.logs = NULL; +} + +int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) { + SCoder encoder = {0}; + tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); + + if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI32(&encoder, taosArrayGetSize(pInfo->pVloads)) < 0) return -1; + for (int32_t i = 0; i < taosArrayGetSize(pInfo->pVloads); ++i) { + SVnodeLoad *pLoad = taosArrayGet(pInfo->pVloads, i); + if (tEncodeI32(&encoder, pLoad->vgId) < 0) return -1; + if (tEncodeI8(&encoder, pLoad->role) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->numOfTables) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->numOfTimeSeries) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->totalStorage) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->compStorage) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->pointsWritten) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->numOfSelectReqs) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->numOfInsertReqs) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->numOfInsertSuccessReqs) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->numOfBatchInsertReqs) < 0) return -1; + if (tEncodeI64(&encoder, pLoad->numOfBatchInsertSuccessReqs) < 0) return -1; + } + tEndEncode(&encoder); + + int32_t tlen = encoder.pos; + tCoderClear(&encoder); + return tlen; +} + +int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) { + SCoder decoder = {0}; + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); + + if (tStartDecode(&decoder) < 0) return -1; + + int32_t arraySize = 0; + if (tDecodeI32(&decoder, &arraySize) < 0) return -1; + + pInfo->pVloads = taosArrayInit(arraySize, sizeof(SVnodeLoad)); + if (pInfo->pVloads != NULL) return -1; + + for (int32_t i = 0; i < arraySize; ++i) { + SVnodeLoad load = {0}; + if (tDecodeI32(&decoder, &load.vgId) < 0) return -1; + if (tDecodeI8(&decoder, &load.role) < 0) return -1; + if (tDecodeI64(&decoder, &load.numOfTables) < 0) return -1; + if (tDecodeI64(&decoder, &load.numOfTimeSeries) < 0) return -1; + if (tDecodeI64(&decoder, &load.totalStorage) < 0) return -1; + if (tDecodeI64(&decoder, &load.compStorage) < 0) return -1; + if (tDecodeI64(&decoder, &load.pointsWritten) < 0) return -1; + if (tDecodeI64(&decoder, &load.numOfSelectReqs) < 0) return -1; + if (tDecodeI64(&decoder, &load.numOfInsertReqs) < 0) return -1; + if (tDecodeI64(&decoder, &load.numOfInsertSuccessReqs) < 0) return -1; + if (tDecodeI64(&decoder, &load.numOfBatchInsertReqs) < 0) return -1; + if (tDecodeI64(&decoder, &load.numOfBatchInsertSuccessReqs) < 0) return -1; + taosArrayPush(pInfo->pVloads, &load); + } + + tEndDecode(&decoder); + tCoderClear(&decoder); + return 0; +} + +void tFreeSMonVloadInfo(SMonVloadInfo *pInfo) { + taosArrayDestroy(pInfo->pVloads); + pInfo->pVloads = NULL; } \ No newline at end of file From 8ef6b184f2a41b0ba5d6708a8854c34a2a68ef1d Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Fri, 8 Apr 2022 19:44:15 +0800 Subject: [PATCH 49/57] first(*)/last(*) rewrite --- include/libs/nodes/nodes.h | 16 +++- source/libs/nodes/src/nodesUtilFuncs.c | 45 ++++++++- source/libs/parser/src/parTranslater.c | 124 ++++++++++++++++++++----- 3 files changed, 157 insertions(+), 28 deletions(-) diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 28e5483552..39448ceef3 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -30,11 +30,19 @@ extern "C" { #define FOREACH(node, list) \ for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext) -// only be use in FOREACH -#define ERASE_NODE(list) cell = nodesListErase(list, cell); - #define REPLACE_NODE(newNode) cell->pNode = (SNode*)(newNode) +#define INSERT_LIST(target, src) nodesListInsertList((target), cell, src) + +#define WHERE_EACH(node, list) \ + SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); \ + while (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)) + +#define WHERE_NEXT cell = cell->pNext + +// only be use in WHERE_EACH +#define ERASE_NODE(list) cell = nodesListErase((list), cell) + #define FORBOTH(node1, list1, node2, list2) \ for (SListCell* cell1 = (NULL != (list1) ? (list1)->pHead : NULL), *cell2 = (NULL != (list2) ? (list2)->pHead : NULL); \ (NULL == cell1 ? (node1 = NULL, false) : (node1 = cell1->pNode, true)), (NULL == cell2 ? (node2 = NULL, false) : (node2 = cell2->pNode, true)), (node1 != NULL && node2 != NULL); \ @@ -202,7 +210,9 @@ int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode); int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode); int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc); int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc); +int32_t nodesListPushFront(SNodeList* pList, SNodeptr pNode); SListCell* nodesListErase(SNodeList* pList, SListCell* pCell); +void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc); SNodeptr nodesListGetNode(SNodeList* pList, int32_t index); void nodesDestroyList(SNodeList* pList); // Only clear the linked list structure, without releasing the elements inside diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 95a3280fc2..074ec4dcae 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -644,7 +644,7 @@ SNodeList* nodesMakeList() { int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode) { if (NULL == pList || NULL == pNode) { - return TSDB_CODE_SUCCESS; + return TSDB_CODE_FAILED; } SListCell* p = taosMemoryCalloc(1, sizeof(SListCell)); if (NULL == p) { @@ -688,7 +688,7 @@ int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode) { int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) { if (NULL == pTarget || NULL == pSrc) { - return TSDB_CODE_SUCCESS; + return TSDB_CODE_FAILED; } if (NULL == pTarget->pHead) { @@ -717,11 +717,34 @@ int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc) { return code; } +int32_t nodesListPushFront(SNodeList* pList, SNodeptr pNode) { + if (NULL == pList || NULL == pNode) { + return TSDB_CODE_FAILED; + } + SListCell* p = taosMemoryCalloc(1, sizeof(SListCell)); + if (NULL == p) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; + } + p->pNode = pNode; + if (NULL != pList->pHead) { + pList->pHead->pPrev = p; + p->pNext = pList->pHead; + } + pList->pHead = p; + ++(pList->length); + return TSDB_CODE_SUCCESS; +} + SListCell* nodesListErase(SNodeList* pList, SListCell* pCell) { if (NULL == pCell->pPrev) { pList->pHead = pCell->pNext; } else { pCell->pPrev->pNext = pCell->pNext; + } + if (NULL == pCell->pNext) { + pList->pTail = pCell->pPrev; + } else { pCell->pNext->pPrev = pCell->pPrev; } SListCell* pNext = pCell->pNext; @@ -731,6 +754,24 @@ SListCell* nodesListErase(SNodeList* pList, SListCell* pCell) { return pNext; } +void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* pSrc) { + if (NULL == pTarget || NULL == pPos || NULL == pSrc) { + return; + } + + if (NULL == pPos->pPrev) { + pTarget->pHead = pSrc->pHead; + } else { + pPos->pPrev->pNext = pSrc->pHead; + } + pSrc->pHead->pPrev = pPos->pPrev; + pSrc->pTail->pNext = pPos; + pPos->pPrev = pSrc->pTail; + + pTarget->length += pSrc->length; + taosMemoryFreeClear(pSrc); +} + SNodeptr nodesListGetNode(SNodeList* pList, int32_t index) { SNode* node; FOREACH(node, pList) { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 88c3d5b549..cad6de719e 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -743,24 +743,99 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { return code; } -static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect, bool* pIsSelectStar) { +static int32_t createAllColumns(STranslateContext* pCxt, SNodeList** pCols) { + *pCols = nodesMakeList(); + if (NULL == *pCols) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY); + } + SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); + size_t nums = taosArrayGetSize(pTables); + for (size_t i = 0; i < nums; ++i) { + STableNode* pTable = taosArrayGetP(pTables, i); + int32_t code = createColumnNodeByTable(pCxt, pTable, *pCols); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + } + return TSDB_CODE_SUCCESS; +} + +static bool isFirstLastFunc(SFunctionNode* pFunc) { + return (FUNCTION_TYPE_FIRST == pFunc->funcType || FUNCTION_TYPE_LAST == pFunc->funcType); +} + +static bool isFirstLastStar(SNode* pNode) { + if (QUERY_NODE_FUNCTION != nodeType(pNode) || !isFirstLastFunc((SFunctionNode*)pNode)) { + return false; + } + SNodeList* pParameterList = ((SFunctionNode*)pNode)->pParameterList; + if (LIST_LENGTH(pParameterList) != 1) { + return false; + } + SNode* pParam = nodesListGetNode(pParameterList, 0); + return (QUERY_NODE_COLUMN == nodeType(pParam) ? 0 == strcmp(((SColumnNode*)pParam)->colName, "*") : false); +} + +static SNode* createFirstLastFunc(SFunctionNode* pSrcFunc, SColumnNode* pCol) { + SFunctionNode* pFunc = nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pFunc) { + return NULL; + } + pFunc->pParameterList = nodesMakeList(); + if (NULL == pFunc->pParameterList || TSDB_CODE_SUCCESS != nodesListAppend(pFunc->pParameterList, pCol)) { + nodesDestroyNode(pFunc); + return NULL; + } + + pFunc->node.resType = pCol->node.resType; + pFunc->funcId = pSrcFunc->funcId; + pFunc->funcType = pSrcFunc->funcType; + strcpy(pFunc->functionName, pSrcFunc->functionName); + snprintf(pFunc->node.aliasName, sizeof(pFunc->node.aliasName), (FUNCTION_TYPE_FIRST == pSrcFunc->funcType ? "first(%s)" : "last(%s)"), pCol->colName); + + return (SNode*)pFunc; +} + +static int32_t createFirstLastAllCols(STranslateContext* pCxt, SFunctionNode* pSrcFunc, SNodeList** pOutput) { + SNodeList* pCols = NULL; + if (TSDB_CODE_SUCCESS != createAllColumns(pCxt, &pCols)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + SNodeList* pFuncs = nodesMakeList(); + if (NULL == pFuncs) { + return TSDB_CODE_OUT_OF_MEMORY; + } + SNode* pCol = NULL; + FOREACH(pCol, pCols) { + if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pFuncs, createFirstLastFunc(pSrcFunc, (SColumnNode*)pCol))) { + nodesDestroyNode(pFuncs); + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + *pOutput = pFuncs; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) { if (NULL == pSelect->pProjectionList) { // select * ... - SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); - size_t nums = taosArrayGetSize(pTables); - pSelect->pProjectionList = nodesMakeList(); - if (NULL == pSelect->pProjectionList) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY); - } - for (size_t i = 0; i < nums; ++i) { - STableNode* pTable = taosArrayGetP(pTables, i); - int32_t code = createColumnNodeByTable(pCxt, pTable, pSelect->pProjectionList); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - } - *pIsSelectStar = true; + return createAllColumns(pCxt, &pSelect->pProjectionList); } else { // todo : t.* + SNode* pNode = NULL; + WHERE_EACH(pNode, pSelect->pProjectionList) { + if (isFirstLastStar(pNode)) { + SNodeList* pFuncs = NULL; + if (TSDB_CODE_SUCCESS != createFirstLastAllCols(pCxt, (SFunctionNode*)pNode, &pFuncs)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + INSERT_LIST(pSelect->pProjectionList, pFuncs); + ERASE_NODE(pSelect->pProjectionList); + continue; + } + WHERE_NEXT; + } } return TSDB_CODE_SUCCESS; } @@ -797,8 +872,8 @@ static int32_t getPositionValue(const SValueNode* pVal) { static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pProjectionList, SNodeList* pOrderByList, bool* pOther) { *pOther = false; - SNode* pNode; - FOREACH(pNode, pOrderByList) { + SNode* pNode = NULL; + WHERE_EACH(pNode, pOrderByList) { SNode* pExpr = ((SOrderByExprNode*)pNode)->pExpr; if (QUERY_NODE_VALUE == nodeType(pExpr)) { SValueNode* pVal = (SValueNode*)pExpr; @@ -823,6 +898,7 @@ static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pPro } else { *pOther = true; } + WHERE_NEXT; } return TSDB_CODE_SUCCESS; } @@ -845,11 +921,10 @@ static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) { } static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect) { - bool isSelectStar = false; - int32_t code = translateStar(pCxt, pSelect, &isSelectStar); - if (TSDB_CODE_SUCCESS == code && !isSelectStar) { - pCxt->currClause = SQL_CLAUSE_SELECT; - code = translateExprList(pCxt, pSelect->pProjectionList); + pCxt->currClause = SQL_CLAUSE_SELECT; + int32_t code = translateExprList(pCxt, pSelect->pProjectionList); + if (TSDB_CODE_SUCCESS == code) { + code = translateStar(pCxt, pSelect); } if (TSDB_CODE_SUCCESS == code) { code = checkExprListForGroupBy(pCxt, pSelect->pProjectionList); @@ -1829,10 +1904,13 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS pSelect->pFromTable = (SNode*)pTable; pSelect->pProjectionList = nodesCloneList(pStmt->pOptions->pFuncs); - if (NULL == pTable) { + SFunctionNode* pFunc = nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pSelect->pProjectionList || NULL == pFunc) { nodesDestroyNode(pSelect); return TSDB_CODE_OUT_OF_MEMORY; } + strcpy(pFunc->functionName, "_wstartts"); + nodesListPushFront(pSelect->pProjectionList, pFunc); SNode* pProject = NULL; FOREACH(pProject, pSelect->pProjectionList) { sprintf(((SExprNode*)pProject)->aliasName, "#sma_%p", pProject); From b34ea72a04fe644324b14818aa9c6344c453e178 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 8 Apr 2022 19:59:10 +0800 Subject: [PATCH 50/57] feat[cluster]: send monitor information in multi-process mode --- include/libs/monitor/monitor.h | 10 +++--- source/dnode/mgmt/bm/bmHandle.c | 2 +- source/dnode/mgmt/dm/dmWorker.c | 10 +++--- source/dnode/mgmt/inc/dmInt.h | 2 +- source/dnode/mgmt/mm/mmHandle.c | 2 +- source/dnode/mgmt/qm/qmHandle.c | 2 +- source/dnode/mgmt/sm/smHandle.c | 2 +- source/dnode/mgmt/vm/vmHandle.c | 2 +- source/libs/monitor/inc/monInt.h | 2 +- source/libs/monitor/src/monMain.c | 32 +++++++++---------- source/libs/monitor/src/monMsg.c | 48 ++++++++++++++++------------ source/libs/monitor/test/monTest.cpp | 10 +++--- source/os/src/osSysinfo.c | 4 +-- 13 files changed, 68 insertions(+), 60 deletions(-) diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index 3cecb139e1..f5080fbe7b 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -143,7 +143,7 @@ typedef struct { SMonVgroupInfo vgroup; SMonGrantInfo grant; SMonSysInfo sys; - SMonLogs logs; + SMonLogs log; } SMonMmInfo; int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo); @@ -158,7 +158,7 @@ typedef struct { SMonDiskInfo tfs; SVnodesStat vstat; SMonSysInfo sys; - SMonLogs logs; + SMonLogs log; } SMonVmInfo; int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo); @@ -167,7 +167,7 @@ void tFreeSMonVmInfo(SMonVmInfo *pInfo); typedef struct { SMonSysInfo sys; - SMonLogs logs; + SMonLogs log; } SMonQmInfo; int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo); @@ -176,7 +176,7 @@ void tFreeSMonQmInfo(SMonQmInfo *pInfo); typedef struct { SMonSysInfo sys; - SMonLogs logs; + SMonLogs log; } SMonSmInfo; int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); @@ -184,7 +184,7 @@ int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo); void tFreeSMonSmInfo(SMonSmInfo *pInfo); typedef struct { SMonSysInfo sys; - SMonLogs logs; + SMonLogs log; } SMonBmInfo; int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo); diff --git a/source/dnode/mgmt/bm/bmHandle.c b/source/dnode/mgmt/bm/bmHandle.c index 8abfa8955c..4ab000cb4e 100644 --- a/source/dnode/mgmt/bm/bmHandle.c +++ b/source/dnode/mgmt/bm/bmHandle.c @@ -19,7 +19,7 @@ void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo) { if (pWrapper->procType == PROC_CHILD) { dmGetMonitorSysInfo(&bmInfo->sys); - monGetLogs(&bmInfo->logs); + monGetLogs(&bmInfo->log); } } diff --git a/source/dnode/mgmt/dm/dmWorker.c b/source/dnode/mgmt/dm/dmWorker.c index 7b2a3c7015..a6d0f4491a 100644 --- a/source/dnode/mgmt/dm/dmWorker.c +++ b/source/dnode/mgmt/dm/dmWorker.c @@ -119,9 +119,9 @@ int32_t dmStartWorker(SDnodeMgmt *pMgmt) { return -1; } - SSingleWorkerCfg scfg = {.min = 1, .max = 1, .name = "dnode-status", .fp = (FItem)dmProcessQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->statusWorker, &scfg) != 0) { - dError("failed to start dnode status worker since %s", terrstr()); + SSingleWorkerCfg scfg = {.min = 1, .max = 1, .name = "dnode-monitor", .fp = (FItem)dmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->monitorWorker, &scfg) != 0) { + dError("failed to start dnode monitor worker since %s", terrstr()); return -1; } @@ -131,7 +131,7 @@ int32_t dmStartWorker(SDnodeMgmt *pMgmt) { void dmStopWorker(SDnodeMgmt *pMgmt) { tSingleWorkerCleanup(&pMgmt->mgmtWorker); - tSingleWorkerCleanup(&pMgmt->statusWorker); + tSingleWorkerCleanup(&pMgmt->monitorWorker); if (pMgmt->threadId != NULL) { taosDestoryThread(pMgmt->threadId); @@ -151,7 +151,7 @@ int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnodeMgmt *pMgmt = pWrapper->pMgmt; - SSingleWorker *pWorker = &pMgmt->statusWorker; + SSingleWorker *pWorker = &pMgmt->monitorWorker; dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); taosWriteQitem(pWorker->queue, pMsg); diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/inc/dmInt.h index eee529757e..6d37f59595 100644 --- a/source/dnode/mgmt/inc/dmInt.h +++ b/source/dnode/mgmt/inc/dmInt.h @@ -32,7 +32,7 @@ typedef struct SDnodeMgmt { TdThread *threadId; SRWLatch latch; SSingleWorker mgmtWorker; - SSingleWorker statusWorker; + SSingleWorker monitorWorker; SMsgCb msgCb; const char *path; SDnode *pDnode; diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c index eb7edd21d1..1ebcfdcda9 100644 --- a/source/dnode/mgmt/mm/mmHandle.c +++ b/source/dnode/mgmt/mm/mmHandle.c @@ -21,7 +21,7 @@ void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant); if (pWrapper->procType == PROC_CHILD) { dmGetMonitorSysInfo(&mmInfo->sys); - monGetLogs(&mmInfo->logs); + monGetLogs(&mmInfo->log); } } diff --git a/source/dnode/mgmt/qm/qmHandle.c b/source/dnode/mgmt/qm/qmHandle.c index 7f1164bda8..3c29bd717b 100644 --- a/source/dnode/mgmt/qm/qmHandle.c +++ b/source/dnode/mgmt/qm/qmHandle.c @@ -19,7 +19,7 @@ void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo) { if (pWrapper->procType == PROC_CHILD) { dmGetMonitorSysInfo(&qmInfo->sys); - monGetLogs(&qmInfo->logs); + monGetLogs(&qmInfo->log); } } diff --git a/source/dnode/mgmt/sm/smHandle.c b/source/dnode/mgmt/sm/smHandle.c index 1e275d016b..214dc581b8 100644 --- a/source/dnode/mgmt/sm/smHandle.c +++ b/source/dnode/mgmt/sm/smHandle.c @@ -19,7 +19,7 @@ void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo) { if (pWrapper->procType == PROC_CHILD) { dmGetMonitorSysInfo(&smInfo->sys); - monGetLogs(&smInfo->logs); + monGetLogs(&smInfo->log); } } diff --git a/source/dnode/mgmt/vm/vmHandle.c b/source/dnode/mgmt/vm/vmHandle.c index 2c7063b6f6..0433846ca1 100644 --- a/source/dnode/mgmt/vm/vmHandle.c +++ b/source/dnode/mgmt/vm/vmHandle.c @@ -34,7 +34,7 @@ void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo) { if (pWrapper->procType == PROC_CHILD) { dmGetMonitorSysInfo(&vmInfo->sys); - monGetLogs(&vmInfo->logs); + monGetLogs(&vmInfo->log); } } diff --git a/source/libs/monitor/inc/monInt.h b/source/libs/monitor/inc/monInt.h index 4b10aacdee..ae1af4ba62 100644 --- a/source/libs/monitor/inc/monInt.h +++ b/source/libs/monitor/inc/monInt.h @@ -24,7 +24,7 @@ typedef struct { int64_t curTime; int64_t lastTime; SJson *pJson; - SMonLogs logs; + SMonLogs log; SMonDmInfo dmInfo; SMonMmInfo mmInfo; SMonVmInfo vmInfo; diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 1938b0d859..c012911e8b 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -124,7 +124,7 @@ void monCleanup() { static void monCleanupMonitorInfo(SMonInfo *pMonitor) { tsMonitor.lastTime = pMonitor->curTime; - taosArrayDestroy(pMonitor->logs.logs); + taosArrayDestroy(pMonitor->log.logs); tFreeSMonMmInfo(&pMonitor->mmInfo); tFreeSMonVmInfo(&pMonitor->vmInfo); tFreeSMonSmInfo(&pMonitor->smInfo); @@ -141,7 +141,7 @@ static SMonInfo *monCreateMonitorInfo() { return NULL; } - monGetLogs(&pMonitor->logs); + monGetLogs(&pMonitor->log); taosThreadMutexLock(&tsMonitor.lock); memcpy(&pMonitor->dmInfo, &tsMonitor.dmInfo, sizeof(SMonDmInfo)); @@ -159,7 +159,7 @@ static SMonInfo *monCreateMonitorInfo() { taosThreadMutexUnlock(&tsMonitor.lock); pMonitor->pJson = tjsonCreateObject(); - if (pMonitor->pJson == NULL || pMonitor->logs.logs == NULL) { + if (pMonitor->pJson == NULL || pMonitor->log.logs == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; monCleanupMonitorInfo(pMonitor); return NULL; @@ -447,12 +447,12 @@ static void monGenLogJson(SMonInfo *pMonitor) { if (pLogsJson == NULL) return; SMonLogs *logs[6]; - logs[0] = &pMonitor->logs; - logs[1] = &pMonitor->mmInfo.logs; - logs[2] = &pMonitor->vmInfo.logs; - logs[3] = &pMonitor->smInfo.logs; - logs[4] = &pMonitor->qmInfo.logs; - logs[5] = &pMonitor->bmInfo.logs; + logs[0] = &pMonitor->log; + logs[1] = &pMonitor->mmInfo.log; + logs[2] = &pMonitor->vmInfo.log; + logs[3] = &pMonitor->smInfo.log; + logs[4] = &pMonitor->qmInfo.log; + logs[5] = &pMonitor->bmInfo.log; int32_t numOfErrorLogs = 0; int32_t numOfInfoLogs = 0; @@ -460,17 +460,17 @@ static void monGenLogJson(SMonInfo *pMonitor) { int32_t numOfTraceLogs = 0; for (int32_t j = 0; j < 6; j++) { - SMonLogs *pLogs = logs[j]; - numOfErrorLogs += pLogs->numOfErrorLogs; - numOfInfoLogs += pLogs->numOfInfoLogs; - numOfDebugLogs += pLogs->numOfDebugLogs; - numOfTraceLogs += pLogs->numOfTraceLogs; + SMonLogs *pLog = logs[j]; + numOfErrorLogs += pLog->numOfErrorLogs; + numOfInfoLogs += pLog->numOfInfoLogs; + numOfDebugLogs += pLog->numOfDebugLogs; + numOfTraceLogs += pLog->numOfTraceLogs; - for (int32_t i = 0; i < taosArrayGetSize(pLogs->logs); ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pLog->logs); ++i) { SJson *pLogJson = tjsonCreateObject(); if (pLogJson == NULL) continue; - SMonLogItem *pLogItem = taosArrayGet(pLogs->logs, i); + SMonLogItem *pLogItem = taosArrayGet(pLog->logs, i); char buf[40] = {0}; taosFormatUtcTime(buf, sizeof(buf), pLogItem->ts, TSDB_TIME_PRECISION_MILLI); diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c index e58179e394..78a99b1066 100644 --- a/source/libs/monitor/src/monMsg.c +++ b/source/libs/monitor/src/monMsg.c @@ -226,7 +226,7 @@ int32_t tSerializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { if (tEncodeSMonVgroupInfo(&encoder, &pInfo->vgroup) < 0) return -1; if (tEncodeSMonGrantInfo(&encoder, &pInfo->grant) < 0) return -1; if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -243,7 +243,7 @@ int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { if (tDecodeSMonVgroupInfo(&decoder, &pInfo->vgroup) < 0) return -1; if (tDecodeSMonGrantInfo(&decoder, &pInfo->grant) < 0) return -1; if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; tEndDecode(&decoder); tCoderClear(&decoder); @@ -251,8 +251,14 @@ int32_t tDeserializeSMonMmInfo(void *buf, int32_t bufLen, SMonMmInfo *pInfo) { } void tFreeSMonMmInfo(SMonMmInfo *pInfo) { - taosArrayDestroy(pInfo->logs.logs); - pInfo->logs.logs = NULL; + taosArrayDestroy(pInfo->log.logs); + taosArrayDestroy(pInfo->cluster.mnodes); + taosArrayDestroy(pInfo->cluster.dnodes); + taosArrayDestroy(pInfo->vgroup.vgroups); + pInfo->cluster.mnodes = NULL; + pInfo->cluster.dnodes = NULL; + pInfo->vgroup.vgroups = NULL; + pInfo->log.logs = NULL; } int32_t tEncodeSMonDiskDesc(SCoder *encoder, const SMonDiskDesc *pDesc) { @@ -331,7 +337,7 @@ int32_t tSerializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { if (tEncodeSMonDiskInfo(&encoder, &pInfo->tfs) < 0) return -1; if (tEncodeSVnodesStat(&encoder, &pInfo->vstat) < 0) return -1; if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -347,7 +353,7 @@ int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { if (tDecodeSMonDiskInfo(&decoder, &pInfo->tfs) < 0) return -1; if (tDecodeSVnodesStat(&decoder, &pInfo->vstat) < 0) return -1; if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; tEndDecode(&decoder); tCoderClear(&decoder); @@ -355,8 +361,10 @@ int32_t tDeserializeSMonVmInfo(void *buf, int32_t bufLen, SMonVmInfo *pInfo) { } void tFreeSMonVmInfo(SMonVmInfo *pInfo) { - taosArrayDestroy(pInfo->logs.logs); - pInfo->logs.logs = NULL; + taosArrayDestroy(pInfo->log.logs); + taosArrayDestroy(pInfo->tfs.datadirs); + pInfo->log.logs = NULL; + pInfo->tfs.datadirs = NULL; } int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { @@ -365,7 +373,7 @@ int32_t tSerializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { if (tStartEncode(&encoder) < 0) return -1; if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -379,7 +387,7 @@ int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { if (tStartDecode(&decoder) < 0) return -1; if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; tEndDecode(&decoder); tCoderClear(&decoder); @@ -387,8 +395,8 @@ int32_t tDeserializeSMonQmInfo(void *buf, int32_t bufLen, SMonQmInfo *pInfo) { } void tFreeSMonQmInfo(SMonQmInfo *pInfo) { - taosArrayDestroy(pInfo->logs.logs); - pInfo->logs.logs = NULL; + taosArrayDestroy(pInfo->log.logs); + pInfo->log.logs = NULL; } int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { @@ -397,7 +405,7 @@ int32_t tSerializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { if (tStartEncode(&encoder) < 0) return -1; if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -411,7 +419,7 @@ int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { if (tStartDecode(&decoder) < 0) return -1; if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; tEndDecode(&decoder); tCoderClear(&decoder); @@ -419,8 +427,8 @@ int32_t tDeserializeSMonSmInfo(void *buf, int32_t bufLen, SMonSmInfo *pInfo) { } void tFreeSMonSmInfo(SMonSmInfo *pInfo) { - taosArrayDestroy(pInfo->logs.logs); - pInfo->logs.logs = NULL; + taosArrayDestroy(pInfo->log.logs); + pInfo->log.logs = NULL; } int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { @@ -429,7 +437,7 @@ int32_t tSerializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { if (tStartEncode(&encoder) < 0) return -1; if (tEncodeSMonSysInfo(&encoder, &pInfo->sys) < 0) return -1; - if (tEncodeSMonLogs(&encoder, &pInfo->logs) < 0) return -1; + if (tEncodeSMonLogs(&encoder, &pInfo->log) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -443,7 +451,7 @@ int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { if (tStartDecode(&decoder) < 0) return -1; if (tDecodeSMonSysInfo(&decoder, &pInfo->sys) < 0) return -1; - if (tDecodeSMonLogs(&decoder, &pInfo->logs) < 0) return -1; + if (tDecodeSMonLogs(&decoder, &pInfo->log) < 0) return -1; tEndDecode(&decoder); tCoderClear(&decoder); @@ -451,8 +459,8 @@ int32_t tDeserializeSMonBmInfo(void *buf, int32_t bufLen, SMonBmInfo *pInfo) { } void tFreeSMonBmInfo(SMonBmInfo *pInfo) { - taosArrayDestroy(pInfo->logs.logs); - pInfo->logs.logs = NULL; + taosArrayDestroy(pInfo->log.logs); + pInfo->log.logs = NULL; } int32_t tSerializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInfo) { diff --git a/source/libs/monitor/test/monTest.cpp b/source/libs/monitor/test/monTest.cpp index af12297215..ceb9805e3d 100644 --- a/source/libs/monitor/test/monTest.cpp +++ b/source/libs/monitor/test/monTest.cpp @@ -248,25 +248,25 @@ TEST_F(MonitorTest, 01_Full) { GetVgroupInfo(&mmInfo.vgroup); GetGrantInfo(&mmInfo.grant); GetSysInfo(&mmInfo.sys); - GetLogInfo(&mmInfo.logs); + GetLogInfo(&mmInfo.log); SMonVmInfo vmInfo = {0}; GetDiskInfo(&vmInfo.tfs); GetVnodeStat(&vmInfo.vstat); GetSysInfo(&vmInfo.sys); - GetLogInfo(&vmInfo.logs); + GetLogInfo(&vmInfo.log); SMonQmInfo qmInfo = {0}; GetSysInfo(&qmInfo.sys); - GetLogInfo(&qmInfo.logs); + GetLogInfo(&qmInfo.log); SMonSmInfo smInfo = {0}; GetSysInfo(&smInfo.sys); - GetLogInfo(&smInfo.logs); + GetLogInfo(&smInfo.log); SMonBmInfo bmInfo = {0}; GetSysInfo(&bmInfo.sys); - GetLogInfo(&bmInfo.logs); + GetLogInfo(&bmInfo.log); monSetDmInfo(&dmInfo); monSetMmInfo(&mmInfo); diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 5e71505658..26de26ab67 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -623,7 +623,7 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i static int64_t cur_wchars = 0; static int64_t cur_read_bytes = 0; static int64_t cur_write_bytes = 0; - if (taosGetProcIO(&cur_rchars, &cur_wchars, &cur_read_bytes, &cur_write_bytes) != 0) { + if (taosGetProcIO(&cur_rchars, &cur_wchars, &cur_read_bytes, &cur_write_bytes) == 0) { *rchars = cur_rchars - last_rchars; *wchars = cur_wchars - last_wchars; *read_bytes = cur_read_bytes - last_read_bytes; @@ -696,7 +696,7 @@ void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { static int64_t cur_receive_bytes = 0; static int64_t cur_transmit_bytes = 0; - if (taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes) != 0) { + if (taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes) == 0) { *receive_bytes = cur_receive_bytes - last_receive_bytes; *transmit_bytes = cur_transmit_bytes - last_transmit_bytes; last_receive_bytes = cur_receive_bytes; From 743649e1b7b19295fb8e99e7091ad8d8c13f3599 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 8 Apr 2022 20:37:57 +0800 Subject: [PATCH 51/57] [query]: fix length/char_length data block pointer with proper offset TD-14572 --- source/libs/scalar/src/sclfunc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index df9e1bf36d..8fa417306b 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -295,11 +295,11 @@ static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarP SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - char *in = pInputData->pData; + char *in = pInputData->pData + pInputData->varmeta.offset[0]; int16_t *out = (int16_t *)pOutputData->pData; for (int32_t i = 0; i < pInput->numOfRows; ++i) { - if (colDataIsNull_f(pInputData->nullbitmap, i)) { + if (colDataIsNull_s(pInputData, i)) { colDataSetNull_f(pOutputData->nullbitmap, i); continue; } From da2d8efc96101948a2ca2b43f8bb5f2eaf952aff Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 8 Apr 2022 20:37:57 +0800 Subject: [PATCH 52/57] [query]: fix length/char_length data block pointer with proper offset TD-14572 --- source/libs/scalar/src/sclfunc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 8fa417306b..7ce7b422ac 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -357,7 +357,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu } for (int32_t i = 0; i < inputNum; ++i) { pInputData[i] = pInput[i].columnData; - input[i] = pInputData[i]->pData; + input[i] = pInputData[i]->pData + pInputData[i]->varmeta.offset[0]; int32_t factor = 1; if (hasNcharCol && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) { factor = TSDB_NCHAR_SIZE; @@ -438,7 +438,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p } for (int32_t i = 0; i < inputNum; ++i) { pInputData[i] = pInput[i].columnData; - input[i] = pInputData[i]->pData; + input[i] = pInputData[i]->pData + pInputData[i]->varmeta.offset[0]; int32_t factor = 1; if (hasNcharCol && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) { factor = TSDB_NCHAR_SIZE; @@ -509,7 +509,7 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - char *input = pInputData->pData; + char *input = pInputData->pData + pInputData->varmeta.offset[0]; char *output = NULL; int32_t outputLen = pInputData->varmeta.length; @@ -554,7 +554,7 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - char *input = pInputData->pData; + char *input = pInputData->pData + pInputData->varmeta.offset[0]; char *output = NULL; int32_t outputLen = pInputData->varmeta.length; @@ -606,7 +606,7 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu SColumnInfoData *pInputData = pInput->columnData; SColumnInfoData *pOutputData = pOutput->columnData; - char *input = pInputData->pData; + char *input = pInputData->pData + pInputData->varmeta.offset[0]; char *output = NULL; int32_t outputLen = pInputData->varmeta.length * pInput->numOfRows; From 951ee6136cb470f61033866bb3c148e2674d8b32 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 8 Apr 2022 20:30:36 +0800 Subject: [PATCH 53/57] feat[cluster]: send monitor information in multi-process mode --- source/dnode/mgmt/bm/bmHandle.c | 27 +++- source/dnode/mgmt/bm/bmWorker.c | 52 ++++++- source/dnode/mgmt/dm/dmHandle.c | 8 - source/dnode/mgmt/dm/dmMonitor.c | 246 +++++++----------------------- source/dnode/mgmt/dm/dmWorker.c | 18 --- source/dnode/mgmt/inc/bmInt.h | 4 + source/dnode/mgmt/inc/dmInt.h | 10 +- source/dnode/mgmt/inc/mmInt.h | 3 + source/dnode/mgmt/inc/qmInt.h | 3 + source/dnode/mgmt/inc/smInt.h | 3 + source/dnode/mgmt/inc/vmInt.h | 4 + source/dnode/mgmt/mm/mmHandle.c | 25 +++ source/dnode/mgmt/mm/mmWorker.c | 28 +++- source/dnode/mgmt/qm/qmHandle.c | 25 +++ source/dnode/mgmt/qm/qmWorker.c | 46 ++++++ source/dnode/mgmt/sm/smHandle.c | 25 +++ source/dnode/mgmt/sm/smWorker.c | 46 ++++++ source/dnode/mgmt/vm/vmHandle.c | 49 ++++++ source/dnode/mgmt/vm/vmWorker.c | 25 +++ source/libs/monitor/src/monMain.c | 3 + source/util/src/tconfig.c | 2 +- 21 files changed, 414 insertions(+), 238 deletions(-) diff --git a/source/dnode/mgmt/bm/bmHandle.c b/source/dnode/mgmt/bm/bmHandle.c index 4ab000cb4e..3021c2798f 100644 --- a/source/dnode/mgmt/bm/bmHandle.c +++ b/source/dnode/mgmt/bm/bmHandle.c @@ -23,6 +23,29 @@ void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo) { } } +int32_t bmProcessGetMonBmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { + SMonBmInfo bmInfo = {0}; + bmGetMonitorInfo(pWrapper, &bmInfo); + + int32_t rspLen = tSerializeSMonBmInfo(NULL, 0, &bmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonBmInfo(pRsp, rspLen, &bmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonBmInfo(&bmInfo); + return 0; +} + int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnode *pDnode = pWrapper->pDnode; SRpcMsg *pReq = &pMsg->rpcMsg; @@ -61,4 +84,6 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { } } -void bmInitMsgHandle(SMgmtWrapper *pWrapper) {} +void bmInitMsgHandle(SMgmtWrapper *pWrapper) { + dndSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE); +} diff --git a/source/dnode/mgmt/bm/bmWorker.c b/source/dnode/mgmt/bm/bmWorker.c index a5a97f6af0..a08d390d43 100644 --- a/source/dnode/mgmt/bm/bmWorker.c +++ b/source/dnode/mgmt/bm/bmWorker.c @@ -33,7 +33,34 @@ static void bmSendErrorRsps(SMgmtWrapper *pWrapper, STaosQall *qall, int32_t num } } -static void bmProcessQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { +static void bmProcessMonQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { + SBnodeMgmt *pMgmt = pInfo->ahandle; + + dTrace("msg:%p, get from bnode monitor queue", pMsg); + SRpcMsg *pRpc = &pMsg->rpcMsg; + int32_t code = -1; + + if (pMsg->rpcMsg.msgType == TDMT_MON_BM_INFO) { + code = bmProcessGetMonBmInfoReq(pMgmt->pWrapper, pMsg); + } + + if (pRpc->msgType & 1U) { + if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + if (code != 0) { + code = terrno; + dError("msg:%p, failed to process since %s", pMsg, terrstr()); + } + SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; + tmsgSendRsp(&rsp); + } + } + + dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); + rpcFreeCont(pRpc->pCont); + taosFreeQitem(pMsg); +} + +static void bmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SBnodeMgmt *pMgmt = pInfo->ahandle; SMgmtWrapper *pWrapper = pMgmt->pWrapper; @@ -72,18 +99,37 @@ int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } +int32_t bmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SBnodeMgmt *pMgmt = pWrapper->pMgmt; + SSingleWorker *pWorker = &pMgmt->monitorWorker; + + dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); + taosWriteQitem(pWorker->queue, pMsg); + return 0; +} + int32_t bmStartWorker(SBnodeMgmt *pMgmt) { - SMultiWorkerCfg cfg = {.max = 1, .name = "bnode-write", .fp = (FItems)bmProcessQueue, .param = pMgmt}; + SMultiWorkerCfg cfg = {.max = 1, .name = "bnode-write", .fp = (FItems)bmProcessWriteQueue, .param = pMgmt}; if (tMultiWorkerInit(&pMgmt->writeWorker, &cfg) != 0) { - dError("failed to start bnode write worker since %s", terrstr()); + dError("failed to start bnode-write worker since %s", terrstr()); return -1; } + if (tsMultiProcess) { + SSingleWorkerCfg sCfg = { + .min = 1, .max = 1, .name = "bnode-monitor", .fp = (FItem)bmProcessMonQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + dError("failed to start bnode-monitor worker since %s", terrstr()); + return -1; + } + } + dDebug("bnode workers are initialized"); return 0; } void bmStopWorker(SBnodeMgmt *pMgmt) { + tSingleWorkerCleanup(&pMgmt->monitorWorker); tMultiWorkerCleanup(&pMgmt->writeWorker); dDebug("bnode workers are closed"); } diff --git a/source/dnode/mgmt/dm/dmHandle.c b/source/dnode/mgmt/dm/dmHandle.c index c0175fed10..685958aaf0 100644 --- a/source/dnode/mgmt/dm/dmHandle.c +++ b/source/dnode/mgmt/dm/dmHandle.c @@ -212,12 +212,4 @@ void dmInitMsgHandle(SMgmtWrapper *pWrapper) { dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMonitorMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); - - // Monitor info exchange between processes - dndSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, dmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, dmProcessMonitorMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/dm/dmMonitor.c b/source/dnode/mgmt/dm/dmMonitor.c index b9199efac2..ff5225e580 100644 --- a/source/dnode/mgmt/dm/dmMonitor.c +++ b/source/dnode/mgmt/dm/dmMonitor.c @@ -59,74 +59,92 @@ void dmSendMonitorReport(SDnode *pDnode) { tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); epset.eps[0].port = tsServerPort; + SMgmtWrapper *pWrapper = NULL; dmGetMonitorInfo(pDnode, &dmInfo); - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, MNODE); - if (pWrapper != NULL) { - if (!tsMultiProcess) { + pWrapper = &pDnode->wrappers[MNODE]; + if (!tsMultiProcess) { + if (dndMarkWrapper(pWrapper) != 0) { mmGetMonitorInfo(pWrapper, &mmInfo); - } else { + dndReleaseWrapper(pWrapper); + } + } else { + if (pWrapper->required) { req.msgType = TDMT_MON_MM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo); + if (rsp.code == 0) { + tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo); + } rpcFreeCont(rsp.pCont); } - dndReleaseWrapper(pWrapper); } - pWrapper = dndAcquireWrapper(pDnode, VNODES); - if (pWrapper != NULL) { - if (!tsMultiProcess) { + pWrapper = &pDnode->wrappers[VNODES]; + if (!tsMultiProcess) { + if (dndMarkWrapper(pWrapper) != 0) { vmGetMonitorInfo(pWrapper, &vmInfo); - } else { + dndReleaseWrapper(pWrapper); + } + } else { + if (pWrapper->required) { req.msgType = TDMT_MON_VM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - dndReleaseWrapper(pWrapper); - tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo); + if (rsp.code == 0) { + tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo); + } rpcFreeCont(rsp.pCont); } } - pWrapper = dndAcquireWrapper(pDnode, QNODE); - if (pWrapper != NULL) { - if (!tsMultiProcess) { + pWrapper = &pDnode->wrappers[QNODE]; + if (!tsMultiProcess) { + if (dndMarkWrapper(pWrapper) != 0) { qmGetMonitorInfo(pWrapper, &qmInfo); - } else { + dndReleaseWrapper(pWrapper); + } + } else { + if (pWrapper->required) { req.msgType = TDMT_MON_QM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - dndReleaseWrapper(pWrapper); - tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo); + if (rsp.code == 0) { + tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo); + } rpcFreeCont(rsp.pCont); } - dndReleaseWrapper(pWrapper); } - pWrapper = dndAcquireWrapper(pDnode, SNODE); - if (pWrapper != NULL) { - if (!tsMultiProcess) { + pWrapper = &pDnode->wrappers[SNODE]; + if (!tsMultiProcess) { + if (dndMarkWrapper(pWrapper) != 0) { smGetMonitorInfo(pWrapper, &smInfo); - } else { + dndReleaseWrapper(pWrapper); + } + } else { + if (pWrapper->required) { req.msgType = TDMT_MON_SM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - dndReleaseWrapper(pWrapper); - tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo); + if (rsp.code == 0) { + tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo); + } rpcFreeCont(rsp.pCont); } - dndReleaseWrapper(pWrapper); } - pWrapper = dndAcquireWrapper(pDnode, BNODE); - if (pWrapper != NULL) { - if (!tsMultiProcess) { + pWrapper = &pDnode->wrappers[BNODE]; + if (!tsMultiProcess) { + if (dndMarkWrapper(pWrapper) != 0) { bmGetMonitorInfo(pWrapper, &bmInfo); - } else { + dndReleaseWrapper(pWrapper); + } + } else { + if (pWrapper->required) { req.msgType = TDMT_MON_BM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - dndReleaseWrapper(pWrapper); - tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo); + if (rsp.code == 0) { + tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo); + } rpcFreeCont(rsp.pCont); } - dndReleaseWrapper(pWrapper); } monSetDmInfo(&dmInfo); @@ -143,168 +161,6 @@ void dmSendMonitorReport(SDnode *pDnode) { monSendReport(); } -int32_t dmProcessGetMonMmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, MNODE); - if (pWrapper == NULL) return -1; - - SMonMmInfo mmInfo = {0}; - mmGetMonitorInfo(pWrapper, &mmInfo); - dndReleaseWrapper(pWrapper); - - int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo); - pReq->pRsp = pRsp; - pReq->rspLen = rspLen; - tFreeSMonMmInfo(&mmInfo); - return 0; -} - -int32_t dmProcessGetMonVmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, VNODES); - if (pWrapper == NULL) return -1; - - SMonVmInfo vmInfo = {0}; - vmGetMonitorInfo(pWrapper, &vmInfo); - dndReleaseWrapper(pWrapper); - - int32_t rspLen = tSerializeSMonVmInfo(NULL, 0, &vmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonVmInfo(pRsp, rspLen, &vmInfo); - pReq->pRsp = pRsp; - pReq->rspLen = rspLen; - tFreeSMonVmInfo(&vmInfo); - return 0; -} - -int32_t dmProcessGetMonQmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, QNODE); - if (pWrapper == NULL) return -1; - - SMonQmInfo qmInfo = {0}; - qmGetMonitorInfo(pWrapper, &qmInfo); - dndReleaseWrapper(pWrapper); - - int32_t rspLen = tSerializeSMonQmInfo(NULL, 0, &qmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonQmInfo(pRsp, rspLen, &qmInfo); - pReq->pRsp = pRsp; - pReq->rspLen = rspLen; - tFreeSMonQmInfo(&qmInfo); - return 0; -} - -int32_t dmProcessGetMonSmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, SNODE); - if (pWrapper == NULL) return -1; - - SMonSmInfo smInfo = {0}; - smGetMonitorInfo(pWrapper, &smInfo); - dndReleaseWrapper(pWrapper); - - int32_t rspLen = tSerializeSMonSmInfo(NULL, 0, &smInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonSmInfo(pRsp, rspLen, &smInfo); - pReq->pRsp = pRsp; - pReq->rspLen = rspLen; - tFreeSMonSmInfo(&smInfo); - return 0; -} - -int32_t dmProcessGetMonBmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, BNODE); - if (pWrapper == NULL) return -1; - - SMonBmInfo bmInfo = {0}; - bmGetMonitorInfo(pWrapper, &bmInfo); - dndReleaseWrapper(pWrapper); - - int32_t rspLen = tSerializeSMonBmInfo(NULL, 0, &bmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonBmInfo(pRsp, rspLen, &bmInfo); - pReq->pRsp = pRsp; - pReq->rspLen = rspLen; - tFreeSMonBmInfo(&bmInfo); - return 0; -} - -int32_t dmProcessGetVnodeLoadsReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pMgmt->pDnode, VNODES); - if (pWrapper == NULL) return -1; - - SMonVloadInfo vloads = {0}; - vmGetVnodeLoads(pWrapper, &vloads); - dndReleaseWrapper(pWrapper); - - int32_t rspLen = tSerializeSMonVloadInfo(NULL, 0, &vloads); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonVloadInfo(pRsp, rspLen, &vloads); - pReq->pRsp = pRsp; - pReq->rspLen = rspLen; - tFreeSMonVloadInfo(&vloads); - return 0; -} - void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { if (!tsMultiProcess) { vmGetVnodeLoads(pWrapper, pInfo); diff --git a/source/dnode/mgmt/dm/dmWorker.c b/source/dnode/mgmt/dm/dmWorker.c index a6d0f4491a..41b38c8bb7 100644 --- a/source/dnode/mgmt/dm/dmWorker.c +++ b/source/dnode/mgmt/dm/dmWorker.c @@ -78,24 +78,6 @@ static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { case TDMT_MND_GRANT_RSP: code = dmProcessGrantRsp(pMgmt, pMsg); break; - case TDMT_MON_MM_INFO: - code = dmProcessGetMonMmInfoReq(pMgmt, pMsg); - break; - case TDMT_MON_VM_INFO: - code = dmProcessGetMonVmInfoReq(pMgmt, pMsg); - break; - case TDMT_MON_QM_INFO: - code = dmProcessGetMonQmInfoReq(pMgmt, pMsg); - break; - case TDMT_MON_SM_INFO: - code = dmProcessGetMonSmInfoReq(pMgmt, pMsg); - break; - case TDMT_MON_BM_INFO: - code = dmProcessGetMonBmInfoReq(pMgmt, pMsg); - break; - case TDMT_MON_VM_LOAD: - code = dmProcessGetVnodeLoadsReq(pMgmt, pMsg); - break; default: code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg); break; diff --git a/source/dnode/mgmt/inc/bmInt.h b/source/dnode/mgmt/inc/bmInt.h index 919b1d2c7c..84a6a53e99 100644 --- a/source/dnode/mgmt/inc/bmInt.h +++ b/source/dnode/mgmt/inc/bmInt.h @@ -17,6 +17,7 @@ #define _TD_DND_BNODE_INT_H_ #include "dndInt.h" + #include "bnode.h" #ifdef __cplusplus @@ -29,6 +30,7 @@ typedef struct SBnodeMgmt { SMgmtWrapper *pWrapper; const char *path; SMultiWorker writeWorker; + SSingleWorker monitorWorker; } SBnodeMgmt; // bmInt.c @@ -39,11 +41,13 @@ int32_t bmDrop(SMgmtWrapper *pWrapper); void bmInitMsgHandle(SMgmtWrapper *pWrapper); int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t bmProcessGetMonBmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); // bmWorker.c int32_t bmStartWorker(SBnodeMgmt *pMgmt); void bmStopWorker(SBnodeMgmt *pMgmt); int32_t bmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t bmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/inc/dmInt.h index 6d37f59595..a671368f06 100644 --- a/source/dnode/mgmt/inc/dmInt.h +++ b/source/dnode/mgmt/inc/dmInt.h @@ -54,14 +54,8 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); // dmMonitor.c -int32_t dmProcessGetVnodeLoadsReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); -int32_t dmProcessGetMonMmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); -int32_t dmProcessGetMonVmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); -int32_t dmProcessGetMonQmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); -int32_t dmProcessGetMonSmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); -int32_t dmProcessGetMonBmInfoReq(SDnodeMgmt *pMgmt, SNodeMsg *pReq); -void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); -void dmSendMonitorReport(SDnode *pDnode); +void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void dmSendMonitorReport(SDnode *pDnode); // dmWorker.c int32_t dmStartThread(SDnodeMgmt *pMgmt); diff --git a/source/dnode/mgmt/inc/mmInt.h b/source/dnode/mgmt/inc/mmInt.h index d09d15255d..df63e22059 100644 --- a/source/dnode/mgmt/inc/mmInt.h +++ b/source/dnode/mgmt/inc/mmInt.h @@ -32,6 +32,7 @@ typedef struct SMnodeMgmt { SSingleWorker readWorker; SSingleWorker writeWorker; SSingleWorker syncWorker; + SSingleWorker monitorWorker; SReplica replicas[TSDB_MAX_REPLICA]; int8_t replica; int8_t selfIndex; @@ -51,6 +52,7 @@ void mmInitMsgHandle(SMgmtWrapper *pWrapper); int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg); +int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); // mmWorker.c int32_t mmStartWorker(SMnodeMgmt *pMgmt); @@ -59,6 +61,7 @@ int32_t mmProcessWriteMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t mmProcessSyncMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t mmProcessReadMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t mmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t mmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t mmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); diff --git a/source/dnode/mgmt/inc/qmInt.h b/source/dnode/mgmt/inc/qmInt.h index 02905413ab..012869d637 100644 --- a/source/dnode/mgmt/inc/qmInt.h +++ b/source/dnode/mgmt/inc/qmInt.h @@ -30,6 +30,7 @@ typedef struct SQnodeMgmt { const char *path; SSingleWorker queryWorker; SSingleWorker fetchWorker; + SSingleWorker monitorWorker; } SQnodeMgmt; // qmInt.c @@ -40,6 +41,7 @@ int32_t qmDrop(SMgmtWrapper *pWrapper); void qmInitMsgHandle(SMgmtWrapper *pWrapper); int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t qmProcessGetMonQmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); // qmWorker.c int32_t qmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); @@ -50,6 +52,7 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt); void qmStopWorker(SQnodeMgmt *pMgmt); int32_t qmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t qmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t qmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/inc/smInt.h b/source/dnode/mgmt/inc/smInt.h index 285ec84942..039dea2491 100644 --- a/source/dnode/mgmt/inc/smInt.h +++ b/source/dnode/mgmt/inc/smInt.h @@ -32,6 +32,7 @@ typedef struct SSnodeMgmt { int8_t uniqueWorkerInUse; SArray *uniqueWorkers; // SArray SSingleWorker sharedWorker; + SSingleWorker monitorWorker; } SSnodeMgmt; // smInt.c @@ -42,6 +43,7 @@ int32_t smDrop(SMgmtWrapper *pWrapper); void smInitMsgHandle(SMgmtWrapper *pWrapper); int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t smProcessGetMonSmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); // smWorker.c int32_t smStartWorker(SSnodeMgmt *pMgmt); @@ -50,6 +52,7 @@ int32_t smProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t smProcessUniqueMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t smProcessSharedMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t smProcessExecMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t smProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/inc/vmInt.h b/source/dnode/mgmt/inc/vmInt.h index ca210d62c6..f8466fe4f2 100644 --- a/source/dnode/mgmt/inc/vmInt.h +++ b/source/dnode/mgmt/inc/vmInt.h @@ -39,6 +39,7 @@ typedef struct SVnodesMgmt { SDnode *pDnode; SMgmtWrapper *pWrapper; SSingleWorker mgmtWorker; + SSingleWorker monitorWorker; } SVnodesMgmt; typedef struct { @@ -92,6 +93,8 @@ int32_t vmProcessAlterVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq); int32_t vmProcessDropVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq); int32_t vmProcessSyncVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq); int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq); +int32_t vmProcessGetMonVmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); +int32_t vmProcessGetVnodeLoadsReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); // vmFile.c int32_t vmGetVnodesFromFile(SVnodesMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes); @@ -115,6 +118,7 @@ int32_t vmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t vmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t vmProcessMergeMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); int32_t vmProcessMgmtMsg(SMgmtWrapper *pWrappert, SNodeMsg *pMsg); +int32_t vmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c index 1ebcfdcda9..b5aff12992 100644 --- a/source/dnode/mgmt/mm/mmHandle.c +++ b/source/dnode/mgmt/mm/mmHandle.c @@ -25,6 +25,29 @@ void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { } } +int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { + SMonMmInfo mmInfo = {0}; + mmGetMonitorInfo(pWrapper, &mmInfo); + + int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonMmInfo(&mmInfo); + return 0; +} + int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnode *pDnode = pWrapper->pDnode; SRpcMsg *pReq = &pMsg->rpcMsg; @@ -83,6 +106,8 @@ int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { } void mmInitMsgHandle(SMgmtWrapper *pWrapper) { + dndSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE); + // Requests handled by DNODE dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); diff --git a/source/dnode/mgmt/mm/mmWorker.c b/source/dnode/mgmt/mm/mmWorker.c index 735ef53b37..85aa265904 100644 --- a/source/dnode/mgmt/mm/mmWorker.c +++ b/source/dnode/mgmt/mm/mmWorker.c @@ -23,11 +23,13 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SRpcMsg *pRpc = &pMsg->rpcMsg; int32_t code = -1; - if (pMsg->rpcMsg.msgType != TDMT_DND_ALTER_MNODE) { + if (pMsg->rpcMsg.msgType == TDMT_DND_ALTER_MNODE) { + code = mmProcessAlterReq(pMgmt, pMsg); + } else if (pMsg->rpcMsg.msgType == TDMT_MON_MM_INFO) { + code = mmProcessGetMonMmInfoReq(pMgmt->pWrapper, pMsg); + } else { pMsg->pNode = pMgmt->pMnode; code = mndProcessMsg(pMsg); - } else { - code = mmProcessAlterReq(pMgmt, pMsg); } if (pRpc->msgType & 1U) { @@ -98,6 +100,15 @@ int32_t mmProcessQueryMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } +int32_t mmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + SSingleWorker *pWorker = &pMgmt->monitorWorker; + + dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); + taosWriteQitem(pWorker->queue, pMsg); + return 0; +} + static int32_t mmPutRpcMsgToWorker(SSingleWorker *pWorker, SRpcMsg *pRpc) { SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg)); if (pMsg == NULL) return -1; @@ -157,15 +168,24 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) { SSingleWorkerCfg sCfg = {.min = 1, .max = 1, .name = "mnode-sync", .fp = (FItem)mmProcessQueue, .param = pMgmt}; if (tSingleWorkerInit(&pMgmt->syncWorker, &sCfg) != 0) { - dError("failed to start mnode sync-worker since %s", terrstr()); + dError("failed to start mnode mnode-sync worker since %s", terrstr()); return -1; } + if (tsMultiProcess) { + SSingleWorkerCfg sCfg = {.min = 1, .max = 1, .name = "mnode-monitor", .fp = (FItem)mmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + dError("failed to start mnode mnode-monitor worker since %s", terrstr()); + return -1; + } + } + dDebug("mnode workers are initialized"); return 0; } void mmStopWorker(SMnodeMgmt *pMgmt) { + tSingleWorkerCleanup(&pMgmt->monitorWorker); tSingleWorkerCleanup(&pMgmt->queryWorker); tSingleWorkerCleanup(&pMgmt->readWorker); tSingleWorkerCleanup(&pMgmt->writeWorker); diff --git a/source/dnode/mgmt/qm/qmHandle.c b/source/dnode/mgmt/qm/qmHandle.c index 3c29bd717b..c96b396691 100644 --- a/source/dnode/mgmt/qm/qmHandle.c +++ b/source/dnode/mgmt/qm/qmHandle.c @@ -23,6 +23,29 @@ void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo) { } } +int32_t qmProcessGetMonQmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { + SMonQmInfo qmInfo = {0}; + qmGetMonitorInfo(pWrapper, &qmInfo); + + int32_t rspLen = tSerializeSMonQmInfo(NULL, 0, &qmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonQmInfo(pRsp, rspLen, &qmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonQmInfo(&qmInfo); + return 0; +} + int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnode *pDnode = pWrapper->pDnode; SRpcMsg *pReq = &pMsg->rpcMsg; @@ -62,6 +85,8 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { } void qmInitMsgHandle(SMgmtWrapper *pWrapper) { + dndSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE); + // Requests handled by VNODE dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE); dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE); diff --git a/source/dnode/mgmt/qm/qmWorker.c b/source/dnode/mgmt/qm/qmWorker.c index db0752949d..e9d1173f20 100644 --- a/source/dnode/mgmt/qm/qmWorker.c +++ b/source/dnode/mgmt/qm/qmWorker.c @@ -21,6 +21,33 @@ static void qmSendRsp(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t code) { tmsgSendRsp(&rsp); } +static void qmProcessMonQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { + SQnodeMgmt *pMgmt = pInfo->ahandle; + + dTrace("msg:%p, get from qnode monitor queue", pMsg); + SRpcMsg *pRpc = &pMsg->rpcMsg; + int32_t code = -1; + + if (pMsg->rpcMsg.msgType == TDMT_MON_SM_INFO) { + code = qmProcessGetMonQmInfoReq(pMgmt->pWrapper, pMsg); + } + + if (pRpc->msgType & 1U) { + if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + if (code != 0) { + code = terrno; + dError("msg:%p, failed to process since %s", pMsg, terrstr()); + } + SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; + tmsgSendRsp(&rsp); + } + } + + dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); + rpcFreeCont(pRpc->pCont); + taosFreeQitem(pMsg); +} + static void qmProcessQueryQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SQnodeMgmt *pMgmt = pInfo->ahandle; @@ -66,6 +93,15 @@ int32_t qmProcessFetchMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } +int32_t qmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SQnodeMgmt *pMgmt = pWrapper->pMgmt; + SSingleWorker *pWorker = &pMgmt->monitorWorker; + + dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); + taosWriteQitem(pWorker->queue, pMsg); + return 0; +} + static int32_t qmPutRpcMsgToWorker(SQnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) { SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg)); if (pMsg == NULL) { @@ -128,11 +164,21 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) { return -1; } + if (tsMultiProcess) { + SSingleWorkerCfg sCfg = { + .min = 1, .max = 1, .name = "qnode-monitor", .fp = (FItem)qmProcessMonQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + dError("failed to start qnode-monitor worker since %s", terrstr()); + return -1; + } + } + dDebug("qnode workers are initialized"); return 0; } void qmStopWorker(SQnodeMgmt *pMgmt) { + tSingleWorkerCleanup(&pMgmt->monitorWorker); tSingleWorkerCleanup(&pMgmt->queryWorker); tSingleWorkerCleanup(&pMgmt->fetchWorker); dDebug("qnode workers are closed"); diff --git a/source/dnode/mgmt/sm/smHandle.c b/source/dnode/mgmt/sm/smHandle.c index 214dc581b8..5500db4513 100644 --- a/source/dnode/mgmt/sm/smHandle.c +++ b/source/dnode/mgmt/sm/smHandle.c @@ -23,6 +23,29 @@ void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo) { } } +int32_t smProcessGetMonSmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { + SMonSmInfo smInfo = {0}; + smGetMonitorInfo(pWrapper, &smInfo); + + int32_t rspLen = tSerializeSMonSmInfo(NULL, 0, &smInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonSmInfo(pRsp, rspLen, &smInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonSmInfo(&smInfo); + return 0; +} + int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SDnode *pDnode = pWrapper->pDnode; SRpcMsg *pReq = &pMsg->rpcMsg; @@ -62,6 +85,8 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { } void smInitMsgHandle(SMgmtWrapper *pWrapper) { + dndSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, smProcessMonitorMsg, DEFAULT_HANDLE); + // Requests handled by SNODE dndSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, DEFAULT_HANDLE); diff --git a/source/dnode/mgmt/sm/smWorker.c b/source/dnode/mgmt/sm/smWorker.c index afa843953b..33ae289733 100644 --- a/source/dnode/mgmt/sm/smWorker.c +++ b/source/dnode/mgmt/sm/smWorker.c @@ -16,6 +16,33 @@ #define _DEFAULT_SOURCE #include "smInt.h" +static void smProcessMonitorQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { + SSnodeMgmt *pMgmt = pInfo->ahandle; + + dTrace("msg:%p, get from snode monitor queue", pMsg); + SRpcMsg *pRpc = &pMsg->rpcMsg; + int32_t code = -1; + + if (pMsg->rpcMsg.msgType == TDMT_MON_SM_INFO) { + code = smProcessGetMonSmInfoReq(pMgmt->pWrapper, pMsg); + } + + if (pRpc->msgType & 1U) { + if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { + if (code != 0) { + code = terrno; + dError("msg:%p, failed to process since %s", pMsg, terrstr()); + } + SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; + tmsgSendRsp(&rsp); + } + } + + dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); + rpcFreeCont(pRpc->pCont); + taosFreeQitem(pMsg); +} + static void smProcessUniqueQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SSnodeMgmt *pMgmt = pInfo->ahandle; @@ -80,11 +107,21 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { return -1; } + if (tsMultiProcess) { + SSingleWorkerCfg sCfg = { + .min = 1, .max = 1, .name = "snode-monitor", .fp = (FItem)smProcessMonitorQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + dError("failed to start snode-monitor worker since %s", terrstr()); + return -1; + } + } + dDebug("snode workers are initialized"); return 0; } void smStopWorker(SSnodeMgmt *pMgmt) { + tSingleWorkerCleanup(&pMgmt->monitorWorker); for (int32_t i = 0; i < taosArrayGetSize(pMgmt->uniqueWorkers); i++) { SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, i); tMultiWorkerCleanup(pWorker); @@ -120,6 +157,15 @@ int32_t smProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } +int32_t smProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SSnodeMgmt *pMgmt = pWrapper->pMgmt; + SSingleWorker *pWorker = &pMgmt->monitorWorker; + + dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); + taosWriteQitem(pWorker->queue, pMsg); + return 0; +} + int32_t smProcessUniqueMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { SSnodeMgmt *pMgmt = pWrapper->pMgmt; int32_t index = smGetSWIdFromMsg(&pMsg->rpcMsg); diff --git a/source/dnode/mgmt/vm/vmHandle.c b/source/dnode/mgmt/vm/vmHandle.c index 0433846ca1..f003d8c58a 100644 --- a/source/dnode/mgmt/vm/vmHandle.c +++ b/source/dnode/mgmt/vm/vmHandle.c @@ -38,6 +38,52 @@ void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo) { } } +int32_t vmProcessGetMonVmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { + SMonVmInfo vmInfo = {0}; + vmGetMonitorInfo(pWrapper, &vmInfo); + + int32_t rspLen = tSerializeSMonVmInfo(NULL, 0, &vmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonVmInfo(pRsp, rspLen, &vmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonVmInfo(&vmInfo); + return 0; +} + +int32_t vmProcessGetVnodeLoadsReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { + SMonVloadInfo vloads = {0}; + vmGetVnodeLoads(pWrapper, &vloads); + + int32_t rspLen = tSerializeSMonVloadInfo(NULL, 0, &vloads); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonVloadInfo(pRsp, rspLen, &vloads); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonVloadInfo(&vloads); + return 0; +} + static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pCfg->vgId = pCreate->vgId; pCfg->wsize = pCreate->cacheBlockSize; @@ -261,6 +307,9 @@ int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { } void vmInitMsgHandle(SMgmtWrapper *pWrapper) { + dndSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, vmProcessMonitorMsg, DEFAULT_HANDLE); + dndSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, vmProcessMonitorMsg, DEFAULT_HANDLE); + // Requests handled by VNODE dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); diff --git a/source/dnode/mgmt/vm/vmWorker.c b/source/dnode/mgmt/vm/vmWorker.c index ed1a4ca2f4..82c45f172d 100644 --- a/source/dnode/mgmt/vm/vmWorker.c +++ b/source/dnode/mgmt/vm/vmWorker.c @@ -29,6 +29,12 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { dTrace("msg:%p, will be processed in vnode-mgmt queue", pMsg); switch (msgType) { + case TDMT_MON_VM_INFO: + code = vmProcessGetMonVmInfoReq(pMgmt->pWrapper, pMsg); + break; + case TDMT_MON_VM_LOAD: + code = vmProcessGetVnodeLoadsReq(pMgmt->pWrapper, pMsg); + break; case TDMT_DND_CREATE_VNODE: code = vmProcessCreateVnodeReq(pMgmt, pMsg); break; @@ -255,6 +261,15 @@ int32_t vmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return 0; } +int32_t vmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SVnodesMgmt *pMgmt = pWrapper->pMgmt; + SSingleWorker *pWorker = &pMgmt->monitorWorker; + + dTrace("msg:%p, put into worker:%s", pMsg, pWorker->name); + taosWriteQitem(pWorker->queue, pMsg); + return 0; +} + static int32_t vmPutRpcMsgToQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, EQueueType qtype) { SVnodesMgmt *pMgmt = pWrapper->pMgmt; SMsgHead *pHead = pRpc->pCont; @@ -412,11 +427,21 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) { return -1; } + if (tsMultiProcess) { + SSingleWorkerCfg sCfg = { + .min = 1, .max = 1, .name = "vnode-monitor", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + dError("failed to start mnode vnode-monitor worker since %s", terrstr()); + return -1; + } + } + dDebug("vnode workers are initialized"); return 0; } void vmStopWorker(SVnodesMgmt *pMgmt) { + tSingleWorkerCleanup(&pMgmt->monitorWorker); tSingleWorkerCleanup(&pMgmt->mgmtWorker); tQWorkerCleanup(&pMgmt->fetchPool); tQWorkerCleanup(&pMgmt->queryPool); diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index c012911e8b..af7799cd7c 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -187,6 +187,7 @@ static void monGenBasicJson(SMonInfo *pMonitor) { static void monGenClusterJson(SMonInfo *pMonitor) { SMonClusterInfo *pInfo = &pMonitor->mmInfo.cluster; + if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return; SJson *pJson = tjsonCreateObject(); if (pJson == NULL) return; @@ -239,6 +240,7 @@ static void monGenClusterJson(SMonInfo *pMonitor) { static void monGenVgroupJson(SMonInfo *pMonitor) { SMonVgroupInfo *pInfo = &pMonitor->mmInfo.vgroup; + if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return; SJson *pJson = tjsonAddArrayToObject(pMonitor->pJson, "vgroup_infos"); if (pJson == NULL) return; @@ -277,6 +279,7 @@ static void monGenVgroupJson(SMonInfo *pMonitor) { static void monGenGrantJson(SMonInfo *pMonitor) { SMonGrantInfo *pInfo = &pMonitor->mmInfo.grant; + if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return; SJson *pJson = tjsonCreateObject(); if (pJson == NULL) return; diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index e7e870e998..74d7c15e78 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -348,7 +348,7 @@ SConfigItem *cfgGetItem(SConfig *pCfg, const char *name) { } } - uError("name:%s, cfg not found", name); + // uError("name:%s, cfg not found", name); terrno = TSDB_CODE_CFG_NOT_FOUND; return NULL; } From a722d3df4bec1b1025df595dc5935ecb19f949a1 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 9 Apr 2022 09:51:56 +0800 Subject: [PATCH 54/57] feat[cluster]: send monitor information in multi-process mode --- source/libs/monitor/src/monMsg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c index 78a99b1066..94645f9da1 100644 --- a/source/libs/monitor/src/monMsg.c +++ b/source/libs/monitor/src/monMsg.c @@ -81,7 +81,7 @@ static int32_t tDecodeSMonLogs(SCoder *decoder, SMonLogs *pInfo) { if (tDecodeI32(decoder, &arraySize) < 0) return -1; pInfo->logs = taosArrayInit(arraySize, sizeof(SMonLogItem)); - if (pInfo->logs != NULL) return -1; + if (pInfo->logs == NULL) return -1; for (int32_t i = 0; i < arraySize; ++i) { SMonLogItem desc = {0}; @@ -143,7 +143,7 @@ int32_t tDecodeSMonClusterInfo(SCoder *decoder, SMonClusterInfo *pInfo) { pInfo->dnodes = taosArrayInit(dnodesSize, sizeof(SMonDnodeDesc)); pInfo->mnodes = taosArrayInit(mnodesSize, sizeof(SMonMnodeDesc)); - if (pInfo->dnodes != NULL || pInfo->mnodes != NULL) return -1; + if (pInfo->dnodes == NULL || pInfo->mnodes == NULL) return -1; for (int32_t i = 0; i < dnodesSize; ++i) { SMonDnodeDesc desc = {0}; @@ -185,7 +185,7 @@ int32_t tDecodeSMonVgroupInfo(SCoder *decoder, SMonVgroupInfo *pInfo) { if (tDecodeI32(decoder, &arraySize) < 0) return -1; pInfo->vgroups = taosArrayInit(arraySize, sizeof(SMonVgroupDesc)); - if (pInfo->vgroups != NULL) return -1; + if (pInfo->vgroups == NULL) return -1; for (int32_t i = 0; i < arraySize; ++i) { SMonVgroupDesc desc = {0}; @@ -292,7 +292,7 @@ static int32_t tDecodeSMonDiskInfo(SCoder *decoder, SMonDiskInfo *pInfo) { if (tDecodeI32(decoder, &arraySize) < 0) return -1; pInfo->datadirs = taosArrayInit(arraySize, sizeof(SMonDiskDesc)); - if (pInfo->datadirs != NULL) return -1; + if (pInfo->datadirs == NULL) return -1; for (int32_t i = 0; i < arraySize; ++i) { SMonDiskDesc desc = {0}; @@ -501,7 +501,7 @@ int32_t tDeserializeSMonVloadInfo(void *buf, int32_t bufLen, SMonVloadInfo *pInf if (tDecodeI32(&decoder, &arraySize) < 0) return -1; pInfo->pVloads = taosArrayInit(arraySize, sizeof(SVnodeLoad)); - if (pInfo->pVloads != NULL) return -1; + if (pInfo->pVloads == NULL) return -1; for (int32_t i = 0; i < arraySize; ++i) { SVnodeLoad load = {0}; From 8641cfe22b6a30569e6f76b0e061d309ad0d7e30 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Sat, 9 Apr 2022 10:29:07 +0800 Subject: [PATCH 55/57] change test --- source/client/src/tmq.c | 4 ++-- source/dnode/vnode/src/tq/tq.c | 6 +++--- tests/test/c/tmqSim.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 5893a14bd5..955e25fd71 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -1044,7 +1044,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1); if (epStatus == 1) { int32_t epSkipCnt = atomic_add_fetch_32(&tmq->epSkipCnt, 1); - tscDebug("consumer %ld skip ask ep cnt %d", tmq->consumerId, epSkipCnt); + tscTrace("consumer %ld skip ask ep cnt %d", tmq->consumerId, epSkipCnt); if (epSkipCnt < 5000) return 0; } atomic_store_32(&tmq->epSkipCnt, 0); @@ -1235,7 +1235,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { int32_t vgStatus = atomic_val_compare_exchange_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE, TMQ_VG_STATUS__WAIT); if (vgStatus != TMQ_VG_STATUS__IDLE) { int32_t vgSkipCnt = atomic_add_fetch_32(&pVg->vgSkipCnt, 1); - tscDebug("consumer %ld epoch %d skip vg %d skip cnt %d", tmq->consumerId, tmq->epoch, pVg->vgId, vgSkipCnt); + tscTrace("consumer %ld epoch %d skip vg %d skip cnt %d", tmq->consumerId, tmq->epoch, pVg->vgId, vgSkipCnt); continue; /*if (vgSkipCnt < 10000) continue;*/ #if 0 diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index f168695383..beefbc3d84 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -316,7 +316,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { return 0; } - vDebug("poll topic %s from consumer %ld (epoch %d) %s", pTopic->topicName, consumerId, pReq->epoch, pTopic->topicName); + vDebug("poll topic %s from consumer %ld (epoch %d) vg %d", pTopic->topicName, consumerId, pReq->epoch, pTq->pVnode->vgId); rsp.reqOffset = pReq->currentOffset; rsp.skipLogNum = 0; @@ -325,8 +325,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/ // TODO consumerEpoch = atomic_load_32(&pConsumer->epoch); - if (consumerEpoch > pReq->epoch) { - // TODO: return + if (consumerEpoch > reqEpoch) { + vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d discard req epoch %d", consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset, consumerEpoch, reqEpoch); break; } SWalReadHead* pHead; diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 7372745cb8..236d1e2eed 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -226,7 +226,7 @@ void loop_consume(tmq_t* tmq) { int32_t totalRows = 0; int32_t skipLogNum = 0; while (running) { - tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 4000); + tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 8000); if (tmqMsg) { totalMsgs++; From 388ab2f50dcaceff343035f79f0b2be2f15ea6f1 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 9 Apr 2022 10:31:15 +0800 Subject: [PATCH 56/57] :fix compile error --- source/libs/executor/inc/executorimpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index ba49db2c6f..6a1ded6441 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -681,7 +681,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); -SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SLimit* pLimit, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SLimit* pLimit, SLimit* pSlimit, SExecTaskInfo* pTaskInfo); SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SArray* pIndexMap, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pSortInfo, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo); From ffaef98b7543b289491ba0d5d1ab9e958b9779a5 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 9 Apr 2022 10:39:47 +0800 Subject: [PATCH 57/57] feat[cluster]: send monitor information in multi-process mode --- source/dnode/mgmt/bm/bmHandle.c | 6 ++---- source/dnode/mgmt/bm/bmWorker.c | 25 ++++++++++++++----------- source/dnode/mgmt/dm/dmMonitor.c | 26 ++++++++++++++------------ source/dnode/mgmt/mm/mmHandle.c | 6 ++---- source/dnode/mgmt/mm/mmWorker.c | 9 +++------ source/dnode/mgmt/qm/qmHandle.c | 6 ++---- source/dnode/mgmt/qm/qmWorker.c | 22 ++++++++++------------ source/dnode/mgmt/sm/smHandle.c | 11 ++++------- source/dnode/mgmt/sm/smWorker.c | 23 +++++++++++++---------- source/dnode/mgmt/vm/vmHandle.c | 7 ++----- source/dnode/mgmt/vm/vmWorker.c | 14 +++++++++----- source/dnode/mnode/impl/src/mndDnode.c | 2 +- source/dnode/mnode/impl/src/mnode.c | 6 +++++- source/libs/monitor/src/monMain.c | 4 +++- source/libs/transport/src/thttp.c | 2 +- 15 files changed, 85 insertions(+), 84 deletions(-) diff --git a/source/dnode/mgmt/bm/bmHandle.c b/source/dnode/mgmt/bm/bmHandle.c index 3021c2798f..b73acd14c3 100644 --- a/source/dnode/mgmt/bm/bmHandle.c +++ b/source/dnode/mgmt/bm/bmHandle.c @@ -17,15 +17,13 @@ #include "bmInt.h" void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo) { - if (pWrapper->procType == PROC_CHILD) { - dmGetMonitorSysInfo(&bmInfo->sys); - monGetLogs(&bmInfo->log); - } } int32_t bmProcessGetMonBmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonBmInfo bmInfo = {0}; bmGetMonitorInfo(pWrapper, &bmInfo); + dmGetMonitorSysInfo(&bmInfo.sys); + monGetLogs(&bmInfo.log); int32_t rspLen = tSerializeSMonBmInfo(NULL, 0, &bmInfo); if (rspLen < 0) { diff --git a/source/dnode/mgmt/bm/bmWorker.c b/source/dnode/mgmt/bm/bmWorker.c index a08d390d43..cf2d7ac939 100644 --- a/source/dnode/mgmt/bm/bmWorker.c +++ b/source/dnode/mgmt/bm/bmWorker.c @@ -33,6 +33,15 @@ static void bmSendErrorRsps(SMgmtWrapper *pWrapper, STaosQall *qall, int32_t num } } +static inline void bmSendRsp(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t code) { + SRpcMsg rsp = {.handle = pMsg->rpcMsg.handle, + .ahandle = pMsg->rpcMsg.ahandle, + .code = code, + .pCont = pMsg->pRsp, + .contLen = pMsg->rspLen}; + tmsgSendRsp(&rsp); +} + static void bmProcessMonQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SBnodeMgmt *pMgmt = pInfo->ahandle; @@ -45,14 +54,8 @@ static void bmProcessMonQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { } if (pRpc->msgType & 1U) { - if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - if (code != 0) { - code = terrno; - dError("msg:%p, failed to process since %s", pMsg, terrstr()); - } - SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; - tmsgSendRsp(&rsp); - } + if (code != 0 && terrno != 0) code = terrno; + bmSendRsp(pMgmt->pWrapper, pMsg, code); } dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); @@ -116,13 +119,13 @@ int32_t bmStartWorker(SBnodeMgmt *pMgmt) { } if (tsMultiProcess) { - SSingleWorkerCfg sCfg = { + SSingleWorkerCfg mCfg = { .min = 1, .max = 1, .name = "bnode-monitor", .fp = (FItem)bmProcessMonQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { dError("failed to start bnode-monitor worker since %s", terrstr()); return -1; } - } + } dDebug("bnode workers are initialized"); return 0; diff --git a/source/dnode/mgmt/dm/dmMonitor.c b/source/dnode/mgmt/dm/dmMonitor.c index ff5225e580..fb5855070c 100644 --- a/source/dnode/mgmt/dm/dmMonitor.c +++ b/source/dnode/mgmt/dm/dmMonitor.c @@ -62,8 +62,9 @@ void dmSendMonitorReport(SDnode *pDnode) { SMgmtWrapper *pWrapper = NULL; dmGetMonitorInfo(pDnode, &dmInfo); + bool getFromAPI = !tsMultiProcess; pWrapper = &pDnode->wrappers[MNODE]; - if (!tsMultiProcess) { + if (getFromAPI) { if (dndMarkWrapper(pWrapper) != 0) { mmGetMonitorInfo(pWrapper, &mmInfo); dndReleaseWrapper(pWrapper); @@ -72,7 +73,7 @@ void dmSendMonitorReport(SDnode *pDnode) { if (pWrapper->required) { req.msgType = TDMT_MON_MM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - if (rsp.code == 0) { + if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo); } rpcFreeCont(rsp.pCont); @@ -80,7 +81,7 @@ void dmSendMonitorReport(SDnode *pDnode) { } pWrapper = &pDnode->wrappers[VNODES]; - if (!tsMultiProcess) { + if (getFromAPI) { if (dndMarkWrapper(pWrapper) != 0) { vmGetMonitorInfo(pWrapper, &vmInfo); dndReleaseWrapper(pWrapper); @@ -89,7 +90,7 @@ void dmSendMonitorReport(SDnode *pDnode) { if (pWrapper->required) { req.msgType = TDMT_MON_VM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - if (rsp.code == 0) { + if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo); } rpcFreeCont(rsp.pCont); @@ -97,7 +98,7 @@ void dmSendMonitorReport(SDnode *pDnode) { } pWrapper = &pDnode->wrappers[QNODE]; - if (!tsMultiProcess) { + if (getFromAPI) { if (dndMarkWrapper(pWrapper) != 0) { qmGetMonitorInfo(pWrapper, &qmInfo); dndReleaseWrapper(pWrapper); @@ -106,7 +107,7 @@ void dmSendMonitorReport(SDnode *pDnode) { if (pWrapper->required) { req.msgType = TDMT_MON_QM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - if (rsp.code == 0) { + if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo); } rpcFreeCont(rsp.pCont); @@ -114,7 +115,7 @@ void dmSendMonitorReport(SDnode *pDnode) { } pWrapper = &pDnode->wrappers[SNODE]; - if (!tsMultiProcess) { + if (getFromAPI) { if (dndMarkWrapper(pWrapper) != 0) { smGetMonitorInfo(pWrapper, &smInfo); dndReleaseWrapper(pWrapper); @@ -123,7 +124,7 @@ void dmSendMonitorReport(SDnode *pDnode) { if (pWrapper->required) { req.msgType = TDMT_MON_SM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - if (rsp.code == 0) { + if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo); } rpcFreeCont(rsp.pCont); @@ -131,7 +132,7 @@ void dmSendMonitorReport(SDnode *pDnode) { } pWrapper = &pDnode->wrappers[BNODE]; - if (!tsMultiProcess) { + if (getFromAPI) { if (dndMarkWrapper(pWrapper) != 0) { bmGetMonitorInfo(pWrapper, &bmInfo); dndReleaseWrapper(pWrapper); @@ -140,7 +141,7 @@ void dmSendMonitorReport(SDnode *pDnode) { if (pWrapper->required) { req.msgType = TDMT_MON_BM_INFO; dndSendRecv(pDnode, &epset, &req, &rsp); - if (rsp.code == 0) { + if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo); } rpcFreeCont(rsp.pCont); @@ -162,7 +163,8 @@ void dmSendMonitorReport(SDnode *pDnode) { } void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { - if (!tsMultiProcess) { + bool getFromAPI = !tsMultiProcess; + if (getFromAPI) { vmGetVnodeLoads(pWrapper, pInfo); } else { SRpcMsg req = {.msgType = TDMT_MON_VM_LOAD}; @@ -172,7 +174,7 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { epset.eps[0].port = tsServerPort; dndSendRecv(pWrapper->pDnode, &epset, &req, &rsp); - if (rsp.code == 0) { + if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonVloadInfo(rsp.pCont, rsp.contLen, pInfo); } rpcFreeCont(rsp.pCont); diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c index b5aff12992..3c8dbc5d55 100644 --- a/source/dnode/mgmt/mm/mmHandle.c +++ b/source/dnode/mgmt/mm/mmHandle.c @@ -19,15 +19,13 @@ void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { SMnodeMgmt *pMgmt = pWrapper->pMgmt; mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant); - if (pWrapper->procType == PROC_CHILD) { - dmGetMonitorSysInfo(&mmInfo->sys); - monGetLogs(&mmInfo->log); - } } int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonMmInfo mmInfo = {0}; mmGetMonitorInfo(pWrapper, &mmInfo); + dmGetMonitorSysInfo(&mmInfo.sys); + monGetLogs(&mmInfo.log); int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); if (rspLen < 0) { diff --git a/source/dnode/mgmt/mm/mmWorker.c b/source/dnode/mgmt/mm/mmWorker.c index 85aa265904..44bac61906 100644 --- a/source/dnode/mgmt/mm/mmWorker.c +++ b/source/dnode/mgmt/mm/mmWorker.c @@ -34,10 +34,7 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { if (pRpc->msgType & 1U) { if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - if (code != 0) { - code = terrno; - dError("msg:%p, failed to process since %s", pMsg, terrstr()); - } + if (code != 0 && terrno != 0) code = terrno; SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; tmsgSendRsp(&rsp); } @@ -173,8 +170,8 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) { } if (tsMultiProcess) { - SSingleWorkerCfg sCfg = {.min = 1, .max = 1, .name = "mnode-monitor", .fp = (FItem)mmProcessQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + SSingleWorkerCfg mCfg = {.min = 1, .max = 1, .name = "mnode-monitor", .fp = (FItem)mmProcessQueue, .param = pMgmt}; + if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { dError("failed to start mnode mnode-monitor worker since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/qm/qmHandle.c b/source/dnode/mgmt/qm/qmHandle.c index c96b396691..11b4ff0622 100644 --- a/source/dnode/mgmt/qm/qmHandle.c +++ b/source/dnode/mgmt/qm/qmHandle.c @@ -17,15 +17,13 @@ #include "qmInt.h" void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo) { - if (pWrapper->procType == PROC_CHILD) { - dmGetMonitorSysInfo(&qmInfo->sys); - monGetLogs(&qmInfo->log); - } } int32_t qmProcessGetMonQmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonQmInfo qmInfo = {0}; qmGetMonitorInfo(pWrapper, &qmInfo); + dmGetMonitorSysInfo(&qmInfo.sys); + monGetLogs(&qmInfo.log); int32_t rspLen = tSerializeSMonQmInfo(NULL, 0, &qmInfo); if (rspLen < 0) { diff --git a/source/dnode/mgmt/qm/qmWorker.c b/source/dnode/mgmt/qm/qmWorker.c index e9d1173f20..6c8382aef9 100644 --- a/source/dnode/mgmt/qm/qmWorker.c +++ b/source/dnode/mgmt/qm/qmWorker.c @@ -16,8 +16,12 @@ #define _DEFAULT_SOURCE #include "qmInt.h" -static void qmSendRsp(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t code) { - SRpcMsg rsp = {.handle = pMsg->rpcMsg.handle, .ahandle = pMsg->rpcMsg.ahandle, .code = code}; +static inline void qmSendRsp(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t code) { + SRpcMsg rsp = {.handle = pMsg->rpcMsg.handle, + .ahandle = pMsg->rpcMsg.ahandle, + .code = code, + .pCont = pMsg->pRsp, + .contLen = pMsg->rspLen}; tmsgSendRsp(&rsp); } @@ -33,14 +37,8 @@ static void qmProcessMonQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { } if (pRpc->msgType & 1U) { - if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - if (code != 0) { - code = terrno; - dError("msg:%p, failed to process since %s", pMsg, terrstr()); - } - SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; - tmsgSendRsp(&rsp); - } + if (code != 0 && terrno != 0) code = terrno; + qmSendRsp(pMgmt->pWrapper, pMsg, code); } dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); @@ -165,9 +163,9 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) { } if (tsMultiProcess) { - SSingleWorkerCfg sCfg = { + SSingleWorkerCfg mCfg = { .min = 1, .max = 1, .name = "qnode-monitor", .fp = (FItem)qmProcessMonQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { dError("failed to start qnode-monitor worker since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/sm/smHandle.c b/source/dnode/mgmt/sm/smHandle.c index 5500db4513..fed6b6528c 100644 --- a/source/dnode/mgmt/sm/smHandle.c +++ b/source/dnode/mgmt/sm/smHandle.c @@ -16,17 +16,14 @@ #define _DEFAULT_SOURCE #include "smInt.h" -void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo) { - if (pWrapper->procType == PROC_CHILD) { - dmGetMonitorSysInfo(&smInfo->sys); - monGetLogs(&smInfo->log); - } -} +void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo) {} int32_t smProcessGetMonSmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonSmInfo smInfo = {0}; smGetMonitorInfo(pWrapper, &smInfo); - + dmGetMonitorSysInfo(&smInfo.sys); + monGetLogs(&smInfo.log); + int32_t rspLen = tSerializeSMonSmInfo(NULL, 0, &smInfo); if (rspLen < 0) { terrno = TSDB_CODE_INVALID_MSG; diff --git a/source/dnode/mgmt/sm/smWorker.c b/source/dnode/mgmt/sm/smWorker.c index 33ae289733..a29d5d1abc 100644 --- a/source/dnode/mgmt/sm/smWorker.c +++ b/source/dnode/mgmt/sm/smWorker.c @@ -16,6 +16,15 @@ #define _DEFAULT_SOURCE #include "smInt.h" +static inline void smSendRsp(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t code) { + SRpcMsg rsp = {.handle = pMsg->rpcMsg.handle, + .ahandle = pMsg->rpcMsg.ahandle, + .code = code, + .pCont = pMsg->pRsp, + .contLen = pMsg->rspLen}; + tmsgSendRsp(&rsp); +} + static void smProcessMonitorQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SSnodeMgmt *pMgmt = pInfo->ahandle; @@ -28,14 +37,8 @@ static void smProcessMonitorQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { } if (pRpc->msgType & 1U) { - if (pRpc->handle != NULL && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - if (code != 0) { - code = terrno; - dError("msg:%p, failed to process since %s", pMsg, terrstr()); - } - SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .contLen = pMsg->rspLen, .pCont = pMsg->pRsp}; - tmsgSendRsp(&rsp); - } + if (code != 0 && terrno != 0) code = terrno; + smSendRsp(pMgmt->pWrapper, pMsg, code); } dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); @@ -108,9 +111,9 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { } if (tsMultiProcess) { - SSingleWorkerCfg sCfg = { + SSingleWorkerCfg mCfg = { .min = 1, .max = 1, .name = "snode-monitor", .fp = (FItem)smProcessMonitorQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { dError("failed to start snode-monitor worker since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/vm/vmHandle.c b/source/dnode/mgmt/vm/vmHandle.c index f003d8c58a..ecad414fd6 100644 --- a/source/dnode/mgmt/vm/vmHandle.c +++ b/source/dnode/mgmt/vm/vmHandle.c @@ -31,16 +31,13 @@ void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo) { pMgmt->state.numOfBatchInsertSuccessReqs - pMgmt->lastState.numOfBatchInsertSuccessReqs; pMgmt->lastState = pMgmt->state; taosWUnLockLatch(&pMgmt->latch); - - if (pWrapper->procType == PROC_CHILD) { - dmGetMonitorSysInfo(&vmInfo->sys); - monGetLogs(&vmInfo->log); - } } int32_t vmProcessGetMonVmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { SMonVmInfo vmInfo = {0}; vmGetMonitorInfo(pWrapper, &vmInfo); + dmGetMonitorSysInfo(&vmInfo.sys); + monGetLogs(&vmInfo.log); int32_t rspLen = tSerializeSMonVmInfo(NULL, 0, &vmInfo); if (rspLen < 0) { diff --git a/source/dnode/mgmt/vm/vmWorker.c b/source/dnode/mgmt/vm/vmWorker.c index 82c45f172d..ff92cf880b 100644 --- a/source/dnode/mgmt/vm/vmWorker.c +++ b/source/dnode/mgmt/vm/vmWorker.c @@ -16,8 +16,12 @@ #define _DEFAULT_SOURCE #include "vmInt.h" -static void vmSendRsp(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t code) { - SRpcMsg rsp = {.handle = pMsg->rpcMsg.handle, .ahandle = pMsg->rpcMsg.ahandle, .code = code}; +static inline void vmSendRsp(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t code) { + SRpcMsg rsp = {.handle = pMsg->rpcMsg.handle, + .ahandle = pMsg->rpcMsg.ahandle, + .code = code, + .pCont = pMsg->pRsp, + .contLen = pMsg->rspLen}; tmsgSendRsp(&rsp); } @@ -26,7 +30,7 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { int32_t code = -1; tmsg_t msgType = pMsg->rpcMsg.msgType; - dTrace("msg:%p, will be processed in vnode-mgmt queue", pMsg); + dTrace("msg:%p, will be processed in vnode-m queue", pMsg); switch (msgType) { case TDMT_MON_VM_INFO: @@ -428,9 +432,9 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) { } if (tsMultiProcess) { - SSingleWorkerCfg sCfg = { + SSingleWorkerCfg mCfg = { .min = 1, .max = 1, .name = "vnode-monitor", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &sCfg) != 0) { + if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { dError("failed to start mnode vnode-monitor worker since %s", terrstr()); return -1; } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 314e70db9b..6bc3ea9fc0 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -237,7 +237,7 @@ int32_t mndGetDnodeSize(SMnode *pMnode) { bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs) { int64_t interval = TABS(pDnode->lastAccessTime - curMs); - if (interval > 3500 * tsStatusInterval) { + if (interval > 30000 * tsStatusInterval) { if (pDnode->rebootTime > 0) { pDnode->offlineReason = DND_REASON_STATUS_MSG_TIMEOUT; } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 5c3dd778e1..86bbc0257b 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -502,7 +502,11 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr SMonVgroupDesc desc = {0}; desc.vgroup_id = pVgroup->vgId; - strncpy(desc.database_name, pVgroup->dbName, sizeof(desc.database_name)); + + SName name = {0}; + tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + tNameGetDbName(&name, desc.database_name); + desc.tables_num = pVgroup->numOfTables; pGrantInfo->timeseries_used += pVgroup->numOfTimeSeries; tstrncpy(desc.status, "unsynced", sizeof(desc.status)); diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index af7799cd7c..c90b1f58e8 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -529,7 +529,9 @@ void monSendReport() { char *pCont = tjsonToString(pMonitor->pJson); if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; - taosSendHttpReport(tsMonitor.cfg.server, tsMonitor.cfg.port, pCont, strlen(pCont), flag); + if (taosSendHttpReport(tsMonitor.cfg.server, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { + uError("failed to send monitor msg since %s", terrstr()); + } taosMemoryFree(pCont); } diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 90f15dd7d0..cd1fbf8e0e 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -117,7 +117,7 @@ _OVER: static void clientConnCb(uv_connect_t* req, int32_t status) { if (status < 0) { terrno = TAOS_SYSTEM_ERROR(status); - uError("Connection error %s\n", uv_strerror(status)); + uError("connection error %s", uv_strerror(status)); uv_close((uv_handle_t*)req->handle, NULL); return; }