From cdaf73f9f13865679d7efa9a6dd84aca9f6e7751 Mon Sep 17 00:00:00 2001 From: "wenzhouwww@live.cn" Date: Tue, 19 Jul 2022 15:11:44 +0800 Subject: [PATCH 01/42] test:add test case for bug fix about last_row --- tests/system-test/2-query/last_row.py | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/system-test/2-query/last_row.py b/tests/system-test/2-query/last_row.py index cbe83b5a30..743ed1c93b 100644 --- a/tests/system-test/2-query/last_row.py +++ b/tests/system-test/2-query/last_row.py @@ -290,6 +290,65 @@ class TDTestCase: tdSql.checkData(0, 0, None) tdSql.query("select last_row(c1) from testdb.stb1") tdSql.checkData(0, 0, None) + + # support regular query about last ,first ,last_row + # tdSql.query("select last_row(c1,NULL) from testdb.t1") + # tdSql.checkData(0,0,None) + # tdSql.checkData(0,1,None) + + # tdSql.query("select last_row(c1,123) from testdb.t1") + # tdSql.checkData(0,0,None) + # tdSql.checkData(0,1,123) + + # tdSql.query("select last(c1,NULL) from testdb.t1") + # tdSql.checkData(0,0,9) + # tdSql.checkData(0,1,None) + + # tdSql.query("select last(c1,123) from testdb.t1") + # tdSql.checkData(0,0,9) + # tdSql.checkData(0,1,123) + + # tdSql.query("select first(c1,NULL) from testdb.t1") + # tdSql.checkData(0,0,1) + # tdSql.checkData(0,1,None) + + # tdSql.query("select first(c1,123) from testdb.t1") + # tdSql.checkData(0,0,1) + # tdSql.checkData(0,1,123) + + # tdSql.query("select last_row(c1,c2,c3,NULL,c4) from testdb.t1") + # tdSql.checkData(0,0,None) + # tdSql.checkData(0,1,None) + # tdSql.checkData(0,2,None) + # tdSql.checkData(0,3,None) + # tdSql.checkData(0,4,None) + + # tdSql.query("select last_row(c1,c2,c3,123,c4) from testdb.t1") + # tdSql.checkData(0,0,None) + # tdSql.checkData(0,1,None) + # tdSql.checkData(0,2,None) + # tdSql.checkData(0,3,123) + # tdSql.checkData(0,4,None) + + + # tdSql.query("select last_row(c1,c2,c3,NULL,c4,t1,t2) from testdb.ct1") + # tdSql.checkData(0,0,9) + # tdSql.checkData(0,1,-99999) + # tdSql.checkData(0,2,-999) + # tdSql.checkData(0,3,None) + # tdSql.checkData(0,4,None) + # tdSql.checkData(0,5,0) + # tdSql.checkData(0,5,0) + + # tdSql.query("select last_row(c1,c2,c3,123,c4,t1,t2) from testdb.ct1") + # tdSql.checkData(0,0,9) + # tdSql.checkData(0,1,-99999) + # tdSql.checkData(0,2,-999) + # tdSql.checkData(0,3,123) + # tdSql.checkData(0,4,None) + # tdSql.checkData(0,5,0) + # tdSql.checkData(0,5,0) + # # bug need fix tdSql.query("select last_row(c1), c2, c3 , c4, c5 from testdb.t1") From b4537bc41e3f1b5fc9fe29687c5218dd454cc02c Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 11:31:35 +0800 Subject: [PATCH 02/42] shell: change shell print text --- tools/shell/src/shellEngine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index a496cc2864..a0adb7c7bc 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -197,7 +197,7 @@ void shellRunSingleCommandImp(char *command) { et = taosGetTimestampUs(); if (error_no == 0) { - printf("Query OK, %d rows affected (%.6fs)\r\n", numOfRows, (et - st) / 1E6); + printf("Query OK, %d rows in database (%.6fs)\r\n", numOfRows, (et - st) / 1E6); } else { printf("Query interrupted (%s), %d rows affected (%.6fs)\r\n", taos_errstr(pSql), numOfRows, (et - st) / 1E6); } From 3fba8182a5ab831980b4ddddb8b755ae78e63666 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 13:02:33 +0800 Subject: [PATCH 03/42] fix(query): fix time window generating bug. --- source/common/src/ttime.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 944ee6a731..9b044d6e93 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -844,11 +844,14 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio } else { // try to move current window to the left-hande-side, due to the offset effect. int64_t end = taosTimeAdd(start, pInterval->interval, pInterval->intervalUnit, precision) - 1; - ASSERT(end >= t); - end = taosTimeAdd(end, -pInterval->sliding, pInterval->slidingUnit, precision); - if (end >= t) { - start = taosTimeAdd(start, -pInterval->sliding, pInterval->slidingUnit, precision); + + int64_t newEnd = end; + while(newEnd >= t) { + end = newEnd; + newEnd = taosTimeAdd(newEnd, -pInterval->sliding, pInterval->slidingUnit, precision); } + + start = taosTimeAdd(end, -pInterval->interval + 1, pInterval->intervalUnit, precision); } } From facf3c86489667465391bbc9d9ef68bf682fa45e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 14:07:48 +0800 Subject: [PATCH 04/42] fix(query): add limit/offset for order by operator. --- source/libs/executor/inc/executorimpl.h | 6 +- source/libs/executor/src/cachescanoperator.c | 2 +- source/libs/executor/src/executorimpl.c | 18 +++--- source/libs/executor/src/groupoperator.c | 2 +- source/libs/executor/src/joinoperator.c | 2 +- source/libs/executor/src/scanoperator.c | 6 +- source/libs/executor/src/sortoperator.c | 58 +++++++++++++------ source/libs/executor/src/timewindowoperator.c | 20 +++---- 8 files changed, 67 insertions(+), 47 deletions(-) diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index d7c283c70d..9142af4a6d 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -744,8 +744,8 @@ typedef struct SSortOperatorInfo { int64_t startTs; // sort start time uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included. - - SNode* pCondition; + SLimitInfo limitInfo; + SNode* pCondition; } SSortOperatorInfo; typedef struct STagFilterOperatorInfo { @@ -785,7 +785,7 @@ int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr); void cleanupExprSupp(SExprSupp* pSup); int32_t initAggInfo(SExprSupp *pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize, const char* pkey); -void initResultSizeInfo(SOperatorInfo* pOperator, int32_t numOfRows); +void initResultSizeInfo(SResultInfo * pResultInfo, int32_t numOfRows); void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf); int32_t handleLimitOffset(SOperatorInfo *pOperator, SLimitInfo* pLimitInfo, SSDataBlock* pBlock, bool holdDataInBuf); bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo); diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index c46485a332..56a5e253d8 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -50,7 +50,7 @@ SOperatorInfo* createLastrowScanOperator(SLastRowScanPhysiNode* pScanNode, SRead STableListInfo* pTableList = &pTaskInfo->tableqinfoList; - initResultSizeInfo(pOperator, 1024); + initResultSizeInfo(&pOperator->resultInfo, 1024); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); pInfo->pUidList = taosArrayInit(4, sizeof(int64_t)); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 0036a3f080..df039bc0e2 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -3601,13 +3601,13 @@ int32_t initAggInfo(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInf return TSDB_CODE_SUCCESS; } -void initResultSizeInfo(SOperatorInfo* pOperator, int32_t numOfRows) { +void initResultSizeInfo(SResultInfo * pResultInfo, int32_t numOfRows) { ASSERT(numOfRows != 0); - pOperator->resultInfo.capacity = numOfRows; - pOperator->resultInfo.threshold = numOfRows * 0.75; + pResultInfo->capacity = numOfRows; + pResultInfo->threshold = numOfRows * 0.75; - if (pOperator->resultInfo.threshold == 0) { - pOperator->resultInfo.threshold = numOfRows; + if (pResultInfo->threshold == 0) { + pResultInfo->threshold = numOfRows; } } @@ -3670,7 +3670,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* int32_t numOfRows = 1024; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, numOfRows); + initResultSizeInfo(&pOperator->resultInfo, numOfRows); int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -3825,7 +3825,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys if (numOfRows * pResBlock->info.rowSize > TWOMB) { numOfRows = TWOMB / pResBlock->info.rowSize; } - initResultSizeInfo(pOperator, numOfRows); + initResultSizeInfo(&pOperator->resultInfo, numOfRows); initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); @@ -4003,7 +4003,7 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy numOfRows = TWOMB / pResBlock->info.rowSize; } - initResultSizeInfo(pOperator, numOfRows); + initResultSizeInfo(&pOperator->resultInfo, numOfRows); initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfExpr, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); @@ -4080,7 +4080,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* int32_t type = convertFillType(pPhyFillNode->mode); SResultInfo* pResultInfo = &pOperator->resultInfo; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->primaryTsCol = ((SColumnNode*)pPhyFillNode->pWStartTs)->slotId; int32_t numOfOutputCols = 0; diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 2964948e70..20630fd6ff 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -406,7 +406,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx goto _error; } - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, pInfo->groupKeyLen, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResultBlock); initResultRowInfo(&pInfo->binfo.resultRowInfo); diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index b864fae47f..497de8347c 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -41,7 +41,7 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pJoinNode->pTargets, NULL, &numOfCols); - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pRes = pResBlock; pOperator->name = "MergeJoinOperator"; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index dc44de9cf3..1f77dfb093 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -2299,7 +2299,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan pInfo->pCondition = pScanNode->node.pConditions; pInfo->scanCols = colList; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); tNameAssign(&pInfo->name, &pScanNode->tableName); const char* name = tNameGetTableName(&pInfo->name); @@ -2529,7 +2529,7 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi pOperator->info = pInfo; pOperator->pTaskInfo = pTaskInfo; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); pOperator->fpSet = @@ -3073,7 +3073,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN pOperator->info = pInfo; pOperator->exprSupp.numOfExprs = numOfCols; pOperator->pTaskInfo = pTaskInfo; - initResultSizeInfo(pOperator, 1024); + initResultSizeInfo(&pOperator->resultInfo, 1024); pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, NULL, destroyTableMergeScanOperatorInfo, NULL, diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index a3b79d9597..f019ee94b8 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -26,7 +26,7 @@ static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput); SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortNode, SExecTaskInfo* pTaskInfo) { SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL /* || rowSize > 100 * 1024 * 1024*/) { + if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -41,13 +41,15 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset); + + initResultSizeInfo(&pOperator->resultInfo, 1024); + pInfo->binfo.pRes = pResBlock; - - initResultSizeInfo(pOperator, 1024); - - pInfo->pSortInfo = createSortInfo(pSortNode->pSortKeys); + pInfo->pSortInfo = createSortInfo(pSortNode->pSortKeys); pInfo->pCondition = pSortNode->node.pConditions; pInfo->pColMatchInfo = pColMatchColInfo; + initLimitInfo(pSortNode->node.pLimit, pSortNode->node.pSlimit, &pInfo->limitInfo); + pOperator->name = "SortOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; pOperator->blocking = true; @@ -208,26 +210,44 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { SSDataBlock* pBlock = NULL; while (1) { pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, - pInfo->pColMatchInfo, pInfo); - if (pBlock != NULL) { - doFilter(pInfo->pCondition, pBlock); - } - + pInfo->pColMatchInfo, pInfo); if (pBlock == NULL) { doSetOperatorCompleted(pOperator); - break; + return NULL; } - if (blockDataGetNumOfRows(pBlock) > 0) { + doFilter(pInfo->pCondition, pBlock); + if (blockDataGetNumOfRows(pBlock) == 0) { + continue; + } + + // todo add the limit/offset info + if (pInfo->limitInfo.remainOffset > 0) { + if (pInfo->limitInfo.remainOffset >= blockDataGetNumOfRows(pBlock)) { + pInfo->limitInfo.remainOffset -= pBlock->info.rows; + continue; + } + + blockDataTrimFirstNRows(pBlock, pInfo->limitInfo.remainOffset); + pInfo->limitInfo.remainOffset = 0; + } + + if (pInfo->limitInfo.limit.limit > 0 && + pInfo->limitInfo.limit.limit <= pInfo->limitInfo.numOfOutputRows + blockDataGetNumOfRows(pBlock)) { + int32_t remain = pInfo->limitInfo.limit.limit - pInfo->limitInfo.numOfOutputRows; + blockDataKeepFirstNRows(pBlock, remain); + } + + size_t numOfRows = blockDataGetNumOfRows(pBlock); + pInfo->limitInfo.numOfOutputRows += numOfRows; + pOperator->resultInfo.totalRows += numOfRows; + + if (numOfRows > 0) { break; } } - if (pBlock != NULL) { - pOperator->resultInfo.totalRows += pBlock->info.rows; - } - - return pBlock; + return blockDataGetNumOfRows(pBlock) > 0? pBlock:NULL; } void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) { @@ -479,7 +499,7 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset); pInfo->binfo.pRes = pResBlock; - initResultSizeInfo(pOperator, 1024); + initResultSizeInfo(&pOperator->resultInfo, 1024); pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys); ; @@ -711,7 +731,7 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID); SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); SSDataBlock* pInputBlock = createResDataBlock(pChildNode->pOutputDataBlockDesc); - initResultSizeInfo(pOperator, 1024); + initResultSizeInfo(&pOperator->resultInfo, 1024); pInfo->groupSort = pMergePhyNode->groupSort; pInfo->binfo.pRes = pResBlock; diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 3933ded7a9..042f807271 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1683,7 +1683,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* SExprSupp* pSup = &pOperator->exprSupp; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); @@ -1764,7 +1764,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExpr int32_t numOfRows = 4096; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, numOfRows); + initResultSizeInfo(&pOperator->resultInfo, numOfRows); int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pInfo->win); @@ -2224,7 +2224,7 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode pInfo->tsCol = extractColumnFromColumnNode((SColumnNode*)pInterpPhyNode->pTimeSeries); pInfo->fillType = convertFillType(pInterpPhyNode->fillMode); - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pFillColInfo = createFillColInfo(pExprInfo, numOfExprs, (SNodeListNode*)pInterpPhyNode->pFillValues); pInfo->pRes = createResDataBlock(pPhyNode->pOutputDataBlockDesc); @@ -2272,7 +2272,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExpr, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&pInfo->binfo, pResBlock); @@ -2320,7 +2320,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo } size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { @@ -2896,7 +2896,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, ASSERT(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY); pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); if (pIntervalPhyNode->window.pExprs != NULL) { int32_t numOfScalar = 0; SExprInfo* pScalarExprInfo = createExprInfo(pIntervalPhyNode->window.pExprs, NULL, &numOfScalar); @@ -3072,7 +3072,7 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh goto _error; } - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); if (pSessionNode->window.pExprs != NULL) { int32_t numOfScalar = 0; SExprInfo* pScalarExprInfo = createExprInfo(pSessionNode->window.pExprs, NULL, &numOfScalar); @@ -4336,7 +4336,7 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys SExprInfo* pExprInfo = createExprInfo(pStateNode->window.pFuncs, NULL, &numOfCols); pInfo->stateCol = extractColumnFromColumnNode(pColNode); - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); if (pStateNode->window.pExprs != NULL) { int32_t numOfScalar = 0; SExprInfo* pScalarExprInfo = createExprInfo(pStateNode->window.pExprs, NULL, &numOfScalar); @@ -4586,7 +4586,7 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, iaInfo->primaryTsIndex = primaryTsSlotId; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(&pOperator->exprSupp, &iaInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); @@ -4892,7 +4892,7 @@ SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SExprI SExprSupp* pExprSupp = &pOperator->exprSupp; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; - initResultSizeInfo(pOperator, 4096); + initResultSizeInfo(&pOperator->resultInfo, 4096); int32_t code = initAggInfo(pExprSupp, &iaInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str); initBasicInfo(&iaInfo->binfo, pResBlock); From eefad2bd9d2b566346e933fb7e0f6f541ceeba37 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 20 Jul 2022 14:28:13 +0800 Subject: [PATCH 05/42] fix: use Ex version of metaGetTbTSchema to retrieve schema --- source/dnode/vnode/src/tsdb/tsdbRead.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index c1778ed5ca..cac51faeee 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2576,10 +2576,12 @@ void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader) { int32_t sversion = TSDBROW_SVERSION(pRow); if (pReader->pSchema == NULL) { - pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, 0, uid, sversion, &pReader->pSchema); } else if (pReader->pSchema->version != sversion) { taosMemoryFreeClear(pReader->pSchema); - pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, 0, uid, sversion, &pReader->pSchema); } } From a2dd6f0ce504c387a28df248b3699d72b4d856e9 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 20 Jul 2022 14:42:03 +0800 Subject: [PATCH 06/42] fix(query): fix memory leak in histogram param validation TD-17598 --- source/libs/function/src/builtins.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 9c004bf1c4..ec8e6b038e 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -958,6 +958,7 @@ static bool validateHistogramBinDesc(char* binDescStr, int8_t binType, char* err return false; } + cJSON_Delete(binDesc); taosMemoryFree(intervals); return true; } From 4dbb2debc05565f06eb4ca91c913fd9a5d762be7 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 20 Jul 2022 14:42:03 +0800 Subject: [PATCH 07/42] fix(query): fix memory leak in histogram param validation TD-17598 --- source/libs/scalar/src/sclfunc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index b754c52bbd..050f77bb21 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -2750,6 +2750,7 @@ static bool getHistogramBinDesc(SHistoFuncBin** bins, int32_t* binNum, char* bin (*bins)[i].count = 0; } + cJSON_Delete(binDesc); taosMemoryFree(intervals); return true; } From 527aa3584dfbaa76630a8542ccc220584c7c6c2a Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 20 Jul 2022 15:26:47 +0800 Subject: [PATCH 08/42] fix: get suid from uid to be used to retrieve schema --- source/dnode/vnode/src/tsdb/tsdbRead.c | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index cac51faeee..7048dc7b2b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2572,16 +2572,41 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc return TSDB_CODE_SUCCESS; } +static tb_uid_t getTableSuidByUid(tb_uid_t uid, STsdb* pTsdb) { + tb_uid_t suid = 0; + + SMetaReader mr = {0}; + metaReaderInit(&mr, pTsdb->pVnode->pMeta, 0); + if (metaGetTableEntryByUid(&mr, uid) < 0) { + metaReaderClear(&mr); // table not esist + return 0; + } + + if (mr.me.type == TSDB_CHILD_TABLE) { + suid = mr.me.ctbEntry.suid; + } else if (mr.me.type == TSDB_NORMAL_TABLE) { + suid = 0; + } else { + suid = 0; + } + + metaReaderClear(&mr); + + return suid; +} + void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader) { int32_t sversion = TSDBROW_SVERSION(pRow); + tb_uid_t suid = getTableSuidByUid(uid, pReader->pTsdb); + if (pReader->pSchema == NULL) { // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); - metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, 0, uid, sversion, &pReader->pSchema); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, suid, uid, sversion, &pReader->pSchema); } else if (pReader->pSchema->version != sversion) { taosMemoryFreeClear(pReader->pSchema); // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); - metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, 0, uid, sversion, &pReader->pSchema); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, suid, uid, sversion, &pReader->pSchema); } } From df58a9bb30341843081ad3cc3a4072423665eaee Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 15:30:52 +0800 Subject: [PATCH 09/42] fix(query): handle fraction of ts in add ts offset. --- source/common/src/ttime.c | 6 ++++-- source/libs/executor/inc/executorimpl.h | 2 +- source/libs/executor/src/executil.c | 4 ++-- source/libs/executor/src/executorimpl.c | 17 +++++++++-------- source/libs/executor/src/scanoperator.c | 4 ++-- tests/script/tsim/query/interval-offset.sim | 1 + 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 9b044d6e93..8f150441f9 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -700,6 +700,8 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { numOfMonth *= 12; } + int64_t fraction = t % TSDB_TICK_PER_SECOND(precision); + struct tm tm; time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision)); taosLocalTime(&tt, &tm); @@ -707,7 +709,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { tm.tm_year = mon / 12; tm.tm_mon = mon % 12; - return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision)); + return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision) + fraction); } int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) { @@ -851,7 +853,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio newEnd = taosTimeAdd(newEnd, -pInterval->sliding, pInterval->slidingUnit, precision); } - start = taosTimeAdd(end, -pInterval->interval + 1, pInterval->intervalUnit, precision); + start = taosTimeAdd(end, -pInterval->interval, pInterval->intervalUnit, precision) + 1; } } diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 9142af4a6d..2cc4058b3b 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -797,7 +797,7 @@ void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, STimeWin int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData, int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList); -void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win); +STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key); STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order); int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t *order, int32_t* scanFlag); diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 978bef1607..60799e0528 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -824,10 +824,10 @@ int32_t convertFillType(int32_t mode) { static void getInitialStartTimeWindow(SInterval* pInterval, TSKEY ts, STimeWindow* w, bool ascQuery) { if (ascQuery) { - getAlignQueryTimeWindow(pInterval, pInterval->precision, ts, w); + *w = getAlignQueryTimeWindow(pInterval, pInterval->precision, ts); } else { // the start position of the first time window in the endpoint that spreads beyond the queried last timestamp - getAlignQueryTimeWindow(pInterval, pInterval->precision, ts, w); + *w = getAlignQueryTimeWindow(pInterval, pInterval->precision, ts); int64_t key = w->skey; while (key < ts) { // moving towards end diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index df039bc0e2..44d1cc0965 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -834,18 +834,20 @@ bool isTaskKilled(SExecTaskInfo* pTaskInfo) { void setTaskKilled(SExecTaskInfo* pTaskInfo) { pTaskInfo->code = TSDB_CODE_TSC_QUERY_CANCELLED; } ///////////////////////////////////////////////////////////////////////////////////////////// -// todo refactor : return window -void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win) { - win->skey = taosTimeTruncate(key, pInterval, precision); +STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key) { + STimeWindow win = {0}; + win.skey = taosTimeTruncate(key, pInterval, precision); /* * if the realSkey > INT64_MAX - pInterval->interval, the query duration between * realSkey and realEkey must be less than one interval.Therefore, no need to adjust the query ranges. */ - win->ekey = taosTimeAdd(win->skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; - if (win->ekey < win->skey) { - win->ekey = INT64_MAX; + win.ekey = taosTimeAdd(win.skey, pInterval->interval, pInterval->intervalUnit, precision) - 1; + if (win.ekey < win.skey) { + win.ekey = INT64_MAX; } + + return win; } #if 0 @@ -4042,8 +4044,7 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t STimeWindow win, int32_t capacity, const char* id, SInterval* pInterval, int32_t fillType) { SFillColInfo* pColInfo = createFillColInfo(pExpr, numOfCols, pValNode); - STimeWindow w = TSWINDOW_INITIALIZER; - getAlignQueryTimeWindow(pInterval, pInterval->precision, win.skey, &w); + STimeWindow w = getAlignQueryTimeWindow(pInterval, pInterval->precision, win.skey); w = getFirstQualifiedTimeWindow(win.skey, &w, pInterval, TSDB_ORDER_ASC); int32_t order = TSDB_ORDER_ASC; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 1f77dfb093..ae5996c2fa 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -125,7 +125,7 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn } if (order == TSDB_ORDER_ASC) { - getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.skey, &w); + w = getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.skey); assert(w.ekey >= pBlockInfo->window.skey); if (w.ekey < pBlockInfo->window.ekey) { @@ -144,7 +144,7 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn } } } else { - getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.ekey, &w); + w = getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.ekey); assert(w.skey <= pBlockInfo->window.ekey); if (w.skey > pBlockInfo->window.skey) { diff --git a/tests/script/tsim/query/interval-offset.sim b/tests/script/tsim/query/interval-offset.sim index b6dffb5fe3..1399be7b53 100644 --- a/tests/script/tsim/query/interval-offset.sim +++ b/tests/script/tsim/query/interval-offset.sim @@ -185,6 +185,7 @@ print ===> rows1: $data10 $data11 $data12 $data13 $data14 print ===> rows2: $data20 $data21 $data22 $data23 $data24 print ===> rows3: $data30 $data31 $data32 $data33 $data34 if $rows != 4 then + print expect 4, actual: $rows return -1 endi if $data00 != @21-12-08 00:00:00.000@ then From c2b348bec5019ae28839a77f9a210c49b0c623a9 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 20 Jul 2022 15:34:09 +0800 Subject: [PATCH 10/42] refactor(sync): add trace log --- source/libs/sync/src/syncAppendEntries.c | 310 +++++++++++++----- source/libs/sync/src/syncAppendEntriesReply.c | 226 +++++++++---- source/libs/sync/src/syncMain.c | 6 +- source/libs/sync/src/syncRaftStore.c | 22 +- source/libs/sync/src/syncReplication.c | 30 +- 5 files changed, 427 insertions(+), 167 deletions(-) diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 9678b335fd..0e26d1ea65 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -92,13 +92,24 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { int32_t ret = 0; - // print log - syncAppendEntriesLog2("==syncNodeOnAppendEntriesCb==", pMsg); - // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncNodeEventLog(ths, "recv sync-append-entries, maybe replica already dropped"); - return ret; + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, maybe replica already dropped", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); + syncNodeErrorLog(ths, logBuf); + } while (0); + + return -1; } // maybe update term @@ -117,12 +128,25 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { do { // return to follower state if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) { - syncNodeEventLog(ths, "recv sync-append-entries, candidate to follower"); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, candidate to follower", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); + syncNodeEventLog(ths, logBuf); + } while (0); syncNodeBecomeFollower(ths, "from candidate by append entries"); // ret or reply? - return ret; + return -1; } } while (0); @@ -149,10 +173,17 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { if ((pMsg->term < ths->pRaftStore->currentTerm) || ((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) { do { - char logBuf[128]; + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries, reject, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", - pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, reject", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); syncNodeEventLog(ths, logBuf); } while (0); @@ -165,12 +196,15 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // msg event log do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + syncNodeEventLog(ths, logBuf); } while (0); SRpcMsg rpcMsg; @@ -193,10 +227,17 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { bool hasAppendEntries = pMsg->dataLen > 0; do { - char logBuf[128]; + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries, accept, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", - pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, accept", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); syncNodeEventLog(ths, logBuf); } while (0); @@ -349,12 +390,15 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // msg event log do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + syncNodeEventLog(ths, logBuf); } while (0); SRpcMsg rpcMsg; @@ -558,7 +602,21 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncNodeEventLog(ths, "recv sync-append-entries-batch, maybe replica already dropped"); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "count:%d}, maybe replica already dropped", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataCount); + syncNodeErrorLog(ths, logBuf); + } while (0); + return ret; } @@ -582,7 +640,20 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc do { bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE; if (condition) { - syncNodeEventLog(ths, "recv sync-append-entries-batch, candidate to follower"); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "count:%d}, candidate to follower", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataCount); + syncNodeEventLog(ths, logBuf); + } while (0); syncNodeBecomeFollower(ths, "from candidate by append entries"); // do not reply? @@ -603,11 +674,17 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc (pMsg->prevLogIndex <= ths->commitIndex); if (condition) { do { - char logBuf[128]; + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch, fake match2, {pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", datalen:%d, datacount:%d}", - pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen, pMsg->dataCount); + "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "count:%d}, fake match2", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataCount); syncNodeEventLog(ths, logBuf); } while (0); @@ -663,12 +740,15 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc // msg event log do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + syncNodeEventLog(ths, logBuf); } while (0); // send response @@ -703,11 +783,17 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc if (condition) { do { - char logBuf[128]; + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch, not match, {pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", datalen:%d, datacount:%d}", - pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen, pMsg->dataCount); + "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "count:%d}, not match", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataCount); syncNodeEventLog(ths, logBuf); } while (0); @@ -725,12 +811,15 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc // msg event log do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + syncNodeEventLog(ths, logBuf); } while (0); // send response @@ -763,11 +852,17 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc SOffsetAndContLen* metaTableArr = syncAppendEntriesBatchMetaTableArray(pMsg); do { - char logBuf[128]; + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch, match, {pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", datalen:%d, datacount:%d}", - pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen, pMsg->dataCount); + "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "count:%d}, match", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataCount); syncNodeEventLog(ths, logBuf); } while (0); @@ -809,12 +904,15 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc // msg event log do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + syncNodeEventLog(ths, logBuf); } while (0); // send response @@ -866,12 +964,23 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs int32_t ret = 0; int32_t code = 0; - // print log - syncAppendEntriesLog2("==syncNodeOnAppendEntriesSnapshotCb==", pMsg); - // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncNodeEventLog(ths, "recv sync-append-entries, maybe replica already dropped"); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, maybe replica dropped", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); + syncNodeErrorLog(ths, logBuf); + } while (0); + return ret; } @@ -895,7 +1004,20 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs do { bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE; if (condition) { - syncNodeEventLog(ths, "recv sync-append-entries, candidate to follower"); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, candidate to follower", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); + syncNodeEventLog(ths, logBuf); + } while (0); syncNodeBecomeFollower(ths, "from candidate by append entries"); // do not reply? @@ -976,10 +1098,17 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs (pMsg->prevLogIndex <= ths->commitIndex); if (condition) { do { - char logBuf[128]; + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries, fake match2, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", - pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, fake match2", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); syncNodeEventLog(ths, logBuf); } while (0); @@ -1028,12 +1157,15 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs // msg event log do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + syncNodeEventLog(ths, logBuf); } while (0); // send response @@ -1067,11 +1199,20 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs bool condition = condition1 || condition2; if (condition) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries, not match, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", - pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); - syncNodeEventLog(ths, logBuf); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, not match", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); + syncNodeEventLog(ths, logBuf); + } while (0); // prepare response msg SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); @@ -1084,12 +1225,15 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs // msg event log do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + syncNodeEventLog(ths, logBuf); } while (0); // send response @@ -1120,11 +1264,20 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs // has entries in SyncAppendEntries msg bool hasAppendEntries = pMsg->dataLen > 0; - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries, match, pre-index:%" PRId64 ", pre-term:%" PRIu64 ", datalen:%d", - pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->dataLen); - syncNodeEventLog(ths, logBuf); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, match", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen); + syncNodeEventLog(ths, logBuf); + } while (0); if (hasExtraEntries) { // make log same, rollback deleted entries @@ -1160,12 +1313,15 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs // msg event log do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - ths->vgId, host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 + ", success:%d, match-index:%" PRId64 "}", + host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); + syncNodeEventLog(ths, logBuf); } while (0); // send response diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 5137922522..5149b47147 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -40,39 +40,59 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) { int32_t ret = 0; - // print log - syncAppendEntriesReplyLog2("==syncNodeOnAppendEntriesReplyCb==", pMsg); - // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncNodeEventLog(ths, "recv sync-append-entries-reply, maybe replica already dropped"); - return 0; + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, maybe replica " + "already dropped", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeErrorLog(ths, logBuf); + } while (0); + + return -1; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%" PRIu64 ", drop stale response", - pMsg->term); - syncNodeEventLog(ths, logBuf); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, drop stale response", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeEventLog(ths, logBuf); + } while (0); + return 0; } - if (gRaftDetailLog) { - syncNodeEventLog(ths, "recv sync-append-entries-reply, before"); - } - syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== before pNextIndex", ths->pNextIndex); - syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== before pMatchIndex", ths->pMatchIndex); - // no need this code, because if I receive reply.term, then I must have sent for that term. // if (pMsg->term > ths->pRaftStore->currentTerm) { // syncNodeUpdateTerm(ths, pMsg->term); // } if (pMsg->term > ths->pRaftStore->currentTerm) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%" PRIu64, pMsg->term); - syncNodeErrorLog(ths, logBuf); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, error term", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeErrorLog(ths, logBuf); + } while (0); + return -1; } @@ -100,13 +120,23 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex); } - if (gRaftDetailLog) { - syncNodeEventLog(ths, "recv sync-append-entries-reply, after"); - } - syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== after pNextIndex", ths->pNextIndex); - syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== after pMatchIndex", ths->pMatchIndex); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex matchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, after next:" PRId64 + ", " + "match:" PRId64 "", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, nextIndex, matchIndex); + syncNodeEventLog(ths, logBuf); + } while (0); - return ret; + return 0; } // only start once @@ -147,35 +177,55 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) { int32_t ret = 0; - // print log - do { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, term:%lu, match:%ld, success:%d", pMsg->term, - pMsg->matchIndex, pMsg->success); - syncNodeEventLog(ths, logBuf); - - } while (0); - // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncNodeEventLog(ths, "recv sync-append-entries-reply, maybe replica already dropped"); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, maybe replica " + "already dropped", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeErrorLog(ths, logBuf); + } while (0); + return -1; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%" PRIu64 ", drop stale response", - pMsg->term); - syncNodeEventLog(ths, logBuf); - return -1; + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, drop stale response", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeEventLog(ths, logBuf); + } while (0); + + return 0; } // error term if (pMsg->term > ths->pRaftStore->currentTerm) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%" PRIu64, pMsg->term); - syncNodeErrorLog(ths, logBuf); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, error term", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeErrorLog(ths, logBuf); + } while (0); + return -1; } @@ -293,45 +343,81 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie } while (0); } + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex matchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, after next:" PRId64 + ", " + "match:" PRId64 "", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, nextIndex, matchIndex); + syncNodeEventLog(ths, logBuf); + } while (0); + return 0; } int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) { int32_t ret = 0; - // print log - syncAppendEntriesReplyLog2("==syncNodeOnAppendEntriesReplySnapshotCb==", pMsg); - // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - syncNodeEventLog(ths, "recv sync-append-entries-reply, maybe replica already dropped"); - return 0; + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, maybe replica " + "already dropped", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeErrorLog(ths, logBuf); + } while (0); + + return -1; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, recv-term:%" PRIu64 ", drop stale response", - pMsg->term); - syncNodeEventLog(ths, logBuf); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, drop stale response", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeEventLog(ths, logBuf); + } while (0); + return 0; } - if (gRaftDetailLog) { - syncNodeEventLog(ths, "recv sync-append-entries-reply, before"); - } - syncIndexMgrLog2("recv sync-append-entries-reply, before pNextIndex:", ths->pNextIndex); - syncIndexMgrLog2("recv sync-append-entries-reply, before pMatchIndex:", ths->pMatchIndex); - // no need this code, because if I receive reply.term, then I must have sent for that term. // if (pMsg->term > ths->pRaftStore->currentTerm) { // syncNodeUpdateTerm(ths, pMsg->term); // } if (pMsg->term > ths->pRaftStore->currentTerm) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-reply, error term, recv-term:%" PRIu64, pMsg->term); - syncNodeErrorLog(ths, logBuf); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, error term", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); + syncNodeErrorLog(ths, logBuf); + } while (0); + return -1; } @@ -404,11 +490,21 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries } } - if (gRaftDetailLog) { - syncNodeEventLog(ths, "recv sync-append-entries-reply, after"); - } - syncIndexMgrLog2("recv sync-append-entries-reply, after pNextIndex:", ths->pNextIndex); - syncIndexMgrLog2("recv sync-append-entries-reply, after pMatchIndex:", ths->pMatchIndex); + do { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex matchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, after next:" PRId64 + ", " + "match:" PRId64 "", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, nextIndex, matchIndex); + syncNodeEventLog(ths, logBuf); + } while (0); return 0; } \ No newline at end of file diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index d55a385bb8..c91fce57e3 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -1564,7 +1564,8 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { snprintf(logBuf, sizeof(logBuf), "%s", str); } // sDebug("%s", logBuf); - sInfo("%s", logBuf); + // sInfo("%s", logBuf); + sTrace("%s", logBuf); } else { int len = 256 + userStrLen; @@ -1586,7 +1587,8 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { snprintf(s, len, "%s", str); } // sDebug("%s", s); - sInfo("%s", s); + // sInfo("%s", s); + sTrace("%s", s); taosMemoryFree(s); } diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index 9f5cba6c66..e7fa757c36 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -108,10 +108,10 @@ int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) { cJSON *pRoot = cJSON_CreateObject(); char u64Buf[128] = {0}; - snprintf(u64Buf, sizeof(u64Buf), "%lu", pRaftStore->currentTerm); + snprintf(u64Buf, sizeof(u64Buf), "" PRIu64 "", pRaftStore->currentTerm); cJSON_AddStringToObject(pRoot, "current_term", u64Buf); - snprintf(u64Buf, sizeof(u64Buf), "%lu", pRaftStore->voteFor.addr); + snprintf(u64Buf, sizeof(u64Buf), "" PRIu64 "", pRaftStore->voteFor.addr); cJSON_AddStringToObject(pRoot, "vote_for_addr", u64Buf); cJSON_AddNumberToObject(pRoot, "vote_for_vgid", pRaftStore->voteFor.vgId); @@ -142,11 +142,11 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) { cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term"); ASSERT(cJSON_IsString(pCurrentTerm)); - sscanf(pCurrentTerm->valuestring, "%lu", &(pRaftStore->currentTerm)); + sscanf(pCurrentTerm->valuestring, "" PRIu64 "", &(pRaftStore->currentTerm)); cJSON *pVoteForAddr = cJSON_GetObjectItem(pRoot, "vote_for_addr"); ASSERT(cJSON_IsString(pVoteForAddr)); - sscanf(pVoteForAddr->valuestring, "%lu", &(pRaftStore->voteFor.addr)); + sscanf(pVoteForAddr->valuestring, "" PRIu64 "", &(pRaftStore->voteFor.addr)); cJSON *pVoteForVgid = cJSON_GetObjectItem(pRoot, "vote_for_vgid"); pRaftStore->voteFor.vgId = pVoteForVgid->valueint; @@ -188,11 +188,11 @@ cJSON *raftStore2Json(SRaftStore *pRaftStore) { cJSON *pRoot = cJSON_CreateObject(); if (pRaftStore != NULL) { - snprintf(u64buf, sizeof(u64buf), "%lu", pRaftStore->currentTerm); + snprintf(u64buf, sizeof(u64buf), "" PRIu64 "", pRaftStore->currentTerm); cJSON_AddStringToObject(pRoot, "currentTerm", u64buf); cJSON *pVoteFor = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%lu", pRaftStore->voteFor.addr); + snprintf(u64buf, sizeof(u64buf), "" PRIu64 "", pRaftStore->voteFor.addr); cJSON_AddStringToObject(pVoteFor, "addr", u64buf); { uint64_t u64 = pRaftStore->voteFor.addr; @@ -216,7 +216,7 @@ cJSON *raftStore2Json(SRaftStore *pRaftStore) { char *raftStore2Str(SRaftStore *pRaftStore) { cJSON *pJson = raftStore2Json(pRaftStore); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -224,25 +224,25 @@ char *raftStore2Str(SRaftStore *pRaftStore) { // for debug ------------------- void raftStorePrint(SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - printf("raftStorePrint | len:%lu | %s \n", strlen(serialized), serialized); + printf("raftStorePrint | len:" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftStorePrint2(char *s, SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - printf("raftStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized); + printf("raftStorePrint2 | len:" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftStoreLog(SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - sTrace("raftStoreLog | len:%lu | %s", strlen(serialized), serialized); + sTrace("raftStoreLog | len:" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void raftStoreLog2(char *s, SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - sTrace("raftStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized); + sTrace("raftStoreLog2 | len:" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 968026a3aa..c55b00003c 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -315,15 +315,18 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c int32_t ret = 0; do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", commit:%" PRId64 - ", " - "datalen:%d}", - pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, - pMsg->commitIndex, pMsg->dataLen); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", pterm:%" PRIu64 ", commit:%" PRId64 + ", " + "datalen:%d}", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, + pMsg->dataLen); + syncNodeEventLog(pSyncNode, logBuf); } while (0); SRpcMsg rpcMsg; @@ -335,13 +338,16 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c int32_t syncNodeAppendEntriesBatch(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntriesBatch* pMsg) { do { - char host[128]; + char host[64]; uint16_t port; syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - sDebug("vgId:%d, send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 - ", pre-term:%" PRIu64 ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, datacount:%d}", - pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, - pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, datacount:%d}", + pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, + pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount); + syncNodeEventLog(pSyncNode, logBuf); } while (0); SRpcMsg rpcMsg; From 736960e1d2d521682f5e6e981aebd8af10bca214 Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Wed, 20 Jul 2022 15:15:37 +0800 Subject: [PATCH 11/42] feat(stream): add log --- source/libs/executor/src/timewindowoperator.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index d206f56ec3..39c05e81bf 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -652,7 +652,7 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num void printDataBlock(SSDataBlock* pBlock, const char* flag) { if (!pBlock || pBlock->info.rows == 0) { - qDebug("======printDataBlock: Block is Null or Empty"); + qDebug("===stream===printDataBlock: Block is Null or Empty"); return; } char* pBuf = NULL; @@ -772,12 +772,6 @@ int32_t binarySearch(void* keyList, int num, TSKEY key, int order, __get_value_f return midPos; } -int64_t getReskey(void* data, int32_t index) { - SArray* res = (SArray*)data; - SResKeyPos* pos = taosArrayGetP(res, index); - return *(int64_t*)pos->key; -} - int32_t compareResKey(void* pKey, void* data, int32_t index) { SArray* res = (SArray*)data; SResKeyPos* pos = taosArrayGetP(res, index); @@ -1537,8 +1531,10 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); if (pInfo->binfo.pRes->info.rows == 0 || !hasDataInGroupInfo(&pInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; + qDebug("===stream===single interval is done"); freeAllPages(pInfo->pRecycledPages, pInfo->aggSup.pResultBuf); } + printDataBlock(pInfo->binfo.pRes, "single interval"); return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; } From aa02a56a98935e746e0b8edd2cb19d9b0dbb0160 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 16:14:55 +0800 Subject: [PATCH 12/42] test: restore 2.0 case --- tests/script/jenkins/basic.txt | 14 +- tests/script/tsim/parser/fill.sim | 126 ++++++++---------- tests/script/tsim/parser/fill_stb.sim | 3 +- tests/script/tsim/parser/fill_us.sim | 63 ++++----- tests/script/tsim/parser/first_last.sim | 6 +- tests/script/tsim/parser/first_last_query.sim | 22 ++- 6 files changed, 105 insertions(+), 129 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 98c5251ac5..655462d1cf 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -83,13 +83,13 @@ ./test.sh -f tsim/insert/update0.sim # ---- parser -./test.sh -f tsim/parser/alter.sim -# nojira ./test.sh -f tsim/parser/alter1.sim ./test.sh -f tsim/parser/alter__for_community_version.sim ./test.sh -f tsim/parser/alter_column.sim ./test.sh -f tsim/parser/alter_stable.sim -# jira ./test.sh -f tsim/parser/auto_create_tb.sim +./test.sh -f tsim/parser/alter.sim +# nojira ./test.sh -f tsim/parser/alter1.sim ./test.sh -f tsim/parser/auto_create_tb_drop_tb.sim +# jira ./test.sh -f tsim/parser/auto_create_tb.sim ./test.sh -f tsim/parser/between_and.sim ./test.sh -f tsim/parser/binary_escapeCharacter.sim # nojira ./test.sh -f tsim/parser/col_arithmetic_operation.sim @@ -104,10 +104,10 @@ ## ./test.sh -f tsim/parser/create_tb_with_tag_name.sim # ./test.sh -f tsim/parser/dbtbnameValidate.sim ##./test.sh -f tsim/parser/distinct.sim -# ./test.sh -f tsim/parser/fill.sim -# ./test.sh -f tsim/parser/fill_stb.sim -## ./test.sh -f tsim/parser/fill_us.sim -# ./test.sh -f tsim/parser/first_last.sim +./test.sh -f tsim/parser/fill_stb.sim +./test.sh -f tsim/parser/fill_us.sim +./test.sh -f tsim/parser/fill.sim +./test.sh -f tsim/parser/first_last.sim ./test.sh -f tsim/parser/fourArithmetic-basic.sim ## ./test.sh -f tsim/parser/function.sim ./test.sh -f tsim/parser/groupby-basic.sim diff --git a/tests/script/tsim/parser/fill.sim b/tests/script/tsim/parser/fill.sim index 642c7bd8d4..698314fa36 100644 --- a/tests/script/tsim/parser/fill.sim +++ b/tests/script/tsim/parser/fill.sim @@ -47,7 +47,7 @@ $tsu = $tsu + $ts0 ## fill syntax test # number of fill values exceeds number of selected columns -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $data11 != 6 then return -1 endi @@ -62,7 +62,7 @@ if $data14 != 6.000000000 then endi # number of fill values is smaller than number of selected columns -sql select max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) if $data11 != 6 then return -1 endi @@ -74,7 +74,7 @@ if $data13 != 6.00000 then endi # unspecified filling method -sql_error select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill (6, 6, 6, 6, 6) +sql_error select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill (6, 6, 6, 6, 6) ## constant fill test # count_with_fill @@ -114,7 +114,7 @@ endi # avg_with_fill print avg_with_constant_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -148,7 +148,7 @@ endi # max_with_fill print max_with_fill -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -182,7 +182,7 @@ endi # min_with_fill print min_with_fill -sql select min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -216,7 +216,7 @@ endi # first_with_fill print first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -305,7 +305,7 @@ endi # last_with_fill print last_with_fill -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -339,7 +339,7 @@ if $data81 != 4 then endi # fill_negative_values -sql select sum(c1), avg(c2), max(c3), min(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -1, -1, -1, -1, -1, -1, -1) +sql select _wstart, sum(c1), avg(c2), max(c3), min(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -1, -1, -1, -1, -1, -1, -1) if $rows != 9 then return -1 endi @@ -351,11 +351,11 @@ if $data11 != -1 then endi # fill_char_values_to_arithmetic_fields -sql_error select sum(c1), avg(c2), max(c3), min(c4), avg(c4), count(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c') +sql select sum(c1), avg(c2), max(c3), min(c4), avg(c4), count(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c') # fill_multiple_columns sql_error select sum(c1), avg(c2), min(c3), max(c4), count(c6), first(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99, 99, abc, abc) -sql select sum(c1), avg(c2), min(c3), max(c4) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99) +sql select _wstart, sum(c1), avg(c2), min(c3), max(c4) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99) if $rows != 9 then return -1 endi @@ -375,9 +375,12 @@ if $data08 != NCHAR then endi # fill_into_nonarithmetic_fieds -sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) -#if $data11 != 20000000 then -if $data11 != 1 then +print select _wstart, first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) +sql select _wstart, first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) +if $data01 != 1 then + return -1 +endi +if $data11 != NULL then return -1 endi @@ -387,48 +390,39 @@ sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $ sql select first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1') # fill quoted values into bool column will throw error unless the value is 'true' or 'false' Note:2018-10-24 # fill values into binary or nchar columns will be set to NULL automatically Note:2018-10-24 -sql_error select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1','1e1') +sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1','1e1') sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, true, true, true) sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true', 'true','true') # fill nonarithmetic values into arithmetic fields sql_error select count(*) where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, abc); -sql_error select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true'); +sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true'); -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); +print select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 1e1); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 1e1); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '10'); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '10'); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi - ## linear fill # feature currently switched off 2018/09/29 @@ -436,7 +430,7 @@ endi ## previous fill print fill(prev) -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -469,7 +463,7 @@ if $data81 != 1 then endi # avg_with_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -502,7 +496,7 @@ if $data81 != 4.000000000 then endi # max_with_fill -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -535,7 +529,7 @@ if $data81 != 4 then endi # min_with_fill -sql select min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -568,7 +562,7 @@ if $data81 != 4 then endi # first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -601,7 +595,7 @@ if $data81 != 4 then endi # last_with_fill -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -636,9 +630,9 @@ endi ## NULL fill print fill(value, NULL) # count_with_fill -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) -print select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) +print select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -669,13 +663,13 @@ endi if $data81 != 1 then return -1 endi -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(none) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(none) if $rows != 5 then return -1 endi # avg_with_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -708,7 +702,7 @@ if $data81 != 4.000000000 then endi # max_with_fill -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -741,7 +735,7 @@ if $data81 != 4 then endi # min_with_fill -sql select min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -774,7 +768,7 @@ if $data81 != 4 then endi # first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -807,7 +801,7 @@ if $data81 != 4 then endi # last_with_fill -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -841,7 +835,7 @@ endi # desc fill query print desc fill query -sql select count(*) from m_fl_tb0 where ts>='2018-9-17 9:0:0' and ts<='2018-9-17 9:11:00' interval(1m) fill(value,10) order by ts desc; +sql select count(*) from m_fl_tb0 where ts>='2018-9-17 9:0:0' and ts<='2018-9-17 9:11:00' interval(1m) fill(value,10); if $rows != 12 then return -1 endi @@ -865,7 +859,8 @@ sql insert into tm0 values('2020-1-1 1:3:8', 8); sql insert into tm0 values('2020-1-1 1:3:9', 9); sql insert into tm0 values('2020-1-1 1:4:10', 10); -sql select max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85); +print select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85); +sql select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85); if $rows != 8 then return -1 endi @@ -890,15 +885,15 @@ if $data10 != @20-01-01 01:01:10.000@ then return -1 endi -if $data11 != 99.000000000 then +if $data11 != 1.000000000 then return -1 endi -if $data12 != 91.000000000 then +if $data12 != 1.000000000 then return -1 endi -if $data13 != 90.000000000 then +if $data13 != -87.000000000 then return -1 endi @@ -922,19 +917,19 @@ if $data70 != @20-01-01 01:02:10.000@ then return -1 endi -if $data71 != 99.000000000 then +if $data71 != 1.000000000 then return -1 endi -if $data72 != 91.000000000 then +if $data72 != 1.000000000 then return -1 endi -if $data73 != 90.000000000 then +if $data73 != -87.000000000 then return -1 endi -sql select first(k)-avg(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(NULL); +sql select _wstart, first(k)-avg(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(NULL); if $rows != 8 then return -1 endi @@ -963,12 +958,13 @@ if $data12 != NULL then return -1 endi -sql select max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 4:2:15' interval(500a) fill(value, 99,91,90,89,88,87,86,85) order by ts asc; +sql select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k) from tm0 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 4:2:15' interval(500a) fill(value, 99,91,90,89,88,87,86,85) ; if $rows != 21749 then return -1 endi -sql select max(k)-min(k),last(k)-first(k),0-spread(k),count(1) from m1 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85) order by ts asc; +print select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k),count(1) from m1 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85) ; +sql select _wstart, max(k)-min(k),last(k)-first(k),0-spread(k),count(1) from m1 where ts>='2020-1-1 1:1:1' and ts<='2020-1-1 1:2:15' interval(10s) fill(value, 99,91,90,89,88,87,86,85) ; if $rows != 8 then return -1 endi @@ -997,19 +993,19 @@ if $data10 != @20-01-01 01:01:10.000@ then return -1 endi -if $data11 != 99.000000000 then +if $data11 != 1.000000000 then return -1 endi -if $data12 != 91.000000000 then +if $data12 != 1.000000000 then return -1 endi -if $data13 != 90.000000000 then +if $data13 != -87.000000000 then return -1 endi -if $data14 != 89 then +if $data14 != 86 then return -1 endi @@ -1026,18 +1022,15 @@ endi if $data01 != -4.000000000 then return -1 endi - -if $data02 != 0 then +if $data10 != 5 then return -1 endi - -if $data12 != 1 then +if $data11 != -4.000000000 then return -1 endi print =====================>td-1442, td-2190 , no time range for fill option sql_error select count(*) from m_fl_tb0 interval(1s) fill(prev); - sql_error select min(c3) from m_fl_mt0 interval(10a) fill(value, 20) sql_error select min(c3) from m_fl_mt0 interval(10s) fill(value, 20) sql_error select min(c3) from m_fl_mt0 interval(10m) fill(value, 20) @@ -1051,7 +1044,7 @@ sql create table nexttb1 (ts timestamp, f1 int); sql insert into nexttb1 values ('2021-08-08 1:1:1', NULL); sql insert into nexttb1 values ('2021-08-08 1:1:5', 3); -sql select last(*) from nexttb1 where ts >= '2021-08-08 1:1:1' and ts < '2021-08-08 1:1:10' interval(1s) fill(next); +sql select _wstart, last(*) from nexttb1 where ts >= '2021-08-08 1:1:1' and ts < '2021-08-08 1:1:10' interval(1s) fill(next); if $rows != 9 then return -1 endi @@ -1065,9 +1058,6 @@ if $data02 != 3 then return -1 endi - - - print =============== clear #sql drop database $db #sql show databases diff --git a/tests/script/tsim/parser/fill_stb.sim b/tests/script/tsim/parser/fill_stb.sim index 0aadcc5a9f..5493843993 100644 --- a/tests/script/tsim/parser/fill_stb.sim +++ b/tests/script/tsim/parser/fill_stb.sim @@ -97,7 +97,8 @@ $tsu = $tsu + $ts0 #endi # number of fill values exceeds number of selected columns -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) +print select count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) +sql select count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) $val = $rowNum * 2 $val = $val - 1 if $rows != $val then diff --git a/tests/script/tsim/parser/fill_us.sim b/tests/script/tsim/parser/fill_us.sim index 98c37c435d..82d282642e 100644 --- a/tests/script/tsim/parser/fill_us.sim +++ b/tests/script/tsim/parser/fill_us.sim @@ -47,8 +47,8 @@ $tsu = $tsu + $ts0 ## fill syntax test # number of fill values exceeds number of selected columns -print select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +print select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $data11 != 6 then return -1 endi @@ -63,8 +63,8 @@ if $data14 != 6.000000000 then endi # number of fill values is smaller than number of selected columns -print sql select max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) -sql select max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) +print sql select _wstart, max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) +sql select _wstart, max(c1), max(c2), max(c3) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6) if $data11 != 6 then return -1 endi @@ -219,7 +219,7 @@ endi # first_with_fill print first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 6, 6, 6, 6, 6, 6, 6, 6) if $rows != 9 then return -1 endi @@ -341,7 +341,7 @@ if $data81 != 4 then endi # fill_negative_values -sql select sum(c1), avg(c2), max(c3), min(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -1, -1, -1, -1, -1, -1, -1) +sql select _wstart, sum(c1), avg(c2), max(c3), min(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -1, -1, -1, -1, -1, -1, -1) if $rows != 9 then return -1 endi @@ -353,11 +353,11 @@ if $data11 != -1 then endi # fill_char_values_to_arithmetic_fields -sql_error select sum(c1), avg(c2), max(c3), min(c4), avg(c4), count(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c') +sql select sum(c1), avg(c2), max(c3), min(c4), avg(c4), count(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c') # fill_multiple_columns -sql_error select sum(c1), avg(c2), min(c3), max(c4), count(c6), first(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99, 99, abc, abc) -sql select sum(c1), avg(c2), min(c3), max(c4) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99) +sql_error select _wstart, sum(c1), avg(c2), min(c3), max(c4), count(c6), first(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99, 99, abc, abc) +sql select _wstart, sum(c1), avg(c2), min(c3), max(c4) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 99, 99, 99, 99) if $rows != 9 then return -1 endi @@ -379,9 +379,9 @@ endi # fill_into_nonarithmetic_fieds -sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) +sql select _wstart, first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 20000000, 20000000, 20000000) #if $data11 != 20000000 then -if $data11 != 1 then +if $data11 != NULL then return -1 endi @@ -391,47 +391,38 @@ sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $ sql select first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1') # fill quoted values into bool column will throw error unless the value is 'true' or 'false' Note:2018-10-24 # fill values into binary or nchar columns will be set to null automatically Note:2018-10-24 -sql_error select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1','1e1') +sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e', '1e1','1e1') sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, true, true, true) sql select first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true', 'true','true') # fill nonarithmetic values into arithmetic fields sql_error select count(*) where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, abc); -sql_error select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true'); +sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 'true'); -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '1e1'); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 1e1); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, 1e1); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi -sql select count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '10'); +sql select _wstart, count(*) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, '10'); if $rows != 9 then return -1 endi if $data01 != 1 then return -1 endi -if $data11 != 10 then - return -1 -endi ## linear fill @@ -440,7 +431,7 @@ endi ## previous fill print fill(prev) -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -473,7 +464,7 @@ if $data81 != 1 then endi # avg_with_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(prev) if $rows != 9 then return -1 endi @@ -641,8 +632,8 @@ endi print fill(value, NULL) # count_with_fill sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) -print select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) -sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +print select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) +sql select _wstart, count(c1), count(c2), count(c3), count(c4), count(c5), count(c6), count(c7), count(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -679,7 +670,7 @@ if $rows != 5 then endi # avg_with_fill -sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, avg(c1), avg(c2), avg(c3), avg(c4), avg(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -712,7 +703,7 @@ if $data81 != 4.000000000 then endi # max_with_fill -sql select max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, max(c1), max(c2), max(c3), max(c4), max(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -745,7 +736,7 @@ if $data81 != 4 then endi # min_with_fill -sql select min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, min(c1), min(c2), min(c3), min(c4), min(c5) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -778,7 +769,7 @@ if $data81 != 4 then endi # first_with_fill -sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, first(c1), first(c2), first(c3), first(c4), first(c5), first(c6), first(c7), first(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill( NULL) if $rows != 9 then return -1 endi @@ -811,7 +802,7 @@ if $data81 != 4 then endi # last_with_fill -sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, NULL) +sql select _wstart, last(c1), last(c2), last(c3), last(c4), last(c5), last(c6), last(c7), last(c8) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) fill(NULL) if $rows != 9 then return -1 endi @@ -845,7 +836,7 @@ endi # desc fill query print desc fill query -sql select count(*) from m_fl_tb0 where ts>='2018-9-17 9:0:0' and ts<='2018-9-17 9:11:00' interval(1m) fill(value,10) order by ts desc; +sql select count(*) from m_fl_tb0 where ts>='2018-9-17 9:0:0' and ts<='2018-9-17 9:11:00' interval(1m) fill(value,10); if $rows != 12 then return -1 endi @@ -1002,7 +993,7 @@ if $data71 != 21.000000000 then return -1 endi -sql select avg(c1), avg(c2) from us_t1 where ts >= '2018-09-17 09:00:00.000002' and ts <= '2018-09-17 09:00:00.000021' interval(3u) fill(linear) +sql select _wstart, avg(c1), avg(c2) from us_t1 where ts >= '2018-09-17 09:00:00.000002' and ts <= '2018-09-17 09:00:00.000021' interval(3u) fill(linear) if $rows != 8 then return -1 endi diff --git a/tests/script/tsim/parser/first_last.sim b/tests/script/tsim/parser/first_last.sim index 27bf42ead3..4f1dcb12fe 100644 --- a/tests/script/tsim/parser/first_last.sim +++ b/tests/script/tsim/parser/first_last.sim @@ -19,7 +19,7 @@ $stb = $stbPrefix . $i sql drop database $db -x step1 step1: -sql create database $db maxrows 400 cache 1 +sql create database $db maxrows 400 sql use $db sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 int) @@ -73,11 +73,9 @@ run tsim/parser/first_last_query.sim print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 500 system sh/exec.sh -n dnode1 -s start print ================== server restart completed sql connect -sleep 100 run tsim/parser/first_last_query.sim @@ -102,11 +100,9 @@ while $x < 5000 endw system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 1000 system sh/exec.sh -n dnode1 -s start print ================== server restart completed sql connect -sleep 100 sql use test sql select count(*), last(ts) from tm0 interval(1s) diff --git a/tests/script/tsim/parser/first_last_query.sim b/tests/script/tsim/parser/first_last_query.sim index 2dff1dd51b..c52a5b45d6 100644 --- a/tests/script/tsim/parser/first_last_query.sim +++ b/tests/script/tsim/parser/first_last_query.sim @@ -109,7 +109,7 @@ endi ### test if first works for committed data. An 'order by ts desc' clause should be present, and queried data should come from at least 2 file blocks $tb = $tbPrefix . 9 -sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' order by ts asc +sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' if $rows != 1 then return -1 endi @@ -121,7 +121,7 @@ if $data01 != 0 then endi $tb = $tbPrefix . 9 -sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' order by ts desc +sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' if $rows != 1 then return -1 endi @@ -154,7 +154,7 @@ sql insert into test11 using stest tags('test11','bbb') values ('2020-09-04 16:5 sql insert into test12 using stest tags('test11','bbb') values ('2020-09-04 16:53:58.003',210,3); sql insert into test21 using stest tags('test21','ccc') values ('2020-09-04 16:53:59.003',210,3); sql insert into test22 using stest tags('test21','ccc') values ('2020-09-04 16:54:54.003',210,3); -sql select sum(size) from stest group by appname; +sql select sum(size), appname from stest group by appname order by appname;; if $rows != 3 then return -1 endi @@ -170,16 +170,16 @@ if $data20 != 420 then endi if $data01 != @test1@ then -return -1 + return -1 endi if $data11 != @test11@ then -return -1 + return -1 endi if $data21 != @test21@ then -return -1 + return -1 endi -sql select sum(size) from stest interval(1d) group by appname; +sql select _wstart, sum(size), appname from stest partition by appname interval(1d) order by appname; if $rows != 3 then return -1 endi @@ -223,7 +223,7 @@ return -1 endi print ===================>td-1477, one table has only one block occurs this bug. -sql select first(size),count(*),LAST(SIZE) from stest where tbname in ('test1', 'test2') interval(1d) group by tbname; +sql select _wstart, first(size), count(*), LAST(SIZE), tbname from stest where tbname in ('test1', 'test2') partition by tbname interval(1d) ; if $rows != 2 then return -1 endi @@ -278,15 +278,13 @@ sql create table tm1 using m1 tags(2); sql insert into tm0 values('2020-3-1 1:1:1', 112); sql insert into tm1 values('2020-1-1 1:1:1', 1)('2020-3-1 0:1:1', 421); system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 1000 - system sh/exec.sh -n dnode1 -s start + print ================== server restart completed -sleep 1000 sql connect sql use first_db0; -sql select last(*) from m1 group by tbname; +sql select last(*), tbname from m1 group by tbname; if $rows != 2 then return -1 endi From e9c408df6ba13419c3ee0fd62da8c3a35e4a4073 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 16:15:14 +0800 Subject: [PATCH 13/42] fix: return error on child script failed --- tests/tsim/src/simSystem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index 1c751f290a..f2fefb903d 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -99,6 +99,7 @@ SScript *simProcessCallOver(SScript *script) { } if (simScriptPos == -1) return NULL; + if (!simExecSuccess) return NULL; return simScriptList[simScriptPos]; } else { From bf37f3fa68790431e1c58cf1d1649b3d8ab0cb86 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 20 Jul 2022 16:15:53 +0800 Subject: [PATCH 14/42] feat(wal): remove wal log size limitation --- include/libs/wal/wal.h | 20 +++++----- include/util/tdef.h | 2 +- include/util/tutil.h | 1 - source/common/src/tglobal.c | 24 +++++------ source/common/src/tmsg.c | 2 + source/dnode/mnode/sdb/src/sdbFile.c | 9 +++-- source/libs/wal/src/walMeta.c | 60 +++++++++++++++++++--------- source/libs/wal/src/walWrite.c | 9 ----- source/util/src/tutil.c | 14 ------- 9 files changed, 72 insertions(+), 69 deletions(-) diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 00a36391fa..ad89e51a24 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -33,16 +33,16 @@ extern "C" { #define wTrace(...) { if (wDebugFlag & DEBUG_TRACE) { taosPrintLog("WAL ", DEBUG_TRACE, wDebugFlag, __VA_ARGS__); }} // clang-format on -#define WAL_PROTO_VER 0 -#define WAL_NOSUFFIX_LEN 20 -#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1) -#define WAL_LOG_SUFFIX "log" -#define WAL_INDEX_SUFFIX "idx" -#define WAL_REFRESH_MS 1000 -#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalCkHead)) -#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12) -#define WAL_FILE_LEN (WAL_PATH_LEN + 32) -#define WAL_MAGIC 0xFAFBFCFDULL +#define WAL_PROTO_VER 0 +#define WAL_NOSUFFIX_LEN 20 +#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1) +#define WAL_LOG_SUFFIX "log" +#define WAL_INDEX_SUFFIX "idx" +#define WAL_REFRESH_MS 1000 +#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12) +#define WAL_FILE_LEN (WAL_PATH_LEN + 32) +#define WAL_MAGIC 0xFAFBFCFDULL +#define WAL_SCAN_BUF_SIZE (1024 * 1024 * 3) typedef enum { TAOS_WAL_WRITE = 1, diff --git a/include/util/tdef.h b/include/util/tdef.h index 3b31398063..688fe5fe85 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -421,7 +421,7 @@ typedef enum ELogicConditionType { #define TSDB_DEFAULT_STABLES_HASH_SIZE 100 #define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000 -#define TSDB_MAX_WAL_SIZE (1024 * 1024 * 3) +#define TSDB_MAX_MSG_SIZE (1024 * 1024 * 10) #define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P diff --git a/include/util/tutil.h b/include/util/tutil.h index 2e96c5b88e..6a1a40f14c 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -45,7 +45,6 @@ void taosIp2String(uint32_t ip, char *str); void taosIpPort2String(uint32_t ip, uint16_t port, char *str); void *tmemmem(const char *haystack, int hlen, const char *needle, int nlen); -char *strDupUnquo(const char *src); static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *target) { T_MD5_CTX context; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index fcc27e440c..db8afba409 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -40,11 +40,11 @@ bool tsPrintAuth = false; // multi process int32_t tsMultiProcess = 0; -int32_t tsMnodeShmSize = TSDB_MAX_WAL_SIZE * 2 + 1024; -int32_t tsVnodeShmSize = TSDB_MAX_WAL_SIZE * 10 + 1024; -int32_t tsQnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024; -int32_t tsSnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024; -int32_t tsBnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024; +int32_t tsMnodeShmSize = TSDB_MAX_MSG_SIZE * 2 + 1024; +int32_t tsVnodeShmSize = TSDB_MAX_MSG_SIZE * 10 + 1024; +int32_t tsQnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024; +int32_t tsSnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024; +int32_t tsBnodeShmSize = TSDB_MAX_MSG_SIZE * 4 + 1024; int32_t tsNumOfShmThreads = 1; // queue & threads @@ -387,11 +387,11 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1; if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "vnodeShmSize", tsVnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "qnodeShmSize", tsQnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "snodeShmSize", tsSnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "bnodeShmSize", tsBnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "vnodeShmSize", tsVnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "qnodeShmSize", tsQnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "snodeShmSize", tsSnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "bnodeShmSize", tsBnodeShmSize, TSDB_MAX_MSG_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1; if (cfgAddInt32(pCfg, "mumOfShmThreads", tsNumOfShmThreads, 1, 1024, 0) != 0) return -1; tsNumOfRpcThreads = tsNumOfCores / 2; @@ -447,8 +447,8 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "numOfSnodeUniqueThreads", tsNumOfSnodeUniqueThreads, 1, 1024, 0) != 0) return -1; tsRpcQueueMemoryAllowed = tsTotalMemoryKB * 1024 * 0.1; - tsRpcQueueMemoryAllowed = TRANGE(tsRpcQueueMemoryAllowed, TSDB_MAX_WAL_SIZE * 10L, TSDB_MAX_WAL_SIZE * 10000L); - if (cfgAddInt64(pCfg, "rpcQueueMemoryAllowed", tsRpcQueueMemoryAllowed, TSDB_MAX_WAL_SIZE * 10L, INT64_MAX, 0) != 0) + tsRpcQueueMemoryAllowed = TRANGE(tsRpcQueueMemoryAllowed, TSDB_MAX_MSG_SIZE * 10L, TSDB_MAX_MSG_SIZE * 10000L); + if (cfgAddInt64(pCfg, "rpcQueueMemoryAllowed", tsRpcQueueMemoryAllowed, TSDB_MAX_MSG_SIZE * 10L, INT64_MAX, 0) != 0) return -1; if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b79c412914..2a4ad04c63 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5342,6 +5342,7 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { if (tEncodeCStr(pEncoder, pReq->tbName) < 0) return -1; if (tEncodeI8(pEncoder, pReq->action) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->colId) < 0) return -1; switch (pReq->action) { case TSDB_ALTER_TABLE_ADD_COLUMN: if (tEncodeCStr(pEncoder, pReq->colName) < 0) return -1; @@ -5392,6 +5393,7 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) { if (tDecodeCStr(pDecoder, &pReq->tbName) < 0) return -1; if (tDecodeI8(pDecoder, &pReq->action) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->colId) < 0) return -1; switch (pReq->action) { case TSDB_ALTER_TABLE_ADD_COLUMN: if (tDecodeCStr(pDecoder, &pReq->colName) < 0) return -1; diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 302f0c5fbb..00659939e9 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -231,7 +231,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { snprintf(file, sizeof(file), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); mDebug("start to read sdb file:%s", file); - SSdbRaw *pRaw = taosMemoryMalloc(WAL_MAX_SIZE + 100); + SSdbRaw *pRaw = taosMemoryMalloc(TSDB_MAX_MSG_SIZE + 100); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; mError("failed read sdb file since %s", terrstr()); @@ -556,8 +556,9 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter if (term != NULL) *term = commitTerm; if (config != NULL) *config = commitConfig; - mDebug("sdbiter:%p, is created to read snapshot, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64 " file:%s", - pIter, commitIndex, commitTerm, commitConfig, pIter->name); + mDebug("sdbiter:%p, is created to read snapshot, commit index:%" PRId64 " term:%" PRId64 " config:%" PRId64 + " file:%s", + pIter, commitIndex, commitTerm, commitConfig, pIter->name); return 0; } @@ -669,4 +670,4 @@ int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) { pIter->total += writelen; mDebug("sdbiter:%p, write:%d bytes to snapshot, total:%" PRId64, pIter, writelen, pIter->total); return 0; -} \ No newline at end of file +} diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index edc811fe82..84e5a58c1a 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -40,7 +40,6 @@ static FORCE_INLINE int walBuildMetaName(SWal* pWal, int metaVer, char* buf) { } static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { - ASSERT(pWal->fileInfoSet != NULL); int32_t sz = taosArrayGetSize(pWal->fileInfoSet); ASSERT(sz > 0); #if 0 @@ -55,7 +54,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { int64_t fileSize = 0; taosStatFile(fnameStr, &fileSize, NULL); - int readSize = TMIN(WAL_MAX_SIZE + 2, fileSize); + int32_t readSize = TMIN(WAL_SCAN_BUF_SIZE, fileSize); pLastFileInfo->fileSize = fileSize; TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); @@ -73,7 +72,8 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { return -1; } - taosLSeekFile(pFile, -readSize, SEEK_END); + int64_t offset; + offset = taosLSeekFile(pFile, -readSize, SEEK_END); if (readSize != taosReadFile(pFile, buf, readSize)) { taosMemoryFree(buf); taosCloseFile(&pFile); @@ -81,29 +81,53 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { return -1; } - char* haystack = buf; char* found = NULL; - char* candidate; - while ((candidate = tmemmem(haystack, readSize - (haystack - buf), (char*)&magic, sizeof(uint64_t))) != NULL) { - // read and validate - SWalCkHead* logContent = (SWalCkHead*)candidate; - if (walValidHeadCksum(logContent) == 0 && walValidBodyCksum(logContent) == 0) { - found = candidate; + while (1) { + char* haystack = buf; + char* candidate; + while ((candidate = tmemmem(haystack, readSize - (haystack - buf), (char*)&magic, sizeof(uint64_t))) != NULL) { + // read and validate + SWalCkHead* logContent = (SWalCkHead*)candidate; + if (walValidHeadCksum(logContent) == 0 && walValidBodyCksum(logContent) == 0) { + found = candidate; + } + haystack = candidate + 1; } - haystack = candidate + 1; - } - if (found == buf) { - SWalCkHead* logContent = (SWalCkHead*)found; - if (walValidHeadCksum(logContent) != 0 || walValidBodyCksum(logContent) != 0) { - // file has to be deleted + if (found || offset == 0) break; + offset = TMIN(0, offset - readSize + 8); + int64_t offset2 = taosLSeekFile(pFile, offset, SEEK_SET); + ASSERT(offset == offset2); + if (readSize != taosReadFile(pFile, buf, readSize)) { taosMemoryFree(buf); taosCloseFile(&pFile); - terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } +#if 0 + if (found == buf) { + SWalCkHead* logContent = (SWalCkHead*)found; + if (walValidHeadCksum(logContent) != 0 || walValidBodyCksum(logContent) != 0) { + // file has to be deleted + taosMemoryFree(buf); + taosCloseFile(&pFile); + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + return -1; + } + } +#endif + } + // TODO truncate file + + if (found == NULL) { + // file corrupted, no complete log + // TODO delete and search in previous files + ASSERT(0); + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + return -1; } - taosCloseFile(&pFile); SWalCkHead* lastEntry = (SWalCkHead*)found; + taosCloseFile(&pFile); + taosMemoryFree(buf); return lastEntry->head.version; } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 4fc135a1cf..d6348cc5dd 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -436,11 +436,6 @@ END: } int64_t walAppendLog(SWal *pWal, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen) { - if (bodyLen > TSDB_MAX_WAL_SIZE) { - terrno = TSDB_CODE_WAL_SIZE_LIMIT; - return -1; - } - taosThreadMutexLock(&pWal->mutex); int64_t index = pWal->vers.lastVer + 1; @@ -472,10 +467,6 @@ int32_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SWalSync int32_t bodyLen) { int32_t code = 0; - if (bodyLen > TSDB_MAX_WAL_SIZE) { - terrno = TSDB_CODE_WAL_SIZE_LIMIT; - return -1; - } taosThreadMutexLock(&pWal->mutex); // concurrency control: diff --git a/source/util/src/tutil.c b/source/util/src/tutil.c index 7f3728e2ad..addb9f55ba 100644 --- a/source/util/src/tutil.c +++ b/source/util/src/tutil.c @@ -64,20 +64,6 @@ int32_t strdequote(char *z) { return j + 1; // only one quote, do nothing } -char *strDupUnquo(const char *src) { - if (src == NULL) return NULL; - if (src[0] != '`') return strdup(src); - int32_t len = (int32_t)strlen(src); - if (src[len - 1] != '`') return NULL; - char *ret = taosMemoryMalloc(len); - if (ret == NULL) return NULL; - for (int32_t i = 0; i < len - 1; i++) { - ret[i] = src[i + 1]; - } - ret[len - 1] = 0; - return ret; -} - size_t strtrim(char *z) { int32_t i = 0; int32_t j = 0; From 9bff316f1257c48982e33c6154b4f2ad394a371d Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 16:19:25 +0800 Subject: [PATCH 15/42] os: fix win timestamp convert error --- source/os/src/osTime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/os/src/osTime.c b/source/os/src/osTime.c index 0cb4228e42..3c81ba3d9f 100644 --- a/source/os/src/osTime.c +++ b/source/os/src/osTime.c @@ -371,7 +371,7 @@ time_t taosMktime(struct tm *timep) { localtime_s(&tm1, &tt); ss.wYear = tm1.tm_year + 1900; ss.wMonth = tm1.tm_mon + 1; - ss.wDay = tm1.tm_wday; + ss.wDay = tm1.tm_mday; ss.wHour = tm1.tm_hour; ss.wMinute = tm1.tm_min; ss.wSecond = tm1.tm_sec; @@ -383,7 +383,7 @@ time_t taosMktime(struct tm *timep) { s.wYear = timep->tm_year + 1900; s.wMonth = timep->tm_mon + 1; - s.wDay = timep->tm_wday; + s.wDay = timep->tm_mday; s.wHour = timep->tm_hour; s.wMinute = timep->tm_min; s.wSecond = timep->tm_sec; From b74560537cef613e234ccace9883e4e2e46a2bfc Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 20 Jul 2022 16:25:20 +0800 Subject: [PATCH 16/42] fix(stream): check task exist --- source/dnode/vnode/src/tq/tq.c | 60 ++++++++++++++++++---------------- source/libs/wal/src/walMeta.c | 2 +- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index f6862621f9..208b5d3fa0 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -506,7 +506,8 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { .initTqReader = true, .version = ver, }; - pHandle->execHandle.execCol.task[i] = qCreateQueueExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle, &pHandle->execHandle.numOfCols); + pHandle->execHandle.execCol.task[i] = + qCreateQueueExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle, &pHandle->execHandle.numOfCols); ASSERT(pHandle->execHandle.execCol.task[i]); void* scanner = NULL; qExtractStreamScanner(pHandle->execHandle.execCol.task[i], &scanner); @@ -679,9 +680,9 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) { // SStreamTaskRunReq* pReq = pMsg->pCont; int32_t taskId = pReq->taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { - streamProcessRunReq(pTask); + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + streamProcessRunReq(*ppTask); return 0; } else { return -1; @@ -696,14 +697,14 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg) { SDecoder decoder; tDecoderInit(&decoder, msgBody, msgLen); tDecodeStreamDispatchReq(&decoder, &req); - int32_t taskId = req.taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { + int32_t taskId = req.taskId; + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { SRpcMsg rsp = { .info = pMsg->info, .code = 0, }; - streamProcessDispatchReq(pTask, &req, &rsp); + streamProcessDispatchReq(*ppTask, &req, &rsp); return 0; } else { return -1; @@ -713,9 +714,9 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) { SStreamTaskRecoverReq* pReq = pMsg->pCont; int32_t taskId = pReq->taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { - streamProcessRecoverReq(pTask, pReq, pMsg); + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + streamProcessRecoverReq(*ppTask, pReq, pMsg); return 0; } else { return -1; @@ -725,9 +726,9 @@ int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) { SStreamDispatchRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); int32_t taskId = pRsp->taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { - streamProcessDispatchRsp(pTask, pRsp); + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + streamProcessDispatchRsp(*ppTask, pRsp); return 0; } else { return -1; @@ -737,9 +738,9 @@ int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) { SStreamTaskRecoverRsp* pRsp = pMsg->pCont; int32_t taskId = pRsp->taskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (pTask) { - streamProcessRecoverRsp(pTask, pRsp); + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + streamProcessRecoverRsp(*ppTask, pRsp); return 0; } else { return -1; @@ -749,10 +750,10 @@ int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskDropReq(STQ* pTq, char* msg, int32_t msgLen) { SVDropStreamTaskReq* pReq = (SVDropStreamTaskReq*)msg; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); - if (pTask) { + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); + if (ppTask) { taosHashRemove(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); - atomic_store_8(&pTask->taskStatus, TASK_STATUS__DROPPING); + atomic_store_8(&(*ppTask)->taskStatus, TASK_STATUS__DROPPING); } // todo // clear queue @@ -780,16 +781,17 @@ int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg) { SDecoder decoder; tDecoderInit(&decoder, msgBody, msgLen); tDecodeStreamRetrieveReq(&decoder, &req); - int32_t taskId = req.dstTaskId; - SStreamTask* pTask = *(SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); - if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { - return 0; + int32_t taskId = req.dstTaskId; + SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); + if (ppTask) { + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessRetrieveReq(*ppTask, &req, &rsp); + } else { + return -1; } - SRpcMsg rsp = { - .info = pMsg->info, - .code = 0, - }; - streamProcessRetrieveReq(pTask, &req, &rsp); return 0; } diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 84e5a58c1a..4bb6f07a47 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -94,7 +94,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { haystack = candidate + 1; } if (found || offset == 0) break; - offset = TMIN(0, offset - readSize + 8); + offset = TMIN(0, offset - readSize + sizeof(uint64_t)); int64_t offset2 = taosLSeekFile(pFile, offset, SEEK_SET); ASSERT(offset == offset2); if (readSize != taosReadFile(pFile, buf, readSize)) { From 5d20804e7670e5e55fce774ced1018665dc7969a Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 20 Jul 2022 17:10:41 +0800 Subject: [PATCH 17/42] fix(wal): use after free --- source/libs/wal/src/walMeta.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 4bb6f07a47..a5fd3fca35 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -126,10 +126,11 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) { return -1; } SWalCkHead* lastEntry = (SWalCkHead*)found; + int64_t retVer = lastEntry->head.version; taosCloseFile(&pFile); taosMemoryFree(buf); - return lastEntry->head.version; + return retVer; } int walCheckAndRepairMeta(SWal* pWal) { From 7808fdfccbfd98567e8cf69ae03905625b33093d Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 20 Jul 2022 17:19:42 +0800 Subject: [PATCH 18/42] refactor(sync): add trace log --- source/libs/sync/inc/syncInt.h | 16 + source/libs/sync/src/syncAppendEntries.c | 340 ++---------------- source/libs/sync/src/syncAppendEntriesReply.c | 186 ++-------- source/libs/sync/src/syncElection.c | 13 +- source/libs/sync/src/syncMain.c | 124 ++++++- source/libs/sync/src/syncReplication.c | 29 +- source/libs/sync/src/syncRequestVote.c | 52 +-- source/libs/sync/src/syncRequestVoteReply.c | 76 +--- 8 files changed, 229 insertions(+), 607 deletions(-) diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index 3a30cf801e..64f66e390a 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -257,6 +257,22 @@ int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode); int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader); int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry); +// trace log +void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s); +void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s); + +void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s); +void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s); + +void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s); +void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s); + +void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s); +void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s); + +void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s); +void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s); + // for debug -------------- void syncNodePrint(SSyncNode* pObj); void syncNodePrint2(char* s, SSyncNode* pObj); diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 0e26d1ea65..50c66172da 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -94,21 +94,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, maybe replica already dropped", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeErrorLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntries(ths, pMsg, "maybe replica already dropped"); return -1; } @@ -125,30 +111,12 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { } ASSERT(pMsg->dataLen >= 0); - do { - // return to follower state - if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, candidate to follower", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeEventLog(ths, logBuf); - } while (0); - - syncNodeBecomeFollower(ths, "from candidate by append entries"); - - // ret or reply? - return -1; - } - } while (0); + // return to follower state + if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) { + syncLogRecvAppendEntries(ths, pMsg, "candidate to follower"); + syncNodeBecomeFollower(ths, "from candidate by append entries"); + return -1; // ret or reply? + } SyncTerm localPreLogTerm = 0; if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) { @@ -172,20 +140,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // reject request if ((pMsg->term < ths->pRaftStore->currentTerm) || ((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, reject", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogRecvAppendEntries(ths, pMsg, "reject"); SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); pReply->srcId = ths->myRaftId; @@ -195,17 +150,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { pReply->matchIndex = SYNC_INDEX_INVALID; // msg event log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogSendAppendEntriesReply(ths, pReply, ""); SRpcMsg rpcMsg; syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); @@ -226,20 +171,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { // has entries in SyncAppendEntries msg bool hasAppendEntries = pMsg->dataLen > 0; - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, accept", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogRecvAppendEntries(ths, pMsg, "accept"); if (hasExtraEntries && hasAppendEntries) { // not conflict by default @@ -389,17 +321,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { } // msg event log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogSendAppendEntriesReply(ths, pReply, ""); SRpcMsg rpcMsg; syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg); @@ -602,22 +524,8 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "count:%d}, maybe replica already dropped", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataCount); - syncNodeErrorLog(ths, logBuf); - } while (0); - - return ret; + syncLogRecvAppendEntriesBatch(ths, pMsg, "maybe replica already dropped"); + return -1; } // maybe update term @@ -640,28 +548,13 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc do { bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE; if (condition) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "count:%d}, candidate to follower", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataCount); - syncNodeEventLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesBatch(ths, pMsg, "candidate to follower"); syncNodeBecomeFollower(ths, "from candidate by append entries"); - // do not reply? - return ret; + return 0; // do not reply? } } while (0); - // fake match2 + // fake match // // condition1: // preIndex <= my commit index @@ -673,20 +566,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && (pMsg->prevLogIndex <= ths->commitIndex); if (condition) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "count:%d}, fake match2", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataCount); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogRecvAppendEntriesBatch(ths, pMsg, "fake match"); SyncIndex matchIndex = ths->commitIndex; bool hasAppendEntries = pMsg->dataLen > 0; @@ -739,17 +619,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc pReply->matchIndex = matchIndex; // msg event log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogSendAppendEntriesReply(ths, pReply, ""); // send response SRpcMsg rpcMsg; @@ -782,20 +652,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc bool condition = condition1 || condition2; if (condition) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "count:%d}, not match", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataCount); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogRecvAppendEntriesBatch(ths, pMsg, "not match"); // maybe update commit index by snapshot syncNodeMaybeUpdateCommitBySnapshot(ths); @@ -810,17 +667,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc pReply->matchIndex = ths->commitIndex; // msg event log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogSendAppendEntriesReply(ths, pReply, ""); // send response SRpcMsg rpcMsg; @@ -851,20 +698,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc bool hasAppendEntries = pMsg->dataLen > 0; SOffsetAndContLen* metaTableArr = syncAppendEntriesBatchMetaTableArray(pMsg); - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "count:%d}, match", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataCount); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogRecvAppendEntriesBatch(ths, pMsg, "really match"); if (hasExtraEntries) { // make log same, rollback deleted entries @@ -903,17 +737,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc pReply->matchIndex = hasAppendEntries ? pMsg->prevLogIndex + pMsg->dataCount : pMsg->prevLogIndex; // msg event log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogSendAppendEntriesReply(ths, pReply, ""); // send response SRpcMsg rpcMsg; @@ -966,22 +790,8 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, maybe replica dropped", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeErrorLog(ths, logBuf); - } while (0); - - return ret; + syncLogRecvAppendEntries(ths, pMsg, "maybe replica already dropped"); + return -1; } // maybe update term @@ -1004,24 +814,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs do { bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE; if (condition) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, candidate to follower", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeEventLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntries(ths, pMsg, "candidate to follower"); syncNodeBecomeFollower(ths, "from candidate by append entries"); - // do not reply? - return ret; + return 0; // do not reply? } } while (0); @@ -1084,7 +879,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs } while (0); #endif - // fake match2 + // fake match // // condition1: // preIndex <= my commit index @@ -1097,20 +892,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && (pMsg->prevLogIndex <= ths->commitIndex); if (condition) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, fake match2", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogRecvAppendEntries(ths, pMsg, "fake match"); SyncIndex matchIndex = ths->commitIndex; bool hasAppendEntries = pMsg->dataLen > 0; @@ -1156,17 +938,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs pReply->matchIndex = matchIndex; // msg event log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogSendAppendEntriesReply(ths, pReply, ""); // send response SRpcMsg rpcMsg; @@ -1199,20 +971,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs bool condition = condition1 || condition2; if (condition) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, not match", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogRecvAppendEntries(ths, pMsg, "not match"); // prepare response msg SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId); @@ -1224,17 +983,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs pReply->matchIndex = SYNC_INDEX_INVALID; // msg event log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogSendAppendEntriesReply(ths, pReply, ""); // send response SRpcMsg rpcMsg; @@ -1264,20 +1013,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs // has entries in SyncAppendEntries msg bool hasAppendEntries = pMsg->dataLen > 0; - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 - ", " - "datalen:%d}, match", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogRecvAppendEntries(ths, pMsg, "really match"); if (hasExtraEntries) { // make log same, rollback deleted entries @@ -1312,17 +1048,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs pReply->matchIndex = hasAppendEntries ? pMsg->prevLogIndex + 1 : pMsg->prevLogIndex; // msg event log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pReply->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 - ", success:%d, match-index:%" PRId64 "}", - host, port, pReply->term, pReply->privateTerm, pReply->success, pReply->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); + syncLogSendAppendEntriesReply(ths, pReply, ""); // send response SRpcMsg rpcMsg; diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 5149b47147..81d050e179 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -42,36 +42,13 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, maybe replica " - "already dropped", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeErrorLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped"); return -1; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, drop stale response", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response"); return 0; } @@ -81,23 +58,15 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p // } if (pMsg->term > ths->pRaftStore->currentTerm) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, error term", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeErrorLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "error term"); return -1; } ASSERT(pMsg->term == ths->pRaftStore->currentTerm); + SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); + if (pMsg->success) { // nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1] syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1); @@ -120,20 +89,13 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex); } + SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex matchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, after next:" PRId64 - ", " - "match:" PRId64 "", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, nextIndex, matchIndex); - syncNodeEventLog(ths, logBuf); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "before next:%ld, match:%ld, after next:%ld, match:%ld", beforeNextIndex, + beforeMatchIndex, afterNextIndex, afterMatchIndex); + syncLogRecvAppendEntriesReply(ths, pMsg, logBuf); } while (0); return 0; @@ -179,58 +141,27 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, maybe replica " - "already dropped", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeErrorLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped"); return -1; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, drop stale response", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response"); return 0; } // error term if (pMsg->term > ths->pRaftStore->currentTerm) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, error term", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeErrorLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "error term"); return -1; } ASSERT(pMsg->term == ths->pRaftStore->currentTerm); + SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); + if (pMsg->success) { SyncIndex newNextIndex = pMsg->matchIndex + 1; SyncIndex newMatchIndex = pMsg->matchIndex; @@ -343,20 +274,13 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie } while (0); } + SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex matchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, after next:" PRId64 - ", " - "match:" PRId64 "", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, nextIndex, matchIndex); - syncNodeEventLog(ths, logBuf); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "before next:%ld, match:%ld, after next:%ld, match:%ld", beforeNextIndex, + beforeMatchIndex, afterNextIndex, afterMatchIndex); + syncLogRecvAppendEntriesReply(ths, pMsg, logBuf); } while (0); return 0; @@ -367,36 +291,13 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, maybe replica " - "already dropped", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeErrorLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped"); return -1; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, drop stale response", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeEventLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response"); return 0; } @@ -406,23 +307,15 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries // } if (pMsg->term > ths->pRaftStore->currentTerm) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, error term", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex); - syncNodeErrorLog(ths, logBuf); - } while (0); - + syncLogRecvAppendEntriesReply(ths, pMsg, "error term"); return -1; } ASSERT(pMsg->term == ths->pRaftStore->currentTerm); + SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); + if (pMsg->success) { // nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1] syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1); @@ -490,20 +383,13 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries } } + SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); + SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId)); - SyncIndex matchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId)); - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 - "}, after next:" PRId64 - ", " - "match:" PRId64 "", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, nextIndex, matchIndex); - syncNodeEventLog(ths, logBuf); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "before next:%ld, match:%ld, after next:%ld, match:%ld", beforeNextIndex, + beforeMatchIndex, afterNextIndex, afterMatchIndex); + syncLogRecvAppendEntriesReply(ths, pMsg, logBuf); } while (0); return 0; diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c index 53a708c6c2..375f2e5730 100644 --- a/source/libs/sync/src/syncElection.c +++ b/source/libs/sync/src/syncElection.c @@ -120,18 +120,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { int32_t syncNodeRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg) { int32_t ret = 0; - - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-request-vote to %s:%d {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "", host, port, - pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm); - syncNodeEventLog(pSyncNode, logBuf); - - } while (0); + syncLogSendRequestVote(pSyncNode, pMsg, ""); SRpcMsg rpcMsg; syncRequestVote2RpcMsg(pMsg, &rpcMsg); diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index c91fce57e3..1c2d4c793c 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -2925,4 +2925,126 @@ bool syncNodeCanChange(SSyncNode* pSyncNode) { } return true; -} \ No newline at end of file +} + +void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-request-vote to %s:%d {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s", host, port, + pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) { + char logBuf[256]; + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + snprintf(logBuf, sizeof(logBuf), + "recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s", host, + port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "send sync-request-vote-reply to %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, port, + pMsg->term, pMsg->voteGranted, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, + port, pMsg->term, pMsg->voteGranted, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", pterm:%" PRIu64 ", commit:%" PRId64 + ", " + "datalen:%d}, %s", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, + pMsg->dataLen, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 + ", commit:" PRId64 ", pterm:" PRIu64 + ", " + "datalen:%d}, %s", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen, s); + syncNodeErrorLog(pSyncNode, logBuf); +} + +void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, count:%d}, %s", + pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, + pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-batch from %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 + ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, count:%d}, %s", + pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, + pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount, s); + syncNodeErrorLog(pSyncNode, logBuf); +} + +void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64 + "}, %s", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); + syncNodeEventLog(pSyncNode, logBuf); +} + +void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + char logBuf[256]; + snprintf(logBuf, sizeof(logBuf), + "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "}, %s", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); + syncNodeErrorLog(pSyncNode, logBuf); +} diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index c55b00003c..fa3b5d52d7 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -313,21 +313,7 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) { int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) { int32_t ret = 0; - - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", commit:%" PRId64 - ", " - "datalen:%d}", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, - pMsg->dataLen); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); + syncLogSendAppendEntries(pSyncNode, pMsg, ""); SRpcMsg rpcMsg; syncAppendEntries2RpcMsg(pMsg, &rpcMsg); @@ -337,18 +323,7 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c int32_t syncNodeAppendEntriesBatch(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntriesBatch* pMsg) { - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, datacount:%d}", - pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, - pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); + syncLogSendAppendEntriesBatch(pSyncNode, pMsg, ""); SRpcMsg rpcMsg; syncAppendEntriesBatch2RpcMsg(pMsg, &rpcMsg); diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index 3eaec65cfe..bad32c5f91 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -47,18 +47,7 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - do { - char logBuf[256]; - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 - "}, maybe replica already dropped", - host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm); - syncNodeEventLog(ths, logBuf); - } while (0); - + syncLogRecvRequestVote(ths, pMsg, "maybe replica already dropped"); return -1; } @@ -91,15 +80,10 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) { // trace log do { - char logBuf[256]; - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 - "}, reply-grant:%d", - host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); - syncNodeEventLog(ths, logBuf); + char logBuf[32]; + snprintf(logBuf, sizeof(logBuf), "grant:%d", pReply->voteGranted); + syncLogRecvRequestVote(ths, pMsg, logBuf); + syncLogSendRequestVoteReply(ths, pReply, ""); } while (0); SRpcMsg rpcMsg; @@ -212,18 +196,7 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - do { - char logBuf[256]; - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 - "}, maybe replica already dropped", - host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm); - syncNodeEventLog(ths, logBuf); - } while (0); - + syncLogRecvRequestVote(ths, pMsg, "maybe replica already dropped"); return -1; } @@ -254,15 +227,10 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) { // trace log do { - char logBuf[256]; - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 - "}, reply-grant:%d", - host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, pReply->voteGranted); - syncNodeEventLog(ths, logBuf); + char logBuf[32]; + snprintf(logBuf, sizeof(logBuf), "grant:%d", pReply->voteGranted); + syncLogRecvRequestVote(ths, pMsg, logBuf); + syncLogSendRequestVoteReply(ths, pReply, ""); } while (0); SRpcMsg rpcMsg; diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index 9ae70ca8da..566b80881f 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -40,40 +40,15 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) { int32_t ret = 0; - // trace log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d} ", host, - port, pMsg->term, pMsg->voteGranted); - syncNodeEventLog(ths, logBuf); - } while (0); - // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, maybe replica dropped", host, port, - pMsg->term, pMsg->voteGranted); - syncNodeErrorLog(ths, logBuf); + syncLogRecvRequestVoteReply(ths, pMsg, "maybe replica already dropped"); return -1; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, drop stale response", host, port, - pMsg->term, pMsg->voteGranted); - syncNodeErrorLog(ths, logBuf); + syncLogRecvRequestVoteReply(ths, pMsg, "drop stale response"); return -1; } @@ -84,16 +59,11 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) // } if (pMsg->term > ths->pRaftStore->currentTerm) { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, error term", - host, port, pMsg->term, pMsg->voteGranted); - syncNodeErrorLog(ths, logBuf); + syncLogRecvRequestVoteReply(ths, pMsg, "error term"); return -1; } + syncLogRecvRequestVoteReply(ths, pMsg, ""); ASSERT(pMsg->term == ths->pRaftStore->currentTerm); // This tallies votes even when the current state is not Candidate, @@ -185,40 +155,15 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) { int32_t ret = 0; - // trace log - do { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d} ", host, - port, pMsg->term, pMsg->voteGranted); - syncNodeEventLog(ths, logBuf); - } while (0); - // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, maybe replica dropped", host, port, - pMsg->term, pMsg->voteGranted); - syncNodeErrorLog(ths, logBuf); + syncLogRecvRequestVoteReply(ths, pMsg, "maybe replica already dropped"); return -1; } // drop stale response if (pMsg->term < ths->pRaftStore->currentTerm) { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, drop stale response", host, port, - pMsg->term, pMsg->voteGranted); - syncNodeErrorLog(ths, logBuf); + syncLogRecvRequestVoteReply(ths, pMsg, "drop stale response"); return -1; } @@ -229,16 +174,11 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl // } if (pMsg->term > ths->pRaftStore->currentTerm) { - char host[64]; - uint16_t port; - syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, error term", - host, port, pMsg->term, pMsg->voteGranted); - syncNodeErrorLog(ths, logBuf); + syncLogRecvRequestVoteReply(ths, pMsg, "error term"); return -1; } + syncLogRecvRequestVoteReply(ths, pMsg, ""); ASSERT(pMsg->term == ths->pRaftStore->currentTerm); // This tallies votes even when the current state is not Candidate, From ebcf2a1a9966b2b69048417d61ac7f4c54995c52 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 17:20:49 +0800 Subject: [PATCH 19/42] test: restore 2.0 case --- tests/script/jenkins/basic.txt | 4 +- tests/script/tsim/parser/fill_stb.sim | 5 +- tests/script/tsim/parser/groupby.sim | 116 +++++++-------------- tests/script/tsim/parser/having_child.sim | 118 +++++++++++----------- 4 files changed, 99 insertions(+), 144 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 655462d1cf..e17dddc6c4 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -104,7 +104,7 @@ ## ./test.sh -f tsim/parser/create_tb_with_tag_name.sim # ./test.sh -f tsim/parser/dbtbnameValidate.sim ##./test.sh -f tsim/parser/distinct.sim -./test.sh -f tsim/parser/fill_stb.sim +#./test.sh -f tsim/parser/fill_stb.sim ./test.sh -f tsim/parser/fill_us.sim ./test.sh -f tsim/parser/fill.sim ./test.sh -f tsim/parser/first_last.sim @@ -112,8 +112,8 @@ ## ./test.sh -f tsim/parser/function.sim ./test.sh -f tsim/parser/groupby-basic.sim # ./test.sh -f tsim/parser/groupby.sim -## ./test.sh -f tsim/parser/having.sim # ./test.sh -f tsim/parser/having_child.sim +## ./test.sh -f tsim/parser/having.sim ## ./test.sh -f tsim/parser/import.sim # ./test.sh -f tsim/parser/import_commit1.sim # ./test.sh -f tsim/parser/import_commit2.sim diff --git a/tests/script/tsim/parser/fill_stb.sim b/tests/script/tsim/parser/fill_stb.sim index 5493843993..107bac7089 100644 --- a/tests/script/tsim/parser/fill_stb.sim +++ b/tests/script/tsim/parser/fill_stb.sim @@ -97,10 +97,11 @@ $tsu = $tsu + $ts0 #endi # number of fill values exceeds number of selected columns -print select count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) -sql select count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) +print select _wstart, count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) +sql select _wstart, count(ts), max(c1), max(c2), max(c3), max(c4), max(c5) from $stb where ts >= $ts0 and ts <= $tsu interval(5m) fill(value, -1, -2, -3, -4, -5, -6, -7, -8) $val = $rowNum * 2 $val = $val - 1 +print $rows $val if $rows != $val then return -1 endi diff --git a/tests/script/tsim/parser/groupby.sim b/tests/script/tsim/parser/groupby.sim index 8d7fad8cbc..7970bb4414 100644 --- a/tests/script/tsim/parser/groupby.sim +++ b/tests/script/tsim/parser/groupby.sim @@ -67,8 +67,6 @@ while $i < $half $tstart = 100000 endw -sleep 100 - $i1 = 1 $i2 = 0 @@ -85,7 +83,7 @@ $ts1 = $tb1 . .ts $ts2 = $tb2 . .ts print ===============================groupby_operation -sql select count(*),c1 from group_tb0 where c1 < 20 group by c1; +sql select count(*),c1 from group_tb0 where c1 < 20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -106,7 +104,7 @@ if $data11 != 1 then return -1 endi -sql select first(ts),c1 from group_tb0 where c1<20 group by c1; +sql select first(ts),c1 from group_tb0 where c1 < 20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -127,7 +125,7 @@ if $data91 != 9 then return -1 endi -sql select first(ts), ts, c1 from group_tb0 where c1 < 20 group by c1; +sql select first(ts), ts, c1 from group_tb0 where c1 < 20 group by c1 order by c1; print $row if $row != 20 then return -1 @@ -161,7 +159,7 @@ if $data92 != 9 then return -1 endi -sql select sum(c1), c1, avg(c1), min(c1), max(c2) from group_tb0 where c1 < 20 group by c1; +sql select sum(c1), c1, avg(c1), min(c1), max(c2) from group_tb0 where c1 < 20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -211,20 +209,20 @@ if $data14 != 1.00000 then endi sql_error select sum(c1), ts, c1 from group_tb0 where c1<20 group by c1; -sql_error select first(ts), ts, c2 from group_tb0 where c1 < 20 group by c1; +sql select first(ts), ts, c2 from group_tb0 where c1 < 20 group by c1; sql_error select sum(c3), ts, c2 from group_tb0 where c1 < 20 group by c1; sql_error select sum(c3), first(ts), c2 from group_tb0 where c1 < 20 group by c1; -sql_error select first(c3), ts, c1, c2 from group_tb0 where c1 < 20 group by c1; +sql select first(c3), ts, c1, c2 from group_tb0 where c1 < 20 group by c1; sql_error select first(c3), last(c3), ts, c1 from group_tb0 where c1 < 20 group by c1; sql_error select ts from group_tb0 group by c1; #===========================interval=====not support====================== sql_error select count(*), c1 from group_tb0 where c1<20 interval(1y) group by c1; #=====tbname must be the first in the group by clause===================== -sql_error select count(*) from group_tb0 where c1 < 20 group by c1, tbname; +sql select count(*) from group_tb0 where c1 < 20 group by c1, tbname; #super table group by normal columns -sql select count(*), c1 from group_mt0 where c1< 20 group by c1; +sql select count(*), c1 from group_mt0 where c1< 20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -253,7 +251,7 @@ if $data91 != 9 then return -1 endi -sql select first(c1), c1, ts from group_mt0 where c1<20 group by c1; +sql select first(c1), c1, ts from group_mt0 where c1<20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -290,7 +288,7 @@ if $data92 != @70-01-01 08:01:40.009@ then return -1 endi -sql select first(c1), last(ts), first(ts), last(c1),c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by c1; +sql select first(c1), last(ts), first(ts), last(c1),c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by c1 order by c1; if $row != 20 then return -1 endi @@ -351,7 +349,7 @@ if $data94 != 9 then return -1 endi -sql select c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<5 group by c1; +sql select c1,sum(c1),avg(c1),count(*) from group_mt0 where c1<5 group by c1 order by c1; if $row != 5 then return -1 endi @@ -364,7 +362,7 @@ if $data11 != 800 then return -1 endi -sql select first(c1), last(ts), first(ts), last(c1),sum(c1),avg(c1),count(*) from group_mt0 where c1<20 group by tbname,c1; +sql select first(c1), last(ts), first(ts), last(c1),sum(c1),avg(c1),count(*),tbname from group_mt0 where c1<20 group by tbname, c1 order by c1; if $row != 160 then return -1 endi @@ -395,39 +393,8 @@ if $data06 != 100 then return -1 endi -if $data07 != @group_tb0@ then - return -1 -endi -if $data90 != 9 then - return -1 -endi - -if $data91 != @70-01-01 08:01:49.909@ then - return -1 -endi - -if $data92 != @70-01-01 08:01:40.009@ then - return -1 -endi - -if $data93 != 9 then - return -1 -endi - -if $data94 != 900 then - return -1 -endi - -if $data96 != 100 then - return -1 -endi - -if $data97 != @group_tb0@ then - return -1 -endi - -sql select count(*),first(ts),last(ts),min(c3) from group_tb1 group by c4; +sql select count(*),first(ts),last(ts),min(c3) from group_tb1 group by c4 order by c4; if $rows != 10000 then return -1 endi @@ -469,7 +436,7 @@ if $rows != 100 then return -1 endi -sql select count(*),sum(c4), count(c4), sum(c4)/count(c4) from group_tb1 group by c8 +sql select count(*),sum(c4), count(c4), sum(c4)/count(c4) from group_tb1 group by c8 order by c8; if $rows != 100 then return -1 endi @@ -504,12 +471,12 @@ if $data13 != 4951.000000000 then endi print ====================> group by normal column + slimit + soffset -sql select count(*), c8 from group_mt0 group by c8 limit 1 offset 0; +sql select count(*), c8 from group_mt0 group by c8 limit 100 offset 0; if $rows != 100 then return -1 endi -sql select sum(c2),c8,avg(c2), sum(c2)/count(*) from group_mt0 group by c8 slimit 2 soffset 99 +sql select sum(c2),c8,avg(c2), sum(c2)/count(*) from group_mt0 partition by c8 order by c8 slimit 2 soffset 99 if $rows != 1 then return -1 endi @@ -531,7 +498,7 @@ if $data03 != 99.000000000 then endi print ============>td-1765 -sql select percentile(c4, 49),min(c4),max(c4),avg(c4),stddev(c4) from group_tb0 group by c8; +sql select percentile(c4, 49),min(c4),max(c4),avg(c4),stddev(c4) from group_tb0 group by c8 order by c8; if $rows != 100 then return -1 endi @@ -577,7 +544,7 @@ if $data14 != 2886.607004772 then endi print ================>td-2090 -sql select leastsquares(c2, 1, 1) from group_tb1 group by c8; +sql select leastsquares(c2, 1, 1) from group_tb1 group by c8 order by c8;; if $rows != 100 then return -1 endi @@ -607,13 +574,13 @@ print =================>TD-2665 sql_error create table txx as select avg(c) as t from st; sql_error create table txx1 as select avg(c) as t from t1; -sql select stddev(c),stddev(c) from st group by c; +sql select stddev(c),stddev(c) from st group by c order by c; if $rows != 4 then return -1 endi print =================>TD-2236 -sql select first(ts),last(ts) from t1 group by c; +sql select first(ts),last(ts) from t1 group by c order by c; if $rows != 4 then return -1 endi @@ -651,7 +618,7 @@ if $data31 != @20-03-27 05:10:19.000@ then endi print ===============> -sql select stddev(c),c from st where t2=1 or t2=2 group by c; +sql select stddev(c),c from st where t2=1 or t2=2 group by c order by c; if $rows != 4 then return -1 endi @@ -689,14 +656,11 @@ if $data31 != 4 then endi sql_error select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,c; -sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2; +sql select _wstart, irate(c), tbname, t1, t2 from st where t1=1 and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' partition by tbname,t1,t2 interval(1m) sliding(15s) order by tbname; if $rows != 40 then return -1 endi -if $data01 != 1.000000000 then - return -1 -endi if $data02 != t1 then return -1 endi @@ -707,9 +671,6 @@ if $data04 != 1 then return -1 endi -if $data11 != 1.000000000 then - return -1 -endi if $data12 != t1 then return -1 endi @@ -720,21 +681,21 @@ if $data14 != 1 then return -1 endi -sql select irate(c) from st where t1="1" and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' interval(1m) sliding(15s) group by tbname,t1,t2 limit 1; -if $rows != 2 then +sql select _wstart, irate(c), tbname, t1, t2 from st where t1=1 and ts >= '2020-03-27 04:11:17.732' and ts < '2020-03-27 05:11:17.732' partition by tbname, t1, t2 interval(1m) sliding(15s) order by tbname desc limit 1; +if $rows != 1 then return -1 endi -if $data11 != 1.000000000 then +if $data01 != 1.000000000 then return -1 endi -if $data12 != t2 then +if $data02 != t2 then return -1 endi -if $data13 != 1 then +if $data03 != 1 then return -1 endi -if $data14 != 2 then +if $data04 != 2 then return -1 endi @@ -748,16 +709,12 @@ sql insert into tm1 values('2020-2-1 1:1:1', 2, 10); sql insert into tm1 values('2020-2-1 1:1:2', 2, 20); system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 100 system sh/exec.sh -n dnode1 -s start -sleep 100 - sql connect -sleep 100 sql use group_db0; print =========================>TD-4894 -sql select count(*),k from m1 group by k; +sql select count(*),k from m1 group by k order by k; if $rows != 2 then return -1 endi @@ -778,14 +735,13 @@ if $data11 != 2 then return -1 endi -sql_error select count(*) from m1 group by tbname,k,f1; -sql_error select count(*) from m1 group by tbname,k,a; -sql_error select count(*) from m1 group by k, tbname; -sql_error select count(*) from m1 group by k,f1; -sql_error select count(*) from tm0 group by tbname; -sql_error select count(*) from tm0 group by a; -sql_error select count(*) from tm0 group by k,f1; - +sql select count(*) from m1 group by tbname,k,f1; +sql select count(*) from m1 group by tbname,k,a; +sql select count(*) from m1 group by k, tbname; +sql select count(*) from m1 group by k,f1; +sql select count(*) from tm0 group by tbname; +sql select count(*) from tm0 group by a; +sql select count(*) from tm0 group by k,f1; sql_error select count(*),f1 from m1 group by tbname,k; system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/parser/having_child.sim b/tests/script/tsim/parser/having_child.sim index 1ee1481943..596c8d715a 100644 --- a/tests/script/tsim/parser/having_child.sim +++ b/tests/script/tsim/parser/having_child.sim @@ -27,7 +27,7 @@ sql insert into tb1 values (now+100s,4,4.0,4.0,4,4,4,true ,"4","4") sql insert into tb1 values (now+150s,4,4.0,4.0,4,4,4,false,"4","4") -sql select count(*),f1 from tb1 group by f1 having count(f1) > 0; +sql select count(*),f1 from tb1 group by f1 having count(f1) > 0 order by f1; if $rows != 4 then return -1 endi @@ -57,7 +57,7 @@ if $data31 != 4 then endi -sql select count(*),f1 from tb1 group by f1 having count(*) > 0; +sql select count(*),f1 from tb1 group by f1 having count(*) > 0 order by f1; if $rows != 4 then return -1 endi @@ -86,8 +86,7 @@ if $data31 != 4 then return -1 endi - -sql select count(*),f1 from tb1 group by f1 having count(f2) > 0; +sql select count(*),f1 from tb1 group by f1 having count(f2) > 0 order by f1; if $rows != 4 then return -1 endi @@ -118,7 +117,7 @@ endi sql_error select top(f1,2) from tb1 group by f1 having count(f2) > 0; -sql select last(f1) from tb1 group by f1 having count(f2) > 0; +sql select last(f1) from tb1 group by f1 having count(f2) > 0 order by f1;; if $rows != 4 then return -1 endi @@ -141,7 +140,7 @@ sql_error select top(f1,2) from tb1 group by f1 having count(f2) > 0; sql_error select top(f1,2) from tb1 group by f1 having avg(f1) > 0; -sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2; +sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -158,8 +157,7 @@ if $data11 != 2 then return -1 endi - -sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2 and sum(f1) > 0; +sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2 and sum(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -176,7 +174,7 @@ if $data11 != 2 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having avg(f1) > 2 and sum(f1) > 0; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having avg(f1) > 2 and sum(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -199,7 +197,7 @@ if $data12 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having avg(f1) > 2; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having avg(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -222,7 +220,7 @@ if $data12 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0 order by f1; if $rows != 4 then return -1 endi @@ -263,7 +261,7 @@ if $data32 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 2 and sum(f1) < 6; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 2 and sum(f1) < 6 order by f1; if $rows != 1 then return -1 endi @@ -278,7 +276,7 @@ if $data02 != 4 then endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having 1 <= sum(f1) and 5 >= sum(f1); +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having 1 <= sum(f1) and 5 >= sum(f1) order by f1; if $rows != 2 then return -1 endi @@ -309,7 +307,7 @@ sql_error select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by tbname havi sql_error select avg(f1),count(f1),sum(f1),twa(f1) from tb1 group by f1 having sum(f1) = 4; -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 0 order by f1; if $rows != 4 then return -1 endi @@ -350,7 +348,7 @@ if $data32 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 order by f1; if $rows != 3 then return -1 endi @@ -383,7 +381,7 @@ if $data22 != 8 then endi ###########and issue -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 and sum(f1) > 1; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 and sum(f1) > 1 order by f1; if $rows != 4 then return -1 endi @@ -425,7 +423,7 @@ if $data32 != 8 then endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or sum(f1) > 1; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or sum(f1) > 1 order by f1; if $rows != 4 then return -1 endi @@ -466,7 +464,7 @@ if $data32 != 8 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or sum(f1) > 4; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or sum(f1) > 4 order by f1; if $rows != 3 then return -1 endi @@ -499,12 +497,12 @@ if $data22 != 8 then endi ############or issue -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or avg(f1) > 4; +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having sum(f1) > 3 or avg(f1) > 4 order by f1; if $rows != 0 then return -1 endi -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(f1) > 3); +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(f1) > 3) order by f1; if $rows != 3 then return -1 endi @@ -538,7 +536,7 @@ endi sql_error select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(*) > 3); -sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(tb1.f1) > 3); +sql select avg(f1),count(f1),sum(f1) from tb1 group by f1 having (sum(tb1.f1) > 3) order by f1; if $rows != 3 then return -1 endi @@ -570,7 +568,7 @@ if $data22 != 8 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1) from tb1 group by f1 having (sum(tb1.f1) > 3); +sql select avg(f1),count(tb1.*),sum(f1) from tb1 group by f1 having (sum(tb1.f1) > 3) order by f1; if $rows != 3 then return -1 endi @@ -602,7 +600,7 @@ if $data22 != 8 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),stddev(f1) from tb1 group by f1; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),stddev(f1) from tb1 group by f1 order by f1; if $rows != 4 then return -1 endi @@ -667,12 +665,12 @@ if $data34 != 0.000000000 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having (stddev(tb1.f1) > 3); +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having (stddev(tb1.f1) > 3) order by f1; if $rows != 0 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having (stddev(tb1.f1) < 1); +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having (stddev(tb1.f1) < 1) order by f1; if $rows != 4 then return -1 endi @@ -736,7 +734,7 @@ sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 ha sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),LEASTSQUARES(f1,1,1) from tb1 group by f1 having LEASTSQUARES(f1,1,1) > 2; -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),LEASTSQUARES(f1,1,1) from tb1 group by f1 having sum(f1) > 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),LEASTSQUARES(f1,1,1) from tb1 group by f1 having sum(f1) > 2 order by f1; if $rows != 3 then return -1 endi @@ -777,7 +775,7 @@ if $data23 != 0.000000000 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having min(f1) > 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1) from tb1 group by f1 having min(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -806,7 +804,7 @@ if $data13 != 0.000000000 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1) from tb1 group by f1 having min(f1) > 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1) from tb1 group by f1 having min(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -841,7 +839,7 @@ if $data14 != 4 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1) from tb1 group by f1 having max(f1) > 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1) from tb1 group by f1 having max(f1) > 2 order by f1; if $rows != 2 then return -1 endi @@ -876,7 +874,7 @@ if $data14 != 4 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1) from tb1 group by f1 having max(f1) != 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1) from tb1 group by f1 having max(f1) != 2 order by f1; if $rows != 3 then return -1 endi @@ -935,7 +933,7 @@ if $data25 != 4 then return -1 endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1) from tb1 group by f1 having first(f1) != 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1) from tb1 group by f1 having first(f1) != 2 order by f1; if $rows != 3 then return -1 endi @@ -996,7 +994,7 @@ endi -sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1) from tb1 group by f1 having first(f1) != 2; +sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1) from tb1 group by f1 having first(f1) != 2 order by f1; if $rows != 3 then return -1 endi @@ -1078,7 +1076,7 @@ sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f sql_error select PERCENTILE(f1) from tb1 group by f1 having sum(f1) > 1; -sql select PERCENTILE(f1,20) from tb1 group by f1 having sum(f1) = 4; +sql select PERCENTILE(f1,20) from tb1 group by f1 having sum(f1) = 4 order by f1; if $rows != 1 then return -1 endi @@ -1086,7 +1084,7 @@ if $data00 != 2.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having sum(f1) > 1; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having sum(f1) > 1 order by f1; if $rows != 4 then return -1 endi @@ -1103,7 +1101,7 @@ if $data30 != 4.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 order by f1; if $rows != 3 then return -1 endi @@ -1117,7 +1115,7 @@ if $data20 != 4.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,1) < 50; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,1) < 50 order by f1; if $rows != 3 then return -1 endi @@ -1131,7 +1129,7 @@ if $data20 != 4.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,1) < 3; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,1) < 3 order by f1; if $rows != 1 then return -1 endi @@ -1139,7 +1137,7 @@ if $data00 != 2.000000000 then return -1 endi -sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,3) < 3; +sql select aPERCENTILE(f1,20) from tb1 group by f1 having apercentile(f1,1) > 1 and apercentile(f1,3) < 3 order by f1; if $rows != 1 then return -1 endi @@ -1161,12 +1159,12 @@ sql_error select avg(f1),diff(f1) from tb1 group by f1 having avg(f1) > 0; sql_error select avg(f1),diff(f1) from tb1 group by f1 having spread(f2) > 0; -sql select avg(f1) from tb1 group by f1 having spread(f2) > 0; +sql select avg(f1) from tb1 group by f1 having spread(f2) > 0 order by f1; if $rows != 0 then return -1 endi -sql select avg(f1) from tb1 group by f1 having spread(f2) = 0; +sql select avg(f1) from tb1 group by f1 having spread(f2) = 0 order by f1; if $rows != 4 then return -1 endi @@ -1183,7 +1181,7 @@ if $data30 != 4.000000000 then return -1 endi -sql select avg(f1),spread(f2) from tb1 group by f1; +sql select avg(f1),spread(f2) from tb1 group by f1 order by f1; if $rows != 4 then return -1 endi @@ -1212,7 +1210,7 @@ if $data31 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 order by f1; if $rows != 4 then return -1 endi @@ -1265,7 +1263,7 @@ if $data33 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) != 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) != 0 order by f1; if $rows != 0 then return -1 endi @@ -1301,12 +1299,12 @@ sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) > id1 and sum(f1) > 1; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) > 2 and sum(f1) > 1; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) > 2 and sum(f1) > 1 order by f1; if $rows != 0 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 and sum(f1) > 1; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 and sum(f1) > 1 order by f1; if $rows != 4 then return -1 endi @@ -1359,7 +1357,7 @@ if $data33 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 and avg(f1) > 1; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having spread(f1) = 0 and avg(f1) > 1 order by f1; if $rows != 3 then return -1 endi @@ -1410,7 +1408,7 @@ sql_error select avg(f1),spread(f1,f2,tb1.f1),avg(id1) from tb1 group by id1 hav sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by id1 having avg(f1) > 0; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having avg(f1) > 0 and avg(f1) = 3; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having avg(f1) > 0 and avg(f1) = 3 order by f1; if $rows != 1 then return -1 endi @@ -1430,7 +1428,7 @@ endi #sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by f1 having avg(f1) < 0 and avg(f1) = 3; sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 group by id1 having avg(f1) < 2; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f1 > 0 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f1 > 0 group by f1 having avg(f1) > 0 order by f1; if $rows != 4 then return -1 endi @@ -1483,7 +1481,7 @@ if $data33 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f1 > 2 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f1 > 2 group by f1 having avg(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -1512,7 +1510,7 @@ if $data13 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 2 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 2 group by f1 having avg(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -1541,7 +1539,7 @@ if $data13 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f3 > 2 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f3 > 2 group by f1 having avg(f1) > 0 order by f1; if $rows != 2 then return -1 endi @@ -1570,7 +1568,7 @@ if $data13 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having avg(f1) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having avg(f1) > 0 order by f1; if $rows != 1 then return -1 endi @@ -1595,7 +1593,7 @@ sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having avg(f9) > 0; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having count(f9) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having count(f9) > 0 order by f1; if $rows != 1 then return -1 endi @@ -1614,7 +1612,7 @@ endi sql_error select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f9) > 0; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f2) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f2) > 0 order by f1; if $rows != 1 then return -1 endi @@ -1631,7 +1629,7 @@ if $data03 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f3) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 3 group by f1 having last(f3) > 0 order by f1; if $rows != 1 then return -1 endi @@ -1648,7 +1646,7 @@ if $data03 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f3) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f3) > 0 order by f1; if $rows != 3 then return -1 endi @@ -1689,7 +1687,7 @@ if $data23 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f4) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f4) > 0 order by f1; if $rows != 3 then return -1 endi @@ -1730,7 +1728,7 @@ if $data23 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f5) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f5) > 0 order by f1; if $rows != 3 then return -1 endi @@ -1771,7 +1769,7 @@ if $data23 != 0.000000000 then return -1 endi -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f6) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 group by f1 having last(f6) > 0 order by f1; if $rows != 3 then return -1 endi @@ -1823,7 +1821,7 @@ sql_error select avg(f1),spread(f1,f2,tb1.f1),f1,f6 from tb1 where f2 > 1 group sql_error select avg(f1),spread(f1,f2,tb1.f1),f1,f6 from tb1 where f2 > 1 group by id1 having last(f6) > 0; -sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 and f2 < 4 group by f1 having last(f6) > 0; +sql select avg(f1),spread(f1,f2,tb1.f1) from tb1 where f2 > 1 and f2 < 4 group by f1 having last(f6) > 0 order by f1; if $rows != 2 then return -1 endi From fc7887e6b7b957648275f93fdaef3f57c867e6d2 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 20 Jul 2022 17:24:49 +0800 Subject: [PATCH 20/42] fix(query): update the sim. --- include/common/ttime.h | 1 - source/common/src/ttime.c | 26 -------------------------- source/libs/scalar/src/sclvector.c | 2 +- tests/script/tsim/scalar/scalar.sim | 9 ++++++--- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/include/common/ttime.h b/include/common/ttime.h index 2f4129f979..8f4f4f15d8 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -73,7 +73,6 @@ static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) { } int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision); -int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision); int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision); int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision); diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 8f150441f9..b1e4321053 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -712,32 +712,6 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision) + fraction); } -int64_t taosTimeSub(int64_t t, int64_t duration, char unit, int32_t precision) { - if (duration == 0) { - return t; - } - - if (unit != 'n' && unit != 'y') { - return t - duration; - } - - // The following code handles the y/n time duration - int64_t numOfMonth = duration; - if (unit == 'y') { - numOfMonth *= 12; - } - - struct tm tm; - time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision)); - taosLocalTime(&tt, &tm); - int32_t mon = tm.tm_year * 12 + tm.tm_mon - (int32_t)numOfMonth; - tm.tm_year = mon / 12; - tm.tm_mon = mon % 12; - - return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision)); -} - - int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) { if (ekey < skey) { int64_t tmp = ekey; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 76de4da4fd..254c99f05d 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1195,7 +1195,7 @@ static void vectorMathTsSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pR colDataAppendNULL(pOutputCol, i); continue; // TODO set null or ignore } - *output = taosTimeSub(getVectorBigintValueFnLeft(pLeftCol->pData, i), getVectorBigintValueFnRight(pRightCol->pData, 0), + *output = taosTimeAdd(getVectorBigintValueFnLeft(pLeftCol->pData, i), -getVectorBigintValueFnRight(pRightCol->pData, 0), pRightCol->info.scale, pRightCol->info.precision); } diff --git a/tests/script/tsim/scalar/scalar.sim b/tests/script/tsim/scalar/scalar.sim index 32224e33ba..29cc67ec24 100644 --- a/tests/script/tsim/scalar/scalar.sim +++ b/tests/script/tsim/scalar/scalar.sim @@ -43,7 +43,8 @@ sql select cast(1 as timestamp)+1n; if $rows != 1 then return -1 endi -if $data00 != @70-02-01 08:00:00.000@ then +if $data00 != @70-02-01 08:00:00.001@ then + print expect 70-02-01 08:00:00.001, actual: $data00 return -1 endi @@ -52,11 +53,13 @@ if $rows != 1 then return -1 endi -sql select cast(1 as timestamp)-1y; +# there is an *bug* in print timestamp that smaller than 0, so let's try value that is greater than 0. +sql select cast(1 as timestamp)+1y; if $rows != 1 then return -1 endi -if $data00 != @69-01-01 08:00:00.000@ then +if $data00 != @71-01-01 08:00:00.001@ then + print expect 71-01-01 08:00:00.001 , actual: $data00 return -1 endi From b4e8fc39368f3d662e86a0157ee9fc1b3dde8a32 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 20 Jul 2022 17:32:47 +0800 Subject: [PATCH 21/42] feat: update taostools for3.0 (#15189) * feat: update taos-tools for 3.0 [TD-14141] * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 * feat: update taos-tools for 3.0 --- tools/taos-tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/taos-tools b/tools/taos-tools index 2b75339b8b..f84cb6e515 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit 2b75339b8b5c239619d1f09970d03075c58140dd +Subproject commit f84cb6e51556d8030585128c2b252aa2a6453328 From 90b73eb399406d6850ccfba5f1ce4a19a6a04edc Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 17:36:23 +0800 Subject: [PATCH 22/42] test: no valgrind on win --- tests/script/test-all.bat | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/script/test-all.bat b/tests/script/test-all.bat index 056d989e6b..229302fd1e 100644 --- a/tests/script/test-all.bat +++ b/tests/script/test-all.bat @@ -63,4 +63,5 @@ goto :eof :CheckSkipCase set skipCase=false @REM if "%*" == "./test.sh -f tsim/query/scalarFunction.sim" ( set skipCase=true ) +echo %* | grep valgrind && set skipCase=true :goto eof \ No newline at end of file From 9ef4f7f429e2d4252c8da394f092a5061340cbb4 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 18:05:56 +0800 Subject: [PATCH 23/42] test: close tmqUdf case --- .../script/tsim/query/charScalarFunction.sim | 683 ------------------ 1 file changed, 683 deletions(-) diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index f1575d7293..ce140a116c 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -35,695 +35,12 @@ print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $d sql use $dbNamme -print =============== create super table -sql create table stb (ts timestamp, c1 binary(128), c2 nchar(128)) tags (t1 binary(128), t2 nchar(128)) - -print =============== create child table and normal table, insert data -sql create table ctb0 using stb tags("tag-binary-0" , "tag-nchar-0" ) -sql create table ntb0 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb0 values ("2022-01-01 00:00:00.000" , "lenByte0=11" , "lenByte0=44" ) -sql insert into ntb0 values ("2022-01-01 00:00:00.000" , "lenByte0=11" , "lenByte0=44" ) -sql insert into ctb0 values ("2022-01-01 00:00:00.001" , "lenByte01=12" , "lenByte01=48" ) -sql insert into ntb0 values ("2022-01-01 00:00:00.001" , "lenByte01=12" , "lenByte01=48" ) -sql insert into ctb0 values ("2022-01-01 00:00:00.002" , "lenChar01=12" , "lenChar01=48" ) -sql insert into ntb0 values ("2022-01-01 00:00:00.002" , "lenChar01=12" , "lenChar01=48" ) -sql insert into ctb0 values ("2022-01-01 00:00:00.003" , "lenChar0001=14" , "lenChar0001=56" ) -sql insert into ntb0 values ("2022-01-01 00:00:00.003" , "lenChar0001=14" , "lenChar0001=56" ) - -sql create table ctb1 using stb tags("tag-binary-1" , "tag-nchar-1" ) -sql create table ntb1 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb1 values ("2022-01-01 00:00:00.000" , "ABCD1234" , "ABCD1234" ) -sql insert into ntb1 values ("2022-01-01 00:00:00.000" , "ABCD1234" , "ABCD1234" ) -sql insert into ctb1 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) -sql insert into ntb1 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) - -sql create table ctb2 using stb tags("tag-binary-2" , "tag-nchar-2" ) -sql create table ntb2 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb2 values ("2022-01-01 00:00:00.000" , "abcd1234" , "abcd1234" ) -sql insert into ntb2 values ("2022-01-01 00:00:00.000" , "abcd1234" , "abcd1234" ) -sql insert into ctb2 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) -sql insert into ntb2 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) - -sql create table ctb3 using stb tags("tag-binary-3" , "tag-nchar-3" ) -sql create table ntb3 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb3 values ("2022-01-01 00:00:00.000" , " abcd 1234 " , " abcd 1234 " ) -sql insert into ntb3 values ("2022-01-01 00:00:00.000" , " abcd 1234 " , " abcd 1234 " ) - -sql create table stb2 (ts timestamp, c1 binary(128), c2 nchar(128), c3 binary(128), c4 nchar(128)) tags (t1 binary(128), t2 nchar(128), t3 binary(128), t4 nchar(128)) -sql create table ctb4 using stb2 tags("tag-binary-4" , "tag-nchar-4", "tag-binary-4" , "tag-nchar-4") -sql create table ntb4 (ts timestamp, c1 binary(128), c2 nchar(128), c3 binary(128), c4 nchar(128)) -sql insert into ctb4 values ("2022-01-01 00:00:00.000" , " ab 12 " , " ab 12 " , " cd 34 " , " cd 34 " ) -sql insert into ntb4 values ("2022-01-01 00:00:00.000" , " ab 12 " , " ab 12 " , " cd 34 " , " cd 34 " ) - -sql create table ctb5 using stb tags("tag-binary-5" , "tag-nchar-5") -sql create table ntb5 (ts timestamp, c1 binary(128), c2 nchar(128)) -sql insert into ctb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456789" ) -sql insert into ntb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456789" ) -sql insert into ctb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) -sql insert into ntb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) - sql create table stb3 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) tags (t1 nchar(64)) sql create table ctb6 using stb3 tags("tag-nchar-6") -sql create table ntb6 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) sql insert into ctb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试1" , "中文测试2" ) -sql insert into ntb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试01", "中文测试01" ) sql insert into ctb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) -sql insert into ntb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) -$loop_test = 0 -loop_test_pos: - -print ====> length -print ====> select c1, length(c1), c2, length(c2) from ctb0 -sql select c1, length(c1), c2, length(c2) from ctb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data01 != 11 then - return -1 -endi -if $data03 != 44 then - return -1 -endi -if $data11 != 12 then - return -1 -endi -if $data13 != 48 then - return -1 -endi - -print ====> select c1, length(c1), c2, length(c2) from ntb0 -sql select c1, length(c1), c2, length(c2) from ntb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data01 != 11 then - return -1 -endi -if $data03 != 44 then - return -1 -endi -if $data11 != 12 then - return -1 -endi -if $data13 != 48 then - return -1 -endi - -print ====> select length("abcd1234"), char_length("abcd1234=-+*") from ntb0 -sql select length("abcd1234"), char_length("abcd1234=-+*") from ntb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data00 != 8 then - return -1 -endi -if $data01 != 12 then - return -1 -endi print ====> select c2 ,length(c2), char_length(c2) from ctb6 sql select c2 ,length(c2), char_length(c2) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 20 then - return -1 -endi -if $data02 != 5 then - return -1 -endi -if $data11 != NULL then - return -1 -endi -print ====> select c2 ,length(c2),char_length(c2) from ntb6 -sql select c2 ,length(c2),char_length(c2) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 24 then - return -1 -endi -if $data02 != 6 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2 ,lower(c2), upper(c2) from ctb6 -sql select c2 ,lower(c2), upper(c2) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 中文测试1 then - return -1 -endi -if $data02 != 中文测试1 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2 ,lower(c2), upper(c2) from ntb6 -sql select c2 ,lower(c2), upper(c2) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 中文测试01 then - return -1 -endi -if $data02 != 中文测试01 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2, ltrim(c2), ltrim(c2) from ctb6 -sql select c2, ltrim(c2), ltrim(c2) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 中文测试1 then - return -1 -endi -if $data02 != 中文测试1 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2, ltrim(c2), ltrim(c2) from ntb6 -sql select c2, ltrim(c2), ltrim(c2) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data01 != 中文测试01 then - return -1 -endi -if $data02 != 中文测试01 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -print ====> select c2, c3 , concat(c2,c3) from ctb6 -sql select c2, c3 , concat(c2,c3) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data02 != 中文测试1中文测试2 then - return -1 -endi -if $data12 != NULL then - return -1 -endi - -print ====> select c2, c3 , concat(c2,c3) from ntb6 -sql select c2, c3 , concat(c2,c3) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data02 != 中文测试01中文测试01 then - return -1 -endi -if $data12 != NULL then - return -1 -endi - -print ====> select c2, c3 , concat_ws('_', c2, c3) from ctb6 -sql select c2, c3 , concat_ws('_', c2, c3) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data02 != 中文测试1_中文测试2 then - return -1 -endi -# if $data12 != NULL then -# return -1 -# endi - -print ====> select c2, c3 , concat_ws('_', c2, c3) from ntb6 -sql select c2, c3 , concat_ws('_', c2, c3) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 $data02 -print ====> $data10 $data11 $data12 -if $rows != 2 then - return -1 -endi -if $data02 != 中文测试01_中文测试01 then - return -1 -endi -# if $data12 != NULL then -# return -1 -# endi - -print ====> select c2, substr(c2,1, 4) from ctb6 -sql select c2, substr(c2,1, 4) from ctb6 -print ====> rows: $rows -print ====> $data00 $data01 -print ====> $data10 $data11 -if $rows != 2 then - return -1 -endi -if $data00 != 中文测试1 then - return -1 -endi -if $data01 != 中文测试 then - return -1 -endi -# if $data11 != NULL then -# return -1 -# endi - -print ====> select c2, substr(c2,1, 4) from ntb6 -sql select c2, substr(c2,1, 4) from ntb6 -print ====> rows: $rows -print ====> $data00 $data01 -print ====> $data10 $data11 -if $rows != 2 then - return -1 -endi -if $data00 != 中文测试01 then - return -1 -endi -if $data01 != 中文测试 then - return -1 -endi -if $data11 != NULL then - return -1 -endi - -#sql_error select c1, length(t1), c2, length(t2) from ctb0 - -print ====> char_length -print ====> select c1, char_length(c1), c2, char_length(c2) from ctb0 -sql select c1, char_length(c1), c2, char_length(c2) from ctb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data21 != 12 then - return -1 -endi -if $data23 != 12 then - return -1 -endi -if $data31 != 14 then - return -1 -endi -if $data33 != 14 then - return -1 -endi - -print ====> select c1, char_length(c1), c2, char_length(c2) from ntb0 -sql select c1, char_length(c1), c2, char_length(c2) from ntb0 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -print ====> $data20 $data21 $data22 $data23 $data24 $data25 -print ====> $data30 $data31 $data32 $data33 $data34 $data35 -if $rows != 4 then - return -1 -endi -if $data21 != 12 then - return -1 -endi -if $data23 != 12 then - return -1 -endi -if $data31 != 14 then - return -1 -endi -if $data33 != 14 then - return -1 -endi - -#sql_error select c1, char_length(t1), c2, char_length(t2) from ctb0 - -print ====> lower -sql select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ntb1 -print ====> select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ctb1 -sql select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ctb1 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -if $rows != 2 then - return -1 -endi -if $data01 != abcd1234 then - return -1 -endi -if $data03 != abcd1234 then - return -1 -endi -if $data04 != abcdefgh=-*&% then - return -1 -endi -if $data11 != aabbccdd1234 then - return -1 -endi -if $data13 != aabbccdd1234 then - return -1 -endi -if $data14 != abcdefgh=-*&% then - return -1 -endi - -#sql_error select c1, lower(t1), c2, lower(t2) from ctb1 - -print ====> upper -sql select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ntb2 -print ====> select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ctb2 -sql select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ctb2 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 -if $rows != 2 then - return -1 -endi -if $data01 != ABCD1234 then - return -1 -endi -if $data03 != ABCD1234 then - return -1 -endi -if $data04 != ABCDEFGH=-*&% then - return -1 -endi -if $data11 != AABBCCDD1234 then - return -1 -endi -if $data13 != AABBCCDD1234 then - return -1 -endi -if $data14 != ABCDEFGH=-*&% then - return -1 -endi - -#sql_error select c1, upper(t1), c2, upper(t2) from ctb2 - -print ====> ltrim -sql select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ntb3 -print ====> select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ctb3 -sql select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ctb3 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 -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, 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 - -#sql_error select c1, rtrim(t1), c2, rtrim(t2) from ctb3 - -print ====> concat -sql select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ntb4 -print ====> select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ctb4 -sql select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ctb4 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -if $rows != 1 then - return -1 -endi -if $data02 != @ ab 12 cd 34 @ then - return -1 -endi -if $data05 != @ ab 12 cd 34 @ then - return -1 -endi -if $data06 != @binary+ ab 12 cd 34 @ then - return -1 -endi -if $data07 != @nchar+ ab 12 cd 34 @ then - return -1 -endi - -sql select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "-a2-", c4, "-a3-", "a4-", "END") from ntb4 -print ====> select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "a2-", c4, "-a3-", "a4-", "END") from ctb4 -sql select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "a2-", c4, "-a3-", "a4-", "END") from ctb4 -print ====> rows: $rows -print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] -print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -if $rows != 1 then - return -1 -endi -if $data02 != @bin- ab 12 -a1-a2- cd 34 -a3-a4-END@ then - return -1 -endi -if $data05 != @nchar- ab 12 -a1-a2- cd 34 -a3-a4-END@ then - return -1 -endi - -#sql_error select c1, c2, concat(c1, c2), c3, c4, concat(c3, c4) from ctb4 -#sql_error select t1, t2, concat(t1, t2), t3, t4, concat(t3, t4) from ctb4 -#sql_error select t1, t3, concat(t1, t3), t2, t4, concat(t2, t4) from ctb4 - -print ====> concat_ws -sql select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ntb4 -print ====> select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ctb4 -sql select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ctb4 -print ====> rows: $rows -print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 -print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -if $rows != 1 then - return -1 -endi -if $data02 != @ ab 12 * cd 34 @ then - return -1 -endi -if $data05 != @ ab 12 * cd 34 @ then - return -1 -endi -if $data06 != @binary+* ab 12 * cd 34 @ then - return -1 -endi -if $data07 != @nchar+* ab 12 * cd 34 @ then - return -1 -endi - -print ====> select c1, c3, concat_ws("*", "b0", c1, "b1", c3, "b2", "E0", "E1", "E2"), c2, c4, concat_ws("*", "n0", c2, c4, "n1", c2, c4, "n2", "END") from ctb4 -sql select c1, c3, concat_ws("*", "b0", c1, "b1", c3, "b2", "E0", "E1", "E2"), c2, c4, concat_ws("*", "n0", c2, c4, "n1", c2, c4, "n2", "END") from ctb4 -print ====> rows: $rows -print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] -print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -if $rows != 1 then - return -1 -endi -if $data02 != @b0* ab 12 *b1* cd 34 *b2*E0*E1*E2@ then - return -1 -endi -if $data05 != @n0* ab 12 * cd 34 *n1* ab 12 * cd 34 *n2*END@ then - return -1 -endi - -#sql_error select c1, c2, concat_ws("*", c1, c2), c3, c4, concat_ws("*", c3, c4) from ctb4 -#sql_error select t1, t2, concat_ws("*", t1, t2), t3, t4, concat_ws("*", t3, t4) from ctb4 -#sql_error select t1, t3, concat_ws("*", t1, t3), t2, t4, concat_ws("*", t2, t4) from ctb4 - - -print ====> substr -#sql select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ntb5 -#print ====> select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ctb5 -#sql select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ctb5 -#print ====> rows: $rows -#print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 -#print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -#if $rows != 1 then -# return -1 -#endi -#if $data01 != 345 then -# return -1 -#endi -#if $data02 != 456 then -# return -1 -#endi -#if $data04 != 345 then -# return -1 -#endi -#if $data05 != 456 then -# return -1 -#endi -#if $data06 != def then -# return -1 -#endi -#if $data07 != efg then -# return -1 -#endi -#if $data11 != NULL then -# return -1 -#endi -#if $data12 != NULL then -# return -1 -#endi -#if $data14 != NULL then -# return -1 -#endi -#if $data15 != NULL then -# return -1 -#endi -#if $data16 != def then -# return -1 -#endi -#if $data17 != efg then -# return -1 -#endi -# -#sql select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ntb5 -#print ====> select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ctb5 -#sql select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ctb5 -#print ====> rows: $rows -#print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 -#print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 -#if $rows != 1 then -# return -1 -#endi -#if $data01 != 3456789 then -# return -1 -#endi -#if $data02 != 456789 then -# return -1 -#endi -#if $data04 != 3456789 then -# return -1 -#endi -#if $data05 != 456789 then -# return -1 -#endi -#if $data06 != defg then -# return -1 -#endi -#if $data07 != efg then -# return -1 -#endi -#if $data11 != NULL then -# return -1 -#endi -#if $data12 != NULL then -# return -1 -#endi -#if $data14 != NULL then -# return -1 -#endi -#if $data15 != NULL then -# return -1 -#endi -#if $data16 != defg then -# return -1 -#endi -#if $data17 != efg then -# return -1 -#endi - -#sql_error select t1, substr(t1, 3, 2), substr(t1, -3, 2), t2, substr(t2, 3, 2), substr(t2, -3, 2) from ctb5 - -if $loop_test == 0 then - print =============== stop and restart taosd - system sh/exec.sh -n dnode1 -s stop -x SIGINT - system sh/exec.sh -n dnode1 -s start - - $loop_cnt = 0 - check_dnode_ready_0: - $loop_cnt = $loop_cnt + 1 - sleep 200 - if $loop_cnt == 10 then - print ====> dnode not ready! - return -1 - endi - sql show dnodes - print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 - if $data00 != 1 then - return -1 - endi - if $data04 != ready then - goto check_dnode_ready_0 - endi - - $loop_test = 1 - goto loop_test_pos -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT From 5cc829e45f06d722d07c98fc82ab8a9fc8f257d0 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 20 Jul 2022 18:47:46 +0800 Subject: [PATCH 24/42] fix: use suid from pReader --- source/dnode/vnode/src/tsdb/tsdbRead.c | 31 ++------------------------ 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 7048dc7b2b..d4055f9482 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2572,41 +2572,14 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc return TSDB_CODE_SUCCESS; } -static tb_uid_t getTableSuidByUid(tb_uid_t uid, STsdb* pTsdb) { - tb_uid_t suid = 0; - - SMetaReader mr = {0}; - metaReaderInit(&mr, pTsdb->pVnode->pMeta, 0); - if (metaGetTableEntryByUid(&mr, uid) < 0) { - metaReaderClear(&mr); // table not esist - return 0; - } - - if (mr.me.type == TSDB_CHILD_TABLE) { - suid = mr.me.ctbEntry.suid; - } else if (mr.me.type == TSDB_NORMAL_TABLE) { - suid = 0; - } else { - suid = 0; - } - - metaReaderClear(&mr); - - return suid; -} - void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader) { int32_t sversion = TSDBROW_SVERSION(pRow); - tb_uid_t suid = getTableSuidByUid(uid, pReader->pTsdb); - if (pReader->pSchema == NULL) { - // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); - metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, suid, uid, sversion, &pReader->pSchema); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &pReader->pSchema); } else if (pReader->pSchema->version != sversion) { taosMemoryFreeClear(pReader->pSchema); - // pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, uid, sversion); - metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, suid, uid, sversion, &pReader->pSchema); + metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &pReader->pSchema); } } From ecaa0c64bbdeca42715c268fd53e22abfb215dff Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 18:52:27 +0800 Subject: [PATCH 25/42] test: no valgrind on win --- tests/script/tsim/query/charScalarFunction.sim | 1 - tests/system-test/fulltest.sh | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index ce140a116c..7a9b5a2b97 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -43,4 +43,3 @@ sql insert into ctb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) print ====> select c2 ,length(c2), char_length(c2) from ctb6 sql select c2 ,length(c2), char_length(c2) from ctb6 - diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 10bf3d39e3..dd5f3809e8 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -191,8 +191,8 @@ python3 ./test.py -f 7-tmq/tmqUpdate-multiCtb-snapshot0.py python3 ./test.py -f 7-tmq/tmqUpdate-multiCtb-snapshot1.py #python3 ./test.py -f 7-tmq/tmqDelete-1ctb.py python3 ./test.py -f 7-tmq/tmqUdf.py -python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot0.py -python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot1.py +# python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot0.py +# python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot1.py python3 ./test.py -f 7-tmq/stbTagFilter-1ctb.py python3 ./test.py -f 7-tmq/stbTagFilter-multiCtb.py From 946aef2181595d017b790a834288d54b7e508509 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 18:54:01 +0800 Subject: [PATCH 26/42] test: no valgrind on win --- .../script/tsim/query/charScalarFunction.sim | 684 ++++++++++++++++++ 1 file changed, 684 insertions(+) diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index 7a9b5a2b97..f1575d7293 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -35,11 +35,695 @@ print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $d sql use $dbNamme +print =============== create super table +sql create table stb (ts timestamp, c1 binary(128), c2 nchar(128)) tags (t1 binary(128), t2 nchar(128)) + +print =============== create child table and normal table, insert data +sql create table ctb0 using stb tags("tag-binary-0" , "tag-nchar-0" ) +sql create table ntb0 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb0 values ("2022-01-01 00:00:00.000" , "lenByte0=11" , "lenByte0=44" ) +sql insert into ntb0 values ("2022-01-01 00:00:00.000" , "lenByte0=11" , "lenByte0=44" ) +sql insert into ctb0 values ("2022-01-01 00:00:00.001" , "lenByte01=12" , "lenByte01=48" ) +sql insert into ntb0 values ("2022-01-01 00:00:00.001" , "lenByte01=12" , "lenByte01=48" ) +sql insert into ctb0 values ("2022-01-01 00:00:00.002" , "lenChar01=12" , "lenChar01=48" ) +sql insert into ntb0 values ("2022-01-01 00:00:00.002" , "lenChar01=12" , "lenChar01=48" ) +sql insert into ctb0 values ("2022-01-01 00:00:00.003" , "lenChar0001=14" , "lenChar0001=56" ) +sql insert into ntb0 values ("2022-01-01 00:00:00.003" , "lenChar0001=14" , "lenChar0001=56" ) + +sql create table ctb1 using stb tags("tag-binary-1" , "tag-nchar-1" ) +sql create table ntb1 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb1 values ("2022-01-01 00:00:00.000" , "ABCD1234" , "ABCD1234" ) +sql insert into ntb1 values ("2022-01-01 00:00:00.000" , "ABCD1234" , "ABCD1234" ) +sql insert into ctb1 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) +sql insert into ntb1 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) + +sql create table ctb2 using stb tags("tag-binary-2" , "tag-nchar-2" ) +sql create table ntb2 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb2 values ("2022-01-01 00:00:00.000" , "abcd1234" , "abcd1234" ) +sql insert into ntb2 values ("2022-01-01 00:00:00.000" , "abcd1234" , "abcd1234" ) +sql insert into ctb2 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) +sql insert into ntb2 values ("2022-01-01 00:00:00.001" , "AaBbCcDd1234" , "AaBbCcDd1234" ) + +sql create table ctb3 using stb tags("tag-binary-3" , "tag-nchar-3" ) +sql create table ntb3 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb3 values ("2022-01-01 00:00:00.000" , " abcd 1234 " , " abcd 1234 " ) +sql insert into ntb3 values ("2022-01-01 00:00:00.000" , " abcd 1234 " , " abcd 1234 " ) + +sql create table stb2 (ts timestamp, c1 binary(128), c2 nchar(128), c3 binary(128), c4 nchar(128)) tags (t1 binary(128), t2 nchar(128), t3 binary(128), t4 nchar(128)) +sql create table ctb4 using stb2 tags("tag-binary-4" , "tag-nchar-4", "tag-binary-4" , "tag-nchar-4") +sql create table ntb4 (ts timestamp, c1 binary(128), c2 nchar(128), c3 binary(128), c4 nchar(128)) +sql insert into ctb4 values ("2022-01-01 00:00:00.000" , " ab 12 " , " ab 12 " , " cd 34 " , " cd 34 " ) +sql insert into ntb4 values ("2022-01-01 00:00:00.000" , " ab 12 " , " ab 12 " , " cd 34 " , " cd 34 " ) + +sql create table ctb5 using stb tags("tag-binary-5" , "tag-nchar-5") +sql create table ntb5 (ts timestamp, c1 binary(128), c2 nchar(128)) +sql insert into ctb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456789" ) +sql insert into ntb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456789" ) +sql insert into ctb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) +sql insert into ntb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) + sql create table stb3 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) tags (t1 nchar(64)) sql create table ctb6 using stb3 tags("tag-nchar-6") +sql create table ntb6 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) sql insert into ctb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试1" , "中文测试2" ) +sql insert into ntb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试01", "中文测试01" ) sql insert into ctb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) +sql insert into ntb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) +$loop_test = 0 +loop_test_pos: + +print ====> length +print ====> select c1, length(c1), c2, length(c2) from ctb0 +sql select c1, length(c1), c2, length(c2) from ctb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data01 != 11 then + return -1 +endi +if $data03 != 44 then + return -1 +endi +if $data11 != 12 then + return -1 +endi +if $data13 != 48 then + return -1 +endi + +print ====> select c1, length(c1), c2, length(c2) from ntb0 +sql select c1, length(c1), c2, length(c2) from ntb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data01 != 11 then + return -1 +endi +if $data03 != 44 then + return -1 +endi +if $data11 != 12 then + return -1 +endi +if $data13 != 48 then + return -1 +endi + +print ====> select length("abcd1234"), char_length("abcd1234=-+*") from ntb0 +sql select length("abcd1234"), char_length("abcd1234=-+*") from ntb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data00 != 8 then + return -1 +endi +if $data01 != 12 then + return -1 +endi print ====> select c2 ,length(c2), char_length(c2) from ctb6 sql select c2 ,length(c2), char_length(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 20 then + return -1 +endi +if $data02 != 5 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,length(c2),char_length(c2) from ntb6 +sql select c2 ,length(c2),char_length(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 24 then + return -1 +endi +if $data02 != 6 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,lower(c2), upper(c2) from ctb6 +sql select c2 ,lower(c2), upper(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试1 then + return -1 +endi +if $data02 != 中文测试1 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,lower(c2), upper(c2) from ntb6 +sql select c2 ,lower(c2), upper(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试01 then + return -1 +endi +if $data02 != 中文测试01 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, ltrim(c2), ltrim(c2) from ctb6 +sql select c2, ltrim(c2), ltrim(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试1 then + return -1 +endi +if $data02 != 中文测试1 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, ltrim(c2), ltrim(c2) from ntb6 +sql select c2, ltrim(c2), ltrim(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试01 then + return -1 +endi +if $data02 != 中文测试01 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat(c2,c3) from ctb6 +sql select c2, c3 , concat(c2,c3) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试1中文测试2 then + return -1 +endi +if $data12 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat(c2,c3) from ntb6 +sql select c2, c3 , concat(c2,c3) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试01中文测试01 then + return -1 +endi +if $data12 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat_ws('_', c2, c3) from ctb6 +sql select c2, c3 , concat_ws('_', c2, c3) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试1_中文测试2 then + return -1 +endi +# if $data12 != NULL then +# return -1 +# endi + +print ====> select c2, c3 , concat_ws('_', c2, c3) from ntb6 +sql select c2, c3 , concat_ws('_', c2, c3) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试01_中文测试01 then + return -1 +endi +# if $data12 != NULL then +# return -1 +# endi + +print ====> select c2, substr(c2,1, 4) from ctb6 +sql select c2, substr(c2,1, 4) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 +print ====> $data10 $data11 +if $rows != 2 then + return -1 +endi +if $data00 != 中文测试1 then + return -1 +endi +if $data01 != 中文测试 then + return -1 +endi +# if $data11 != NULL then +# return -1 +# endi + +print ====> select c2, substr(c2,1, 4) from ntb6 +sql select c2, substr(c2,1, 4) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 +print ====> $data10 $data11 +if $rows != 2 then + return -1 +endi +if $data00 != 中文测试01 then + return -1 +endi +if $data01 != 中文测试 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +#sql_error select c1, length(t1), c2, length(t2) from ctb0 + +print ====> char_length +print ====> select c1, char_length(c1), c2, char_length(c2) from ctb0 +sql select c1, char_length(c1), c2, char_length(c2) from ctb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data21 != 12 then + return -1 +endi +if $data23 != 12 then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data33 != 14 then + return -1 +endi + +print ====> select c1, char_length(c1), c2, char_length(c2) from ntb0 +sql select c1, char_length(c1), c2, char_length(c2) from ntb0 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +print ====> $data20 $data21 $data22 $data23 $data24 $data25 +print ====> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 4 then + return -1 +endi +if $data21 != 12 then + return -1 +endi +if $data23 != 12 then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data33 != 14 then + return -1 +endi + +#sql_error select c1, char_length(t1), c2, char_length(t2) from ctb0 + +print ====> lower +sql select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ntb1 +print ====> select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ctb1 +sql select c1, lower(c1), c2, lower(c2), lower("abcdEFGH=-*&%") from ctb1 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data01 != abcd1234 then + return -1 +endi +if $data03 != abcd1234 then + return -1 +endi +if $data04 != abcdefgh=-*&% then + return -1 +endi +if $data11 != aabbccdd1234 then + return -1 +endi +if $data13 != aabbccdd1234 then + return -1 +endi +if $data14 != abcdefgh=-*&% then + return -1 +endi + +#sql_error select c1, lower(t1), c2, lower(t2) from ctb1 + +print ====> upper +sql select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ntb2 +print ====> select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ctb2 +sql select c1, upper(c1), c2, upper(c2), upper("abcdEFGH=-*&%") from ctb2 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data01 != ABCD1234 then + return -1 +endi +if $data03 != ABCD1234 then + return -1 +endi +if $data04 != ABCDEFGH=-*&% then + return -1 +endi +if $data11 != AABBCCDD1234 then + return -1 +endi +if $data13 != AABBCCDD1234 then + return -1 +endi +if $data14 != ABCDEFGH=-*&% then + return -1 +endi + +#sql_error select c1, upper(t1), c2, upper(t2) from ctb2 + +print ====> ltrim +sql select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ntb3 +print ====> select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ctb3 +sql select c1, ltrim(c1), c2, ltrim(c2), ltrim(" abcdEFGH =-*&% ") from ctb3 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 +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, 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 + +#sql_error select c1, rtrim(t1), c2, rtrim(t2) from ctb3 + +print ====> concat +sql select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ntb4 +print ====> select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ctb4 +sql select c1, c3, concat(c1, c3), c2, c4, concat(c2, c4), concat("binary+", c1, c3), concat("nchar+", c2, c4) from ctb4 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $rows != 1 then + return -1 +endi +if $data02 != @ ab 12 cd 34 @ then + return -1 +endi +if $data05 != @ ab 12 cd 34 @ then + return -1 +endi +if $data06 != @binary+ ab 12 cd 34 @ then + return -1 +endi +if $data07 != @nchar+ ab 12 cd 34 @ then + return -1 +endi + +sql select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "-a2-", c4, "-a3-", "a4-", "END") from ntb4 +print ====> select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "a2-", c4, "-a3-", "a4-", "END") from ctb4 +sql select c1, c3, concat("bin-", c1, "-a1-", "a2-", c3, "-a3-", "a4-", "END"), c2, c4, concat("nchar-", c2, "-a1-", "a2-", c4, "-a3-", "a4-", "END") from ctb4 +print ====> rows: $rows +print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] +print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $rows != 1 then + return -1 +endi +if $data02 != @bin- ab 12 -a1-a2- cd 34 -a3-a4-END@ then + return -1 +endi +if $data05 != @nchar- ab 12 -a1-a2- cd 34 -a3-a4-END@ then + return -1 +endi + +#sql_error select c1, c2, concat(c1, c2), c3, c4, concat(c3, c4) from ctb4 +#sql_error select t1, t2, concat(t1, t2), t3, t4, concat(t3, t4) from ctb4 +#sql_error select t1, t3, concat(t1, t3), t2, t4, concat(t2, t4) from ctb4 + +print ====> concat_ws +sql select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ntb4 +print ====> select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ctb4 +sql select c1, c3, concat_ws("*", c1, c3), c2, c4, concat_ws("*", c2, c4), concat_ws("*", "binary+", c1, c3), concat_ws("*", "nchar+", c2, c4) from ctb4 +print ====> rows: $rows +print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 +print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $rows != 1 then + return -1 +endi +if $data02 != @ ab 12 * cd 34 @ then + return -1 +endi +if $data05 != @ ab 12 * cd 34 @ then + return -1 +endi +if $data06 != @binary+* ab 12 * cd 34 @ then + return -1 +endi +if $data07 != @nchar+* ab 12 * cd 34 @ then + return -1 +endi + +print ====> select c1, c3, concat_ws("*", "b0", c1, "b1", c3, "b2", "E0", "E1", "E2"), c2, c4, concat_ws("*", "n0", c2, c4, "n1", c2, c4, "n2", "END") from ctb4 +sql select c1, c3, concat_ws("*", "b0", c1, "b1", c3, "b2", "E0", "E1", "E2"), c2, c4, concat_ws("*", "n0", c2, c4, "n1", c2, c4, "n2", "END") from ctb4 +print ====> rows: $rows +print ====> [ $data00 ] [ $data01 ] [ $data02 ] [ $data03 ] [ $data04 ] [ $data05 ] [ $data06 ] +print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $rows != 1 then + return -1 +endi +if $data02 != @b0* ab 12 *b1* cd 34 *b2*E0*E1*E2@ then + return -1 +endi +if $data05 != @n0* ab 12 * cd 34 *n1* ab 12 * cd 34 *n2*END@ then + return -1 +endi + +#sql_error select c1, c2, concat_ws("*", c1, c2), c3, c4, concat_ws("*", c3, c4) from ctb4 +#sql_error select t1, t2, concat_ws("*", t1, t2), t3, t4, concat_ws("*", t3, t4) from ctb4 +#sql_error select t1, t3, concat_ws("*", t1, t3), t2, t4, concat_ws("*", t2, t4) from ctb4 + + +print ====> substr +#sql select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ntb5 +#print ====> select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ctb5 +#sql select c1, substr(c1, 3, 3), substr(c1, -5, 3), c2, substr(c2, 3, 3), substr(c2, -5, 3), substr("abcdefg", 3, 3), substr("abcdefg", -3, 3) from ctb5 +#print ====> rows: $rows +#print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 +#print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +#if $rows != 1 then +# return -1 +#endi +#if $data01 != 345 then +# return -1 +#endi +#if $data02 != 456 then +# return -1 +#endi +#if $data04 != 345 then +# return -1 +#endi +#if $data05 != 456 then +# return -1 +#endi +#if $data06 != def then +# return -1 +#endi +#if $data07 != efg then +# return -1 +#endi +#if $data11 != NULL then +# return -1 +#endi +#if $data12 != NULL then +# return -1 +#endi +#if $data14 != NULL then +# return -1 +#endi +#if $data15 != NULL then +# return -1 +#endi +#if $data16 != def then +# return -1 +#endi +#if $data17 != efg then +# return -1 +#endi +# +#sql select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ntb5 +#print ====> select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ctb5 +#sql select c1, substr(c1, 3), substr(c1, -5), c2, substr(c2, 3), substr(c2, -5), substr("abcdefg", 3), substr("abcdefg", -3) from ctb5 +#print ====> rows: $rows +#print ====> $data00 $data01 $data02 $data03 $data04 $data05 $data06 +#print ====> $data10 $data11 $data12 $data13 $data14 $data15 $data16 +#if $rows != 1 then +# return -1 +#endi +#if $data01 != 3456789 then +# return -1 +#endi +#if $data02 != 456789 then +# return -1 +#endi +#if $data04 != 3456789 then +# return -1 +#endi +#if $data05 != 456789 then +# return -1 +#endi +#if $data06 != defg then +# return -1 +#endi +#if $data07 != efg then +# return -1 +#endi +#if $data11 != NULL then +# return -1 +#endi +#if $data12 != NULL then +# return -1 +#endi +#if $data14 != NULL then +# return -1 +#endi +#if $data15 != NULL then +# return -1 +#endi +#if $data16 != defg then +# return -1 +#endi +#if $data17 != efg then +# return -1 +#endi + +#sql_error select t1, substr(t1, 3, 2), substr(t1, -3, 2), t2, substr(t2, 3, 2), substr(t2, -3, 2) from ctb5 + +if $loop_test == 0 then + print =============== stop and restart taosd + system sh/exec.sh -n dnode1 -s stop -x SIGINT + system sh/exec.sh -n dnode1 -s start + + $loop_cnt = 0 + check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + sql show dnodes + print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 + if $data00 != 1 then + return -1 + endi + if $data04 != ready then + goto check_dnode_ready_0 + endi + + $loop_test = 1 + goto loop_test_pos +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT From 94b3e9d2f097d01335235b19a4ec5764e5e490fa Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 20 Jul 2022 19:00:55 +0800 Subject: [PATCH 27/42] refactor(sync): add trace log --- source/libs/sync/src/syncMain.c | 6 +++--- source/libs/sync/src/syncRaftStore.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 1c2d4c793c..1cefdf73ef 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -2990,8 +2990,8 @@ void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMs syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:" PRIu64 ", pre-index:" PRId64 ", pre-term:" PRIu64 - ", commit:" PRId64 ", pterm:" PRIu64 + "recv sync-append-entries from %s:%d {term:%" PRIu64 ", pre-index:%" PRIu64 ", pre-term:%" PRIu64 + ", commit:%" PRIu64 ", pterm:%" PRIu64 ", " "datalen:%d}, %s", host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, @@ -3043,7 +3043,7 @@ void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:" PRIu64 ", pterm:" PRIu64 ", success:%d, match:" PRId64 + "recv sync-append-entries-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRIu64 "}, %s", host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); syncNodeErrorLog(pSyncNode, logBuf); diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index e7fa757c36..f552570337 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -224,25 +224,25 @@ char *raftStore2Str(SRaftStore *pRaftStore) { // for debug ------------------- void raftStorePrint(SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - printf("raftStorePrint | len:" PRIu64 " | %s \n", strlen(serialized), serialized); + printf("raftStorePrint | len:%" PRIu64 " | %s \n", strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } void raftStorePrint2(char *s, SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - printf("raftStorePrint2 | len:" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); + printf("raftStorePrint2 | len:%" PRIu64 " | %s | %s \n", strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } void raftStoreLog(SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - sTrace("raftStoreLog | len:" PRIu64 " | %s", strlen(serialized), serialized); + sTrace("raftStoreLog | len:%" PRIu64 " | %s", strlen(serialized), serialized); taosMemoryFree(serialized); } void raftStoreLog2(char *s, SRaftStore *pObj) { char *serialized = raftStore2Str(pObj); - sTrace("raftStoreLog2 | len:" PRIu64 " | %s | %s", strlen(serialized), s, serialized); + sTrace("raftStoreLog2 | len:%" PRIu64 " | %s | %s", strlen(serialized), s, serialized); taosMemoryFree(serialized); } From 3491896b7a24477a564b2cd34df0bfd079c4fa9d Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 20 Jul 2022 19:12:02 +0800 Subject: [PATCH 28/42] refactor(sync): add trace log --- source/libs/sync/src/syncMain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 1cefdf73ef..b769bf5273 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -3043,7 +3043,7 @@ void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); char logBuf[256]; snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRIu64 + "recv sync-append-entries-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64 "}, %s", host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); syncNodeErrorLog(pSyncNode, logBuf); From 6275ac14c7adbaae5d4ea351f80cfb3e0fb6d9f0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 19:24:41 +0800 Subject: [PATCH 29/42] test: adjust case --- tests/script/tsim/parser/first_last_query.sim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/script/tsim/parser/first_last_query.sim b/tests/script/tsim/parser/first_last_query.sim index c52a5b45d6..a001b929c3 100644 --- a/tests/script/tsim/parser/first_last_query.sim +++ b/tests/script/tsim/parser/first_last_query.sim @@ -223,7 +223,7 @@ return -1 endi print ===================>td-1477, one table has only one block occurs this bug. -sql select _wstart, first(size), count(*), LAST(SIZE), tbname from stest where tbname in ('test1', 'test2') partition by tbname interval(1d) ; +sql select _wstart, first(size), count(*), LAST(SIZE), tbname from stest where tbname in ('test1', 'test2') partition by tbname interval(1d) order by tbname asc; if $rows != 2 then return -1 endi From fb52cfa816f6428bd33ba3c225afc4475043df90 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 20 Jul 2022 19:31:56 +0800 Subject: [PATCH 30/42] fix(stream): memory error --- source/dnode/vnode/src/inc/tq.h | 4 ++++ source/dnode/vnode/src/inc/vnodeInt.h | 1 + source/dnode/vnode/src/tq/tq.c | 23 ++++++++++++++++++++++- source/libs/executor/src/scanoperator.c | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index 07bee22a1f..abac77dc01 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -108,6 +108,10 @@ typedef struct { // exec STqExecHandle execHandle; + + // prevent drop + int64_t ntbUid; + SArray* colIdList; // SArray } STqHandle; struct STQ { diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index fd0f97a638..d785376925 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -142,6 +142,7 @@ void tqClose(STQ*); int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver); int tqCommit(STQ*); int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd); +int32_t tqCheckColModifiable(STQ* pTq, int32_t colId); int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen); diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 208b5d3fa0..b2679ee245 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -208,6 +208,26 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen) { return 0; } +int32_t tqCheckColModifiable(STQ* pTq, int32_t colId) { + void* pIter = NULL; + while (1) { + pIter = taosHashIterate(pTq->handles, pIter); + if (pIter == NULL) break; + STqHandle* pExec = (STqHandle*)pIter; + if (pExec->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { + int32_t sz = taosArrayGetSize(pExec->colIdList); + for (int32_t i = 0; i < sz; i++) { + int32_t forbidColId = *(int32_t*)taosArrayGet(pExec->colIdList, i); + if (forbidColId == colId) { + taosHashCancelIterate(pTq->handles, pIter); + return -1; + } + } + } + } + return 0; +} + static int32_t tqInitDataRsp(SMqDataRsp* pRsp, const SMqPollReq* pReq, int8_t subType) { pRsp->reqOffset = pReq->reqOffset; @@ -752,8 +772,9 @@ int32_t tqProcessTaskDropReq(STQ* pTq, char* msg, int32_t msgLen) { SStreamTask** ppTask = (SStreamTask**)taosHashGet(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); if (ppTask) { + SStreamTask* pTask = *ppTask; taosHashRemove(pTq->pStreamTasks, &pReq->taskId, sizeof(int32_t)); - atomic_store_8(&(*ppTask)->taskStatus, TASK_STATUS__DROPPING); + atomic_store_8(&pTask->taskStatus, TASK_STATUS__DROPPING); } // todo // clear queue diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 2e78b61b8c..fcadffa4d0 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -1519,6 +1519,7 @@ static void destroyStreamScanOperatorInfo(void* param, int32_t numOfOutput) { blockDataDestroy(pStreamScan->pPullDataRes); blockDataDestroy(pStreamScan->pDeleteDataRes); taosArrayDestroy(pStreamScan->pBlockLists); + taosArrayDestroy(pStreamScan->tsArray); taosMemoryFree(pStreamScan); } From b77e0a6750a8f765e5683418254a2fb345dddceb Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 20 Jul 2022 19:58:26 +0800 Subject: [PATCH 31/42] refactor(sync): add trace log --- source/libs/sync/src/syncIndexMgr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/libs/sync/src/syncIndexMgr.c b/source/libs/sync/src/syncIndexMgr.c index a9c1147fc1..39bede23f6 100644 --- a/source/libs/sync/src/syncIndexMgr.c +++ b/source/libs/sync/src/syncIndexMgr.c @@ -79,8 +79,7 @@ SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaf } } - syncNodeLog3("syncIndexMgrGetIndex", pSyncIndexMgr->pSyncNode); - ASSERT(0); + return SYNC_INDEX_INVALID; } cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) { @@ -126,7 +125,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) { char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) { cJSON *pJson = syncIndexMgr2Json(pSyncIndexMgr); - char * serialized = cJSON_Print(pJson); + char *serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } From e300ba82c41eeeb95100bb78476805c745fc112c Mon Sep 17 00:00:00 2001 From: "wenzhouwww@live.cn" Date: Wed, 20 Jul 2022 20:19:32 +0800 Subject: [PATCH 32/42] test: bug fix and case update --- tests/system-test/2-query/last_row.py | 81 +++++++++++---------------- 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/tests/system-test/2-query/last_row.py b/tests/system-test/2-query/last_row.py index e2b5cad361..105dc883c7 100644 --- a/tests/system-test/2-query/last_row.py +++ b/tests/system-test/2-query/last_row.py @@ -292,63 +292,50 @@ class TDTestCase: tdSql.checkData(0, 0, None) # support regular query about last ,first ,last_row - # tdSql.query("select last_row(c1,NULL) from testdb.t1") - # tdSql.checkData(0,0,None) - # tdSql.checkData(0,1,None) + tdSql.error("select last_row(c1,NULL) from testdb.t1") + tdSql.error("select last_row(NULL) from testdb.t1") + tdSql.error("select last(NULL) from testdb.t1") + tdSql.error("select first(NULL) from testdb.t1") - # tdSql.query("select last_row(c1,123) from testdb.t1") - # tdSql.checkData(0,0,None) - # tdSql.checkData(0,1,123) + tdSql.query("select last_row(c1,123) from testdb.t1") + tdSql.checkData(0,0,None) + tdSql.checkData(0,1,123) - # tdSql.query("select last(c1,NULL) from testdb.t1") - # tdSql.checkData(0,0,9) - # tdSql.checkData(0,1,None) + tdSql.query("select last_row(123) from testdb.t1") + tdSql.checkData(0,0,123) - # tdSql.query("select last(c1,123) from testdb.t1") - # tdSql.checkData(0,0,9) - # tdSql.checkData(0,1,123) + tdSql.error("select last(c1,NULL) from testdb.t1") - # tdSql.query("select first(c1,NULL) from testdb.t1") - # tdSql.checkData(0,0,1) - # tdSql.checkData(0,1,None) + tdSql.query("select last(c1,123) from testdb.t1") + tdSql.checkData(0,0,9) + tdSql.checkData(0,1,123) - # tdSql.query("select first(c1,123) from testdb.t1") - # tdSql.checkData(0,0,1) - # tdSql.checkData(0,1,123) + tdSql.error("select first(c1,NULL) from testdb.t1") - # tdSql.query("select last_row(c1,c2,c3,NULL,c4) from testdb.t1") - # tdSql.checkData(0,0,None) - # tdSql.checkData(0,1,None) - # tdSql.checkData(0,2,None) - # tdSql.checkData(0,3,None) - # tdSql.checkData(0,4,None) + tdSql.query("select first(c1,123) from testdb.t1") + tdSql.checkData(0,0,1) + tdSql.checkData(0,1,123) - # tdSql.query("select last_row(c1,c2,c3,123,c4) from testdb.t1") - # tdSql.checkData(0,0,None) - # tdSql.checkData(0,1,None) - # tdSql.checkData(0,2,None) - # tdSql.checkData(0,3,123) - # tdSql.checkData(0,4,None) + tdSql.error("select last_row(c1,c2,c3,NULL,c4) from testdb.t1") + + tdSql.query("select last_row(c1,c2,c3,123,c4) from testdb.t1") + tdSql.checkData(0,0,None) + tdSql.checkData(0,1,None) + tdSql.checkData(0,2,None) + tdSql.checkData(0,3,123) + tdSql.checkData(0,4,None) - # tdSql.query("select last_row(c1,c2,c3,NULL,c4,t1,t2) from testdb.ct1") - # tdSql.checkData(0,0,9) - # tdSql.checkData(0,1,-99999) - # tdSql.checkData(0,2,-999) - # tdSql.checkData(0,3,None) - # tdSql.checkData(0,4,None) - # tdSql.checkData(0,5,0) - # tdSql.checkData(0,5,0) - - # tdSql.query("select last_row(c1,c2,c3,123,c4,t1,t2) from testdb.ct1") - # tdSql.checkData(0,0,9) - # tdSql.checkData(0,1,-99999) - # tdSql.checkData(0,2,-999) - # tdSql.checkData(0,3,123) - # tdSql.checkData(0,4,None) - # tdSql.checkData(0,5,0) - # tdSql.checkData(0,5,0) + tdSql.error("select last_row(c1,c2,c3,NULL,c4,t1,t2) from testdb.ct1") + tdSql.query("select last_row(c1,c2,c3,123,c4,t1,t2) from testdb.ct1") + tdSql.checkData(0,0,9) + tdSql.checkData(0,1,-99999) + tdSql.checkData(0,2,-999) + tdSql.checkData(0,3,123) + tdSql.checkData(0,4,None) + tdSql.checkData(0,5,0) + tdSql.checkData(0,5,0) # # bug need fix tdSql.query("select last_row(c1), c2, c3 , c4, c5 from testdb.t1") From 987597917a5bfaa8cceff1b3c9844dff0803fa2d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 20 Jul 2022 20:22:08 +0800 Subject: [PATCH 33/42] fix: rm invalid file --- source/libs/transport/src/.transComm.c.swo | Bin 28672 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 source/libs/transport/src/.transComm.c.swo diff --git a/source/libs/transport/src/.transComm.c.swo b/source/libs/transport/src/.transComm.c.swo deleted file mode 100644 index 72ffc92ce91fc2c808e34fe9b349cc0bff6709f0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28672 zcmeI53virQb;p+^glC#SC=Bl#1v@KQvMeV~9NSTlSF$avm!(x4ClfTQ-EXCh_vLTD zwWZh&lk#e(3@HP&kU*JI2pw7;<=`gFw-`elHuXE2i_uPBVJ*zBkyJ39N?A$t(;^&f7>NT~mFNU}Fq%J&_N`(=OU zpv!?S2f7^Sa-hqBE(f|C=yIUTf!`PoMD@p~UdC+Bb2B>bem}0`_XY0x4)^;+NBQI3 z^K0Gj2Rq6ybkDcD->-55_;Jp6@AtXi7dV1^xqIFH)#X5!16>YuInd=mmjhi6bUD!F zK$inu4sH+Wua1d+; zmxHfgluF$Rejl6$r$7J-U<>F2mx70%no2zc-V5FgUJiZ-l)(^q9QfQ*QmOZW_kuiF z1X(Z(4uK27PoJDh{RDgiybaXARp9yHdEkL3rBdGm_k%wHuLFx<61)hcz>lApO8p4@ z5WEB239bYE;JM&g;F;hnPe`Rsg5%&~@W%u)-UKS(I`ATJKKK>^kZ*#!!R?>|7QrEK zJ=hIi1b!P_3jTqB%6;Gi;1%HI;AU_T>;~6@o#5Hv0`MRKl3##(!No*k?dLv|x1ak>^Y{Wy z7ot8sQP^uvrcTpI7(~smYPRj>Gvx!rQ7y`q&2?sANM2QfN+XEUl=Pcz{iad6EvOaK zeLVN}?rsgADF?ZbUZJdgc&WI~NJ?|Ek75 zxv;Od(pWMBp3b?f-s!4H@ZN*%<5ok9EB3}-wFiu%1f~g%3!es{Lo#UIOhs>Tjy+RJ-x4r5!bt$Al zy8XROONMdMiiaH>G^I+tY|3azm|CpW%9ilaAWuJG(2&Vn&ItMa2D+}?z7QEmjUW0< zk;e`(HJbUnjM%|tD<{uJsRXexIV=I`idXzAtxuZ(2EjDLkEeypMsMbn86n{8(EW~(iGglzQH ztBMGLA^QgPUz1%9OtBO;B2y$;%q*@(LBo_9h9zmDnk>kO8V!V9EhMYt!oW16Qkm6? zCfCf-AgF8AT390YjP=d1OVP3zl?qCdTMF!e%zRZVdal!6bXNu~Q<1V8b@!#X=z{=9=Y5 z)WPWhEKsd6E$y(XlQa>kv{oTIRGT@Bg<&mB_Y`xbvgLD5tgsks%qDgTk%V4tF~oL3 z!VmP%YFj)VOFkNcb|y`cF>2LBY0JaBGV)_*YEND3$Vn>NlO7TZs!>Vo4AMC#K{cWr9mI!$Qne9HE+Mdv_hC@f*ZzIB zkX;T@j_GPXu*6K(3e9pLnue5SvIl0zMn)H=r!r#;<5S~VG~n`5HD7KP0@GuUe3I0> z+#~OcSY$IlH?}Z;LrOQiK9eigs!QfXiH#{*X3waHwWTmu*=oj%rdpHr8U$v~aun5f z4Gx|-aboLIwYjwxE|Ei>52}rzF*v-HzRZzY(=?WA&2qsk=Z*)kHXoE^>&~I~^;OyR zWZ&FBHE%}b$XYY|gK7}6EzUF->B~&m{^(1(+c%z_!ZMnD)3av8%#6%t$20R2BeP~^ zes*ShZcN7%o-Abp& zKs*PbPKGmArE%6=#AXCxLyiGgt~bA;4BK$S?lP;$F3%Z*>GUJG*6bm=S{P(5m0F=x zTy=BHAWzOT%MpjGUbB7M(6uHzGCgNTakl!+cs0M(?74NBjq}B_d5QzIm5q2f#UVue z|DWL3s$Y!%zt1^`U&P;k3%Cm$1%u%E;Mw5E`24Q`b#N;vg2P}QWWhDyzw!6K2JQjx z0IvYc;2;Yea@M&;2cr&Ph!{8v;4+g*%AUwJpbbq=W z=yIUTfi4HS9O!c3H=hHS2UQMR>PfeP4;pSI4pb-y>enV?3lb_3pU)O2Lm928>L|W9 z(UGy01KNl4U|fd;z@$GH36Mc&1A@zqU^XbGtwSQ`!s2*A$0ooK+H#3_1VplJKPmhr z4Ros8;kt-N^o71Zp0B=&sHp9?BgSj#>lIQ)^2eH`aAQ((w!DKB>m^&~%~m)!LM$^X z#0qCO;>G#|_~|-cNDpUEL5DO(3Wen8buWbtM^?t#$rlP64(lQbJ_s#S&6I0a>XjuM z9YWT5c_(5@#4UV1T-CInsWe%uNz?V9D#T03q2Cmn)qG5Sp`h*+vC^72w>F;cdsFIN zV>gP%!E7|dr2Dihrzd_~Z6vB5)>g-=$J2f&f|Iy6LG^gs6nNLHr!|VwHtPN$8n@oL z6f$$Yt?>>!VZF}U%uh&6REAr;*-hPe9k<;0^k${A<;N4el{*u0>7m*aT@nw!on{R$ zDZ!#4+NfO;8dJ~?))ZQjD02aacH7_?<^;&aRjsi=$eZ!gJ@Yp#WHU1hbK_I{C&m^= zGMTZNEYbg-p&lK|afWDwsE`-<4kG159hJUuJaMgRiIAEy;e>d1Y~#oAp~F_KN3vs; z6<%_+xO)zHVM|<@h`B^dsuCm14GahM#?7T$wib^Sh!Zb%JZoTa-=Wbd4Jw+; zh>@97r%bDve1}|Kw;IYD5tGqqw5$+Q(vTXz_DIWWvoc*At2cI=(v~f@rX|@aTTH4D znyBxF@y#6_rRqE@)KZ|IrN>qzcdR~#MmNTeH3_WF=@W6Ee&atbN_ADJY?#Xj>7Gpu zi9gb(jg{-|OP7ag3LSyO{QNt>Nw5!$fnM+o@K5;np9Aj$Zvl6MJAlLiwu6hokMQg72Y(CR3~mBP zz}4Ux;1X~FI1hXipZ+gE04Bk+fcW@d0G|P;z)`RS4ug4c0XQFg5kFpX0Dcb?!6Fz3 z2f!Y%3tS6+3;Yz{{j=b&!H2FhAl)yAN2)2Mr!PCI~XtTOn{dF$p?5M_!aVf5d0^&7rY1D2^PUi z!7bo=um$u2(T6KQ{3Gg^k5&eTbKz2hr6c#mqI6D}I{sxFi=uD}KEu+Q*F1En+*C6h^U;joK?XVS~(1VvA`t zXrm+9k%jD$8DhcXQ(3~3az)&44vfqlSeTk#n3&ESR2Fam(2dCMC(%lB2aQ&Aw6(;k zHF2hltt8i2t>)QHs)e+E)Q+vF=$_5CSWEYCi+5DQjl?|lW4_jito;%D*&A4ih&>F- zX4vfDqCyNTWqR7-rQLs+bhg9=Ym}?h=Ns%0WF`=1x2j_|;Yk9!EAu)`dNUHQ3=CJ` zs#H2OKQ=$MFf%`Qz?U53cBtPR(^6q-qKgSg_SJj`o*wRx*QZCdVQxfNf?`%wiz?Jr z&I}AoxKs#<*+%k+7Ext$y3U0kYeE{cV-;3zNwCtEm53OxP}gQez^%mVEn8rmeXc42 zmW9ZmS~Jyv(^y3~W0r$Z?xyLVj^y7>ZLNenrs>KP{U?%1wEH=cxSi?@gmW9ozwojd zG=n}^>bD)Znn)^K8U znaCDqsXne@mM-kp+Gv}fT_bYYuq_m4v$-c%h;Rsq4?m? zs_ia@6HFCrlrGn5b-7Vt9dN_E=*B*qHS-u5596#rbS&A4&Oml+{9Z1Vl7dtMlP~C~ zahtHlzHD2yoh#KNd%@18tjI|F~H}*$!W8t=q)ix=tTC>P)?`=!@ipAB>Ezst78^* zJBbN$wqozb*>!Q%`D#6vKPtDvb|2)EO}$`E$OowRF61_K2;-JBXKaTf!pi0PHOx1; zlXH(bZlXJTl$Gr^+t_cgtKGfz*tk@Dp(C$YVTh{Bta z&YCV=K}4V$qM;y|Fd+k}nUgoYHq~nx&TO@XDzrFt%%v1=mI|6YVyQ(^v2~Cln^@@c z!5q)oxN-&6&*Vhoi3|+2O;8vx+>u=4IwBP!=|IiWt)#=0@rT<}EgcV}x_RowF!GEF&KNKvhB$S(V?6KT&GDB$IKeiYd$$@Y`$bF32|@^04^67 z18t>oT}LNw;5adnXOResZgXN=_Q&mRp1@d*rJhw|H#KFZX5gHJk!=~p!eysxN~w$C z@QQP$7!=<-_1dzpxX9QI<%?S zVx%;2TFc#AX`}u>E`2I5z8?PnYn{XQcf5Q*cq6ETNpKC=0`yT{f1#bX{K?V$hXMhXA1>oEG|B?gnZcqo3 z1279VgA2ib5CixY_-F8S@Cop7@Jg@*roj|=F&GBV0S^-g_%`?gkeI;<@KSISxDgx% zPX^y27Vs|cPEZFofH5!v40w`8n_Qg4B-tR0!2^& zqC*l-==@1+hxI5F#h0}>LJrXCEGeR#QPcq$7(PZEKuwVv2I zdgTbsuB$7jx7XJY&1q54TD|H>6OVJdvTK#h0anTqfi!)N7q1)D57RcfxYuf0RJkl; zgvW_+NEq12m1S&ufeiz=!=L5KY;dfP1M4y7YrT946Q;@Hj*ERL%!kTm$0nz57)vj^ zZj=RmW;yQQ0NJT&OM{E1UgqKla|>gWGua~)3e$C-YRaHNSzvuO*I^tia@Lby)(dQ( z?g>BN4mQa9#B^y5fih1#9xbx*9CLm0$%RRFx!^Mbwv@XmZ?>Jv+&ZlWU5Y-eVR}s7 zx+Mt$MW3Z|azkj%!N0XDCfDF(6=`)xG5Z5;EnTtT`i!wXw#{2kaemhN+0RxZE+<05 zIT9*RQhYQ=by#M{kL9E_Ire><4BdunOGI1S4WZ+cWvd2V*^?7|mHwUFke84zY)vvk zD#*KarrA<~weck!r7B4dsGc+?;LtJCGqi10md5MMS&R%_TYHoUb2_z`u$f&Cc#IOv zQs%0fud@i$E+p4Lav$-FpbtknyGnjCPJ-N-EQYnCL6s{C@vx;pH8kDVQAjki8emY` zn{fAm4Cq=}(`IdTJbZhUv!juA)vlJ7GaKkfCR!P7R_c3|&~mAI6k^>DLy=x`=($C< zSN#&8%wmo5Xe^3p(HJMq%|;*EC$W~4j$J;vWlC@DGqJh_U6eqYmaBo6TNOEXC^OJ* zu1(uEhs{Ujiz&|X^Vw=!8%x_pZryjae=*XB@+{LBeu>` zy-iEVmDTOfyi#?XN4Y4AtF~Q~`3`5AQM%BGY-jy4B>&)qGgC;5=i4VwcE+CD#%Mdg zm!%8TXkE5h#gcc{uK7jn880PhxFbI^N}|HPTs}*YEcTeq$#o%QyC7_|G8u$RgvQjY>H?;TKQ!nw zbcs~u{{K=OHofb`|M!2N?;r8+KL*|n?g6L3ZD1N~1wY5X|2%jPco+Cn@M`c%a3dH7 z2D|_~AAAEJ|Lx#bFaoXwY49BIOdvS{mx2fI^*;&j0`j*34ucsWx&P;Z`|#=C3Yy?X zum?!K|MS4l@Z-M^z6-trJ_=5O6>uC#KENaR^4|rL^Z!>s@&Hyq5s1J4V$cVA!E?dI z;3Du;@L7ENcLMo)0k?x0Ah`iofXjgR`wxMSf{%c^z{@}p1mGap54M1(gG+$?O@a60 z`G18k|1kJ6xEGuRli++HKK_4!2f^K-0d|01a0S>5evQ8_`2b%6p8}r% z_ka+{-wAjDcptvH{9S+{Aou>F13jSQ#~KT(|MuU)sl6)Q)csH56~>fOSaZ>cobc zuqD_3J@6)ocAc~-T@ss=FTmcsV`%#=n1qwtP77<+S|uNH7K>!G3zrkdH0%u4w;3~% zGo&=f8A-OfSc&8rM@^*M2yv$$E)e(RsH^88Lc#LN=ZqbaOMkxp#k2h|$!=`DV{QfN zB=pH4*|n56Yy(lQagcN7YjHnC9f_dSjNV`Qm`Xgzu1!5=W_G-J z^;Pa-yG56$!|q7!8XdQXxs_5itCR#QK|V_>v*$W)H0R#in^)@iR~ zlgH*dj5pL#xr39zI8@nD86ST(%JF|k2^aV?6TF^+AsFwtZa>307P;Z1hVAnJoRlZ+ zPd?C}aCfp)O)}fE!1CJ@MNOIHmX^R|O12KW55@f3dL{Xuypvz@vPB-JBau<^+G6d2 zKc0*`@gq@98!<+Su#GuV2>Ug4WRld8#0}->p*e1M$Y#)v4!H~l8(-6%uq`1~9rHv~ zfxiUe2aE+DD|*Y<*vCz!<(lfF@X;qNBotT6tTuHt6+T!_ukkNorM4p@(Wg4`ii`Rj zU-lewMRQp?7zvliI8pw`vT#SLb$EW(x`W7!YDRku)~-aSbdC&f_3<6}GbwF)ZZ)iR zI+jk)UIlR-?Fmjs)lglMt^N`?wT5}FmWWQW##$$z(L-K7XVMGD@Lrd6FQSNrZ|7(a zf_*v;ii}4K5jeg&qIc@$wZ4^mduquq_eSf<3J?n2JDDS|` z+X>rc&xvi|fZ=vOCw##(A^m>0Zk-RajDlrY)r9bRgrE$h!NJQ4A z2}vs<%tNk22_+g9d%eB&!pg~#YNaIQ5ZWfC#SQlOj&?(x?Id$N-cIAQfxD50xAsb; zWf)vYq$N~3fDl6Htyir?BQZ;Q|K=^LGrl%trolxuOo`|)D&8{5TIkzahg4s6n1gtj zL_gdJ>T0pV@ax!(A8(uX+c%=dGAL;ribKNVZAtMbOatQh*4%g8;ET o8cslWI;L&svhk#y8f`qXtVUf6ZTk2aFImPa^=Q?_0y Date: Wed, 20 Jul 2022 20:24:49 +0800 Subject: [PATCH 34/42] refactor(sync): add trace log --- source/libs/sync/src/syncMain.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index b769bf5273..94f22c3601 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -3007,8 +3007,8 @@ void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries snprintf(logBuf, sizeof(logBuf), "send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, count:%d}, %s", - pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, - pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount, s); + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, + pMsg->dataLen, pMsg->dataCount, s); syncNodeEventLog(pSyncNode, logBuf); } @@ -3020,8 +3020,8 @@ void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries snprintf(logBuf, sizeof(logBuf), "recv sync-append-entries-batch from %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 ", pterm:%" PRIu64 ", commit:%" PRId64 ", datalen:%d, count:%d}, %s", - pSyncNode->vgId, host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, - pMsg->commitIndex, pMsg->dataLen, pMsg->dataCount, s); + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, + pMsg->dataLen, pMsg->dataCount, s); syncNodeErrorLog(pSyncNode, logBuf); } From 3b8669a50d97ef72b3f0ff5b5a99693cb39e1069 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Wed, 20 Jul 2022 20:57:48 +0800 Subject: [PATCH 35/42] test: fix win test stop taosd error --- tests/pytest/util/dnodes.py | 6 +++--- tests/system-test/0-others/sysinfo.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 613673ea8e..656687255e 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -300,7 +300,7 @@ class TDDnode: if self.valgrind == 0: if platform.system().lower() == 'windows': - cmd = "mintty -h never -w hide %s -c %s" % ( + cmd = "mintty -h never %s -c %s" % ( binPath, self.cfgDir) else: cmd = "nohup %s -c %s > /dev/null 2>&1 & " % ( @@ -309,7 +309,7 @@ class TDDnode: valgrindCmdline = "valgrind --log-file=\"%s/../log/valgrind.log\" --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"%self.cfgDir if platform.system().lower() == 'windows': - cmd = "mintty -h never -w hide %s %s -c %s" % ( + cmd = "mintty -h never %s %s -c %s" % ( valgrindCmdline, binPath, self.cfgDir) else: cmd = "nohup %s %s -c %s 2>&1 & " % ( @@ -521,7 +521,7 @@ class TDDnode: if self.running != 0: if platform.system().lower() == 'windows': - psCmd = "for /f %a in ('wmic process where \"name='taosd.exe' and CommandLine like '%%dnode%d%%'\" get processId ^| xargs echo ^| awk ^'{print $2}^'') do @(ps | grep %a | awk '{print $1}' | xargs kill -INT )" % (self.index) + psCmd = "for /f %%a in ('wmic process where \"name='taosd.exe' and CommandLine like '%%dnode%d%%'\" get processId ^| xargs echo ^| awk ^'{print $2}^'') do @(ps | grep %%a | awk '{print $1}' | xargs kill -INT )" % (self.index) else: psCmd = "ps -ef|grep -w %s| grep dnode%d|grep -v grep | awk '{print $2}'" % (toBeKilled,self.index) processID = subprocess.check_output( diff --git a/tests/system-test/0-others/sysinfo.py b/tests/system-test/0-others/sysinfo.py index 129c8bc530..f6f177d995 100644 --- a/tests/system-test/0-others/sysinfo.py +++ b/tests/system-test/0-others/sysinfo.py @@ -48,6 +48,8 @@ class TDTestCase: #!for bug tdDnodes.stoptaosd(1) sleep(self.delaytime) + if platform.system().lower() == 'windows': + sleep(10) tdSql.error('select server_status()') def run(self): From 245ec4273f12fd8cfcc5624b63fc76c59d27e3f6 Mon Sep 17 00:00:00 2001 From: Hui Li <52318143+plum-lihui@users.noreply.github.com> Date: Wed, 20 Jul 2022 21:00:11 +0800 Subject: [PATCH 36/42] Delete tmqUdf-multCtb.py test: remove no use case --- tests/system-test/7-tmq/tmqUdf-multCtb.py | 372 ---------------------- 1 file changed, 372 deletions(-) delete mode 100644 tests/system-test/7-tmq/tmqUdf-multCtb.py diff --git a/tests/system-test/7-tmq/tmqUdf-multCtb.py b/tests/system-test/7-tmq/tmqUdf-multCtb.py deleted file mode 100644 index 392a7d452e..0000000000 --- a/tests/system-test/7-tmq/tmqUdf-multCtb.py +++ /dev/null @@ -1,372 +0,0 @@ -from distutils.log import error -import taos -import sys -import time -import socket -import os -import threading -import subprocess -import platform - -from util.log import * -from util.sql import * -from util.cases import * -from util.dnodes import * -from util.common import * -sys.path.append("./7-tmq") -from tmqCommon import * - -class TDTestCase: - def __init__(self): - self.snapshot = 0 - self.vgroups = 4 - self.ctbNum = 100 - self.rowsPerTbl = 1000 - - def init(self, conn, logSql): - tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor()) - #tdSql.init(conn.cursor(), logSql) # output sql.txt file - - def prepare_udf_so(self): - selfPath = os.path.dirname(os.path.realpath(__file__)) - - if ("community" in selfPath): - projPath = selfPath[:selfPath.find("community")] - else: - projPath = selfPath[:selfPath.find("tests")] - print(projPath) - - if platform.system().lower() == 'windows': - self.libudf1 = subprocess.Popen('(for /r %s %%i in ("udf1.d*") do @echo %%i)|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8") - if (not tdDnodes.dnodes[0].remoteIP == ""): - tdDnodes.dnodes[0].remote_conn.get(tdDnodes.dnodes[0].config["path"]+'/debug/build/lib/libudf1.so',projPath+"\\debug\\build\\lib\\") - self.libudf1 = self.libudf1.replace('udf1.dll','libudf1.so') - else: - self.libudf1 = subprocess.Popen('find %s -name "libudf1.so"|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8") - self.libudf1 = self.libudf1.replace('\r','').replace('\n','') - return - - def create_udf_function(self): - # create scalar functions - tdSql.execute("create function udf1 as '%s' outputtype int bufSize 8;"%self.libudf1) - - functions = tdSql.getResult("show functions") - function_nums = len(functions) - if function_nums == 1: - tdLog.info("create one udf functions success ") - else: - tdLog.exit("create udf functions fail") - return - - def checkFileContent(self, consumerId, queryString): - buildPath = tdCom.getBuildPath() - cfgPath = tdCom.getClientCfgPath() - dstFile = '%s/../log/dstrows_%d.txt'%(cfgPath, consumerId) - cmdStr = '%s/build/bin/taos -c %s -s "%s >> %s"'%(buildPath, cfgPath, queryString, dstFile) - tdLog.info(cmdStr) - os.system(cmdStr) - - consumeRowsFile = '%s/../log/consumerid_%d.txt'%(cfgPath, consumerId) - tdLog.info("rows file: %s, %s"%(consumeRowsFile, dstFile)) - - consumeFile = open(consumeRowsFile, mode='r') - queryFile = open(dstFile, mode='r') - - # skip first line for it is schema - queryFile.readline() - - while True: - dst = queryFile.readline() - src = consumeFile.readline() - - if dst: - if dst != src: - tdLog.exit("consumerId %d consume rows is not match the rows by direct query"%consumerId) - else: - break - return - - def prepareTestEnv(self): - tdLog.printNoPrefix("======== prepare test env include database, stable, ctables, and insert data: ") - paraDict = {'dbName': 'dbt', - 'dropFlag': 1, - 'event': '', - 'vgroups': 4, - 'stbName': 'stb', - 'colPrefix': 'c', - 'tagPrefix': 't', - 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], - 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], - 'ctbPrefix': 'ctb', - 'ctbStartIdx': 0, - 'ctbNum': 100, - 'rowsPerTbl': 1000, - 'batchNum': 100, - 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 3, - 'showMsg': 1, - 'showRow': 1, - 'snapshot': 0} - - paraDict['vgroups'] = self.vgroups - paraDict['ctbNum'] = self.ctbNum - paraDict['rowsPerTbl'] = self.rowsPerTbl - - tmqCom.initConsumerTable() - tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=paraDict["vgroups"],replica=1) - tdLog.info("create stb") - tmqCom.create_stable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"]) - tdLog.info("create ctb") - tmqCom.create_ctable(tdSql, dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix=paraDict['ctbPrefix'], - ctbNum=paraDict["ctbNum"],ctbStartIdx=paraDict['ctbStartIdx']) - tdLog.info("insert data") - tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], - ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], - startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) - # tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix="ctbx", - # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], - # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) - - # tdLog.info("restart taosd to ensure that the data falls into the disk") - # tdSql.query("flush database %s"%(paraDict['dbName'])) - return - - def tmqCase1(self): - tdLog.printNoPrefix("======== test case 1: multi sub table") - paraDict = {'dbName': 'dbt', - 'dropFlag': 1, - 'event': '', - 'vgroups': 4, - 'stbName': 'stb', - 'colPrefix': 'c', - 'tagPrefix': 't', - 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], - 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], - 'ctbPrefix': 'ctb', - 'ctbStartIdx': 0, - 'ctbNum': 100, - 'rowsPerTbl': 1000, - 'batchNum': 100, - 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 3, - 'showMsg': 1, - 'showRow': 1, - 'snapshot': 0} - paraDict['snapshot'] = self.snapshot - paraDict['vgroups'] = self.vgroups - paraDict['ctbNum'] = self.ctbNum - paraDict['rowsPerTbl'] = self.rowsPerTbl - - topicNameList = ['topic1', 'topic2'] - expectRowsList = [] - tmqCom.initConsumerTable() - # tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=4,replica=1) - # tdLog.info("create stb") - # tdCom.create_stable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"], column_elm_list=paraDict['colSchema'], tag_elm_list=paraDict['tagSchema']) - # tdLog.info("create ctb") - # tdCom.create_ctable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"],tag_elm_list=paraDict['tagSchema'],count=paraDict["ctbNum"], default_ctbname_prefix=paraDict['ctbPrefix']) - # tdLog.info("insert data") - # tmqCom.insert_data_1(tdSql,paraDict["dbName"],paraDict["ctbPrefix"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]) - - tdLog.info("create topics from stb with filter") - queryString = "select ts,c1,udf1(c1),c2,udf1(c2) from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName']) - sqlString = "create topic %s as %s" %(topicNameList[0], queryString) - tdLog.info("create topic sql: %s"%sqlString) - tdSql.execute(sqlString) - tdSql.query(queryString) - expectRowsList.append(tdSql.getRows()) - - # init consume info, and start tmq_sim, then check consume result - tdLog.info("insert consume info to consume processor") - consumerId = 0 - expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] - topicList = topicNameList[0] - ifcheckdata = 1 - ifManualCommit = 1 - keyList = 'group.id:cgrp1, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest' - tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) - - tdLog.info("start consume processor") - tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow'],snapshot=paraDict['snapshot']) - - tdLog.info("wait the consume result") - expectRows = 1 - resultList = tmqCom.selectConsumeResult(expectRows) - - if expectRowsList[0] != resultList[0]: - tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[0], resultList[0])) - tdLog.exit("0 tmq consume rows error!") - - # self.checkFileContent(consumerId, queryString) - # tdLog.printNoPrefix("consumerId %d check data ok!"%(consumerId)) - - # reinit consume info, and start tmq_sim, then check consume result - tmqCom.initConsumerTable() - - queryString = "select ts, c1,udf1(c1),sin(udf1(c2)), log(udf1(c2)) from %s.%s where udf1(c1) == 88 or sin(udf1(c1)) > 0" %(paraDict['dbName'], paraDict['stbName']) - sqlString = "create topic %s as %s" %(topicNameList[1], queryString) - tdLog.info("create topic sql: %s"%sqlString) - tdSql.execute(sqlString) - tdSql.query(queryString) - expectRowsList.append(tdSql.getRows()) - - consumerId = 1 - topicList = topicNameList[1] - tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) - - tdLog.info("start consume processor") - tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow'],snapshot=paraDict['snapshot']) - - tdLog.info("wait the consume result") - expectRows = 1 - resultList = tmqCom.selectConsumeResult(expectRows) - if expectRowsList[1] != resultList[0]: - tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[1], resultList[0])) - tdLog.exit("1 tmq consume rows error!") - - # self.checkFileContent(consumerId, queryString) - # tdLog.printNoPrefix("consumerId %d check data ok!"%(consumerId)) - - time.sleep(10) - for i in range(len(topicNameList)): - tdSql.query("drop topic %s"%topicNameList[i]) - - tdLog.printNoPrefix("======== test case 1 end ...... ") - - def tmqCase2(self): - tdLog.printNoPrefix("======== test case 2: multi sub table, consume with auto create tble and insert data") - paraDict = {'dbName': 'dbt', - 'dropFlag': 1, - 'event': '', - 'vgroups': 4, - 'stbName': 'stb', - 'colPrefix': 'c', - 'tagPrefix': 't', - 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], - 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], - 'ctbPrefix': 'ctb', - 'ctbStartIdx': 0, - 'ctbNum': 100, - 'rowsPerTbl': 1000, - 'batchNum': 100, - 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 3, - 'showMsg': 1, - 'showRow': 1, - 'snapshot': 0} - paraDict['snapshot'] = self.snapshot - paraDict['vgroups'] = self.vgroups - paraDict['ctbNum'] = self.ctbNum - paraDict['rowsPerTbl'] = self.rowsPerTbl - - topicNameList = ['topic1', 'topic2'] - expectRowsList = [] - tmqCom.initConsumerTable() - # tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=4,replica=1) - # tdLog.info("create stb") - # tdCom.create_stable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"], column_elm_list=paraDict['colSchema'], tag_elm_list=paraDict['tagSchema']) - # tdLog.info("create ctb") - # tdCom.create_ctable(tdSql, dbname=paraDict["dbName"],stbname=paraDict["stbName"],tag_elm_list=paraDict['tagSchema'],count=paraDict["ctbNum"], default_ctbname_prefix=paraDict['ctbPrefix']) - # tdLog.info("insert data") - # tmqCom.insert_data_1(tdSql,paraDict["dbName"],paraDict["ctbPrefix"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]) - - tdLog.info("create topics from stb with filter") - queryString = "select ts,c1,udf1(c1),c2,udf1(c2) from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName']) - sqlString = "create topic %s as %s" %(topicNameList[0], queryString) - tdLog.info("create topic sql: %s"%sqlString) - tdSql.execute(sqlString) - # tdSql.query(queryString) - # expectRowsList.append(tdSql.getRows()) - - # init consume info, and start tmq_sim, then check consume result - tdLog.info("insert consume info to consume processor") - consumerId = 2 - expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2 - topicList = topicNameList[0] - ifcheckdata = 1 - ifManualCommit = 1 - keyList = 'group.id:cgrp1, enable.auto.commit:false, auto.commit.interval.ms:6000, auto.offset.reset:earliest' - tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) - - tdLog.info("start consume processor") - tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow'],snapshot=paraDict['snapshot']) - - paraDict['startTs'] = paraDict['startTs'] + int(self.rowsPerTbl) - tmqCom.insert_data_interlaceByMultiTbl(tsql=tdSql,dbName=paraDict["dbName"],ctbPrefix=paraDict["ctbPrefix"], - ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], - startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) - - tdLog.info("wait the consume result") - expectRows = 1 - resultList = tmqCom.selectConsumeResult(expectRows) - - tdSql.query(queryString) - expectRowsList.append(tdSql.getRows()) - - if expectRowsList[0] != resultList[0]: - tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[0], resultList[0])) - tdLog.exit("2 tmq consume rows error!") - - # self.checkFileContent(consumerId, queryString) - # tdLog.printNoPrefix("consumerId %d check data ok!"%(consumerId)) - - # reinit consume info, and start tmq_sim, then check consume result - tmqCom.initConsumerTable() - - queryString = "select ts, c1,udf1(c1),sin(udf1(c2)), log(udf1(c2)) from %s.%s where udf1(c1) == 88 or sin(udf1(c1)) > 0" %(paraDict['dbName'], paraDict['stbName']) - sqlString = "create topic %s as %s" %(topicNameList[1], queryString) - tdLog.info("create topic sql: %s"%sqlString) - tdSql.execute(sqlString) - tdSql.query(queryString) - expectRowsList.append(tdSql.getRows()) - - consumerId = 3 - topicList = topicNameList[1] - tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) - - tdLog.info("start consume processor") - tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow'],snapshot=paraDict['snapshot']) - - tdLog.info("wait the consume result") - expectRows = 1 - resultList = tmqCom.selectConsumeResult(expectRows) - if expectRowsList[1] != resultList[0]: - tdLog.info("expect consume rows: %d, act consume rows: %d"%(expectRowsList[1], resultList[0])) - tdLog.exit("3 tmq consume rows error!") - - # self.checkFileContent(consumerId, queryString) - # tdLog.printNoPrefix("consumerId %d check data ok!"%(consumerId)) - - time.sleep(10) - for i in range(len(topicNameList)): - tdSql.query("drop topic %s"%topicNameList[i]) - - tdLog.printNoPrefix("======== test case 2 end ...... ") - - def run(self): - # tdSql.prepare() - self.prepare_udf_so() - self.create_udf_function() - - tdLog.printNoPrefix("=============================================") - tdLog.printNoPrefix("======== snapshot is 0: only consume from wal") - self.prepareTestEnv() - self.tmqCase1() - self.tmqCase2() - - tdLog.printNoPrefix("====================================================================") - tdLog.printNoPrefix("======== snapshot is 1: firstly consume from tsbs, and then from wal") - self.prepareTestEnv() - self.snapshot = 1 - self.tmqCase1() - self.tmqCase2() - - def stop(self): - tdSql.close() - tdLog.success(f"{__file__} successfully executed") - -event = threading.Event() - -tdCases.addLinux(__file__, TDTestCase()) -tdCases.addWindows(__file__, TDTestCase()) From 947638acdf723938bafa9fbcf40c76c0da34434a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 20 Jul 2022 21:01:47 +0800 Subject: [PATCH 37/42] test: restore 2.0 case --- tests/script/jenkins/basic.txt | 16 ++++++------ tests/script/tsim/parser/groupby.sim | 26 ++++++++++---------- tests/script/tsim/parser/slimit.sim | 6 ++--- tests/script/tsim/parser/stableOp.sim | 4 +-- tests/script/tsim/parser/tbnameIn.sim | 1 - tests/script/tsim/parser/tbnameIn_query.sim | 17 +++++++------ tests/script/tsim/parser/timestamp.sim | 2 -- tests/script/tsim/parser/timestamp_query.sim | 10 +++----- tests/script/tsim/parser/topbot.sim | 24 ++++++++---------- 9 files changed, 48 insertions(+), 58 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index e17dddc6c4..d360f9f1d1 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -154,19 +154,19 @@ # ./test.sh -f tsim/parser/set_tag_vals.sim # ./test.sh -f tsim/parser/single_row_in_tb.sim # ./test.sh -f tsim/parser/sliding.sim +# ./test.sh -f tsim/parser/slimit_alter_tags.sim # ./test.sh -f tsim/parser/slimit.sim # ./test.sh -f tsim/parser/slimit1.sim -# ./test.sh -f tsim/parser/slimit_alter_tags.sim -# ./test.sh -f tsim/parser/stableOp.sim +./test.sh -f tsim/parser/stableOp.sim # ./test.sh -f tsim/parser/tags_dynamically_specifiy.sim # ./test.sh -f tsim/parser/tags_filter.sim -# ./test.sh -f tsim/parser/tbnameIn.sim -# ./test.sh -f tsim/parser/timestamp.sim -## ./test.sh -f tsim/parser/top_groupby.sim -# ./test.sh -f tsim/parser/topbot.sim -# ./test.sh -f tsim/parser/udf.sim -# ./test.sh -f tsim/parser/udf_dll.sim +# jira ./test.sh -f tsim/parser/tbnameIn.sim +./test.sh -f tsim/parser/timestamp.sim +./test.sh -f tsim/parser/top_groupby.sim +./test.sh -f tsim/parser/topbot.sim # ./test.sh -f tsim/parser/udf_dll_stable.sim +# ./test.sh -f tsim/parser/udf_dll.sim +# ./test.sh -f tsim/parser/udf.sim # ./test.sh -f tsim/parser/union.sim # ./test.sh -f tsim/parser/where.sim diff --git a/tests/script/tsim/parser/groupby.sim b/tests/script/tsim/parser/groupby.sim index 7970bb4414..bf2c7cc7bf 100644 --- a/tests/script/tsim/parser/groupby.sim +++ b/tests/script/tsim/parser/groupby.sim @@ -476,26 +476,26 @@ if $rows != 100 then return -1 endi -sql select sum(c2),c8,avg(c2), sum(c2)/count(*) from group_mt0 partition by c8 order by c8 slimit 2 soffset 99 +sql select sum(c2),c8,avg(c2), sum(c2)/count(*) from group_mt0 partition by c8 slimit 2 soffset 99 if $rows != 1 then return -1 endi -if $data00 != 79200.000000000 then - return -1 -endi +#if $data00 != 79200.000000000 then +# return -1 +#endi -if $data01 != @binary99@ then - return -1 -endi +#if $data01 != @binary99@ then +# return -1 +#endi -if $data02 != 99.000000000 then - return -1 -endi +#if $data02 != 99.000000000 then +# return -1 +#endi -if $data03 != 99.000000000 then - return -1 -endi +#if $data03 != 99.000000000 then +# return -1 +#endi print ============>td-1765 sql select percentile(c4, 49),min(c4),max(c4),avg(c4),stddev(c4) from group_tb0 group by c8 order by c8; diff --git a/tests/script/tsim/parser/slimit.sim b/tests/script/tsim/parser/slimit.sim index 9ca5da678a..2a1f2a1ec7 100644 --- a/tests/script/tsim/parser/slimit.sim +++ b/tests/script/tsim/parser/slimit.sim @@ -17,7 +17,7 @@ $db = $dbPrefix . $i $stb = $stbPrefix . $i sql drop database if exists $db -sql create database $db maxrows 200 cache 16 +sql create database $db maxrows 200 print ====== create tables sql use $db sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 binary(15), t2 int, t3 bigint, t4 nchar(10), t5 double, t6 bool) @@ -59,7 +59,7 @@ print ====== $db tables created $db = $dbPrefix . 1 sql drop database if exists $db -sql create database $db maxrows 200 cache 16 +sql create database $db maxrows 200 sql use $db sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 binary(15), t2 int, t3 bigint, t4 nchar(10), t5 double, t6 bool) @@ -93,11 +93,9 @@ run tsim/parser/slimit_query.sim print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 500 system sh/exec.sh -n dnode1 -s start print ================== server restart completed sql connect -sleep 100 run tsim/parser/slimit_query.sim diff --git a/tests/script/tsim/parser/stableOp.sim b/tests/script/tsim/parser/stableOp.sim index 4fe0a6f38d..76f9fe202b 100644 --- a/tests/script/tsim/parser/stableOp.sim +++ b/tests/script/tsim/parser/stableOp.sim @@ -62,7 +62,7 @@ sql_error insert into $tb values (now, 1, 2.0); sql alter stable $stb add tag tag2 int; -sql alter stable $stb change tag tag2 tag3; +sql alter stable $stb rename tag tag2 tag3; sql_error drop stable $tb @@ -85,7 +85,7 @@ print create/alter/drop stable test passed sql drop database $db sql show databases -if $rows != 0 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/parser/tbnameIn.sim b/tests/script/tsim/parser/tbnameIn.sim index e9206b59e2..4a6513cfaa 100644 --- a/tests/script/tsim/parser/tbnameIn.sim +++ b/tests/script/tsim/parser/tbnameIn.sim @@ -64,7 +64,6 @@ run tsim/parser/tbnameIn_query.sim print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 500 system sh/exec.sh -n dnode1 -s start print ================== server restart completed diff --git a/tests/script/tsim/parser/tbnameIn_query.sim b/tests/script/tsim/parser/tbnameIn_query.sim index db27886bbf..33587cb7c1 100644 --- a/tests/script/tsim/parser/tbnameIn_query.sim +++ b/tests/script/tsim/parser/tbnameIn_query.sim @@ -1,4 +1,3 @@ -sleep 100 sql connect $dbPrefix = ti_db @@ -27,10 +26,11 @@ sql use $db sql select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') and t1 > 2 # tbname in used on meter -sql_error select count(*) from $tb where tbname in ('ti_tb1', 'ti_tb300') +sql select count(*) from $tb where tbname in ('ti_tb1', 'ti_tb300') ## tbname in + group by tag -sql select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') group by t1 order by t1 asc +print select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') group by t1 order by t1 asc +sql select count(*), t1 from $stb where tbname in ('ti_tb1', 'ti_tb300') group by t1 order by t1 asc if $rows != 2 then return -1 endi @@ -48,7 +48,7 @@ if $data11 != 300 then endi ## duplicated tbnames -sql select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb1', 'ti_tb1', 'ti_tb2', 'ti_tb2', 'ti_tb3') group by t1 order by t1 asc +sql select count(*), t1 from $stb where tbname in ('ti_tb1', 'ti_tb1', 'ti_tb1', 'ti_tb2', 'ti_tb2', 'ti_tb3') group by t1 order by t1 asc if $rows != 3 then return -1 endi @@ -72,7 +72,7 @@ if $data21 != 3 then endi ## wrong tbnames -sql select count(*) from $stb where tbname in ('tbname in', 'ti_tb1', 'ti_stb0') group by t1 order by t1 +sql select count(*), t1 from $stb where tbname in ('tbname in', 'ti_tb1', 'ti_stb0') group by t1 order by t1 if $rows != 1 then return -1 endi @@ -84,7 +84,7 @@ if $data01 != 1 then endi ## tbname in + colummn filtering -sql select count(*) from $stb where tbname in ('tbname in', 'ti_tb1', 'ti_stb0', 'ti_tb2') and c8 like 'binary%' group by t1 order by t1 asc +sql select count(*), t1 from $stb where tbname in ('tbname in', 'ti_tb1', 'ti_stb0', 'ti_tb2') and c8 like 'binary%' group by t1 order by t1 asc if $rows != 2 then return -1 endi @@ -102,7 +102,8 @@ if $data11 != 2 then endi ## tbname in can accpet Upper case table name -sql select count(*) from $stb where tbname in ('ti_tb0', 'TI_tb1', 'TI_TB2') group by t1 order by t1 +print select count(*), t1 from $stb where tbname in ('ti_tb0', 'TI_tb1', 'TI_TB2') group by t1 order by t1 +sql select count(*), t1 from $stb where tbname in ('ti_tb0', 'TI_tb1', 'TI_TB2') group by t1 order by t1 if $rows != 3 then return -1 endi @@ -126,7 +127,7 @@ if $data21 != 2 then endi # multiple tbname in is not allowed NOW -sql_error select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') and tbname in ('ti_tb5', 'ti_tb1000') group by t1 order by t1 asc +sql select count(*), t1 from $stb where tbname in ('ti_tb1', 'ti_tb300') and tbname in ('ti_tb5', 'ti_tb1000') group by t1 order by t1 asc #if $rows != 4 then # return -1 #endi diff --git a/tests/script/tsim/parser/timestamp.sim b/tests/script/tsim/parser/timestamp.sim index 524f6d5de3..e663e499e5 100644 --- a/tests/script/tsim/parser/timestamp.sim +++ b/tests/script/tsim/parser/timestamp.sim @@ -54,10 +54,8 @@ run tsim/parser/timestamp_query.sim print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 100 system sh/exec.sh -n dnode1 -s start print ================== server restart completed sql connect -sleep 100 run tsim/parser/timestamp_query.sim diff --git a/tests/script/tsim/parser/timestamp_query.sim b/tests/script/tsim/parser/timestamp_query.sim index 3f6a1af4bc..e9f13e4461 100644 --- a/tests/script/tsim/parser/timestamp_query.sim +++ b/tests/script/tsim/parser/timestamp_query.sim @@ -1,4 +1,3 @@ -sleep 100 sql connect $dbPrefix = ts_db @@ -22,14 +21,14 @@ $tsu = $tsu - $delta $tsu = $tsu + $ts0 print ==================>issue #3481, normal column not allowed, -sql_error select ts,c1,min(c2) from ts_stb0 +sql select ts,c1,min(c2) from ts_stb0 print ==================>issue #4681, not equal operator on primary timestamp not allowed -sql_error select * from ts_stb0 where ts <> $ts0 +sql select * from ts_stb0 where ts <> $ts0 ##### select from supertable $tb = $tbPrefix . 0 -sql select first(c1), last(c1), (1537325400 - 1537146000)/(5*60) v from $tb where ts >= $ts0 and ts < $tsu interval(5m) fill(value, -1) +sql select _wstart, first(c1), last(c1), (1537325400 - 1537146000)/(5*60) v from $tb where ts >= $ts0 and ts < $tsu interval(5m) fill(value, -1) $res = $rowNum * 2 $n = $res - 2 print ============>$n @@ -43,13 +42,12 @@ if $data03 != 598.000000000 then return -1 endi - if $data13 != 598.000000000 then print expect 598.000000000, actual $data03 return -1 endi -sql select first(c1), last(c1), (1537325400 - 1537146000)/(5*60) v from $tb where ts >= $ts0 and ts < $tsu interval(5m) fill(value, NULL) +sql select _wstart, first(c1), last(c1), (1537325400 - 1537146000)/(5*60) v from $tb where ts >= $ts0 and ts < $tsu interval(5m) fill(value, NULL) if $data13 != 598.000000000 then print expect 598.000000000, actual $data03 return -1 diff --git a/tests/script/tsim/parser/topbot.sim b/tests/script/tsim/parser/topbot.sim index 61b2db2862..5106f3499e 100644 --- a/tests/script/tsim/parser/topbot.sim +++ b/tests/script/tsim/parser/topbot.sim @@ -20,7 +20,7 @@ $stb = $stbPrefix . $i sql drop database $db -x step1 step1: -sql create database $db cache 16 maxrows 4096 keep 36500 +sql create database $db maxrows 4096 keep 36500 print ====== create tables sql use $db sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 int) @@ -68,7 +68,7 @@ if $row != 100 then return -1 endi -sql select bottom(c3, 5) from tb_tb1 interval(1y); +sql select _wstart, bottom(c3, 5) from tb_tb1 interval(1y); if $rows != 5 then return -1 endi @@ -90,7 +90,7 @@ if $data31 != 0.00000 then return -1 endi -sql select top(c4, 5) from tb_tb1 interval(1y); +sql select _wstart, top(c4, 5) from tb_tb1 interval(1y); if $rows != 5 then return -1 endi @@ -112,7 +112,7 @@ if $data31 != 9.000000000 then return -1 endi -sql select top(c3, 5) from tb_tb1 interval(40h) +sql select _wstart, top(c3, 5) from tb_tb1 interval(40h) if $rows != 25 then return -1 endi @@ -149,7 +149,7 @@ sql insert into test1 values(1537146000006, 7, 7, 7, 7, 6.100000, 6.100000, 0, ' sql insert into test1 values(1537146000007, 8, 8, 8, 8, 7.100000, 7.100000, 1, 'taosdata8', '涛思数据8'); sql insert into test1 values(1537146000008, 9, 9, 9, 9, 8.100000, 8.100000, 0, 'taosdata9', '涛思数据9'); sql insert into test1 values(1537146000009, 10, 10, 10, 10, 9.100000, 9.100000, 1, 'taosdata10', '涛思数据10'); -sql select bottom(col5, 10) from test +sql select ts, bottom(col5, 10) from test order by col5; if $rows != 10 then return -1 endi @@ -177,13 +177,11 @@ sql insert into test values(29999, 1)(70000, 2)(80000, 3) print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 500 system sh/exec.sh -n dnode1 -s start print ================== server restart completed sql connect -sleep 100 -sql select count(*) from t1.test where ts>10000 and ts<90000 interval(5000a) +sql select count(*) from t1.test where ts > 10000 and ts < 90000 interval(5000a) if $rows != 3 then return -1 endi @@ -218,7 +216,6 @@ endw system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start sql connect -sleep 100 sql use db; $ts = 1000 @@ -270,10 +267,9 @@ sql insert into t2 values('2020-2-2 1:1:1', 1); system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start sql connect -sleep 100 sql use db -sql select count(*), first(ts), last(ts) from t2 interval(1d); +sql select _wstart, count(*), first(ts), last(ts) from t2 interval(1d); if $rows != 2 then return -1 endi @@ -367,9 +363,9 @@ if $row != 1 then return -1 endi -sql_error select * from ttm2 where k=null -sql_error select * from ttm2 where k<>null +sql select * from ttm2 where k=null +sql select * from ttm2 where k<>null sql_error select * from ttm2 where k like null -sql_error select * from ttm2 where k Date: Wed, 20 Jul 2022 21:29:22 +0800 Subject: [PATCH 38/42] test: restore 2.0 case --- tests/script/jenkins/basic.txt | 19 +- tests/script/tsim/parser/create_db.sim | 79 +++--- .../create_db__for_community_version.sim | 234 ------------------ tests/script/tsim/parser/where.sim | 5 - 4 files changed, 41 insertions(+), 296 deletions(-) delete mode 100644 tests/script/tsim/parser/create_db__for_community_version.sim diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index d360f9f1d1..0aa33002cf 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -87,18 +87,17 @@ ./test.sh -f tsim/parser/alter_column.sim ./test.sh -f tsim/parser/alter_stable.sim ./test.sh -f tsim/parser/alter.sim -# nojira ./test.sh -f tsim/parser/alter1.sim +# jira ./test.sh -f tsim/parser/alter1.sim ./test.sh -f tsim/parser/auto_create_tb_drop_tb.sim # jira ./test.sh -f tsim/parser/auto_create_tb.sim ./test.sh -f tsim/parser/between_and.sim ./test.sh -f tsim/parser/binary_escapeCharacter.sim -# nojira ./test.sh -f tsim/parser/col_arithmetic_operation.sim -# nojira ./test.sh -f tsim/parser/columnValue.sim +# jira ./test.sh -f tsim/parser/col_arithmetic_operation.sim +# jira ./test.sh -f tsim/parser/columnValue.sim ## ./test.sh -f tsim/parser/commit.sim ## ./test.sh -f tsim/parser/condition.sim ## ./test.sh -f tsim/parser/constCol.sim -# ./test.sh -f tsim/parser/create_db.sim -## ./test.sh -f tsim/parser/create_db__for_community_version.sim +./test.sh -f tsim/parser/create_db.sim # ./test.sh -f tsim/parser/create_mt.sim # ./test.sh -f tsim/parser/create_tb.sim ## ./test.sh -f tsim/parser/create_tb_with_tag_name.sim @@ -235,15 +234,15 @@ ./test.sh -f tsim/stream/drop_stream.sim ./test.sh -f tsim/stream/distributeInterval0.sim ./test.sh -f tsim/stream/distributeIntervalRetrive0.sim -# ./test.sh -f tsim/stream/distributesession0.sim +./test.sh -f tsim/stream/distributeSession0.sim ./test.sh -f tsim/stream/session0.sim ./test.sh -f tsim/stream/session1.sim ./test.sh -f tsim/stream/state0.sim ./test.sh -f tsim/stream/triggerInterval0.sim -# ./test.sh -f tsim/stream/triggerSession0.sim +./test.sh -f tsim/stream/triggerSession0.sim ./test.sh -f tsim/stream/partitionby.sim ./test.sh -f tsim/stream/partitionby1.sim -# ./test.sh -f tsim/stream/schedSnode.sim +# unsupport ./test.sh -f tsim/stream/schedSnode.sim ./test.sh -f tsim/stream/windowClose.sim ./test.sh -f tsim/stream/ignoreExpiredData.sim ./test.sh -f tsim/stream/sliding.sim @@ -294,12 +293,12 @@ ./test.sh -f tsim/db/basic3.sim -m ./test.sh -f tsim/db/error1.sim -m ./test.sh -f tsim/insert/backquote.sim -m -# nojira ./test.sh -f tsim/parser/fourArithmetic-basic.sim -m +# unsupport ./test.sh -f tsim/parser/fourArithmetic-basic.sim -m ./test.sh -f tsim/query/interval-offset.sim -m ./test.sh -f tsim/tmq/basic3.sim -m ./test.sh -f tsim/stable/vnode3.sim -m ./test.sh -f tsim/qnode/basic1.sim -m -# nojira ./test.sh -f tsim/mnode/basic1.sim -m +# unsupport ./test.sh -f tsim/mnode/basic1.sim -m # --- sma ./test.sh -f tsim/sma/drop_sma.sim diff --git a/tests/script/tsim/parser/create_db.sim b/tests/script/tsim/parser/create_db.sim index c4c5b89bd2..34ce858409 100644 --- a/tests/script/tsim/parser/create_db.sim +++ b/tests/script/tsim/parser/create_db.sim @@ -23,10 +23,10 @@ sql create database $db sql use $db sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data00 != $db then +if $data20 != $db then return -1 endi sql drop database $db @@ -38,10 +38,10 @@ sql CREATE DATABASE $db sql use $db sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data00 != $db then +if $data20 != $db then return -1 endi sql drop database $db @@ -87,7 +87,7 @@ print create_db.sim case4: db_already_exists sql create database db0 sql create database db0 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi sql drop database db0 @@ -107,29 +107,21 @@ $ctime = 36000 # 10 hours $wal = 1 # valid value is 1, 2 $comp = 1 # max=32, automatically trimmed when exceeding -sql create database $db replica $replica duration $duration keep $keep maxrows $rows_db cache $cache blocks 4 ctime $ctime wal $wal comp $comp +sql create database $db replica $replica duration $duration keep $keep maxrows $rows_db wal $wal comp $comp sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data00 != $db then +if $data20 != $db then return -1 endi -if $data04 != $replica then +if $data24 != $replica then return -1 endi -if $data06 != $duration then +if $data26 != 14400m then return -1 endi -if $data07 != 365,365,365 then - return -1 -endi -print data08 = $data07 -if $data08 != $cache then - print expect $cache, actual:$data08 - return -1 -endi -if $data09 != 4 then +if $data27 != 525600m,525600m,525600m then return -1 endi @@ -160,56 +152,56 @@ sql_error create database $db keep 12,11 sql_error create database $db keep 365001,365001,365001 sql create database dbk0 keep 19 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data07 != 19,19,19 then +if $data27 != 27360m,27360m,27360m then return -1 endi sql drop database dbk0 sql create database dbka keep 19,20 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data07 != 19,20,20 then +if $data27 != 27360m,28800m,28800m then return -1 endi sql drop database dbka sql create database dbk1 keep 11,11,11 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data07 != 11,11,11 then +if $data27 != 15840m,15840m,15840m then return -1 endi sql drop database dbk1 sql create database dbk2 keep 11,12,13 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data07 != 11,12,13 then +if $data27 != 15840m,17280m,18720m then return -1 endi sql drop database dbk2 sql create database dbk3 keep 11,11,13 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data07 != 11,11,13 then +if $data27 != 15840m,15840m,18720m then return -1 endi sql drop database dbk3 sql create database dbk4 keep 11,13,13 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -if $data07 != 11,13,13 then +if $data27 != 15840m,18720m,18720m then return -1 endi sql drop database dbk4 @@ -233,38 +225,31 @@ sql_error create database $db ctime 29 sql_error create database $db ctime 40961 # wal {0, 2} -sql create database testwal wal 0 +sql_error create database testwal wal 0 sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi -sql show databases -print wallevel $data12_testwal -if $data12_testwal != 0 then - return -1 -endi -sql drop database testwal - sql create database testwal wal 1 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi sql show databases -print wallevel $data12_testwal -if $data12_testwal != 1 then +print wallevel $data13_testwal +if $data13_testwal != 1 then return -1 endi sql drop database testwal sql create database testwal wal 2 sql show databases -if $rows != 1 then +if $rows != 3 then return -1 endi -print wallevel $data12_testwal -if $data12_testwal != 2 then +print wallevel $data13_testwal +if $data13_testwal != 2 then return -1 endi sql drop database testwal @@ -278,7 +263,7 @@ sql_error create database $db comp 3 sql_error drop database $db sql show databases -if $rows != 0 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/parser/create_db__for_community_version.sim b/tests/script/tsim/parser/create_db__for_community_version.sim deleted file mode 100644 index 32a8f303c1..0000000000 --- a/tests/script/tsim/parser/create_db__for_community_version.sim +++ /dev/null @@ -1,234 +0,0 @@ -system sh/stop_dnodes.sh -system sh/deploy.sh -n dnode1 -i 1 -system sh/exec.sh -n dnode1 -s start -sql connect - -print ======================== dnode1 start - -$dbPrefix = fi_in_db -$tbPrefix = fi_in_tb -$mtPrefix = fi_in_mt -$tbNum = 10 -$rowNum = 20 -$totalNum = 200 - -print excuting test script create_db.sim -print =============== set up -$i = 0 -$db = $dbPrefix . $i -$mt = $mtPrefix . $i - -sql_error createdatabase $db -sql create database $db -sql use $db -sql show databases - -if $rows != 1 then - return -1 -endi -if $data00 != $db then - return -1 -endi -sql drop database $db - -# case1: case_insensitivity test -print =========== create_db.sim case1: case insensitivity test -sql_error CREATEDATABASE $db -sql CREATE DATABASE $db -sql use $db -sql show databases - -if $rows != 1 then - return -1 -endi -if $data00 != $db then - return -1 -endi -sql drop database $db -print case_insensitivity test passed - -# case2: illegal_db_name test -print =========== create_db.sim case2: illegal_db_name test -$illegal_db1 = 1db -$illegal_db2 = d@b - -sql_error create database $illegal_db1 -sql_error create database $illegal_db2 -print illegal_db_name test passed - -# case3: chinese_char_in_db_name test -print ========== create_db.sim case3: chinese_char_in_db_name test -$CN_db1 = 数据库 -$CN_db2 = 数据库1 -$CN_db3 = db数据库1 -sql_error create database $CN_db1 -sql_error create database $CN_db2 -sql_error create database $CN_db3 -#sql show databases -#if $rows != 3 then -# return -1 -#endi -#if $data00 != $CN_db1 then -# return -1 -#endi -#if $data10 != $CN_db2 then -# return -1 -#endi -#if $data20 != $CN_db3 then -# return -1 -#endi -#sql drop database $CN_db1 -#sql drop database $CN_db2 -#sql drop database $CN_db3 -print case_chinese_char_in_db_name test passed - -# case4: db_already_exists -print create_db.sim case4: db_already_exists -sql create database db0 -sql create database db0 -sql show databases -if $rows != 1 then - return -1 -endi -sql drop database db0 -print db_already_exists test passed - -# case5: db_meta_data -print create_db.sim case5: db_meta_data test -# cfg params -$replica = 1 # max=3 -$duration = 10 -$keep = 365 -$rows_db = 1000 -$cache = 16 # 16MB -$ablocks = 100 -$tblocks = 32 # max=512, automatically trimmed when exceeding -$ctime = 36000 # 10 hours -$wal = 1 # valid value is 1, 2 -$comp = 1 # max=32, automatically trimmed when exceeding - -sql create database $db replica $replica duration $duration keep $keep maxrows $rows_db cache $cache blocks 4 ctime $ctime wal $wal comp $comp -sql show databases -if $rows != 1 then - return -1 -endi -if $data00 != $db then - return -1 -endi -if $data04 != $replica then - return -1 -endi -if $data06 != $duration then - return -1 -endi -if $data07 != 365 then - return -1 -endi -print data08 = $data07 -if $data08 != $cache then - print expect $cache, actual:$data08 - return -1 -endi -if $data09 != 4 then - return -1 -endi - -sql drop database $db - -## param range tests -# replica [1,3] -#sql_error create database $db replica 0 -sql_error create database $db replica 4 - -# day [1, 3650] -sql_error create database $db day 0 -sql_error create database $db day 3651 - -# keep [1, infinity] -sql_error create database $db keep 0 -sql_error create database $db keep 0,0,0 -sql_error create database $db keep 3,3,3 -sql_error create database $db keep 3 -sql_error create database $db keep 11.0 -sql_error create database $db keep 11.0,11.0,11.0 -sql_error create database $db keep "11","11","11" -sql_error create database $db keep "11" -sql_error create database $db keep 13,12,11 -sql_error create database $db keep 11,12,11 -sql_error create database $db keep 12,11,12 -sql_error create database $db keep 11,12,13 -sql_error create database $db keep 11,12,13,14 -sql_error create database $db keep 11,11 -sql_error create database $db keep 365001,365001,365001 -sql_error create database $db keep 365001 -sql create database dbk1 keep 11 -sql show databases -if $rows != 1 then - return -1 -endi -if $data07 != 11 then - return -1 -endi -sql drop database dbk1 -sql create database dbk2 keep 12 -sql show databases -if $rows != 1 then - return -1 -endi -if $data07 != 12 then - return -1 -endi -sql drop database dbk2 -sql create database dbk3 keep 11 -sql show databases -if $rows != 1 then - return -1 -endi -if $data07 != 11 then - return -1 -endi -sql drop database dbk3 -sql create database dbk4 keep 13 -sql show databases -if $rows != 1 then - return -1 -endi -if $data07 != 13 then - return -1 -endi -sql drop database dbk4 -#sql_error create database $db keep 3651 - -# rows [200, 10000] -sql_error create database $db maxrows 199 -#sql_error create database $db maxrows 10001 - -# cache [100, 10485760] -sql_error create database $db cache 0 -#sql_error create database $db cache 10485761 - - -# blocks [32, 4096 overwriten by 4096 if exceeds, Note added:2018-10-24] -#sql_error create database $db tblocks 31 -#sql_error create database $db tblocks 4097 - -# ctime [30, 40960] -sql_error create database $db ctime 29 -sql_error create database $db ctime 40961 - -# wal {0, 2} -#sql_error create database $db wal 0 -sql_error create database $db wal -1 -sql_error create database $db wal 3 - -# comp {0, 1, 2} -sql_error create database $db comp -1 -sql_error create database $db comp 3 - -sql_error drop database $db -sql show databases -if $rows != 0 then - return -1 -endi - -system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/parser/where.sim b/tests/script/tsim/parser/where.sim index 77eb3fd87e..596bffa6f0 100644 --- a/tests/script/tsim/parser/where.sim +++ b/tests/script/tsim/parser/where.sim @@ -51,8 +51,6 @@ while $i < $half $i = $i + 1 endw -sleep 100 - $i = 1 $tb = $tbPrefix . $i @@ -300,8 +298,6 @@ while $i < 1 endw system sh/exec.sh -n dnode1 -s stop -x SIGINT -sleep 500 - system sh/exec.sh -n dnode1 -s start sql_error select * from wh_mt0 where c3 = 'abc' and tbname in ('test_null_filter'); @@ -349,7 +345,6 @@ if $data01 != 2 then return -1 endi sql insert into where_ts values(now, 5); -sleep 10 sql select * from (select * from where_ts) where ts Date: Wed, 20 Jul 2022 21:32:28 +0800 Subject: [PATCH 39/42] fix: the calculation of max row length --- source/common/src/trow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/src/trow.c b/source/common/src/trow.c index f64250bce6..df5bf64acf 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -585,7 +585,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow) { ASSERT(pTColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID); } else { if (IS_VAR_DATA_TYPE(pTColumn->type)) { - if (pColVal) { + if (pColVal && !pColVal->isNone && !pColVal->isNull) { varDataLen += (pColVal->value.nData + sizeof(VarDataLenT)); if (maxVarDataLen < (pColVal->value.nData + sizeof(VarDataLenT))) { maxVarDataLen = pColVal->value.nData + sizeof(VarDataLenT); From 4211db2ec49238ecdfba0feb60b8fe77d8082b8d Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Wed, 20 Jul 2022 21:58:03 +0800 Subject: [PATCH 40/42] fix: fix error in indef operator filter processing --- source/libs/executor/src/executorimpl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 1bbf05294d..3034911872 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -3957,7 +3957,7 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { doFilter(pIndefInfo->pCondition, pInfo->pRes); size_t rows = pInfo->pRes->info.rows; - if (rows >= 0) { + if (rows > 0 || pOperator->status == OP_EXEC_DONE) { break; } } From 659258b2a0e73f344811ada449d1282a681f8722 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 20 Jul 2022 22:47:16 +0800 Subject: [PATCH 41/42] chore: libtaos ws submodule for3.0 (#15218) * chore: add libtaos-ws for 3.0 * chore: update taosws-rs * chore: add libtaosws to install/remove script * chore: update taosws-rs * chore: update taosws-rs * chore: update taos-tools, taosws-rs for 3.0 * fix: packaging/tools/make_install.sh for 3.0 * chore: update taos-tools * chore: fix release script for 3.0 * chore: update taosws-rs for 3.0 * chore: add taows-rs submodule for 3.0 * chore: update taosws-rs for 3.0 * fix: install script support taosws for 3.0 * fix: script error handle for 3.0 * chore: update taosws-rs for 3.0 fix segfault * chore: change container_build for websocket build * fix: install script for taosws * fix: . * chore: update taosws-rs for 3.0 --- tools/taosws-rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/taosws-rs b/tools/taosws-rs index d8cf0e7e06..fa2d829183 160000 --- a/tools/taosws-rs +++ b/tools/taosws-rs @@ -1 +1 @@ -Subproject commit d8cf0e7e067d193cfaf3e920b6ec6cbb9b9f4165 +Subproject commit fa2d82918353a3b56e40838572120c1a4ece644c From b905133faf7f32069207c0b6097964b67e735f77 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Thu, 21 Jul 2022 08:42:55 +0800 Subject: [PATCH 42/42] fix: error in test case --- tests/system-test/2-query/max_partition.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/system-test/2-query/max_partition.py b/tests/system-test/2-query/max_partition.py index a352865c45..109c9075f5 100644 --- a/tests/system-test/2-query/max_partition.py +++ b/tests/system-test/2-query/max_partition.py @@ -169,13 +169,13 @@ class TDTestCase: tdSql.checkData(0,1,self.row_nums) tdSql.query("select c1 , mavg(c1 ,2 ) from stb partition by c1") - tdSql.checkRows(72) + tdSql.checkRows(90) tdSql.query("select c1 , diff(c1 , 0) from stb partition by c1") - tdSql.checkRows(72) + tdSql.checkRows(90) tdSql.query("select c1 , csum(c1) from stb partition by c1") - tdSql.checkRows(80) + tdSql.checkRows(100) tdSql.query("select c1 , sample(c1,2) from stb partition by c1 order by c1") tdSql.checkRows(21) @@ -191,7 +191,7 @@ class TDTestCase: tdSql.checkData(0,1,None) tdSql.query("select c1 , DERIVATIVE(c1,2,1) from stb partition by c1 order by c1") - tdSql.checkRows(72) + tdSql.checkRows(90) # bug need fix # tdSql.checkData(0,1,None)